大家好我有一个名为vertices []的OpenLayers点对象数组 vertices =" POINT(78.40873715820317 17.400524043704443), 要点(78.425388311768 17.38692766193279), 要点(78.40238568725626 17.384142736159205)"
我想用多边形格式更改它,坐标相同 vertices1 [] =" POLYGON((78.40873715820317 17.400524043704443,78.425388311768 17.38692766193279,78.40238568725626 17.384142736159205,78.40873715820317 17.400524043704443))" 我怎么能以编程方式转换它。
答案 0 :(得分:0)
尝试使用此代码:
var vertices="POINT(78.40873715820317 17.400524043704443), POINT(78.425388311768 17.38692766193279), POINT(78.40238568725626 17.384142736159205)";
var vertices_array = vertices.split(',');
var sitePoints = [];
for (var i=0;i<vertices_array.length;i++)
{
var wkt = new OpenLayers.Format.WKT();
var pointWKT = wkt.read(vertices_array[i]);
var point = new OpenLayers.Geometry.Point(pointWKT.geometry.x, pointWKT.geometry.y);
sitePoints.push(point);
}
var linearRing = new OpenLayers.Geometry.LinearRing(sitePoints);
var geometry = new OpenLayers.Geometry.Polygon([linearRing]);
var polygonFeature = new OpenLayers.Feature.Vector(geometry,null);
var polygonWKT = new OpenLayers.Format.WKT();
var output = polygonWKT.write(polygonFeature);
alert(output);