问题
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 BaseLayer
s 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