/** * 面测量工具 * @author 温杨彪 2015-9-13 **/ define([ "dojo/_base/declare", "controls/toolbar/tools/DrawBaseTool", "esri/toolbars/draw", "dojo/dom-style", "dijit/TooltipDialog", "dijit/popup", "esri/geometry/geometryEngine", "dojo/dom", "base/utils/RendererUtil", "esri/graphic", "esri/geometry/geodesicUtils", "esri/units" ], function( declare, DrawBaseTool, Draw, domStyle, TooltipDialog, popup, geometryEngine, dom, RendererUtil, Graphic, geodesicUtils, Units ) { var RL = declare([DrawBaseTool], { _tooltip: null, graphic: null, _symbol: null, constructor: function(args) { this._normalIconClass = "tool-measurepolygon-normal"; this._overIconClass = "tool-measurepolygon-over"; this._selectedIconClass = "tool-measurepolygon-select"; this._drawType = Draw.POLYGON; this.tooltip = "测量面积"; this._symbol = RendererUtil.createSymbol({ type: "SimpleFillSymbol", "outline": { style: "solid", width: 2, alpha: 0.5, color: "#FD8044" }, width: 2, alpha: 0.5, color: "#FD8044" }); }, postCreate: function() { this.inherited(arguments); this._isDrawOnece = false; this._tooltip = new TooltipDialog({ id: '_polygonresulttooltip', content: "测量结果:" }); /* domStyle.set(this.tool, "border-top-right-radius", "5px"); domStyle.set(this.tool, "border-bottom-right-radius", "5px"); domStyle.set(this.tool, "margin-right", "10px");*/ }, onDrawEnd: function(geom) { this.inherited(arguments); geom.spatialReference.wkid = 4490; var results = geodesicUtils.geodesicAreas([geom], Units.SQUARE_METERS); var result = results[0]; if(result > 100000000) { dom.byId("measurepolygonresultspan").innerHTML = "测量结果:" + (result / 1000000).toFixed(2) + "平方千米"; } else if(result > 10000) { dom.byId("measurepolygonresultspan").innerHTML = "测量结果:" + (result / 10000).toFixed(2) + "公顷"; } else { dom.byId("measurepolygonresultspan").innerHTML = "测量结果:" + result.toFixed(0) + "平方米"; } if(this.graphic != null) { this.graphic.setGeometry(geom); } else { this.graphic = new Graphic(geom, this._symbol); this.map.graphics.add(this.graphic); } }, activate: function() { this.inherited(arguments); dijit.Tooltip.defaultPosition = ["below"]; popup.open({ popup: this._tooltip, around: this.domNode }); dom.byId("measurepolygonresultspan").innerHTML = "测量结果:"; }, deactivate: function() { this.inherited(arguments); popup.close(this._tooltip); this.map.graphics.remove(this.graphic); this.graphic = null; }, }); return RL; });