简体   繁体   English

Openlayers缩放编辑

[英]Openlayers edit with zoom

I am working with Openlayers, and I want to modify a feature, but there seems to be an issue with zoom level 17, as it works perfectly at zoom level 16. 我正在使用Openlayers,并且我想修改功能,但是缩放级别17似乎存在问题,因为它在缩放级别16时可以正常工作。

zoom 16 变焦16

在此处输入图片说明

zoom 17 变焦17

在此处输入图片说明

As shown in the image, at zoom level 17, the editing handles and the polygon do not coincide. 如图所示,在缩放级别17时,编辑手柄和多边形不重合。

Can anybody help me? 有谁能够帮助我?

One thing you could do to get round the number of points limitation with the SVG renderer in Firefox would be to call simplify on the Polygon. 要解决Firefox中SVG渲染器的点数限制问题,您可以做的一件事就是在Polygon上调用simple。 See the simplify function here, http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Geometry/LineString.js , which is based on the Douglas-Peucker algorithm. 请参阅http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Geometry/LineString.js此处的简化函数,该函数基于Douglas-Peucker算法。 The simplify function takes a Linestring as an argument, so you would have to call simplify several times until you reach a number below 15,000 and then recreate the Polygon. simple函数将Linestring作为参数,因此您必须多次调用simple直到达到15,000以下的数字,然后重新创建Polygon。

I have put an example of how to do this on jsFiddle: http://jsfiddle.net/u6Yfg/ 我已经在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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM