我正在使用Openlayers,我想要修改一个功能,但是缩放级别17似乎存在问题,因为它在缩放级别16下工作正常。
zoom 16
zoom 17
如图所示,在缩放级别17,编辑手柄和多边形不重合。
有人能帮助我吗?
答案 0 :(得分:0)
在Firefox中使用SVG渲染器来计算点数限制可以做的一件事就是在Polygon上调用简化。请参阅此处的简化函数http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Geometry/LineString.js,它基于Douglas-Peucker算法。 simplify函数将Linestring作为参数,因此您必须多次调用simplify直到达到15,000以下的数字,然后重新创建Polygon。
我在jsFiddle:http://jsfiddle.net/u6Yfg/
上举了一个如何做的例子var polygon='POLYGON((x1 y1, x2, y2......xn,yn))'
//convert wkt to OpenLayers.Feature.Vector
var reader=new OpenLayers.Format.WKT();
var feat=reader.read(polygon);
//get initial points from feature's geometry and set target points (eg, 200 here).
var num_points=feat.geometry.components[0].components.length;
var target_points=200;
//set simplification tolerance to one meter initially
var tolerance=1;
//convert feature's geometry to linestring
var linestring=new OpenLayers.Geometry.LineString(feat.geometry.components[0].components);
var simplified_linestring;
//simplify linestring until target points reached
while(target_points<num_points){
simplified_linestring=linestring.simplify(tolerance);
num_points=simplified_linestring.components.length;
tolerance+=1;
}
alert('Number of points in simplified geometry: ' + simplified_linestring.components.length);
//create new geometry from simplified linestring
var geom=new OpenLayers.Geometry.Polygon(new OpenLayers.Geometry.LinearRing(simplified_linestring.components));