Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I first uploaded a geojson type polygon to the OpenLayer. Can I still edit the feature of this layer? Here is the code I am using: (It can upload the geojson layer but can not edit it)

        var map, layer;

        function init(){
        map = new OpenLayers.Map( 'map');
        layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
        map.addLayer(layer);
        map.setCenter(

        new OpenLayers.LonLat(0.8,52.472).transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
            ), 7
        );    


       var featurecollection = {"type":"Polygon","coordinates":[[[-248052.78111938,6928922.6476283],[-193018.12076172,6933661.7433813],[-167335.27926147,6885812.1636815],[-184915.79576462,6855084.4783151],[-228484.9018811,6854931.6042586],[-260588.45375641,6872512.1207617],[-266703.41601837,6898194.962262],[-248052.78111938,6928922.6476283]]]};
       var geojson_format = new OpenLayers.Format.GeoJSON();
       var vector_layer = new OpenLayers.Layer.Vector({
        projection: new OpenLayers.Projection("EPSG:4326")
       }); 

       map.addLayer(vector_layer);
       vector_layer.addFeatures(geojson_format.read(featurecollection));

//Until Here, No Problem    

        var select_control = new OpenLayers.Control.SelectFeature(vector_layer);
        select_control.activate();

        var modify_control = new OpenLayers.Control.ModifyFeature(vector_layer,{
            mode:OpenLayers.Control.ModifyFeature.RESHAPE
        });
        map.addControl(modify_control);
        modify_control.activate();

    }

Is there something wrong with the editing code? Thanks in advance.

share|improve this question
    
Still need an answer. –  Yu Guo May 29 '13 at 8:45

1 Answer 1

You have a select control and a modify control activated at the same time, The modify control has it's own select mechanism, so there's no need for a select control (and if you do need it, deactivate it when activating the modify control. A Panel might simplify that).

See http://jsfiddle.net/MGHFu/ for what is needed to get your code working.

share|improve this answer
    
Thanks a lot. Can I ask one more question to you: After the modification, how can I save the new feature as the geojson data? Thanks a lot. –  Yu Guo May 29 '13 at 9:54
    
sure: listen to the "afterfeaturemodified" event on the layer, like so: jsfiddle.net/2VUX3/4 and then use your favorite method to POST/PUT to server –  atlefren May 29 '13 at 10:06
    
Thanks Altefren. You know, I am still a student, could you give me more advice on this field. I am feeling that OpenLayers API documentation seems a little bit confusion to me since it doesn't have a relevant example on each command. Do you know how can I learn it fast. Thanks –  Yu Guo May 29 '13 at 18:26
    
I strongly advise you to read up on javascript, and study the source code of Openlayers. I'm not sure what you mean by fast, but what I do know (from personal expirience) is that it takes time to learn to write code. –  atlefren May 29 '13 at 18:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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