1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
| /**
| * 面测量工具
| * @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: "<span id='measurepolygonresultspan'>测量结果:</span>"
| });
| /* 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 = 4326;
| 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;
| });
|
|