Discussion:
[OpenLayers-Users] Question on having multiple layers
Ali Khan
2007-08-08 15:26:13 UTC
Permalink
Hey, presently we're developing a system that will have MANY layers
we're talking 20-50.

I know in OpenLayers you need to setup a name etc for each layer. I was
thinking using a loop to output each layer (the basic data ie layer name
etc is stored in a backend database). Still when somoene opens up the
navigation tab though it can become quite long.

Is there anyway one can make a select box on the page and on change have
it reference the appropriate layer to show in OpenLayers?
Also for each layer we want to have a seperate getFeatureinfo query as
each layer contains different data. How do we do this? can we do
layer.events.register instead of map.events.register for instance so
that each layer has its own on click event?


Thanks.
Gregor Mosheh
2007-08-08 15:43:35 UTC
Permalink
Post by Ali Khan
Is there anyway one can make a select box on the page and on change have
it reference the appropriate layer to show in OpenLayers?
Sure. While loading your layers in a loop (that's how I like doing it)
store the layers into an associative array so they can be referenced by
name. Give the HTML checkboxes a onClick handler to fetch and layer and
toggle it.

Should look something like this:

<input type="checkbox" name="toggle[]" value="Oceans"
onClick="toggleLayer('Oceans');"/> Oceans

<script>
function toggleLayer(layername) {
var l = ALL_LAYERS[layername]; if (!l) return;
l.setVisibility(! l.getVisibility() );
}
</script>
Post by Ali Khan
Also for each layer we want to have a seperate getFeatureinfo query as
each layer contains different data. How do we do this? can we do
layer.events.register instead of map.events.register for instance so
that each layer has its own on click event?
I experimented with that a month ago using WFS layers, and found that
only one layer can use click-to-query at a time. I may be wrong about
that...
--
Gregor Mosheh / Greg Allensworth
System Administrator, HostGIS cartographic development & hosting services
http://www.HostGIS.com/

"Remember that no one cares if you can back up,
only if you can restore." - AMANDA
Ali Khan
2007-08-08 16:04:41 UTC
Permalink
Thanks for the info...For the second part though about multiple event
clicks..When one chooses a new layer to display, can the javascript
update the url being used for the query some how to reflect the
appropriate layer?
Post by Gregor Mosheh
Post by Ali Khan
Is there anyway one can make a select box on the page and on change
have it reference the appropriate layer to show in OpenLayers?
Sure. While loading your layers in a loop (that's how I like doing it)
store the layers into an associative array so they can be referenced
by name. Give the HTML checkboxes a onClick handler to fetch and layer
and toggle it.
<input type="checkbox" name="toggle[]" value="Oceans"
onClick="toggleLayer('Oceans');"/> Oceans
<script>
function toggleLayer(layername) {
var l = ALL_LAYERS[layername]; if (!l) return;
l.setVisibility(! l.getVisibility() );
}
</script>
Post by Ali Khan
Also for each layer we want to have a seperate getFeatureinfo query
as each layer contains different data. How do we do this? can we do
layer.events.register instead of map.events.register for instance so
that each layer has its own on click event?
I experimented with that a month ago using WFS layers, and found that
only one layer can use click-to-query at a time. I may be wrong about
that...
Lee Keel
2007-08-08 16:05:19 UTC
Permalink
-----Original Message-----
On Behalf Of Ali Khan
Is there anyway one can make a select box on the page and on change have
it reference the appropriate layer to show in OpenLayers?
Also for each layer we want to have a seperate getFeatureinfo query as
each layer contains different data. How do we do this? can we do
layer.events.register instead of map.events.register for instance so
that each layer has its own on click event?
What we are currently doing is catching the map click and getting a list of
all visible layers and layers that are in range. Something like:

var layers = "";
for (var i = 0; i < map.layers.length; i++){
map.layers[i].inRange + " - " + map.layers[i].displayOutsideMaxExtent);
if (map.layers[i].visibility == true && map.layers[i].inRange == true ){
if (layers == "") layers = map.layers[i].name;
else layers = layers + ", " + map.layers[i].name;
}
}

Then, we have queries in the configuration file that are related to each
available layer so that we can make spatial queries to the appropriate
tables at the given XY (of course + some buffer).
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Ali Khan
2007-08-08 16:11:43 UTC
Permalink
Thanks for the help from all parties involved hopefully i'll be able to
get my map system up and running.
Post by Lee Keel
-----Original Message-----
On Behalf Of Ali Khan
Is there anyway one can make a select box on the page and on change have
it reference the appropriate layer to show in OpenLayers?
Also for each layer we want to have a seperate getFeatureinfo query as
each layer contains different data. How do we do this? can we do
layer.events.register instead of map.events.register for instance so
that each layer has its own on click event?
What we are currently doing is catching the map click and getting a list of
var layers = "";
for (var i = 0; i < map.layers.length; i++){
map.layers[i].inRange + " - " + map.layers[i].displayOutsideMaxExtent);
if (map.layers[i].visibility == true && map.layers[i].inRange == true ){
if (layers == "") layers = map.layers[i].name;
else layers = layers + ", " + map.layers[i].name;
}
}
Then, we have queries in the configuration file that are related to each
available layer so that we can make spatial queries to the appropriate
tables at the given XY (of course + some buffer).
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Eric Lemoine
2007-08-08 18:36:23 UTC
Permalink
Hi Ali,
Post by Ali Khan
Hey, presently we're developing a system that will have MANY layers
we're talking 20-50.
I know in OpenLayers you need to setup a name etc for each layer. I was
thinking using a loop to output each layer (the basic data ie layer name
etc is stored in a backend database). Still when somoene opens up the
navigation tab though it can become quite long.
Don't use one OpenLayers layer per server layer, it'll result in a
performance disaster! Group your layers into as few OpenLayer layers
as possible. For example, if you use WMS, group your layers using
OpenLayers.Layer.WMS's 'layers' param, and switch from one layer to
another using the mergeNewParams() method.

