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

Eric Lemoine eric.lemoine at camptocamp.com
Thu Aug 20 01:45:24 EDT 2009


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 "";
                     }
                 }
            }
    })

Cheers,

>
> Mike
>
>
> ----- Original Message ----- From: "Christopher Schmidt" <crschmidt at metacarta.com>
> To: "Eric Lemoine" <eric.lemoine at camptocamp.com>
> Cc: "Michael Anderson" <mike at spatialit.com>; <users at openlayers.org>
> Sent: Wednesday, August 19, 2009 12:24 PM
> Subject: SPAM-LOW: Re: [OpenLayers-Users] problem labeling vector features - vertices being labeled too
>
>
> On Wed, Aug 19, 2009 at 06:20:57PM +0200, Eric Lemoine wrote:
>
> On Wednesday, August 19, 2009, Christopher Schmidt
> <crschmidt at metacarta.com> wrote:
>> On Wed, Aug 19, 2009 at 10:42:57AM -0400, Michael Anderson wrote:
>>> In the real app I'd tried setting the select style's label to an empty
>>> string, but it didn't work so I didn't include it in my example. I >> added
>>> it to the example (http://128.118.7.3/testing/testlabel.html). It makes
>>> the label for the polygon go away, but still labels the vertices with
>>> 'undefined'.
>>
>> Sorry; I forgot that for the modifyFeature, the style name used is
>> 'temporary';
>
> is it? The modify feature control uses a select feature control, whose
> default select style is "select" IIRC.
>
>
> Okay, grep failed me. So then what is the user doing wrong?
>
> -- Chris
>
>
> Regards,
>
>
>
>> I think that if you change 'select' to 'temporary' it might
>> help.
>>
>> -- Chris
>>
>>
>>> Mike
>>>
>>> ----- Original Message ----- From: "Christopher Schmidt"
>>> <crschmidt at metacarta.com>
>>> To: "Michael Anderson" <mike at spatialit.com>
>>> Cc: <users at openlayers.org>
>>> Sent: Wednesday, August 19, 2009 10:06 AM
>>> Subject: SPAM-LOW: Re: [OpenLayers-Users] problem labeling vector
>>> features - vertices being labeled too
>>>
>>>
>>> On Wed, Aug 19, 2009 at 09:56:12AM -0400, Michael Anderson wrote:
>>>> Hello,
>>>>
>>>> I'm having a problem with labeling vector features. It works fine >>> until I
>>>> select a feature with a ModifyFeature control. Then it labels all the
>>>> vertices as well as the feature itself. And they are all labeled
>>>> 'undefined'
>>>> because the vertices don't have the attributes needed for the label.
>>>>
>>>> I have a stylemap set up with 'default' and 'select' styles. Only the
>>>> default style has a label defined. At first I had a label set up for >>> the
>>>> select style too so it would be labeled when selected. Then when the
>>>> vertices were labeled I removed the label from the style, but the >>> vertices
>>>> are still labeled.
>>>
>>> "The “default” intent has a special role: if the extendDefault property
>>> of the StyleMap is set to true (default), symbolizers calculated for
>>> other render intents will extend the symbolizer calcualated for the
>>> “default” intent. So if we want selected features just to have a
>>> different size or color, we only have to set a single property (in this
>>> example: pointRadius)."
>>>
>>> -- http://docs.openlayers.org/library/feature_styling.html#stylemap
>>>
>>> So, if you have (in your select style) the 'label' set to '' -- an >> empty
>>> string -- I think this should solve your problem.
>>>
>>>
>>>> Is there a way to label a feature while it's vertices are visible and >>> not
>>>> have the vertices labeled too?
>>>
>>> Vertices are features too, but I think the above solution should solve
>>> your problem, based on your description.
>>>
>>> Regards,
>>> --
>>> Christopher Schmidt
>>> MetaCarta
>>>
>>>
>>>
>>>
>>
>> --
>> Christopher Schmidt
>> MetaCarta
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com
>
>
> --
> Christopher Schmidt
> MetaCarta
>
>
>
>
>


-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com



More information about the Users mailing list