@hzab/map-combine 0.4.2-alpha.1 → 0.4.2-alpha.12

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +5 -5
  3. package/src/amap/AMap.ts +318 -306
  4. package/src/amap/AMapEvent.ts +110 -54
  5. package/src/amap/AMapLayer.ts +241 -0
  6. package/src/amap/AMapPoint.ts +140 -143
  7. package/src/amap/AMapPolygon.ts +214 -195
  8. package/src/amap/AMapPolyline.ts +199 -185
  9. package/src/basic/BasicBusiness.ts +5 -5
  10. package/src/basic/BasicModel.ts +49 -0
  11. package/src/basic/Layer.ts +154 -0
  12. package/src/basic/MapCombine.ts +105 -98
  13. package/src/basic/MapElement.ts +2 -1
  14. package/src/basic/MapEvent.ts +5 -0
  15. package/src/basic/Point.ts +1 -0
  16. package/src/basic/PointAggregation.tsx +22 -11
  17. package/src/basic/ReactPopup.tsx +3 -0
  18. package/src/basic/Tile3D.ts +0 -1
  19. package/src/cesium/CesiumEvent.ts +97 -84
  20. package/src/cesium/CesiumLayer.ts +365 -0
  21. package/src/cesium/CesiumMap.ts +363 -347
  22. package/src/cesium/CesiumModel.ts +64 -0
  23. package/src/cesium/CesiumPoint.ts +3 -0
  24. package/src/cesium/CesiumPolygon.ts +2 -0
  25. package/src/cesium/CesiumPolyline.ts +185 -47
  26. package/src/cesium/CesiumTile3D.ts +222 -225
  27. package/src/mine/MineEvent.ts +70 -46
  28. package/src/mine/MineMap.ts +217 -125
  29. package/src/mine/MinePoint.ts +7 -1
  30. package/src/mine/MinePolygon.ts +6 -1
  31. package/src/mine/MinePolyline.ts +6 -1
  32. package/src/openlayer/OpenlayerEvent.ts +109 -87
  33. package/src/openlayer/OpenlayerMap.ts +33 -6
  34. package/src/openlayer/OpenlayerPoint.ts +6 -1
  35. package/src/openlayer/OpenlayerPolygon.ts +6 -1
  36. package/src/openlayer/OpenlayerPolyline.ts +8 -1
  37. package/src/utils/color.ts +49 -0
  38. package/src/utils/index.ts +3 -0
  39. package/src/utils/points-viewer.ts +27 -1
  40. package/src/utils/turfjs-utils.ts +52 -0
  41. package/src/utils/types.d.ts +12 -0
