我想重新投影多边形的顶点。我已经能够为边界实现这一点,但顶点有点麻烦。
function onFeatureModified(event) {
var bounds = event.feature.geometry.getBounds();
var answer = "bottom: " + bounds.bottom + "\n";
answer += "left: " + bounds.left + "\n";
answer += "right: " + bounds.right + "\n";
answer += "top: " + bounds.top + "\n";
alert(answer);
var mapProjv = map.getProjectionObject();
var epsg4326v = new OpenLayers.Projection("EPSG:4326");
var verticesNative = event.features[0].geometry.getVertices();
var verticesLatLon = verticesNative.transform( mapProjv , epsg4326v );
var vertices = verticesNative;
alert(verticesNative);
}
下面有效的代码:
var vertices = event.features[0].geometry.getVertices();
alert(vertices);
答案 0 :(得分:0)
getVertices()
方法返回OpenLayers.Geometry.Point
个对象的数组,因此您无法在其上调用transform()
方法。你应该做的是循环遍历数组并在每个对象上调用transform()
:
var vertices = event.features[0].geometry.getVertices();
var transformedVertices = [];
for(var i=0; i < vertices.length; i++){
transformedVertices.push(vertices[i].transform(
new OpenLayers.Projection("EPSG:900913"),
new OpenLayers.Projection("EPSG:4326")
));
}
//create new feature with transformed vertices