I have a LayerGroup in which several ImageOverlays are placed. These are all displayed correctly.
Now I would like to be able to show and hide this LayerGroup within the LayersControl.
My LayerGroup is defined within a function like this:
this.imgOvl.forEach((img) => {
this.imgOvlGp.addLayer(img);
});
If I add this LayerGroup to my existing and working overlays object, I get an error message:
lControl = {
bLayers: {
'Open Street Map': xyz
},
ol: {
'GeoJSONs': xyz,
'Image Overlays': this.imgOvlGp // does not work
}
};
I get this error message in the browser:
MapViewComponent.html:1 ERROR TypeError: Cannot read property 'on' of undefined at NewClass._addLayer (leaflet-src.js:5101) at NewClass.addOverlay (leaflet-src.js:5005) at leaflet-control-layers.wrapper.js:52 at DefaultKeyValueDiffer.push../node_modules/@angular/core/fesm5/core.js.DefaultKeyValueDiffer.forEachAddedItem (core.js:19640) at leaflet-control-layers.wrapper.js:51 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150) at NgZone.push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular (core.js:17248) at LeafletControlLayersWrapper.push../node_modules/@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.wrapper.js.LeafletControlLayersWrapper.applyChanges (leaflet-control-layers.wrapper.js:41) at LeafletControlLayersWrapper.push../node_modules/@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.wrapper.js.LeafletControlLayersWrapper.applyOverlayChanges (leaflet-control-layers.wrapper.js:32)
If I remove the the line..
'Image Overlays': this.imgOvlGp // does not work
..from the ol object, everything is working fine.
Any ideas?
UPDATE
this.overlays = imgOverlays;
this.overLayGroup = new L.LayerGroup().addTo(this.map);
this.overlays.forEach((img) => {
this.overLayGroup.addLayer(img);
});
// If I do it like this, it works..
const overlay = {'Overlays': this.overLayGroup};
L.control.layers(null, overlay).addTo(this.map);