TransWikia.com

Get all the Tile layers added to the map using OpenLayers?

Geographic Information Systems Asked on January 5, 2021

I want to get all the Tile layers which are added in the base_map. When I am using map.getLayers() I get the list in the array_. How can I identify all the charts and remove the individual charts.

My process to add the code is:

var layer = new ol.layer.Tile({
     source: new ol.source.TileWMS({ 
     url:url,
     serverType: 'geoserver'
    }) 
});
map.addLayer(layer);

Any suggestions will be highly helpful.

One Answer

You could filter the layers array to return only layers whose source has a getTileGrid method (which would include VectorTile layers)

var tileLayers = map.getlayers().getArray().filter(function(layer){
  return layer.getSource() && layer.getSource().getTileGrid
});

or you could use instanceOf

var tileLayers = map.getlayers().getArray().filter(function(layer){
  return layer instanceOf ol.layer.Tile
});

If you have layer groups you would also need to search those

Correct answer by Mike on January 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP