Browse Source

Corrige les liens pifo*

master
vincent 4 weeks ago
parent
commit
21645289fc
2 changed files with 21 additions and 3 deletions
  1. +20
    -3
      assets/controllers/map_controller.js
  2. +1
    -0
      templates/macro.html.twig

+ 20
- 3
assets/controllers/map_controller.js View File

@ -178,12 +178,25 @@ export default class extends Controller {
window.open(url, '_blank'); 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() { 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) { 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) { 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'); window.open(url2, '_blank');
} else { } else {
window.alert('Impossible de trouver le code INSEE de la commune…'); window.alert('Impossible de trouver le code INSEE de la commune…');
@ -216,4 +229,8 @@ export default class extends Controller {
window.open(url, '_blank'); 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();
}
} }

+ 1
- 0
templates/macro.html.twig View File

@ -60,6 +60,7 @@ Où :
<button class="btn btn-sm btn-link" data-action="map#openInPifometre">Pifomètre</button> <button class="btn btn-sm btn-link" data-action="map#openInPifometre">Pifomètre</button>
<button class="btn btn-sm btn-link" data-action="map#openInGeohack">GeoHack</button> <button class="btn btn-sm btn-link" data-action="map#openInGeohack">GeoHack</button>
<button class="btn btn-sm btn-link" data-action="map#openInGeoportail">GéoPortail</button> <button class="btn btn-sm btn-link" data-action="map#openInGeoportail">GéoPortail</button>
<button class="btn btn-sm btn-link" data-action="map#openInF4Map">F4Map</button>
<button class="btn btn-sm btn-link ça-pue-c’est-pas-libre" data-action="map#openInMapillary">Mapillary</button> <button class="btn btn-sm btn-link ça-pue-c’est-pas-libre" data-action="map#openInMapillary">Mapillary</button>
<button class="btn btn-sm btn-link ça-pue-c’est-pas-libre" data-action="map#openInGoogleMaps">Google Maps</button> <button class="btn btn-sm btn-link ça-pue-c’est-pas-libre" data-action="map#openInGoogleMaps">Google Maps</button>
<button class="btn btn-sm btn-link ça-pue-c’est-pas-libre" data-action="map#openInBing">Bing</button> <button class="btn btn-sm btn-link ça-pue-c’est-pas-libre" data-action="map#openInBing">Bing</button>


Loading…
Cancel
Save