[OpenLayers-Users] Layer.clone()
Matt Williamson
matthewdw at gmail.com
Sat Apr 26 20:06:53 EDT 2008
Hello list,
Questions about Layer.clone(): Is it supposed to work? I'm having
major problems with it. My use-case is, I have a set of pre-defined
layers in an included .js file, but I want users to be able to add
multiple maps to a page, two or more of which may use the same layer.
So, I'm trying to Layer.clone() a copy of each layer each time it gets
put into a map. Couple of problems I've encountered so far:
1. It looks like the clone method is supposed to take either a null
argument (which will return a clone of "this" layer), or a layer to
clone. But, for example, if I call wmslayer.clone(), I get back an
object with class = "OpenLayers.Layer", rather than
"OpenLayers.Layer.WMS". This doesn't seem correct.
2. If I do something like this: wmslayerA = wmslayer.clone(wmslayer);
wmslayerB = wmslayer.clone(wmslayer); then wmslayerA and wmslayerB
have the same id...this doesn't seem right, and it seems to confuse
the layer switchers for the two different maps...or something else is
confusing them, because they're definitely confused.
3. The clone method is overridden in OpenLayers.Layer.Image , and it
behaves differently--specifically, for a WMS layer
wmslayer.clone(wmslayer) seems to work better, but for an Image layer
imagelayer.clone() seems to work better...but it still doesn't work
right.
Shouldn't somelayer.clone() always be the same as
somelayer.clone(somelayer)? or am I misunderstanding something? Is
this supposed to work? Is it deprecated, or is there a better way to
do it?
Example of some of the above problems (especially #2) can be seen
here: http://s89238293.onlinehome.us/w/index.php?title=Two_Maps . The
site is using OpenLayers 2.6.
Thanks!
-Matt W.
More information about the Users
mailing list