liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
///////////////////////////////////////////////////////////////////////////
// Copyright © 2019 jxdnosng All Rights Reserved.
// 模块描述:标记功能
///////////////////////////////////////////////////////////////////////////
define([
    "dojo/_base/declare",
    "dojo/_base/lang",
    'dojo/_base/html',
    "dojo/_base/fx",
    'jimu/BaseWidget',
    "dojo/topic",
    "dojo/Deferred",
    "dojo/on",
    "libs/layer/layer"
], function(
    declare,
    lang,
    html,
    fx,
    BaseWidget,
    topic,
    Deferred,
    on
) {
    return declare("Marker", [BaseWidget], {
        baseClass: "demo-widgets-Marker",
        postCreate: function() {
            this.inherited(arguments);
 
            this._tooltip = this.createTooltip(this.map.cesiumWidget.container);
        },
        createTooltip: function(frameDiv) {
 
            var tooltip = function(frameDiv) {
 
                var div = document.createElement('DIV');
                div.className = "twipsy right";
 
                var arrow = document.createElement('DIV');
                arrow.className = "twipsy-arrow";
                div.appendChild(arrow);
 
                var title = document.createElement('DIV');
                title.className = "twipsy-inner";
                div.appendChild(title);
 
                this._div = div;
                this._title = title;
 
                // add to frame div and display coordinates
                frameDiv.appendChild(div);
            }
 
            tooltip.prototype.setVisible = function(visible) {
                this._div.style.display = visible ? 'block' : 'none';
            }
 
            tooltip.prototype.showAt = function(position, message) {
                if(position && message) {
                    this.setVisible(true);
                    this._title.innerHTML = message;
                    this._div.style.left = position.x + 10 + "px";
                    this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
                }
            }
 
            return new tooltip(frameDiv);
        },
        destroy: function() {
 
            this.inherited(arguments);
        },
        click: function() {
            this.active = !this.active;
            if(this.active) {
                this._tooltip.setVisible(true);
            } else {
                this._tooltip.setVisible(false);
            }
 
            this.clearEntity();
        },
        active: false,
        startup: function() {
            this.inherited(arguments);
 
            var handler = new Cesium.ScreenSpaceEventHandler(window.viewer.scene.canvas);
 
            handler.setInputAction(
                lang.hitch(this, function(movement) {
                    if(!this.active) return;
                    var ellipsoid = window.viewer.scene.globe.ellipsoid;
                    var ellipsoid = Cesium.Ellipsoid.WGS84;
                    //                    var cartesian = window.viewer.scene.camera.pickEllipsoid(movement.position, ellipsoid);//两种的经纬度获取的不一样
                    var pickRay = window.viewer.scene.camera.getPickRay(movement.position);
                    var cartesian = window.viewer.scene.globe.pick(pickRay, window.viewer.scene);
 
                    if(cartesian) {
 
                        var cartographic = ellipsoid.cartesianToCartographic(cartesian);
                        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude); //.toFixed(2);
                        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude); //.toFixed(2);
 
                        this.points.push({
                            "lgtd": longitudeString,
                            "lttd": latitudeString
                        });
 
                        if(this.points.length == 2) {
                            //计算
                            var points = this.createHundryPoints(this.points);
                            //弹出
                            this.getData(points);
                            this.points = [];
                            this.active = false;
                            this._tooltip.setVisible(false);
                            this.bill2 = window.viewer.entities.add({
                                position: Cesium.Cartesian3.fromDegrees(longitudeString, latitudeString),
                                billboard: {
                                    image: "images/marker_green.png",
                                    pixelOffset: new Cesium.Cartesian2(0, 0),
                                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
                                }
                            });
                            return;
                        }
                        this.bill1 = window.viewer.entities.add({
                            position: Cesium.Cartesian3.fromDegrees(longitudeString, latitudeString),
                            billboard: {
                                image: "images/marker_green.png",
                                pixelOffset: new Cesium.Cartesian2(0, 0),
                                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
                            }
                        });
                    }
 
                }), Cesium.ScreenSpaceEventType.LEFT_CLICK);
 
            handler.setInputAction(
                lang.hitch(this, function(movement) {
                    if(!this.active) return;
                    if(this.points.length == 0) {
                        this._tooltip.showAt(movement.endPosition, "请获取起点");
                        return;
                    }
                    this._tooltip.showAt(movement.endPosition, "点击结束");
 
                }), Cesium.ScreenSpaceEventType.MOUSE_MOVE);
        },
        clearEntity: function() {
            window.viewer.entities.remove(this.bill1);
            window.viewer.entities.remove(this.bill2);
            window.viewer.entities.remove(this.line);
        },
        createHundryPoints: function(list) {
 
            var lgtd1 = list[0].lgtd;
            var lgtd100 = list[1].lgtd;
            var lgtdStep = (lgtd100 - lgtd1) / 1000;
 
            var lttd1 = list[0].lttd;
            var lttd100 = list[1].lttd;
            var lttdStep = (lttd100 - lttd1) / 1000;
            var ary = [];
            for(var i = 0; i < 1000; i++) {
                var lgtd = lgtd1 + (lgtdStep * i);
                var lttd = lttd1 + (lttdStep * i);
                ary.push({
                    "id": i,
                    "lgtd": lgtd,
                    "lttd": lttd
                });
            }
 
            return ary;
        },
        points: [],
        getData: function(ary) {
            var mappints = [];
            for(var j = 0; j < ary.length; j++) {
                var pt = ary[j];
                mappints.push({
                    lgtd: pt.lgtd,
                    lttd: pt.lttd,
                    height: 0
                });
            }
            //获取高程去
            this.makeChange(mappints).then(lang.hitch(this, function(list) {
                var ptsAry = [];
                var numbers_lgtd = [];
                var numbers_lttd = [];
                for(var j = 0; j < list.length; j++) {
                    var pt = list[j];
                    ptsAry.push(Number(pt.lgtd));
                    ptsAry.push(Number(pt.lttd));
                    ptsAry.push(Number(pt.height));
 
                    numbers_lgtd.push(Number(pt.lgtd));
                    numbers_lttd.push(Number(pt.lttd));
                }
 
                this.line = window.viewer.entities.add({
                    polyline: {
                        positions: Cesium.Cartesian3.fromDegreesArrayHeights(ptsAry),
                        width: 3,
                        material: new Cesium.PolylineOutlineMaterialProperty({
                            color: Cesium.Color.ORANGE,
                            outlineWidth: 1,
                            outlineColor: Cesium.Color.BLACK
                        })
                    }
                });
 
                layer.open({
                          type: 2,
                          title: '一键找河长',
                          shadeClose: true,
                          shade: false,
                          offset: '70px',
                          maxmin: true, //开启最大化最小化按钮
                          area: ['100%', 'calc(100% - 70px)'],
                          content: 'http://www.sw797.com:10011/gzsw3D/views/water/River_Len.html'
                        });
                
            }));
        },
        makeChange: function(datas) {
            var datas = datas;
            var def = new Deferred();
            var tIds = [];
            var pos = [];
            for(var i = 0; i < datas.length; i++) {
                var item = datas[i];
                tIds.push(item.id);
                pos.push(Cesium.Cartographic.fromDegrees(item.lgtd, item.lttd));
            }
            Cesium.sampleTerrain(window.viewer.terrainProvider, 9, pos).then(function(pos) { //去获取高程
                for(var i = 0; i < tIds.length; i++) {
                    datas[i].height = pos[i].height;
                }
                def.resolve(datas);
            });
            return def;
        }
    });
});