Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I added the style on the polygon layer like so.

var style = $.extend(true, {}, OpenLayers.Feature.Vector.style['default']); // get a copy of the default style
style.label = "1233456 ha"
style.fillOpacity = 0.1
style.strokeWidth = 3
var styleMap = new OpenLayers.StyleMap({"default": style});
polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer", {styleMap: styleMap});

The polygon looks fine on normal mode.

label on normal mode

However, on ModifyFeature, labels are showing up on every vertex.

enter image description here

So, I test this http://trac.osgeo.org/openlayers/ticket/2176.

var styleMap = new OpenLayers.StyleMap(new OpenLayers.Style({
        label: "${getLabel}"
        // your other symbolizer properties here
    }, {context: {
        getLabel: function(feature) {
            if(mycontrolIsNotInEditMode) {
                return feature.attributes.label;
            }
        }
    }}
));

Then the labels on the vertices are disabled, BUT the label between vertices are still showing up.

how can I disable the labels between the vertices? Thank you..

share|improve this question
1  
I'm using your exact code and cannot duplicate this behaviour. Can you provide us with more code that will help us duplicate this behavior. My tests don't have the problems you are having. Are you using the latest OpenLayers? –  CaptDragon Feb 9 '12 at 18:22
    
oh, i am sorry, it's showing labels in ModifyFeature. You used SelectFeature which is working fine. Thx –  Michelle Chan Feb 10 '12 at 1:30
add comment

2 Answers 2

up vote 5 down vote accepted

You can make sure that the geometry is of type polygon so that it only gets the label if it's a polygon and not the line or point. By adding && feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon" to your if statement. That should work.

Like this:

...
getLabel: function (feature) {
    if (mycontrolIsNotInEditMode && feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") {
        return feature.attributes.label;
    }
}
...

Update:

Here is a Working Example

This is the important part:

var style = $.extend(true, {}, OpenLayers.Feature.Vector.style['default']); // get a copy of the default style
style.label = "${getLabel}";
style.fillOpacity = 0.1
style.strokeWidth = 3

var styleMap = new OpenLayers.StyleMap({
    "default": new OpenLayers.Style(style, {
        context: {
            getLabel: function (feature) {
                if (feature.geometry && feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") {
                    return "1233456 ha";
                } else {
                    return "";
                }
            }
        }
    })
});  

So that it only returns a label if it's a polygon: enter image description here

share|improve this answer
    
would you mind providing a working example? I haven't been able to successfully hide the duplicate labels in edit mode. Thanks a ton! –  Michelle Chan Feb 13 '12 at 2:59
3  
No problem, please view my update. –  CaptDragon Feb 13 '12 at 15:23
    
@MichelleChan : Did this solve your problem? Let me know. :) –  CaptDragon Feb 14 '12 at 16:06
    
yay! thanks a lot, it works now! –  Michelle Chan Feb 15 '12 at 9:40
add comment

I've faced with the same issue today. Because my layer contains not only polygonal features, solution proposed by CaptDragon didn't work in my case. I've spent couple of hours for resolving my problem and would like to share results.

#Create custom symbolizer for virtual vertices (withot label option)
OpenLayers.Feature.Vector.style['virtual'] = {
    fillColor: "#ee9900",
    fillOpacity: 0.4,
    strokeColor: "#ee9900",
    strokeOpacity: 1,
    strokeWidth: 1,
    pointRadius: 3
}

var styleMap = new OpenLayers.StyleMap({
   "default":OpenLayers.Feature.Vector.style['default'],
   "virtual": OpenLayers.Feature.Vector.style['virtual']
}, {extendDefault: false});

var vectors = new OpenLayers.Layer.Vector('features', {styleMap: styleMap});
var modify = new OpenLayers.Control.ModifyFeature(vectors, {vertexRenderIntent: "virtual"});
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.