@hzab/map-combine 0.2.6 → 0.2.8
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/basic/Point.ts +66 -69
- package/src/basic/ReactPoint.tsx +7 -2
- package/src/cesium/CesiumMap.ts +24 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/basic/Point.ts
CHANGED
|
@@ -1,176 +1,173 @@
|
|
|
1
|
-
import Eventful from "zrender/lib/core/Eventful"
|
|
1
|
+
import Eventful from "zrender/lib/core/Eventful";
|
|
2
2
|
|
|
3
|
-
import { MapElement, MapElementOption } from "./MapElement"
|
|
4
|
-
import { MapCombine } from "./MapCombine"
|
|
3
|
+
import { MapElement, MapElementOption } from "./MapElement";
|
|
4
|
+
import { MapCombine } from "./MapCombine";
|
|
5
5
|
|
|
6
6
|
export interface PointOption<K> extends MapElementOption {
|
|
7
|
-
show: boolean
|
|
8
|
-
cursor: string
|
|
9
|
-
coordinates?: number[]
|
|
10
|
-
src: string
|
|
11
|
-
center: number[]
|
|
12
|
-
size: number[]
|
|
13
|
-
rotation: number
|
|
14
|
-
editable: boolean
|
|
15
|
-
userdata: K
|
|
16
|
-
silent: boolean
|
|
17
|
-
height: number
|
|
7
|
+
show: boolean;
|
|
8
|
+
cursor: string;
|
|
9
|
+
coordinates?: number[];
|
|
10
|
+
src: string;
|
|
11
|
+
center: number[];
|
|
12
|
+
size: number[];
|
|
13
|
+
rotation: number;
|
|
14
|
+
editable: boolean;
|
|
15
|
+
userdata: K;
|
|
16
|
+
silent: boolean;
|
|
17
|
+
height: number;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export class Point<K = undefined> extends MapElement<PointOption<K>> {
|
|
21
|
-
type =
|
|
21
|
+
type = "Point";
|
|
22
22
|
event = new Eventful<{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}>()
|
|
23
|
+
"data-loaded": () => void;
|
|
24
|
+
"data-update": () => void;
|
|
25
|
+
"pointer-in": () => void;
|
|
26
|
+
"pointer-out": () => void;
|
|
27
|
+
"left-click": () => void;
|
|
28
|
+
"right-click": () => void;
|
|
29
|
+
update: (keys: Set<string>) => void;
|
|
30
|
+
destroy: () => void;
|
|
31
|
+
}>();
|
|
32
32
|
|
|
33
33
|
get userdata() {
|
|
34
|
-
return this._option.userdata
|
|
34
|
+
return this._option.userdata;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
37
|
get cursor() {
|
|
39
|
-
return this._option.cursor
|
|
38
|
+
return this._option.cursor;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
get show() {
|
|
43
|
-
return this._option.show
|
|
42
|
+
return this._option.show;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
set show(val) {
|
|
47
46
|
if (this._option.show != val) {
|
|
48
|
-
this._option.show = val
|
|
49
|
-
this._update(
|
|
47
|
+
this._option.show = val;
|
|
48
|
+
this._update("show");
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
get silent() {
|
|
54
|
-
return this._option.silent
|
|
53
|
+
return this._option.silent;
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
set silent(val) {
|
|
58
57
|
if (this._option.silent != val) {
|
|
59
|
-
this._option.silent = val
|
|
60
|
-
this._update(
|
|
58
|
+
this._option.silent = val;
|
|
59
|
+
this._update("silent");
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
get editable() {
|
|
65
|
-
return this._option.editable
|
|
64
|
+
return this._option.editable;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
set editable(val) {
|
|
69
68
|
if (this._option.editable != val) {
|
|
70
|
-
this._option.editable = val
|
|
71
|
-
this._update(
|
|
69
|
+
this._option.editable = val;
|
|
70
|
+
this._update("editable");
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
get coordinates() {
|
|
76
|
-
return this._option.coordinates
|
|
75
|
+
return this._option.coordinates;
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
set coordinates(val) {
|
|
80
79
|
if (this._option.coordinates != val) {
|
|
81
|
-
this._option.coordinates = val
|
|
82
|
-
this._update(
|
|
80
|
+
this._option.coordinates = val;
|
|
81
|
+
this._update("coordinates");
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
get src() {
|
|
87
|
-
return this._option.src
|
|
86
|
+
return this._option.src;
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
set src(val) {
|
|
91
90
|
if (this._option.src != val) {
|
|
92
|
-
this._option.src = val
|
|
93
|
-
this._update(
|
|
91
|
+
this._option.src = val;
|
|
92
|
+
this._update("src");
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
get size() {
|
|
98
|
-
return this._option.size
|
|
97
|
+
return this._option.size;
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
set size(val) {
|
|
102
101
|
if (this._option.size != val) {
|
|
103
|
-
this._option.size = val
|
|
104
|
-
this._update(
|
|
102
|
+
this._option.size = val;
|
|
103
|
+
this._update("size");
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
get center() {
|
|
108
|
-
return this._option.center
|
|
107
|
+
return this._option.center;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
set center(val) {
|
|
112
111
|
if (this._option.center != val) {
|
|
113
|
-
this._option.center = val
|
|
114
|
-
this._update(
|
|
112
|
+
this._option.center = val;
|
|
113
|
+
this._update("center");
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
get height() {
|
|
119
|
-
return this._option.height
|
|
118
|
+
return this._option.height;
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
set height(val) {
|
|
123
122
|
if (this._option.height != val) {
|
|
124
|
-
this._option.height = val
|
|
125
|
-
this._update(
|
|
123
|
+
this._option.height = val;
|
|
124
|
+
this._update("height");
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
get rotation() {
|
|
130
|
-
return this._option.rotation
|
|
129
|
+
return this._option.rotation;
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
set rotation(val) {
|
|
134
133
|
if (this._option.rotation != val) {
|
|
135
|
-
this._option.rotation = val
|
|
136
|
-
this._update(
|
|
134
|
+
this._option.rotation = val;
|
|
135
|
+
this._update("rotation");
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
|
|
141
|
-
|
|
142
139
|
constructor(map: MapCombine, option: Partial<PointOption<K>> = {}) {
|
|
143
|
-
super(map, Object.assign({ ...Point.option }, option))
|
|
140
|
+
super(map, Object.assign({ ...Point.option }, option));
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
static option: PointOption<undefined> = {
|
|
147
|
-
name:
|
|
144
|
+
name: "点",
|
|
148
145
|
show: true,
|
|
149
|
-
src:
|
|
146
|
+
src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAIxJREFUOE+tU4ENgCAM6y5TL1MuEy+bmQjChAjIEkKAretIS1DBwAy3pnuXDAvgIGDT+RRfsEtYdZI6mxgoAFQWe6wAcgE0FicgHoA/aJeeF+rs/rBgYI9+u5WIFQa99K9mQwB+j1AjntLfGBlBZCssmoMAGiOkDjWmUvbcK0WVN1PGlS87i63JWTvECRNBLcaa3Jq0AAAAAElFTkSuQmCC",
|
|
150
147
|
center: [0.5, 0.5],
|
|
151
148
|
editable: false,
|
|
152
149
|
size: [16, 16],
|
|
153
150
|
rotation: 0,
|
|
154
|
-
cursor:
|
|
151
|
+
cursor: "pointer",
|
|
155
152
|
userdata: undefined,
|
|
156
153
|
silent: false,
|
|
157
|
-
height: 0
|
|
158
|
-
}
|
|
154
|
+
height: 0,
|
|
155
|
+
};
|
|
159
156
|
|
|
160
|
-
private _needUpdate?: Set<string
|
|
157
|
+
private _needUpdate?: Set<string>;
|
|
161
158
|
private _update(key: string) {
|
|
162
159
|
if (this._needUpdate) {
|
|
163
|
-
this._needUpdate.add(key)
|
|
160
|
+
this._needUpdate.add(key);
|
|
164
161
|
} else {
|
|
165
|
-
this._needUpdate = new Set([key])
|
|
162
|
+
this._needUpdate = new Set([key]);
|
|
166
163
|
setTimeout(() => {
|
|
167
|
-
this.event.trigger(
|
|
168
|
-
this._needUpdate = undefined
|
|
164
|
+
this.event.trigger("update", this._needUpdate);
|
|
165
|
+
this._needUpdate = undefined;
|
|
169
166
|
});
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
|
|
173
170
|
protected _onDestroy(): void {
|
|
174
|
-
this.event.trigger(
|
|
171
|
+
this.event.trigger("destroy");
|
|
175
172
|
}
|
|
176
|
-
}
|
|
173
|
+
}
|
package/src/basic/ReactPoint.tsx
CHANGED
|
@@ -20,6 +20,8 @@ export interface ReactPointOption<K> extends MapElementOption {
|
|
|
20
20
|
export class ReactPoint<K = undefined> extends MapElement<ReactPointOption<K>> {
|
|
21
21
|
type: "ReactPoint";
|
|
22
22
|
event = new Eventful<{
|
|
23
|
+
"data-loaded": () => void;
|
|
24
|
+
"data-update": () => void;
|
|
23
25
|
"pointer-in": () => void;
|
|
24
26
|
"pointer-out": () => void;
|
|
25
27
|
"left-click": () => void;
|
|
@@ -197,7 +199,6 @@ export function drawReactPoint(map: MapCombine, point: ReactPoint<unknown>) {
|
|
|
197
199
|
status == 2 && point.event.trigger("right-click");
|
|
198
200
|
});
|
|
199
201
|
ReactDOM.render(point.element(point.props), root);
|
|
200
|
-
|
|
201
202
|
let delay = 0;
|
|
202
203
|
|
|
203
204
|
root.addEventListener("pointerdown", () => {
|
|
@@ -210,13 +211,15 @@ export function drawReactPoint(map: MapCombine, point: ReactPoint<unknown>) {
|
|
|
210
211
|
}, 300);
|
|
211
212
|
}
|
|
212
213
|
});
|
|
213
|
-
|
|
214
214
|
if (point.coordinates) {
|
|
215
215
|
status = 2;
|
|
216
216
|
const p = map.geographyTcanvas(point.coordinates);
|
|
217
217
|
root.style.left = `${p[0]}px`;
|
|
218
218
|
root.style.top = `${p[1]}px`;
|
|
219
219
|
htmllayer.appendChild(root);
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
point.event.trigger("data-loaded");
|
|
222
|
+
});
|
|
220
223
|
}
|
|
221
224
|
|
|
222
225
|
const onViewChange = () => {
|
|
@@ -320,6 +323,7 @@ export function drawReactPoint(map: MapCombine, point: ReactPoint<unknown>) {
|
|
|
320
323
|
status = 2;
|
|
321
324
|
skip++;
|
|
322
325
|
point.coordinates = event.geography;
|
|
326
|
+
point.event.trigger("data-loaded");
|
|
323
327
|
}
|
|
324
328
|
};
|
|
325
329
|
|
|
@@ -334,6 +338,7 @@ export function drawReactPoint(map: MapCombine, point: ReactPoint<unknown>) {
|
|
|
334
338
|
root.style.pointerEvents = point.silent ? "none" : "all";
|
|
335
339
|
skip++;
|
|
336
340
|
point.coordinates = event.geography;
|
|
341
|
+
point.event.trigger("data-update");
|
|
337
342
|
}
|
|
338
343
|
};
|
|
339
344
|
|
package/src/cesium/CesiumMap.ts
CHANGED
|
@@ -13,7 +13,13 @@ import { drawPolyline } from "./CesiumPolyline";
|
|
|
13
13
|
import { drawTile3D } from "./CesiumTile3D";
|
|
14
14
|
|
|
15
15
|
const $m = 20037508.34278924;
|
|
16
|
+
/**
|
|
17
|
+
* flyToViewer 最小判断半径(米)
|
|
18
|
+
*/
|
|
16
19
|
const MIN_RADIUS = 500;
|
|
20
|
+
/**
|
|
21
|
+
* flyToViewer 最大缩放层级
|
|
22
|
+
*/
|
|
17
23
|
const MAX_ZOOM = 18;
|
|
18
24
|
|
|
19
25
|
export class CesiumMap extends MapCombine {
|
|
@@ -255,8 +261,24 @@ export class CesiumMap extends MapCombine {
|
|
|
255
261
|
* @param points
|
|
256
262
|
* @param opt
|
|
257
263
|
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
264
|
+
* @param {Array<number> = [0,0,0,0]} opt.minRadius flyToViewer 最小范围(米)
|
|
265
|
+
* @param {Array<number> = [0,0,0,0]} opt.maxZoom flyToViewer 最大缩放层级
|
|
258
266
|
*/
|
|
259
|
-
flyToViewer(
|
|
267
|
+
flyToViewer(
|
|
268
|
+
points,
|
|
269
|
+
opt = {
|
|
270
|
+
avoid: [0, 0, 0, 0],
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* flyToViewer 最小判断半径(米)
|
|
274
|
+
*/
|
|
275
|
+
minRadius: MIN_RADIUS,
|
|
276
|
+
/**
|
|
277
|
+
* flyToViewer 最大缩放层级
|
|
278
|
+
*/
|
|
279
|
+
maxZoom: MAX_ZOOM,
|
|
280
|
+
},
|
|
281
|
+
) {
|
|
260
282
|
if (points?.length === 0) {
|
|
261
283
|
return this.flyTo(points[0], opt);
|
|
262
284
|
}
|
|
@@ -278,7 +300,7 @@ export class CesiumMap extends MapCombine {
|
|
|
278
300
|
|
|
279
301
|
let destination = rectangle;
|
|
280
302
|
// 点位距离小于指定范围使用固定高度
|
|
281
|
-
if (radius < MIN_RADIUS) {
|
|
303
|
+
if (radius < MIN_RADIUS || (opt?.minRadius && radius < opt.minRadius)) {
|
|
282
304
|
const center = Cesium.Rectangle.center(rectangle);
|
|
283
305
|
destination = Cesium.Cartesian3.fromRadians(
|
|
284
306
|
center.longitude,
|