[OpenLayers-Users] Select style for point features
Arnd Wippermann
arnd.wippermann at web.de
Tue Mar 2 13:47:22 EST 2010
Hi
You can try to add an elseFilter to your style
var lookupSens = {
"aller": {strokeDashstyle: "solid"},
"retour": {strokeDashstyle: "dash"}
};
styles.addUniqueValueRules("default", "sens", lookupSens);
var rules = [new OpenLayers.Rule({
symbolizer: {fillOpacity:0, strokeOpacity:1, strokeColor:"#FF0000",
strokeWidth: 4, pointRadius:10},
elseFilter: true
})];
styles.styles["default"].addRules(rules);
Arnd
-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von Olivier THIERRY
Gesendet: Dienstag, 2. März 2010 15:06
An: Alexandre Dube; users at openlayers.org
Betreff: Re: [OpenLayers-Users] Select style for point features
2010/3/2 Alexandre Dube <adube at mapgears.com>:
> 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
>
>
For what I understood, when you define a "default" style, other styles
extend this default style. So when defining a "select" style for example,
you just have to set the style attributes that you want to be different from
default style. And it works very well indeed. I read this there :
http://trac.openlayers.org/wiki/Styles#UsingPropertyStyles
Anyway, I just found where my problem comes from. Actually I use rules with
my style map, this way :
var lookupSens = {
"aller": {strokeDashstyle: "solid"},
"retour": {strokeDashstyle: "dash"}
};
styles.addUniqueValueRules("default", "sens", lookupSens);
This rule helps me to have a different style for journey and return journey.
But since it has no sense for points (just for lines), I don't have the
"sens" property on the point I add to the layer, and it looks like it causes
some problems !
If I remove this rule, the points print OK. But I really need this rule, so
I can't remove it.
Do you know if there is a way to tell OpenLayers to apply the rule only for
some elements of the layer ? Or another workaround for this ?
Regards,
Olivier
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users
More information about the Users
mailing list