Commit 68be9674 authored by Sp3r4z's avatar Sp3r4z
Browse files

[Script] Add marker popup on click

City or village + latitude and longitude
parent c7a1511f
......@@ -22,13 +22,15 @@ createCircle = (lat,lng) => {
return L.layerGroup(shapeArray)
},
createMarker = (lat,lng) => {
return L.marker([lat, lng])
createMarker = (lat,lng,city) => {
let marker = L.marker([lat, lng]),
precision = 10000
marker.bindPopup(`<b>${city}</b><br>[ ${Math.round(lat*precision)/precision}, ${Math.round(lng*precision)/precision} ]`).openPopup();
return marker
},
createPoint = (lat,lng,departement=null) => {
let marker = createMarker(lat,lng),
createPoint = (lat,lng,city,departement=null) => {
let marker = createMarker(lat,lng,city),
circle = createCircle(lat,lng),
figures = [marker,circle],
layer = null
if(departement != null) {
......@@ -82,7 +84,8 @@ L.Control.geocoder({
.on('markgeocode', (e) => {
let center = e.geocode.center,
postCode = e.geocode.properties.address.postcode,
departementRef = null
departementRef = null,
city = e.geocode.properties.address.city != undefined ? e.geocode.properties.address.city : e.geocode.properties.address.village
if(postCode != null) {
departementRef = postCode.substring(0,2).toUpperCase()
......@@ -91,7 +94,7 @@ L.Control.geocoder({
departementRef = getPostcodeByName(e.geocode.properties.address.county)[0].code
}
createPoint(center.lat,center.lng,departementRef)
createPoint(center.lat,center.lng,city,departementRef)
})
.addTo(theMap)
......@@ -108,8 +111,9 @@ theMap.on('click', (e) => {
// comme à Marseille (inexistant) ou Lyon (Métropole de lyon au lieu de rhone)
if(datas.address != undefined && datas.address.country == 'France') {
let departementRef = datas.address.postcode.substring(0,2)
createPoint(lat,lon,departementRef)
let departementRef = datas.address.postcode.substring(0,2),
city = datas.address.city != undefined ? datas.address.city : datas.address.village
createPoint(lat,lon,city,departementRef)
}
})
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment