Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setVisibleLayers makes all sublayersvisible if group layer id is a part of array #633

Closed
deepal13 opened this issue Nov 18, 2016 · 6 comments

Comments

@deepal13
Copy link

Hello,

I am trying to set visibility of sublayers using setVisibleLayers(). If I pass the group layer id of a sublayer in the array then the TOC works fine(checks group layer and specific sublayer), but the map shows all the sublayers. If I don't pass the group layer,then the group layer is unchecked in TOC and so even if the map looks right (shows only specific sublayer) at first, as soon as I click on any other sublayer, all the sublayers disappear.

Can anyone please help me?

Thanks

@green3g
Copy link
Member

green3g commented Nov 18, 2016

This issue has come up a few times. I've run into it before as well. But first, just to clarify a few things...

  • Are you using the latest version of CMV (are you using the develop branch)? - The develop branch may have some fixes for this issue
  • When you say TOC, you're referring to the CMV widget, LayerControl, correct?

How are you setting the visible layers? If you could share the relevent code in a gist, it would be much easier to offer advice.

Also, when are you setting the visible layers? Is it before or after the LayerControl (and other widgets) load?

@deepal13
Copy link
Author

  • I downloaded CMV from develop branch a month ago.
  • Yes, by TOC I mean LayerControl widget.

I am using local storage to get the layers as JSON array and one of the parameter is visibleLayers which is an array of visible layer IDs.
individualLayerVisibility: function () {
dojox.storage.manager.initialize();
storageProvider = dojox.storage.manager.getProvider();
storageProvider.initialize();
layer1 = storageProvider.get("layers");
var i = 0;
for (var j = 0; j<this.map.layerIds.length ; j++) {
var currentLayer = this.map.getLayer(this.map.layerIds[j]);
if (layer1[i].options.visibleLayers != null) {
currentLayer.setVisibleLayers(layer1[i].options.visibleLayers);
}
i++;
}
},

I am calling this function in LayerControl.js after everything loads.

@deepal13
Copy link
Author

@roemhildtg Can you please help me with this?

@tmcgee
Copy link
Member

tmcgee commented Nov 29, 2016

@deepal13 can you provide a repository with code demonstrating this issue? Probably most helpful to create a stand-alone widget and not modify the core CMV layerControl widget.

@green3g
Copy link
Member

green3g commented Dec 1, 2016

@deepal13 I agree with @tmcgee, I wouldn't modify the core CMV widget since it'll be harder for you to update in the future.

If you write a widget that does this for you, you can use dojo/ready to make sure that other widgets are loaded and "ready" for the layer infos to be set. That is what I've done in the past. Here is an example of how I have used it: https://github.com/roemhildtg/cmv-widgets/blob/master/widgets/AppSettings/_layerMixin.js#L38

@green3g
Copy link
Member

green3g commented Jan 13, 2017

@deepal13 I think the solution here is to exclude group layers from your setVisibleLayers array. You'd need to write some logic to determine which layer id's are group layers. Feel free to reopen this if you need further assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants