1

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

Group

I need expand the group like this

Group expanded

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

2 Answers 2

1

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..

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.