3

I'm taking a layer (layer_orig) and calling the clone method to create a new layer (layer_clone) with same features, styles, etc. I am changing the name and map instance of the layer with:

layer_clone.map = null;
layer_clone.setName(name);

This works exactly as expected, even giving a unique layer id to the new layer.

However, if I then update the styleMap of layer_clone, the styleMap of layer_orig is updated as well - suggesting that layer_clone is a reference to layer_orig and not a completely unique Layer object.

Is there a way to get a unique Layer object that is a direct clone of another layer?

5
  • I have in mind to use cloning in the next few days, i ll let you know what i end up with.
    – U2ros
    Oct 9 '12 at 17:50
  • That's be helpful! I look forward to hearing from you! Thanks!
    – swatkins
    Oct 9 '12 at 18:33
  • have you tried cloning the stylemap also?
    – CaptDragon
    Oct 9 '12 at 19:09
  • No, I hadn't. I just did clone the OpenLayers.Style object (OpenLayers.StyleMap doesn't have a clone method) - and it worked. @CaptDragon - add this as an answer and I'll mark it as the accepted answer! Thanks for the help!
    – swatkins
    Oct 9 '12 at 19:26
  • @swatkins: roger that!
    – CaptDragon
    Oct 9 '12 at 19:28
1

have you tried cloning the Style object seperately? :)

3
  • No, I hadn't. I just did clone the OpenLayers.Style object (OpenLayers.StyleMap doesn't have a clone method) - and it worked.
    – swatkins
    Oct 9 '12 at 19:33
  • Could you please provide the syntax for how to clone an existing layers style? Thanks Jan 10 '13 at 17:33
  • it's feature.style.clone(); I know you're getting undefined for this. Check what is undefined. Is it feature.style?
    – CaptDragon
    Jan 10 '13 at 18:08

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .