Kaung Htet
Kaung Htet

Reputation: 587

Duplicate labels showing up while in polygon edit mode

When the user has finished drawing polygons, the polygon label will be update with the calculated area.

polygonLayer.styleMap.styles.default.defaultStyle.label = "xxx";
polygonLayer.redraw();

which will achieve this, no problem.

enter image description here

I call this two lines everytime the area of the polygon is updated. However, if I edit the polygon with edit control, the updated area will be displayed on all the nodes.

enter image description here

And if the user has finished editing and switch to other nodes, everything went back to normal. I have tried setting the labels to empty strings when the user clicks on the editing control but that only hides the main label (the one in the center), but the labels on the nodes are still there.

    $('.olControlModifyFeatureItemInactive').click(function() {
            polygonLayer.styleMap.styles.default.defaultStyle.label = "";
            polygonLayer.redraw();
    });

What is happening there and how do I prevent duplicated area values from showing up?

Upvotes: 0

Views: 754

Answers (1)

capdragon
capdragon

Reputation: 14899

Take a look at THIS

You should be able to setup context on our style map and only return the label if it's NOT in edit mode:

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

Upvotes: 1

Related Questions