[OpenLayers-Users] Destroy/Delete a vector feature

Yves Moisan yves.moisan at boreal-is.com
Tue Dec 16 16:00:20 EST 2008


> > pts_gps = new OpenLayers.Layer.Vector("GeoJSON", {
> >                                   // styleMap: styleMap,
> >                    strategies: [new OpenLayers.Strategy.BBOX()],
> >                    protocol: new OpenLayers.Protocol.HTTP({
> >                        url: "http://myserver/PGTEST4326/all.json",
> >                        format: new OpenLayers.Format.GeoJSON()
> >                    }),
> >                                        eventListeners: {
> >                    loadend: function(??) {
> >                                        for (var i = 0, var len = pts_gps.features.length; i < len; i++) {
> >                pts_gps.features[i].state = OpenLayers.State.UNKNOWN;
> >                }} }
> >
> >                });
> >
> > and it doesn't work ...
> 
> I think you should use the Style framework for this.
> 
> Try this:
> 
> var tpl = {"display": "${getDisplay}"};
> var ctx = {
>     "getDisplay": function(feature) {
>         // "fid" is the identifier of the feature
>         // to filter out
>         return feature.fid == "fid" ? "none" : "";
>     }
> };
> var style = new OpenLayers.Style(tpl, {
>     "context": ctx}
> );
> var layer = new OpenLayers.Layer.Vector("vec", {
>     styleMap: style
> });
> 
> (hmm, this may not work because of a limitation in the Style implementation!)
> 
> I see this as an alternative:
> 
> var style = new OpenLayers.Style();
> var rule = new OpenLayers.Rule({
>     "symbolizer": {"display": "none"},
>     "filter": new OpenLayers.Filter.FeatureId({
>         "fids": ["fid"]
>     })
> });
> var elseRule = new OpenLayers.Rule({
>     elseFilter: true
> });
> style.addRules([rule, elseRule]);
> var layer = new OpenLayers.Layer.Vector("vec", {
>     styleMap: style
> });
> 

Unless I'm mistaken, which I probably am, this only has to do with
styling and not with assigning values to the 'state' property of a
Layer.Vector.  I'm pretty confident that style will apply given I can
get values in features[i].state.  I tried to read the article on
closures in a bid to understand, but at any rate all I want is 

1) make sure all the points from my service are loaded (which does take
a bit of time) and then

2) assign the state property (e.g. to "unknown") on all features
retrieved from my service

The idea here is that new points added by the user and not yet committed
to the server will clearly show.

Thanx for your code, again :-)

Yves





More information about the Users mailing list