简体   繁体   中英

How to expand layer group by code OpenLayers3

My question is simple: I need expand a layer group, just like the event clic in the "+" button but programmatically.

I have a group in this image

组

I need expand the group like this

集团扩大

How can I do this programmatically in Openlayers3. Ty for your help.

On Openlayers site, under examples section you have one fine example how can one implement similar behavior.

http://openlayers.org/en/latest/examples/layer-group.html

Also, something similar is explained here , but keep in mind that this example uses 3.4.0 version.

You can do something like this for each group

 var Group1 = new ol.layer.Group({ title: 'Group1', openInLayerSwitcher: false, visible: false, layers:[ new ol.layer.Group({ title: 'SubGroup1', openInLayerSwitcher: false, visible: false, layers: Object.values(G1) }), new ol.layer.Group({ title: 'SubGroup2', openInLayerSwitcher: false, visible: false, layers: Object.values(G2) })] }); G1['Layer1'] = new ol.layer.Tile({ title: "Layer1 in Group 1", baseLayer: false, visible: false, source: new ol.source.XYZ({ projection: 'EPSG:4326', wrapX: false, url: '/{z}/{x}/{-y}.png'//depends on the layer type }) }); 

And so on..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM