当更改为OpenLayers 2.11并显示测量线上每个段的长度时,遇到一个小问题。
之前放置点A - >; B,B - > C.段A到B的长度将显示在这些点之间,同样在B到C之间,在结束该行之后将显示总数。
我的脚本在OpenLayers 2.10上运行良好,但是在我结束行之后更改为OpenLayers 2.11时,只有段值从向量层中消失。
我理解这个问题,但我在制定逻辑时遇到了麻烦...
以下是我正在使用的脚本:
line: new OpenLayers.Control.Measure(OpenLayers.Handler.Path, {
persist: true,
handlerOptions: {
layerOptions: {
renderers: renderer,
styleMap: styleMap
}
},
textNodes: null,
callbacks:{
create:
function(){
this.textNodes = [];
vlayer.destroyFeatures(vlayer.features); /*-- figured this area is the problem */
mouseMovements = 0;
},
modify:
function(point, line){
if(mouseMovements++ < 5){
return;
}
var len = line.geometry.components.length;
var from = line.geometry.components[len -2];
var to = line.geometry.components[len -1];
var ls = new OpenLayers.Geometry.LineString([from, to]);
var dist = this.getBestLength(ls);
if(!dist[0]){
return;
}
var total = this.getBestLength(line.geometry);
var label = dist[0].toFixed(3) + " " + dist[1];
var textNode = this.textNodes[len -2] || null;
if(textNode && !textNode.layer){
this.textNodes.pop();
textNode = null;
}
if(!textNode){
var c = ls.getCentroid();
textNode = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(c.x, c.y), {}, {
label: "",
fontColor: "#800517",
fontSize: "12px",
fontFamily: "Tahoma",
fontWeight: "bold",
labelAlign: "cm"
});
this.textNodes.push(textNode);
vlayer.addFeatures([textNode]);
}
textNode.geometry.x = (from.x + to.x) / 2;
textNode.geometry.y = (from.y + to.y) / 2;
textNode.style.label = label;
textNode.layer.drawFeature(textNode);
this.events.triggerEvent("measuredynamic", {
measure: dist[0],
total: total[0],
units: dist[1],
order: 1,
geometry: ls
});
}
}
2011-11-28
经过一番研究,我得出的结论是,在OpenLayers 2.11中,只要点击按钮,就会激活测量部分控制。以前在OpenLayers 2.10中,当单击地图并在路径结束的同时结束时,会激活度量部分控制,因此之前工作的原因是textnodes数组仅在新行的开头处为空,但是在2.11中,测量部分控制在路径的末尾不会停用一次,因此实际上会在我结束直线时恢复为空数组并删除图层特征。
来源:http://trac.osgeo.org/openlayers/ticket/3315
有人可以详细说明一下这个吗?