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

collapse Layers Control & copyright

parent f66cb395
window.addEventListener('load', async function () {
/* @preserve
* 100km
* https://framagit.org/gegeweb/100km
*
* (c) 2020 @Sp3r4z (https://framagit.org/Sp3r4z)
* (c) 2020 @gegeweb (https://framagit.org/gegeweb)
*
* @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-later
*/
window.addEventListener('load', async () => {
const center = [46.415, 1.461],
zoom = 6,
metropole = await getJsonAsync('geojson/metropole-et-outre-mer.geojson'),
......@@ -121,8 +131,9 @@ window.addEventListener('load', async function () {
layerGroup.addTo(theMap);
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>');
const geoCoder = new L.Control.Geocoder.Nominatim({
const controlLayer = new L.control.layers(null, null, { collapsed: true }),
geoCoder = new L.Control.Geocoder.Nominatim({
reverseQueryParams: {
'accept-language': 'fr,fr-FR'
},
......@@ -131,10 +142,12 @@ window.addEventListener('load', async function () {
'countrycodes': 'FR'
}
}),
ControlgeoCoder = new L.Control.Geocoder({
controlGeocoder = new L.Control.Geocoder({
defaultMarkGeocode: false,
position: 'topleft',
placeholder: 'Rechercher une ville, une adresse…',
showResultIcons: true,
iconLabel: 'Localiser une adresse',
geocoder: geoCoder
})
.on('markgeocode', (e) => {
......@@ -147,10 +160,6 @@ window.addEventListener('load', async function () {
createPoint(center.lat, center.lng, html, dpt);
theMap.setView([center.lat, center.lng], 8);
});
theMap.addControl(ControlgeoCoder);
const controlLayer = new L.control.layers(null, null, { collapsed: false });
theMap.addControl(controlLayer);
for (let i = 0; i < baseLayers.length; i++) {
let m = baseLayers[i];
......@@ -162,14 +171,14 @@ window.addEventListener('load', async function () {
for (let i = 0; i < overlayLayers.length; i++) {
let m = overlayLayers[i];
let l = new L.TileLayer(m.url, m.options);
controlLayer.addOverlay(l, m.name)
controlLayer.addOverlay(l, m.name);
theMap.addLayer(l);
}
theMap.on('click', (e) => {
getReverse( e.latlng.lat, e.latlng.lng )
theMap.setView([e.latlng.lat, e.latlng.lng], 8)
})
getReverse( e.latlng.lat, e.latlng.lng );
theMap.setView([e.latlng.lat, e.latlng.lng], 8);
});
L.Control.mapTitle = L.Control.extend({
options: {
......@@ -197,9 +206,7 @@ window.addEventListener('load', async function () {
${(navigator.geolocation ? '<li>⦿ Localiser votre position</li>' : '')} \
<li>♽ Réinitialiser la carte</li> \
<li>✖️ Effacer le dernier point</li> \
</ul> \
<p>Déplacements dans un rayon de 100 km autour du domicile.<br> \
Plus de 100 km autorisé uniquement dans le même département.</p>`;
</ul>`;
return container;
}
});
......@@ -279,6 +286,8 @@ window.addEventListener('load', async function () {
})
}
controlLayer.addTo( theMap );
controlGeocoder.addTo( theMap );
theMap.addControl( new L.Control.mapTitle() );
theMap.addControl( new L.Control.Help() );
if (navigator.geolocation) {
......@@ -287,9 +296,11 @@ window.addEventListener('load', async function () {
theMap.addControl(new L.Control.CustomClean());
theMap.addControl(new L.Control.CustomPoint());
/* -----------
Fonctions
------------ */
/*
* ---------
* Functions
* ---------
*/
async function getJsonAsync( url ) {
return await fetch( url ).then( async (response) => {
......@@ -302,7 +313,7 @@ window.addEventListener('load', async function () {
lon = p.coords.longitude;
clearLayer();
getReverse(lat, lon);
theMap.setView([lat, lon], 8)
theMap.setView([lat, lon], 8);
}
function createCircle( lat, lng ) {
......@@ -314,16 +325,17 @@ window.addEventListener('load', async function () {
metropoleElements.forEach((e, index) => {
let feat = { 'type': 'Polygon', 'coordinates': metropoleElements[index] },
tmpCircle = turf.intersect(turfCircle, feat);
shapeArray.push(L.geoJSON(tmpCircle))
shapeArray.push(L.geoJSON(tmpCircle));
})
return L.layerGroup(shapeArray)
return L.layerGroup(shapeArray);
}
function createMarker (lat, lng, html) {
let marker = L.marker([lat, lng]), precision = 10000
let marker = L.marker([lat, lng]),
precision = 10000;
marker.bindPopup(`<p>${html}<br><em>[ ${Math.round(lat * precision) / precision}, ${Math.round(lng * precision) / precision} ]</em></p>`).openPopup();
return marker
return marker;
}
async function createPoint(lat, lng, html, departement = null) {
......@@ -340,17 +352,17 @@ window.addEventListener('load', async function () {
}
function clearLayer() {
layerGroup.clearLayers()
layerGroup.clearLayers();
}
function addToLayerGroup( elm ) {
layerGroup.addLayer( elm )
layerGroup.addLayer( elm );
}
function removeLastPoint() {
if (layersArray.length > 0) {
let layer = layersArray.pop()
layerGroup.removeLayer(layer)
let layer = layersArray.pop();
layerGroup.removeLayer(layer);
}
}
......@@ -382,7 +394,8 @@ window.addEventListener('load', async function () {
cp = (cp == '97' || cp == '98') ? a.postcode.substring(0, 3) : cp;
if ( !cp ) {
if ( a.state == 'Corse' ) cp = '20';
if ( a.state == 'Corse' )
cp = '20';
else if ( a.region && a.region == 'Nouvelle-Calédonie' )
cp = getPostcodeByName(a.region).code;
else if ( a.county )
......@@ -396,6 +409,7 @@ window.addEventListener('load', async function () {
}
function initView() {
theMap.setView( center, zoom )
theMap.setView( center, zoom );
}
});
// @license-end
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