[OpenLayers-Users] changing the state of a selected feature

Eric Lemoine eric.lemoine at camptocamp.com
Tue Jan 5 06:29:58 EST 2010


On Tue, Jan 5, 2010 at 11:57 AM, Marco Scheuble <mail at marco-scheuble.de> wrote:
> Hi list,
>
> after selecting a feature and editing its attributes, I want to save the
> changes.
> Unfortunately the state of the selected feature isn't set, so changes
> would not be saved.
> Trying to set the state manually with: feature.toState() won't work, too.
>
> I'm doing it like this:
> point.events.on({
>    "featureselected": function(e) {
>     showAttributes(e.feature);
>   },
>   "featureunselected": function(e) {
>     hideAttributes(e.feature);
>   }
> });
>
> function showAttributes(feature){
>     document.getElementById("label").value = feature.attributes.label;
> }
>
> function hideAttributes(feature){
>     feature.attributes.label = document.getElementById("label").value;
>     feature.toState("Update");
>     alert(feature.state);
> }
>
> alert(feature.state) -> null

to change a feature's state do feature.state = OpenLayers.State.INSERT
(or UPDATE or DELETE). If you use the modify feature control it'll
take care of modifying the feature's state.

Hope this helps,


-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com



More information about the Users mailing list