drone_view 3.0.18 → 3.0.20
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/.vscode/settings.json +3 -0
- package/dist/514.droneView.js +1 -1
- package/dist/800.droneView.js +1 -1
- package/dist/droneView.js +1 -1
- package/package.json +1 -1
- package/src/app.interface.ts +684 -0
- package/src/droneView.ts +1070 -0
- package/src/event.ts +359 -0
- package/src/layers/annotation.ts +175 -0
- package/src/layers/droneImages.ts +199 -0
- package/src/layers/editLine.ts +521 -0
- package/src/layers/editPoint.ts +345 -0
- package/src/layers/editPolygon.ts +511 -0
- package/src/layers/line.ts +210 -0
- package/src/layers/marker.ts +333 -0
- package/src/layers/marker3d.ts +326 -0
- package/src/layers/model.ts +253 -0
- package/src/layers/note.ts +333 -0
- package/src/layers/ortho.ts +76 -0
- package/src/layers/polygon.ts +218 -0
- package/src/measurement.ts +374 -0
- package/src/utility.ts +802 -0
@@ -0,0 +1,345 @@
|
|
1
|
+
import {
|
2
|
+
CallbackProperty,
|
3
|
+
Color,
|
4
|
+
Cartesian3,
|
5
|
+
CustomDataSource,
|
6
|
+
Entity,
|
7
|
+
Math as cMath,
|
8
|
+
HeadingPitchRange,
|
9
|
+
PolygonHierarchy,
|
10
|
+
PolylineDashMaterialProperty,
|
11
|
+
sampleTerrainMostDetailed,
|
12
|
+
ScreenSpaceEventHandler,
|
13
|
+
ScreenSpaceEventType,
|
14
|
+
HeightReference,
|
15
|
+
VerticalOrigin,
|
16
|
+
Cartographic,
|
17
|
+
Cartesian2
|
18
|
+
} from "cesium";
|
19
|
+
|
20
|
+
import {
|
21
|
+
EditPointOption,
|
22
|
+
LineData,
|
23
|
+
LineOptions,
|
24
|
+
MarkerData,
|
25
|
+
MarkerOptions,
|
26
|
+
Point,
|
27
|
+
PolygonData,
|
28
|
+
PolygonOptions,
|
29
|
+
} from "../app.interface";
|
30
|
+
|
31
|
+
import type CesiumView from "../droneView";
|
32
|
+
|
33
|
+
import {
|
34
|
+
cartesianArrayToPointArray,
|
35
|
+
cartesianToPoint,
|
36
|
+
getMidPoint,
|
37
|
+
pointArrayToCartesianArray,
|
38
|
+
screenToWorldPosition,
|
39
|
+
} from "../utility";
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @param {CesiumView} mapObject - The viewer object
|
43
|
+
* @param {string} uniqueName - The unique name of the layer
|
44
|
+
* @param {MarkerData} data - The data to be used in the layer
|
45
|
+
* @param { EditPointOption } options - The options for the layer)
|
46
|
+
*/
|
47
|
+
export default class EditPoint {
|
48
|
+
editLayerId: string;
|
49
|
+
pointLayer: CustomDataSource;
|
50
|
+
selectedPointID: string | number | null;
|
51
|
+
pointWasDragged: boolean;
|
52
|
+
mapWasMoved: boolean;
|
53
|
+
mouseOverEntity: any | null;
|
54
|
+
opacity: number = 0.0;
|
55
|
+
handler: ScreenSpaceEventHandler;
|
56
|
+
isMouseDown: boolean = false;
|
57
|
+
|
58
|
+
/**
|
59
|
+
* @param { CesiumView } mapObject map object
|
60
|
+
* @param { string }uniqueName string unique name for the layer
|
61
|
+
* @param { MarkerData } data
|
62
|
+
* @param { EditPointOption } options
|
63
|
+
*/
|
64
|
+
constructor(
|
65
|
+
public mapObject: CesiumView,
|
66
|
+
public uniqueName: string,
|
67
|
+
public data: MarkerData,
|
68
|
+
public options: EditPointOption
|
69
|
+
) {
|
70
|
+
this.editLayerId = `point-edit-layer-${this.uniqueName}`;
|
71
|
+
this.opacity = 0.0;
|
72
|
+
this.buildLayer();
|
73
|
+
this.add(this.data);
|
74
|
+
if (this.options.setBounds === undefined || this.options.setBounds) {
|
75
|
+
this.setBounds();
|
76
|
+
}
|
77
|
+
this.zoomToDrawing();
|
78
|
+
this.addListeners();
|
79
|
+
}
|
80
|
+
|
81
|
+
/** To initialize layer */
|
82
|
+
public buildLayer(): void {
|
83
|
+
if (
|
84
|
+
this.mapObject.viewer.dataSources.getByName(
|
85
|
+
"point-edit-Point-" + this.uniqueName
|
86
|
+
)
|
87
|
+
) {
|
88
|
+
this.mapObject.viewer.dataSources.remove(
|
89
|
+
this.mapObject.viewer.dataSources.getByName(
|
90
|
+
"point-edit-Point-" + this.uniqueName
|
91
|
+
)[0],
|
92
|
+
true
|
93
|
+
);
|
94
|
+
}
|
95
|
+
|
96
|
+
this.pointLayer = new CustomDataSource(
|
97
|
+
`point-edit-Point-${this.editLayerId}`
|
98
|
+
);
|
99
|
+
|
100
|
+
this.mapObject.viewer.dataSources.add(this.pointLayer);
|
101
|
+
}
|
102
|
+
|
103
|
+
/** To add layer on map */
|
104
|
+
public add(data: MarkerData) {
|
105
|
+
const self = this;
|
106
|
+
return new Promise<void>((resolve) => {
|
107
|
+
const cartesianPositions = pointArrayToCartesianArray([data.point]);
|
108
|
+
const cartographicPositions =
|
109
|
+
this.mapObject.viewer.scene.globe.ellipsoid.cartesianArrayToCartographicArray(
|
110
|
+
cartesianPositions
|
111
|
+
);
|
112
|
+
this.mapObject.viewer.scene
|
113
|
+
let positions =
|
114
|
+
this.mapObject.viewer.scene.globe.ellipsoid.cartographicArrayToCartesianArray(
|
115
|
+
cartographicPositions
|
116
|
+
);
|
117
|
+
const svg = `<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg">
|
118
|
+
<circle cx="10" cy="10" r="8.5" stroke="red" stroke-width="1.5" fill="whiteSmoke" />
|
119
|
+
</svg>`;
|
120
|
+
const pointMain = {
|
121
|
+
position: positions[0],
|
122
|
+
billboard: {
|
123
|
+
image: `data:image/svg+xml;base64,${window.btoa(svg)}`,
|
124
|
+
verticalOrigin: VerticalOrigin.CENTER,
|
125
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
126
|
+
},
|
127
|
+
layerId: this.editLayerId,
|
128
|
+
};
|
129
|
+
this.mapObject.viewer.scene.requestRender();
|
130
|
+
|
131
|
+
this.pointLayer.entities.add(pointMain);
|
132
|
+
resolve();
|
133
|
+
});
|
134
|
+
}
|
135
|
+
|
136
|
+
/** to set map bouds fit with layer data */
|
137
|
+
public setBounds(): void {
|
138
|
+
const time = this.options.setBoundsInstant ? 0 : undefined;
|
139
|
+
this.mapObject.viewer.flyTo(this.pointLayer.entities, {
|
140
|
+
duration: time,
|
141
|
+
offset: new HeadingPitchRange(
|
142
|
+
cMath.toRadians(this.mapObject.viewer.camera.heading),
|
143
|
+
-Math.PI / 2,
|
144
|
+
0
|
145
|
+
),
|
146
|
+
});
|
147
|
+
}
|
148
|
+
|
149
|
+
public zoomToDrawing(): void {
|
150
|
+
if (this.options.zoom){
|
151
|
+
const point = this.data.point
|
152
|
+
this.mapObject.viewer.camera.flyTo({
|
153
|
+
destination: Cartesian3.fromDegrees(point[0], point[1], 30)
|
154
|
+
});
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
/** Add all listeners for layer */
|
159
|
+
public addListeners() {
|
160
|
+
this.handler = new ScreenSpaceEventHandler(this.mapObject.viewer.canvas);
|
161
|
+
this.handler.setInputAction(
|
162
|
+
this.mouseMoveHandler.bind(this),
|
163
|
+
ScreenSpaceEventType.MOUSE_MOVE
|
164
|
+
);
|
165
|
+
|
166
|
+
this.handler.setInputAction(
|
167
|
+
this.mouseMoveHandler.bind(this),
|
168
|
+
ScreenSpaceEventType.PINCH_MOVE
|
169
|
+
);
|
170
|
+
}
|
171
|
+
|
172
|
+
mouseMoveHandler(event: any) {
|
173
|
+
if (!event.endPosition) {
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
|
177
|
+
if (
|
178
|
+
this.mouseOverEntity &&
|
179
|
+
this.mouseOverEntity.layerId === this.editLayerId &&
|
180
|
+
this.isMouseDown
|
181
|
+
) {
|
182
|
+
this.pointWasDragged = true;
|
183
|
+
|
184
|
+
const mousePosition = new Cartesian2(event.endPosition.x, event.endPosition.y);
|
185
|
+
const point = this.mapObject.viewer.scene.pickPosition(mousePosition);
|
186
|
+
|
187
|
+
if (!point) {
|
188
|
+
return;
|
189
|
+
}
|
190
|
+
|
191
|
+
this.mouseOverEntity.position = point;
|
192
|
+
this.mapObject.viewer.scene.requestRender();
|
193
|
+
return;
|
194
|
+
}
|
195
|
+
|
196
|
+
if (this.mapObject.viewer.scene.pickPositionSupported) {
|
197
|
+
let result: any;
|
198
|
+
|
199
|
+
const pickedObject = this.mapObject.viewer.scene.drillPick(
|
200
|
+
event.endPosition
|
201
|
+
);
|
202
|
+
|
203
|
+
const entity: any = pickedObject.filter(
|
204
|
+
(object) => object.id && object.id.billboard !== undefined
|
205
|
+
)[0];
|
206
|
+
|
207
|
+
if (
|
208
|
+
entity &&
|
209
|
+
entity.id &&
|
210
|
+
entity.id instanceof Entity &&
|
211
|
+
entity.id.layerId === this.editLayerId
|
212
|
+
) {
|
213
|
+
result = {
|
214
|
+
id:
|
215
|
+
((entity as any).id.data && (entity as any).data.id) ||
|
216
|
+
entity.id.id,
|
217
|
+
point: event.position,
|
218
|
+
target: this.mapObject.viewer,
|
219
|
+
type: "mousemove",
|
220
|
+
features: [entity.id],
|
221
|
+
};
|
222
|
+
|
223
|
+
this.mouseEnter(entity, result);
|
224
|
+
// }
|
225
|
+
} else {
|
226
|
+
if (this.mouseOverEntity && !this.pointWasDragged) {
|
227
|
+
this.mouseLeave();
|
228
|
+
}
|
229
|
+
}
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
/** On mouse enter */
|
234
|
+
mouseEnter(entity: any, result?: any) {
|
235
|
+
if (!result.features[0]) {
|
236
|
+
return;
|
237
|
+
}
|
238
|
+
|
239
|
+
this.mapObject.viewer.canvas.style.cursor = "pointer";
|
240
|
+
this.mouseOverEntity = entity.id;
|
241
|
+
|
242
|
+
this.handler.setInputAction(
|
243
|
+
this.mouseDown.bind(this),
|
244
|
+
ScreenSpaceEventType.LEFT_DOWN
|
245
|
+
);
|
246
|
+
this.handler.setInputAction(
|
247
|
+
this.mouseUp.bind(this),
|
248
|
+
ScreenSpaceEventType.LEFT_UP
|
249
|
+
);
|
250
|
+
this.handler.setInputAction(
|
251
|
+
this.mouseDown.bind(this),
|
252
|
+
ScreenSpaceEventType.PINCH_START
|
253
|
+
);
|
254
|
+
this.handler.setInputAction(
|
255
|
+
this.mouseUp.bind(this),
|
256
|
+
ScreenSpaceEventType.PINCH_END
|
257
|
+
);
|
258
|
+
}
|
259
|
+
|
260
|
+
/** On mouse leave */
|
261
|
+
private mouseLeave = () => {
|
262
|
+
this.mapObject.viewer.scene.requestRender();
|
263
|
+
// this.updateVerticesPoints();
|
264
|
+
// this.selectedIndex = -1;
|
265
|
+
this.pointWasDragged = false;
|
266
|
+
this.mouseOverEntity = null;
|
267
|
+
this.mapObject.viewer.canvas.style.cursor = "default";
|
268
|
+
this.mapObject.viewer.scene.requestRender();
|
269
|
+
};
|
270
|
+
|
271
|
+
/** On mouse down */
|
272
|
+
private mouseDown = () => {
|
273
|
+
if (this.mouseOverEntity) {
|
274
|
+
this.isMouseDown = true;
|
275
|
+
this.mapObject.disablePan();
|
276
|
+
}
|
277
|
+
};
|
278
|
+
|
279
|
+
/** On mouse up */
|
280
|
+
private mouseUp() {
|
281
|
+
if (this.pointWasDragged) {
|
282
|
+
console.log(this.mouseOverEntity);
|
283
|
+
|
284
|
+
// let carto = Cartographic.fromCartesian(this.mouseOverEntity._position._value);
|
285
|
+
// this.mapObject.viewer.scene
|
286
|
+
// .sampleHeightMostDetailed([carto])
|
287
|
+
// .then((pos) => {
|
288
|
+
// const position = Cartesian3.fromRadians(pos[0].longitude,pos[0].latitude,pos[0].height)
|
289
|
+
// this.mouseOverEntity.position = position;
|
290
|
+
if(this.options.onDragEnd){
|
291
|
+
const dragEventData = {
|
292
|
+
points: cartesianToPoint(this.mouseOverEntity._position._value),
|
293
|
+
id: this.data?.properties?.id
|
294
|
+
};
|
295
|
+
this.options.onDragEnd(dragEventData);
|
296
|
+
}
|
297
|
+
this.pointWasDragged = false;
|
298
|
+
this.mouseOverEntity = null;
|
299
|
+
this.isMouseDown = false;
|
300
|
+
this.mapObject.enablePan();
|
301
|
+
this.mapObject.viewer.scene.requestRender();
|
302
|
+
// });
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
}
|
307
|
+
|
308
|
+
/** Removes all listeners added by this layer */
|
309
|
+
public removeListeners() {
|
310
|
+
this.handler.removeInputAction(ScreenSpaceEventType.LEFT_DOWN);
|
311
|
+
this.handler.removeInputAction(ScreenSpaceEventType.LEFT_UP);
|
312
|
+
this.handler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE);
|
313
|
+
this.handler.removeInputAction(ScreenSpaceEventType.PINCH_END);
|
314
|
+
this.handler.removeInputAction(ScreenSpaceEventType.PINCH_START);
|
315
|
+
this.handler.removeInputAction(ScreenSpaceEventType.PINCH_MOVE);
|
316
|
+
}
|
317
|
+
|
318
|
+
/** Returns the layer's data */
|
319
|
+
public getData() {
|
320
|
+
// const data: any = {
|
321
|
+
// points: cartesianArrayToPointArray(this.verticsPostions),
|
322
|
+
// properties: this.data.properties,
|
323
|
+
// };
|
324
|
+
// return data;
|
325
|
+
}
|
326
|
+
|
327
|
+
/** @inheritdoc */
|
328
|
+
remove() {
|
329
|
+
this.mapObject.viewer.dataSources.remove(this.pointLayer, true);
|
330
|
+
this.removeListeners();
|
331
|
+
this.mapObject.viewer.scene.requestRender();
|
332
|
+
}
|
333
|
+
|
334
|
+
/** @inheritdoc */
|
335
|
+
show() {
|
336
|
+
this.pointLayer.show = true;
|
337
|
+
this.mapObject.viewer.scene.requestRender();
|
338
|
+
}
|
339
|
+
|
340
|
+
/** @inheritdoc */
|
341
|
+
hide() {
|
342
|
+
this.pointLayer.show = false;
|
343
|
+
this.mapObject.viewer.scene.requestRender();
|
344
|
+
}
|
345
|
+
}
|