Unable to edit a "Extent" Draw Tool

1731
7
Jump to solution
10-10-2016 03:04 PM
PriyaRam
New Contributor III

I'm trying to edit an extent graphic using the EditTool and I'm getting the following error.

activeEditToolbars(evt) {

if (this.editingEnabled) {
this.editingEnabled = false;
this.edittoolbar.deactivate();

}
else {
this.editingEnabled = true;
this.edittoolbar.activate(Edit.EDIT_VERTICES|Edit.MOVE, evt.graphic);

}
}

Uncaught Error: [esri.toolbars.Edit::activate] Unable to activate the tool. Check if the tool is valid for the given geometry type.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
7 Replies
RobertScheitlin__GISP
MVP Emeritus

Priya,

  Editing a extents vertices is not allowed because that would change the geometry type to a polygon. You can only scale, move and rotate.

PriyaRam
New Contributor III

Hi Robert - That makes sense. Yet, I'm still having problems with the scale,move operations . Please advise. (Error Message:[esri.toolbars.Edit::activate] Unable to activate the tool. Check if the tool is valid for the given geometry type.)

activeEditToolbars(evt) {

if (this.editingEnabled) {
this.editingEnabled = false;
this.edittoolbar.deactivate();

}
else {
this.editingEnabled = true;
if(evt.graphic.geometry.type === "extent") {
this.edittoolbar.activate(Edit.MOVE|Edit.SCALE, evt.graphic);
}
else {
this.edittoolbar.activate(Edit.EDIT_VERTICES|Edit.MOVE, evt.graphic);
}

}
}

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Priya,

   What happens if you only include Edit.MOVE?

0 Kudos
PriyaRam
New Contributor III

Robert - It's the same issue, as stated above.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Priya,

   I have to apologize as it seems that the Extent Geometry type is not a supported type for any operation in the edit toolbar. If you want to do anything with an extent you must first convert it to a polygon.

0 Kudos
PriyaRam
New Contributor III

Hi Robert - That's good to know.

Please see,if this function looks okay for constructing a polygon.I'm getting an error, Cannot read property 'spatialReference' of undefined.should I update the geometry ? Any samples is much appreciated.

if(evt.graphic.geometry.type === "extent") {
//console.log("evt.graphic",evt.graphic);
let tempPoly = this.convertExtentToPolygon(evt.graphic,new SpatialReference({wkid:102100}));
console.log(tempPoly.geometry);
this.edittoolbar.activate(Edit.MOVE, tempPoly);
}

convertExtentToPolygon (extent, spatialRef) {
const xmin = extent.xmin;
const xmax = extent.xmax;
const ymin = extent.ymin;
const ymax = extent.ymax;

const topLeft = new MapPoint(xmin, ymax, spatialRef);
const topRight = new MapPoint(xmax, ymax, spatialRef);
const bottomRight = new MapPoint(xmax, ymin, spatialRef);
const bottomLeft = new MapPoint(xmin, ymin, spatialRef);

var rings = new Array(topLeft, topRight, bottomRight, bottomLeft, topLeft);

var newPolygon = new Polygon(spatialRef);
newPolygon.addRing(rings);
return newPolygon;
}

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Priya,

  You should just use the Polygons fromExtent method:

Polygon | API Reference | ArcGIS API for JavaScript 3.18 | fromExtent