@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/src/mine/MineMap.ts
CHANGED
|
@@ -1,176 +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?: 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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
+
}
|
|
@@ -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 异常情况
|