[OpenLayers-Users] Possible to change feature style before
adding feature collection?
adsaero
ag at ads.aero
Wed Nov 18 22:27:02 EST 2009
When I try that, it seems the feature doesn't render at all. I also tried
setting the style in the feature object before adding the feature, but I get
the same result.
Some code snippets:
tracks_style = new OpenLayers.Style({
label: "test",
strokeColor: "#FFFFFF",
stroke: true,
pointRadius: 2
});
track_layer = new OpenLayers.Layer.Vector("Tracks", { styleMap:
tracks_stylemap });
map.addLayer(track_layer);
track_layer.events.register("beforefeaturesadded", track_layer, function (o)
{
alert("boo!");
o.features[0].style = tracks_style;
});
This basically causes that first feature not to render, although the second
feature renders fine (there are two features in the feature array)
This also fails, with the same result:
testfeatures = geojson_format.read(results);
testfeatures[0].style = tracks_style;
track_layer.addFeatures(poofeatures);
I'm stumped :)
Roald de Wit-2 wrote:
>
> Hi,
>
> On 19/11/09 10:51, adsaero wrote:
>> I've got a collection of features (FeatureCollection) returned from a
>> server,
>> and I'd like to change the style of, say, the first feature in the
>> collection to have "stroke" set to true... but I'd like the rest of the
>> features to use the default style(s).
>>
>> Can this be done? If so, what's the best way to do it?
>>
> You can listen to the 'beforefeaturesadded' event [1] and manipulate the
> features you like before they get added to the layer.
>
> [1]
> http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.EVENT_TYPES
>
> Regards, Roald
>
> --
> Roald de Wit
> Software Engineer
> roald.dewit at lisasoft.com
>
> Commercial Support for Open Source GIS Software
> http://lisasoft.com/LISAsoft/SupportedProducts/
>
>
>
> The contents of this email are confidential and may be subject to legal or
> professional privilege and copyright. No representation is made that this
> email is free of viruses or other defects. If you have received this
> communication in error, you may not copy or distribute any part of it or
> otherwise disclose its contents to anyone. Please advise the sender of
> your incorrect receipt of this correspondence.
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
--
View this message in context: http://n2.nabble.com/Possible-to-change-feature-style-before-adding-feature-collection-tp4029160p4029891.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list