I receive the list of layers to use in a json.
To add them, I browse the json and add the layers in the overlaylayers.
Then, I want to materialize the coordinates passed to the page with a marker.
It is displayed correctly but instead of finding the name of the marker “Position” in the layerSwitcher, there is a number.
Below is the code to use.
Any idea?
jsonData.Layers.forEach(layer => {
console.log("2 "+layer.Layer.nom); // Affiche le nom de chaque layer
index = index + 1;
const layerKey = `lyr${index}`; // Créer une clé dynamique
let [unLayer,unNom,unVisible]=createLayer(layer.Layer);
theLayers[index]=unLayer;
theLayersSwitcher[index]= {layer : unLayer, config : {title : unNom,description : unNom,visibility : unVisible}};
theLayersNom[index]=unNom;
theLayersVisible[index]=unVisible;
if (layer.Layer.inUse==1)
{
overlayLayers[layer.Layer.nom] = unLayer; // Stocker la couche dans l'objet}
unLayer.addTo(map);
}
else
{
overlayLayers[layer.Layer.nom] = unLayer; // Stocker la couche dans l'objet
}
});
let PositionMarker = L.marker([<?php echo $_REQUEST["LATITUDE"]?>, <?php echo $_REQUEST["LONGITUDE"]?>], {
title: "La position"
}).addTo(map);
let reversedLayersSwitcher = {};
let keys = Object.keys(theLayersSwitcher).reverse();
index = 0;
for (let i = 0; i < keys.length; i++) {
index += 1;
reversedLayersSwitcher[index] = theLayersSwitcher[keys[i]];
}
let layerSwitcher = L.geoportalControl.LayerSwitcher({ layers: reversedLayersSwitcher });
map.addControl(layerSwitcher);