[OpenLayers-Users] Change vector style dynamically
Maxime Phaneuf
maxime.phaneuf at usherbrooke.ca
Thu Oct 27 15:58:54 EDT 2011
Hi,
I'm developping a map where the baselayer is Google and the overlay layers
are GeoJSON I build server side.
var busRoutes = new OpenLayers.Layer.Vector("routes", {
visibility: true,
style: styleLine,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: GlobalParams.MakeUrl("mapHandler.ashx"),
format: new OpenLayers.Format.GeoJSON(),
params: { 'routes': 'all', 'action':'route' }
})
});
This works as expected. I can see my layer no problem, with the style being:
var styleLine = new OpenLayers.Style({ 'strokeColor': '#000000'});
var styleLineSelect = new OpenLayers.Style({ 'strokeColor': '#FF0505'
});
var styleLineTemp = new OpenLayers.Style({'strokeColor':'#ffffff'});
var smLine = new
OpenLayers.StyleMap({'default':styleLine,'select':styleLineSelect,
'temporary':styleLineTemp});
This busRoute layer shows every bus routes. Sometimes, a user will only need
to see one route instead of all. So, I built a custom layer changer where
I'm refreshing this layer with this code:
map.getLayersByName('routes')[0].refresh({ force: true, params: { 'routes':
routeNumberJSON, 'action':'route'} });
This also works as expected. I can see the specific route on the map.
The problem is that I cannot change the style (stroke color) for this
particular route. I tried setting a new style and stylemap for the layer,
and a new style for the new features. Nothing seems to work. It always keeps
the #000000 (black) stroke color. I really need to be able to change style
dynamically when I refresh the layer. I know my new style and style are
valid.
Is it possible to change style dynamically in OpenLayers?
Thanks,
Maxime
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Change-vector-style-dynamically-tp6937851p6937851.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list