Commit 23d2c451 authored by Sp3r4z's avatar Sp3r4z
Browse files

[Script] Add small js improvments

Better layerGroup use
parent 4ce67ba7
......@@ -5,23 +5,25 @@ getPostcodeByName = name => {
})
},
createMarker = (lat,lng) => {
layerGroupArray.push( L.marker([lat, lng]) )
addToLayerGroup( L.marker([lat, lng]) )
},
createCircle = (lat,lng) => {
layerGroupArray.push( L.circle([lat,lng], {radius: 100000}) )
addToLayerGroup( L.circle([lat,lng], {radius: 100000}) )
},
showLayer = _ => {
layerGroup = L.layerGroup(layerGroupArray)
layerGroup.addTo(theMap)
addToLayerGroup = (elm) => {
if(layerGroup == null) {
layerGroup = L.layerGroup([elm])
layerGroup.addTo(theMap)
}
else {
layerGroup.addLayer(elm)
}
},
clearLayer = _ => {
theMap.removeLayer(layerGroup)
layerGroupArray = []
layerGroup = null
layerGroup.clearLayers()
}
let theMap = L.map('map').setView([46.415,1.461], 6),
layerGroupArray = [],
layerGroup = null
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
......@@ -51,8 +53,7 @@ L.Control.geocoder({
fetch('geojson/'+departementRef+'.geojson')
.then(response => response.json())
.then(datas => {
layerGroupArray.push( L.geoJSON(datas) )
showLayer()
addToLayerGroup( L.geoJSON(datas) )
})
}
......@@ -62,8 +63,6 @@ L.Control.geocoder({
theMap.on('click', function(e) {
createCircle(e.latlng.lat,e.latlng.lng)
createMarker(e.latlng.lat,e.latlng.lng)
showLayer()
})
const customControl = L.Control.extend({
......
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