在Openlayers中更改多边形的顶点会产生多个错误

时间:2012-05-30 07:37:10

标签: firebug openlayers polygon vertices

updatePolygon: function() {
    drawControls.modify.createVertices;
    var sides = 50;
    drawControls.regular.handler.sides = sides;
}

我从OpenLayers示例中获得了此功能。它完全有效,只有firebug会将多个错误悬停在要编辑的点上:

this.features["OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow)] is undefined
http://freetrack.local/js/OpenLayers.js
Line 1310

有人可以帮我解决这个问题,因为它看起来不太整洁。

提前致谢!

1 个答案:

答案 0 :(得分:0)

@Pepijn,我遇到了接近这个的挑战,不得不从多边形改变一个点,以下代码适用,希望它有所帮助。

var ls = new OpenLayers.Geometry.LineString([a, b]);

    // calculate scale
    var distance = a.distanceTo(b);
    var scale = newSize / distance;

    ls.resize(scale, a);
    var newB = ls.getVertices()[1];
    console.debug( 'novo b : ' + newB );

    var ownerFeature = vectors.getFeatureById(owner)
    var points = ownerFeature.geometry.getVertices();

    for (var i=0;i<points.length-1;i++){
        if( points[i].x == b.x && points[i].y == b.y ){
            console.debug('found b');
            ownerFeature.geometry.addComponent(newB,i);
            ownerFeature.geometry.removeComponent(b);
            vectors.redraw();
            break;      
        }
    }