0

I can draw a polygon in OpenLayers by running this code.

        var points = [];

        var point = new OpenLayers.Geometry.Point(0, 0);
        point.transform('EPSG:4326', 'EPSG:900913');
        points.push(point);

        var point = new OpenLayers.Geometry.Point(0, 30);
        point.transform('EPSG:4326', 'EPSG:900913');
        points.push(point);

        var point = new OpenLayers.Geometry.Point(30, 30);
        point.transform('EPSG:4326', 'EPSG:900913');
        points.push(point);

        var point = new OpenLayers.Geometry.Point(30, 0);
        point.transform('EPSG:4326', 'EPSG:900913');
        points.push(point);

        var ring = new OpenLayers.Geometry.LinearRing(points);
        var polygon = new OpenLayers.Geometry.Polygon([ring]);

        // create some attributes for the feature
        var attributes = { name: "my name", bar: "foo" };

        var feature = new OpenLayers.Feature.Vector(polygon, attributes);
        select.addFeatures([feature]);

        map.addLayer(select);

My map can show this polygon perfectly. Here I did point.transform to match my map's projection system.

Now I want to edit this polygon like 'DragFeature', 'SelectFeature', 'Separator', 'DrawHole', 'ModifyFeature' etc by OpenLayers.

How can I do that?

1

The best place to look is the online OpenLayers examples

Here's an example of creating and modifying shapes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.