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

Fonction pour remonter n° dpt

parent 150b951f
......@@ -139,24 +139,12 @@ window.addEventListener('load', async function () {
})
.on('markgeocode', (e) => {
let center = e.geocode.center,
a = e.geocode.properties.address,
postCode = a.postcode,
departementRef = null;
if (postCode != null) {
let cp = postCode.substring(0, 2).toUpperCase();
departementRef = ( cp == '97' || cp == '98' ) ? postCode.substring(0, 3).toUpperCase() : cp;
}
else if (a.region == 'Nouvelle-Calédonie') {
departementRef = '988'
}
else if (a.county != null) {
departementRef = getPostcodeByName(a.county)[0].code
}
else if (a.state != null) {
departementRef = getPostcodeByName(a.state)[0].code
}
createPoint(center.lat, center.lng, e.geocode.html, departementRef);
html = e.geocode.html || '',
address = e.geocode.properties ? e.geocode.properties.address : null,
dpt = null;
if ( address ) dpt = getDepartementRef( address );
createPoint(center.lat, center.lng, html, dpt);
theMap.setView([center.lat, center.lng], 8);
});
theMap.addControl(ControlgeoCoder);
......@@ -368,22 +356,43 @@ window.addEventListener('load', async function () {
function getReverse( lat, lng ) {
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 == '98') 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 = '988';
createPoint(lat, lng, html, departementRef);
}
r = r[0] || null;
let address = r && r.properties ? r.properties.address : null,
html = r ? ( r.html || '' ) : '',
dpt = null;
if ( address ) dpt = getDepartementRef( address );
createPoint(lat, lng, html, dpt);
});
}
function getPostcodeByName( name ) {
return departements.filter( dep => {
return dep.nom == name
});
return dep.nom == name;
})[0];
}
function getDepartementRef( a = null ) {
if (!a || a.country != 'France' ) return null;
let cp = a.postcode ? a.postcode.substring(0, 2).toUpperCase() : null,
dpt = null;
cp = (cp == '97' || cp == '98') ? a.postcode.substring(0, 3) : cp;
if ( !cp ) {
if ( a.state == 'Corse' ) cp = '20';
else if ( a.region && a.region == 'Nouvelle-Calédonie' )
cp = getPostcodeByName(a.region).code;
else if ( a.county )
cp = getPostcodeByName(a.county).code;
else if ( a.state )
cp = getPostcodeByName(a.state).code;
}
dpt = cp == '20' ? (a.county == 'Corse-du-Sud' ? '2A' : '2B') : cp;
return dpt;
}
function initView() {
......
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