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

Utilisation Geocoder pour le reverse

parent 4f9e43dd
......@@ -121,19 +121,20 @@ window.addEventListener('load', async function () {
theMap.attributionControl.addAttribution('©2020 <a href="https://framagit.org/Sp3r4z">@Sp3r4z</a> / <a href="https://framagit.org/gegeweb">@gegeweb</a> - <a href="http://www.gnu.org/licenses/agpl-3.0.html">AGPL</a> - <a href="https://framagit.org/gegeweb/100km">Source sur FramaGit</a>');
let geoCoder = new L.Control.Geocoder({
const geoCoder = new L.Control.Geocoder.Nominatim({
reverseQueryParams: {
'accept-language': 'fr'
},
geocodingQueryParams: {
'accept-language': 'fr',
'countrycodes': 'FR'
}
}),
ControlgeoCoder = new L.Control.Geocoder({
defaultMarkGeocode: false,
position: 'topleft',
placeholder: 'Rechercher une ville, une adresse…',
geocoder: new L.Control.Geocoder.Nominatim({
reverseQueryParams: {
'accept-language': 'fr'
},
geocodingQueryParams: {
'accept-language': 'fr',
'countrycodes': 'FR'
}
})
geocoder: geoCoder
})
.on('markgeocode', (e) => {
......@@ -141,7 +142,7 @@ window.addEventListener('load', async function () {
a = e.geocode.properties.address,
postCode = a.postcode,
departementRef = null,
city = e.geocode.properties.address.city != undefined ? e.geocode.properties.address.city : e.geocode.properties.address.village;
city = a.city != undefined ? a.city : a.village;
if (postCode != null) {
departementRef = postCode.substring(0, 2).toUpperCase()
......@@ -153,8 +154,7 @@ window.addEventListener('load', async function () {
createPoint(center.lat, center.lng, city, departementRef);
theMap.setView([center.lat, center.lng], 8);
});
theMap.addControl(geoCoder);
//.addTo(theMap)
theMap.addControl(ControlgeoCoder);
const controlLayer = new L.control.layers(null, null, { collapsed: false });
theMap.addControl(controlLayer);
......@@ -174,7 +174,7 @@ window.addEventListener('load', async function () {
}
theMap.on('click', (e) => {
drawArea( e.latlng.lat, e.latlng.lng )
getReverse( e.latlng.lat, e.latlng.lng )
theMap.setView([e.latlng.lat, e.latlng.lng], 8)
})
......@@ -311,7 +311,7 @@ window.addEventListener('load', async function () {
let lat = p.coords.latitude,
lon = p.coords.longitude;
clearLayer();
drawArea(lat, lon);
getReverse(lat, lon);
theMap.setView([lat, lon], 8)
}
......@@ -368,18 +368,16 @@ window.addEventListener('load', async function () {
}
}
async function drawArea( lat, lon ) {
reverse = `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json&zoom=18&accept-language=fr`;
datas = await getJsonAsync( reverse );
if(datas.address != undefined && datas.address.country == 'France') {
let a = datas.address,
cp = a.state == 'Corse' ? '20' : a.postcode.substring(0, 2);
let departementRef = cp == '20' ? ( a.county == 'Corse-du-Sud' ? '2A' : '2B' ) : cp,
city = datas.address.city != undefined ? datas.address.city : ( datas.address.village || '');
createPoint( lat, lon, city, departementRef );
}
function getReverse( lat, lng ) {
geoCoder.reverse({ 'lat': lat, 'lng': lng }, theMap.options.crs.scale(18), ( r ) => {
let address = r[0].properties.address;
if ( address != undefined && address.country == 'France' ) {
let cp = address.state == 'Corse' ? '20' : address.postcode.substring(0, 2),
departementRef = cp == '20' ? (address.county == 'Corse-du-Sud' ? '2A' : '2B') : cp,
city = address.city != undefined ? address.city : (address.village || '');
createPoint(lat, lng, city, departementRef);
}
});
}
function getPostcodeByName( name ) {
......
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