Pergunta

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.

zoom 16

enter image description here

zoom 17

enter image description here

As shown in the image, at zoom level 17, the editing handles and the polygon do not coincide.

Can anybody help me?

Foi útil?

Solução

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. 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. 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.

I have put an example of how to do this on 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));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top