2024-10-17 15:01:47 +02:00
|
|
|
//import * as geoDataPointsFromApi from './data.json';
|
|
|
|
|
|
|
|
const overrideQuery = true
|
|
|
|
const initialZoom = 14
|
|
|
|
const osmMention = '© <a href="https://openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
2024-10-18 00:47:01 +02:00
|
|
|
let unknown_color = '#676767' // color for unknown power output of the station
|
2024-10-17 15:01:47 +02:00
|
|
|
|
|
|
|
// 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
|
2024-10-18 00:47:01 +02:00
|
|
|
// https://tile.openstreetmap.org/{z}/{x}/{y}.png
|
|
|
|
// 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png'
|
2024-10-17 15:01:47 +02:00
|
|
|
const tileServer = 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png'
|
|
|
|
|
|
|
|
// Créer la carte centrée sur Rouen
|
|
|
|
var map = L.map('map').setView([49.4438, 1.0993], initialZoom)
|
|
|
|
// 'https://overpass-api.de/api/interpreter?data=[out:json][timeout:25];' +
|
|
|
|
// 'area(id:3600075628)->.searchArea;' +
|
|
|
|
// 'node[amenity=charging_station](area.searchArea);' +
|
|
|
|
// 'out body geom;'
|
|
|
|
|
|
|
|
L.tileLayer(tileServer, {
|
|
|
|
maxZoom: 19,
|
|
|
|
attribution: osmMention,
|
|
|
|
}).addTo(map)
|
|
|
|
|
|
|
|
// if (overrideQuery) {
|
|
|
|
// $('#overpass-api-controls').hide();
|
|
|
|
// }
|
|
|
|
|
|
|
|
function buildOverpassApiUrl (map, overpassQuery) {
|
|
|
|
|
|
|
|
var baseUrl = 'https://overpass-api.de/api/interpreter'
|
|
|
|
var bounds = map.getBounds().getSouth() + ',' + map.getBounds().getWest() + ',' + map.getBounds().getNorth() + ',' + map.getBounds().getEast()
|
|
|
|
var resultUrl, query = ''
|
|
|
|
|
|
|
|
if (overrideQuery) {
|
|
|
|
query = `?data=[out:json][timeout:15];(
|
|
|
|
node[amenity=charging_station](${bounds});
|
|
|
|
);out body geom;`
|
|
|
|
} else {
|
|
|
|
var nodeQuery = 'node[' + overpassQuery + '](' + bounds + ');'
|
|
|
|
var wayQuery = 'way[' + overpassQuery + '](' + bounds + ');'
|
|
|
|
var relationQuery = 'relation[' + overpassQuery + '](' + bounds + ');'
|
|
|
|
query = '?data=[out:json][timeout:15];(' + nodeQuery + wayQuery + relationQuery + ');out body geom;'
|
|
|
|
|
|
|
|
}
|
|
|
|
resultUrl = baseUrl + query
|
|
|
|
return resultUrl
|
|
|
|
}
|
|
|
|
|
2024-10-18 00:47:01 +02:00
|
|
|
const tags_to_display_in_popup = [
|
|
|
|
'name',
|
|
|
|
'capacity',
|
|
|
|
'date_start',
|
2024-10-17 15:01:47 +02:00
|
|
|
'charging_station:output',
|
2024-10-18 00:47:01 +02:00
|
|
|
'socket:type_2',
|
|
|
|
'socket:type2:output',
|
2024-10-17 15:01:47 +02:00
|
|
|
'socket:typee',
|
2024-10-18 00:47:01 +02:00
|
|
|
'socket:typee:output',
|
2024-10-17 15:01:47 +02:00
|
|
|
'socket:type2_combo',
|
2024-10-18 00:47:01 +02:00
|
|
|
'socket:type2_combo:output',
|
2024-10-17 15:01:47 +02:00
|
|
|
'socket:chademo',
|
|
|
|
'operator', 'ref:EU:EVSE',
|
2024-10-18 00:33:25 +02:00
|
|
|
'network',
|
2024-10-18 00:47:01 +02:00
|
|
|
'opening_hours',
|
2024-10-17 15:01:47 +02:00
|
|
|
'contact',
|
2024-10-18 00:47:01 +02:00
|
|
|
'phone',
|
|
|
|
'contact:phone',
|
|
|
|
'website',
|
|
|
|
'contact:website',
|
|
|
|
'ref',
|
|
|
|
'fee',
|
|
|
|
'payment',
|
|
|
|
'payment:contactless',
|
|
|
|
'authentication:app',
|
|
|
|
'authentication:debit_card',
|
|
|
|
]
|
2024-10-17 15:01:47 +02:00
|
|
|
|
2024-10-18 00:33:25 +02:00
|
|
|
function supprimerMarqueurs (map) {
|
|
|
|
map.eachLayer((layer) => {
|
|
|
|
if (layer instanceof L.Marker) {
|
|
|
|
layer.remove()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const colors = [
|
|
|
|
'#fe8e5d',
|
|
|
|
'#fec35d',
|
|
|
|
'#b7a543',
|
|
|
|
'#7fb743',
|
|
|
|
'#0fae50',
|
|
|
|
'#08c1c7',
|
|
|
|
'#0081f0',
|
|
|
|
]
|
2024-10-18 00:47:01 +02:00
|
|
|
|
2024-10-18 00:33:25 +02:00
|
|
|
function getColor (feature) {
|
|
|
|
var outputPower = 0
|
|
|
|
if (feature.properties && feature.properties.tags) {
|
|
|
|
for (var tag in feature.properties.tags) {
|
|
|
|
let value = feature.properties.tags[tag]
|
2024-10-18 00:47:01 +02:00
|
|
|
if (value && tag.toLowerCase().indexOf('output') !== -1) {
|
2024-10-18 00:33:25 +02:00
|
|
|
console.log('tag contient output', tag, value)
|
2024-10-18 00:47:01 +02:00
|
|
|
value = '' + value
|
|
|
|
if (value.replace) {
|
2024-10-18 00:33:25 +02:00
|
|
|
value = value.replace(' ')
|
|
|
|
value = value.replace('kW', '')
|
|
|
|
}
|
|
|
|
var power = parseInt(value)
|
|
|
|
if (power > outputPower) {
|
|
|
|
outputPower = power
|
|
|
|
console.log('power', power)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-18 00:47:01 +02:00
|
|
|
if (!outputPower) {
|
2024-10-18 00:33:25 +02:00
|
|
|
console.log('pas de outputPower', outputPower)
|
2024-10-18 00:47:01 +02:00
|
|
|
|
|
|
|
return unknown_color
|
2024-10-18 00:33:25 +02:00
|
|
|
}
|
|
|
|
feature.properties.tags.has_output_of_irve_specified = outputPower
|
|
|
|
var index = Math.min(Math.floor(outputPower / 10), colors.length - 1)
|
|
|
|
console.log('outputPower', outputPower)
|
|
|
|
console.log('colors[index]', colors[index])
|
|
|
|
return colors[index]
|
|
|
|
}
|
|
|
|
|
2024-10-17 15:01:47 +02:00
|
|
|
function displayPointsFromApi (points) {
|
|
|
|
|
|
|
|
var resultAsGeojson = osmtogeojson(points)
|
|
|
|
var resultLayer = L.geoJson(resultAsGeojson, {
|
|
|
|
style: function (feature) {
|
|
|
|
return { color: '#f00' }
|
|
|
|
},
|
|
|
|
filter: function (feature, layer) {
|
|
|
|
var isPolygon = (feature.geometry) && (feature.geometry.type !== undefined) && (feature.geometry.type === 'Polygon')
|
|
|
|
if (isPolygon) {
|
|
|
|
feature.geometry.type = 'Point'
|
|
|
|
var polygonCenter = L.latLngBounds(feature.geometry.coordinates[0]).getCenter()
|
|
|
|
feature.geometry.coordinates = [polygonCenter.lat, polygonCenter.lng]
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
onzoomend: function (event) {
|
|
|
|
console.log('event', event)
|
|
|
|
},
|
|
|
|
onEachFeature: function (feature, layer) {
|
|
|
|
var popupContent = ''
|
2024-10-18 00:33:25 +02:00
|
|
|
// console.log('feature.properties', feature.properties)
|
2024-10-17 15:01:47 +02:00
|
|
|
// popupContent = popupContent + '<dt>@id</dt><dd> capacité: ' + feature.properties.tags['capacity'] + '</dd>'
|
|
|
|
var keys = Object.keys(feature.properties.tags)
|
|
|
|
// 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) {
|
|
|
|
popupContent = popupContent + '<br/><strong class="popup-key">' + key + ' :</strong> ' + value + ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// popupContent = popupContent + '</dl>'
|
|
|
|
layer.bindPopup(popupContent)
|
|
|
|
|
|
|
|
let iconSiZePx = 20
|
|
|
|
|
|
|
|
let rest_name = ''
|
|
|
|
|
|
|
|
let html = '<a class="edit-button" href="https://www.openstreetmap.org/edit?editor=id&node=' + feature.properties.id + '">' +
|
|
|
|
'✏️</a> <br/>' + popupContent
|
|
|
|
|
2024-10-18 00:33:25 +02:00
|
|
|
// console.log('layer', layer)
|
2024-10-17 15:01:47 +02:00
|
|
|
var label = L.marker(layer._latlng, {
|
|
|
|
icon: L.divIcon({
|
2024-10-18 00:33:25 +02:00
|
|
|
iconUrl: '/img/beer.jpg',
|
|
|
|
//+ getIconFromTags(feature.properties.tags),
|
2024-10-17 23:57:47 +02:00
|
|
|
// className: 'label ' + makeCssClassFromTags(feature.properties.tags),
|
2024-10-17 15:01:47 +02:00
|
|
|
|
|
|
|
iconSize: ['auto', 'auto'],
|
|
|
|
}),
|
|
|
|
}).addTo(map)
|
|
|
|
|
2024-10-18 00:33:25 +02:00
|
|
|
let color = getColor(feature)
|
2024-10-18 00:47:01 +02:00
|
|
|
let radius = 50
|
|
|
|
if (color == '#0081f0') {
|
|
|
|
radius = 200
|
|
|
|
} else if (color == '#08c1c7') {
|
|
|
|
radius = 100
|
2024-10-18 00:33:25 +02:00
|
|
|
}
|
2024-10-17 23:57:47 +02:00
|
|
|
let circle = L.circle(layer._latlng, {
|
2024-10-18 00:33:25 +02:00
|
|
|
color: color,
|
|
|
|
fillColor: color,
|
|
|
|
fillOpacity: 0.8,
|
|
|
|
radius: radius
|
|
|
|
}).addTo(map)
|
2024-10-17 15:01:47 +02:00
|
|
|
|
2024-10-17 23:57:47 +02:00
|
|
|
// var myIcon = L.icon({
|
|
|
|
// // iconUrl: 'https://cipherbliss.com/ou-manger/img/' + getIconFromTags(feature.properties.tags),
|
|
|
|
// iconSize: [iconSiZePx, iconSiZePx],
|
|
|
|
// iconAnchor: [iconSiZePx / 2, iconSiZePx / 2],
|
|
|
|
// popupAnchor: [iconSiZePx / 2, iconSiZePx / 2],
|
|
|
|
// className: makeCssClassFromTags(feature.properties.tags),
|
|
|
|
//
|
|
|
|
// })
|
2024-10-17 15:01:47 +02:00
|
|
|
|
2024-10-17 23:57:47 +02:00
|
|
|
// let regular_marker = L.marker(layer._latlng, {
|
2024-10-18 00:33:25 +02:00
|
|
|
// title: rest_name,
|
|
|
|
// icon: myIcon
|
2024-10-17 23:57:47 +02:00
|
|
|
// }).addTo(map)
|
|
|
|
|
|
|
|
circle.bindPopup(html)
|
|
|
|
circle.on({
|
2024-10-17 15:01:47 +02:00
|
|
|
mouseover: function () {
|
|
|
|
this.openPopup()
|
|
|
|
},
|
|
|
|
mouseout: function () {
|
|
|
|
setTimeout(() => this.closePopup(), 3000)
|
|
|
|
},
|
|
|
|
click: function () {
|
|
|
|
this.openPopup()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeCssClassFromTags (tags) {
|
|
|
|
console.log('tags', tags)
|
|
|
|
let tagKeys = Object.keys(tags)
|
|
|
|
console.log('tagKeys', tagKeys)
|
|
|
|
if (!tags) {
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
let listOfClasses = []
|
|
|
|
|
|
|
|
tagKeys.forEach((element) => {
|
|
|
|
listOfClasses.push('tag-' + element + '_' + tags[element].replace(':', '--').replace(' ', '-'))
|
|
|
|
})
|
|
|
|
|
|
|
|
return listOfClasses.join(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
function getIconFromTags (tags) {
|
|
|
|
let iconFileName = ''
|
|
|
|
// let iconFileName = 'icon_restaurant.png';
|
|
|
|
if (tags['man_made']) {
|
|
|
|
iconFileName = 'fountain.png'
|
|
|
|
}
|
|
|
|
return iconFileName
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#query-button').click(function () {
|
2024-10-18 00:33:25 +02:00
|
|
|
supprimerMarqueurs(map)
|
2024-10-17 15:01:47 +02:00
|
|
|
loadOverpassQuery()
|
|
|
|
})
|
|
|
|
|
|
|
|
let isLoading = false
|
|
|
|
|
|
|
|
function loadOverpassQuery () {
|
|
|
|
|
|
|
|
// ne pas charger si on recherche déjà
|
|
|
|
if (!isLoading) {
|
|
|
|
isLoading = true
|
|
|
|
$('#spinning_icon').fadeIn()
|
|
|
|
var queryTextfieldValue = $('#query-textfield').val()
|
|
|
|
var overpassApiUrl = buildOverpassApiUrl(map, queryTextfieldValue)
|
|
|
|
|
|
|
|
$.get(overpassApiUrl, function (geoDataPointsFromApi) {
|
|
|
|
|
|
|
|
displayPointsFromApi(geoDataPointsFromApi)
|
|
|
|
$('#spinning_icon').fadeOut()
|
2024-10-18 00:33:25 +02:00
|
|
|
$('#message-loading').fadeOut()
|
2024-10-17 15:01:47 +02:00
|
|
|
isLoading = false
|
|
|
|
}) // end of the getting from overpass API
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#spinning_icon').hide()
|
2024-10-18 00:33:25 +02:00
|
|
|
$('#message-loading').hide()
|
2024-10-17 15:01:47 +02:00
|
|
|
|
|
|
|
loadOverpassQuery()
|