[OpenLayers-Users] Using the same Layer in two maps

Gabriel Vatin gabriel.vatin at mines-paristech.fr
Mon Jul 2 08:00:02 PDT 2012


Hello all,

I have an application developed with Ext / GeoExt / OpenLayers, and two 
OpenLayers maps (within two different tabs). The zooms and centers of 
these two maps objects are synchronised with listeners.
My first map is the main map, with all the layers, gathered in a GeoExt 
layertree : base layers, WMS, WFS... The second map object has only a 
base layer (for now). These two maps aren't displayed at the same time 
side by side, but only the first or the second map; depending on the 
active tab (Ext TabPanel).
When displaying map2, I try to clone a WFS layer from map1, and add it 
to this new map. If the WFS layer is visible in map1 while changing the 
tab, the clone() function creates a new layer which will always be 
visible (I haven't any LayerTree for map2). If I go back to map1 and 
deactivate the WFS layer, the clone layer is still visible in map2. But 
that's not what I want...
If I get it right, the clone() function creates a second layer with the 
same configuration, the same features, etc, than the original layer when 
cloning. So the number of features is doubled.

The second test I made is adding to map2 the existing WFS layer with:

/tab.map.addLayers([_vess_wfs]);/

rather than...

/tab.map.addLayers([_vess_wfs.clone()]);/

With this code, map2 doesn't display this layer, but Firebug says that 
map2 has the layer...

What I want is that my two maps use the same layer, so that the feature 
number isn't doubled within my web browser, and the layer's attributes 
are the same in both maps (visibility, filter, etc...). Does OpenLayers 
offers some functionalities to do so? Can I create two maps with common 
layer objects, without doubling the weight of it?
I thank you for your advice!

Gabriel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120702/0689cec3/attachment-0001.html>


More information about the Users mailing list