diff --git a/index.html b/index.html index 1be84cf..d4b2196 100644 --- a/index.html +++ b/index.html @@ -119,24 +119,24 @@ -
- prise: - - - - -
-
- - puissance: - - - - - -
+ + + + + + + + + + + + + + + + + +
diff --git a/js/config.js b/js/config.js index dc0c177..9d9422c 100644 --- a/js/config.js +++ b/js/config.js @@ -2,6 +2,13 @@ const config = { osmMention:'© OpenStreetMap contributors', showHighPower : true, overrideQuery : true, - initialZoom : 12 + initialZoom : 12, + tileServers:{ + osm : 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', + cycle : 'https://{s}.tile.opencyclemap.org/{z}/{x}/{y}.png', + cartodb : 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', + stamen : 'https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', + transport : 'https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png' + } } export default config diff --git a/js/main.js b/js/main.js index 11a33d6..9c2df2e 100644 --- a/js/main.js +++ b/js/main.js @@ -11,13 +11,15 @@ import colorUtils from './color-utils.js' console.log('config', config) let geojsondata + + + // serveurs de tuiles: https://wiki.openstreetmap.org/wiki/Tile_servers // https://stamen-tiles.a.ssl.fastly.net/toner/{z}/{x}/{y}.png // https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png // https://tile.openstreetmap.org/{z}/{x}/{y}.png // 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png' -const tileServer = 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png' -const tileServer_stamen = 'https://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png' + // Créer la carte centrée sur Rouen // Liste des 20 villes les plus peuplées de France avec leurs coordonnées géographiques @@ -31,6 +33,8 @@ L.control.scale().addTo(map) * à appliquer à chaque rafraîchissement des points geojson * TODO: make buttons and filter in refresh circles */ +let filterStatesAvailable = ['hide', 'show', 'showOnly'] + let display_type2_sockets = 'show'; let display_type2_combo_sockets = 'show'; let display_unknown_max_power_station = 'show'; @@ -42,7 +46,6 @@ let display_lower_than_200kw = 'show'; let display_higer_than_200kw = 'show'; let display_chelou = 'show'; // les stations avec une valeur suspecte, plus de 400kW -let filterStatesAvailable = ['hide', 'show', 'showOnly'] function setRandomView() { console.log('set random view') @@ -81,29 +84,28 @@ function updateURLWithMapCoordinatesAndZoom() { // Construit l'URL avec les paramètres de coordonnées et de zoom const url = `#coords=1&lat=${center.lat}&lng=${center.lng}&zoom=${zoom}` - // console.log('updateURLWithMapCoordinatesAndZoom url', url) // Met à jour l'URL de la page history.replaceState(null, null, url) } -var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { +var osm = L.tileLayer(config.tileServers.osm, { attribution: config.osmMention + '© OpenStreetMap contributors' }) -var cycle = L.tileLayer('https://{s}.tile.opencyclemap.org/{z}/{x}/{y}.png', { +var cycle = L.tileLayer(config.tileServers.cycle, { attribution: config.osmMention + '© OpenCycleMap contributors' }) -var transport = L.tileLayer('https://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png', { +var transport = L.tileLayer(config.tileServers.transport, { attribution: config.osmMention }) let tileGrey = - L.tileLayer(tileServer, { + L.tileLayer(config.tileServers.cartodb, { attribution: config.osmMention }) let stamen = - L.tileLayer(tileServer_stamen, { + L.tileLayer(config.tileServers.stamen, { attribution: config.osmMention }) var baseLayers = { @@ -114,10 +116,10 @@ var baseLayers = { 'Transport': transport } -let stations_bof = L.layerGroup().addTo(map) // layer group pour tous les marqueurs +let all_stations_markers = L.layerGroup().addTo(map) // layer group pour tous les marqueurs let stations_much_speed_wow = L.layerGroup().addTo(map) // layer group des stations rapides -let overlays = {stations_bof, stations_much_speed_wow} // Si vous avez des calques superposables, ajoutez-les ici +let overlays = {stations_bof: all_stations_markers, stations_much_speed_wow} // Si vous avez des calques superposables, ajoutez-les ici const layerControl = L.control.layers(baseLayers, overlays, {collapsed: true}).addTo(map) tileGrey.addTo(map) @@ -146,6 +148,7 @@ function buildOverpassApiUrl(map, overpassQuery) { const tags_to_display_in_popup = [ 'name', 'capacity', + 'description', 'date_start', 'charging_station:output', 'socket:type_2', @@ -184,7 +187,7 @@ function createJOSMEditLink(feature) { } function supprimerMarqueurs() { - stations_bof.clearLayers() + all_stations_markers.clearLayers() stations_much_speed_wow.clearLayers() map.eachLayer((layer) => { @@ -279,7 +282,7 @@ function displayStatsFromGeoJson(resultAsGeojson) {
${count_station_outputoutput_between_1_and_50 ? count_station_outputoutput_between_1_and_50 : ''}
${output_more_than_50 ? output_more_than_50 : ''}
${output_more_than_100 ? output_more_than_100 : ''}
-
${output_more_than_200? output_more_than_200 : '' | ''}
+
${output_more_than_200 ? output_more_than_200 : '' | ''}
${output_more_than_300 ? output_more_than_300 : ''}
` @@ -315,7 +318,6 @@ function bindEventsOnJosmRemote() { } - function displayPointsFromApi(points = geojsondata) { @@ -337,6 +339,7 @@ function displayPointsFromApi(points = geojsondata) { filter: function (feature, layer) { let isPolygon = (feature.geometry) && (feature.geometry.type !== undefined) && (feature.geometry.type === 'Polygon') if (isPolygon) { + console.log('polygon feature', feature) feature.geometry.type = 'Point' let polygonCenter = L.latLngBounds(feature.geometry.coordinates[0]).getCenter() feature.geometry.coordinates = [polygonCenter.lat, polygonCenter.lng] @@ -350,137 +353,156 @@ function displayPointsFromApi(points = geojsondata) { supprimerMarqueurs() displayPointsFromApi() }, - onEachFeature: function (feature, layer) { - let popupContent = '' - - popupContent += '
' - let type2 = feature.properties.tags['socket:type2'] - let type2_combo = feature.properties.tags['socket:type2_combo'] - if (type2) { - popupContent += ' prise de type 2' - if (type2 !== 'yes') { - popupContent += 'x ' + type2 + '' - } - } - if (feature.properties.tags['socket:type2_combo']) { - - popupContent += ' prise de type 2 combo CCS' - if (type2_combo !== 'yes') { - popupContent += 'x ' + type2_combo + '' - } - } - popupContent += '
' - popupContent += '
' - // ne montrer que certains champs dans la popup - tags_to_display_in_popup.forEach(function (key) { - if (tags_to_display_in_popup.indexOf(key)) { - let value = feature.properties.tags[key] - if (value) { - if (value.indexOf('http') !== -1) { - value = '' + value + '' - } - popupContent = popupContent + '
' + key + ' :' + value + '' - } - } - }) - popupContent += '
' - layer.bindPopup(popupContent) - - let outPowerGuessed = utils.guessOutputPowerFromFeature(feature) - let color = colorUtils.getColor(feature) - let displayOutPowerGuessed = '? kW' - if (outPowerGuessed) { - displayOutPowerGuessed = outPowerGuessed + ' kW max' - } - if (!popupContent) { - popupContent = ` Aucune information renseignée, -ajoutez la dans OpenStreetMap!` - } - let link_josm = createJOSMEditLink(feature) - // console.log('link_josm', link_josm) - // boutons d'itinéraire - - let html = ` 🚗🚴‍♀️👠 -✏️JOSM ${displayOutPowerGuessed}${popupContent}` - - let zoom = map.getZoom() - let radius = 20 - let opacity = 0.5 - let ratio_circle = 10 - - // quand on est loin, montrer d'avantage de couleur, pas le centre - if (zoom < 13) { - ratio_circle = 5 - } - else if (zoom < 15) { - ratio_circle = 1 - opacity = 0.25 - } - else if (zoom <= 16) { - ratio_circle = 0.5 - } - else if (zoom <= 18) { - ratio_circle = 0.25 - } - console.log('ratio_circle', ratio_circle) - radius = outPowerGuessed * ratio_circle - - // if (outPowerGuessed >= 300) { - // radius = 70 * ratio_circle - // } else if (outPowerGuessed >= 200) { - // radius = 60 * ratio_circle - // } else if (outPowerGuessed >= 100) { - // radius = 50 * ratio_circle - // } else if (outPowerGuessed >= 50) { - // radius = 40 * ratio_circle - // } else if (outPowerGuessed >= 20) { - // radius = 30 * ratio_circle - // } else if (outPowerGuessed >= 7) { - // radius = 20 * ratio_circle - // } - - let circle = L.circle(layer._latlng, { - color: color, - fillColor: color, - fillOpacity: opacity, - colorOpacity: opacity, - radius: radius - }).addTo(stations_bof) - - - // montrer les détails quand on est proche - // afficher moins de couleur, montrer le centre plus précis - if (zoom > 15) { - opacity = 0.25 - let circle_center = L.circle(layer._latlng, { - color: 'black', - fillColor: color, - fillOpacity: 1, - radius: 0.1 - }).addTo(stations_bof) - - } - - - circle.bindPopup(html) - circle.on({ - mouseover: function () { - this.openPopup() - bindEventsOnJosmRemote() - }, - mouseout: function () { - // setTimeout(() => this.closePopup(), 15000) - }, - click: function () { - this.openPopup() - bindEventsOnJosmRemote() - }, - }) - }, + onEachFeature: eachFeature, }) } +function makePopupOfFeature(feature) { + let popupContent = '' + + popupContent += '
' + let type2 = feature.properties.tags['socket:type2'] + let type2_combo = feature.properties.tags['socket:type2_combo'] + if (type2) { + popupContent += ' prise de type 2' + if (type2 !== 'yes') { + popupContent += 'x ' + type2 + '' + } + } + if (feature.properties.tags['socket:type2_combo']) { + + popupContent += ' prise de type 2 combo CCS' + if (type2_combo !== 'yes') { + popupContent += 'x ' + type2_combo + '' + } + } + popupContent += '
' + popupContent += '
' + // ne montrer que certains champs dans la popup + tags_to_display_in_popup.forEach(function (key) { + if (tags_to_display_in_popup.indexOf(key)) { + let value = feature.properties.tags[key] + if (value) { + if (value.indexOf('http') !== -1) { + value = '' + value + '' + } + popupContent = popupContent + '
' + key + ' :' + value + '' + } + } + }) + popupContent += '
' + return popupContent; +} + +function eachFeature(feature, layer) { + + let link_josm = createJOSMEditLink(feature) + + let popupContent = makePopupOfFeature(feature) + layer.bindPopup(popupContent) + + let outPowerGuessed = utils.guessOutputPowerFromFeature(feature) + let color = colorUtils.getColor(feature) + let displayOutPowerGuessed = '? kW' + if (outPowerGuessed) { + displayOutPowerGuessed = outPowerGuessed + ' kW max' + } + if (!popupContent) { + popupContent = ` Aucune information renseignée, +ajoutez la dans OpenStreetMap!` + } + // boutons d'itinéraire + + let html = ` 🚗🚴‍♀️👠 +✏️JOSM ${displayOutPowerGuessed}${popupContent}` + + let zoom = map.getZoom() + let radius = 20 + let opacity = 0.5 + let ratio_circle = 10 + + // quand on est loin, montrer d'avantage de couleur, pas le centre + if (zoom < 13) { + ratio_circle = 5 + } else if (zoom < 15) { + ratio_circle = 1 + opacity = 0.25 + } else if (zoom <= 16) { + ratio_circle = 0.5 + } else if (zoom <= 18) { + ratio_circle = 0.25 + } + console.log('ratio_circle', ratio_circle) + if (!outPowerGuessed) { + radius = radius * ratio_circle + } else { + radius = outPowerGuessed * ratio_circle + } + + // if (outPowerGuessed >= 300) { + // radius = 70 * ratio_circle + // } else if (outPowerGuessed >= 200) { + // radius = 60 * ratio_circle + // } else if (outPowerGuessed >= 100) { + // radius = 50 * ratio_circle + // } else if (outPowerGuessed >= 50) { + // radius = 40 * ratio_circle + // } else if (outPowerGuessed >= 20) { + // radius = 30 * ratio_circle + // } else if (outPowerGuessed >= 7) { + // radius = 20 * ratio_circle + // } + + let circle = L.circle(layer._latlng, { + color: color, + fillColor: color, + fillOpacity: opacity, + colorOpacity: opacity, + radius: radius + }).addTo(all_stations_markers) + + + // montrer les détails quand on est proche + // afficher moins de couleur, montrer le centre plus précis + if (zoom > 15) { + opacity = 0.25 + let circle_center = L.circle(layer._latlng, { + color: 'black', + fillColor: color, + fillOpacity: 1, + radius: 0.1 + }) + if (!outPowerGuessed) { + + circle_center.bindTooltip("?" , { + permanent: true, + className: "my-label", + offset: [0, 0] + }); + } + circle_center.addTo(all_stations_markers); + + + } + + + circle.bindPopup(html) + circle.on({ + mouseover: function () { + this.openPopup() + bindEventsOnJosmRemote() + }, + mouseout: function () { + // setTimeout(() => this.closePopup(), 15000) + }, + click: function () { + this.openPopup() + bindEventsOnJosmRemote() + }, + }) +} + function makeCssClassFromTags(tags) { let tagKeys = Object.keys(tags) if (!tags) { @@ -542,8 +564,8 @@ function loadOverpassQuery() { let overpassApiUrl = buildOverpassApiUrl(map, queryTextfieldValue) $.get(overpassApiUrl, function (geoDataPointsFromApi) { - supprimerMarqueurs() - displayPointsFromApi(geoDataPointsFromApi) + geojsondata = geoDataPointsFromApi + refreshDisplay() $('#spinning_icon').fadeOut() $('#message-loading').fadeOut() isLoading = false @@ -551,6 +573,12 @@ function loadOverpassQuery() { } } +function refreshDisplay() { + supprimerMarqueurs() + console.log('geojsondata', geojsondata) + displayPointsFromApi(geojsondata) +} + function onMapMoveEnd() { let center = map.getCenter() @@ -585,17 +613,20 @@ $(document).ready(function () { // boutons de toggle et de cycle de visibilité // $('#filterUnkown').on('click', function () { - cycleVariableState(display_unknown_max_power_station, '#filterUnkown') + console.log('filterUnkown', filterUnkown) + display_unknown_max_power_station = cycleVariableState(display_unknown_max_power_station, '#filterUnkown') showActiveFilter(display_unknown_max_power_station, '#filterUnkown') + refreshDisplay() }) showActiveFilter(display_unknown_max_power_station, '#filterUnkown') }) function showActiveFilter(filterVariableName, selectorId) { - $(selectorId).attr('class', 'filter-state-' + filterVariableName ) + $(selectorId).attr('class', 'filter-state-' + filterVariableName) } function cycleVariableState(filterVariableName, selectorId) { + console.log('filterVariableName', filterVariableName, filterStatesAvailable) if (filterVariableName) { if (filterVariableName == filterStatesAvailable[0]) { filterVariableName = filterStatesAvailable[1] @@ -609,6 +640,7 @@ function cycleVariableState(filterVariableName, selectorId) { } showActiveFilter(filterVariableName, selectorId) + console.log('filterVariableName after', filterVariableName) return filterVariableName } diff --git a/styles/images/layers.png b/styles/images/layers.png index d2a6a8c..814e5c5 100644 Binary files a/styles/images/layers.png and b/styles/images/layers.png differ diff --git a/styles/images/map-marker.png b/styles/images/map-marker.png deleted file mode 100644 index 1c1c045..0000000 Binary files a/styles/images/map-marker.png and /dev/null differ diff --git a/styles/images/marker-icon.png b/styles/images/marker-icon.png new file mode 100644 index 0000000..814e5c5 Binary files /dev/null and b/styles/images/marker-icon.png differ diff --git a/styles/style.css b/styles/style.css index 141eb41..5c92c3f 100644 --- a/styles/style.css +++ b/styles/style.css @@ -346,16 +346,35 @@ button { padding: 1rem 2rem; border-radius: 0.25rem; } +.filter-group button:after{ + position: relative; + float:right; + left: 1rem; + top: 1rem; + font-size: 0.9em; +} +.filter-group button.filter-state-hide:after{ + content: "cacher"; + color: grey; +} +.filter-group button.filter-state-show:after{ + content: "montrer"; + color: green; +} +.filter-group button.filter-state-showOnly:after{ + content: "montrer uniquement"; + color: orange; +} .filter-group button.filter-state-hide{ - color: #670a0a; + /*color: #670a0a;*/ background: #fff; } .filter-group button.filter-state-show{ color: green; - background: #96b1ea; + /*background: #96b1ea;*/ } .filter-group button.filter-state-showOnly{ color: orange; - background: #96b1ea; + /*background: #96b1ea;*/ } \ No newline at end of file