@@ -1,185 +1,199 @@
1
- import { AMap } from "./AMap";
2
- import { Polyline } from "../basic/Polyline";
3
-
4
- export function drawPolyline(map: AMap, polyline: Polyline<unknown>) {
5
- const { event, viewer, LbsAMap } = map;
6
-
7
- let status = 0;
8
- let skip = 0;
9
- let target = null;
10
- let aMapPolylineEditor = null;
11
-
12
- const _event = {
13
- cursor: polyline.cursor,
14
- silent: polyline.silent,
15
- onPointerIn() {
16
- status == 2 && polyline.event.trigger("pointer-in");
17
- },
18
- onPointerOut() {
19
- status == 2 && polyline.event.trigger("pointer-out");
20
- },
21
- onLClick() {
22
- status == 2 && polyline.event.trigger("left-click");
23
- },
24
- onRClick(e) {
25
- event.canvas = [e.pixel.x, e.pixel.y];
26
- if (polyline.menu) {
27
- map.menu.show(polyline.menu);
28
- }
29
- status == 2 && polyline.event.trigger("right-click");
30
- },
31
- onDbClick() {
32
- polyline.editable &&
33
- status == 2 &&
34
- setTimeout(() => {
35
- aMapPolylineEditor.setTarget(target);
36
- aMapPolylineEditor.open();
37
- polyline.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
- aMapPolylineEditor = new LbsAMap.PolylineEditor(viewer, undefined, {
51
- createOptions: {
52
- strokeColor: polyline.stroke,
53
- strokeWeight: polyline.lineWidth,
54
- strokeStyle: polyline.dash ? "dashed" : "solid",
55
- strokeDasharray: [10, 10],
56
- },
57
- editOptions: {
58
- strokeColor: polyline.stroke,
59
- strokeWeight: polyline.lineWidth,
60
- strokeStyle: polyline.dash ? "dashed" : "solid",
61
- strokeDasharray: [10, 10],
62
- },
63
- });
64
-
65
- aMapPolylineEditor.on("add", (e) => {
66
- status = 3;
67
- target = e.target;
68
- bindEvent(target);
69
- // polygon.event.trigger("data-loaded");
70
- });
71
-
72
- if (polyline.coordinates) {
73
- status = 2;
74
- target = new LbsAMap.Polyline({
75
- path: polyline.coordinates,
76
- strokeColor: polyline.stroke,
77
- strokeWeight: polyline.lineWidth,
78
- strokeStyle: polyline.dash ? "dashed" : "solid",
79
- strokeDasharray: [10, 10],
80
- });
81
- viewer.add(target);
82
- bindEvent(target);
83
- } else {
84
- aMapPolylineEditor.close();
85
- aMapPolylineEditor.setTarget();
86
- aMapPolylineEditor.open();
87
- }
88
- const onUpdate = (e: Set<string>) => {
89
- if (skip) {
90
- skip--;
91
- return;
92
- }
93
-
94
- e.forEach((key) => {
95
- switch (key) {
96
- case "show":
97
- if (polyline.show) {
98
- target.show();
99
- } else {
100
- target.hide();
101
- }
102
- break;
103
- case "editable":
104
- break;
105
- case "coordinates":
106
- if (polyline.coordinates) {
107
- target.setPath(polyline.coordinates);
108
- target.setzIndex(polyline.coordinates[2]);
109
- target.show();
110
- status = 2;
111
- } else {
112
- target.hide();
113
- status = 0;
114
- }
115
- break;
116
-
117
- case "lineWidth":
118
- target.setOptions({
119
- strokeWeight: polyline.lineWidth,
120
- });
121
- break;
122
- case "stroke":
123
- target.setOptions({
124
- strokeColor: polyline.stroke,
125
- });
126
- break;
127
- case "dash":
128
- target.setOptions({
129
- strokeStyle: polyline.dash ? "dashed" : "solid",
130
- });
131
- break;
132
- default:
133
- throw new Error(`${key} 还不支持修改`);
134
- }
135
- });
136
- };
137
- const onDbClick = () => {
138
- switch (status) {
139
- case 1:
140
- status = 2;
141
- skip++;
142
- polyline.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
143
- polyline.event.trigger("data-loaded");
144
- polyline.event.trigger("pointer-in");
145
- break;
146
- case 3:
147
- polyline.event.trigger("stop-edit");
148
- aMapPolylineEditor.setTarget();
149
- aMapPolylineEditor.close();
150
- break;
151
- }
152
- };
153
- const onStartEdit = () => {
154
- switch (status) {
155
- case 2:
156
- status = 3;
157
- break;
158
- }
159
- };
160
-
161
- const onStopEdit = () => {
162
- if (status == 3) {
163
- status = 2;
164
- skip++;
165
- polyline.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
166
- }
167
- };
168
-
169
- const onDestroy = () => {
170
- viewer.remove(target);
171
- aMapPolylineEditor.close();
172
- aMapPolylineEditor.setTarget();
173
- event.off("double-click", onDbClick);
174
- polyline.event.off("update", onUpdate);
175
- polyline.event.off("start-edit", onStartEdit);
176
- polyline.event.off("stop-edit", onStopEdit);
177
- polyline.event.off("destroy", onDestroy);
178
- };
179
-
180
- event.on("double-click", onDbClick);
181
- polyline.event.on("update", onUpdate);
182
- polyline.event.on("start-edit", onStartEdit);
183
- polyline.event.on("stop-edit", onStopEdit);
184
- polyline.event.on("destroy", onDestroy);
185
- }
1
+ import { AMap } from "./AMap";
2
+ import { Polyline } from "../basic/Polyline";
3
+
4
+ import { parseHexColor } from "../utils/color";
5
+
6
+ export function drawPolyline(map: AMap, polyline: Polyline<unknown>) {
7
+ const { event, viewer, LbsAMap } = map;
8
+ const { color: strokeColor, opacity: strokeOpacity } = parseHexColor(polyline.stroke);
9
+
10
+ let status = 0;
11
+ let skip = 0;
12
+ let target = null;
13
+ let aMapPolylineEditor = null;
14
+
15
+ const _event = {
16
+ cursor: polyline.cursor,
17
+ silent: polyline.silent,
18
+ onPointerIn() {
19
+ status == 2 && polyline.event.trigger("pointer-in");
20
+ },
21
+ onPointerOut() {
22
+ status == 2 && polyline.event.trigger("pointer-out");
23
+ },
24
+ onLClick() {
25
+ status == 2 && polyline.event.trigger("left-click");
26
+ },
27
+ onRClick(e) {
28
+ event.canvas = [e.pixel.x, e.pixel.y];
29
+ if (polyline.menu) {
30
+ map.menu.show(polyline.menu);
31
+ }
32
+ status == 2 && polyline.event.trigger("right-click");
33
+ },
34
+ onDbClick() {
35
+ polyline.editable &&
36
+ status == 2 &&
37
+ setTimeout(() => {
38
+ aMapPolylineEditor.setTarget(target);
39
+ aMapPolylineEditor.open();
40
+ polyline.event.trigger("start-edit");
41
+ });
42
+ },
43
+ };
44
+
45
+ const bindEvent = (graphical) => {
46
+ graphical.on("click", _event.onLClick);
47
+ graphical.on("rightclick", _event.onRClick);
48
+ graphical.on("dblclick", _event.onDbClick);
49
+ graphical.on("mouseover", _event.onPointerIn);
50
+ graphical.on("mouseout", _event.onPointerOut);
51
+ };
52
+
53
+ aMapPolylineEditor = new LbsAMap.PolylineEditor(viewer, undefined, {
54
+ createOptions: {
55
+ strokeColor: strokeColor,
56
+ strokeOpacity: strokeOpacity,
57
+ strokeWeight: polyline.lineWidth,
58
+ strokeStyle: polyline.dash ? "dashed" : "solid",
59
+ strokeDasharray: [10, 10],
60
+ },
61
+ editOptions: {
62
+ strokeColor: strokeColor,
63
+ strokeOpacity: strokeOpacity,
64
+ strokeWeight: polyline.lineWidth,
65
+ strokeStyle: polyline.dash ? "dashed" : "solid",
66
+ strokeDasharray: [10, 10],
67
+ },
68
+ });
69
+
70
+ aMapPolylineEditor.on("add", (e) => {
71
+ status = 3;
72
+ target = e.target;
73
+ bindEvent(target);
74
+ // polygon.event.trigger("data-loaded");
75
+ });
76
+
77
+ if (polyline.coordinates) {
78
+ status = 2;
79
+ target = new LbsAMap.Polyline({
80
+ path: polyline.coordinates,
81
+ strokeColor: strokeColor,
82
+ strokeOpacity: strokeOpacity,
83
+ strokeWeight: polyline.lineWidth,
84
+ strokeStyle: polyline.dash ? "dashed" : "solid",
85
+ strokeDasharray: [10, 10],
86
+ zIndex: polyline.coordinates[0]?.[2] ?? polyline.height,
87
+ bubble: true,
88
+ extData: {
89
+ userdata: polyline.userdata,
90
+ cursor: polyline.cursor,
91
+ silent: polyline.silent,
92
+ target: polyline,
93
+ },
94
+ });
95
+ viewer.add(target);
96
+ bindEvent(target);
97
+ } else {
98
+ aMapPolylineEditor.close();
99
+ aMapPolylineEditor.setTarget();
100
+ aMapPolylineEditor.open();
101
+ }
102
+ const onUpdate = (e: Set<string>) => {
103
+ if (skip) {
104
+ skip--;
105
+ return;
106
+ }
107
+
108
+ e.forEach((key) => {
109
+ switch (key) {
110
+ case "show":
111
+ if (polyline.show) {
112
+ target.show();
113
+ } else {
114
+ target.hide();
115
+ }
116
+ break;
117
+ case "editable":
118
+ break;
119
+ case "coordinates":
120
+ if (polyline.coordinates) {
121
+ target.setPath(polyline.coordinates);
122
+ target.setzIndex(polyline.coordinates[0]?.[2] ?? polyline.height);
123
+ target.show();
124
+ status = 2;
125
+ } else {
126
+ target.hide();
127
+ status = 0;
128
+ }
129
+ break;
130
+
131
+ case "lineWidth":
132
+ target.setOptions({
133
+ strokeWeight: polyline.lineWidth,
134
+ });
135
+ break;
136
+ case "stroke":
137
+ target.setOptions({
138
+ strokeColor: polyline.stroke,
139
+ });
140
+ break;
141
+ case "dash":
142
+ target.setOptions({
143
+ strokeStyle: polyline.dash ? "dashed" : "solid",
144
+ });
145
+ break;
146
+ default:
147
+ throw new Error(`${key} 还不支持修改`);
148
+ }
149
+ });
150
+ };
151
+ const onDbClick = () => {
152
+ switch (status) {
153
+ case 1:
154
+ status = 2;
155
+ skip++;
156
+ polyline.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
157
+ polyline.event.trigger("data-loaded");
158
+ polyline.event.trigger("pointer-in");
159
+ break;
160
+ case 3:
161
+ polyline.event.trigger("stop-edit");
162
+ aMapPolylineEditor.setTarget();
163
+ aMapPolylineEditor.close();
164
+ break;
165
+ }
166
+ };
167
+ const onStartEdit = () => {
168
+ switch (status) {
169
+ case 2:
170
+ status = 3;
171
+ break;
172
+ }
173
+ };
174
+
175
+ const onStopEdit = () => {
176
+ if (status == 3) {
177
+ status = 2;
178
+ skip++;
179
+ polyline.coordinates = target.getPath().map((item) => [item.lng, item.lat]);
180
+ }
181
+ };
182
+
183
+ const onDestroy = () => {
184
+ viewer.remove(target);
185
+ aMapPolylineEditor.close();
186
+ aMapPolylineEditor.setTarget();
187
+ event.off("double-click", onDbClick);
188
+ polyline.event.off("update", onUpdate);
189
+ polyline.event.off("start-edit", onStartEdit);
190
+ polyline.event.off("stop-edit", onStopEdit);
191
+ polyline.event.off("destroy", onDestroy);
192
+ };
193
+
194
+ event.on("double-click", onDbClick);
195
+ polyline.event.on("update", onUpdate);
196
+ polyline.event.on("start-edit", onStartEdit);
197
+ polyline.event.on("stop-edit", onStopEdit);
198
+ polyline.event.on("destroy", onDestroy);
199
+ }
@@ -36,11 +36,11 @@ export abstract class BasicBusiness<T extends BasicBusinessOption> {
36
36
  constructor(map: MapCombine, option: T) {
37
37
  this._map = map;
38
38
  this._option = option;
39
- // const oldElement = map.bussinesses.get(this.name);
40
- // if (oldElement) {
41
- // oldElement.destroy();
42
- // }
43
- // map.bussinesses.set(this.name, this);
39
+ const oldElement = map.bussinesses.get(this.name);
40
+ if (oldElement) {
41
+ oldElement.destroy();
42
+ }
43
+ map.bussinesses.set(this.name, this);
44
44
  }
45
45
 
46
46
  /** 地图展示时触发一次 */
@@ -0,0 +1,49 @@
1
+ import { BasicElement, type BasicElementOption } from "./BasicElement";
2
+
3
+ export interface BasicModelOption extends BasicElementOption {
4
+ name?: string;
5
+ /** 经度 */
6
+ lon: number;
7
+ /** 纬度 */
8
+ lat: number;
9
+ /** 海拔 */
10
+ alt: number;
11
+ /** 模型地址 */
12
+ model: string;
13
+ /** 缩放 */
14
+ scale: number;
15
+ /** 朝向 */
16
+ heading: number;
17
+ /** 俯角 */
18
+ pitch: number;
19
+ /** 倾角 */
20
+ roll: number;
21
+ /** 最小尺寸 */
22
+ minSize: number;
23
+ }
24
+
25
+ export abstract class BasicModel extends BasicElement<BasicModelOption> {
26
+ constructor(option: Partial<BasicModelOption> = {}) {
27
+ super(
28
+ Object.assign(
29
+ {
30
+ show: true,
31
+ cursor: "pointer",
32
+ silent: false,
33
+ lon: 120,
34
+ lat: 30,
35
+ alt: 0,
36
+ scale: 1,
37
+ model: BasicModel.defualtModel,
38
+ heading: 0,
39
+ pitch: 0,
40
+ roll: 0,
41
+ minSize: 16,
42
+ },
43
+ option,
44
+ ),
45
+ );
46
+ }
47
+
48
+ static defualtModel = "./public/xiaoche.glb";
49
+ }
@@ -0,0 +1,154 @@
1
+ import Eventful from "zrender/lib/core/Eventful";
2
+
3
+ import { MapElement, MapElementOption } from "./MapElement";
4
+ import { MapCombine } from "./MapCombine";
5
+
6
+ export interface LayerOption extends MapElementOption {
7
+ show: boolean;
8
+ src: string;
9
+ /** 中心点坐标 [lng, lat, height] */
10
+ coordinates?: number[];
11
+ /** 移动 [x, y, z] */
12
+ translates?: number[];
13
+ /** 旋转 [x, y, z] */
14
+ rotates?: number[];
15
+ /** 缩放 [x, y, z] */
16
+ scales?: number[];
17
+ quality: number;
18
+ opacity?: number;
19
+ zIndex?: number;
20
+ minZoom?: number;
21
+ maxZoom?: number;
22
+ /** 瓦片地图的切分规则 */
23
+ tilingScheme?: any;
24
+ /** 正射影像瓦片数据在地球上覆盖的精确地理范围 */
25
+ rectangle?: any;
26
+ /** 支持自定义瓦片加载参数 */
27
+ credit?: any;
28
+ }
29
+
30
+ export class Layer extends MapElement<LayerOption> {
31
+ type = "Layer";
32
+ tileset;
33
+ event = new Eventful<{
34
+ ready: () => void;
35
+ update: (keys: Set<string>) => void;
36
+ destroy: () => void;
37
+ focus: () => void;
38
+ }>();
39
+
40
+ get show() {
41
+ return this._option.show;
42
+ }
43
+
44
+ set show(val) {
45
+ if (this._option.show != val) {
46
+ this._option.show = val;
47
+ this._update("show");
48
+ }
49
+ }
50
+
51
+ get src() {
52
+ return this._option.src;
53
+ }
54
+
55
+ set src(val) {
56
+ if (this._option.src != val) {
57
+ this._option.src = val;
58
+ this._update("src");
59
+ }
60
+ }
61
+
62
+ get coordinates() {
63
+ return this._option.coordinates;
64
+ }
65
+
66
+ set coordinates(val) {
67
+ if (this._option.coordinates != val) {
68
+ this._option.coordinates = val;
69
+ this._update("coordinates");
70
+ }
71
+ }
72
+ get opacity() {
73
+ return this._option.opacity;
74
+ }
75
+
76
+ set opacity(val) {
77
+ if (this._option.opacity != val) {
78
+ this._option.opacity = val;
79
+ this._update("opacity");
80
+ }
81
+ }
82
+
83
+ get quality() {
84
+ return this._option.quality;
85
+ }
86
+
87
+ set quality(val) {
88
+ if (this._option.quality != val) {
89
+ this._option.quality = val;
90
+ this._update("quality");
91
+ }
92
+ }
93
+
94
+ constructor(map: MapCombine, option: Partial<LayerOption> = {}) {
95
+ super(map, Object.assign({ ...Layer.option }, option));
96
+ }
97
+
98
+ static option: LayerOption = {
99
+ name: "Layer",
100
+ show: true,
101
+ src: "",
102
+ quality: 0.5,
103
+ opacity: 1,
104
+ };
105
+
106
+ private _needUpdate?: Set<string>;
107
+ private _update(key: string) {
108
+ if (this._needUpdate) {
109
+ this._needUpdate.add(key);
110
+ } else {
111
+ this._needUpdate = new Set([key]);
112
+ setTimeout(() => {
113
+ this.event.trigger("update", this._needUpdate);
114
+ this._needUpdate = undefined;
115
+ });
116
+ }
117
+ }
118
+
119
+ /** 基于本地的 ENU 坐标系的偏移,也就是垂直于地表向上为 Z,东为 X,北为 Y
120
+ * @param dx x轴偏移量。单位:米
121
+ * @param dy y轴偏移量。单位:米
122
+ * @param dz z轴偏移量。单位:米
123
+ * @param tileset Cesium3DTileset
124
+ */
125
+ translate(dx: number, dy: number, dz: number, tileset: any = this.tileset) {
126
+ console.info("Layer translate");
127
+ }
128
+ /** 基于本地的 ENU 坐标系的旋转,也就是垂直于地表向上为 Z,东为 X,北为 Y
129
+ * @param rx 绕X轴旋转的角度。单位:度
130
+ * @param ry 绕Y轴旋转的角度。单位:度
131
+ * @param rz 绕Z轴旋转的角度。单位:度
132
+ * @param tileset Cesium3DTileset
133
+ */
134
+ rotate(rx: number, ry: number, rz: number, tileset = this.tileset) {
135
+ console.info("Layer rotate");
136
+ }
137
+ /** 基于本地的 ENU 坐标系的缩放,也就是垂直于地表向上为 Z,东为 X,北为 Y
138
+ * @param sx x 轴缩放倍数
139
+ * @param sy y 轴缩放倍数
140
+ * @param sz z 轴缩放倍数
141
+ * @param tileset Cesium3DTileset
142
+ */
143
+ scale(sx: number, sy: number, sz: number, tileset = this.tileset) {
144
+ console.info("Layer scale");
145
+ }
146
+
147
+ protected _onDestroy(): void {
148
+ this.event.trigger("destroy");
149
+ }
150
+
151
+ focus() {
152
+ this.event.trigger("focus");
153
+ }
154
+ }