[Users] Tree node disabling with min/max scale

60 views
Skip to first unread message

Alexandre Dube

unread,
Oct 21, 2010, 9:30:06 AM10/21/10
to GeoEXT Users
Hi,

The LayerSwitcher automatically disables its layer elements when
zooming in/out following the min/max scale values of each layer. Is
that feature available with GeoExt tree nodes as well or do I need to do
that manually ?

Thanks,

--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Users mailing list
Us...@geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users

Andreas Hocevar

unread,
Oct 21, 2010, 9:39:34 AM10/21/10
to Alexandre Dube, GeoEXT Users
Hi,

this would be a useful improvement, but it is not yet implemented - patches welcome!

Regards,
Andreas.

--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

Alexandre Dube

unread,
Oct 21, 2010, 9:55:58 AM10/21/10
to Andreas Hocevar, GeoEXT Users
Got it. I guess it shouldn't be that hard to implement, so I'll give it
a try and report back with a patch + ticket if it goes well.

Thanks,

Alexandre

Matt Priour

unread,
Oct 21, 2010, 10:29:15 AM10/21/10
to Alexandre Dube, Andreas Hocevar, GeoEXT Users
"It's a race" ;)
I am working on implementing that feature today as well.

Matt Priour
Kestrel Computer Consutling


--------------------------------------------------
From: "Alexandre Dube" <ad...@mapgears.com>
Sent: Thursday, October 21, 2010 8:55 AM
To: "Andreas Hocevar" <ahoc...@opengeo.org>
Cc: "GeoEXT Users" <us...@geoext.org>
Subject: Re: [Users] Tree node disabling with min/max scale

Pierre Giraud

unread,
Oct 21, 2010, 10:49:26 AM10/21/10
to Matt Priour, GeoEXT Users, Andreas Hocevar
Hey all,

Eric just told me to have a look at this thread.
Actually, he remembered something I wrote for a project 4 months ago.

So, here's how I managed to deal with min/maxScale in a layer tree.
This code is on application side and it probably doesn't deserves to
be in GeoExt.

var checkInRange = function(node) {
var n = node,
scale = map.getScale(),
minScale = n.attributes.minScale,
maxScale = n.attributes.maxScale;
if ((minScale && minScale > scale) || (maxScale && maxScale < scale)) {
n.getUI().addClass("gx-tree-layer-outofrange");
} else if (minScale || maxScale) {
n.getUI().removeClass("gx-tree-layer-outofrange");
}
};

map.events.on({
"zoomend": function() {
tree.getRootNode().cascade(checkInRange);
}
});

With the css styles :

.x-tree-node .gx-tree-layer-outofrange .x-tree-node-icon {
opacity: 0.5;
}

.gx-tree-layer-outofrange .x-tree-node-anchor span {
color: #777;
}


Pierre (so happy to contribute)

--
Pierre GIRAUD
Géomaticien, Analyste

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 93
Mail : pierre...@camptocamp.com
http://www.camptocamp.com

Andreas Hocevar

unread,
Oct 21, 2010, 10:51:34 AM10/21/10
to Pierre Giraud, GeoEXT Users
This would make a very nice TreePanel plugin.

-Andreas.

--

Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________

Alexandre Dube

unread,
Oct 21, 2010, 10:52:17 AM10/21/10
to Matt Priour, GeoEXT Users, Andreas Hocevar
Hi Matt,

Nah, it's no "race" but I definitively need that feature soon, so I
rather share how I would have done it.

