I have multiple layers created depending on a category, they show on the map but now I wish to bind a pop-up on them showing some properties like "Nom de la structure" etc
Here is a dummy code from my Json
{
"type": "Feature",
"properties": {
"Nom de la structure": "Stade Olympique Maritime Boulonnais",
"Nom": "Monteuuis Pierre",
"Adresse": "4 rue du Colonel de l'Esperance",
"category": "CVGd",
"Exemple 1": "Organisation d'un match de Basket ball",
"Exemple 2": "Gestion des partenaires commerciaux",
"Exemple 3": "Gestion de la communication",
},
"geometry": {
"type": "Point",
"coordinates": [1.5986012, 50.7202296]
}
and here is my JS file:
$.getScript("CoordinatesPdC.js");
$(document).ready(function() {
// Create an object to keep track of active layers and each layer with its markers
const layers = {
active: [],
APEnEvSa: new L.LayerGroup()
};
// create the map
var map = L.map('map').setView([50.5703007,2.4328028], 9);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, '
}).addTo(map);
// based on the category assign a marker to the layer
layers.APEnEvSa = L.geoJson(internships, {
filter: function(feature, layer) {
return (feature.properties.category === "APEnEvSa");
}
}) //repeat for each category
// register click event
$('button').on('click', function(e) {
const layerName = e.target.name;
// if a layer is already active, remove it from the map and the active array
if (layers.active.includes(layerName)) {
layers.active = layers.active.filter(layer => layer !== layerName);
map.removeLayer(layers[layerName]);
} else {
// add the layer to the map and to the active array
layers.active.push(layerName);
layers[layerName].addTo(map);
}
});
});