@go-home-early/go-home-early98 0.3.1 → 0.3.2
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 +28 -16
- package/dist/go-home-early.umd.js +5 -5
- package/package.json +2 -16
- 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
package/README.md
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
# go-home-early
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
```
|
|
5
|
-
npm
|
|
3
|
+
# 1 安装
|
|
4
|
+
```js
|
|
5
|
+
1. npm i @go-home-early/go-home-early98
|
|
6
|
+
2. 此组件库依赖cesium和element-ui,如果没有安装请执行以下命令
|
|
7
|
+
npm i cesium@1.95 element-ui
|
|
6
8
|
```
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
npm run serve
|
|
11
|
-
```
|
|
10
|
+
# 2 快速配置
|
|
12
11
|
|
|
13
|
-
### Compiles and minifies for production
|
|
14
|
-
```
|
|
15
|
-
npm run build
|
|
16
12
|
```
|
|
13
|
+
1 import GoHomeEarly from '@go-home-early/go-home-early98'
|
|
14
|
+
Vue.use(GoHomeEarly)
|
|
15
|
+
2 在vue.config.js中添加如下配置
|
|
16
|
+
|
|
17
|
+
const Path = require("path");
|
|
18
|
+
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
19
|
+
const webpack = require('webpack');
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
configureWebpack: {
|
|
22
|
+
plugins: [
|
|
23
|
+
new CopyWebpackPlugin({
|
|
24
|
+
patterns: [
|
|
25
|
+
{ from: Path.resolve('./node_modules/cesium/Source/Workers'), to: 'Workers' },
|
|
26
|
+
{ from: Path.resolve('./node_modules/cesium/Source/Assets'), to: 'Assets' },
|
|
27
|
+
{ from: Path.resolve('./node_modules/cesium/Source/Widgets'), to: 'Widgets' },
|
|
28
|
+
{ from: Path.resolve('./node_modules/cesium/Source/ThirdParty/Workers'), to: 'ThirdParty/Workers' }
|
|
29
|
+
]
|
|
30
|
+
}),
|
|
31
|
+
new webpack.DefinePlugin({
|
|
32
|
+
CESIUM_BASE_URL: JSON.stringify('./')
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
}
|
|
21
36
|
```
|
|
22
|
-
|
|
23
|
-
### Customize configuration
|
|
24
|
-
See [Configuration Reference](https://cli.vuejs.org/config/).
|
|
@@ -42236,7 +42236,7 @@ if (typeof window !== 'undefined') {
|
|
|
42236
42236
|
// Indicate to webpack that this file can be concatenated
|
|
42237
42237
|
/* harmony default export */ var setPublicPath = (null);
|
|
42238
42238
|
|
|
42239
|
-
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"
|
|
42239
|
+
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"01d304bc-vue-loader-template"}!./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/packages/Cesium/index.vue?vue&type=template&id=ec7fecf6&scoped=true
|
|
42240
42240
|
var Cesiumvue_type_template_id_ec7fecf6_scoped_true_render = function render() {
|
|
42241
42241
|
var _vm = this,
|
|
42242
42242
|
_c = _vm._self._c;
|
|
@@ -417681,7 +417681,7 @@ function CesiumNavigation_initialize(viewerCesiumWidget, options) {
|
|
|
417681
417681
|
|
|
417682
417682
|
/* harmony default export */ var dist_CesiumNavigation = (CesiumNavigation);
|
|
417683
417683
|
|
|
417684
|
-
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"
|
|
417684
|
+
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"01d304bc-vue-loader-template"}!./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/packages/Cesium/DrawMap/index.vue?vue&type=template&id=37acc99b&scoped=true
|
|
417685
417685
|
var DrawMapvue_type_template_id_37acc99b_scoped_true_render = function render() {
|
|
417686
417686
|
var _vm = this,
|
|
417687
417687
|
_c = _vm._self._c;
|
|
@@ -422392,7 +422392,7 @@ var component = normalizeComponent(
|
|
|
422392
422392
|
var terraformer_wkt_parser = __webpack_require__("5a1f");
|
|
422393
422393
|
var terraformer_wkt_parser_default = /*#__PURE__*/__webpack_require__.n(terraformer_wkt_parser);
|
|
422394
422394
|
|
|
422395
|
-
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"
|
|
422395
|
+
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"01d304bc-vue-loader-template"}!./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/packages/Cesium/components/Popup.vue?vue&type=template&id=3cb00216&scoped=true
|
|
422396
422396
|
var Popupvue_type_template_id_3cb00216_scoped_true_render = function render() {
|
|
422397
422397
|
var _vm = this,
|
|
422398
422398
|
_c = _vm._self._c;
|
|
@@ -422756,7 +422756,7 @@ var Popup_component = normalizeComponent(
|
|
|
422756
422756
|
)
|
|
422757
422757
|
|
|
422758
422758
|
/* harmony default export */ var Popup = (Popup_component.exports);
|
|
422759
|
-
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"
|
|
422759
|
+
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"01d304bc-vue-loader-template"}!./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/packages/Cesium/components/LocationDialog.vue?vue&type=template&id=8660a454&scoped=true
|
|
422760
422760
|
var LocationDialogvue_type_template_id_8660a454_scoped_true_render = function render() {
|
|
422761
422761
|
var _vm = this,
|
|
422762
422762
|
_c = _vm._self._c;
|
|
@@ -423191,7 +423191,7 @@ var LocationDialog_component = normalizeComponent(
|
|
|
423191
423191
|
)
|
|
423192
423192
|
|
|
423193
423193
|
/* harmony default export */ var LocationDialog = (LocationDialog_component.exports);
|
|
423194
|
-
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"
|
|
423194
|
+
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"01d304bc-vue-loader-template"}!./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/packages/Cesium/components/PoumianDialog.vue?vue&type=template&id=854b6d14&scoped=true
|
|
423195
423195
|
var PoumianDialogvue_type_template_id_854b6d14_scoped_true_render = function render() {
|
|
423196
423196
|
var _vm = this,
|
|
423197
423197
|
_c = _vm._self._c;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@go-home-early/go-home-early98",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/go-home-early.umd.js",
|
|
6
6
|
"description": "text-components",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
|
-
"packages",
|
|
9
|
+
"src/packages",
|
|
10
10
|
"README.md"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
@@ -42,20 +42,6 @@
|
|
|
42
42
|
"eslint-plugin-vue": "^6.2.2",
|
|
43
43
|
"vue-template-compiler": "^2.6.11"
|
|
44
44
|
},
|
|
45
|
-
"eslintConfig": {
|
|
46
|
-
"root": true,
|
|
47
|
-
"env": {
|
|
48
|
-
"node": true
|
|
49
|
-
},
|
|
50
|
-
"extends": [
|
|
51
|
-
"plugin:vue/essential",
|
|
52
|
-
"eslint:recommended"
|
|
53
|
-
],
|
|
54
|
-
"parserOptions": {
|
|
55
|
-
"parser": "babel-eslint"
|
|
56
|
-
},
|
|
57
|
-
"rules": {}
|
|
58
|
-
},
|
|
59
45
|
"browserslist": [
|
|
60
46
|
"> 1%",
|
|
61
47
|
"last 2 versions",
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import * as turf from '@turf/turf';
|
|
2
|
+
import * as Cesium from 'cesium';
|
|
3
|
+
|
|
4
|
+
class CesiumEntityEdit {
|
|
5
|
+
constructor(viewer, options) {
|
|
6
|
+
this.viewer = viewer;
|
|
7
|
+
this.options = options || {};
|
|
8
|
+
this.selectedEntity = null; // 被选择的实体对象
|
|
9
|
+
this.handler = null; // 事件捕获
|
|
10
|
+
this.mouseStatus = null; // 当前鼠标状态 LEFT_DOWN:左键按下;LEFT_UP: 左键抬起;MOVE: 鼠标移动
|
|
11
|
+
this.coordinates = []; // 当前被选中的实体组成的点集合
|
|
12
|
+
this.entityType = 'polygon'; // 当前被选中实体的类型
|
|
13
|
+
this.entityCenter = []; // 多边形中心点
|
|
14
|
+
this.strecthPointIds = []; // 拉伸点Id集合
|
|
15
|
+
this.strecthObj = null; // 被选中的拉伸点
|
|
16
|
+
this.isStrecth = false; // 当前是否点击拉伸点
|
|
17
|
+
}
|
|
18
|
+
start() {
|
|
19
|
+
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
|
|
20
|
+
// 监听鼠标左键按下事件
|
|
21
|
+
this.handler.setInputAction(
|
|
22
|
+
(e) => this.handleLeftDown(e),
|
|
23
|
+
Cesium.ScreenSpaceEventType.LEFT_DOWN
|
|
24
|
+
);
|
|
25
|
+
// 监听鼠标左键抬起事件
|
|
26
|
+
this.handler.setInputAction(
|
|
27
|
+
(e) => this.handleLeftUp(e),
|
|
28
|
+
Cesium.ScreenSpaceEventType.LEFT_UP
|
|
29
|
+
);
|
|
30
|
+
// 监听鼠标移动事件
|
|
31
|
+
this.handler.setInputAction(
|
|
32
|
+
(e) => this.handleMouseMove(e),
|
|
33
|
+
Cesium.ScreenSpaceEventType.MOUSE_MOVE
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
handleLeftDown(e) {
|
|
37
|
+
// 更新鼠标状态
|
|
38
|
+
this.mouseStatus = 'LEFT_DOWN';
|
|
39
|
+
// 获取当前点击位置的实体对象
|
|
40
|
+
const obj = this.viewer.scene.pick(e.position);
|
|
41
|
+
if (!obj) {
|
|
42
|
+
this.strecthObj = null;
|
|
43
|
+
this.selectedEntity = null;
|
|
44
|
+
this.viewer.scene.screenSpaceCameraController.enableRotate = true;
|
|
45
|
+
this.removeStretchPoint();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (obj && obj.id.name === 'stretch_point') {
|
|
49
|
+
const index = this.strecthPointIds.findIndex((p) => p === obj.id.id);
|
|
50
|
+
this.strecthObjId_index = index;
|
|
51
|
+
this.strecthObj = obj;
|
|
52
|
+
this.isStrecth = true;
|
|
53
|
+
} else {
|
|
54
|
+
this.removeStretchPoint();
|
|
55
|
+
this.strecthObj = null;
|
|
56
|
+
this.selectedEntity = obj;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log(`output->obj`, obj);
|
|
60
|
+
|
|
61
|
+
// 锁定相机
|
|
62
|
+
this.viewer.scene.screenSpaceCameraController.enableRotate = false;
|
|
63
|
+
if (obj.id.polygon) {
|
|
64
|
+
this.entityType = 'polygon';
|
|
65
|
+
this.coordinates = this.selectedEntity.id.polygon.hierarchy.getValue(
|
|
66
|
+
Cesium.JulianDate.now()
|
|
67
|
+
).positions;
|
|
68
|
+
this.entityCenter = this.getEntityCenter();
|
|
69
|
+
// 添加拉伸点
|
|
70
|
+
this.addStrecthPoint(this.selectedEntity.id.polygon);
|
|
71
|
+
}
|
|
72
|
+
if (obj.id.polyline) {
|
|
73
|
+
this.entityType = 'polyline';
|
|
74
|
+
this.coordinates = this.selectedEntity.id.polyline.positions.getValue(
|
|
75
|
+
Cesium.JulianDate.now()
|
|
76
|
+
);
|
|
77
|
+
// this.entityCenter = this.getEntityCenter();
|
|
78
|
+
// 添加拉伸点
|
|
79
|
+
this.addStrecthPoint(this.selectedEntity.id.polyline);
|
|
80
|
+
}
|
|
81
|
+
if (obj.id.rectangle) {
|
|
82
|
+
this.entityType = 'rectangle';
|
|
83
|
+
this.coordinates = this.selectedEntity.id.rectangle.coordinates.getValue(
|
|
84
|
+
Cesium.JulianDate.now()
|
|
85
|
+
);
|
|
86
|
+
// 添加拉伸点
|
|
87
|
+
this.addStrecthPoint(this.selectedEntity.id.rectangle);
|
|
88
|
+
}
|
|
89
|
+
if (obj.id.point) {
|
|
90
|
+
this.entityType = 'point';
|
|
91
|
+
}
|
|
92
|
+
if (obj.id.ellipse) {
|
|
93
|
+
// 圆形
|
|
94
|
+
this.entityType = 'ellipse';
|
|
95
|
+
}
|
|
96
|
+
if (obj.id.billboard && obj.id.label) {
|
|
97
|
+
// 文字点位,图片和文字
|
|
98
|
+
this.entityType = 'pointText';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
handleLeftUp(e) {
|
|
102
|
+
// 更新鼠标状态
|
|
103
|
+
this.mouseStatus = 'LEFT_UP';
|
|
104
|
+
}
|
|
105
|
+
handleMouseMove(e) {
|
|
106
|
+
// 表示鼠标左键后有选中实体
|
|
107
|
+
if (this.mouseStatus === 'LEFT_DOWN' && this.selectedEntity) {
|
|
108
|
+
// 拖拽实体
|
|
109
|
+
if (this.strecthObj) {
|
|
110
|
+
// 点中了拉伸点
|
|
111
|
+
this.handleDrag(e, this.strecthObj);
|
|
112
|
+
this.handleStretch(this.selectedEntity); // 实体的点位传进去
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.removeStretchPoint();
|
|
116
|
+
this.handleDrag(e, this.selectedEntity);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 拖拽移动实体
|
|
121
|
+
* @param {*} e
|
|
122
|
+
*/
|
|
123
|
+
handleDrag(e, selectedEntity) {
|
|
124
|
+
if (!selectedEntity) return;
|
|
125
|
+
const coordinates = this.coordinates;
|
|
126
|
+
// 获取开始位置坐标
|
|
127
|
+
const startPosition = this.viewer.scene.camera.pickEllipsoid(
|
|
128
|
+
e.startPosition,
|
|
129
|
+
this.viewer.scene.globe.ellipsoid
|
|
130
|
+
);
|
|
131
|
+
// 获取结束位置坐标
|
|
132
|
+
const endPosition = this.viewer.scene.camera.pickEllipsoid(
|
|
133
|
+
e.endPosition,
|
|
134
|
+
this.viewer.scene.globe.ellipsoid
|
|
135
|
+
);
|
|
136
|
+
selectedEntity.id.position = new Cesium.CallbackProperty(function() {
|
|
137
|
+
return endPosition;
|
|
138
|
+
}, false);
|
|
139
|
+
const changed_x = endPosition.x - startPosition.x;
|
|
140
|
+
const changed_y = endPosition.y - startPosition.y;
|
|
141
|
+
const changed_z = endPosition.z - startPosition.z;
|
|
142
|
+
if (this.entityType === 'point') {
|
|
143
|
+
const ray = this.viewer.camera.getPickRay(e.endPosition);
|
|
144
|
+
const cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
|
|
145
|
+
selectedEntity.id.position = new Cesium.CallbackProperty(function(time) {
|
|
146
|
+
return cartesian;
|
|
147
|
+
}, false);
|
|
148
|
+
}
|
|
149
|
+
if (this.entityType === 'polygon') {
|
|
150
|
+
const currentsPoint = [];
|
|
151
|
+
for (let i = 0; i < coordinates.length; i++) {
|
|
152
|
+
coordinates[i].x = coordinates[i].x + changed_x;
|
|
153
|
+
coordinates[i].y = coordinates[i].y + changed_y;
|
|
154
|
+
coordinates[i].z = coordinates[i].z + changed_z;
|
|
155
|
+
currentsPoint.push(coordinates[i]);
|
|
156
|
+
}
|
|
157
|
+
selectedEntity.id.polygon.hierarchy = new Cesium.CallbackProperty(
|
|
158
|
+
(time) => {
|
|
159
|
+
return { positions: currentsPoint };
|
|
160
|
+
},
|
|
161
|
+
false
|
|
162
|
+
); // 防止闪烁
|
|
163
|
+
}
|
|
164
|
+
if (this.entityType === 'polyline') {
|
|
165
|
+
const currentsPoint = [];
|
|
166
|
+
for (let i = 0; i < coordinates.length; i++) {
|
|
167
|
+
coordinates[i].x = coordinates[i].x + changed_x;
|
|
168
|
+
coordinates[i].y = coordinates[i].y + changed_y;
|
|
169
|
+
coordinates[i].z = coordinates[i].z + changed_z;
|
|
170
|
+
currentsPoint.push(coordinates[i]);
|
|
171
|
+
}
|
|
172
|
+
selectedEntity.id.polyline.positions = new Cesium.CallbackProperty(
|
|
173
|
+
(time) => {
|
|
174
|
+
return currentsPoint;
|
|
175
|
+
},
|
|
176
|
+
false
|
|
177
|
+
); // 防止闪烁
|
|
178
|
+
}
|
|
179
|
+
if (this.entityType === 'rectangle') {
|
|
180
|
+
const position_start = startPosition;
|
|
181
|
+
const cartographic_start =
|
|
182
|
+
Cesium.Cartographic.fromCartesian(position_start);
|
|
183
|
+
const longitude_start = Cesium.Math.toDegrees(
|
|
184
|
+
cartographic_start.longitude
|
|
185
|
+
);
|
|
186
|
+
const latitude_start = Cesium.Math.toDegrees(cartographic_start.latitude);
|
|
187
|
+
|
|
188
|
+
const position_end = endPosition;
|
|
189
|
+
const cartographic_end = Cesium.Cartographic.fromCartesian(position_end);
|
|
190
|
+
const longitude_end = Cesium.Math.toDegrees(cartographic_end.longitude);
|
|
191
|
+
const latitude_end = Cesium.Math.toDegrees(cartographic_end.latitude);
|
|
192
|
+
|
|
193
|
+
const changer_lng = longitude_end - longitude_start;
|
|
194
|
+
const changer_lat = latitude_end - latitude_start;
|
|
195
|
+
coordinates.west = Cesium.Math.toRadians(
|
|
196
|
+
Cesium.Math.toDegrees(coordinates.west) + changer_lng
|
|
197
|
+
);
|
|
198
|
+
coordinates.east = Cesium.Math.toRadians(
|
|
199
|
+
Cesium.Math.toDegrees(coordinates.east) + changer_lng
|
|
200
|
+
);
|
|
201
|
+
coordinates.south = Cesium.Math.toRadians(
|
|
202
|
+
Cesium.Math.toDegrees(coordinates.south) + changer_lat
|
|
203
|
+
);
|
|
204
|
+
coordinates.north = Cesium.Math.toRadians(
|
|
205
|
+
Cesium.Math.toDegrees(coordinates.north) + changer_lat
|
|
206
|
+
);
|
|
207
|
+
selectedEntity.id.rectangle.coordinates = new Cesium.CallbackProperty(
|
|
208
|
+
() => {
|
|
209
|
+
return coordinates;
|
|
210
|
+
},
|
|
211
|
+
false
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 旋转实体
|
|
217
|
+
* @param {*} angle
|
|
218
|
+
*/
|
|
219
|
+
handleRotation(angle) {
|
|
220
|
+
if (!this.selectedEntity) return;
|
|
221
|
+
// 旋转时清除辅助拉伸的点
|
|
222
|
+
if (this.strecthPointIds.length) {
|
|
223
|
+
this.removeStretchPoint();
|
|
224
|
+
}
|
|
225
|
+
if (this.entityType === 'rectangle') {
|
|
226
|
+
// 旋转图形
|
|
227
|
+
this.selectedEntity.id.rectangle.rotation = new Cesium.CallbackProperty(
|
|
228
|
+
function() {
|
|
229
|
+
return angle;
|
|
230
|
+
},
|
|
231
|
+
false
|
|
232
|
+
);
|
|
233
|
+
// 旋转图形材质
|
|
234
|
+
this.selectedEntity.id.rectangle.stRotation = new Cesium.CallbackProperty(
|
|
235
|
+
function() {
|
|
236
|
+
return angle;
|
|
237
|
+
},
|
|
238
|
+
false
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
if (this.entityType === 'polygon') {
|
|
242
|
+
// let previousCoordinates = this.selectedEntity.id.polygon.hierarchy.getValue().positions
|
|
243
|
+
// let coors = this.getWGS84FromDKR(previousCoordinates)
|
|
244
|
+
// console.log(coors)
|
|
245
|
+
// let poly = turf.polygon([coors])
|
|
246
|
+
// let centroid = turf.centroid(poly)
|
|
247
|
+
// let rotatedPoly = turf.transformRotate(poly, angle, { pivot: centroid.geometry.coordinates})
|
|
248
|
+
// let newCoors = rotatedPoly.geometry.coordinates[0]
|
|
249
|
+
// let positions = []
|
|
250
|
+
// newCoors.forEach(item => {
|
|
251
|
+
// positions.push(item[0], item[1])
|
|
252
|
+
// })
|
|
253
|
+
this.selectedEntity.id.polygon.stRotation = new Cesium.CallbackProperty(
|
|
254
|
+
function(time) {
|
|
255
|
+
return Cesium.Math.toRadians(angle);
|
|
256
|
+
},
|
|
257
|
+
false
|
|
258
|
+
);
|
|
259
|
+
// this.selectedEntity.id.polygon.hierarchy = new Cesium.CallbackProperty(function () {
|
|
260
|
+
// return { positions: Cesium.Cartesian3.fromDegreesArray(positions) }
|
|
261
|
+
// }, false)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* 拉伸实体
|
|
266
|
+
*/
|
|
267
|
+
handleStretch(selectedEntity) {
|
|
268
|
+
const positions = [];
|
|
269
|
+
// 更新polygon的位置数组 多边形的
|
|
270
|
+
if (selectedEntity.id.polygon) {
|
|
271
|
+
for (let i = 0; i < this.strecthPointIds.length; i++) {
|
|
272
|
+
const id = this.strecthPointIds[i];
|
|
273
|
+
if (this.viewer.entities.getById(id)) {
|
|
274
|
+
positions.push(
|
|
275
|
+
this.viewer.entities
|
|
276
|
+
.getById(id)
|
|
277
|
+
.position.getValue(Cesium.JulianDate.now())
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
selectedEntity.id.polygon.hierarchy = new Cesium.CallbackProperty(() => {
|
|
283
|
+
return { positions: positions };
|
|
284
|
+
}, false);
|
|
285
|
+
}
|
|
286
|
+
// 更新polyline的位置数组 线段的
|
|
287
|
+
if (selectedEntity.id.polyline) {
|
|
288
|
+
for (let i = 0; i < this.strecthPointIds.length; i++) {
|
|
289
|
+
const id = this.strecthPointIds[i];
|
|
290
|
+
if (this.viewer.entities.getById(id)) {
|
|
291
|
+
positions.push(
|
|
292
|
+
this.viewer.entities
|
|
293
|
+
.getById(id)
|
|
294
|
+
.position.getValue(Cesium.JulianDate.now())
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
selectedEntity.id.polyline.positions = new Cesium.CallbackProperty(() => {
|
|
300
|
+
return positions;
|
|
301
|
+
}, false);
|
|
302
|
+
}
|
|
303
|
+
// 更新rectangle的位置数组 矩形的
|
|
304
|
+
if (selectedEntity.id.rectangle) {
|
|
305
|
+
const index = this.strecthPointIds.findIndex(
|
|
306
|
+
(item) => item === this.strecthObj.id.id
|
|
307
|
+
);
|
|
308
|
+
for (let i = 0; i < this.strecthPointIds.length; i++) {
|
|
309
|
+
const id = this.strecthPointIds[i];
|
|
310
|
+
|
|
311
|
+
// 矩形由两个对角的点组成的区域,因此先判断用户点击的是哪一个点,即奇偶判断
|
|
312
|
+
if (index % 2 === 0) {
|
|
313
|
+
if (i % 2 === 0) {
|
|
314
|
+
positions.push(
|
|
315
|
+
this.viewer.entities
|
|
316
|
+
.getById(id)
|
|
317
|
+
.position.getValue(Cesium.JulianDate.now())
|
|
318
|
+
);
|
|
319
|
+
} else {
|
|
320
|
+
// 将另外一半点隐藏
|
|
321
|
+
this.viewer.entities.getById(id).show = false;
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
if (i % 2 != 0) {
|
|
325
|
+
positions.push(
|
|
326
|
+
this.viewer.entities
|
|
327
|
+
.getById(id)
|
|
328
|
+
.position.getValue(Cesium.JulianDate.now())
|
|
329
|
+
);
|
|
330
|
+
} else {
|
|
331
|
+
this.viewer.entities.getById(id).show = false;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
selectedEntity.id.rectangle.coordinates = new Cesium.CallbackProperty(
|
|
336
|
+
(time) => {
|
|
337
|
+
const obj = Cesium.Rectangle.fromCartesianArray(positions);
|
|
338
|
+
return obj;
|
|
339
|
+
},
|
|
340
|
+
false
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* 添加拉伸点
|
|
346
|
+
* @param {*} entity
|
|
347
|
+
*/
|
|
348
|
+
addStrecthPoint(entity) {
|
|
349
|
+
let points = [];
|
|
350
|
+
if (this.entityType === 'polygon') {
|
|
351
|
+
points = entity.hierarchy.getValue(Cesium.JulianDate.now()).positions;
|
|
352
|
+
} else if (this.entityType === 'polyline') {
|
|
353
|
+
points = entity.positions.getValue(Cesium.JulianDate.now());
|
|
354
|
+
} else if (this.entityType === 'rectangle') {
|
|
355
|
+
const rectangle = entity.coordinates.getValue(Cesium.JulianDate.now());
|
|
356
|
+
Cesium.Rectangle.subsample(
|
|
357
|
+
rectangle,
|
|
358
|
+
Cesium.Ellipsoid.WGS84,
|
|
359
|
+
rectangle.height,
|
|
360
|
+
points
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
for (const position of points) {
|
|
364
|
+
const point = this.viewer.entities.add({
|
|
365
|
+
name: 'stretch_point',
|
|
366
|
+
position: position,
|
|
367
|
+
point: {
|
|
368
|
+
color: Cesium.Color.WHITE,
|
|
369
|
+
pixelSize: 10,
|
|
370
|
+
outlineColor: Cesium.Color.BLACK,
|
|
371
|
+
outlineWidth: 1
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
this.strecthPointIds.push(point.id);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* 清除拉伸点
|
|
379
|
+
*/
|
|
380
|
+
removeStretchPoint() {
|
|
381
|
+
for (const id of this.strecthPointIds) {
|
|
382
|
+
this.viewer.entities.removeById(id);
|
|
383
|
+
}
|
|
384
|
+
this.strecthPointIds = [];
|
|
385
|
+
this.strecthObj = null;
|
|
386
|
+
this.isStrecth = false;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* 获取多边形图形中心点
|
|
390
|
+
*/
|
|
391
|
+
getEntityCenter() {
|
|
392
|
+
const previousCoordinates =
|
|
393
|
+
this.selectedEntity.id.polygon.hierarchy.getValue(
|
|
394
|
+
Cesium.JulianDate.now()
|
|
395
|
+
).positions;
|
|
396
|
+
const coors = this.getWGS84FromDKR(previousCoordinates);
|
|
397
|
+
coors.push(coors[0]);
|
|
398
|
+
const poly = turf.polygon([coors]);
|
|
399
|
+
const centroid = turf.centroid(poly);
|
|
400
|
+
|
|
401
|
+
return centroid.geometry.coordinates;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* 将笛卡尔坐标转换成国际坐标
|
|
405
|
+
* @param {*} coors
|
|
406
|
+
* @returns
|
|
407
|
+
*/
|
|
408
|
+
getWGS84FromDKR(coors) {
|
|
409
|
+
const newCoors = [];
|
|
410
|
+
for (let i = 0; i < coors.length; i++) {
|
|
411
|
+
const coor = coors[i];
|
|
412
|
+
const cartographic = Cesium.Cartographic.fromCartesian(coor);
|
|
413
|
+
const x = Cesium.Math.toDegrees(cartographic.longitude);
|
|
414
|
+
const y = Cesium.Math.toDegrees(cartographic.latitude);
|
|
415
|
+
newCoors.push([x, y]);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return newCoors;
|
|
419
|
+
}
|
|
420
|
+
destroy() {
|
|
421
|
+
this.handler && this.handler.destroy();
|
|
422
|
+
this.removeStretchPoint();
|
|
423
|
+
this.viewer.scene.screenSpaceCameraController.enableRotate = true;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export default CesiumEntityEdit;
|