@xingm/vmap-cesium-toolbar 0.0.1-beta.3 → 0.0.1-beta.4
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/dist/index.js +74 -32
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +19 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as n from "cesium";
|
|
2
|
-
import { Ion as
|
|
2
|
+
import { Ion as E, Viewer as b, createWorldTerrainAsync as w } from "cesium";
|
|
3
3
|
class m {
|
|
4
4
|
viewer;
|
|
5
5
|
scene;
|
|
@@ -116,8 +116,8 @@ class m {
|
|
|
116
116
|
flat: !0
|
|
117
117
|
})
|
|
118
118
|
});
|
|
119
|
-
this.viewer.scene.primitives.add(d), this.viewer.scene.primitives.add(p), this.frustumPrimitives.push(d, p), e.onRightClick && this.screenSpaceEventHandler && this.screenSpaceEventHandler.setInputAction((
|
|
120
|
-
|
|
119
|
+
this.viewer.scene.primitives.add(d), this.viewer.scene.primitives.add(p), this.frustumPrimitives.push(d, p), e.onRightClick && this.screenSpaceEventHandler && this.screenSpaceEventHandler.setInputAction((C) => {
|
|
120
|
+
C.position && e.onRightClick && e.onRightClick(a);
|
|
121
121
|
}, n.ScreenSpaceEventType.RIGHT_CLICK);
|
|
122
122
|
} catch (t) {
|
|
123
123
|
console.error("绘制视锥体时发生错误:", t), this.clearFrustum();
|
|
@@ -865,7 +865,7 @@ class v {
|
|
|
865
865
|
*/
|
|
866
866
|
updateButtonConfig(e, t) {
|
|
867
867
|
const i = this.toolbarElement.querySelector(`[data-tool="${e}"]`);
|
|
868
|
-
i && (t.title && (i.title = t.title), t.icon && this.setButtonIcon(i, t.icon), t.size && (i.style.width = `${t.size}px`, i.style.height = `${t.size}px`), t.color && (i.style.
|
|
868
|
+
i && (t.title && (i.title = t.title), t.icon && this.setButtonIcon(i, t.icon), t.size && (i.style.width = `${t.size}px`, i.style.height = `${t.size}px`), t.color && (i.style.color = t.color), t.backgroundColor && (i.style.background = t.backgroundColor), t.borderColor && (i.style.borderColor = t.borderColor), t.borderWidth && (i.style.borderWidth = t.borderWidth + "px"), t.borderStyle && (i.style.borderStyle = t.borderStyle), t.padding && (i.style.padding = t.padding), t.activeIcon && this.setButtonIcon(i, t.activeIcon));
|
|
869
869
|
}
|
|
870
870
|
/**
|
|
871
871
|
* 添加自定义按钮
|
|
@@ -878,7 +878,8 @@ class v {
|
|
|
878
878
|
size: e.size,
|
|
879
879
|
color: e.color,
|
|
880
880
|
hoverColor: e.hoverColor,
|
|
881
|
-
activeColor: e.activeColor
|
|
881
|
+
activeColor: e.activeColor,
|
|
882
|
+
backgroundColor: e.backgroundColor
|
|
882
883
|
}, i = this.createButton(t);
|
|
883
884
|
this.toolbarElement.appendChild(i), this.config.buttons || (this.config.buttons = []), this.config.buttons.push(e);
|
|
884
885
|
}
|
|
@@ -972,16 +973,21 @@ class v {
|
|
|
972
973
|
{ id: "zoom-in", icon: "🔍+", title: "放大" },
|
|
973
974
|
{ id: "zoom-out", icon: "🔍-", title: "缩小" },
|
|
974
975
|
{ id: "fullscreen", icon: "⛶", title: "全屏" }
|
|
975
|
-
];
|
|
976
|
-
return this.config.buttons && this.config.buttons.length > 0 ? this.config.buttons.map((
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
976
|
+
], t = (i) => e.find((s) => s.id === i);
|
|
977
|
+
return this.config.buttons && this.config.buttons.length > 0 ? this.config.buttons.map((i) => {
|
|
978
|
+
const s = t(i.id);
|
|
979
|
+
return {
|
|
980
|
+
id: i.id || s?.id || "",
|
|
981
|
+
icon: typeof i.icon == "string" ? i.icon : s?.icon || "",
|
|
982
|
+
title: i.title || s?.title || "",
|
|
983
|
+
size: typeof i.size == "number" ? i.size : typeof s?.size == "number" ? s.size : void 0,
|
|
984
|
+
backgroundColor: i.backgroundColor || s?.backgroundColor || "",
|
|
985
|
+
borderColor: i.borderColor || s?.borderColor || "",
|
|
986
|
+
borderWidth: i.borderWidth || s?.borderWidth || 1,
|
|
987
|
+
borderStyle: i.borderStyle || s?.borderStyle || "solid",
|
|
988
|
+
color: i.color || s?.color || "rgba(66, 133, 244, 0.4)"
|
|
989
|
+
};
|
|
990
|
+
}) : e;
|
|
985
991
|
}
|
|
986
992
|
/**
|
|
987
993
|
* 创建按钮
|
|
@@ -989,34 +995,70 @@ class v {
|
|
|
989
995
|
createButton(e) {
|
|
990
996
|
const t = document.createElement("div");
|
|
991
997
|
t.className = "cesium-toolbar-button", t.setAttribute("data-tool", e.id), t.title = e.title;
|
|
992
|
-
const i = e.size || this.config.buttonSize, s = e.color || "rgba(66, 133, 244, 0.4)", o = e.
|
|
998
|
+
const i = e.size || this.config.buttonSize, s = e.color || "rgba(66, 133, 244, 0.4)", o = e.backgroundColor || "rgba(66, 133, 244, 0.4)", a = e.borderColor || "rgba(66, 133, 244, 0.4)", r = e.borderWidth || 1, l = e.borderStyle || "solid";
|
|
993
999
|
return t.style.cssText = `
|
|
994
1000
|
width: ${i}px;
|
|
995
1001
|
height: ${i}px;
|
|
996
1002
|
display: flex;
|
|
997
1003
|
align-items: center;
|
|
998
1004
|
justify-content: center;
|
|
999
|
-
background: ${
|
|
1000
|
-
color:
|
|
1001
|
-
border:
|
|
1002
|
-
border-
|
|
1005
|
+
background: ${o};
|
|
1006
|
+
color: ${s};
|
|
1007
|
+
border-width: ${r}px;
|
|
1008
|
+
border-style: ${l};
|
|
1009
|
+
border-color: ${a};
|
|
1003
1010
|
cursor: pointer;
|
|
1004
|
-
font-size: 14px;
|
|
1005
1011
|
font-weight: bold;
|
|
1006
1012
|
transition: all 0.2s ease;
|
|
1007
1013
|
user-select: none;
|
|
1008
1014
|
position: relative;
|
|
1009
1015
|
`, this.setButtonIcon(t, e.icon), t.addEventListener("mouseenter", () => {
|
|
1010
|
-
t.style.
|
|
1016
|
+
t.style.transform = "scale(1.05)";
|
|
1011
1017
|
}), t.addEventListener("mouseleave", () => {
|
|
1012
|
-
t.style.
|
|
1018
|
+
t.style.transform = "scale(1)";
|
|
1013
1019
|
}), this.setupButtonEvents(t, e), t;
|
|
1014
1020
|
}
|
|
1015
1021
|
/**
|
|
1016
1022
|
* 设置按钮图标
|
|
1017
1023
|
*/
|
|
1018
1024
|
setButtonIcon(e, t) {
|
|
1019
|
-
|
|
1025
|
+
t instanceof HTMLElement ? (e.innerHTML = "", e.appendChild(t)) : typeof t == "string" && (this.isImagePath(t) ? this.loadImageIcon(e, t) : e.innerHTML = t);
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* 判断是否为图片路径
|
|
1029
|
+
*/
|
|
1030
|
+
isImagePath(e) {
|
|
1031
|
+
return /\.(jpg|jpeg|png|gif|bmp|webp|svg|ico)$/i.test(e);
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* 加载图片图标
|
|
1035
|
+
*/
|
|
1036
|
+
loadImageIcon(e, t) {
|
|
1037
|
+
const i = new Image(), s = e.getBoundingClientRect(), o = window.getComputedStyle(e), a = s.width || parseInt(o.width) || 36, r = s.height || parseInt(o.height) || 36, l = Math.min(a, r) * 0.6, c = Math.min(a, r) * 0.6;
|
|
1038
|
+
i.width = l, i.height = c, i.onload = () => {
|
|
1039
|
+
e.appendChild(i);
|
|
1040
|
+
}, i.onerror = () => {
|
|
1041
|
+
console.warn(`Failed to load icon: ${t}`), this.setDefaultIcon(e, t);
|
|
1042
|
+
}, i.src = t;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* 设置默认图标(当图片加载失败时)
|
|
1046
|
+
*/
|
|
1047
|
+
setDefaultIcon(e, t) {
|
|
1048
|
+
const i = t.split("/").pop()?.split(".")[0] || "icon";
|
|
1049
|
+
e.style.backgroundImage = "none", e.style.backgroundColor = "#ccc", e.style.position = "relative";
|
|
1050
|
+
const s = document.createElement("div");
|
|
1051
|
+
s.style.cssText = `
|
|
1052
|
+
position: absolute;
|
|
1053
|
+
top: 50%;
|
|
1054
|
+
left: 50%;
|
|
1055
|
+
transform: translate(-50%, -50%);
|
|
1056
|
+
font-size: 12px;
|
|
1057
|
+
color: #666;
|
|
1058
|
+
font-weight: bold;
|
|
1059
|
+
text-align: center;
|
|
1060
|
+
line-height: 1;
|
|
1061
|
+
`, s.textContent = i.charAt(0).toUpperCase(), e.innerHTML = "", e.appendChild(s);
|
|
1020
1062
|
}
|
|
1021
1063
|
/**
|
|
1022
1064
|
* 设置按钮事件
|
|
@@ -1440,7 +1482,7 @@ class v {
|
|
|
1440
1482
|
this.toolbarElement && this.toolbarElement.parentNode && this.toolbarElement.parentNode.removeChild(this.toolbarElement), this.drawHelper.destroy();
|
|
1441
1483
|
}
|
|
1442
1484
|
}
|
|
1443
|
-
function
|
|
1485
|
+
function y() {
|
|
1444
1486
|
return new n.UrlTemplateImageryProvider({
|
|
1445
1487
|
url: "https://webst0{s}.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}",
|
|
1446
1488
|
subdomains: ["1", "2", "3", "4"],
|
|
@@ -1450,15 +1492,15 @@ function x() {
|
|
|
1450
1492
|
credit: "© 高德地图"
|
|
1451
1493
|
});
|
|
1452
1494
|
}
|
|
1453
|
-
async function
|
|
1454
|
-
|
|
1495
|
+
async function x(u, e, t = { longitude: 120.2052342, latitude: 30.2489634, height: 1e3, pitch: -60, heading: 0 }) {
|
|
1496
|
+
E.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3M2M3NWU1Ni0xZmJkLTRkNjAtOTk4NC0wZDZhNWFiOWJlZDEiLCJpZCI6MzMxNTg1LCJpYXQiOjE3NTUyMjQ2MzB9.WBUG7ctHKtOrnay1ng8JNfaNgngbkNgOmRXP59OJ7ME";
|
|
1455
1497
|
const i = new b(u, {
|
|
1456
1498
|
timeline: !1,
|
|
1457
1499
|
animation: !1,
|
|
1458
1500
|
baseLayerPicker: !1,
|
|
1459
1501
|
...e
|
|
1460
1502
|
});
|
|
1461
|
-
return !e.terrainProvider && !e.terrain && (i.terrainProvider = await w()), e.mapType === "gaode" && (i.imageryLayers.removeAll(), i.imageryLayers.addImageryProvider(
|
|
1503
|
+
return !e.terrainProvider && !e.terrain && (i.terrainProvider = await w()), e.mapType === "gaode" && (i.imageryLayers.removeAll(), i.imageryLayers.addImageryProvider(y())), t && i.camera.flyTo({
|
|
1462
1504
|
destination: n.Cartesian3.fromDegrees(t.longitude, t.latitude, t.height),
|
|
1463
1505
|
// 中国中心坐标
|
|
1464
1506
|
orientation: {
|
|
@@ -1469,15 +1511,15 @@ async function L(u, e, t = { longitude: 120.2052342, latitude: 30.2489634, heigh
|
|
|
1469
1511
|
}
|
|
1470
1512
|
}), i.cesiumWidget.creditContainer.style.display = "none", { viewer: i, initialCenter: t };
|
|
1471
1513
|
}
|
|
1472
|
-
const
|
|
1514
|
+
const L = {
|
|
1473
1515
|
CesiumMapToolbar: v,
|
|
1474
1516
|
DrawHelper: m,
|
|
1475
|
-
initCesium:
|
|
1517
|
+
initCesium: x
|
|
1476
1518
|
};
|
|
1477
1519
|
export {
|
|
1478
1520
|
v as CesiumMapToolbar,
|
|
1479
1521
|
m as DrawHelper,
|
|
1480
|
-
|
|
1481
|
-
|
|
1522
|
+
L as default,
|
|
1523
|
+
x as initCesium
|
|
1482
1524
|
};
|
|
1483
1525
|
//# sourceMappingURL=index.es.js.map
|