我有一个放置了几个 ImageOverlays 的 LayerGroup。这些都显示正确。
现在我希望能够在 LayersControl 中显示和隐藏这个 LayerGroup。
我的 LayerGroup 是在这样的函数中定义的:
this.imgOvl.forEach((img) => {
this.imgOvlGp.addLayer(img);
});
如果我将此 LayerGroup 添加到我现有的和工作的叠加对象中,我会收到一条错误消息:
lControl = {
bLayers: {
'Open Street Map': xyz
},
ol: {
'GeoJSONs': xyz,
'Image Overlays': this.imgOvlGp // does not work
}
};
我在浏览器中收到此错误消息:
MapViewComponent.html:1 错误类型错误:无法在 Leaflet-control-layers.wrapper 的 NewClass.addOverlay (leaflet-src.js:5005) 的 NewClass._addLayer (leaflet-src.js:5101) 处读取未定义的属性“on” .js:52 at DefaultKeyValueDiffer.push../node_modules/@angular/core/fesm5/core.js.DefaultKeyValueDiffer.forEachAddedItem (core.js:19640) 位于 Leaflet-control-layers.wrapper.js:51 位于 ZoneDelegate.push ../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391) 在 Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone. js:150) 在 NgZone.push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular (core.js:17248) 在 LeafletControlLayersWrapper.push../node_modules/@asymmetrik/ngx-leaflet/ dist/leaflet/layers/control/leaflet-control-layers.wrapper.js。LeafletControlLayersWrapper.push../node_modules/@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.wrapper.js 的 LeafletControlLayersWrapper.applyChanges (leaflet-control-layers.wrapper.js:41)。 LeafletControlLayersWrapper.applyOverlayChanges (leaflet-control-layers.wrapper.js:32)
如果我删除线..
'Image Overlays': this.imgOvlGp // does not work
..从 ol 对象开始,一切正常。
有任何想法吗?
更新
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);