| New file |
| | |
| | | /** |
| | | * 线测量工具 |
| | | * @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], { |
| | | _lineresulttooltip: null, |
| | | graphic: null, |
| | | _symbol: null, |
| | | constructor: function(args) { |
| | | this._normalIconClass = "tool-measureline-normal"; |
| | | this._overIconClass = "tool-measureline-over"; |
| | | this._selectedIconClass = "tool-measureline-select"; |
| | | this._drawType = Draw.POLYLINE; |
| | | this.tooltip = "量距离"; |
| | | this._symbol = RendererUtil.createSymbol({ |
| | | type: "SimpleLineSymbol", |
| | | width: 2, |
| | | color: "#FD8044" |
| | | }); |
| | | }, |
| | | postCreate: function() { |
| | | this.inherited(arguments); |
| | | this._isDrawOnece = false; |
| | | this._lineresulttooltip = new TooltipDialog({ |
| | | id: '_lineresulttooltip', |
| | | content: "<span id='measurelineresultspan'>测量结果:</span>" |
| | | }); |
| | | }, |
| | | onDrawEnd: function(geom) { |
| | | this.inherited(arguments); |
| | | geom.spatialReference.wkid = 4326; |
| | | var results = geodesicUtils.geodesicLengths([geom], Units.METERS); |
| | | var result = results[0]; |
| | | if(result > 1000) { |
| | | dom.byId("measurelineresultspan").innerHTML = "测量结果:" + (result / 1000).toFixed(3) + "公里"; |
| | | } else { |
| | | dom.byId("measurelineresultspan").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._lineresulttooltip, |
| | | around: this.domNode |
| | | }); |
| | | dom.byId("measurelineresultspan").innerHTML = "测量结果:"; |
| | | }, |
| | | deactivate: function() { |
| | | this.inherited(arguments); |
| | | popup.close(this._lineresulttooltip); |
| | | this.map.graphics.remove(this.graphic); |
| | | this.graphic = null; |
| | | }, |
| | | }); |
| | | return RL; |
| | | }); |