From d1aeb6044e7da79ac0c97498ba31f953f34e6618 Mon Sep 17 00:00:00 2001 From: vincent Date: Tue, 10 Dec 2024 22:22:17 +0100 Subject: [PATCH] Ajoute le lien vers Pifometre --- assets/controllers/map_controller.js | 14 +++++++++++--- templates/macro.html.twig | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/assets/controllers/map_controller.js b/assets/controllers/map_controller.js index 8e73086..fe7972e 100644 --- a/assets/controllers/map_controller.js +++ b/assets/controllers/map_controller.js @@ -178,9 +178,17 @@ export default class extends Controller { window.open(url, '_blank'); } - openInPifomap() { - const url = "https://bano.openstreetmap.fr/pifometre/pifomap.html?ratio=N#map="+this.mapInstance.getZoom()+"/"+this.mapInstance.getCenter().lat+"/"+this.mapInstance.getCenter().lng; - window.open(url, '_blank'); + openInPifometre() { + const self = this, url1 = "https://nominatim.openstreetmap.org/reverse?format=json&lat="+this.mapInstance.getCenter().lat+"&lon="+this.mapInstance.getCenter().lng+"&zoom="+this.mapInstance.getZoom()+"&extratags=1"; + fetch(url1).then(function (response) { return response.json(); }).then(function (json) { + const hasInsee = ((typeof json.extratags === 'undefined') || (json.extratags.hasOwnProperty('ref:INSEE'))); + if (hasInsee) { + const url2 = "https://bano.openstreetmap.fr/pifometre/?insee="+json.extratags['ref:INSEE']; + window.open(url2, '_blank'); + } else { + window.alert('Impossible de trouver le code INSEE de la commune…'); + } + }); } openInGeohack() { diff --git a/templates/macro.html.twig b/templates/macro.html.twig index bda15ca..b600536 100644 --- a/templates/macro.html.twig +++ b/templates/macro.html.twig @@ -57,6 +57,7 @@ Où : +