2

Is there a way of moving two or more polygons simultaneously?

The following code enables the movement of a singular graphic:

           moveToolbar.activate(esri.toolbars.Edit.MOVE, tempMoveLayer.graphics[graphicNum]);

However I cannot seem to find a method that allows the movement of multiple selected graphics simultaneously.

EDIT

With the following code I manage to activate multiple toolbars for multiple graphics at the same time, however they still move separately rather than being moves as a whole when one of them is clicked and dragged.

//Loop to get all the layers on the map
for (var gCount = 0; gCount < app.map.graphicsLayerIds.length; gCount++) {
    //This will obtain the layer that the selected graphic is on 
    var tempMoveLayer = app.map.getLayer(app.map.graphicsLayerIds[gCount]);

    //Looping through all the graphics in the selected layer
    for (var graphicNum = 0; graphicNum < tempMoveLayer.graphics.length; graphicNum++) {

        //Comparing the selected graphic to the layer graphic currently in the loop
        if (tempMoveLayer.graphics[graphicNum].attributes.OBJECTID == results.features[j].attributes.OBJECTID) {

        //Activating the toolbar for the graphic. This is activated for every graphic in the loop
        moveToolbar.activate(esri.toolbars.Edit.MOVE | esri.toolbars.Edit.SCALE | esri.toolbars.Edit.ROTATE, tempMoveLayer.graphics[graphicNum]);

                                                            }
                                                        }
                                                    }
1

In ArcGIS JS API method activate() before activation graphic calls deactivate method. That why you cant activate multiple graphics.

I resolved this problem in such way:

- create array of graphics which i want to move (edited_array[])

- create polyline (edited_polyline). Using forEach() i create paths for polyline. Each path its a geometry point of edited_array[] graphic. If in this array(edited_array[]) you use polylines, polygons and other geometries, you can get first point(path, ring etc.) of geometry and create path for edited_polyline.

- next step its activation of edited_polyline

- you should to set 'graphic-move' listener on Edit tool

- while graphic moving in evetn you get field 'transform'. In this field stores object with 'dx' and 'dy' values. Its different between start graphic position and current position in screen points. You can compute new position for each graphics (edited_array[]) and redraw all graphics with new position.

In "https://jsfiddle.net/catcherholms/9e563hju/" i compute new coordinates while moving.

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.