[OpenLayers-Users] SPAM-LOW: Re: problem labeling vector features - vertices being labeled too

Eric Lemoine eric.lemoine at camptocamp.com
Thu Aug 20 02:22:01 EDT 2009


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