[OpenLayers-Users] Changing styleMap of a OpenLayers.Layer.Vector after map initialization?

alexe100 imoveisnacionais at gmail.com
Sat Jun 2 16:45:33 PDT 2012


Hi
I have a map where user can draw polygons to represent geofences. I want
that geofences where vehicles must be inside to be drawn in green and
geofences where vehicles can not be inside to be drawn in red.
I have the styleMapVermelho (red color) and styleMapVerde (green)
OpenLayers.StyleMap variables.  
So, the application starts with the green color selected. I have a button to
change the color to red and vice-versa. 

The question is, how to remove the current  OpenLayers.StyleMap and set the
other OpenLayers.StyleMap  when the button is pressed?
Please, see code below for init function:

var map, drawControls;
		var polygonLayer;
		var styleMapVerde;
		var styleMapVermelho;
		function init()
		{
			map = new OpenLayers.Map('mapdiv');

			var wmsLayer= new OpenLayers.Layer.OSM(); //This uses meters in X/Y!!!
			map.addLayer(wmsLayer);
			
			map.addControl(new OpenLayers.Control.MousePosition());
			
			

			//cores para polygon layer
			styleMapVermelho = new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults
			(
				{fillColor: "red", fillOpacity: 0.25, strokeColor: "black"},
				OpenLayers.Feature.Vector.style["default"])
			);
			
			styleMapVerde = new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults
			(
				{fillColor: "green", fillOpacity: 0.25, strokeColor: "black"},
				OpenLayers.Feature.Vector.style["default"])
			);
			polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer",{styleMap:
styleMapVerde});
			map.addLayer(polygonLayer);
			document.getElementById('dentro').checked=true;
			
 	
			drawControls = 
			{
				polygon: new
OpenLayers.Control.DrawFeature(polygonLayer,OpenLayers.Handler.Polygon)
			};
			map.addControl(drawControls['polygon']);
			drawControls['polygon'].activate();
			
			
			map.setCenter(new OpenLayers.LonLat(0, 0), 3);
		}





--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Changing-styleMap-of-a-OpenLayers-Layer-Vector-after-map-initialization-tp4978765.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list