cesium_dev_kit 1.0.48 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +13 -0
- package/dist/ColorDeal.js +59 -0
- package/dist/common.js +40 -0
- package/dist/index.js +23 -13561
- package/dist/initConf.js +188 -0
- package/dist/libs/Analysis.js +779 -0
- package/dist/libs/Base.js +950 -0
- package/dist/libs/ChartLayer.js +24 -0
- package/dist/libs/Control.js +947 -0
- package/dist/libs/CustomCesiumPlugin.js +92 -0
- package/dist/libs/DomUtil.js +105 -0
- package/dist/libs/Draw.js +704 -0
- package/dist/libs/Graphics.js +734 -0
- package/dist/libs/MapvLayer.js +26 -0
- package/dist/libs/Material.js +590 -0
- package/dist/libs/Math2d.js +559 -0
- package/dist/libs/Math3d.js +646 -0
- package/dist/libs/PassEffect.js +154 -0
- package/dist/libs/Plugin.js +751 -0
- package/dist/libs/Primitive.js +1559 -0
- package/dist/libs/Shaders.js +298 -0
- package/dist/libs/ThreeJs.js +190 -0
- package/dist/libs/cesium-plugin.js +3387 -0
- package/dist/libs/index.js +117 -0
- package/dist/libs/plot/AttackArrow.js +266 -0
- package/dist/libs/plot/BasePlot.js +41 -0
- package/dist/libs/plot/PincerArrow.js +278 -0
- package/dist/libs/plot/StraightArrow.js +244 -0
- package/dist/libs/plot/algorithm.js +315 -0
- package/dist/libs/plot/index.js +19 -0
- package/dist/libs/plot/plotUtil.js +242 -0
- package/index.js +1 -1
- package/package.json +5 -12
- package/dist/index.min.js +0 -1
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Draw = Draw;
|
|
7
|
+
var _Graphics = require("./Graphics");
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
let Cesium = null;
|
|
14
|
+
/**
|
|
15
|
+
* 画笔模块
|
|
16
|
+
* @param {*} viewer
|
|
17
|
+
*/
|
|
18
|
+
function Draw(viewer, cesiumGlobal) {
|
|
19
|
+
if (viewer) {
|
|
20
|
+
Cesium = cesiumGlobal;
|
|
21
|
+
this._drawLayer = new Cesium.CustomDataSource('drawLayer');
|
|
22
|
+
this.$graphics = new _Graphics.Graphics(viewer, cesiumGlobal);
|
|
23
|
+
viewer && viewer.dataSources.add(this._drawLayer);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
Draw.prototype = {
|
|
27
|
+
/**
|
|
28
|
+
* 画点
|
|
29
|
+
* @param {*} options
|
|
30
|
+
*/
|
|
31
|
+
drawPointGraphics: function (options) {
|
|
32
|
+
options = options || {};
|
|
33
|
+
options.style = options.style || {
|
|
34
|
+
image: 'static/data/images/file/location4.png',
|
|
35
|
+
width: 35,
|
|
36
|
+
height: 40,
|
|
37
|
+
clampToGround: true,
|
|
38
|
+
scale: 1,
|
|
39
|
+
pixelOffset: new Cesium.Cartesian2(0, -20)
|
|
40
|
+
};
|
|
41
|
+
if (this._viewer && options) {
|
|
42
|
+
var _poiEntity = new Cesium.Entity(),
|
|
43
|
+
position,
|
|
44
|
+
positions = [],
|
|
45
|
+
poiObj,
|
|
46
|
+
$this = this,
|
|
47
|
+
_handlers = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
48
|
+
// left
|
|
49
|
+
_handlers.setInputAction(function (movement) {
|
|
50
|
+
var cartesian = $this._viewer.scene.camera.pickEllipsoid(movement.position, $this._viewer.scene.globe.ellipsoid);
|
|
51
|
+
if (cartesian && cartesian.x) {
|
|
52
|
+
position = cartesian;
|
|
53
|
+
positions.push(cartesian);
|
|
54
|
+
}
|
|
55
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
56
|
+
// right
|
|
57
|
+
_handlers.setInputAction(function (movement) {
|
|
58
|
+
_handlers.destroy();
|
|
59
|
+
_handlers = null;
|
|
60
|
+
if (typeof options.callback === 'function') {
|
|
61
|
+
options.callback($this.transformCartesianArrayToWGS84Array(positions), poiObj);
|
|
62
|
+
}
|
|
63
|
+
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
64
|
+
_poiEntity.billboard = options.style;
|
|
65
|
+
_poiEntity.position = new Cesium.CallbackProperty(function () {
|
|
66
|
+
return position;
|
|
67
|
+
}, false);
|
|
68
|
+
poiObj = this._drawLayer.entities.add(_poiEntity);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* 画线 or 测距
|
|
73
|
+
* @param {*} options
|
|
74
|
+
*/
|
|
75
|
+
drawLineGraphics: function (options) {
|
|
76
|
+
options = options || {};
|
|
77
|
+
if (this._viewer && options) {
|
|
78
|
+
var positions = [],
|
|
79
|
+
_lineEntity = new Cesium.Entity(),
|
|
80
|
+
$this = this,
|
|
81
|
+
lineObj,
|
|
82
|
+
_handlers = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
83
|
+
// left
|
|
84
|
+
_handlers.setInputAction(function (movement) {
|
|
85
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
86
|
+
if (cartesian && cartesian.x) {
|
|
87
|
+
if (positions.length == 0) {
|
|
88
|
+
positions.push(cartesian.clone());
|
|
89
|
+
}
|
|
90
|
+
if (options.measure) {
|
|
91
|
+
_addInfoPoint(cartesian);
|
|
92
|
+
}
|
|
93
|
+
// 绘制直线 两个点
|
|
94
|
+
if (positions.length == 2 && options.type === 'straightLine') {
|
|
95
|
+
_handlers.destroy();
|
|
96
|
+
_handlers = null;
|
|
97
|
+
if (typeof options.callback === 'function') {
|
|
98
|
+
options.callback($this.transformCartesianArrayToWGS84Array(positions), lineObj);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
positions.push(cartesian);
|
|
102
|
+
}
|
|
103
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
104
|
+
_handlers.setInputAction(function (movement) {
|
|
105
|
+
var cartesian = $this.getCatesian3FromPX(movement.endPosition);
|
|
106
|
+
if (positions.length >= 2) {
|
|
107
|
+
if (cartesian && cartesian.x) {
|
|
108
|
+
positions.pop();
|
|
109
|
+
positions.push(cartesian);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
113
|
+
// right
|
|
114
|
+
_handlers.setInputAction(function (movement) {
|
|
115
|
+
_handlers.destroy();
|
|
116
|
+
_handlers = null;
|
|
117
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
118
|
+
if (options.measure) {
|
|
119
|
+
_addInfoPoint(cartesian);
|
|
120
|
+
}
|
|
121
|
+
if (typeof options.callback === 'function') {
|
|
122
|
+
options.callback($this.transformCartesianArrayToWGS84Array(positions), lineObj);
|
|
123
|
+
}
|
|
124
|
+
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
125
|
+
_lineEntity.polyline = {
|
|
126
|
+
width: options.width || 5,
|
|
127
|
+
material: options.material || Cesium.Color.BLUE.withAlpha(0.8),
|
|
128
|
+
clampToGround: options.clampToGround || false,
|
|
129
|
+
clampToS3M: options.clampToS3M || false
|
|
130
|
+
};
|
|
131
|
+
_lineEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
|
132
|
+
return positions;
|
|
133
|
+
}, false);
|
|
134
|
+
lineObj = this._drawLayer.entities.add(_lineEntity);
|
|
135
|
+
|
|
136
|
+
//添加坐标点
|
|
137
|
+
const _addInfoPoint = function (position) {
|
|
138
|
+
var _labelEntity = new Cesium.Entity();
|
|
139
|
+
_labelEntity.position = position;
|
|
140
|
+
_labelEntity.point = {
|
|
141
|
+
pixelSize: 10,
|
|
142
|
+
outlineColor: Cesium.Color.BLUE,
|
|
143
|
+
outlineWidth: 5
|
|
144
|
+
};
|
|
145
|
+
_labelEntity.label = {
|
|
146
|
+
text: ($this.getPositionDistance($this.transformCartesianArrayToWGS84Array(positions)) / 1000).toFixed(4) + '公里',
|
|
147
|
+
show: true,
|
|
148
|
+
showBackground: true,
|
|
149
|
+
font: '14px monospace',
|
|
150
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
151
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
152
|
+
pixelOffset: new Cesium.Cartesian2(-20, -80) //left top
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
/**
|
|
160
|
+
* 画面 or 测面积
|
|
161
|
+
* @param {*} options
|
|
162
|
+
*/
|
|
163
|
+
drawPolygonGraphics: function (options) {
|
|
164
|
+
options = options || {};
|
|
165
|
+
options.style = options.style || {
|
|
166
|
+
width: 3,
|
|
167
|
+
material: Cesium.Color.BLUE.withAlpha(0.8),
|
|
168
|
+
clampToGround: true
|
|
169
|
+
};
|
|
170
|
+
if (this._viewer && options) {
|
|
171
|
+
var positions = [],
|
|
172
|
+
polygon = new Cesium.PolygonHierarchy(),
|
|
173
|
+
_polygonEntity = new Cesium.Entity(),
|
|
174
|
+
$this = this,
|
|
175
|
+
polyObj = null,
|
|
176
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
177
|
+
const create = function () {
|
|
178
|
+
_polygonEntity.polyline = options.style;
|
|
179
|
+
_polygonEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
|
180
|
+
return positions;
|
|
181
|
+
}, false);
|
|
182
|
+
_polygonEntity.polygon = {
|
|
183
|
+
hierarchy: new Cesium.CallbackProperty(function () {
|
|
184
|
+
return polygon;
|
|
185
|
+
}, false),
|
|
186
|
+
material: Cesium.Color.WHITE.withAlpha(0.1),
|
|
187
|
+
clampToGround: options.clampToGround || false
|
|
188
|
+
};
|
|
189
|
+
_polygonEntity.clampToS3M = true;
|
|
190
|
+
polyObj = $this._drawLayer.entities.add(_polygonEntity);
|
|
191
|
+
};
|
|
192
|
+
const _addInfoPoint = function (position) {
|
|
193
|
+
var _labelEntity = new Cesium.Entity();
|
|
194
|
+
_labelEntity.position = position;
|
|
195
|
+
_labelEntity.point = {
|
|
196
|
+
pixelSize: 10,
|
|
197
|
+
outlineColor: Cesium.Color.BLUE,
|
|
198
|
+
outlineWidth: 5
|
|
199
|
+
};
|
|
200
|
+
_labelEntity.label = {
|
|
201
|
+
text: ($this.getPositionsArea($this.transformCartesianArrayToWGS84Array(positions)) / 1000000.0).toFixed(4) + '平方公里',
|
|
202
|
+
show: true,
|
|
203
|
+
showBackground: true,
|
|
204
|
+
font: '14px monospace',
|
|
205
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
206
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
207
|
+
pixelOffset: new Cesium.Cartesian2(-20, -50) //left top
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
$this._drawLayer.entities.add(_labelEntity);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// left
|
|
214
|
+
_handler.setInputAction(function (movement) {
|
|
215
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
216
|
+
if (cartesian && cartesian.x) {
|
|
217
|
+
if (positions.length == 0) {
|
|
218
|
+
polygon.positions.push(cartesian.clone());
|
|
219
|
+
positions.push(cartesian.clone());
|
|
220
|
+
}
|
|
221
|
+
positions.push(cartesian.clone());
|
|
222
|
+
polygon.positions.push(cartesian.clone());
|
|
223
|
+
if (!polyObj) create();
|
|
224
|
+
}
|
|
225
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
226
|
+
// mouse
|
|
227
|
+
_handler.setInputAction(function (movement) {
|
|
228
|
+
var cartesian = $this.getCatesian3FromPX(movement.endPosition);
|
|
229
|
+
if (positions.length >= 2) {
|
|
230
|
+
if (cartesian && cartesian.x) {
|
|
231
|
+
positions.pop();
|
|
232
|
+
positions.push(cartesian);
|
|
233
|
+
polygon.positions.pop();
|
|
234
|
+
polygon.positions.push(cartesian);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
238
|
+
|
|
239
|
+
// right
|
|
240
|
+
_handler.setInputAction(function () {
|
|
241
|
+
_handler.destroy();
|
|
242
|
+
positions.push(positions[0]);
|
|
243
|
+
if (options.height) {
|
|
244
|
+
//立体
|
|
245
|
+
_polygonEntity.polygon.extrudedHeight = options.height;
|
|
246
|
+
_polygonEntity.polygon.material = Cesium.Color.BLUE.withAlpha(0.5);
|
|
247
|
+
}
|
|
248
|
+
if (options.measure) {
|
|
249
|
+
// 量测
|
|
250
|
+
_addInfoPoint(positions[0]);
|
|
251
|
+
}
|
|
252
|
+
if (typeof options.callback === 'function') {
|
|
253
|
+
options.callback($this.transformCartesianArrayToWGS84Array(positions), polyObj);
|
|
254
|
+
}
|
|
255
|
+
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
/**
|
|
259
|
+
* 画矩形
|
|
260
|
+
* @param {*} options
|
|
261
|
+
*/
|
|
262
|
+
drawRectangleGraphics: function (options) {
|
|
263
|
+
options = options || {};
|
|
264
|
+
options.style = options.style || {
|
|
265
|
+
width: 3,
|
|
266
|
+
material: Cesium.Color.BLUE.withAlpha(0.5),
|
|
267
|
+
clampToGround: true
|
|
268
|
+
};
|
|
269
|
+
if (this._viewer && options) {
|
|
270
|
+
var _positions = [],
|
|
271
|
+
_rectangleEntity = new Cesium.Entity(),
|
|
272
|
+
_coordinates = new Cesium.Rectangle(),
|
|
273
|
+
$this = this,
|
|
274
|
+
rectangleObj,
|
|
275
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
276
|
+
// left
|
|
277
|
+
_handler.setInputAction(function (movement) {
|
|
278
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
279
|
+
if (cartesian && cartesian.x) {
|
|
280
|
+
if (_positions.length == 0) {
|
|
281
|
+
_positions.push(cartesian.clone());
|
|
282
|
+
} else {
|
|
283
|
+
_handler.destroy();
|
|
284
|
+
_positions.push(cartesian.clone());
|
|
285
|
+
_coordinates = Cesium.Rectangle.fromCartesianArray([..._positions, cartesian], Cesium.Ellipsoid.WGS84);
|
|
286
|
+
if (typeof options.callback === 'function') {
|
|
287
|
+
options.callback($this.transformCartesianArrayToWGS84Array(_positions), rectangleObj);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
292
|
+
// mouse
|
|
293
|
+
_handler.setInputAction(function (movement) {
|
|
294
|
+
var cartesian = $this.getCatesian3FromPX(movement.endPosition);
|
|
295
|
+
if (cartesian) {
|
|
296
|
+
_coordinates = Cesium.Rectangle.fromCartesianArray([..._positions, cartesian], Cesium.Ellipsoid.WGS84);
|
|
297
|
+
}
|
|
298
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
299
|
+
_rectangleEntity.rectangle = options.style;
|
|
300
|
+
if (options.height) _rectangleEntity.rectangle.extrudedHeight = options.height;
|
|
301
|
+
_rectangleEntity.rectangle.coordinates = new Cesium.CallbackProperty(function () {
|
|
302
|
+
return _coordinates;
|
|
303
|
+
}, false);
|
|
304
|
+
rectangleObj = this._drawLayer.entities.add(_rectangleEntity);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
/**
|
|
308
|
+
* 画圆
|
|
309
|
+
* @param {*} options
|
|
310
|
+
*/
|
|
311
|
+
drawCircleGraphics: function (options) {
|
|
312
|
+
options = options || {};
|
|
313
|
+
options.style = options.style || {
|
|
314
|
+
width: 3,
|
|
315
|
+
material: Cesium.Color.BLUE.withAlpha(0.5),
|
|
316
|
+
clampToGround: true
|
|
317
|
+
};
|
|
318
|
+
if (this._viewer && options) {
|
|
319
|
+
var _center = undefined,
|
|
320
|
+
_circleEntity = new Cesium.Entity(),
|
|
321
|
+
$this = this,
|
|
322
|
+
circleObj,
|
|
323
|
+
_radius = 1,
|
|
324
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
325
|
+
|
|
326
|
+
// 计算半径
|
|
327
|
+
const computeRadius = function (src, dest) {
|
|
328
|
+
let srcCartographic = Cesium.Cartographic.fromCartesian(src);
|
|
329
|
+
let destCartographic = Cesium.Cartographic.fromCartesian(dest);
|
|
330
|
+
let geodesic = new Cesium.EllipsoidGeodesic();
|
|
331
|
+
geodesic.setEndPoints(srcCartographic, destCartographic);
|
|
332
|
+
let s = geodesic.surfaceDistance;
|
|
333
|
+
_radius = Math.sqrt(
|
|
334
|
+
//开平方
|
|
335
|
+
Math.pow(s, 2) + Math.pow(destCartographic.height - srcCartographic.height, 2));
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
//
|
|
339
|
+
const drawGraphics = function () {
|
|
340
|
+
_circleEntity.ellipse = options.style;
|
|
341
|
+
_circleEntity.ellipse.semiMajorAxis = new Cesium.CallbackProperty(function () {
|
|
342
|
+
return _radius;
|
|
343
|
+
}, false);
|
|
344
|
+
_circleEntity.ellipse.semiMinorAxis = new Cesium.CallbackProperty(function () {
|
|
345
|
+
return _radius;
|
|
346
|
+
}, false);
|
|
347
|
+
_circleEntity.position = new Cesium.CallbackProperty(function () {
|
|
348
|
+
return _center;
|
|
349
|
+
}, false);
|
|
350
|
+
_circleEntity.point = {
|
|
351
|
+
pixelSize: 5,
|
|
352
|
+
outlineColor: Cesium.Color.RED,
|
|
353
|
+
outlineWidth: 3
|
|
354
|
+
};
|
|
355
|
+
if (options.height) _circleEntity.ellipse.extrudedHeight = options.height;
|
|
356
|
+
circleObj = $this._drawLayer.entities.add(_circleEntity);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// left
|
|
360
|
+
_handler.setInputAction(function (movement) {
|
|
361
|
+
var cartesian = $this.getCatesian3FromPX(movement.position);
|
|
362
|
+
if (cartesian && cartesian.x) {
|
|
363
|
+
if (!_center) {
|
|
364
|
+
_center = cartesian;
|
|
365
|
+
drawGraphics();
|
|
366
|
+
} else {
|
|
367
|
+
computeRadius(_center, cartesian);
|
|
368
|
+
_handler.destroy();
|
|
369
|
+
if (typeof options.callback === 'function') {
|
|
370
|
+
options.callback({
|
|
371
|
+
center: _center,
|
|
372
|
+
radius: _radius
|
|
373
|
+
}, circleObj);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
378
|
+
// mouse
|
|
379
|
+
_handler.setInputAction(function (movement) {
|
|
380
|
+
var cartesian = $this._viewer.scene.camera.pickEllipsoid(movement.endPosition, $this._viewer.scene.globe.ellipsoid);
|
|
381
|
+
if (_center && cartesian && cartesian.x) {
|
|
382
|
+
computeRadius(_center, cartesian);
|
|
383
|
+
}
|
|
384
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
/**
|
|
388
|
+
* 画三角量测
|
|
389
|
+
* @param {*} options
|
|
390
|
+
*/
|
|
391
|
+
drawTrianglesGraphics: function (options) {
|
|
392
|
+
options = options || {};
|
|
393
|
+
options.style = options.style || {
|
|
394
|
+
width: 3,
|
|
395
|
+
material: Cesium.Color.BLUE.withAlpha(0.5)
|
|
396
|
+
};
|
|
397
|
+
if (this._viewer && options) {
|
|
398
|
+
var _trianglesEntity = new Cesium.Entity(),
|
|
399
|
+
_tempLineEntity = new Cesium.Entity(),
|
|
400
|
+
_tempLineEntity2 = new Cesium.Entity(),
|
|
401
|
+
_positions = [],
|
|
402
|
+
_tempPoints = [],
|
|
403
|
+
_tempPoints2 = [],
|
|
404
|
+
$this = this,
|
|
405
|
+
_handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
|
|
406
|
+
|
|
407
|
+
// 高度
|
|
408
|
+
const _getHeading = function (startPosition, endPosition) {
|
|
409
|
+
if (!startPosition && !endPosition) return 0;
|
|
410
|
+
if (Cesium.Cartesian3.equals(startPosition, endPosition)) return 0;
|
|
411
|
+
let cartographic = Cesium.Cartographic.fromCartesian(startPosition);
|
|
412
|
+
let cartographic2 = Cesium.Cartographic.fromCartesian(endPosition);
|
|
413
|
+
return (cartographic2.height - cartographic.height).toFixed(2);
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// 偏移点
|
|
417
|
+
const _computesHorizontalLine = function (positions) {
|
|
418
|
+
let cartographic = Cesium.Cartographic.fromCartesian(positions[0]);
|
|
419
|
+
let cartographic2 = Cesium.Cartographic.fromCartesian(positions[1]);
|
|
420
|
+
return Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), cartographic2.height);
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// left
|
|
424
|
+
_handler.setInputAction(function (movement) {
|
|
425
|
+
var position = $this.getCatesian3FromPX(movement.position);
|
|
426
|
+
if (!position) return false;
|
|
427
|
+
if (_positions.length == 0) {
|
|
428
|
+
_positions.push(position.clone());
|
|
429
|
+
_positions.push(position.clone());
|
|
430
|
+
_tempPoints.push(position.clone());
|
|
431
|
+
_tempPoints.push(position.clone());
|
|
432
|
+
} else {
|
|
433
|
+
_handler.destroy();
|
|
434
|
+
if (typeof options.callback === 'function') {
|
|
435
|
+
options.callback({
|
|
436
|
+
e: _trianglesEntity,
|
|
437
|
+
e2: _tempLineEntity,
|
|
438
|
+
e3: _tempLineEntity2
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
443
|
+
// mouse
|
|
444
|
+
_handler.setInputAction(function (movement) {
|
|
445
|
+
var position = $this.getCatesian3FromPX(movement.endPosition);
|
|
446
|
+
if (position && _positions.length > 0) {
|
|
447
|
+
//直线
|
|
448
|
+
_positions.pop();
|
|
449
|
+
_positions.push(position.clone());
|
|
450
|
+
let horizontalPosition = _computesHorizontalLine(_positions);
|
|
451
|
+
//高度
|
|
452
|
+
_tempPoints.pop();
|
|
453
|
+
_tempPoints.push(horizontalPosition.clone());
|
|
454
|
+
//水平线
|
|
455
|
+
_tempPoints2.pop(), _tempPoints2.pop();
|
|
456
|
+
_tempPoints2.push(position.clone());
|
|
457
|
+
_tempPoints2.push(horizontalPosition.clone());
|
|
458
|
+
}
|
|
459
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
460
|
+
|
|
461
|
+
// create entity
|
|
462
|
+
|
|
463
|
+
//直线
|
|
464
|
+
_trianglesEntity.polyline = _objectSpread({
|
|
465
|
+
positions: new Cesium.CallbackProperty(function () {
|
|
466
|
+
return _positions;
|
|
467
|
+
}, false)
|
|
468
|
+
}, options.style);
|
|
469
|
+
_trianglesEntity.position = new Cesium.CallbackProperty(function () {
|
|
470
|
+
return _positions[0];
|
|
471
|
+
}, false);
|
|
472
|
+
_trianglesEntity.point = {
|
|
473
|
+
pixelSize: 5,
|
|
474
|
+
outlineColor: Cesium.Color.BLUE,
|
|
475
|
+
outlineWidth: 5
|
|
476
|
+
};
|
|
477
|
+
_trianglesEntity.label = {
|
|
478
|
+
text: new Cesium.CallbackProperty(function () {
|
|
479
|
+
return '直线:' + $this.getPositionDistance($this.transformCartesianArrayToWGS84Array(_positions)) + '米';
|
|
480
|
+
}, false),
|
|
481
|
+
show: true,
|
|
482
|
+
showBackground: true,
|
|
483
|
+
font: '14px monospace',
|
|
484
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
485
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
486
|
+
pixelOffset: new Cesium.Cartesian2(50, -100) //left top
|
|
487
|
+
};
|
|
488
|
+
//高度
|
|
489
|
+
_tempLineEntity.polyline = _objectSpread({
|
|
490
|
+
positions: new Cesium.CallbackProperty(function () {
|
|
491
|
+
return _tempPoints;
|
|
492
|
+
}, false)
|
|
493
|
+
}, options.style);
|
|
494
|
+
_tempLineEntity.position = new Cesium.CallbackProperty(function () {
|
|
495
|
+
return _tempPoints2[1];
|
|
496
|
+
}, false);
|
|
497
|
+
_tempLineEntity.point = {
|
|
498
|
+
pixelSize: 5,
|
|
499
|
+
outlineColor: Cesium.Color.BLUE,
|
|
500
|
+
outlineWidth: 5
|
|
501
|
+
};
|
|
502
|
+
_tempLineEntity.label = {
|
|
503
|
+
text: new Cesium.CallbackProperty(function () {
|
|
504
|
+
return '高度:' + _getHeading(_tempPoints[0], _tempPoints[1]) + '米';
|
|
505
|
+
}, false),
|
|
506
|
+
show: true,
|
|
507
|
+
showBackground: true,
|
|
508
|
+
font: '14px monospace',
|
|
509
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
510
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
511
|
+
pixelOffset: new Cesium.Cartesian2(-20, 100) //left top
|
|
512
|
+
};
|
|
513
|
+
//水平
|
|
514
|
+
_tempLineEntity2.polyline = _objectSpread({
|
|
515
|
+
positions: new Cesium.CallbackProperty(function () {
|
|
516
|
+
return _tempPoints2;
|
|
517
|
+
}, false)
|
|
518
|
+
}, options.style);
|
|
519
|
+
_tempLineEntity2.position = new Cesium.CallbackProperty(function () {
|
|
520
|
+
return _positions[1];
|
|
521
|
+
}, false);
|
|
522
|
+
_tempLineEntity2.point = {
|
|
523
|
+
pixelSize: 5,
|
|
524
|
+
outlineColor: Cesium.Color.BLUE,
|
|
525
|
+
outlineWidth: 5
|
|
526
|
+
};
|
|
527
|
+
_tempLineEntity2.label = {
|
|
528
|
+
text: new Cesium.CallbackProperty(function () {
|
|
529
|
+
return '水平距离:' + $this.getPositionDistance($this.transformCartesianArrayToWGS84Array(_tempPoints2)) + '米';
|
|
530
|
+
}, false),
|
|
531
|
+
show: true,
|
|
532
|
+
showBackground: true,
|
|
533
|
+
font: '14px monospace',
|
|
534
|
+
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
|
|
535
|
+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
536
|
+
pixelOffset: new Cesium.Cartesian2(-150, -20) //left top
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
this._drawLayer.entities.add(_tempLineEntity2);
|
|
540
|
+
this._drawLayer.entities.add(_tempLineEntity);
|
|
541
|
+
this._drawLayer.entities.add(_trianglesEntity);
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
/**
|
|
545
|
+
* 画围栏
|
|
546
|
+
* @param {*} options
|
|
547
|
+
*/
|
|
548
|
+
drawWallGraphics: function (options) {
|
|
549
|
+
options = options || {};
|
|
550
|
+
options.style = options.style || {
|
|
551
|
+
material: Cesium.Color.BLUE.withAlpha(0.5),
|
|
552
|
+
outline: true,
|
|
553
|
+
outlineColor: Cesium.Color.WHITE
|
|
554
|
+
};
|
|
555
|
+
if (this._viewer && options) {
|
|
556
|
+
var $this = this;
|
|
557
|
+
this.drawPolygonGraphics({
|
|
558
|
+
callback: function (polygon, polygonObj) {
|
|
559
|
+
var wallEntity = $this._drawLayer.entities.add({
|
|
560
|
+
wall: _objectSpread({
|
|
561
|
+
positions: $this.transformWGS84ArrayToCartesianArray(polygon)
|
|
562
|
+
}, options.style)
|
|
563
|
+
});
|
|
564
|
+
if (typeof options.callback === 'function') {
|
|
565
|
+
options.callback(polygon, wallEntity);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
/**
|
|
572
|
+
* 绘制球体
|
|
573
|
+
* @param {*} options
|
|
574
|
+
*/
|
|
575
|
+
drawEllipsoidGraphics: function (options) {
|
|
576
|
+
options = options || {};
|
|
577
|
+
options.style = options.style || {};
|
|
578
|
+
if (this._viewer && options) {
|
|
579
|
+
var $this = this;
|
|
580
|
+
this.drawCircleGraphics({
|
|
581
|
+
callback: function (result, obj) {
|
|
582
|
+
var entity = $this.createGraphics();
|
|
583
|
+
entity.ellipsoid = $this.$graphics.getEllipsoidGraphics({
|
|
584
|
+
radii: result.radius
|
|
585
|
+
});
|
|
586
|
+
entity.position = result.center;
|
|
587
|
+
$this._drawLayer.entities.remove(obj);
|
|
588
|
+
var ellipsoidObj = $this._drawLayer.entities.add(entity);
|
|
589
|
+
if (typeof options.callback === 'function') {
|
|
590
|
+
options.callback({
|
|
591
|
+
center: result.center,
|
|
592
|
+
radius: result.radius
|
|
593
|
+
}, ellipsoidObj);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
/**
|
|
600
|
+
* 绘制圆柱体 or 圆锥
|
|
601
|
+
* @param {*} options
|
|
602
|
+
*/
|
|
603
|
+
drawCylinderGraphics: function (options) {
|
|
604
|
+
options = options || {};
|
|
605
|
+
options.style = options.style || {};
|
|
606
|
+
if (this._viewer && options) {
|
|
607
|
+
var $this = this;
|
|
608
|
+
this.drawCircleGraphics({
|
|
609
|
+
callback: function (result, obj) {
|
|
610
|
+
var cylinderObj = $this._drawLayer.entities.add({
|
|
611
|
+
position: result.center,
|
|
612
|
+
cylinder: {
|
|
613
|
+
length: result.radius * 2 || options.length,
|
|
614
|
+
topRadius: options.topRadius || result.radius,
|
|
615
|
+
bottomRadius: options.bottomRadius || result.radius,
|
|
616
|
+
material: Cesium.Color.BLUE.withAlpha(0.5),
|
|
617
|
+
outline: true,
|
|
618
|
+
outlineColor: Cesium.Color.WHITE
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
$this._drawLayer.entities.remove(obj);
|
|
622
|
+
if (typeof options.callback === 'function') {
|
|
623
|
+
options.callback({
|
|
624
|
+
center: result.center,
|
|
625
|
+
radius: result.radius
|
|
626
|
+
}, cylinderObj);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
/**
|
|
633
|
+
* 绘制走廊
|
|
634
|
+
* @param {*} options
|
|
635
|
+
*/
|
|
636
|
+
drawCorridorGraphics: function (options) {
|
|
637
|
+
options = options || {};
|
|
638
|
+
options.style = options.style || {};
|
|
639
|
+
if (this._viewer && options) {
|
|
640
|
+
var $this = this;
|
|
641
|
+
$this.drawLineGraphics({
|
|
642
|
+
callback: function (line, lineObj) {
|
|
643
|
+
var entity = $this.createGraphics();
|
|
644
|
+
entity.corridor = {
|
|
645
|
+
positions: $this.transformWGS84ArrayToCartesianArray(line),
|
|
646
|
+
height: options.height || 1,
|
|
647
|
+
width: options.width || 100,
|
|
648
|
+
cornerType: Cesium.CornerType.BEVELED,
|
|
649
|
+
extrudedHeight: options.extrudedHeight || 1,
|
|
650
|
+
material: Cesium.Color.BLUE.withAlpha(0.5),
|
|
651
|
+
outline: true,
|
|
652
|
+
// height required for outlines to display
|
|
653
|
+
outlineColor: Cesium.Color.WHITE
|
|
654
|
+
};
|
|
655
|
+
$this._drawLayer.entities.remove(lineObj);
|
|
656
|
+
var corridorObj = $this._drawLayer.entities.add(entity);
|
|
657
|
+
if (typeof options.callback === 'function') {
|
|
658
|
+
options.callback(line, corridorObj);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
/**
|
|
665
|
+
* 绘制管道
|
|
666
|
+
* @param {*} options
|
|
667
|
+
* {
|
|
668
|
+
* color:颜色,
|
|
669
|
+
* style:样式,
|
|
670
|
+
* circleRadius:圆形管道半径
|
|
671
|
+
* arms:五角管道指数
|
|
672
|
+
* rOuter:五角管道外圆半径
|
|
673
|
+
* rInner:五角管道内圆半径
|
|
674
|
+
* }
|
|
675
|
+
*/
|
|
676
|
+
drawPolylineVolumeGraphics: function (options) {
|
|
677
|
+
options = options || {};
|
|
678
|
+
options.style = options.style || {};
|
|
679
|
+
const circleRadius = options.circleRadius || 20,
|
|
680
|
+
arms = options.arms || 7,
|
|
681
|
+
rOuter = options.rOuter || 150,
|
|
682
|
+
rInner = options.rInner || 75;
|
|
683
|
+
if (this._viewer && options) {
|
|
684
|
+
var $this = this;
|
|
685
|
+
$this.drawLineGraphics({
|
|
686
|
+
callback: function (line, lineObj) {
|
|
687
|
+
var entity = $this.createGraphics();
|
|
688
|
+
let shapeVal = options.shape === 'fivePoint' ? $this.computeStar2d(arms, rOuter, rInner) : $this.computeCircleShap(circleRadius);
|
|
689
|
+
entity.polylineVolume = {
|
|
690
|
+
positions: $this.transformWGS84ArrayToCartesianArray(line),
|
|
691
|
+
shape: shapeVal,
|
|
692
|
+
cornerType: Cesium.CornerType.MITERED,
|
|
693
|
+
material: options.color || Cesium.Color.RED
|
|
694
|
+
};
|
|
695
|
+
$this._drawLayer.entities.remove(lineObj);
|
|
696
|
+
var polylineVolumeObj = $this._drawLayer.entities.add(entity);
|
|
697
|
+
if (typeof options.callback === 'function') {
|
|
698
|
+
options.callback(line, polylineVolumeObj);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
};
|