OpenLayers Map addLayer and getLayers methods dealing with custom layer types

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-10 22:49:55

问题


I am extending LayerGroup and TileLayer classes to include an id property that I need to identify a specific layer/group of layers (this also reflects an id of a layer DIV in the DOM).

Example for TileLayer:

export class OperationalLayer extends TileLayer {
    id: String;
    
    constructor(url: string, name: string, id: string) {
        const source = new TileWMS({
            params: {'LAYERS': name},
            url: url,
        });
        super({source: source});

        this.id = id;
    }
}

I also have another class which extends the ol Map class.

What I'd like to do is to somehow have in this extended Map class a getLayers() method that should return my customized (extended) layers with their id information, rather than the default BaseLayers of OpenLayers.

I cannot find a way to do that. I had a look at the source code of both addLayer(), and getLayers() methods and they deal with BaseLayer type of layers, so I guess I need to tweak these methods (overloading them?), but I am not quite sure this is the right path.

Basically, my final aim would be to retrieve my customized layer ids like so:

// here getLayers() should now return my customized layer type
myCustomizedMap.getLayers().forEach(customLyr => console.log(customLyr.id)) // MY ID PROPERTY HERE

来源:https://stackoverflow.com/questions/63246723/openlayers-map-addlayer-and-getlayers-methods-dealing-with-custom-layer-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!