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

Jorge Gustavo Rocha jgr at di.uminho.pt
Tue Jan 5 06:45:58 EST 2010


Hi Marco,

I don't use the toState method, but changing the property directly does
work.

For example:
/*
* allow editing the selected feature
*/
(...)
featureToBeModify = someVecLayer.selectedFeatures[0];
theCorrespondingForm.getForm().items.each(unsetReadOnly);
(...)
/*
* save
*/
if (featureToBeModify.state != OpenLayers.State.UPDATE) {
	featureToBeModify.state = OpenLayers.State.UPDATE
}
var rec = theCorrespondingForm.getForm().getValues();
featureToBeModify.attributes.one = rec.one;
featureToBeModify.attributes.two = rec.two;
(...)      
saveStrategy.save();

As you can see, state can/should be changed to allow the feature be
written in the save operation.

I hope it helps,

Jorge

Ter, 2010-01-05 às 11:57 +0100, Marco Scheuble escreveu:
> 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
> 
> anyone can help me?
> cheers, marco
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


-- 
jorge gustavo rocha
departamento de informática
universidade do minho
4710-057 braga
portugal
N 41º33'44,5" W 8º23'40,5"
tel +351 253604470 fax +351 253604471 cel +351 927210173




More information about the Users mailing list