Hi. I would like to add text graphic on the map to add informations about the dimensions of the polygon which is selected when the EditToolBar is selected.
To do that I use dojo.connect(this.editToolbar,'onGraphicClick',function(feature,info)
How, inside this function can I write graphics in a GraphicLayer ? Indeed It seems that I cannot "reach" the variable of the graphicLayer I created on widget startup (undefined dimensionGraphicLayer) ?
_activateEditToolbar: function (feature) {
var layer = feature.getLayer();
if (this.editToolbar.getCurrentState().tool !== 0) {
this.editToolbar.deactivate();
}
switch (layer.geometryType) {
case "esriGeometryPoint":
this.editToolbar.activate(Edit.MOVE, feature);
break;
case "esriGeometryPolyline":
case "esriGeometryPolygon":
/*jslint bitwise: true*/
this.editToolbar.activate(Edit.EDIT_VERTICES |
Edit.MOVE |
Edit.ROTATE |
Edit.SCALE, feature);
/*jslint bitwise: false*/
/*draw text graphics on the polygon */
dojo.connect(this.editToolbar,'onGraphicClick',function(feature,info){
var distanceUnits = "meters";
var pgeometry = feature.geometry;
var pspatialReference = pgeometry.spatialReference
var prings = pgeometry.rings;
/*list that stores the point to place the graphics*/
var listePointMedian = [];
/*list that stores the distance to display*/
var listeDistance = [];
prings.forEach(function(pring,index){
var indexvertice = 0;
while (indexvertice < pring.length - 1) {
var pdepart = pring[indexvertice];
var xDepart = pdepart[0];
var yDepart = pdepart[1];
var pointDepart = new Point(xDepart,yDepart,pspatialReference);
indexSuivant = indexvertice+1;
var parrivee = pring[indexSuivant];
var xArrivee = parrivee[0];
var yArrivee = parrivee[1];
var pointArrivee = new Point(xArrivee,yArrivee,pspatialReference);
var xMedian = (xDepart + xArrivee)/2;
var yMedian = (yDepart + yArrivee)/2;
var pointMedian = new Point(xMedian,yMedian,pspatialReference);
listePointMedian.push(pointMedian);
var geometryService = new GeometryService("https://....../arcgis/rest/services/Utilities/Geometry/GeometryServer");
var distParams = new DistanceParameters();
distParams.distanceUnit = esri.tasks.GeometryService.UNIT_KILOMETER;
distParams.geometry1 = pointDepart;
distParams.geometry2 = pointArrivee;
distParams.geodesic = true;
geometryService.distance(distParams, function(distance) {
result = distance;
listeDistance.push(result);
});
indexvertice++;
}
});
});
break;
}
},