Skip to content

Commit e5579be

Browse files
Carte GTFS : affichage popup au clic
1 parent 08e54d9 commit e5579be

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

  • apps/transport/client/javascripts

apps/transport/client/javascripts/gtfs.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ const map = Leaflet.map('map', { renderer: Leaflet.canvas() }).setView([lat, lng
3535

3636
Leaflet.tileLayer(IGN.url, IGN.config).addTo(map)
3737

38+
let currentPopup = null
39+
40+
function showPopup (info) {
41+
if (currentPopup) {
42+
currentPopup.remove()
43+
currentPopup = null
44+
}
45+
if (info.picked && info.object) {
46+
let content = ''
47+
if (info.object.count !== undefined) {
48+
content = `${info.object.count.toString()} stops`
49+
} else if (info.object.properties) {
50+
content = `${info.object.properties.d_title} - ${info.object.properties.stop_id} <pre><code>${JSON.stringify(info.object, null, 4)}</code></pre>`
51+
}
52+
if (content) {
53+
setTimeout(() => {
54+
currentPopup = Leaflet.popup()
55+
.setLatLng([info.coordinate[1], info.coordinate[0]])
56+
.setContent(content)
57+
.openOn(map)
58+
}, 0)
59+
}
60+
}
61+
}
62+
3863
const deckGLLayer = new LeafletLayer({
3964
views: [new MapView({ repeat: true })],
4065
layers: []
@@ -43,8 +68,7 @@ map.addLayer(deckGLLayer)
4368

4469
map.on('movestart', function (event) {
4570
deckGLLayer.setProps({
46-
// eslint-disable-next-line no-return-assign
47-
layers: deckGLLayer.props.layers.map(l => l.visible = false)
71+
layers: deckGLLayer.props.layers.map(l => l.clone({ visible: false }))
4872
})
4973
})
5074

@@ -97,7 +121,8 @@ map.on('moveend', function (event) {
97121
getPosition: d => [d.lon, d.lat],
98122
getRadius: d => 2,
99123
getFillColor: d => colorFunc(maxCount < 3 ? 0 : d.count / maxCount),
100-
getLineColor: d => colorFunc(maxCount < 3 ? 0 : d.count / maxCount)
124+
getLineColor: d => colorFunc(maxCount < 3 ? 0 : d.count / maxCount),
125+
onClick: showPopup
101126
})
102127
layer = scatterplotLayer
103128
tooltip = function (d) {
@@ -125,7 +150,8 @@ map.on('moveend', function (event) {
125150
pointRadiusMinPixels: 1,
126151
pointRadiusMaxPixels: 3,
127152
getLineWidth: 1,
128-
getElevation: 30
153+
getElevation: 30,
154+
onClick: showPopup
129155
})
130156
layer = geoJsonLayer
131157
tooltip = function (d) {

0 commit comments

Comments
 (0)