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ù :
+