1

The map application I'm currently designing allows users to create features on one or more vector layers. What I'd like to know is if it is possible to set default feature properties at the layer level so that any features created on the layer automatically have those properties/attributes.

For example if I setup a vector layer called 'House_Residential' when a user creates a feature on it it automatically has an attribute/value of 'house:residential'.

At the moment the only solution I can think of is to capture when the feature is added to the layer and give it a property/attribute at that point, not sure if this is the best way though.

1

You got it. The library itself cannot do it for you. Listen to:

layer.getSource().on('addfeature', function(evt){
    //add your attributes
    var feature = evt.feature;
});
  • Thanks for the reply, I shall use the 'addfeature' approach. – marlowp Jun 18 '15 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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