[OpenLayers-Users] SPAM-LOW: Re: problem labeling vector
features - vertices being labeled too
Michael Anderson
mike at spatialit.com
Thu Aug 20 09:06:51 EDT 2009
Thanks again Eric. Haven't used a context before, but it sounds like exactly
what I need. I'll give it a try later today.
Mike
----- Original Message -----
From: "Eric Lemoine" <eric.lemoine at camptocamp.com>
To: "Michael Anderson" <mike at spatialit.com>
Cc: <users at openlayers.org>
Sent: Thursday, August 20, 2009 2:22 AM
Subject: Re: [OpenLayers-Users] SPAM-LOW: Re: problem labeling vector
features - vertices being labeled too
On Thursday, August 20, 2009, Eric Lemoine <eric.lemoine at camptocamp.com>
wrote:
> On Wednesday, August 19, 2009, Michael Anderson <mike at spatialit.com>
> wrote:
>> Eric is correct. The modifyFeature control is using the select style.
>> Setting the select style's label to an empty string does remove the label
>> on the polygon feature being edited. But the vertices are still labeled.
>> So it is still trying to label the vertices with an attribute value (from
>> the default style?) and putting the empty string from the select style on
>> the polygon.
>
> Right. This is because the modify feature control uses the "default"
> render intent for drawing the vertices (and the rotation and drag
> handles).
>
>
>>
>> Gives me an idea for a temporary hack though. I have a function that
>> finds vertices. I can modify it to add the label attribute to the
>> vertices and set them to empty strings. That should let me label the
>> polygon while the vertices appear to not have labels. Should work as long
>> as adding attributes to a vertex won't cause a problem I don't know
>> about.
>
> How about using a context, with something like that in your style map:
>
> "default": new OpenLayers.Style({
> label: "${label}",
> // other symbolizer properties here
> }, {
> context: {
> label: function(f) {
> if(f.geometry.CLASS_NAME !=
> "OpenLayers.Geometry.Point") {
> return f.attributes.label;
> } else {
> return "";
> }
> }
> }
> })
>
even better: have the context function check if the label attribute exists:
context: {
label: function(f) {
return f.attributes.label != undefined ? f.attributes.label :
"";
}
}
More information about the Users
mailing list