@hzab/map-combine 0.2.5 → 0.2.7
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 +1 -1
- package/src/cesium/CesiumMap.ts +51 -2
- package/src/mine/MineMap.ts +15 -5
- package/src/openlayer/OpenlayerMap.ts +7 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/cesium/CesiumMap.ts
CHANGED
|
@@ -13,6 +13,14 @@ import { drawPolyline } from "./CesiumPolyline";
|
|
|
13
13
|
import { drawTile3D } from "./CesiumTile3D";
|
|
14
14
|
|
|
15
15
|
const $m = 20037508.34278924;
|
|
16
|
+
/**
|
|
17
|
+
* flyToViewer 最小判断半径(米)
|
|
18
|
+
*/
|
|
19
|
+
const MIN_RADIUS = 500;
|
|
20
|
+
/**
|
|
21
|
+
* flyToViewer 最大缩放层级
|
|
22
|
+
*/
|
|
23
|
+
const MAX_ZOOM = 18;
|
|
16
24
|
|
|
17
25
|
export class CesiumMap extends MapCombine {
|
|
18
26
|
viewer: any;
|
|
@@ -253,16 +261,57 @@ export class CesiumMap extends MapCombine {
|
|
|
253
261
|
* @param points
|
|
254
262
|
* @param opt
|
|
255
263
|
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
264
|
+
* @param {Array<number> = [0,0,0,0]} opt.minRadius flyToViewer 最小范围(米)
|
|
265
|
+
* @param {Array<number> = [0,0,0,0]} opt.maxZoom flyToViewer 最大缩放层级
|
|
256
266
|
*/
|
|
257
|
-
flyToViewer(
|
|
267
|
+
flyToViewer(
|
|
268
|
+
points,
|
|
269
|
+
opt = {
|
|
270
|
+
avoid: [0, 0, 0, 0],
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* flyToViewer 最小判断半径(米)
|
|
274
|
+
*/
|
|
275
|
+
minRadius: MIN_RADIUS,
|
|
276
|
+
/**
|
|
277
|
+
* flyToViewer 最大缩放层级
|
|
278
|
+
*/
|
|
279
|
+
maxZoom: MAX_ZOOM,
|
|
280
|
+
},
|
|
281
|
+
) {
|
|
282
|
+
if (points?.length === 0) {
|
|
283
|
+
return this.flyTo(points[0], opt);
|
|
284
|
+
}
|
|
258
285
|
// 创建矩形
|
|
259
286
|
const rectangle = Cesium.Rectangle.fromDegrees(
|
|
260
287
|
...this.getBounds(points, { canvas: this.viewer.scene.canvas, ...opt }),
|
|
261
288
|
);
|
|
262
289
|
|
|
290
|
+
// 将经纬度转换为笛卡尔坐标
|
|
291
|
+
const positions = points.map((coord) => {
|
|
292
|
+
return Cesium.Cartesian3.fromDegrees(coord[0], coord[1]);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// 计算所有点位的包围球
|
|
296
|
+
const boundingSphere = Cesium.BoundingSphere.fromPoints(positions);
|
|
297
|
+
|
|
298
|
+
// 计算包围球半径
|
|
299
|
+
const radius = boundingSphere.radius;
|
|
300
|
+
|
|
301
|
+
let destination = rectangle;
|
|
302
|
+
// 点位距离小于指定范围使用固定高度
|
|
303
|
+
if (radius < MIN_RADIUS || (opt?.minRadius && radius < opt.minRadius)) {
|
|
304
|
+
const center = Cesium.Rectangle.center(rectangle);
|
|
305
|
+
destination = Cesium.Cartesian3.fromRadians(
|
|
306
|
+
center.longitude,
|
|
307
|
+
center.latitude,
|
|
308
|
+
this.zoomTdistance(opt?.maxZoom ?? MAX_ZOOM),
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
263
312
|
// 设置相机视角
|
|
264
313
|
this.viewer.camera.flyTo({
|
|
265
|
-
destination
|
|
314
|
+
destination,
|
|
266
315
|
...opt,
|
|
267
316
|
});
|
|
268
317
|
}
|
package/src/mine/MineMap.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { drawPolygon } from "./MinePolygon";
|
|
|
9
9
|
import { drawPolyline } from "./MinePolyline";
|
|
10
10
|
import { drawTile3D } from "./MineTile3D";
|
|
11
11
|
|
|
12
|
+
const MAX_ZOOM = 18;
|
|
13
|
+
|
|
12
14
|
export class MineMap extends MapCombine {
|
|
13
15
|
viewer: any;
|
|
14
16
|
container: HTMLDivElement;
|
|
@@ -82,14 +84,22 @@ export class MineMap extends MapCombine {
|
|
|
82
84
|
* @param opt
|
|
83
85
|
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
84
86
|
*/
|
|
85
|
-
flyToViewer(points, opt = { avoid: [0, 0, 0, 0] }) {
|
|
87
|
+
flyToViewer(points, opt = { avoid: [0, 0, 0, 0], maxZoom: MAX_ZOOM }) {
|
|
88
|
+
if (points?.length === 0) {
|
|
89
|
+
return this.flyTo(points[0], opt);
|
|
90
|
+
}
|
|
86
91
|
const rectangle = this.getBounds(points, { canvas: this.viewer.getCanvas(), ...opt });
|
|
87
92
|
|
|
88
93
|
// 设置地图视图,使用调整后的边界范围
|
|
89
|
-
this.viewer.fitBounds(
|
|
90
|
-
[
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
this.viewer.fitBounds(
|
|
95
|
+
[
|
|
96
|
+
[rectangle[0], rectangle[1]],
|
|
97
|
+
[rectangle[2], rectangle[3]],
|
|
98
|
+
],
|
|
99
|
+
{
|
|
100
|
+
maxZoom: opt?.maxZoom ?? MAX_ZOOM,
|
|
101
|
+
},
|
|
102
|
+
);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
/**
|
|
@@ -27,6 +27,8 @@ import { drawPolygon } from "./OpenlayerPolygon";
|
|
|
27
27
|
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
28
28
|
import { gcjMecator } from "./openlayer-tile-gcj02-wgs84";
|
|
29
29
|
|
|
30
|
+
const MAX_ZOOM = 18;
|
|
31
|
+
|
|
30
32
|
export interface IOpenlayerOption {
|
|
31
33
|
container;
|
|
32
34
|
url: string | string[];
|
|
@@ -182,7 +184,10 @@ export class OpenlayerMap extends MapCombine {
|
|
|
182
184
|
* @param opt
|
|
183
185
|
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
184
186
|
*/
|
|
185
|
-
flyToViewer(points, opt = { avoid: [0, 0, 0, 0] }) {
|
|
187
|
+
flyToViewer(points, opt = { avoid: [0, 0, 0, 0], maxZoom: MAX_ZOOM }) {
|
|
188
|
+
if (points?.length === 0) {
|
|
189
|
+
return this.flyTo(points[0], opt);
|
|
190
|
+
}
|
|
186
191
|
const { avoid } = opt || {};
|
|
187
192
|
// 创建 Feature 数组
|
|
188
193
|
const features = points.map((point) => {
|
|
@@ -210,6 +215,7 @@ export class OpenlayerMap extends MapCombine {
|
|
|
210
215
|
// 上 右 下 左
|
|
211
216
|
padding: [avoid[0], avoid[3], avoid[1], avoid[2]],
|
|
212
217
|
duration: 1000,
|
|
218
|
+
maxZoom: opt?.maxZoom ?? MAX_ZOOM, // 最大缩放级别,
|
|
213
219
|
...opt,
|
|
214
220
|
});
|
|
215
221
|
}
|