@go-home-early/go-home-early98 0.3.1 → 0.3.3
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/README.md +53 -24
- package/dist/go-home-early.umd.js +5 -5
- package/package.json +4 -18
- package/src/packages/Cesium/DrawMap/DrawJs/CesiumEntityEdit.js +427 -0
- package/src/packages/Cesium/DrawMap/DrawJs/CreatePolygonOnGround.js +202 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawAttackArrow.js +477 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawBillboard.js +114 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawCircle.js +311 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawCircleTY.js +237 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawCurve.js +256 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPincerArrow.js +584 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPoint.js +158 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPolygon.js +215 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPolyline.js +213 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawPolylineJT.js +218 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawProFile.js +314 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawRectangle.js +215 -0
- package/src/packages/Cesium/DrawMap/DrawJs/DrawstraightArrow.js +364 -0
- package/src/packages/Cesium/DrawMap/DrawJs/MeasurePolygon.js +337 -0
- package/src/packages/Cesium/DrawMap/DrawJs/MeasurePolyline.js +285 -0
- package/src/packages/Cesium/DrawMap/DrawJs/ReminderTip.js +78 -0
- package/src/packages/Cesium/DrawMap/DrawJs/SlopeAspect.js +436 -0
- package/src/packages/Cesium/DrawMap/DrawJs/measureLength.js +177 -0
- package/src/packages/Cesium/DrawMap/index.vue +272 -0
- package/src/packages/Cesium/components/LocationDialog.vue +283 -0
- package/src/packages/Cesium/components/Popup.vue +591 -0
- package/src/packages/Cesium/components/PoumianDialog.vue +200 -0
- package/src/packages/Cesium/imgs/add-off.png +0 -0
- package/src/packages/Cesium/imgs/add.png +0 -0
- package/src/packages/Cesium/imgs/circle.png +0 -0
- package/src/packages/Cesium/imgs/icon-position-blue.png +0 -0
- package/src/packages/Cesium/imgs/line.png +0 -0
- package/src/packages/Cesium/imgs/map-delete.png +0 -0
- package/src/packages/Cesium/imgs/map.png +0 -0
- package/src/packages/Cesium/imgs/orientation-bg.svg +14 -0
- package/src/packages/Cesium/imgs/orientation.svg +21 -0
- package/src/packages/Cesium/imgs/poi.png +0 -0
- package/src/packages/Cesium/imgs/point.png +0 -0
- package/src/packages/Cesium/imgs/polygon.png +0 -0
- package/src/packages/Cesium/imgs/popup/back-popup-img.png +0 -0
- package/src/packages/Cesium/imgs/popup/backimg-btn.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-bd.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-btn.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-ft.png +0 -0
- package/src/packages/Cesium/imgs/popup/dialog-hd.png +0 -0
- package/src/packages/Cesium/imgs/reduce-off.png +0 -0
- package/src/packages/Cesium/index.md +292 -0
- package/src/packages/Cesium/index.vue +3830 -0
- package/src/packages/Cesium/materials/CircularDiffusionMaterialProperty.js +98 -0
- package/src/packages/Cesium/materials/CircularRippleMaterialProperty.js +126 -0
- package/src/packages/Cesium/materials/PolylineArrowMaterialProperty.js +109 -0
- package/src/packages/Cesium/utils/MeasureHeight.js +261 -0
- package/src/packages/Cesium/utils/MeasureTools.js +1188 -0
- package/src/packages/index.js +33 -0
- package/src/packages/utils/charts.js +54 -0
- package/src/packages/utils/index.js +50 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
绘制图标
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
class DrawBillboard {
|
|
6
|
+
constructor(arg) {
|
|
7
|
+
this.objId = Number(
|
|
8
|
+
new Date().getTime() + "" + Number(Math.random() * 1000).toFixed(0)
|
|
9
|
+
);
|
|
10
|
+
this.viewer = arg.viewer;
|
|
11
|
+
this.Cesium = arg.Cesium;
|
|
12
|
+
this.handler = null;
|
|
13
|
+
this._billboard = null;
|
|
14
|
+
this._billboardData = null; //点数据用于构造billboard
|
|
15
|
+
this._entities = [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//返回最后活动点
|
|
19
|
+
get billboard() {
|
|
20
|
+
return this._billboard;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//返回点数据用于加载billboard
|
|
24
|
+
getData() {
|
|
25
|
+
return this._billboardData;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//加载图标
|
|
29
|
+
loadBillboard(data) {
|
|
30
|
+
return this.createBillboard(data);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
startCreate() {
|
|
34
|
+
var $this = this;
|
|
35
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
36
|
+
this.viewer.scene.canvas
|
|
37
|
+
);
|
|
38
|
+
this.handler.setInputAction(function (evt) {
|
|
39
|
+
//单机开始绘制
|
|
40
|
+
var cartesian = $this.getCatesian3FromPX(evt.position);
|
|
41
|
+
if (!cartesian) return;
|
|
42
|
+
var billboard = $this.createBillboard(cartesian);
|
|
43
|
+
$this._billboardData = cartesian;
|
|
44
|
+
$this._billboard = billboard;
|
|
45
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 创建点击删除事件
|
|
49
|
+
creatDeleteClick(isSelect) {
|
|
50
|
+
const $this = this;
|
|
51
|
+
if (isSelect) {
|
|
52
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
53
|
+
$this.viewer.scene.canvas
|
|
54
|
+
);
|
|
55
|
+
this.handler.setInputAction(function (movement) {
|
|
56
|
+
var pick = $this.viewer.scene.pick(movement.position, 3, 3);
|
|
57
|
+
|
|
58
|
+
if (!pick) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
$this.viewer.entities.removeById(pick.id._id);
|
|
62
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
63
|
+
} else {
|
|
64
|
+
this.handler.destroy();
|
|
65
|
+
this.handler = null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//创建图标
|
|
70
|
+
createBillboard(cartesian) {
|
|
71
|
+
var img = require("../../assets/mark4.png");
|
|
72
|
+
var $this = this;
|
|
73
|
+
var billboard = this.viewer.entities.add({
|
|
74
|
+
position: cartesian,
|
|
75
|
+
billboard: {
|
|
76
|
+
image: img,
|
|
77
|
+
scale: 1,
|
|
78
|
+
horizontalOrigin: $this.Cesium.HorizontalOrigin.CENTER,
|
|
79
|
+
verticalOrigin: $this.Cesium.VerticalOrigin.BOTTOM,
|
|
80
|
+
heightReference: $this.Cesium.HeightReference.CLAMP_TO_GROUND,
|
|
81
|
+
disableDepthTestDistance: Number.MAX_VALUE,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
billboard.objId = this.objId;
|
|
85
|
+
$this._entities.push(billboard); //加载脏数据
|
|
86
|
+
return billboard;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
destroy() {
|
|
90
|
+
if (this.handler) {
|
|
91
|
+
this.handler.destroy();
|
|
92
|
+
this.handler = null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//清空实体对象
|
|
97
|
+
clear() {
|
|
98
|
+
for (var i = 0; i < this._entities.length; i++) {
|
|
99
|
+
this.viewer.entities.remove(this._entities[i]);
|
|
100
|
+
}
|
|
101
|
+
this._billboard = null;
|
|
102
|
+
this._billboardData = null;
|
|
103
|
+
this._entities = [];
|
|
104
|
+
}
|
|
105
|
+
getCatesian3FromPX(px) {
|
|
106
|
+
var cartesian;
|
|
107
|
+
var ray = this.viewer.camera.getPickRay(px);
|
|
108
|
+
if (!ray) return null;
|
|
109
|
+
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
|
|
110
|
+
return cartesian;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default DrawBillboard;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/*
|
|
2
|
+
绘制圆
|
|
3
|
+
*/
|
|
4
|
+
import * as turf from '@turf/turf';
|
|
5
|
+
class DrawCircle {
|
|
6
|
+
constructor(arg) {
|
|
7
|
+
this.drawName = 'DrawCircle';
|
|
8
|
+
this.viewer = arg.viewer;
|
|
9
|
+
this.Cesium = arg.Cesium;
|
|
10
|
+
this.Text = arg.data.text || '';
|
|
11
|
+
this.Color = arg.data.color || '#000';
|
|
12
|
+
this.imgUrl = arg.data.imgUrl || '';
|
|
13
|
+
this.FontSize = arg.data.fontSize || 16;
|
|
14
|
+
this.callback = arg.data.callback || null;
|
|
15
|
+
this.pxNum = arg.data.pxNum || 5;
|
|
16
|
+
this.handler = null;
|
|
17
|
+
this._cicle = null; // 活动圆
|
|
18
|
+
this.floatingPoint = null;
|
|
19
|
+
this._cicleLast = null; // 最后一个圆
|
|
20
|
+
this._positions = []; // 活动点
|
|
21
|
+
this._entities_point = []; // 脏数据
|
|
22
|
+
this._entities_cicle = []; // 脏数据
|
|
23
|
+
this._cicleData = null; // 用于构造圆形数据
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get cicle() {
|
|
27
|
+
return this._cicleLast;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 修改样式
|
|
31
|
+
updateStyleFunction(data) {
|
|
32
|
+
this.Text = data.text || '';
|
|
33
|
+
this.Color = data.color || '#000';
|
|
34
|
+
this.imgUrl = data.imgUrl || '';
|
|
35
|
+
this.FontSize = data.fontSize || 16;
|
|
36
|
+
this.callback = data.callback || null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 加载圆
|
|
40
|
+
loadCicle(data) {
|
|
41
|
+
for (var i = 0; i < this._entities_point.length; i++) {
|
|
42
|
+
this.viewer.entities.remove(this._entities_point[i]);
|
|
43
|
+
}
|
|
44
|
+
var that = this;
|
|
45
|
+
var position = data[0];
|
|
46
|
+
var value = data;
|
|
47
|
+
var r = Math.sqrt(
|
|
48
|
+
Math.pow(value[0].x - value[value.length - 1].x, 2) +
|
|
49
|
+
Math.pow(value[0].y - value[value.length - 1].y, 2)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
var shape = this.viewer.entities.add({
|
|
53
|
+
position: position,
|
|
54
|
+
name: 'circle',
|
|
55
|
+
type: 'circle',
|
|
56
|
+
ellipse: {
|
|
57
|
+
semiMinorAxis: r,
|
|
58
|
+
semiMajorAxis: r,
|
|
59
|
+
material: that.Cesium.Color.fromCssColorString(that.Color),
|
|
60
|
+
outline: true,
|
|
61
|
+
clampToGround: true
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return shape;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 返回数据
|
|
68
|
+
getData() {
|
|
69
|
+
return this._cicleData;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
startCreate() {
|
|
73
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
74
|
+
this.viewer.scene.canvas
|
|
75
|
+
);
|
|
76
|
+
this.viewer.scene.globe.depthTestAgainstTerrain = true; // 启动深度测试,确保绘制的时候不会穿过地形表面
|
|
77
|
+
|
|
78
|
+
var $this = this;
|
|
79
|
+
this.handler.setInputAction(function(evt) {
|
|
80
|
+
// 单机开始绘制
|
|
81
|
+
$this.viewer.scene.globe.depthTestAgainstTerrain = true;
|
|
82
|
+
// 屏幕坐标转地形上坐标
|
|
83
|
+
var cartesian = $this.getCatesian3FromPX(evt.position);
|
|
84
|
+
if ($this._positions.length == 0) {
|
|
85
|
+
$this._positions.push(cartesian.clone());
|
|
86
|
+
$this.floatingPoint = $this.createPoint(cartesian);
|
|
87
|
+
}
|
|
88
|
+
if (!$this._cicle) {
|
|
89
|
+
$this.createPoint(cartesian); // 绘制点
|
|
90
|
+
}
|
|
91
|
+
$this._positions.push(cartesian);
|
|
92
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
93
|
+
|
|
94
|
+
this.handler.setInputAction(function(evt) {
|
|
95
|
+
// 移动时绘制圆
|
|
96
|
+
if ($this._positions.length < 1) return;
|
|
97
|
+
var cartesian = $this.viewer.scene.pickPosition(evt.endPosition); // $this.getCatesian3FromPX(evt.endPosition);
|
|
98
|
+
if (!$this.Cesium.defined($this._cicle)) {
|
|
99
|
+
$this._cicle = $this.createCicle();
|
|
100
|
+
}
|
|
101
|
+
$this.floatingPoint.position.setValue(cartesian);
|
|
102
|
+
if ($this._cicle) {
|
|
103
|
+
// 因为有时候获取移动的点会出现undefined导致报错,所以在这里控制住
|
|
104
|
+
if (cartesian.x && cartesian.y && cartesian.z) {
|
|
105
|
+
$this._positions.pop();
|
|
106
|
+
$this._positions.push(cartesian);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}, $this.Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
110
|
+
|
|
111
|
+
this.handler.setInputAction(function(evt) {
|
|
112
|
+
if (!$this._cicle) return;
|
|
113
|
+
$this.viewer.scene.globe.depthTestAgainstTerrain = false;
|
|
114
|
+
var cartesian = $this.viewer.scene.pickPosition(evt.position); // $this.getCatesian3FromPX(evt.position);
|
|
115
|
+
$this._positions.pop();
|
|
116
|
+
$this._positions.push(cartesian);
|
|
117
|
+
$this._cicleData = $this._positions.concat();
|
|
118
|
+
$this.viewer.entities.remove($this._cicle); // 移除
|
|
119
|
+
$this._cicle = null;
|
|
120
|
+
$this._positions = [];
|
|
121
|
+
$this.floatingPoint.position.setValue(cartesian);
|
|
122
|
+
var cicle = $this.loadCicle($this._cicleData); // 加载
|
|
123
|
+
$this._entities_cicle.push(cicle);
|
|
124
|
+
$this._cicleLast = cicle;
|
|
125
|
+
$this.clearPoint();
|
|
126
|
+
if (typeof $this.callback == 'function') {
|
|
127
|
+
var entity = cicle;
|
|
128
|
+
|
|
129
|
+
if (entity.ellipse) {
|
|
130
|
+
// 获取圆形实体的中心点和半径
|
|
131
|
+
var center = entity.position.getValue($this.Cesium.JulianDate.now());
|
|
132
|
+
// 获取圆形实体的中心点
|
|
133
|
+
|
|
134
|
+
// 将中心点坐标转换为经纬度坐标
|
|
135
|
+
var cartographic = $this.Cesium.Cartographic.fromCartesian(center);
|
|
136
|
+
var longitude = $this.Cesium.Math.toDegrees(cartographic.longitude);
|
|
137
|
+
var latitude = $this.Cesium.Math.toDegrees(cartographic.latitude);
|
|
138
|
+
var radius = entity.ellipse.semiMajorAxis.getValue(
|
|
139
|
+
$this.Cesium.JulianDate.now()
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
// 将半径从米转换为度
|
|
143
|
+
radius /= 1000;
|
|
144
|
+
|
|
145
|
+
// 定义圆形的细分度数
|
|
146
|
+
var subdivisions = 64;
|
|
147
|
+
|
|
148
|
+
// 创建圆形的多边形逼近
|
|
149
|
+
// 中心点坐标用的是经纬度,实体拿到的事笛卡尔坐标
|
|
150
|
+
// 半径用的单位是公里,实体拿到的事米
|
|
151
|
+
var circle = turf.circle([longitude, latitude], radius, {
|
|
152
|
+
steps: subdivisions,
|
|
153
|
+
units: 'kilometers'
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// 创建 GeoJSON 对象
|
|
157
|
+
var geojson = {
|
|
158
|
+
type: 'Feature',
|
|
159
|
+
geometry: circle.geometry,
|
|
160
|
+
properties: {
|
|
161
|
+
color: $this.Color
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
$this.callback(geojson);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// var position1 = $this._cicleData[0];
|
|
169
|
+
// const value = $this._cicleData;
|
|
170
|
+
// const r = Math.sqrt(
|
|
171
|
+
// Math.pow(value[0].x - value[value.length - 1].x, 2) +
|
|
172
|
+
// Math.pow(value[0].y - value[value.length - 1].y, 2)
|
|
173
|
+
// );
|
|
174
|
+
|
|
175
|
+
// // 创建圆形的坐标集合
|
|
176
|
+
// const coordinates = [];
|
|
177
|
+
|
|
178
|
+
// // 定义圆形的细分度数
|
|
179
|
+
// const subdivisions = 64;
|
|
180
|
+
|
|
181
|
+
// for (let i = 0; i <= subdivisions; i++) {
|
|
182
|
+
// const theta = (i / subdivisions) * (2 * Math.PI);
|
|
183
|
+
// const x = position1.x + r * Math.cos(theta);
|
|
184
|
+
// const y = position1.y + r * Math.sin(theta);
|
|
185
|
+
// position1 = new Cesium.Cartesian3(x, y, position1.z);
|
|
186
|
+
|
|
187
|
+
// const cartographic = Cesium.Cartographic.fromCartesian(position1);
|
|
188
|
+
// const longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
|
189
|
+
// const latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
|
190
|
+
|
|
191
|
+
// coordinates.push([longitude, latitude]);
|
|
192
|
+
// }
|
|
193
|
+
|
|
194
|
+
// // 创建GeoJSON对象;
|
|
195
|
+
// var geojson = {
|
|
196
|
+
// type: 'Polygon',
|
|
197
|
+
// coordinates: [coordinates],
|
|
198
|
+
// color: $this.Color
|
|
199
|
+
// };
|
|
200
|
+
|
|
201
|
+
// $this.callback(geojson);
|
|
202
|
+
|
|
203
|
+
// console.log(geojson);
|
|
204
|
+
}
|
|
205
|
+
// $this.handler.destroy();
|
|
206
|
+
}, $this.Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 创建圆
|
|
210
|
+
createCicle() {
|
|
211
|
+
var that = this;
|
|
212
|
+
var shape = this.viewer.entities.add({
|
|
213
|
+
position: that._positions[0],
|
|
214
|
+
name: 'circle',
|
|
215
|
+
type: 'circle',
|
|
216
|
+
ellipse: {
|
|
217
|
+
semiMinorAxis: new that.Cesium.CallbackProperty(function() {
|
|
218
|
+
// 半径 两点间距离
|
|
219
|
+
var r = Math.sqrt(
|
|
220
|
+
Math.pow(
|
|
221
|
+
that._positions[0].x -
|
|
222
|
+
that._positions[that._positions.length - 1].x,
|
|
223
|
+
2
|
|
224
|
+
) +
|
|
225
|
+
Math.pow(
|
|
226
|
+
that._positions[0].y -
|
|
227
|
+
that._positions[that._positions.length - 1].y,
|
|
228
|
+
2
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
return r || r + 1;
|
|
232
|
+
}, false),
|
|
233
|
+
semiMajorAxis: new that.Cesium.CallbackProperty(function() {
|
|
234
|
+
var r = Math.sqrt(
|
|
235
|
+
Math.pow(
|
|
236
|
+
that._positions[0].x -
|
|
237
|
+
that._positions[that._positions.length - 1].x,
|
|
238
|
+
2
|
|
239
|
+
) +
|
|
240
|
+
Math.pow(
|
|
241
|
+
that._positions[0].y -
|
|
242
|
+
that._positions[that._positions.length - 1].y,
|
|
243
|
+
2
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
return r || r + 1;
|
|
247
|
+
}, false),
|
|
248
|
+
material:
|
|
249
|
+
that.Cesium.Color.fromCssColorString('#ffffff').withAlpha(0.5),
|
|
250
|
+
outline: true,
|
|
251
|
+
clampToGround: true
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
that._entities_cicle.push(shape);
|
|
255
|
+
return shape;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// 创建点
|
|
259
|
+
createPoint(cartesian) {
|
|
260
|
+
var $this = this;
|
|
261
|
+
var point = this.viewer.entities.add({
|
|
262
|
+
position: cartesian,
|
|
263
|
+
point: {
|
|
264
|
+
pixelSize: 10,
|
|
265
|
+
color: $this.Cesium.Color.YELLOW
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
$this._entities_point.push(point);
|
|
269
|
+
return point;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
getCatesian3FromPX(px) {
|
|
273
|
+
var cartesian;
|
|
274
|
+
var ray = this.viewer.camera.getPickRay(px);
|
|
275
|
+
if (!ray) return null;
|
|
276
|
+
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
|
|
277
|
+
return cartesian;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
destroy() {
|
|
281
|
+
if (this.handler) {
|
|
282
|
+
this.handler.destroy();
|
|
283
|
+
this.handler = null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
clearPoint() {
|
|
288
|
+
for (var i = 0; i < this._entities_point.length; i++) {
|
|
289
|
+
this.viewer.entities.remove(this._entities_point[i]);
|
|
290
|
+
}
|
|
291
|
+
this._entities_point = []; // 脏数据
|
|
292
|
+
}
|
|
293
|
+
clear() {
|
|
294
|
+
for (let i = 0; i < this._entities_point.length; i++) {
|
|
295
|
+
this.viewer.entities.remove(this._entities_point[i]);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
for (let i = 0; i < this._entities_cicle.length; i++) {
|
|
299
|
+
this.viewer.entities.remove(this._entities_cicle[i]);
|
|
300
|
+
}
|
|
301
|
+
this._cicle = null; // 活动圆
|
|
302
|
+
this.floatingPoint = null;
|
|
303
|
+
this._cicleLast = null; // 最后一个圆
|
|
304
|
+
this._positions = []; // 活动点
|
|
305
|
+
this._entities_point = []; // 脏数据
|
|
306
|
+
this._entities_cicle = []; // 脏数据
|
|
307
|
+
this._cicleData = null; // 用于构造圆形数据
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export default DrawCircle;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/*
|
|
2
|
+
绘制椭圆
|
|
3
|
+
*/
|
|
4
|
+
class DrawCircle {
|
|
5
|
+
constructor(arg) {
|
|
6
|
+
this.viewer = arg.viewer;
|
|
7
|
+
this.Cesium = arg.Cesium;
|
|
8
|
+
this.Text = arg.data.text || "";
|
|
9
|
+
this.Color = arg.data.color || "#000";
|
|
10
|
+
this.imgUrl = arg.data.imgUrl || "";
|
|
11
|
+
this.FontSize = arg.data.fontSize || 16;
|
|
12
|
+
this.callback = arg.data.callback || null;
|
|
13
|
+
this.pxNum = arg.data.pxNum || 5;
|
|
14
|
+
this.handler = null;
|
|
15
|
+
this._cicle = null; // 活动圆
|
|
16
|
+
this.floatingPoint = null;
|
|
17
|
+
this._cicleLast = null; // 最后一个圆
|
|
18
|
+
this._positions = []; // 活动点
|
|
19
|
+
this._entities_point = []; // 脏数据
|
|
20
|
+
this._entities_cicle = []; // 脏数据
|
|
21
|
+
this._cicleData = null; // 用于构造圆形数据
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get cicle() {
|
|
25
|
+
return this._cicleLast;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 加载椭圆
|
|
29
|
+
loadEllipse(data) {
|
|
30
|
+
var that = this;
|
|
31
|
+
var position = data[0];
|
|
32
|
+
var value = data;
|
|
33
|
+
var semiMajorAxis = Math.sqrt(
|
|
34
|
+
Math.pow(value[1].x - value[0].x, 2) +
|
|
35
|
+
Math.pow(value[1].y - value[0].y, 2)
|
|
36
|
+
);
|
|
37
|
+
var semiMinorAxis = semiMajorAxis * value[2].z; // 设置短轴为长轴的比例
|
|
38
|
+
var shape = this.viewer.entities.add({
|
|
39
|
+
position: position,
|
|
40
|
+
name: "ellipse",
|
|
41
|
+
type: "ellipse",
|
|
42
|
+
ellipse: {
|
|
43
|
+
semiMinorAxis: semiMinorAxis,
|
|
44
|
+
semiMajorAxis: semiMajorAxis,
|
|
45
|
+
material: that.Cesium.Color.fromCssColorString(that.Color),
|
|
46
|
+
outline: true,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return shape;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 返回数据
|
|
53
|
+
getData() {
|
|
54
|
+
return this._cicleData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
startCreateEllipse() {
|
|
58
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
59
|
+
this.viewer.scene.canvas
|
|
60
|
+
);
|
|
61
|
+
this.viewer.scene.globe.depthTestAgainstTerrain = true;
|
|
62
|
+
var $this = this;
|
|
63
|
+
this.handler.setInputAction(function (evt) {
|
|
64
|
+
// 单机开始绘制
|
|
65
|
+
$this.viewer.scene.globe.depthTestAgainstTerrain = true;
|
|
66
|
+
// 屏幕坐标转地形上坐标
|
|
67
|
+
var cartesian = $this.getCatesian3FromPX(evt.position);
|
|
68
|
+
if ($this._positions.length == 0) {
|
|
69
|
+
$this._positions.push(cartesian.clone());
|
|
70
|
+
$this.floatingPoint = $this.createPoint(cartesian);
|
|
71
|
+
}
|
|
72
|
+
if (!$this._ellipse && $this._positions.length == 2) {
|
|
73
|
+
$this.createPoint(cartesian); // 绘制点
|
|
74
|
+
}
|
|
75
|
+
if ($this._positions.length == 3) {
|
|
76
|
+
$this._positions.pop(); // 只需要3个点,弹出最后一个点
|
|
77
|
+
$this._ellipseData = $this._positions.concat();
|
|
78
|
+
var ellipse = $this.loadEllipse($this._ellipseData); // 加载椭圆
|
|
79
|
+
$this._entities_ellipse.push(ellipse);
|
|
80
|
+
$this._ellipseLast = ellipse;
|
|
81
|
+
$this.clearPoint();
|
|
82
|
+
if (typeof $this.callback == "function") {
|
|
83
|
+
$this.callback(ellipse);
|
|
84
|
+
}
|
|
85
|
+
$this.handler.destroy();
|
|
86
|
+
}
|
|
87
|
+
$this._positions.push(cartesian);
|
|
88
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
89
|
+
this.handler.setInputAction(function (evt) {
|
|
90
|
+
// 移动时绘制椭圆
|
|
91
|
+
if ($this._positions.length < 2) return;
|
|
92
|
+
var cartesian = $this.viewer.scene.pickPosition(evt.endPosition); // $this.getCatesian3FromPX(evt.endPosition);
|
|
93
|
+
if (!$this._ellipse) {
|
|
94
|
+
$this.createPoint(cartesian); // 绘制点
|
|
95
|
+
}
|
|
96
|
+
if ($this._positions.length == 3) {
|
|
97
|
+
$this.viewer.entities.remove($this.floatingPoint); // 移除浮动点
|
|
98
|
+
$this.floatingPoint = null;
|
|
99
|
+
$this.clearPoint();
|
|
100
|
+
$this._positions.pop(); // 只需要3个点,弹出最后一个点
|
|
101
|
+
$this._ellipseData = $this._positions.concat();
|
|
102
|
+
var ellipse = $this.loadEllipse($this._ellipseData); // 加载椭圆
|
|
103
|
+
$this._entities_ellipse.push(ellipse);
|
|
104
|
+
$this._ellipseLast = ellipse;
|
|
105
|
+
if (typeof $this.callback == "function") {
|
|
106
|
+
$this.callback(ellipse);
|
|
107
|
+
}
|
|
108
|
+
$this.handler.destroy();
|
|
109
|
+
}
|
|
110
|
+
$this.floatingPoint.position.setValue(cartesian); // 更新浮动点的位置
|
|
111
|
+
$this._positions[$this._positions.length - 1] = cartesian; // 更新最后一个点的位置
|
|
112
|
+
}, $this.Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 创建点击删除事件
|
|
116
|
+
creatDeleteClick(isSelect) {
|
|
117
|
+
const $this = this;
|
|
118
|
+
if (isSelect) {
|
|
119
|
+
this.handler = new this.Cesium.ScreenSpaceEventHandler(
|
|
120
|
+
$this.viewer.scene.canvas
|
|
121
|
+
);
|
|
122
|
+
this.handler.setInputAction(function (movement) {
|
|
123
|
+
var pick = $this.viewer.scene.pick(movement.position, 3, 3);
|
|
124
|
+
|
|
125
|
+
if (!pick) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
$this.viewer.entities.removeById(pick.id._id);
|
|
129
|
+
}, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
130
|
+
} else {
|
|
131
|
+
this.handler.destroy();
|
|
132
|
+
this.handler = null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 创建圆
|
|
137
|
+
createCicle() {
|
|
138
|
+
var that = this;
|
|
139
|
+
var shape = this.viewer.entities.add({
|
|
140
|
+
position: that._positions[0],
|
|
141
|
+
name: "circle",
|
|
142
|
+
type: "circle",
|
|
143
|
+
ellipse: {
|
|
144
|
+
semiMinorAxis: new that.Cesium.CallbackProperty(function () {
|
|
145
|
+
// 半径 两点间距离
|
|
146
|
+
var r = Math.sqrt(
|
|
147
|
+
Math.pow(
|
|
148
|
+
that._positions[0].x -
|
|
149
|
+
that._positions[that._positions.length - 1].x,
|
|
150
|
+
2
|
|
151
|
+
) +
|
|
152
|
+
Math.pow(
|
|
153
|
+
that._positions[0].y -
|
|
154
|
+
that._positions[that._positions.length - 1].y,
|
|
155
|
+
2
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
return r || r + 1;
|
|
159
|
+
}, false),
|
|
160
|
+
semiMajorAxis: new that.Cesium.CallbackProperty(function () {
|
|
161
|
+
var r = Math.sqrt(
|
|
162
|
+
Math.pow(
|
|
163
|
+
that._positions[0].x -
|
|
164
|
+
that._positions[that._positions.length - 1].x,
|
|
165
|
+
2
|
|
166
|
+
) +
|
|
167
|
+
Math.pow(
|
|
168
|
+
that._positions[0].y -
|
|
169
|
+
that._positions[that._positions.length - 1].y,
|
|
170
|
+
2
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
return r || r + 1;
|
|
174
|
+
}, false),
|
|
175
|
+
material:
|
|
176
|
+
that.Cesium.Color.fromCssColorString("#ffffff").withAlpha(0.5),
|
|
177
|
+
outline: true,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
that._entities_cicle.push(shape);
|
|
181
|
+
return shape;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 创建点
|
|
185
|
+
createPoint(cartesian) {
|
|
186
|
+
var $this = this;
|
|
187
|
+
var point = this.viewer.entities.add({
|
|
188
|
+
position: cartesian,
|
|
189
|
+
point: {
|
|
190
|
+
pixelSize: 10,
|
|
191
|
+
color: $this.Cesium.Color.YELLOW,
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
$this._entities_point.push(point);
|
|
195
|
+
return point;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
getCatesian3FromPX(px) {
|
|
199
|
+
var cartesian;
|
|
200
|
+
var ray = this.viewer.camera.getPickRay(px);
|
|
201
|
+
if (!ray) return null;
|
|
202
|
+
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
|
|
203
|
+
return cartesian;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
destroy() {
|
|
207
|
+
if (this.handler) {
|
|
208
|
+
this.handler.destroy();
|
|
209
|
+
this.handler = null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
clearPoint() {
|
|
214
|
+
for (var i = 0; i < this._entities_point.length; i++) {
|
|
215
|
+
this.viewer.entities.remove(this._entities_point[i]);
|
|
216
|
+
}
|
|
217
|
+
this._entities_point = []; // 脏数据
|
|
218
|
+
}
|
|
219
|
+
clear() {
|
|
220
|
+
for (var i = 0; i < this._entities_point.length; i++) {
|
|
221
|
+
this.viewer.entities.remove(this._entities_point[i]);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
for (var i = 0; i < this._entities_cicle.length; i++) {
|
|
225
|
+
this.viewer.entities.remove(this._entities_cicle[i]);
|
|
226
|
+
}
|
|
227
|
+
this._cicle = null; // 活动圆
|
|
228
|
+
this.floatingPoint = null;
|
|
229
|
+
this._cicleLast = null; // 最后一个圆
|
|
230
|
+
this._positions = []; // 活动点
|
|
231
|
+
this._entities_point = []; // 脏数据
|
|
232
|
+
this._entities_cicle = []; // 脏数据
|
|
233
|
+
this._cicleData = null; // 用于构造圆形数据
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export default DrawCircle;
|