Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
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 Answer 1

up vote 0 down vote accepted

have you tried cloning the Style object seperately? :)

share|improve this answer
    
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 –  Todd Krueger 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.