diff --git a/src/runtime/components/feed-version-map-viewer.vue b/src/runtime/components/feed-version-map-viewer.vue index 62f0298..8620f31 100644 --- a/src/runtime/components/feed-version-map-viewer.vue +++ b/src/runtime/components/feed-version-map-viewer.vue @@ -29,7 +29,7 @@ > Select routes
- Use your cursor to highlight routes + Use your cursor to highlight route lines or stop points. Click for details. diff --git a/src/runtime/components/map-layers.js b/src/runtime/components/map-layers.js index 2d61cd6..e9e857b 100644 --- a/src/runtime/components/map-layers.js +++ b/src/runtime/components/map-layers.js @@ -21,12 +21,43 @@ const colors = { } const stopLayers = [ + // Add hover/active layer first + { + name: 'stop-active', + type: 'circle', + source: 'stops', + minzoom: 14, // Match the stopTiles minzoom + paint: { + 'circle-radius': [ + 'case', + ['boolean', ['feature-state', 'hover'], false], + 8, // hovered size + 6 // normal size + ], + 'circle-color': colors.stop, + 'circle-opacity': [ + 'case', + ['boolean', ['feature-state', 'hover'], false], + 0.8, // hovered opacity + 0.0 // normal opacity (invisible when not hovered) + ], + 'circle-stroke-width': [ + 'case', + ['boolean', ['feature-state', 'hover'], false], + 2, // hovered stroke width + 0 // normal stroke width + ], + 'circle-stroke-color': '#ffffff' + } + }, + // Regular stops layer { name: 'stops', type: 'circle', source: 'stops', + minzoom: 14, paint: { - 'circle-color': '#000', + 'circle-color': colors.stop, 'circle-radius': 4, 'circle-opacity': 0.75 } diff --git a/src/runtime/components/map-route-list.vue b/src/runtime/components/map-route-list.vue index 03c0bd4..81b3009 100644 --- a/src/runtime/components/map-route-list.vue +++ b/src/runtime/components/map-route-list.vue @@ -1,8 +1,14 @@ @@ -39,6 +50,15 @@ export default { isComponentModalActive: { type: Boolean, default: false }, agencyFeatures: { type: Object, default () { return {} } } }, + computed: { + hasFeatures() { + return Object.keys(this.agencyFeatures).some(agency => { + const features = this.agencyFeatures[agency] + return (features.routes && Object.keys(features.routes).length > 0) || + (features.stops && Object.keys(features.stops).length > 0) + }) + } + }, methods: { close () { this.$emit('close') diff --git a/src/runtime/components/map-viewer.vue b/src/runtime/components/map-viewer.vue index 6fadcf6..f5f0e46 100644 --- a/src/runtime/components/map-viewer.vue +++ b/src/runtime/components/map-viewer.vue @@ -34,7 +34,8 @@ export default { return { map: null, marker: null, - hovering: [] + hoveringRoutes: [], + hoveringStops: [] } }, watch: { @@ -363,28 +364,57 @@ export default { }, mapMouseMove (e) { const map = this.map - const features = map.queryRenderedFeatures(e.point, { layers: ['route-active'] }) + // Query both routes and stops + const routeFeatures = map.queryRenderedFeatures(e.point, { layers: ['route-active'] }) + const stopFeatures = map.queryRenderedFeatures(e.point, { layers: ['stop-active'] }) + map.getCanvas().style.cursor = 'pointer' - for (const k of this.hovering) { + + // Handle route hover states + for (const k of this.hoveringRoutes) { map.setFeatureState( { source: 'routes', id: k, sourceLayer: this.routeTiles ? this.routeTiles.id : null }, { hover: false } ) } - this.hovering = [] - for (const v of features) { - this.hovering.push(v.id) + this.hoveringRoutes = [] + for (const v of routeFeatures) { + this.hoveringRoutes.push(v.id) map.setFeatureState({ source: 'routes', id: v.id, sourceLayer: this.routeTiles ? this.routeTiles.id : null }, { hover: true }) } + + // Handle stop hover states + for (const k of this.hoveringStops) { + map.setFeatureState( + { source: 'stops', id: k, sourceLayer: this.stopTiles ? this.stopTiles.id : null }, + { hover: false } + ) + } + this.hoveringStops = [] + for (const v of stopFeatures) { + this.hoveringStops.push(v.id) + map.setFeatureState({ source: 'stops', id: v.id, sourceLayer: this.stopTiles ? this.stopTiles.id : null }, { hover: true }) + } + + // Combine features for emission const agencyFeatures = {} - for (const v of features) { + const processFeature = (v) => { const agencyId = v.properties.agency_name - const routeId = v.properties.route_id + const featureId = v.properties.route_id || v.properties.stop_id + const featureType = v.properties.route_id ? 'route' : 'stop' if (agencyFeatures[agencyId] == null) { - agencyFeatures[agencyId] = {} + agencyFeatures[agencyId] = { routes: {}, stops: {} } + } + if (featureType === 'route') { + agencyFeatures[agencyId].routes[featureId] = v.properties + } else { + agencyFeatures[agencyId].stops[featureId] = v.properties } - agencyFeatures[agencyId][routeId] = v.properties } + + routeFeatures.forEach(processFeature) + stopFeatures.forEach(processFeature) + console.log(agencyFeatures) this.$emit('setAgencyFeatures', agencyFeatures) } } diff --git a/src/runtime/components/pages/map.vue b/src/runtime/components/pages/map.vue index 6dc6bbf..c757e0d 100644 --- a/src/runtime/components/pages/map.vue +++ b/src/runtime/components/pages/map.vue @@ -28,7 +28,7 @@ /> -->
- Zoom in to select routes and to see stop points. + Zoom in to select route lines and to see stop points.
@@ -39,10 +39,10 @@ @close="isComponentModalActive = false" >
- Select routes + Select routes and stops
- Use your cursor to highlight routes and see their names here.
Click for more details. + Use your cursor to highlight routes lines or stop points. Click for details.
@@ -197,7 +197,12 @@ export default { } else { this.setCoords(null) } - if (Object.keys(this.agencyFeatures).length > 0) { + // Check if we have any routes or stops to show in the modal + const hasFeatures = Object.keys(this.agencyFeatures).some(agency => { + return Object.keys(this.agencyFeatures[agency].routes || {}).length > 0 || + Object.keys(this.agencyFeatures[agency].stops || {}).length > 0 + }) + if (hasFeatures) { this.isComponentModalActive = true } } diff --git a/src/runtime/components/route-select.vue b/src/runtime/components/route-select.vue index 7528a3f..37291c3 100644 --- a/src/runtime/components/route-select.vue +++ b/src/runtime/components/route-select.vue @@ -1,33 +1,60 @@