Commit da096246 authored by Gérald Niel's avatar Gérald Niel
Browse files

Modifs fonctions & Nouvelle-Calédonie

parent 6f07e13e
......@@ -408,7 +408,7 @@
"nom": "Mayotte"
},
{
"code": "98",
"code": "988",
"nom": "Nouvelle-Calédonie"
}
]
\ No newline at end of file
......@@ -145,10 +145,10 @@ window.addEventListener('load', async function () {
if (postCode != null) {
let cp = postCode.substring(0, 2).toUpperCase();
departementRef = cp == '97' ? postCode.substring(0, 3).toUpperCase() : cp;
departementRef = ( cp == '97' || cp == '98' ) ? postCode.substring(0, 3).toUpperCase() : cp;
}
else if (a.region == 'Nouvelle-Calédonie') {
departementRef = '98'
departementRef = '988'
}
else if (a.county != null) {
departementRef = getPostcodeByName(a.county)[0].code
......@@ -188,9 +188,8 @@ window.addEventListener('load', async function () {
position: 'topleft'
},
onAdd: function () {
var container = L.DomUtil.create('div',
'leaflet-control-title leaflet-bar leaflet-control');
var title = L.DomUtil.create('h1', 'leaflet-bar-part leaflet-bar-part-single', container);
let container = L.DomUtil.create('div', 'leaflet-control-title leaflet-bar leaflet-control'),
title = L.DomUtil.create('h1', 'leaflet-bar-part leaflet-bar-part-single', container);
title.innerHTML = 'Déplacements à 100 km';
return container;
}
......@@ -207,7 +206,7 @@ window.addEventListener('load', async function () {
<ul> \
<li>Cliquer directement sur la carte à l'endroit choisi</ii> \
<li>🔍 Faire une recherche (ville, code postal…)</li> \
${(navigator.geolocation ? '<li>⦿ Rechercher votre position</li>' : '')} \
${(navigator.geolocation ? '<li>⦿ Localiser votre position</li>' : '')} \
<li>♽ Réinitialiser la carte</li> \
<li>✖️ Effacer le dernier point</li> \
</ul> \
......@@ -262,7 +261,7 @@ window.addEventListener('load', async function () {
}
});
if ( navigator.geolocation ) {
if (navigator.geolocation) {
L.Control.CustomPosition = L.Control.extend({
options: {
position: 'topleft'
......@@ -294,7 +293,7 @@ window.addEventListener('load', async function () {
theMap.addControl( new L.Control.mapTitle() );
theMap.addControl( new L.Control.Help() );
if ( navigator.geolocation ) {
if (navigator.geolocation) {
theMap.addControl(new L.Control.CustomPosition());
}
theMap.addControl(new L.Control.CustomClean());
......@@ -306,9 +305,7 @@ window.addEventListener('load', async function () {
async function getJsonAsync( url ) {
return await fetch( url ).then( async (response) => {
if ( response.status == 200 || response.status == 301 )
return await response.json();
else return null;
return [200, 301].indexOf(response.status) !== -1 ? await response.json() : null;
});
}
......@@ -341,22 +338,17 @@ window.addEventListener('load', async function () {
return marker
}
async function createPoint(lat, lng, city, departement = null) {
let marker = createMarker(lat, lng, city),
circle = createCircle(lat, lng),
layer = null
async function createPoint(lat, lng, html, departement = null) {
let layers = [ createMarker(lat, lng, html), createCircle(lat, lng) ],
layer = null,
datas = null;
if (departement != null) {
let datas = await getJsonAsync('geojson/' + departement + '.geojson' );
layer = L.layerGroup([marker, circle, L.geoJSON(datas)]);
layersArray.push(layer);
addToLayerGroup(layer);
}
else {
layer = L.layerGroup([marker, circle])
layersArray.push(layer)
addToLayerGroup(layer)
}
if ( departement ) datas = await getJsonAsync('geojson/' + departement + '.geojson');
if ( datas ) layers.push(L.geoJSON(datas) );
layer = L.layerGroup( layers );
layersArray.push(layer);
addToLayerGroup(layer);
}
function clearLayer() {
......@@ -375,14 +367,14 @@ window.addEventListener('load', async function () {
}
function getReverse( lat, lng ) {
geoCoder.reverse({ 'lat': lat, 'lng': lng }, theMap.options.crs.scale(18), ( r ) => {
geoCoder.reverse({ 'lat': lat, 'lng': lng }, theMap.options.crs.scale(20), ( r ) => {
let address = r[0] ? r[0].properties.address : undefined,
html = r[0] ? (r[0].html || '') : '';
if ( address != undefined && address.country == 'France' ) {
let cp = address.state == 'Corse' ? '20' : (address.postcode ? address.postcode.substring(0, 2) : null);
if (cp == '97') cp = address.postcode.substring(0, 3);
let departementRef = cp == '20' ? (address.county == 'Corse-du-Sud' ? '2A' : '2B') : cp;
if (!departementRef && address.region == 'Nouvelle-Calédonie') departementRef = '98';
if (!departementRef && address.region == 'Nouvelle-Calédonie') departementRef = '988';
createPoint(lat, lng, html, departementRef);
}
});
......
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