1

I am developing an OpenLayers 3 web application were I would like to incorporate multiple layer trees. Instead of manually adding each layer to a layer tree I would like to do it using the method below.

I have this JSFiddle set up that it has a map with multiple layers and one Layer Tree. I would like to duplicate the layer tree multiple (4) times and have a parameter (as per the one in each layer of the example) that then assigns a layer to different layer trees.

I imagine it involves an extra if statement when building the layer tree at the bottom of the code, similar to the slider option already in there, but I don't seem to be able to make it work.

The solution should also ideally remove the "all layers" group at the top of each Layer Tree.

  • I did something similar in ESRI using dictionary. I queried the layers from my server, each map service got a a particular key (name of service) and the value for that key was the layer information. Once that was all one collecting (3 map services), I would iterate through them, each layer in the individual map services would create a list, then each list would separately be added to a placeholder node I had.. Are you trying to do something like that? – Branco Aug 28 '15 at 13:59
1

When you're declaring your layers you can simply add a 'layerType' attribute from which you can later use to add and remove layers as a group.

var birmingham = new ol.Feature({
    geometry: new ol.geom.Point(ol.proj.transform([-1.900878, 51.483952], 'EPSG:4326', 'EPSG:3857')),
    name: 'Birmingham',
    layerType: 'layerOne'
});

When declaring your vector sources you can then loop through your layers and push layers into a vector source based on that defined layerType attribute.

Hope that helps.

  • I understand the first bit about assigning the attribute to the layer but then how would the second part of your example work? Would it be possible to fork my JSFiddle? Thanks @dylan – Joshua Dickerson Sep 17 '15 at 7:36
  • Looking at this again @dylan, that would only put certain "cities" into different vector sources depending on the layerType. What i want to do is when the 'buildLayerTree' is executed it queries which layerType a layer is and only uses it if it's the correct layer tree – Joshua Dickerson Sep 17 '15 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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