[OpenLayers-Users] edit points in Geometry of a vector?

Arnd Wippermann arnd.wippermann at web.de
Mon Aug 16 12:23:30 EDT 2010


Hi,

Below a function I use to snap the points of my features (point, line,
polygon) programatically to a rounded value, so that the points lie all on a
grid with a raster i.e 1000x1000 (SnapRadius=1000).

Arnd

function ctrlDragFeature_SnapPoint(feature)
{
    if(SnapRadius>0)
    {
        var objF   = feature;

        geomType =
objF.geometry.CLASS_NAME.replace(/OpenLayers.Geometry./,"");
        if(geomType=="Point")
        {   objF.geometry.x =
Math.round(objF.geometry.x/SnapRadius)*SnapRadius;
            objF.geometry.y =
Math.round(objF.geometry.y/SnapRadius)*SnapRadius;
        }
        else if(geomType=="LineString")
        {   for(var j=0;j<objF.geometry.components.length;j++)
            {
                objF.geometry.components[j].x =
Math.round(objF.geometry.components[j].x/SnapRadius)*SnapRadius;
                objF.geometry.components[j].y =
Math.round(objF.geometry.components[j].y/SnapRadius)*SnapRadius;
            }
        }
        else if(geomType=="Polygon")
        {
            var objFpt = objF.geometry.components[0].components;

            for(var i=0;i<objFpt.length;i++)
            {
                objFpt[i].x = Math.round(objFpt[i].x/SnapRadius)*SnapRadius;
                objFpt[i].y = Math.round(objFpt[i].y/SnapRadius)*SnapRadius;
            }
            objFpt[i-1].x = objFpt[0].x;
        }
        objF.layer.drawFeature(feature);

    }
} 

-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von ulao
Gesendet: Montag, 16. August 2010 14:11
An: users at openlayers.org
Betreff: Re: [OpenLayers-Users] edit points in Geometry of a vector?


I'd like to do this programatically .

--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/edit-points-in-Geometry-of-a-vector-t
p5417230p5427609.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list