2

I cobbled together a code where I can print the features as a popup and wanted to make the objects on and off

var baseMaps = {
  "Wikimedia-Map": Wikimedia,
  "GrayCanvas-Map": Esri_WorldGrayCanvas,
  "Neighbourhood": Thunderforest_Neighbourhood,
  "WaterColor-Map": Stamen_Watercolor
};

var controlLayers = L.control.layers(baseMaps).addTo(map);

for (var i = 0; i < markers.length; i++) {
   var geojsonLayer = L.marker( [markers[i].lat, markers[i].lng] )
      .bindPopup('<a href="' + markers[i].url + '" target="_blank">' + markers[i].name + '</a>'+
                    '<br/>Adresse: ' + markers[i].adresse +
                        '<br/>Ort: ' + markers[i].ort +
                            '<br/>Telefon: ' + markers[i].telefonnum +
                                '<br/>E-Mail: ' + markers[i].email +
                                    '<br/>Kategorie: ' + markers[i].kategorie + 
                                        '<br/>Art: ' + markers[i].art +
                                            '<br/>Bemerkung: ' + markers[i].bemerkung)


     .addTo(map);

    controlLayers.addOverlay(geojsonLayer, 'all');  
}

With this code, I found that this code outputs every single object as a clickable field (see screenshot)

enter image description here

Does anyone have any idea what code would be necessary to bring the objects together to a selectable group?

0

First add all markers to group layer and then add this group layer to map as overlay:

var markerLayer = L.layerGroup();

for ( var i=0; i < markers.length; i++ ) {
   L.marker( [markers[i].lat, markers[i].lng] )
      .bindPopup('<a href="' + markers[i].url + '" target="_blank">' + markers[i].name + '</a>'+
                    '<br/>Adresse: ' + markers[i].adresse +
                        '<br/>Ort: ' + markers[i].ort +
                            '<br/>Telefon: ' + markers[i].telefonnum +
                                '<br/>E-Mail: ' + markers[i].email +
                                    '<br/>Kategorie: ' + markers[i].kategorie + 
                                        '<br/>Art: ' + markers[i].art +
                                            '<br/>Bemerkung: ' + markers[i].bemerkung)
     .addTo(markerLayer);
}

controlLayers.addOverlay(markerLayer);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.