[OpenLayers-Users] Select style for point features

Olivier THIERRY olivier.thierry at gmail.com
Tue Mar 2 06:07:27 EST 2010


Hi,

I have to draw routes on a map. I need points for the steps of the
route and lines between the steps.
I could make it work, but now I need to highlight these lines and points.
Actually I need to change the colour of either lines or points when
they are selected in a list outside the map or clicked on the map.

To do this, I added a SelectFeature control to the layer containing the routes.

I could make it work for lines by adding the following style map to
the routes layer :

	var symbolizer = OpenLayers.Util.applyDefaults(
		{
			fillColor: "#0000FF"
			, strokeColor: "#2A2AFF"
			, strokeWidth: 2
		}
		, OpenLayers.Feature.Vector.style["default"]);
				
	var styles = new OpenLayers.StyleMap({
		"default": symbolizer,
		"select": {
			fillColor: "red"
			, strokeColor: "red"
		}
	});

But I can't make it work with points.

I create the points this way :

var point = new OpenLayers.Geometry.Point(lon, lat, 0);
point.transform(map.displayProjection, map.projection);
var styleSite = OpenLayers.Util.extend({},
OpenLayers.Feature.Vector.style['default']);
styleSite.strokeColor = "blue";
styleSite.fillColor = "blue";
styleSite.pointRadius = 3;
styleSite.strokeLinecap = "square";
var feature = new OpenLayers.Feature.Vector(point, null, styleSite);

The points display OK, but colour doesn't change when I select the point.
I think my problem deals with style, but I can't find what is wrong.
Note I had to set the style for point vector. If I don't do this, it
doesn't diplay. I find this strange since I don't need to do this for
line feature !

Any idea what I did wrong ?

Regards,

Olivier



More information about the Users mailing list