Hope this helps...

--
Eric
Ali Khan
2007-08-08 19:12:03 UTC
Permalink
I'm planning to use the layers param, is there any way to switch the
click event to go to a specific url for a specific layer doing this though?
Post by Eric Lemoine
Hi Ali,
Post by Ali Khan
Hey, presently we're developing a system that will have MANY layers
we're talking 20-50.
I know in OpenLayers you need to setup a name etc for each layer. I was
thinking using a loop to output each layer (the basic data ie layer name
etc is stored in a backend database). Still when somoene opens up the
navigation tab though it can become quite long.
Don't use one OpenLayers layer per server layer, it'll result in a
performance disaster! Group your layers into as few OpenLayer layers
as possible. For example, if you use WMS, group your layers using
OpenLayers.Layer.WMS's 'layers' param, and switch from one layer to
another using the mergeNewParams() method.
Hope this helps...
--
Eric
Eric Lemoine
2007-08-08 19:17:18 UTC
Permalink
Post by Ali Khan
I'm planning to use the layers param, is there any way to switch the
click event to go to a specific url for a specific layer doing this though?
You can register your own "click on map" callback using something like:

map.events.register('click', map, yourOwnClickCallback);

Does that answer your question?
--
Eric
Ali Khan
2007-08-08 19:41:36 UTC
Permalink
some what. This much I knew already but I was hoping to grab the layer
visible as well so I knew which layer to query data for.
Post by Eric Lemoine
Post by Ali Khan
I'm planning to use the layers param, is there any way to switch the
click event to go to a specific url for a specific layer doing this though?
map.events.register('click', map, yourOwnClickCallback);
Does that answer your question?
--
Eric
Gregor Mosheh
2007-08-08 19:47:26 UTC
Permalink
Post by Ali Khan
some what. This much I knew already but I was hoping to grab the layer
visible as well so I knew which layer to query data for.
I suppose you'd want to iterate through the list of all layers and stop
at the first that's both visible and also queryable. Should be simple,
if "queryable" can be defined in calculable terms. (the object's class?
some custom attribute you stick in there? all of them?)
--
Gregor Mosheh / Greg Allensworth
System Administrator, HostGIS cartographic development & hosting services
http://www.HostGIS.com/

"Remember that no one cares if you can back up,
only if you can restore." - AMANDA
bradleyspencer
2007-08-08 22:25:19 UTC
Permalink
Ali,

I have done this is what I would call clumsy javascript.

Have a look at the demo at http://ozdemo.getmyip.com/interopDemo.html

To do a getFeatuerInfo (GFI) the user needs to make a layer 'active' and
then I disable all mouse events and register a new doubleclick event for the
GFI request.

The problem I have not solved yet is that once I disable all mouse events I
lose things like doubleclick zoom-recenter and I am unable to reactivate
them after the user makes a subsequent layer active that does not have GFI
capability (i). Maybe you can help me?

Cheers,

Brad....


-----Original Message-----
From: Ali Khan [mailto:***@unfpa.org]
Sent: Thursday, 9 August 2007 5:42 AM
To: Eric Lemoine
Cc: ***@openlayers.org
Subject: Re: [OpenLayers-Users] Question on having multiple layers

some what. This much I knew already but I was hoping to grab the layer
visible as well so I knew which layer to query data for.
Post by Eric Lemoine
Post by Ali Khan
I'm planning to use the layers param, is there any way to switch the
click event to go to a specific url for a specific layer doing this
though?
Post by Eric Lemoine
map.events.register('click', map, yourOwnClickCallback);
Does that answer your question?
--
Eric
Continue reading on narkive:
Loading...