[OpenLayers-Users] Select style for point features
Alexandre Dube
adube at mapgears.com
Tue Mar 2 08:27:48 EST 2010
Olivier,
The way to defined your "default" symbolizer with the applyDefaults
method is correct, but you didn't do so with your "select" symbolizer.
In order for a point to be drawn, it needs more than these two
properties (like pointRadius for example). Try using applyDefaults there
too.
Then, remove the style from your point features too. In order for a
feature to change style automatically when selected, it has to be done
with the StyleMap or manually. If you set a symbolizer (style) directly
to your feature, that's the only style it's going to have regardless of
any stylemap defined.
// are you saying that with this, points don't show at all when
unselected ? Normally, it shouldn't.
var feature = new OpenLayers.Feature.Vector(point);
Kind regards,
Alexandre
Olivier THIERRY wrote:
> 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
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list