A.Andre
A.Andre

Reputation: 29

Leaflet Layer Control not displaying layer

I am trying to add a layercontrol for certain markers. The city marker works fine when I add it to the map. The baseLayers control works properly, and the overlayMaps control is created too. However, the marker does not show when the overlayMaps control is clicked. I'm sure I made a simple error, but I have not been able to detect it.

var city = L.marker([34.26112, -116.8456], {
   icon: L.BeautifyIcon.icon(options)
   }).bindPopup( '<a href="' + "https://en.wikipedia.org/wiki/Big_Bear_Lake,_California" + '" target="_blank">' + "Big Bear Lake" + '</a>');

var citymarkers = L.layerGroup(city);

var overlayMaps = {
    "Cities": citymarkers
   };

L.control.layers(baseLayers, overlayMaps).addTo(map);

Upvotes: 1

Views: 5326

Answers (1)

ghybs
ghybs

Reputation: 53185

L.layerGroup expects an array of layers as optional argument, not a simple layer / marker.

L.layerGroup(<Layer[]> layers?) Create a layer group, optionally given an initial set of layers.

var citymarkers = L.layerGroup([city]); // instead of (city)

Live demo: https://jsfiddle.net/3v7hd2vx/413/

Upvotes: 2

Related Questions