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

Add listener to Layer Control for layer.setVisibleLayers #309

Closed
msamwill opened this issue Nov 20, 2014 · 17 comments
Closed

Add listener to Layer Control for layer.setVisibleLayers #309

msamwill opened this issue Nov 20, 2014 · 17 comments
Assignees
Labels
Milestone

Comments

@msamwill
Copy link

When I make a layer visible/invisible in custom widgit the layer control is still unchecked/checked.

@btfou
Copy link
Contributor

btfou commented Nov 20, 2014

Hey @msamwill I'm aware of this. AGS map service layers (including groups) are in order and use parentLayerId and subLayerIds properties to describe structure. When setting visible layers (requesting different layers) AGS disregards folder ids. The api also ignores the folder ids. LayerControl's dynamic layer control checks the state of the sublayer/folder checkboxes to create an array of layer ids to set layers that reflects said state including folders. So when you set layers with your widget, the layer control has no way to insure proper check states for sublayers/folders.

I would prefer the layer control to be self aware of sublayer changes (as is layer visibility) but that's hard with out dynamic layer keeping track of folder ids. I've thought of a couple solutions. I may just end up using topic to provide a method for others to get and set visible layers so everything syncs up. It does kinda box in devs to a degree.

Thoughts?

@green3g
Copy link
Member

green3g commented Nov 20, 2014

I think that if you listen for dynamic layer visibleLayers changes, and update the parent/sublayer visibility as follows there shouldn't be an issue:

  1. setVisibleLayers is called
  2. Check each id in layer.visibleLayers for parent layers (recursively)
  3. Set checkbox for each parent layer to checked (the sublayers id would not be in the visibleLayers array if their parent wasn't turned on)

I'm not sure if this would work, but I had worked with something similar on a different widget at one point. Thoughts?

Array.forEach(layer.visibleLayers, Lang.hitch(layer, function( id ) {
   setParentIds(id);
}));
function setParentIds( id ) {
                        if (id !== -1 &&
                                layer.visibleLayers !== [-1] &&
                                layer.layerInfos[id].hasOwnProperty('parentLayerId') &&
                                layer.layerInfos[id].parentLayerId !== -1
                                ) {
                            LayerControl[id].set('checked', true);
                            setParentIds( layer.layerInfos[id].parentLayerId);
                        }
                    };

@msamwill
Copy link
Author

The TOC control has this functionality. Looks like the code below allows the TOC to sync with other widgets. If something similar can't be done in the Layer Control then a method that allows us to set the visibility would be the next best thing. Thanks!

this._visLayerHandler = aspect.after(this.rootLayer, "setVisibleLayers", lang.hitch(this, this._onSetVisibleLayers), true);

_onSetVisibleLayers: function(visLayers, doNotRefresh) {
// 2012-07-23:
// set the actual individual layerInfo's visibility after service's setVisibility call.
if (!doNotRefresh) {
array.forEach(this.rootLayer.layerInfos, function(layerInfo) {
if (array.indexOf(visLayers, layerInfo.id) != -1) {
layerInfo.visible = true;
} else if (!layerInfo._subLayerInfos) {
layerInfo.visible = false;
}
});
this._adjustToState();
}
},

@msamwill msamwill reopened this Nov 20, 2014
@msamwill
Copy link
Author

Ops. Clicked the wrong button.

@btfou
Copy link
Contributor

btfou commented Nov 20, 2014

@msamwill @roemhildtg Thanks for poking me on this. Needs fixed.

@btfou btfou added the bug label Nov 20, 2014
@btfou btfou added this to the v1.3.2 milestone Nov 20, 2014
@green3g
Copy link
Member

green3g commented Nov 20, 2014

@btfou sure thing, thanks for the layer control. Its an excellent addition to this

@msamwill
Copy link
Author

Thank you for your time on this, love the new layer control.

@green3g
Copy link
Member

green3g commented Dec 2, 2014

It looks like the latest patch works perfectly when setVisibility is used on a layer, after the app is initialized. You might already be aware of this, but if a widget uses setVisibility on a layer on widget startup, the sublayer controls within sub folders are checked correctly, but their parent folder remains unchecked.

Example:

setVisibleLayers( [1] );

Layer 1
---Folder 1 (0) --not checked but should be
------Sublayer 1 (1) --checked
------Sublayer 2 (2) --not checked

@btfou
Copy link
Contributor

btfou commented Dec 3, 2014

@roemhildtg I see where that would be a problem. If LC isn't initialized and the handler wired up I'm not sure how to work around that.

I'm under the gun a project. If you want to look at this and possibly submit a PR I'd appreciate it.

@green3g
Copy link
Member

green3g commented Dec 3, 2014

Okay, I'll see what I can do.

@msamwill
Copy link
Author

msamwill commented Dec 3, 2014

When you said that the "latest patch works" where you referring to 1.3.1? I couldn't find any other patch. I could live with it not checking the map service but still checking the layer.

In my case I have a map service with layers that are not grouped and initially all layers are off. I created two widgets that allow users to dynamically label and classify these layers. In the widgets I use setVisibleLayers to turn the layers on/off when the user labels or classifies a selected layer. The layer becomes visible in the map but the service is not checked and neither is the layer.

CAMA (Map Service not checked)
BLDG (layer not checked)
LAND (layer not checked)
PARCEL (layer not checked)

@green3g
Copy link
Member

green3g commented Dec 3, 2014

I was referring to the latest patch in the develop branch here: https://github.com/cmv/cmv-app/tree/develop/viewer/js/gis/dijit/LayerControl

@btfou
Copy link
Contributor

btfou commented Dec 3, 2014

@msamwill The master branch is always the latest release. PRs are made against the develop branch. Checkout develop and...what @roemhildtg said.

@msamwill
Copy link
Author

msamwill commented Dec 3, 2014

Thanks!

@btfou btfou closed this as completed Dec 3, 2014
@green3g
Copy link
Member

green3g commented Dec 3, 2014

Just in case this helps anyone, I solved the issue I brought up earlier with the on widget startup. I wrapped the setVisibleLayers function call in a dojo/ready callback using Lang.hitch. It looks something like this:

ready( Lang.hitch(this, function() {
   //for each layer
   layer.setVisibleLayers(...);
}));

@goriliukasbuxton
Copy link

Is this corresponds to the feature where checking the child layer it checks the group layer and the parent layer at the same time?

@green3g
Copy link
Member

green3g commented Dec 21, 2014

This issue was related to a custom widget like the one here https://github.com/roemhildtg/CMV_Widgets/tree/master/AppSettings_Widget that call a layers setVisibleLayers function. I don't think the layer control currently supports the behavior you are referring to,

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

No branches or pull requests

4 participants