[OpenLayers-Users] Destroy/Delete a vector feature
Eric Lemoine
eric.c2c at gmail.com
Tue Dec 16 15:25:37 EST 2008
On Tue, Dec 16, 2008 at 7:09 PM, Yves Moisan <yves.moisan at boreal-is.com> wrote:
>
>> My first thought is that after the data is loaded, if I could get the
>> feature by ID or attribute and then destroy it, that would be great.
>
> If you get to doing something like that, please share your code :-).
> I'm trying to do something similar, that is set the state property of
> the features in my GeoJSON response along the lines of :
>
> 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
});
This is untested.
Cheers,
--
Eric
More information about the Users
mailing list