@hzab/map-combine 0.4.2-alpha.11 → 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 +1 -0
- package/package.json +1 -1
- package/src/amap/AMap.ts +5 -0
- package/src/amap/AMapLayer.ts +241 -0
- package/src/basic/Layer.ts +154 -0
- package/src/basic/MapCombine.ts +105 -102
- package/src/basic/Tile3D.ts +0 -1
- package/src/cesium/CesiumLayer.ts +365 -0
- package/src/cesium/CesiumMap.ts +8 -0
- package/src/mine/MineMap.ts +217 -176
- package/src/openlayer/OpenlayerMap.ts +33 -6
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/amap/AMap.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { bindEvent } from "./AMapEvent";
|
|
|
11
11
|
import { drawPoint } from "./AMapPoint";
|
|
12
12
|
import { drawPolyline } from "./AMapPolyline";
|
|
13
13
|
import { drawPolygon } from "./AMapPolygon";
|
|
14
|
+
import { drawLayer } from "./AMapLayer";
|
|
14
15
|
|
|
15
16
|
export interface IAMapOption {
|
|
16
17
|
container: HTMLDivElement;
|
|
@@ -210,6 +211,10 @@ export class AMap extends MapCombine {
|
|
|
210
211
|
throw new Error("Method not implemented.");
|
|
211
212
|
}
|
|
212
213
|
|
|
214
|
+
createLayer(option?: Partial<unknown>): unknown {
|
|
215
|
+
return drawLayer(this, option);
|
|
216
|
+
}
|
|
217
|
+
|
|
213
218
|
/**
|
|
214
219
|
* 将高德地图 Canvas 像素坐标转换为经纬度
|
|
215
220
|
* @param {Array} p - canvas 点位数组 [x, y]
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
export function drawLayer(map, option) {
|
|
2
|
+
console.log("option.url", option.url);
|
|
3
|
+
const urlTemplate = option.url || "";
|
|
4
|
+
const self = map;
|
|
5
|
+
|
|
6
|
+
// 1. 获取地图容器
|
|
7
|
+
const container = map.viewer.getContainer();
|
|
8
|
+
|
|
9
|
+
// 2. 手动创建 canvas 并添加到容器
|
|
10
|
+
const canvas = document.createElement("canvas");
|
|
11
|
+
const mapSize = map.viewer.getSize();
|
|
12
|
+
canvas.width = mapSize.width;
|
|
13
|
+
canvas.height = mapSize.height;
|
|
14
|
+
canvas.style.cssText = `
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: 0;
|
|
17
|
+
left: 0;
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
z-index: 1000;
|
|
21
|
+
pointer-events: none;
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
container.appendChild(canvas);
|
|
25
|
+
console.log("Canvas 已手动添加到容器,尺寸:", canvas.width, canvas.height);
|
|
26
|
+
|
|
27
|
+
// 3. 瓦片缓存
|
|
28
|
+
const tileCache = new Map();
|
|
29
|
+
|
|
30
|
+
// 4. 经纬度转瓦片坐标
|
|
31
|
+
function lngLatToTile(lng: number, lat: number, zoom: number) {
|
|
32
|
+
const n = Math.pow(2, zoom);
|
|
33
|
+
const x = ((lng + 180) / 360) * n;
|
|
34
|
+
const y = ((1 - Math.log(Math.tan((lat * Math.PI) / 180) + 1 / Math.cos((lat * Math.PI) / 180)) / Math.PI) / 2) * n;
|
|
35
|
+
return { x: Math.floor(x), y: Math.floor(y) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 5. 瓦片坐标转经纬度
|
|
39
|
+
function tileToLngLat(tileX: number, tileY: number, zoom: number) {
|
|
40
|
+
const n = Math.pow(2, zoom);
|
|
41
|
+
const lng = (tileX / n) * 360 - 180;
|
|
42
|
+
const lat = (Math.atan(Math.sinh(Math.PI * (1 - (2 * tileY) / n))) * 180) / Math.PI;
|
|
43
|
+
return { lng, lat };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 6. 获取当前视口的瓦片范围(增加预加载扩展)
|
|
47
|
+
function getTileRange() {
|
|
48
|
+
const zoom = self.viewer.getZoom();
|
|
49
|
+
const level = Math.floor(zoom);
|
|
50
|
+
|
|
51
|
+
const bounds = self.viewer.getBounds();
|
|
52
|
+
if (!bounds) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const sw = bounds.getSouthWest();
|
|
57
|
+
const ne = bounds.getNorthEast();
|
|
58
|
+
|
|
59
|
+
// 扩展范围,预加载周边瓦片(移动时更流畅)
|
|
60
|
+
const expandFactor = 0.3;
|
|
61
|
+
const lngMin = sw.getLng() - (ne.getLng() - sw.getLng()) * expandFactor;
|
|
62
|
+
const lngMax = ne.getLng() + (ne.getLng() - sw.getLng()) * expandFactor;
|
|
63
|
+
const latMin = sw.getLat() - (ne.getLat() - sw.getLat()) * expandFactor;
|
|
64
|
+
const latMax = ne.getLat() + (ne.getLat() - sw.getLat()) * expandFactor;
|
|
65
|
+
|
|
66
|
+
const topLeft = lngLatToTile(lngMin, latMax, level);
|
|
67
|
+
const bottomRight = lngLatToTile(lngMax, latMin, level);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
minX: topLeft.x,
|
|
71
|
+
maxX: bottomRight.x,
|
|
72
|
+
minY: topLeft.y,
|
|
73
|
+
maxY: bottomRight.y,
|
|
74
|
+
level: level,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 7. 绘制单张瓦片
|
|
79
|
+
function drawSingleTile(
|
|
80
|
+
ctx: CanvasRenderingContext2D,
|
|
81
|
+
img: HTMLImageElement,
|
|
82
|
+
tileX: number,
|
|
83
|
+
tileY: number,
|
|
84
|
+
zoom: number,
|
|
85
|
+
) {
|
|
86
|
+
const nw = tileToLngLat(tileX, tileY, zoom);
|
|
87
|
+
const se = tileToLngLat(tileX + 1, tileY + 1, zoom);
|
|
88
|
+
|
|
89
|
+
const pNW = self.viewer.lngLatToContainer(new self.LbsAMap.LngLat(nw.lng, nw.lat));
|
|
90
|
+
const pSE = self.viewer.lngLatToContainer(new self.LbsAMap.LngLat(se.lng, se.lat));
|
|
91
|
+
|
|
92
|
+
const minX = Math.min(pNW.x, pSE.x);
|
|
93
|
+
const maxX = Math.max(pNW.x, pSE.x);
|
|
94
|
+
const minY = Math.min(pNW.y, pSE.y);
|
|
95
|
+
const maxY = Math.max(pNW.y, pSE.y);
|
|
96
|
+
|
|
97
|
+
const width = maxX - minX;
|
|
98
|
+
const height = maxY - minY;
|
|
99
|
+
|
|
100
|
+
const padding = 100;
|
|
101
|
+
if (maxX < -padding || minX > canvas.width + padding || maxY < -padding || minY > canvas.height + padding) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
ctx.imageSmoothingEnabled = true;
|
|
106
|
+
ctx.imageSmoothingQuality = "high";
|
|
107
|
+
ctx.drawImage(img, minX, minY, width, height);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 8. 主加载函数
|
|
111
|
+
let isLoading = false;
|
|
112
|
+
let pendingTiles = 0;
|
|
113
|
+
let animationId: number | null = null;
|
|
114
|
+
|
|
115
|
+
function loadAndDrawTiles() {
|
|
116
|
+
if (animationId !== null) {
|
|
117
|
+
cancelAnimationFrame(animationId);
|
|
118
|
+
animationId = null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
animationId = requestAnimationFrame(() => {
|
|
122
|
+
const ctx = canvas.getContext("2d");
|
|
123
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
124
|
+
|
|
125
|
+
const range = getTileRange();
|
|
126
|
+
if (!range) {
|
|
127
|
+
console.warn("无法获取地图范围");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const { minX, maxX, minY, maxY, level } = range;
|
|
132
|
+
|
|
133
|
+
if (!isLoading) {
|
|
134
|
+
isLoading = true;
|
|
135
|
+
pendingTiles = 0;
|
|
136
|
+
|
|
137
|
+
// 先绘制已缓存的瓦片
|
|
138
|
+
for (let x = minX; x <= maxX; x++) {
|
|
139
|
+
for (let y = minY; y <= maxY; y++) {
|
|
140
|
+
const cacheKey = `${level}/${x}/${y}`;
|
|
141
|
+
if (tileCache.has(cacheKey)) {
|
|
142
|
+
const cachedImg = tileCache.get(cacheKey);
|
|
143
|
+
drawSingleTile(ctx, cachedImg, x, y, level);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 加载新的瓦片
|
|
149
|
+
let newTilesCount = 0;
|
|
150
|
+
for (let x = minX; x <= maxX; x++) {
|
|
151
|
+
for (let y = minY; y <= maxY; y++) {
|
|
152
|
+
const cacheKey = `${level}/${x}/${y}`;
|
|
153
|
+
|
|
154
|
+
if (tileCache.has(cacheKey)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const url = urlTemplate
|
|
159
|
+
.replace(/\{z\}/g, String(level))
|
|
160
|
+
.replace(/\{x\}/g, String(x))
|
|
161
|
+
.replace(/\{y\}/g, String(y));
|
|
162
|
+
|
|
163
|
+
newTilesCount++;
|
|
164
|
+
pendingTiles++;
|
|
165
|
+
const img = new Image();
|
|
166
|
+
img.crossOrigin = "anonymous";
|
|
167
|
+
|
|
168
|
+
img.onload = () => {
|
|
169
|
+
tileCache.set(cacheKey, img);
|
|
170
|
+
drawSingleTile(ctx, img, x, y, level);
|
|
171
|
+
pendingTiles--;
|
|
172
|
+
if (pendingTiles === 0) {
|
|
173
|
+
isLoading = false;
|
|
174
|
+
console.log("所有瓦片加载完成");
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
img.onerror = () => {
|
|
179
|
+
console.warn("瓦片加载失败:", url);
|
|
180
|
+
pendingTiles--;
|
|
181
|
+
if (pendingTiles === 0) {
|
|
182
|
+
isLoading = false;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
img.src = url;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (newTilesCount === 0) {
|
|
191
|
+
isLoading = false;
|
|
192
|
+
} else {
|
|
193
|
+
console.log(`正在加载 ${newTilesCount} 个新瓦片`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
animationId = null;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 9. 绑定事件
|
|
202
|
+
let renderTimer: any = null;
|
|
203
|
+
|
|
204
|
+
function scheduleRender() {
|
|
205
|
+
if (renderTimer) {
|
|
206
|
+
clearTimeout(renderTimer);
|
|
207
|
+
}
|
|
208
|
+
renderTimer = setTimeout(() => {
|
|
209
|
+
loadAndDrawTiles();
|
|
210
|
+
renderTimer = null;
|
|
211
|
+
}, 16);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
map.viewer.on("moving", scheduleRender);
|
|
215
|
+
map.viewer.on("moveend", () => {
|
|
216
|
+
if (renderTimer) {
|
|
217
|
+
clearTimeout(renderTimer);
|
|
218
|
+
renderTimer = null;
|
|
219
|
+
}
|
|
220
|
+
loadAndDrawTiles();
|
|
221
|
+
});
|
|
222
|
+
map.viewer.on("zoomend", () => {
|
|
223
|
+
if (renderTimer) {
|
|
224
|
+
clearTimeout(renderTimer);
|
|
225
|
+
renderTimer = null;
|
|
226
|
+
}
|
|
227
|
+
loadAndDrawTiles();
|
|
228
|
+
});
|
|
229
|
+
map.viewer.on("resize", function () {
|
|
230
|
+
const newSize = self.viewer.getSize();
|
|
231
|
+
canvas.width = newSize.width;
|
|
232
|
+
canvas.height = newSize.height;
|
|
233
|
+
loadAndDrawTiles();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
setTimeout(() => {
|
|
237
|
+
loadAndDrawTiles();
|
|
238
|
+
}, 500);
|
|
239
|
+
|
|
240
|
+
return canvas;
|
|
241
|
+
}
|
|
@@ -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
|
+
}
|
package/src/basic/MapCombine.ts
CHANGED
|
@@ -1,102 +1,105 @@
|
|
|
1
|
-
import { ContextMenu } from "./ContextMenu";
|
|
2
|
-
import { MapElement } from "./MapElement";
|
|
3
|
-
import { MapEvent } from "./MapEvent";
|
|
4
|
-
import { Point, PointOption } from "./Point";
|
|
5
|
-
import { PointAggregation, PointAggregationOption } from "./PointAggregation";
|
|
6
|
-
import { Polygon, PolygonOption } from "./Polygon";
|
|
7
|
-
import { Polyline, PolylineOption } from "./Polyline";
|
|
8
|
-
import { ReactPoint, ReactPointOption, drawReactPoint } from "./ReactPoint";
|
|
9
|
-
import { Tile3D, Tile3DOption } from "./Tile3D";
|
|
10
|
-
import { BasicModel, BasicModelOption } from "./BasicModel";
|
|
11
|
-
import { type BasicBusiness, type BasicBusinessOption } from "./BasicBusiness";
|
|
12
|
-
|
|
13
|
-
import { getBounds } from "../utils/points-viewer";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
21
|
-
|
|
22
|
-
abstract
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
abstract
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
abstract
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
abstract
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
htmllayer
|
|
42
|
-
htmllayer.style.
|
|
43
|
-
htmllayer.style.
|
|
44
|
-
htmllayer.style.
|
|
45
|
-
htmllayer.style.
|
|
46
|
-
htmllayer.style.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* @param
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
import { ContextMenu } from "./ContextMenu";
|
|
2
|
+
import { MapElement } from "./MapElement";
|
|
3
|
+
import { MapEvent } from "./MapEvent";
|
|
4
|
+
import { Point, PointOption } from "./Point";
|
|
5
|
+
import { PointAggregation, PointAggregationOption } from "./PointAggregation";
|
|
6
|
+
import { Polygon, PolygonOption } from "./Polygon";
|
|
7
|
+
import { Polyline, PolylineOption } from "./Polyline";
|
|
8
|
+
import { ReactPoint, ReactPointOption, drawReactPoint } from "./ReactPoint";
|
|
9
|
+
import { Tile3D, Tile3DOption } from "./Tile3D";
|
|
10
|
+
import { BasicModel, BasicModelOption } from "./BasicModel";
|
|
11
|
+
import { type BasicBusiness, type BasicBusinessOption } from "./BasicBusiness";
|
|
12
|
+
|
|
13
|
+
import { getBounds } from "../utils/points-viewer";
|
|
14
|
+
import { Layer, LayerOption } from "./Layer";
|
|
15
|
+
|
|
16
|
+
export abstract class MapCombine {
|
|
17
|
+
/* 用于挂载html元素的根节点 */
|
|
18
|
+
readonly htmllayer = document.createElement("div");
|
|
19
|
+
readonly elements = new Map<string, MapElement>();
|
|
20
|
+
readonly event = new MapEvent();
|
|
21
|
+
readonly menu: ContextMenu;
|
|
22
|
+
abstract get cursor(): string;
|
|
23
|
+
abstract set cursor(val: string);
|
|
24
|
+
|
|
25
|
+
abstract get moveable(): boolean;
|
|
26
|
+
abstract set moveable(val: boolean);
|
|
27
|
+
|
|
28
|
+
abstract get center(): number[];
|
|
29
|
+
abstract set center(val);
|
|
30
|
+
|
|
31
|
+
abstract get zoom(): number;
|
|
32
|
+
abstract set zoom(val);
|
|
33
|
+
|
|
34
|
+
loadPromise: Promise<this> = Promise.resolve(this);
|
|
35
|
+
|
|
36
|
+
bussinesses = new Map<string, BasicBusiness<BasicBusinessOption>>();
|
|
37
|
+
|
|
38
|
+
/** 地图是否存在 */
|
|
39
|
+
isAlive = true;
|
|
40
|
+
constructor() {
|
|
41
|
+
const { htmllayer } = this;
|
|
42
|
+
htmllayer.style.zIndex = "1000";
|
|
43
|
+
htmllayer.style.position = "absolute";
|
|
44
|
+
htmllayer.style.width = "0";
|
|
45
|
+
htmllayer.style.height = "0";
|
|
46
|
+
htmllayer.style.left = "0";
|
|
47
|
+
htmllayer.style.top = "0";
|
|
48
|
+
this.menu = new ContextMenu(this);
|
|
49
|
+
(window as any).map = this;
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
this.bussinesses.forEach((e) => e.show && e.onMapLoaded?.());
|
|
52
|
+
}, 100);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
createReactPoint<K>(option?: Partial<ReactPointOption<K>>): ReactPoint<K> {
|
|
56
|
+
const e = new ReactPoint(this, option);
|
|
57
|
+
drawReactPoint(this, e);
|
|
58
|
+
return e;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 设置地图视图
|
|
63
|
+
* @param option 视图参数
|
|
64
|
+
* @param time 设置时间会动画形式调整视图
|
|
65
|
+
*/
|
|
66
|
+
abstract createPoint<K>(option?: Partial<PointOption<K>>): Point<K>;
|
|
67
|
+
|
|
68
|
+
/** 聚合点 */
|
|
69
|
+
abstract createPointAggregation(option?: PointAggregationOption): PointAggregation;
|
|
70
|
+
|
|
71
|
+
abstract createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K>;
|
|
72
|
+
|
|
73
|
+
abstract createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K>;
|
|
74
|
+
|
|
75
|
+
abstract createTile3D(option?: Partial<Tile3DOption>): Tile3D;
|
|
76
|
+
|
|
77
|
+
abstract createLayer(option?: Partial<LayerOption>): Layer;
|
|
78
|
+
|
|
79
|
+
/** 创建模型 */
|
|
80
|
+
createModel?(option?: Partial<BasicModelOption>): BasicModel;
|
|
81
|
+
|
|
82
|
+
abstract canvasTgeography(p: number[]): number[];
|
|
83
|
+
|
|
84
|
+
abstract geographyTcanvas(p: number[]): number[];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 所有点位移动至视口,调整位置及层级
|
|
88
|
+
* @param points
|
|
89
|
+
*/
|
|
90
|
+
abstract flyToViewer(points: number[][], opt?: Object): void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 移动点位到中心点
|
|
94
|
+
* @param points
|
|
95
|
+
*/
|
|
96
|
+
abstract flyTo(point: number[], opt?: Object): void;
|
|
97
|
+
|
|
98
|
+
getBounds = getBounds;
|
|
99
|
+
|
|
100
|
+
destroy() {
|
|
101
|
+
this.isAlive = false;
|
|
102
|
+
this.htmllayer.remove();
|
|
103
|
+
this.event.trigger("destroy");
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/basic/Tile3D.ts
CHANGED
|
@@ -105,7 +105,6 @@ export class Tile3D extends MapElement<Tile3DOption> {
|
|
|
105
105
|
console.info("TileD translate");
|
|
106
106
|
}
|
|
107
107
|
/** 基于本地的 ENU 坐标系的旋转,也就是垂直于地表向上为 Z,东为 X,北为 Y
|
|
108
|
-
* https://blog.csdn.net/weixin_70945905/article/details/142419968
|
|
109
108
|
* @param rx 绕X轴旋转的角度。单位:度
|
|
110
109
|
* @param ry 绕Y轴旋转的角度。单位:度
|
|
111
110
|
* @param rz 绕Z轴旋转的角度。单位:度
|