zengh
2022-06-13 7973e449e74aab353d632e0db2937b376d45a6be
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
/**
 * 线测量工具
 * @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;
});