Thursday, 21 December 2017

javascript - Openlayers 4 - get all child layers in a layer group


How can I get all child layers of a given layer group in Openlayers?


I go as far as establishing that a given layer is in fact a group, but then I get stumped:


// Handle visibility control
$('i').on('click', function() {
var layername = $(this).closest('li').data('layerid');

var layer = findBy(map.getLayerGroup(), 'name', layername);
var flagGroup = layer instanceof ol.layer.Group;
if (flagGroup) {
...
}
});

Answer



childLayers = layer.getLayers()


https://openlayers.org/en/latest/apidoc/ol.layer.Group.html#getLayers


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...