Ideally, I would have made a new "rangechange" event for the
OpenLayers.Layer object and listen to that event to disable/enable the
UI of the node accordingly. Upon creation, a node would be disabled if
the 'inRange' is set to 'false' (unless it's a base layer).

That's pretty much it. Does that make sense ? How about your method ?

Alexandre

Pierre Giraud

unread,
Oct 21, 2010, 10:55:44 AM10/21/10
to Matt Priour, GeoEXT Users, Andreas Hocevar
You must add a listener on TreeNode::expandnode too :

tree.on({
"expandnode": function(node) {
node.eachChild(checkInRange);
}
});

Matt Priour

unread,
Oct 21, 2010, 11:44:50 AM10/21/10
to Alexandre Dube, GeoEXT Users, Andreas Hocevar
My method is very similar to Pierre's.
I have a TreePanel plugin who's init function wires up event listeners to
the map's zoom change event and async node expand event.

it walks the tree and for each gx_layer type node it checks if the
associated layer is in range.
If not then it disables the node and all of its children if any.
It also checks for any node that has all of its children disabled, and if so
it also disables that node.

I should have a working patch with test soon.

Matt Priour

--------------------------------------------------
From: "Alexandre Dube" <ad...@mapgears.com>

Sent: Thursday, October 21, 2010 9:52 AM
To: "Matt Priour" <mpr...@kestrelcomputer.com>
Cc: "Andreas Hocevar" <ahoc...@opengeo.org>; "GeoEXT Users"

Alexandre Dube

unread,
Oct 21, 2010, 11:51:04 AM10/21/10
to Matt Priour, GeoEXT Users, Andreas Hocevar
Hi,

Would it make sense to register a 'visibilitychanged' event inside
the LayerNode object and disable/enable the UI components accordingly ?
Having a plugin is nice but this seems like a feature everyone would
like to have by default. Having to configure an additional plugin for
that could be avoided IMHO.

Using the 'visibilitychanged' event registration method, you trigger
much less events and you don't need to check each node on each map
zoom. Only when a layer would be actually changed the according event
would trigger only once and for the layer only.

What do you think ? What do others think ?

Alexandre

Matt Priour

unread,
Oct 21, 2010, 12:24:56 PM10/21/10
to Alexandre Dube, GeoEXT Users, Andreas Hocevar
The only issue I see with that is that checking / unchecking a layer will
cause it to become visible or not and that in turn fires the
'visibilitychanged' event which would now disable the layer node, preventing
one from turning on that layer again

If you wanted to strictly tie the node disable/enable to the layer's
'visibilitychanged' event then you would need to have some kind of flag that
would prevent the node from disabling itself after a checkbox change event

Matt Priour

--------------------------------------------------
From: "Alexandre Dube" <ad...@mapgears.com>

Sent: Thursday, October 21, 2010 10:51 AM

Alexandre Dube

unread,
Oct 21, 2010, 1:33:22 PM10/21/10
to Matt Priour, GeoEXT Users, Andreas Hocevar
The 'visibilitychanged' event would be used as usual, but for the
disabling/enabling we only need to check the 'inRange' property of the
layer. If it's set to false and it's not a base layer, disable the
node, else enable it. That way, it would prevent the issue you mentioned.

Alexandre

Matt Priour

unread,
Oct 21, 2010, 1:58:18 PM10/21/10
to Alexandre Dube, GeoEXT Users, Andreas Hocevar
Good plan, I like that idea.
Matt Priour

--------------------------------------------------
From: "Alexandre Dube" <ad...@mapgears.com>

Sent: Thursday, October 21, 2010 12:33 PM

Alexandre Dube

unread,
Oct 21, 2010, 2:14:11 PM10/21/10
to Matt Priour, GeoEXT Users, Andreas Hocevar
Matt,

Like I mentioned, I would need this feature rather quickly. Do you
wish to do the fix ? If not, I'm willing to make the changes (with the
appropriate ticket + patch).

Andreas, do you agree with the change or would you rather see it as a
plugin as Pierre and Matt proposed ?

Alexandre


On 10-10-21 01:58 PM, Matt Priour wrote:
> Good plan, I like that idea.
> Matt Priour
>
> --------------------------------------------------
> From: "Alexandre Dube" <ad...@mapgears.com>
> Sent: Thursday, October 21, 2010 12:33 PM
> To: "Matt Priour" <mpr...@kestrelcomputer.com>
> Cc: "Andreas Hocevar" <ahoc...@opengeo.org>; "GeoEXT Users"
> <us...@geoext.org>
> Subject: Re: [Users] Tree node disabling with min/max scale
>
>> The 'visibilitychanged' event would be used as usual, but for the
>> disabling/enabling we only need to check the 'inRange' property of
>> the layer. If it's set to false and it's not a base layer, disable
>> the node, else enable it. That way, it would prevent the issue you
>> mentioned.
>>
>> Alexandre
>>

--

Eric Lemoine

unread,
Oct 21, 2010, 3:14:59 PM10/21/10
to Alexandre Dube, GeoEXT Users, Andreas Hocevar
On Thu, Oct 21, 2010 at 8:14 PM, Alexandre Dube <ad...@mapgears.com> wrote:
> Matt,
>
>   Like I mentioned, I would need this feature rather quickly.  Do you
> wish to do the fix ?  If not, I'm willing to make the changes (with the
> appropriate ticket + patch).
>
>   Andreas, do you agree with the change or would you rather see it as a
> plugin as Pierre and Matt proposed ?

A plugin would be great.


--
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.l...@camptocamp.com
http://www.camptocamp.com

Andreas Hocevar

