@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.
- package/CHANGELOG.md +8 -0
- package/package.json +5 -5
- package/src/amap/AMap.ts +318 -306
- package/src/amap/AMapEvent.ts +110 -54
- package/src/amap/AMapLayer.ts +241 -0
- package/src/amap/AMapPoint.ts +140 -143
- package/src/amap/AMapPolygon.ts +214 -195
- package/src/amap/AMapPolyline.ts +199 -185
- package/src/basic/BasicBusiness.ts +5 -5
- package/src/basic/BasicModel.ts +49 -0
- package/src/basic/Layer.ts +154 -0
- package/src/basic/MapCombine.ts +105 -98
- package/src/basic/MapElement.ts +2 -1
- package/src/basic/MapEvent.ts +5 -0
- package/src/basic/Point.ts +1 -0
- package/src/basic/PointAggregation.tsx +22 -11
- package/src/basic/ReactPopup.tsx +3 -0
- package/src/basic/Tile3D.ts +0 -1
- package/src/cesium/CesiumEvent.ts +97 -84
- package/src/cesium/CesiumLayer.ts +365 -0
- package/src/cesium/CesiumMap.ts +363 -347
- package/src/cesium/CesiumModel.ts +64 -0
- package/src/cesium/CesiumPoint.ts +3 -0
- package/src/cesium/CesiumPolygon.ts +2 -0
- package/src/cesium/CesiumPolyline.ts +185 -47
- package/src/cesium/CesiumTile3D.ts +222 -225
- package/src/mine/MineEvent.ts +70 -46
- package/src/mine/MineMap.ts +217 -125
- package/src/mine/MinePoint.ts +7 -1
- package/src/mine/MinePolygon.ts +6 -1
- package/src/mine/MinePolyline.ts +6 -1
- package/src/openlayer/OpenlayerEvent.ts +109 -87
- package/src/openlayer/OpenlayerMap.ts +33 -6
- package/src/openlayer/OpenlayerPoint.ts +6 -1
- package/src/openlayer/OpenlayerPolygon.ts +6 -1
- package/src/openlayer/OpenlayerPolyline.ts +8 -1
- package/src/utils/color.ts +49 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/points-viewer.ts +27 -1
- package/src/utils/turfjs-utils.ts +52 -0
- package/src/utils/types.d.ts +12 -0
package/src/mine/MineMap.ts
CHANGED
|
@@ -1,125 +1,217 @@
|
|
|
1
|
-
import { MapCombine } from "../basic/MapCombine";
|
|
2
|
-
import { PointOption, Point } from "../basic/Point";
|
|
3
|
-
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
4
|
-
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
5
|
-
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
6
|
-
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
7
|
-
import { bindEvent } from "./MineEvent";
|
|
8
|
-
import { drawPoint } from "./MinePoint";
|
|
9
|
-
import { drawPolygon } from "./MinePolygon";
|
|
10
|
-
import { drawPolyline } from "./MinePolyline";
|
|
11
|
-
import { drawTile3D } from "./MineTile3D";
|
|
12
|
-
|
|
13
|
-
const MAX_ZOOM = 18;
|
|
14
|
-
|
|
15
|
-
export class MineMap extends MapCombine {
|
|
16
|
-
viewer: any;
|
|
17
|
-
container: HTMLDivElement;
|
|
18
|
-
|
|
19
|
-
get cursor(): string {
|
|
20
|
-
return this.viewer.getCursor();
|
|
21
|
-
}
|
|
22
|
-
set cursor(val: string) {
|
|
23
|
-
this.viewer.setCursor(val);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get moveable(): boolean {
|
|
27
|
-
return this.viewer.dragPan.isEnabled();
|
|
28
|
-
}
|
|
29
|
-
set moveable(val: boolean) {
|
|
30
|
-
val ? this.viewer.dragPan.enable() : this.viewer.dragPan.disable();
|
|
31
|
-
}
|
|
32
|
-
get center(): number[] {
|
|
33
|
-
const p = this.viewer.getCenter();
|
|
34
|
-
return [p.lng, p.lat];
|
|
35
|
-
}
|
|
36
|
-
set center(val: number[]) {
|
|
37
|
-
this.viewer.setCenter(val);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get zoom(): number {
|
|
41
|
-
return this.viewer.getZoom();
|
|
42
|
-
}
|
|
43
|
-
set zoom(val: number) {
|
|
44
|
-
this.viewer.setZoom(val);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
constructor(viewer
|
|
48
|
-
super();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.viewer
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
1
|
+
import { MapCombine } from "../basic/MapCombine";
|
|
2
|
+
import { PointOption, Point } from "../basic/Point";
|
|
3
|
+
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
4
|
+
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
5
|
+
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
6
|
+
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
7
|
+
import { bindEvent } from "./MineEvent";
|
|
8
|
+
import { drawPoint } from "./MinePoint";
|
|
9
|
+
import { drawPolygon } from "./MinePolygon";
|
|
10
|
+
import { drawPolyline } from "./MinePolyline";
|
|
11
|
+
import { drawTile3D } from "./MineTile3D";
|
|
12
|
+
|
|
13
|
+
const MAX_ZOOM = 18;
|
|
14
|
+
|
|
15
|
+
export class MineMap extends MapCombine {
|
|
16
|
+
viewer: any;
|
|
17
|
+
container: HTMLDivElement;
|
|
18
|
+
|
|
19
|
+
get cursor(): string {
|
|
20
|
+
return this.viewer.getCursor();
|
|
21
|
+
}
|
|
22
|
+
set cursor(val: string) {
|
|
23
|
+
this.viewer.setCursor(val);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get moveable(): boolean {
|
|
27
|
+
return this.viewer.dragPan.isEnabled();
|
|
28
|
+
}
|
|
29
|
+
set moveable(val: boolean) {
|
|
30
|
+
val ? this.viewer.dragPan.enable() : this.viewer.dragPan.disable();
|
|
31
|
+
}
|
|
32
|
+
get center(): number[] {
|
|
33
|
+
const p = this.viewer.getCenter();
|
|
34
|
+
return [p.lng, p.lat];
|
|
35
|
+
}
|
|
36
|
+
set center(val: number[]) {
|
|
37
|
+
this.viewer.setCenter(val);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get zoom(): number {
|
|
41
|
+
return this.viewer.getZoom();
|
|
42
|
+
}
|
|
43
|
+
set zoom(val: number) {
|
|
44
|
+
this.viewer.setZoom(val);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
constructor(viewer?: any) {
|
|
48
|
+
super();
|
|
49
|
+
viewer && this._initParamsEvent(viewer);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
init(opt) {
|
|
53
|
+
const {
|
|
54
|
+
container,
|
|
55
|
+
url,
|
|
56
|
+
minZoom = 4,
|
|
57
|
+
maxZoom = 18,
|
|
58
|
+
center = [120.2288892, 30.2349677, 0],
|
|
59
|
+
zoom = 13,
|
|
60
|
+
...options
|
|
61
|
+
} = opt || {};
|
|
62
|
+
this.viewer = new minemap.Map({
|
|
63
|
+
container: container,
|
|
64
|
+
style: {
|
|
65
|
+
version: 8,
|
|
66
|
+
sources: {
|
|
67
|
+
tilemap: {
|
|
68
|
+
type: "raster",
|
|
69
|
+
tiles: [url],
|
|
70
|
+
tileSize: 256,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
layers: [
|
|
74
|
+
{
|
|
75
|
+
id: "tilemap",
|
|
76
|
+
type: "raster",
|
|
77
|
+
source: "tilemap",
|
|
78
|
+
minzoom: 0,
|
|
79
|
+
maxzoom: 22,
|
|
80
|
+
layout: { visibility: "visible" },
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
doubleClickZoom: false,
|
|
85
|
+
center,
|
|
86
|
+
zoom,
|
|
87
|
+
pitch: 0,
|
|
88
|
+
maxZoom,
|
|
89
|
+
minZoom,
|
|
90
|
+
...options,
|
|
91
|
+
});
|
|
92
|
+
this._initParamsEvent(this.viewer);
|
|
93
|
+
return this.viewer;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
_initParamsEvent(viewer) {
|
|
97
|
+
if (!viewer) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.viewer = viewer;
|
|
101
|
+
this.container = viewer.getContainer();
|
|
102
|
+
this.container.children.item(1).appendChild(this.htmllayer);
|
|
103
|
+
this.cursor = "default";
|
|
104
|
+
bindEvent(this);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
canvasTgeography(p: number[]): number[] {
|
|
108
|
+
const res = this.viewer.getTDSpaceCoord({ point: p, disableLayer: true });
|
|
109
|
+
return [res.lngLat.lng, res.lngLat.lat, 0];
|
|
110
|
+
}
|
|
111
|
+
geographyTcanvas(p: number[]): number[] {
|
|
112
|
+
const res = this.viewer.project([p[0], p[1]], p[2] ?? 0);
|
|
113
|
+
return [res.x, res.y];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
createPoint<K>(option?: Partial<PointOption<K>>): Point<K> {
|
|
117
|
+
const e = new Point(this, option);
|
|
118
|
+
drawPoint(this, e);
|
|
119
|
+
return e;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
createPointAggregation(option?: PointAggregationOption): PointAggregation {
|
|
123
|
+
const e = new PointAggregation(this, option);
|
|
124
|
+
return e;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
|
|
128
|
+
const e = new Polyline(this, option);
|
|
129
|
+
drawPolyline(this, e);
|
|
130
|
+
return e;
|
|
131
|
+
}
|
|
132
|
+
createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K> {
|
|
133
|
+
const e = new Polygon(this, option);
|
|
134
|
+
drawPolygon(this, e);
|
|
135
|
+
return e;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
createTile3D(option?: Partial<Tile3DOption>): Tile3D {
|
|
139
|
+
const e = new Tile3D(this, option);
|
|
140
|
+
drawTile3D(this, e);
|
|
141
|
+
return e;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
createLayer(option?: Partial<unknown>): unknown {
|
|
145
|
+
const drawLayer = () => {
|
|
146
|
+
// 检查 source 是否已存在
|
|
147
|
+
if (this.viewer.getSource("ortho-source")) {
|
|
148
|
+
console.warn("Source already exists, removing old one");
|
|
149
|
+
try {
|
|
150
|
+
if (this.viewer.getLayer("ortho-layer")) {
|
|
151
|
+
this.viewer.removeLayer("ortho-layer");
|
|
152
|
+
}
|
|
153
|
+
this.viewer.removeSource("ortho-source");
|
|
154
|
+
} catch (e) {
|
|
155
|
+
console.warn("Remove failed:", e);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 添加 source
|
|
160
|
+
this.viewer.addSource("ortho-source", {
|
|
161
|
+
type: "raster",
|
|
162
|
+
tiles: [option.url],
|
|
163
|
+
tileSize: 256,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// 添加 layer
|
|
167
|
+
this.viewer.addLayer({
|
|
168
|
+
id: "ortho-layer",
|
|
169
|
+
type: "raster",
|
|
170
|
+
source: "ortho-source",
|
|
171
|
+
paint: {
|
|
172
|
+
"raster-opacity": option.opacity || 1.0,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// 等待地图加载完成
|
|
178
|
+
if (this.viewer.loaded()) {
|
|
179
|
+
drawLayer();
|
|
180
|
+
} else {
|
|
181
|
+
this.viewer.once("load", drawLayer);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 所有点位移动至视口,调整位置及层级
|
|
187
|
+
* @param points
|
|
188
|
+
* @param opt
|
|
189
|
+
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
190
|
+
*/
|
|
191
|
+
flyToViewer(points, opt = { avoid: [0, 0, 0, 0], maxZoom: MAX_ZOOM }) {
|
|
192
|
+
if (points?.length === 0) {
|
|
193
|
+
return this.flyTo(points[0], opt);
|
|
194
|
+
}
|
|
195
|
+
const rectangle = this.getBounds(points, { canvas: this.viewer.getCanvas(), ...opt });
|
|
196
|
+
|
|
197
|
+
// 设置地图视图,使用调整后的边界范围
|
|
198
|
+
this.viewer.fitBounds(
|
|
199
|
+
[
|
|
200
|
+
[rectangle[0], rectangle[1]],
|
|
201
|
+
[rectangle[2], rectangle[3]],
|
|
202
|
+
],
|
|
203
|
+
{
|
|
204
|
+
maxZoom: opt?.maxZoom ?? MAX_ZOOM,
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* 移动点位到中心点
|
|
211
|
+
* @param point
|
|
212
|
+
*/
|
|
213
|
+
flyTo(point, opt = {}) {
|
|
214
|
+
// 设置相机视角
|
|
215
|
+
this.viewer.flyTo({ center: point, ...opt });
|
|
216
|
+
}
|
|
217
|
+
}
|
package/src/mine/MinePoint.ts
CHANGED
|
@@ -28,10 +28,16 @@ export function drawPoint(map: MineMap, point: Point<unknown>) {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const marker = new minemap.Marker({
|
|
31
|
+
id: point.name,
|
|
31
32
|
draggable: point.editable,
|
|
32
33
|
rotation: 0,
|
|
33
34
|
offset: [-size[0] * center[0], -size[1] * center[1]],
|
|
34
35
|
element: img,
|
|
36
|
+
extData: {
|
|
37
|
+
name: point.name,
|
|
38
|
+
target: point,
|
|
39
|
+
userdata: point.userdata,
|
|
40
|
+
},
|
|
35
41
|
});
|
|
36
42
|
|
|
37
43
|
if (point.coordinates) {
|
|
@@ -69,7 +75,7 @@ export function drawPoint(map: MineMap, point: Point<unknown>) {
|
|
|
69
75
|
break;
|
|
70
76
|
case "coordinates":
|
|
71
77
|
if (point.coordinates) {
|
|
72
|
-
marker.setLngLat(point.coordinates).setAltitude(point.coordinates[2] ??
|
|
78
|
+
marker.setLngLat(point.coordinates).setAltitude(point.coordinates[2] ?? point.height);
|
|
73
79
|
switch (status) {
|
|
74
80
|
case 0:
|
|
75
81
|
point.show && marker.addTo(map.viewer);
|
package/src/mine/MinePolygon.ts
CHANGED
|
@@ -50,6 +50,7 @@ function getPolygonOption(polygon: Polygon<unknown>) {
|
|
|
50
50
|
"fill-color": color,
|
|
51
51
|
"fill-opacity": opacity,
|
|
52
52
|
},
|
|
53
|
+
zIndex: polygon.coordinates[0]?.[2] ?? polygon.height,
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -148,11 +149,15 @@ function main(map: MineMap, polygon: Polygon<unknown>) {
|
|
|
148
149
|
type: "Feature",
|
|
149
150
|
geometry: {
|
|
150
151
|
type: "Polygon",
|
|
151
|
-
coordinates: [[...coordinates, coordinates[0]]],
|
|
152
|
+
coordinates: [[...coordinates, coordinates[0]].map((it) => [it[0], it[1], it[2] ?? polygon.height])],
|
|
152
153
|
},
|
|
153
154
|
properties: {
|
|
154
155
|
id: polygon.name,
|
|
155
156
|
},
|
|
157
|
+
extData: {
|
|
158
|
+
name: polygon.name,
|
|
159
|
+
userdata: polygon.userdata,
|
|
160
|
+
},
|
|
156
161
|
};
|
|
157
162
|
} else {
|
|
158
163
|
data.features = [];
|
package/src/mine/MinePolyline.ts
CHANGED
|
@@ -56,6 +56,7 @@ function getLayerOption(polyline: Polyline<unknown>) {
|
|
|
56
56
|
"line-color": polyline.stroke,
|
|
57
57
|
"line-width": polyline.lineWidth,
|
|
58
58
|
},
|
|
59
|
+
zIndex: polyline.coordinates[0]?.[2] ?? polyline.height,
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -130,10 +131,14 @@ function main(map: MineMap, polyline: Polyline<unknown>) {
|
|
|
130
131
|
type: "Feature",
|
|
131
132
|
geometry: {
|
|
132
133
|
type: "LineString",
|
|
133
|
-
coordinates: coordinates,
|
|
134
|
+
coordinates: coordinates?.map((it) => [it[0], it[1], it[2] ?? polyline.height]),
|
|
134
135
|
},
|
|
135
136
|
properties: {
|
|
136
137
|
id: polyline.name,
|
|
138
|
+
extData: {
|
|
139
|
+
name: polyline.name,
|
|
140
|
+
userdata: polyline.userdata,
|
|
141
|
+
},
|
|
137
142
|
},
|
|
138
143
|
};
|
|
139
144
|
} else {
|
|
@@ -1,87 +1,109 @@
|
|
|
1
|
-
import { OpenlayerMap } from "./OpenlayerMap";
|
|
2
|
-
|
|
3
|
-
export function bindEvent(map: OpenlayerMap) {
|
|
4
|
-
const { event, viewer, container } = map;
|
|
5
|
-
let target: any;
|
|
6
|
-
let moving = false;
|
|
7
|
-
|
|
8
|
-
const frame = () => {
|
|
9
|
-
if (map.isAlive) {
|
|
10
|
-
requestAnimationFrame(frame);
|
|
11
|
-
event.trigger("view-preRender");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
event.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
event.trigger("
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
import { OpenlayerMap } from "./OpenlayerMap";
|
|
2
|
+
|
|
3
|
+
export function bindEvent(map: OpenlayerMap) {
|
|
4
|
+
const { event, viewer, container } = map;
|
|
5
|
+
let target: any;
|
|
6
|
+
let moving = false;
|
|
7
|
+
|
|
8
|
+
const frame = () => {
|
|
9
|
+
if (map.isAlive) {
|
|
10
|
+
requestAnimationFrame(frame);
|
|
11
|
+
event.trigger("view-preRender");
|
|
12
|
+
map.bussinesses.forEach((e) => e.show && e.onFrame?.());
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
frame();
|
|
16
|
+
|
|
17
|
+
viewer.on("moveend", (e) => {
|
|
18
|
+
event.trigger("view-moveEnd");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
viewer.on("pointermove", (e) => {
|
|
22
|
+
event.canvas = e.pixel;
|
|
23
|
+
event.geography = map.canvasTgeography(event.canvas);
|
|
24
|
+
let _target: any;
|
|
25
|
+
if (moving) {
|
|
26
|
+
event.trigger("pointer-move");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const res = viewer.getFeaturesAtPixel(event.canvas)[0];
|
|
30
|
+
_target = res ? res.get("event") : undefined;
|
|
31
|
+
if (_target?.silent) {
|
|
32
|
+
_target = undefined;
|
|
33
|
+
}
|
|
34
|
+
if (_target !== target) {
|
|
35
|
+
target?.onPointerOut?.();
|
|
36
|
+
_target?.onPointerIn?.();
|
|
37
|
+
target = _target;
|
|
38
|
+
}
|
|
39
|
+
event.trigger("pointer-move");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
container.addEventListener("mousedown", () => {
|
|
43
|
+
if (target) {
|
|
44
|
+
moving = true;
|
|
45
|
+
target.onPointerDown?.();
|
|
46
|
+
}
|
|
47
|
+
event.trigger("pointer-down");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
container.addEventListener("mouseup", () => {
|
|
51
|
+
if (target) {
|
|
52
|
+
moving = false;
|
|
53
|
+
target.onPointerUp?.();
|
|
54
|
+
}
|
|
55
|
+
event.trigger("pointer-up");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
container.addEventListener("contextmenu", (e) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
if (target) {
|
|
61
|
+
target.onRClick?.();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
viewer.on("click", () => {
|
|
66
|
+
if (target) {
|
|
67
|
+
target.onLClick?.();
|
|
68
|
+
}
|
|
69
|
+
event.trigger("left-click");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// 监听地图的单击事件
|
|
73
|
+
viewer.on("singleclick", function (e) {
|
|
74
|
+
// 使用 forEachFeatureAtPixel 查询该像素位置下的所有要素
|
|
75
|
+
const pickedObjects = [];
|
|
76
|
+
viewer.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
|
|
77
|
+
// 这个回调函数会为每一个被点击到的要素执行
|
|
78
|
+
pickedObjects.push(feature);
|
|
79
|
+
// 返回 true 可以提前终止遍历
|
|
80
|
+
// return true;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (pickedObjects.length > 0) {
|
|
84
|
+
event.trigger("drill-pick", {
|
|
85
|
+
event: e,
|
|
86
|
+
pickedTargets: pickedObjects.map((it) => it?.values_?.userData?.target),
|
|
87
|
+
sourceObjects: pickedObjects,
|
|
88
|
+
position: map.canvasTgeography(e.pixel),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
viewer.on("dblclick", () => {
|
|
94
|
+
if (target) {
|
|
95
|
+
target.onDbClick?.();
|
|
96
|
+
}
|
|
97
|
+
map.event.trigger("double-click");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
let key = 0;
|
|
101
|
+
|
|
102
|
+
viewer.on("precompose", () => {
|
|
103
|
+
const _key = map.center.reduce((a, b) => a + b, map.zoom);
|
|
104
|
+
if (key != _key) {
|
|
105
|
+
key = _key;
|
|
106
|
+
event.trigger("view-change");
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -6,11 +6,10 @@ import Tile from "ol/layer/Tile";
|
|
|
6
6
|
import DragPan from "ol/interaction/DragPan";
|
|
7
7
|
import VectorSource from "ol/source/Vector";
|
|
8
8
|
import VectorLayer from "ol/layer/Vector";
|
|
9
|
+
import TileLayer from "ol/layer/Tile";
|
|
9
10
|
import { fromLonLat } from "ol/proj";
|
|
10
11
|
import * as olGeom from "ol/geom";
|
|
11
12
|
import * as olSource from "ol/source";
|
|
12
|
-
import * as olStyle from "ol/style";
|
|
13
|
-
import * as olLayer from "ol/layer";
|
|
14
13
|
import * as olExtent from "ol/extent";
|
|
15
14
|
|
|
16
15
|
import { MapCombine } from "../basic/MapCombine";
|
|
@@ -173,6 +172,38 @@ export class OpenlayerMap extends MapCombine {
|
|
|
173
172
|
return e;
|
|
174
173
|
}
|
|
175
174
|
|
|
175
|
+
createTile3D(option?: Partial<Tile3DOption>): Tile3D {
|
|
176
|
+
throw new Error("Method not implemented.");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
createLayer(option?: Partial<unknown>): unknown {
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
import {transformExtent} from 'ol/proj';
|
|
183
|
+
|
|
184
|
+
// 假设你的图片地理范围是经纬度 (EPSG:4326)
|
|
185
|
+
const imageExtent = [115.38, 40.18, 115.39, 40.19];
|
|
186
|
+
// 如果地图视图是 Web Mercator (EPSG:3857),需要转换范围
|
|
187
|
+
const extent3857 = transformExtent(imageExtent, 'EPSG:4326', 'EPSG:3857');
|
|
188
|
+
*/
|
|
189
|
+
const layer = new TileLayer({
|
|
190
|
+
source: new XYZ({
|
|
191
|
+
...option,
|
|
192
|
+
// 可选:如果图片有透明背景,设置透明属性
|
|
193
|
+
// 可选:设置投影(如果你的瓦片是经纬度投影)
|
|
194
|
+
// projection: 'EPSG:4326',
|
|
195
|
+
// 可选:设置瓦片大小(默认256)
|
|
196
|
+
// tileSize: 256,
|
|
197
|
+
// 可选:处理跨域问题
|
|
198
|
+
// crossOrigin: 'anonymous',
|
|
199
|
+
// 可选:设置瓦片加载失败时的重试次数
|
|
200
|
+
// transition: 0,
|
|
201
|
+
}),
|
|
202
|
+
});
|
|
203
|
+
this.viewer.addLayer(layer);
|
|
204
|
+
return layer;
|
|
205
|
+
}
|
|
206
|
+
|
|
176
207
|
// protected _onFrame(): void {
|
|
177
208
|
// const { viewer, camera, offset } = this;
|
|
178
209
|
// const box = viewer.getView().calculateExtent(viewer.getSize());
|
|
@@ -268,10 +299,6 @@ export class OpenlayerMap extends MapCombine {
|
|
|
268
299
|
return [coordinates[0] - this.offset[0], coordinates[1] - this.offset[1], 0];
|
|
269
300
|
}
|
|
270
301
|
|
|
271
|
-
createTile3D(option?: Partial<Tile3DOption>): Tile3D {
|
|
272
|
-
throw new Error("Method not implemented.");
|
|
273
|
-
}
|
|
274
|
-
|
|
275
302
|
canvasTgeography(p: number[]): number[] {
|
|
276
303
|
const coordinates = this.viewer.getCoordinateFromPixel(p);
|
|
277
304
|
// 解决 coordinates 为 null 异常情况
|