当用户完成绘制多边形时,将使用计算的区域更新多边形标签。
polygonLayer.styleMap.styles.default.defaultStyle.label = "xxx";
polygonLayer.redraw();
这将实现这一点,没问题。
每次更新多边形的区域时,我都会调用这两行。但是,如果我使用编辑控件编辑多边形,更新的区域将显示在所有节点上。
如果用户已完成编辑并切换到其他节点,则一切都恢复正常。我尝试在用户点击编辑控件但是只隐藏主标签(中间的标签)时将标签设置为空字符串,但节点上的标签仍然存在。
$('.olControlModifyFeatureItemInactive').click(function() {
polygonLayer.styleMap.styles.default.defaultStyle.label = "";
polygonLayer.redraw();
});
那里发生了什么,如何防止出现重复区域值?
答案 0 :(得分:1)
查看 THIS
您应该可以在我们的样式地图上设置context
,只有在标签不处于编辑模式时才会返回标签:
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;
}
}
}}
));