Commit 144815ac authored by laurent doreille's avatar laurent doreille
Browse files

departement au clic

parent 2c84e5f4
......@@ -79,7 +79,7 @@ L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
L.Control.geocoder({
defaultMarkGeocode: false
})
.on('markgeocode', function(e) {
.on('markgeocode', (e) => {
let center = e.geocode.center,
postCode = e.geocode.properties.address.postcode,
departementRef = null
......@@ -95,10 +95,23 @@ L.Control.geocoder({
})
.addTo(theMap)
theMap.on('click', function(e) {
createPoint(e.latlng.lat,e.latlng.lng)
})
theMap.on('click', (e) => {
let lat = e.latlng.lat
let lon = e.latlng.lng
let reverse = `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json&zoom=18`
fetch(reverse)
.then(response => response.json()
.then(datas => {
// https://nominatim.org/release-docs/develop/api/Reverse/
// le "county" ne donne pas toujours le département mais on a le postcode qui lui est toujours juste CQFD
// comme à Marseille (inexistant) ou Lyon (Métropole de lyon au lieu de rhone)
let departementRef = datas.address.postcode.substring(0,2)
createPoint(lat,lon,departementRef)
})
)
})
const customControlClean = L.Control.extend({
options: {
position: 'topleft'
......
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