unread,
Oct 21, 2010, 3:54:21 PM10/21/10
to Eric Lemoine, GeoEXT Users
Hi,

I think the approach with the visibilitychanged event has less overhead. And if people prefer a plugin, it could also be combined with a plugin approach: whenever a layer node is added to the tree, the plugin could register the event.

But even if it's going to be default behavior, it can easily be disabled by making the css class for the disabled layer configurable.

Having said that, I don't have a strong opinion on plugin or not, but I do like the visibilitychanged approach better.

Regards,
Andreas.

--

Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________

Pierre Giraud

unread,
Oct 22, 2010, 3:43:12 AM10/22/10
to Andreas Hocevar, GeoEXT Users
Hi all,

Sorry about that but I forgot to mention that there's something
special with the code I proposed.

In my case, I had to deal with LayerParamNodes which are not tightly
bound to a layer but to a WMS sub-layer. I couldn't listen to
"visibilitychanged" because the OL Layer visibibility doesn't change
actually.
Code is better than talks so imagine the following tree (manual) configuration:

{
text: "Tourisme et vie local",
children: [{
text: "Tourisme",
children: [{
nodeType: "gx_layerparam",
text: "Piste de ski",
item: "pistes_ski",
maxScale: 50000
}, {
nodeType: "gx_layerparam",
text: "Piste de ski de fond",
item: "pistes_fond"
}]
}]
}

In this example, the maxScale value is set adequately to the
configuration in the mapfile. This is a bit specific because it is
configured manually, but we could imagine a way to get this
information by reading Capabilities.

So, the goal is probably not the same as the one Alexandre or Matt are
trying to reach.

Regards,
Pierre

--
Pierre GIRAUD
Géomaticien, Analyste

Camptocamp France SAS


Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 93
Mail : pierre...@camptocamp.com

Alexandre Dube

unread,
Oct 22, 2010, 12:49:35 PM10/22/10
to us...@geoext.org
Hi Pierre,

In a way, the needs are the same. We all want to have nodes
reflecting to layers or paramlayers to disable when out of specific scales.

When dealing with LayerNodes, it's okay ( and I'd say recommended )
to use the OpenLayers.Layer 'inRange' property that is already
calculated from many properties such as minScale, maxScale,
minResolution, maxResolutions, resolutions, etc. It would be kinda
'duplicate' to define that information in the layertree nodes as well.

For the paramnodes, that's an other story. "param layers" are
specific to the OpenLayers.Layer.WMS layer object and there is no
"min/max scale/resolution" information per param layer in it. Unless
there a plans to integrate that kind of information in OpenLayers, I
think the best approach would be to use a plugin.

So in brief, for LayerNodes it could be dealt by default by the
"visibilitychanged" event and "inRange" layer property inside the class
itself and for ParamNodes we could use a plugin. How about it ?

Alexandre


--
Alexandre Dubé
Mapgears
www.mapgears.com

Matt Priour

unread,
Oct 22, 2010, 2:53:54 PM10/22/10
to Alexandre Dube, us...@geoext.org
Added a patch to ticket #235 [1]
I will add tests later tonight, my manual test on several layer types worked
as expected. It turns out that the layer's 'visibilitychanged' event never
fires when the layer goes out of range. This actually makes sense when you
consider that if OL did actually turn off the layer when it went out of
range, then it would have to know to turn it back on when it came back in
range. Rather, OL just stops drawing the out of range layers if
calculateInRange() returns false.

It appears that OL updates the inRange property for all layers (visible or
not) after the map's moveend event but before it actually does any
redrawing. I attach a map moveend listener for each LayerNode that could
reasonably be auto-disabled. I also evaluate the inRange property or result
of the calculateInRange function before the layer node is rendered.

[1] http://trac.geoext.org/attachment/ticket/235/autoDisableLayerNode.patch

Matt Priour
Kestrel Computer Consulting

--------------------------------------------------
From: "Alexandre Dube" <ad...@mapgears.com>

Sent: Friday, October 22, 2010 11:49 AM
To: <us...@geoext.org>


Subject: Re: [Users] Tree node disabling with min/max scale

> Hi Pierre,

joseluisquevedo

unread,
Mar 19, 2014, 8:51:36 AM3/19/14
to geoext-use...@googlegroups.com, Matt Priour, GeoEXT Users, Andreas Hocevar, pierre...@camptocamp.com
Hola pierre estoy en problemas me poidrias explicar como implemento layercontainer.js para mostrar las capas en arbol. muchas gracias
Reply all
Reply to author
Forward
0 new messages