From 21645289fc5d3c3852944c68f37af600bf7a2b11 Mon Sep 17 00:00:00 2001 From: vincent Date: Tue, 7 Jan 2025 23:16:27 +0100 Subject: [PATCH] Corrige les liens pifo* --- assets/controllers/map_controller.js | 23 ++++++++++++++++++++--- templates/macro.html.twig | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/assets/controllers/map_controller.js b/assets/controllers/map_controller.js index fe7972e..1deb80c 100644 --- a/assets/controllers/map_controller.js +++ b/assets/controllers/map_controller.js @@ -178,12 +178,25 @@ export default class extends Controller { window.open(url, '_blank'); } + openInPifomap() { + const self = this, url1 = "https://geo.api.gouv.fr/communes?lat="+this.mapInstance.getCenter().lat+"&lon="+this.mapInstance.getCenter().lng+"&fields=code,nom"; + fetch(url1).then(function (response) { return response.json(); }).then(function (json) { + const hasInsee = (Array.isArray(json) && (json.length > 0) && json[0].hasOwnProperty('code')); + if (hasInsee) { + const url2 = "https://bano.openstreetmap.fr/pifometre/pifomap.html?insee="+json[0].code; + window.open(url2, '_blank'); + } else { + window.alert('Impossible de trouver le code INSEE de la commune…'); + } + }); + } + 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"; + const self = this, url1 = "https://geo.api.gouv.fr/communes?lat="+this.mapInstance.getCenter().lat+"&lon="+this.mapInstance.getCenter().lng+"&fields=code,nom"; fetch(url1).then(function (response) { return response.json(); }).then(function (json) { - const hasInsee = ((typeof json.extratags === 'undefined') || (json.extratags.hasOwnProperty('ref:INSEE'))); + const hasInsee = (Array.isArray(json) && (json.length > 0) && json[0].hasOwnProperty('code')); if (hasInsee) { - const url2 = "https://bano.openstreetmap.fr/pifometre/?insee="+json.extratags['ref:INSEE']; + const url2 = "https://bano.openstreetmap.fr/pifometre/?insee="+json[0].code; window.open(url2, '_blank'); } else { window.alert('Impossible de trouver le code INSEE de la commune…'); @@ -216,4 +229,8 @@ export default class extends Controller { window.open(url, '_blank'); } + openInF4Map() { + const url = "https://demo.f4map.com/#lat="+this.mapInstance.getCenter().lat+"&lon="+this.mapInstance.getCenter().lng+"&zoom="+this.mapInstance.getZoom(); + } + } diff --git a/templates/macro.html.twig b/templates/macro.html.twig index b600536..228aeab 100644 --- a/templates/macro.html.twig +++ b/templates/macro.html.twig @@ -60,6 +60,7 @@ Où : +