@caoguo/maplibre 0.0.2 → 0.0.5
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/README.md +116 -0
- package/dist/{chunk-EZOV5O2M.js → chunk-QGVXYR2I.js} +3 -3
- package/dist/{chunk-EZOV5O2M.js.map → chunk-QGVXYR2I.js.map} +1 -1
- package/dist/index.cjs +316 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +244 -25
- package/dist/index.d.ts +244 -25
- package/dist/index.js +308 -40
- package/dist/index.js.map +1 -1
- package/dist/sources/index.cjs +1 -1
- package/dist/sources/index.cjs.map +1 -1
- package/dist/sources/index.js +1 -1
- package/package.json +33 -2
package/dist/index.cjs
CHANGED
|
@@ -197,7 +197,7 @@ function buildTiandituSources(type, opts) {
|
|
|
197
197
|
const { base, label } = LAYER_MAP[type];
|
|
198
198
|
const tileSize = opts.tileSize ?? 256;
|
|
199
199
|
const maxzoom = opts.maxzoom ?? 18;
|
|
200
|
-
const attr = "\xA9 \u5929\u5730\u56FE GS(2023)3295\u53F7";
|
|
200
|
+
const attr = "\xA9 \u5929\u5730\u56FE GS(2023)3295\u53F7 \xB7 \u8349\u679C\u5730\u56FE";
|
|
201
201
|
return [
|
|
202
202
|
{
|
|
203
203
|
id: `tianditu-${base}`,
|
|
@@ -765,15 +765,96 @@ var ThemeSwitcher = class {
|
|
|
765
765
|
}
|
|
766
766
|
};
|
|
767
767
|
|
|
768
|
+
// src/controls/LegendControl.ts
|
|
769
|
+
function escapeHtml(s) {
|
|
770
|
+
return s.replace(
|
|
771
|
+
/[&<>"']/g,
|
|
772
|
+
(c) => c === "&" ? "&" : c === "<" ? "<" : c === ">" ? ">" : c === '"' ? """ : "'"
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
function renderLegendHtml(items, title) {
|
|
776
|
+
const titleHtml = title ? `<div class="cg-legend-title">${escapeHtml(title)}</div>` : "";
|
|
777
|
+
const itemsHtml = items.map((it) => {
|
|
778
|
+
const swatch = it.shape === "line" ? `<span class="cg-legend-swatch cg-legend-swatch--line" style="background:${it.color}"></span>` : `<span class="cg-legend-swatch" style="background:${it.color}"></span>`;
|
|
779
|
+
return `<div class="cg-legend-item">${swatch}<span>${escapeHtml(it.label)}</span></div>`;
|
|
780
|
+
}).join("");
|
|
781
|
+
return `<div class="cg-legend-body">${titleHtml}${itemsHtml}</div>`;
|
|
782
|
+
}
|
|
783
|
+
var LegendControl = class {
|
|
784
|
+
constructor(options) {
|
|
785
|
+
this.opts = { title: options.title ?? "", items: options.items };
|
|
786
|
+
this.el = options.container ?? document.createElement("div");
|
|
787
|
+
this.el.className = "caoguo-legend-control";
|
|
788
|
+
this.el.style.cssText = "position:absolute;right:10px;top:10px;padding:8px 10px;background:rgba(10,15,30,.72);color:#cfe;border-radius:6px;font:12px/1.5 system-ui,sans-serif;z-index:2;max-width:220px;";
|
|
789
|
+
this.bodyEl = document.createElement("div");
|
|
790
|
+
this.el.appendChild(this.bodyEl);
|
|
791
|
+
this.render();
|
|
792
|
+
}
|
|
793
|
+
render() {
|
|
794
|
+
this.bodyEl.innerHTML = renderLegendHtml(this.opts.items, this.opts.title || void 0);
|
|
795
|
+
}
|
|
796
|
+
/** 运行时更新图例项(随图层切换重新渲染) */
|
|
797
|
+
setItems(items, title) {
|
|
798
|
+
if (title !== void 0) this.opts.title = title;
|
|
799
|
+
this.opts.items = items;
|
|
800
|
+
this.render();
|
|
801
|
+
}
|
|
802
|
+
/** 挂载到容器 */
|
|
803
|
+
addTo(container) {
|
|
804
|
+
if (!this.el.parentElement) container.appendChild(this.el);
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
remove() {
|
|
808
|
+
this.el.remove();
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
// src/controls/ExportControl.ts
|
|
813
|
+
function triggerDownload(dataUrl, filename) {
|
|
814
|
+
const a = document.createElement("a");
|
|
815
|
+
a.href = dataUrl;
|
|
816
|
+
a.download = filename.endsWith(".png") ? filename : `${filename}.png`;
|
|
817
|
+
document.body.appendChild(a);
|
|
818
|
+
a.click();
|
|
819
|
+
a.remove();
|
|
820
|
+
}
|
|
821
|
+
var ExportControl = class {
|
|
822
|
+
constructor(map, options = {}) {
|
|
823
|
+
this.onClick = () => this.export();
|
|
824
|
+
this.map = map;
|
|
825
|
+
this.filename = options.filename ?? "caoguo-map";
|
|
826
|
+
this.el = options.container ?? document.createElement("button");
|
|
827
|
+
this.el.className = "caoguo-export-control";
|
|
828
|
+
this.el.textContent = options.buttonText ?? "\u5BFC\u51FA PNG";
|
|
829
|
+
this.el.style.cssText = "position:absolute;right:10px;top:10px;padding:5px 10px;background:rgba(10,15,30,.72);color:#cfe;border:1px solid #2a3550;border-radius:4px;font:12px system-ui,sans-serif;cursor:pointer;z-index:3;";
|
|
830
|
+
this.el.addEventListener("click", this.onClick);
|
|
831
|
+
}
|
|
832
|
+
/** 导出当前地图视图为 PNG 并下载 */
|
|
833
|
+
export() {
|
|
834
|
+
const canvas = this.map.getCanvas();
|
|
835
|
+
const url = canvas.toDataURL("image/png");
|
|
836
|
+
triggerDownload(url, this.filename);
|
|
837
|
+
}
|
|
838
|
+
/** 挂载到容器 */
|
|
839
|
+
addTo(container) {
|
|
840
|
+
if (!this.el.parentElement) container.appendChild(this.el);
|
|
841
|
+
return this;
|
|
842
|
+
}
|
|
843
|
+
remove() {
|
|
844
|
+
this.el.removeEventListener("click", this.onClick);
|
|
845
|
+
this.el.remove();
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
|
|
768
849
|
// src/shaders/glowGeometry.ts
|
|
769
|
-
function glowPasses(passes = 4,
|
|
850
|
+
function glowPasses(passes = 4, baseWidth = 3) {
|
|
770
851
|
if (passes < 1) passes = 1;
|
|
771
852
|
const out = [];
|
|
772
853
|
for (let i = 0; i < passes; i++) {
|
|
773
854
|
const t = passes === 1 ? 1 : 1 - i / (passes - 1);
|
|
774
855
|
out.push({
|
|
775
|
-
|
|
776
|
-
opacity:
|
|
856
|
+
width: baseWidth * (1 + (1 - t) * (passes - 1) * 1.8),
|
|
857
|
+
opacity: 0.1 + 0.9 * t * t
|
|
777
858
|
});
|
|
778
859
|
}
|
|
779
860
|
return out;
|
|
@@ -781,17 +862,40 @@ function glowPasses(passes = 4, coreOpacity = 1) {
|
|
|
781
862
|
function projectSimple(lng, lat) {
|
|
782
863
|
const x = lng / 180;
|
|
783
864
|
const y = Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)) / Math.PI;
|
|
784
|
-
return [x, Math.max(-1, Math.min(1, y))];
|
|
865
|
+
return [x, Math.max(-1, Math.min(1, y / Math.PI))];
|
|
785
866
|
}
|
|
786
867
|
function buildGlowGeometry(lines, opts = {}) {
|
|
787
|
-
const passes = glowPasses(opts.passes ?? 4, opts.
|
|
788
|
-
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
868
|
+
const passes = glowPasses(opts.passes ?? 4, opts.baseWidth ?? 3);
|
|
869
|
+
const stride = 5;
|
|
870
|
+
const verts = [];
|
|
871
|
+
const passRanges = [];
|
|
872
|
+
for (const pass of passes) {
|
|
873
|
+
const start = verts.length / stride;
|
|
874
|
+
for (const line of lines) {
|
|
875
|
+
const pts = line.coordinates.map(([lng, lat]) => projectSimple(lng, lat));
|
|
876
|
+
if (pts.length < 2) continue;
|
|
877
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
878
|
+
const a = pts[i];
|
|
879
|
+
const b = pts[i + 1];
|
|
880
|
+
const dx = b[0] - a[0];
|
|
881
|
+
const dy = b[1] - a[1];
|
|
882
|
+
const quad = [
|
|
883
|
+
[a[0], a[1], dx, dy, 1],
|
|
884
|
+
[a[0], a[1], dx, dy, -1],
|
|
885
|
+
[b[0], b[1], dx, dy, 1],
|
|
886
|
+
[b[0], b[1], dx, dy, -1]
|
|
887
|
+
];
|
|
888
|
+
const idx = [0, 1, 2, 2, 1, 3];
|
|
889
|
+
for (const k of idx) {
|
|
890
|
+
const v = quad[k];
|
|
891
|
+
verts.push(v[0], v[1], v[2], v[3], v[4]);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
const count = verts.length / stride - start;
|
|
896
|
+
passRanges.push({ start, count });
|
|
897
|
+
}
|
|
898
|
+
return { vertices: new Float32Array(verts), passRanges, passes, stride };
|
|
795
899
|
}
|
|
796
900
|
|
|
797
901
|
// src/shaders/CustomLineLayer.ts
|
|
@@ -805,17 +909,21 @@ var DEFAULT_COLORS = {
|
|
|
805
909
|
};
|
|
806
910
|
var VERT = `
|
|
807
911
|
attribute vec2 aPos;
|
|
808
|
-
attribute
|
|
912
|
+
attribute vec2 aDir;
|
|
913
|
+
attribute float aSide;
|
|
809
914
|
uniform mat4 uMatrix;
|
|
810
915
|
uniform float uWidth;
|
|
811
916
|
uniform vec2 uResolution;
|
|
812
917
|
void main() {
|
|
813
|
-
// \u7B80\u5316\uFF1A\u6CBF\u6CD5\u7EBF\u65B9\u5411\u504F\u79FB width\uFF08\u5C4F\u5E55\u7A7A\u95F4\uFF09\uFF0C\u8FD9\u91CC\u4EC5\u6F14\u793A\u6838\u5FC3\u6295\u5F71
|
|
814
918
|
vec4 clip = uMatrix * vec4(aPos, 0.0, 1.0);
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
vec2
|
|
818
|
-
|
|
919
|
+
// \u6BB5\u65B9\u5411\u4E5F\u6295\u5F71\uFF0C\u6C42\u5C4F\u5E55\u7A7A\u95F4\u65B9\u5411
|
|
920
|
+
vec4 clipDir = uMatrix * vec4(aPos + aDir, 0.0, 1.0);
|
|
921
|
+
vec2 s0 = clip.xy / clip.w;
|
|
922
|
+
vec2 s1 = clipDir.xy / clipDir.w;
|
|
923
|
+
vec2 dir = normalize(s1 - s0 + vec2(1e-6));
|
|
924
|
+
vec2 normal = vec2(-dir.y, dir.x);
|
|
925
|
+
vec2 offset = normal * aSide * (uWidth / uResolution * 2.0);
|
|
926
|
+
gl_Position = vec4(s0 + offset * clip.w, clip.z, clip.w);
|
|
819
927
|
}
|
|
820
928
|
`;
|
|
821
929
|
var FRAG = `
|
|
@@ -830,6 +938,9 @@ function compile(gl, type, src) {
|
|
|
830
938
|
const sh = gl.createShader(type);
|
|
831
939
|
gl.shaderSource(sh, src);
|
|
832
940
|
gl.compileShader(sh);
|
|
941
|
+
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) {
|
|
942
|
+
console.error("[CustomLineLayer] shader \u7F16\u8BD1\u5931\u8D25:", gl.getShaderInfoLog(sh));
|
|
943
|
+
}
|
|
833
944
|
return sh;
|
|
834
945
|
}
|
|
835
946
|
var CustomLineLayer = class {
|
|
@@ -840,8 +951,7 @@ var CustomLineLayer = class {
|
|
|
840
951
|
this.lines = opts.lines;
|
|
841
952
|
this.colors = { ...DEFAULT_COLORS, ...opts.colors };
|
|
842
953
|
this.baseWidth = opts.baseWidth ?? 3;
|
|
843
|
-
this.
|
|
844
|
-
this.geometry = buildGlowGeometry(this.lines, { passes: this.passes });
|
|
954
|
+
this.geometry = buildGlowGeometry(this.lines, { passes: opts.passes ?? 4, baseWidth: this.baseWidth });
|
|
845
955
|
}
|
|
846
956
|
onAdd(map, gl) {
|
|
847
957
|
this.map = map;
|
|
@@ -851,29 +961,29 @@ var CustomLineLayer = class {
|
|
|
851
961
|
gl.attachShader(prog, vs);
|
|
852
962
|
gl.attachShader(prog, fs);
|
|
853
963
|
gl.linkProgram(prog);
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
for (const line of this.geometry.lines) {
|
|
857
|
-
const pts = line.points;
|
|
858
|
-
for (let i = 0; i < pts.length - 1; i++) {
|
|
859
|
-
verts.push(pts[i][0], pts[i][1], 0, pts[i + 1][0], pts[i + 1][1], 0);
|
|
860
|
-
}
|
|
964
|
+
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) {
|
|
965
|
+
console.error("[CustomLineLayer] program \u94FE\u63A5\u5931\u8D25:", gl.getProgramInfoLog(prog));
|
|
861
966
|
}
|
|
967
|
+
this.program = prog;
|
|
862
968
|
const buf = gl.createBuffer();
|
|
863
969
|
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
|
864
|
-
gl.bufferData(gl.ARRAY_BUFFER,
|
|
970
|
+
gl.bufferData(gl.ARRAY_BUFFER, this.geometry.vertices, gl.STATIC_DRAW);
|
|
865
971
|
this.buffer = buf;
|
|
866
972
|
}
|
|
867
973
|
render(gl, matrix) {
|
|
868
974
|
if (!this.program || !this.buffer) return;
|
|
869
975
|
gl.useProgram(this.program);
|
|
870
976
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
|
|
977
|
+
const stride = this.geometry.stride * 4;
|
|
871
978
|
const aPos = gl.getAttribLocation(this.program, "aPos");
|
|
872
|
-
const
|
|
979
|
+
const aDir = gl.getAttribLocation(this.program, "aDir");
|
|
980
|
+
const aSide = gl.getAttribLocation(this.program, "aSide");
|
|
873
981
|
gl.enableVertexAttribArray(aPos);
|
|
874
|
-
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false,
|
|
875
|
-
gl.enableVertexAttribArray(
|
|
876
|
-
gl.vertexAttribPointer(
|
|
982
|
+
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, stride, 0);
|
|
983
|
+
gl.enableVertexAttribArray(aDir);
|
|
984
|
+
gl.vertexAttribPointer(aDir, 2, gl.FLOAT, false, stride, 8);
|
|
985
|
+
gl.enableVertexAttribArray(aSide);
|
|
986
|
+
gl.vertexAttribPointer(aSide, 1, gl.FLOAT, false, stride, 16);
|
|
877
987
|
const uMatrix = gl.getUniformLocation(this.program, "uMatrix");
|
|
878
988
|
gl.uniformMatrix4fv(uMatrix, false, new Float32Array(matrix));
|
|
879
989
|
const uWidth = gl.getUniformLocation(this.program, "uWidth");
|
|
@@ -885,11 +995,14 @@ var CustomLineLayer = class {
|
|
|
885
995
|
gl.enable(gl.BLEND);
|
|
886
996
|
gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
|
|
887
997
|
const color = this.colors[this.lines[0]?.group ?? "pipe"] ?? this.colors.pipe;
|
|
888
|
-
for (
|
|
889
|
-
|
|
998
|
+
for (let p = 0; p < this.geometry.passes.length; p++) {
|
|
999
|
+
const pass = this.geometry.passes[p];
|
|
1000
|
+
const range = this.geometry.passRanges[p];
|
|
1001
|
+
if (range.count <= 0) continue;
|
|
1002
|
+
gl.uniform1f(uWidth, pass.width);
|
|
890
1003
|
gl.uniform3f(uColor, color[0], color[1], color[2]);
|
|
891
1004
|
gl.uniform1f(uOpacity, pass.opacity);
|
|
892
|
-
gl.drawArrays(gl.
|
|
1005
|
+
gl.drawArrays(gl.TRIANGLES, range.start, range.count);
|
|
893
1006
|
}
|
|
894
1007
|
}
|
|
895
1008
|
onRemove(_map, gl) {
|
|
@@ -953,17 +1066,119 @@ var LodController = class {
|
|
|
953
1066
|
}
|
|
954
1067
|
};
|
|
955
1068
|
|
|
1069
|
+
// src/terrain.ts
|
|
1070
|
+
var DEFAULT_TERRAIN_TILES = [
|
|
1071
|
+
"https://elevation-tiles-prod.s3.amazonaws.com/terrarium/{z}/{x}/{y}.png"
|
|
1072
|
+
];
|
|
1073
|
+
function applyTerrain(mlMap, opts = {}) {
|
|
1074
|
+
const sourceId = opts.sourceId ?? "cg-dem";
|
|
1075
|
+
if (!mlMap.getSource(sourceId)) {
|
|
1076
|
+
mlMap.addSource(sourceId, {
|
|
1077
|
+
type: "raster-dem",
|
|
1078
|
+
tiles: opts.tiles ?? DEFAULT_TERRAIN_TILES,
|
|
1079
|
+
encoding: opts.encoding ?? "terrarium",
|
|
1080
|
+
tileSize: 256,
|
|
1081
|
+
maxzoom: opts.maxzoom ?? 15
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
mlMap.setTerrain({ source: sourceId, exaggeration: opts.exaggeration ?? 1.5 });
|
|
1085
|
+
}
|
|
1086
|
+
function removeTerrain(mlMap, sourceId = "cg-dem") {
|
|
1087
|
+
mlMap.setTerrain(null);
|
|
1088
|
+
if (mlMap.getSource(sourceId)) {
|
|
1089
|
+
mlMap.removeSource(sourceId);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/sourceUtils.ts
|
|
1094
|
+
function upsertSource(mlMap, id, data) {
|
|
1095
|
+
if (mlMap.getSource(id)) {
|
|
1096
|
+
if (mlMap.setData) {
|
|
1097
|
+
mlMap.setData(id, data);
|
|
1098
|
+
} else if (mlMap.addSource) {
|
|
1099
|
+
mlMap.addSource(id, data);
|
|
1100
|
+
}
|
|
1101
|
+
} else if (mlMap.addSource) {
|
|
1102
|
+
mlMap.addSource(id, data);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
function removeSourceSafe(mlMap, id) {
|
|
1106
|
+
if (mlMap.getSource(id) && mlMap.removeSource) {
|
|
1107
|
+
mlMap.removeSource(id);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
function removeSourcesSafe(mlMap, ids) {
|
|
1111
|
+
for (const id of ids) {
|
|
1112
|
+
removeSourceSafe(mlMap, id);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
956
1116
|
// src/index.ts
|
|
1117
|
+
var WebGLUnavailableError = class extends Error {
|
|
1118
|
+
constructor(message = "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 WebGL\uFF0C\u65E0\u6CD5\u6E32\u67D3\u5730\u56FE") {
|
|
1119
|
+
super(message);
|
|
1120
|
+
this.name = "WebGLUnavailableError";
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
function isWebGLAvailable() {
|
|
1124
|
+
try {
|
|
1125
|
+
const canvas = document.createElement("canvas");
|
|
1126
|
+
let failed = false;
|
|
1127
|
+
const onErr = () => {
|
|
1128
|
+
failed = true;
|
|
1129
|
+
};
|
|
1130
|
+
canvas.addEventListener("webglcontextcreationerror", onErr, { once: true });
|
|
1131
|
+
const gl = canvas.getContext("webgl2") || canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
1132
|
+
canvas.removeEventListener("webglcontextcreationerror", onErr);
|
|
1133
|
+
if (failed || !gl) return false;
|
|
1134
|
+
const vendor = gl.getParameter(gl.VERSION);
|
|
1135
|
+
if (!vendor) return false;
|
|
1136
|
+
const vs = gl.createShader(gl.VERTEX_SHADER);
|
|
1137
|
+
if (!vs) return false;
|
|
1138
|
+
gl.shaderSource(vs, "attribute vec2 p; void main(){ gl_Position = vec4(p,0.0,1.0); }");
|
|
1139
|
+
gl.compileShader(vs);
|
|
1140
|
+
if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS)) return false;
|
|
1141
|
+
return true;
|
|
1142
|
+
} catch {
|
|
1143
|
+
return false;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
var GLOBAL_KEY = "__caoguoMapConfig__";
|
|
1147
|
+
function setGlobalConfig(cfg) {
|
|
1148
|
+
const prev = getGlobalConfig();
|
|
1149
|
+
globalThis[GLOBAL_KEY] = { ...prev, ...cfg };
|
|
1150
|
+
}
|
|
1151
|
+
function getGlobalConfig() {
|
|
1152
|
+
return globalThis[GLOBAL_KEY] ?? {};
|
|
1153
|
+
}
|
|
957
1154
|
var Map2 = class {
|
|
958
1155
|
constructor(options) {
|
|
959
1156
|
/** 离线瓦片后端(默认浏览器 IndexedDB / Node 内存) */
|
|
960
1157
|
this._store = createDefaultStore();
|
|
961
1158
|
this._dataCRS = options.dataCRS ?? "WGS84";
|
|
1159
|
+
if (!isWebGLAvailable()) {
|
|
1160
|
+
throw new WebGLUnavailableError();
|
|
1161
|
+
}
|
|
1162
|
+
let style = osmRasterStyle();
|
|
1163
|
+
if (options.style) {
|
|
1164
|
+
style = options.style;
|
|
1165
|
+
} else if (options.tianditu) {
|
|
1166
|
+
if (!options.tianditu.token) throw new MissingTokenError();
|
|
1167
|
+
style = tiandituStyle(
|
|
1168
|
+
options.tianditu.type ?? "vector",
|
|
1169
|
+
options.tianditu
|
|
1170
|
+
);
|
|
1171
|
+
} else {
|
|
1172
|
+
const g = getGlobalConfig();
|
|
1173
|
+
if (g.tiandituToken) {
|
|
1174
|
+
style = tiandituStyle("vector", { token: g.tiandituToken });
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
962
1177
|
this._map = new maplibregl__default.default.Map({
|
|
963
1178
|
container: options.container,
|
|
964
1179
|
center: options.center ?? WUHAN_CENTER,
|
|
965
1180
|
zoom: options.zoom ?? WUHAN_ZOOM,
|
|
966
|
-
style
|
|
1181
|
+
style,
|
|
967
1182
|
pitch: options.pitch ?? 0,
|
|
968
1183
|
bearing: options.bearing ?? 0,
|
|
969
1184
|
attributionControl: { compact: true }
|
|
@@ -1032,8 +1247,23 @@ var Map2 = class {
|
|
|
1032
1247
|
else this._map.on(event, cb);
|
|
1033
1248
|
}
|
|
1034
1249
|
addSource(id, source) {
|
|
1250
|
+
if (this._map.getSource(id)) {
|
|
1251
|
+
try {
|
|
1252
|
+
this._map.removeSource(id);
|
|
1253
|
+
} catch {
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1035
1256
|
this._map.addSource(id, source);
|
|
1036
1257
|
}
|
|
1258
|
+
/** 安全移除 source(不存在时静默忽略) */
|
|
1259
|
+
removeSource(id) {
|
|
1260
|
+
if (this._map.getSource(id)) {
|
|
1261
|
+
try {
|
|
1262
|
+
this._map.removeSource(id);
|
|
1263
|
+
} catch {
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1037
1267
|
getSource(id) {
|
|
1038
1268
|
return this._map.getSource(id);
|
|
1039
1269
|
}
|
|
@@ -1063,6 +1293,26 @@ var Map2 = class {
|
|
|
1063
1293
|
ctrl.addTo(container);
|
|
1064
1294
|
return ctrl;
|
|
1065
1295
|
}
|
|
1296
|
+
/**
|
|
1297
|
+
* 挂载图例控件(通用):渲染数据驱动的色块/线段图例,说明专题图层语义。
|
|
1298
|
+
* 返回控件实例,可调用 .setItems() 随图层切换更新、.remove() 卸载。
|
|
1299
|
+
*/
|
|
1300
|
+
addLegendControl(options) {
|
|
1301
|
+
const ctrl = new LegendControl(options);
|
|
1302
|
+
const container = this._map.getContainer();
|
|
1303
|
+
ctrl.addTo(container);
|
|
1304
|
+
return ctrl;
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* 挂载地图导出控件(通用):点击按钮将当前视图导出为 PNG 下载。
|
|
1308
|
+
* 返回控件实例,可调用 .remove() 卸载。
|
|
1309
|
+
*/
|
|
1310
|
+
addExportControl(options = {}) {
|
|
1311
|
+
const ctrl = new ExportControl(this._map, options);
|
|
1312
|
+
const container = this._map.getContainer();
|
|
1313
|
+
ctrl.addTo(container);
|
|
1314
|
+
return ctrl;
|
|
1315
|
+
}
|
|
1066
1316
|
/**
|
|
1067
1317
|
* 挂载辉光管线 Custom Layer(T6 / F-1.3)。
|
|
1068
1318
|
* 传入 GeoJSON 线集合,叠加渲染管线/路网/水系辉光效果。
|
|
@@ -1083,6 +1333,24 @@ var Map2 = class {
|
|
|
1083
1333
|
ctrl.evaluate(true);
|
|
1084
1334
|
return ctrl;
|
|
1085
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* 启用 3D 地形渲染(F-1.5)。
|
|
1338
|
+
*
|
|
1339
|
+
* 注入 raster-dem 高程源并调用 maplibre-gl 原生 `setTerrain`,使地图呈现地形起伏。
|
|
1340
|
+
* DEM 瓦片默认使用公共 Terrarium 源(elevation-tiles-prod,Terrain-RGB 编码,支持 CORS),
|
|
1341
|
+
* 可在 opts.tiles 覆盖为私有瓦片服务(如 MinIO / 本地 MBTiles 服务)。
|
|
1342
|
+
*
|
|
1343
|
+
* @param opts.exaggeration 地形夸张系数(默认 1.5)
|
|
1344
|
+
* @param opts.tiles DEM 瓦片模板,{z}/{x}/{y} 占位
|
|
1345
|
+
* @param opts.encoding 'terrarium'(默认,Mapzen)| 'mapbox'
|
|
1346
|
+
*/
|
|
1347
|
+
enableTerrain(opts = {}) {
|
|
1348
|
+
applyTerrain(this._map, opts);
|
|
1349
|
+
}
|
|
1350
|
+
/** 关闭 3D 地形渲染(F-1.5),并移除 DEM 源 */
|
|
1351
|
+
disableTerrain(sourceId = "cg-dem") {
|
|
1352
|
+
removeTerrain(this._map, sourceId);
|
|
1353
|
+
}
|
|
1086
1354
|
get instance() {
|
|
1087
1355
|
return this._map;
|
|
1088
1356
|
}
|
|
@@ -1096,7 +1364,9 @@ Object.defineProperty(exports, "maplibregl", {
|
|
|
1096
1364
|
exports.CACHEABLE_HOSTS = CACHEABLE_HOSTS;
|
|
1097
1365
|
exports.CACHE_NAME = CACHE_NAME;
|
|
1098
1366
|
exports.CustomLineLayer = CustomLineLayer;
|
|
1367
|
+
exports.ExportControl = ExportControl;
|
|
1099
1368
|
exports.IdbTileStore = IdbTileStore;
|
|
1369
|
+
exports.LegendControl = LegendControl;
|
|
1100
1370
|
exports.LodController = LodController;
|
|
1101
1371
|
exports.MSG_AIRGAP = MSG_AIRGAP;
|
|
1102
1372
|
exports.Map = Map2;
|
|
@@ -1108,6 +1378,7 @@ exports.ScaleControl = ScaleControl;
|
|
|
1108
1378
|
exports.ThemeSwitcher = ThemeSwitcher;
|
|
1109
1379
|
exports.WUHAN_CENTER = WUHAN_CENTER;
|
|
1110
1380
|
exports.WUHAN_ZOOM = WUHAN_ZOOM;
|
|
1381
|
+
exports.WebGLUnavailableError = WebGLUnavailableError;
|
|
1111
1382
|
exports.addTiandituBaseMap = addTiandituBaseMap;
|
|
1112
1383
|
exports.buildGlowGeometry = buildGlowGeometry;
|
|
1113
1384
|
exports.buildTiandituSources = buildTiandituSources;
|
|
@@ -1120,9 +1391,11 @@ exports.createTransformer = createTransformer;
|
|
|
1120
1391
|
exports.default = src_default;
|
|
1121
1392
|
exports.fromWgs84 = fromWgs84;
|
|
1122
1393
|
exports.gcj02ToWgs84 = gcj02ToWgs84;
|
|
1394
|
+
exports.getGlobalConfig = getGlobalConfig;
|
|
1123
1395
|
exports.glowPasses = glowPasses;
|
|
1124
1396
|
exports.installServiceWorker = installServiceWorker;
|
|
1125
1397
|
exports.isInChina = isInChina;
|
|
1398
|
+
exports.isWebGLAvailable = isWebGLAvailable;
|
|
1126
1399
|
exports.offlineGeoJSONSource = offlineGeoJSONSource;
|
|
1127
1400
|
exports.offlineSourceTiles = offlineSourceTiles;
|
|
1128
1401
|
exports.offlineTileUrl = offlineTileUrl;
|
|
@@ -1133,12 +1406,16 @@ exports.parseOfflineUrl = parseOfflineUrl;
|
|
|
1133
1406
|
exports.projectSimple = projectSimple;
|
|
1134
1407
|
exports.registerOfflineProtocol = registerOfflineProtocol;
|
|
1135
1408
|
exports.registerOfflineServiceWorker = registerOfflineServiceWorker;
|
|
1409
|
+
exports.removeSourceSafe = removeSourceSafe;
|
|
1410
|
+
exports.removeSourcesSafe = removeSourcesSafe;
|
|
1411
|
+
exports.renderLegendHtml = renderLegendHtml;
|
|
1136
1412
|
exports.resolveCacheKey = resolveCacheKey;
|
|
1137
1413
|
exports.resolveFromStore = resolveFromStore;
|
|
1138
1414
|
exports.resolveLod = resolveLod;
|
|
1139
1415
|
exports.resolveResponse = resolveResponse;
|
|
1140
1416
|
exports.setAirgap = setAirgap;
|
|
1141
1417
|
exports.setCgcs2000GridShift = setCgcs2000GridShift;
|
|
1418
|
+
exports.setGlobalConfig = setGlobalConfig;
|
|
1142
1419
|
exports.shouldCache = shouldCache;
|
|
1143
1420
|
exports.suggestDensity = suggestDensity;
|
|
1144
1421
|
exports.themeFromStyle = themeFromStyle;
|
|
@@ -1148,6 +1425,8 @@ exports.tileKey = tileKey;
|
|
|
1148
1425
|
exports.toWgs84 = toWgs84;
|
|
1149
1426
|
exports.transformBounds = transformBounds;
|
|
1150
1427
|
exports.transformPoint = transformPoint;
|
|
1428
|
+
exports.triggerDownload = triggerDownload;
|
|
1429
|
+
exports.upsertSource = upsertSource;
|
|
1151
1430
|
exports.wgs84ToCgcs2000 = wgs84ToCgcs2000;
|
|
1152
1431
|
exports.wgs84ToGcj02 = wgs84ToGcj02;
|
|
1153
1432
|
//# sourceMappingURL=index.cjs.map
|