@hzab/map-combine 0.3.1-alpha.0 → 0.4.0-alpha.0
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 +7 -1
- package/package.json +1 -1
- package/src/amap/AMap.ts +14 -9
- package/src/amap/AMapEvent.ts +5 -0
- package/src/amap/AMapPolygon.ts +195 -195
- package/src/amap/AMapPolyline.ts +185 -185
- package/src/basic/MapCombine.ts +4 -0
- package/src/basic/PointAggregation.tsx +12 -8
- package/src/basic/ReactPoint.tsx +363 -363
- package/src/cesium/CesiumEvent.ts +84 -84
- package/src/cesium/CesiumMap.ts +347 -341
- package/src/cesium/CesiumTile3D.ts +225 -225
- package/src/mine/MineEvent.ts +4 -0
- package/src/mine/MineMap.ts +125 -119
- package/src/openlayer/OpenlayerEvent.ts +4 -0
- package/src/openlayer/OpenlayerMap.ts +287 -273
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/amap/AMap.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MapCombine } from "../basic/MapCombine";
|
|
2
2
|
import { PointOption, Point } from "../basic/Point";
|
|
3
|
+
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
3
4
|
import { ReactPointOption, ReactPoint, drawReactPoint } from "../basic/ReactPoint";
|
|
4
5
|
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
5
6
|
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
@@ -45,6 +46,10 @@ export interface IFlyToViewerOpt {
|
|
|
45
46
|
* 最大缩放级别
|
|
46
47
|
*/
|
|
47
48
|
maxZoom?: number;
|
|
49
|
+
/**
|
|
50
|
+
* 动画时间
|
|
51
|
+
*/
|
|
52
|
+
duration?: number;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export class AMap extends MapCombine {
|
|
@@ -170,6 +175,11 @@ export class AMap extends MapCombine {
|
|
|
170
175
|
return e;
|
|
171
176
|
}
|
|
172
177
|
|
|
178
|
+
createPointAggregation(option?: PointAggregationOption): PointAggregation {
|
|
179
|
+
const e = new PointAggregation(this, option);
|
|
180
|
+
return e;
|
|
181
|
+
}
|
|
182
|
+
|
|
173
183
|
createReactPoint<K>(option?: Partial<ReactPointOption<K>>): ReactPoint<K> {
|
|
174
184
|
const e = new ReactPoint(this, option);
|
|
175
185
|
this.loadPromise.then(() => {
|
|
@@ -211,7 +221,7 @@ export class AMap extends MapCombine {
|
|
|
211
221
|
}
|
|
212
222
|
try {
|
|
213
223
|
const lngLat = this.viewer.lngLatToContainer(p);
|
|
214
|
-
return [lngLat.
|
|
224
|
+
return [lngLat.x, lngLat.y];
|
|
215
225
|
} catch (error) {
|
|
216
226
|
console.error("canvasPixelToLngLat 转换出错:", error);
|
|
217
227
|
return [];
|
|
@@ -247,18 +257,13 @@ export class AMap extends MapCombine {
|
|
|
247
257
|
*/
|
|
248
258
|
flyToViewer(points: number[][], opt: IFlyToViewerOpt = { avoid: [0, 0, 0, 0], immediately: true }): void {
|
|
249
259
|
this.loadPromise.then(() => {
|
|
250
|
-
this.viewer.
|
|
260
|
+
const [zoom, center] = this.viewer.getFitZoomAndCenterByBounds(
|
|
251
261
|
this.getBounds(points, { canvas: this.viewer.canvas, ...opt }),
|
|
252
|
-
opt?.immediately,
|
|
253
262
|
opt?.avoid,
|
|
263
|
+
opt.maxZoom,
|
|
254
264
|
);
|
|
255
265
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (opt.maxZoom && currentZoom > opt.maxZoom) {
|
|
259
|
-
// 如果当前缩放级别超过限制,则手动设置回最大允许级别
|
|
260
|
-
this.viewer.setZoom(opt.maxZoom);
|
|
261
|
-
}
|
|
266
|
+
this.viewer.setZoomAndCenter(zoom, center, opt?.immediately, opt?.duration);
|
|
262
267
|
});
|
|
263
268
|
}
|
|
264
269
|
|
package/src/amap/AMapEvent.ts
CHANGED
|
@@ -16,6 +16,11 @@ export function bindEvent(map: AMap) {
|
|
|
16
16
|
};
|
|
17
17
|
frame();
|
|
18
18
|
|
|
19
|
+
viewer.on("moveend", (e) => {
|
|
20
|
+
event.trigger("view-moveEnd");
|
|
21
|
+
event.trigger("view-change");
|
|
22
|
+
});
|
|
23
|
+
|
|
19
24
|
container.addEventListener("mousedown", (e) => {
|
|
20
25
|
event.trigger("pointer-down");
|
|
21
26
|
});
|
package/src/amap/AMapPolygon.ts
CHANGED
|
@@ -1,195 +1,195 @@
|
|
|
1
|
-
import { AMap } from "./AMap";
|
|
2
|
-
import { Polygon } from "../basic/Polygon";
|
|
3
|
-
|
|
4
|
-
export function drawPolygon(map: AMap, polygon: Polygon<unknown>) {
|
|
5
|
-
const { event, viewer, LbsAMap } = map;
|
|
6
|
-
|
|
7
|
-
let status = 0;
|
|
8
|
-
let skip = 0;
|
|
9
|
-
let target = null;
|
|
10
|
-
let aMapPolygonEditor = null;
|
|
11
|
-
|
|
12
|
-
const _event = {
|
|
13
|
-
cursor: polygon.cursor,
|
|
14
|
-
silent: polygon.silent,
|
|
15
|
-
onPointerIn() {
|
|
16
|
-
status == 2 && polygon.event.trigger("pointer-in");
|
|
17
|
-
},
|
|
18
|
-
onPointerOut() {
|
|
19
|
-
status == 2 && polygon.event.trigger("pointer-out");
|
|
20
|
-
},
|
|
21
|
-
onLClick() {
|
|
22
|
-
status == 2 && polygon.event.trigger("left-click");
|
|
23
|
-
},
|
|
24
|
-
onRClick(e) {
|
|
25
|
-
event.canvas = [e.pixel.x, e.pixel.y];
|
|
26
|
-
if (polygon.menu) {
|
|
27
|
-
map.menu.show(polygon.menu);
|
|
28
|
-
}
|
|
29
|
-
status == 2 && polygon.event.trigger("right-click");
|
|
30
|
-
},
|
|
31
|
-
onDbClick() {
|
|
32
|
-
polygon.editable &&
|
|
33
|
-
status == 2 &&
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
aMapPolygonEditor.setTarget(target);
|
|
36
|
-
aMapPolygonEditor.open();
|
|
37
|
-
polygon.event.trigger("start-edit");
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const bindEvent = (graphical) => {
|
|
43
|
-
graphical.on("click", _event.onLClick);
|
|
44
|
-
graphical.on("rightclick", _event.onRClick);
|
|
45
|
-
graphical.on("dblclick", _event.onDbClick);
|
|
46
|
-
graphical.on("mouseover", _event.onPointerIn);
|
|
47
|
-
graphical.on("mouseout", _event.onPointerOut);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
aMapPolygonEditor = new LbsAMap.PolygonEditor(viewer, undefined, {
|
|
51
|
-
createOptions: {
|
|
52
|
-
strokeColor: polygon.stroke,
|
|
53
|
-
strokeWeight: polygon.lineWidth,
|
|
54
|
-
fillOpacity: 0.4,
|
|
55
|
-
fillColor: polygon.fill,
|
|
56
|
-
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
57
|
-
strokeDasharray: [10, 10],
|
|
58
|
-
},
|
|
59
|
-
editOptions: {
|
|
60
|
-
strokeColor: polygon.stroke,
|
|
61
|
-
strokeWeight: polygon.lineWidth,
|
|
62
|
-
fillOpacity: 0.4,
|
|
63
|
-
fillColor: polygon.fill,
|
|
64
|
-
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
65
|
-
strokeDasharray: [10, 10],
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
aMapPolygonEditor.on("add", (e) => {
|
|
70
|
-
status = 3;
|
|
71
|
-
target = e.target;
|
|
72
|
-
bindEvent(target);
|
|
73
|
-
// polygon.event.trigger("data-loaded");
|
|
74
|
-
});
|
|
75
|
-
if (polygon.coordinates) {
|
|
76
|
-
status = 2;
|
|
77
|
-
target = new LbsAMap.Polygon({
|
|
78
|
-
path: polygon.coordinates,
|
|
79
|
-
strokeColor: polygon.stroke,
|
|
80
|
-
strokeWeight: polygon.lineWidth,
|
|
81
|
-
fillOpacity: 0.4,
|
|
82
|
-
fillColor: polygon.fill,
|
|
83
|
-
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
84
|
-
strokeDasharray: [10, 10],
|
|
85
|
-
});
|
|
86
|
-
viewer.add(target);
|
|
87
|
-
bindEvent(target);
|
|
88
|
-
} else {
|
|
89
|
-
aMapPolygonEditor.close();
|
|
90
|
-
aMapPolygonEditor.setTarget();
|
|
91
|
-
aMapPolygonEditor.open();
|
|
92
|
-
}
|
|
93
|
-
const onUpdate = (e: Set<string>) => {
|
|
94
|
-
if (skip) {
|
|
95
|
-
skip--;
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
e.forEach((key) => {
|
|
100
|
-
switch (key) {
|
|
101
|
-
case "show":
|
|
102
|
-
if (polygon.show) {
|
|
103
|
-
target.show();
|
|
104
|
-
} else {
|
|
105
|
-
target.hide();
|
|
106
|
-
}
|
|
107
|
-
break;
|
|
108
|
-
case "editable":
|
|
109
|
-
break;
|
|
110
|
-
case "coordinates":
|
|
111
|
-
if (polygon.coordinates) {
|
|
112
|
-
target.setPath(polygon.coordinates);
|
|
113
|
-
target.setzIndex(polygon.coordinates[2]);
|
|
114
|
-
target.show();
|
|
115
|
-
status = 2;
|
|
116
|
-
} else {
|
|
117
|
-
target.hide();
|
|
118
|
-
status = 0;
|
|
119
|
-
}
|
|
120
|
-
break;
|
|
121
|
-
|
|
122
|
-
case "lineWidth":
|
|
123
|
-
target.setOptions({
|
|
124
|
-
strokeWeight: polygon.lineWidth,
|
|
125
|
-
});
|
|
126
|
-
break;
|
|
127
|
-
case "fill":
|
|
128
|
-
target.setOptions({
|
|
129
|
-
fillColor: polygon.fill,
|
|
130
|
-
});
|
|
131
|
-
break;
|
|
132
|
-
case "stroke":
|
|
133
|
-
target.setOptions({
|
|
134
|
-
strokeColor: polygon.stroke,
|
|
135
|
-
});
|
|
136
|
-
break;
|
|
137
|
-
case "dash":
|
|
138
|
-
target.setOptions({
|
|
139
|
-
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
140
|
-
});
|
|
141
|
-
break;
|
|
142
|
-
default:
|
|
143
|
-
throw new Error(`${key} 还不支持修改`);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
const onDbClick = () => {
|
|
148
|
-
switch (status) {
|
|
149
|
-
case 1:
|
|
150
|
-
status = 2;
|
|
151
|
-
skip++;
|
|
152
|
-
polygon.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
|
|
153
|
-
polygon.event.trigger("data-loaded");
|
|
154
|
-
polygon.event.trigger("pointer-in");
|
|
155
|
-
break;
|
|
156
|
-
case 3:
|
|
157
|
-
polygon.event.trigger("stop-edit");
|
|
158
|
-
aMapPolygonEditor.setTarget();
|
|
159
|
-
aMapPolygonEditor.close();
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
const onStartEdit = () => {
|
|
164
|
-
switch (status) {
|
|
165
|
-
case 2:
|
|
166
|
-
status = 3;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const onStopEdit = () => {
|
|
172
|
-
if (status == 3) {
|
|
173
|
-
status = 2;
|
|
174
|
-
skip++;
|
|
175
|
-
polygon.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const onDestroy = () => {
|
|
180
|
-
viewer.remove(target);
|
|
181
|
-
aMapPolygonEditor.close();
|
|
182
|
-
aMapPolygonEditor.setTarget();
|
|
183
|
-
event.off("double-click", onDbClick);
|
|
184
|
-
polygon.event.off("update", onUpdate);
|
|
185
|
-
polygon.event.off("start-edit", onStartEdit);
|
|
186
|
-
polygon.event.off("stop-edit", onStopEdit);
|
|
187
|
-
polygon.event.off("destroy", onDestroy);
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
event.on("double-click", onDbClick);
|
|
191
|
-
polygon.event.on("update", onUpdate);
|
|
192
|
-
polygon.event.on("start-edit", onStartEdit);
|
|
193
|
-
polygon.event.on("stop-edit", onStopEdit);
|
|
194
|
-
polygon.event.on("destroy", onDestroy);
|
|
195
|
-
}
|
|
1
|
+
import { AMap } from "./AMap";
|
|
2
|
+
import { Polygon } from "../basic/Polygon";
|
|
3
|
+
|
|
4
|
+
export function drawPolygon(map: AMap, polygon: Polygon<unknown>) {
|
|
5
|
+
const { event, viewer, LbsAMap } = map;
|
|
6
|
+
|
|
7
|
+
let status = 0;
|
|
8
|
+
let skip = 0;
|
|
9
|
+
let target = null;
|
|
10
|
+
let aMapPolygonEditor = null;
|
|
11
|
+
|
|
12
|
+
const _event = {
|
|
13
|
+
cursor: polygon.cursor,
|
|
14
|
+
silent: polygon.silent,
|
|
15
|
+
onPointerIn() {
|
|
16
|
+
status == 2 && polygon.event.trigger("pointer-in");
|
|
17
|
+
},
|
|
18
|
+
onPointerOut() {
|
|
19
|
+
status == 2 && polygon.event.trigger("pointer-out");
|
|
20
|
+
},
|
|
21
|
+
onLClick() {
|
|
22
|
+
status == 2 && polygon.event.trigger("left-click");
|
|
23
|
+
},
|
|
24
|
+
onRClick(e) {
|
|
25
|
+
event.canvas = [e.pixel.x, e.pixel.y];
|
|
26
|
+
if (polygon.menu) {
|
|
27
|
+
map.menu.show(polygon.menu);
|
|
28
|
+
}
|
|
29
|
+
status == 2 && polygon.event.trigger("right-click");
|
|
30
|
+
},
|
|
31
|
+
onDbClick() {
|
|
32
|
+
polygon.editable &&
|
|
33
|
+
status == 2 &&
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
aMapPolygonEditor.setTarget(target);
|
|
36
|
+
aMapPolygonEditor.open();
|
|
37
|
+
polygon.event.trigger("start-edit");
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const bindEvent = (graphical) => {
|
|
43
|
+
graphical.on("click", _event.onLClick);
|
|
44
|
+
graphical.on("rightclick", _event.onRClick);
|
|
45
|
+
graphical.on("dblclick", _event.onDbClick);
|
|
46
|
+
graphical.on("mouseover", _event.onPointerIn);
|
|
47
|
+
graphical.on("mouseout", _event.onPointerOut);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
aMapPolygonEditor = new LbsAMap.PolygonEditor(viewer, undefined, {
|
|
51
|
+
createOptions: {
|
|
52
|
+
strokeColor: polygon.stroke,
|
|
53
|
+
strokeWeight: polygon.lineWidth,
|
|
54
|
+
fillOpacity: 0.4,
|
|
55
|
+
fillColor: polygon.fill,
|
|
56
|
+
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
57
|
+
strokeDasharray: [10, 10],
|
|
58
|
+
},
|
|
59
|
+
editOptions: {
|
|
60
|
+
strokeColor: polygon.stroke,
|
|
61
|
+
strokeWeight: polygon.lineWidth,
|
|
62
|
+
fillOpacity: 0.4,
|
|
63
|
+
fillColor: polygon.fill,
|
|
64
|
+
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
65
|
+
strokeDasharray: [10, 10],
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
aMapPolygonEditor.on("add", (e) => {
|
|
70
|
+
status = 3;
|
|
71
|
+
target = e.target;
|
|
72
|
+
bindEvent(target);
|
|
73
|
+
// polygon.event.trigger("data-loaded");
|
|
74
|
+
});
|
|
75
|
+
if (polygon.coordinates) {
|
|
76
|
+
status = 2;
|
|
77
|
+
target = new LbsAMap.Polygon({
|
|
78
|
+
path: polygon.coordinates,
|
|
79
|
+
strokeColor: polygon.stroke,
|
|
80
|
+
strokeWeight: polygon.lineWidth,
|
|
81
|
+
fillOpacity: 0.4,
|
|
82
|
+
fillColor: polygon.fill,
|
|
83
|
+
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
84
|
+
strokeDasharray: [10, 10],
|
|
85
|
+
});
|
|
86
|
+
viewer.add(target);
|
|
87
|
+
bindEvent(target);
|
|
88
|
+
} else {
|
|
89
|
+
aMapPolygonEditor.close();
|
|
90
|
+
aMapPolygonEditor.setTarget();
|
|
91
|
+
aMapPolygonEditor.open();
|
|
92
|
+
}
|
|
93
|
+
const onUpdate = (e: Set<string>) => {
|
|
94
|
+
if (skip) {
|
|
95
|
+
skip--;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
e.forEach((key) => {
|
|
100
|
+
switch (key) {
|
|
101
|
+
case "show":
|
|
102
|
+
if (polygon.show) {
|
|
103
|
+
target.show();
|
|
104
|
+
} else {
|
|
105
|
+
target.hide();
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case "editable":
|
|
109
|
+
break;
|
|
110
|
+
case "coordinates":
|
|
111
|
+
if (polygon.coordinates) {
|
|
112
|
+
target.setPath(polygon.coordinates);
|
|
113
|
+
target.setzIndex(polygon.coordinates[2]);
|
|
114
|
+
target.show();
|
|
115
|
+
status = 2;
|
|
116
|
+
} else {
|
|
117
|
+
target.hide();
|
|
118
|
+
status = 0;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
|
|
122
|
+
case "lineWidth":
|
|
123
|
+
target.setOptions({
|
|
124
|
+
strokeWeight: polygon.lineWidth,
|
|
125
|
+
});
|
|
126
|
+
break;
|
|
127
|
+
case "fill":
|
|
128
|
+
target.setOptions({
|
|
129
|
+
fillColor: polygon.fill,
|
|
130
|
+
});
|
|
131
|
+
break;
|
|
132
|
+
case "stroke":
|
|
133
|
+
target.setOptions({
|
|
134
|
+
strokeColor: polygon.stroke,
|
|
135
|
+
});
|
|
136
|
+
break;
|
|
137
|
+
case "dash":
|
|
138
|
+
target.setOptions({
|
|
139
|
+
strokeStyle: polygon.dash ? "dashed" : "solid",
|
|
140
|
+
});
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`${key} 还不支持修改`);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
const onDbClick = () => {
|
|
148
|
+
switch (status) {
|
|
149
|
+
case 1:
|
|
150
|
+
status = 2;
|
|
151
|
+
skip++;
|
|
152
|
+
polygon.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
|
|
153
|
+
polygon.event.trigger("data-loaded");
|
|
154
|
+
polygon.event.trigger("pointer-in");
|
|
155
|
+
break;
|
|
156
|
+
case 3:
|
|
157
|
+
polygon.event.trigger("stop-edit");
|
|
158
|
+
aMapPolygonEditor.setTarget();
|
|
159
|
+
aMapPolygonEditor.close();
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const onStartEdit = () => {
|
|
164
|
+
switch (status) {
|
|
165
|
+
case 2:
|
|
166
|
+
status = 3;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const onStopEdit = () => {
|
|
172
|
+
if (status == 3) {
|
|
173
|
+
status = 2;
|
|
174
|
+
skip++;
|
|
175
|
+
polygon.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const onDestroy = () => {
|
|
180
|
+
viewer.remove(target);
|
|
181
|
+
aMapPolygonEditor.close();
|
|
182
|
+
aMapPolygonEditor.setTarget();
|
|
183
|
+
event.off("double-click", onDbClick);
|
|
184
|
+
polygon.event.off("update", onUpdate);
|
|
185
|
+
polygon.event.off("start-edit", onStartEdit);
|
|
186
|
+
polygon.event.off("stop-edit", onStopEdit);
|
|
187
|
+
polygon.event.off("destroy", onDestroy);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
event.on("double-click", onDbClick);
|
|
191
|
+
polygon.event.on("update", onUpdate);
|
|
192
|
+
polygon.event.on("start-edit", onStartEdit);
|
|
193
|
+
polygon.event.on("stop-edit", onStopEdit);
|
|
194
|
+
polygon.event.on("destroy", onDestroy);
|
|
195
|
+
}
|