@caoguo/maplibre 0.0.5 → 0.0.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.
Files changed (64) hide show
  1. package/dist/chunk-DENQSIV2.js +81 -0
  2. package/dist/chunk-DENQSIV2.js.map +1 -0
  3. package/dist/chunk-G7VY42ZG.js +210 -0
  4. package/dist/chunk-G7VY42ZG.js.map +1 -0
  5. package/dist/chunk-MLLIAWVI.js +214 -0
  6. package/dist/chunk-MLLIAWVI.js.map +1 -0
  7. package/dist/chunk-OLS4DD3F.js +27 -0
  8. package/dist/chunk-OLS4DD3F.js.map +1 -0
  9. package/dist/chunk-OUEPE6JT.js +26 -0
  10. package/dist/chunk-OUEPE6JT.js.map +1 -0
  11. package/dist/chunk-SKXL3DKL.js +125 -0
  12. package/dist/chunk-SKXL3DKL.js.map +1 -0
  13. package/dist/chunk-Y3JNDOHU.js +56 -0
  14. package/dist/chunk-Y3JNDOHU.js.map +1 -0
  15. package/dist/controls/index.cjs +227 -0
  16. package/dist/controls/index.cjs.map +1 -0
  17. package/dist/controls/index.d.cts +171 -0
  18. package/dist/controls/index.d.ts +171 -0
  19. package/dist/controls/index.js +4 -0
  20. package/dist/controls/index.js.map +1 -0
  21. package/dist/crs/index.cjs +137 -0
  22. package/dist/crs/index.cjs.map +1 -0
  23. package/dist/crs/index.d.cts +80 -0
  24. package/dist/crs/index.d.ts +80 -0
  25. package/dist/crs/index.js +3 -0
  26. package/dist/crs/index.js.map +1 -0
  27. package/dist/index.cjs +119 -41
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +19 -484
  30. package/dist/index.d.ts +19 -484
  31. package/dist/index.js +18 -604
  32. package/dist/index.js.map +1 -1
  33. package/dist/lod/index.cjs +60 -0
  34. package/dist/lod/index.cjs.map +1 -0
  35. package/dist/lod/index.d.cts +62 -0
  36. package/dist/lod/index.d.ts +62 -0
  37. package/dist/lod/index.js +3 -0
  38. package/dist/lod/index.js.map +1 -0
  39. package/dist/shaders/index.cjs +215 -0
  40. package/dist/shaders/index.cjs.map +1 -0
  41. package/dist/shaders/index.d.cts +131 -0
  42. package/dist/shaders/index.d.ts +131 -0
  43. package/dist/shaders/index.js +3 -0
  44. package/dist/shaders/index.js.map +1 -0
  45. package/dist/sourceUtils.cjs +30 -0
  46. package/dist/sourceUtils.cjs.map +1 -0
  47. package/dist/sourceUtils.d.cts +60 -0
  48. package/dist/sourceUtils.d.ts +60 -0
  49. package/dist/sourceUtils.js +3 -0
  50. package/dist/sourceUtils.js.map +1 -0
  51. package/dist/styles.cjs +47 -12
  52. package/dist/styles.cjs.map +1 -1
  53. package/dist/styles.d.cts +13 -4
  54. package/dist/styles.d.ts +13 -4
  55. package/dist/styles.js +1 -1
  56. package/dist/terrain.cjs +31 -0
  57. package/dist/terrain.cjs.map +1 -0
  58. package/dist/terrain.d.cts +28 -0
  59. package/dist/terrain.d.ts +28 -0
  60. package/dist/terrain.js +3 -0
  61. package/dist/terrain.js.map +1 -0
  62. package/package.json +35 -5
  63. package/dist/chunk-DNEF4DHG.js +0 -48
  64. package/dist/chunk-DNEF4DHG.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/dist/index.cjs CHANGED
@@ -16,20 +16,18 @@ var WUHAN_ZOOM = 11;
16
16
  function caoguoStyle(theme$1 = "caoguo-dark") {
17
17
  return theme.buildStyle(theme$1);
18
18
  }
19
- function osmRasterStyle() {
19
+ function geoqRasterStyle() {
20
20
  return {
21
21
  version: 8,
22
22
  glyphs: "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf",
23
23
  sources: {
24
- "osm-raster": {
24
+ "geoq-raster": {
25
25
  type: "raster",
26
26
  tiles: [
27
- "https://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
28
- "https://b.tile.openstreetmap.org/{z}/{x}/{y}.png",
29
- "https://c.tile.openstreetmap.org/{z}/{x}/{y}.png"
27
+ "https://map.geoq.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}"
30
28
  ],
31
29
  tileSize: 256,
32
- attribution: "\xA9 OpenStreetMap contributors"
30
+ attribution: "\xA9 GeoQ \u667A\u56FE"
33
31
  }
34
32
  },
35
33
  layers: [
@@ -39,19 +37,54 @@ function osmRasterStyle() {
39
37
  paint: { "background-color": "#0a0f1e" }
40
38
  },
41
39
  {
42
- id: "osm-raster",
40
+ id: "geoq-raster",
43
41
  type: "raster",
44
- source: "osm-raster",
42
+ source: "geoq-raster",
45
43
  paint: {
46
- "raster-opacity": 0.85,
47
- "raster-saturation": -0.6,
48
- "raster-brightness-max": 0.7,
49
- "raster-contrast": 0.1
44
+ "raster-opacity": 0.9,
45
+ "raster-saturation": -0.2,
46
+ "raster-contrast": 0.05
50
47
  }
51
48
  }
52
49
  ]
53
50
  };
54
51
  }
52
+ var osmRasterStyle = geoqRasterStyle;
53
+ function buildGraticule(step = 10) {
54
+ const features = [];
55
+ for (let lon = -180; lon <= 180; lon += step) {
56
+ features.push({
57
+ type: "Feature",
58
+ properties: { kind: "meridian" },
59
+ geometry: { type: "LineString", coordinates: [[lon, -85], [lon, 85]] }
60
+ });
61
+ }
62
+ for (let lat = -80; lat <= 80; lat += step) {
63
+ features.push({
64
+ type: "Feature",
65
+ properties: { kind: "parallel" },
66
+ geometry: { type: "LineString", coordinates: [[-180, lat], [180, lat]] }
67
+ });
68
+ }
69
+ return { type: "FeatureCollection", features };
70
+ }
71
+ function localBasemapStyle() {
72
+ return {
73
+ version: 8,
74
+ sources: {
75
+ graticule: { type: "geojson", data: buildGraticule() }
76
+ },
77
+ layers: [
78
+ { id: "bg", type: "background", paint: { "background-color": "#0a0f1e" } },
79
+ {
80
+ id: "graticule",
81
+ type: "line",
82
+ source: "graticule",
83
+ paint: { "line-color": "#1e293b", "line-width": 0.6, "line-opacity": 0.6 }
84
+ }
85
+ ]
86
+ };
87
+ }
55
88
 
56
89
  // src/crs/gcj02.ts
57
90
  var PI = Math.PI;
@@ -866,39 +899,54 @@ function projectSimple(lng, lat) {
866
899
  }
867
900
  function buildGlowGeometry(lines, opts = {}) {
868
901
  const passes = glowPasses(opts.passes ?? 4, opts.baseWidth ?? 3);
869
- const stride = 5;
902
+ const stride = 6;
870
903
  const verts = [];
871
904
  const passRanges = [];
872
- for (const pass of passes) {
905
+ const renderGroups = [];
906
+ const groups = [];
907
+ for (const line of lines) {
908
+ const g = line.group ?? "default";
909
+ if (!groups.includes(g)) groups.push(g);
910
+ }
911
+ for (let p = 0; p < passes.length; p++) {
912
+ passes[p];
873
913
  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]);
914
+ for (const group of groups) {
915
+ const groupStart = verts.length / stride;
916
+ const groupIndex = groups.indexOf(group);
917
+ for (const line of lines) {
918
+ if ((line.group ?? "default") !== group) continue;
919
+ const pts = line.coordinates.map(([lng, lat]) => projectSimple(lng, lat));
920
+ if (pts.length < 2) continue;
921
+ for (let i = 0; i < pts.length - 1; i++) {
922
+ const a = pts[i];
923
+ const b = pts[i + 1];
924
+ const dx = b[0] - a[0];
925
+ const dy = b[1] - a[1];
926
+ const quad = [
927
+ [a[0], a[1], dx, dy, 1, groupIndex],
928
+ [a[0], a[1], dx, dy, -1, groupIndex],
929
+ [b[0], b[1], dx, dy, 1, groupIndex],
930
+ [b[0], b[1], dx, dy, -1, groupIndex]
931
+ ];
932
+ const idx = [0, 1, 2, 2, 1, 3];
933
+ for (const k of idx) {
934
+ const v = quad[k];
935
+ verts.push(v[0], v[1], v[2], v[3], v[4], v[5]);
936
+ }
892
937
  }
893
938
  }
939
+ const count2 = verts.length / stride - groupStart;
940
+ if (count2 > 0) renderGroups.push({ passIndex: p, group, start: groupStart, count: count2 });
894
941
  }
895
942
  const count = verts.length / stride - start;
896
943
  passRanges.push({ start, count });
897
944
  }
898
- return { vertices: new Float32Array(verts), passRanges, passes, stride };
945
+ return { vertices: new Float32Array(verts), passRanges, passes, stride, groups, renderGroups };
899
946
  }
900
947
 
901
948
  // src/shaders/CustomLineLayer.ts
949
+ var FALLBACK_COLOR = [0.6, 0.7, 0.9];
902
950
  var DEFAULT_COLORS = {
903
951
  pipe: [0.2, 0.85, 1],
904
952
  // 青蓝:管线
@@ -952,9 +1000,13 @@ var CustomLineLayer = class {
952
1000
  this.colors = { ...DEFAULT_COLORS, ...opts.colors };
953
1001
  this.baseWidth = opts.baseWidth ?? 3;
954
1002
  this.geometry = buildGlowGeometry(this.lines, { passes: opts.passes ?? 4, baseWidth: this.baseWidth });
1003
+ for (const g of this.geometry.groups) {
1004
+ if (!(g in this.colors)) this.colors[g] = FALLBACK_COLOR;
1005
+ }
955
1006
  }
956
1007
  onAdd(map, gl) {
957
1008
  this.map = map;
1009
+ this.gl = gl;
958
1010
  const vs = compile(gl, gl.VERTEX_SHADER, VERT);
959
1011
  const fs = compile(gl, gl.FRAGMENT_SHADER, FRAG);
960
1012
  const prog = gl.createProgram();
@@ -978,12 +1030,17 @@ var CustomLineLayer = class {
978
1030
  const aPos = gl.getAttribLocation(this.program, "aPos");
979
1031
  const aDir = gl.getAttribLocation(this.program, "aDir");
980
1032
  const aSide = gl.getAttribLocation(this.program, "aSide");
1033
+ const aGroup = gl.getAttribLocation(this.program, "aGroup");
981
1034
  gl.enableVertexAttribArray(aPos);
982
1035
  gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, stride, 0);
983
1036
  gl.enableVertexAttribArray(aDir);
984
1037
  gl.vertexAttribPointer(aDir, 2, gl.FLOAT, false, stride, 8);
985
1038
  gl.enableVertexAttribArray(aSide);
986
1039
  gl.vertexAttribPointer(aSide, 1, gl.FLOAT, false, stride, 16);
1040
+ if (aGroup >= 0) {
1041
+ gl.enableVertexAttribArray(aGroup);
1042
+ gl.vertexAttribPointer(aGroup, 1, gl.FLOAT, false, stride, 20);
1043
+ }
987
1044
  const uMatrix = gl.getUniformLocation(this.program, "uMatrix");
988
1045
  gl.uniformMatrix4fv(uMatrix, false, new Float32Array(matrix));
989
1046
  const uWidth = gl.getUniformLocation(this.program, "uWidth");
@@ -994,15 +1051,31 @@ var CustomLineLayer = class {
994
1051
  gl.uniform2f(uRes, canvas?.width ?? 1024, canvas?.height ?? 768);
995
1052
  gl.enable(gl.BLEND);
996
1053
  gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
997
- const color = this.colors[this.lines[0]?.group ?? "pipe"] ?? this.colors.pipe;
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;
1054
+ for (const rg of this.geometry.renderGroups) {
1055
+ const pass = this.geometry.passes[rg.passIndex];
1056
+ const color = this.colors[rg.group] ?? FALLBACK_COLOR;
1002
1057
  gl.uniform1f(uWidth, pass.width);
1003
1058
  gl.uniform3f(uColor, color[0], color[1], color[2]);
1004
1059
  gl.uniform1f(uOpacity, pass.opacity);
1005
- gl.drawArrays(gl.TRIANGLES, range.start, range.count);
1060
+ gl.drawArrays(gl.TRIANGLES, rg.start, rg.count);
1061
+ }
1062
+ }
1063
+ /**
1064
+ * 动态更新线集合(高亮选中、切换数据等无需重建图层)。
1065
+ * 浏览器环境会刷新 GPU 缓冲;纯逻辑/测试环境仅更新几何与数据。
1066
+ */
1067
+ setLines(lines) {
1068
+ this.lines = lines;
1069
+ this.geometry = buildGlowGeometry(this.lines, {
1070
+ passes: this.geometry.passes.length,
1071
+ baseWidth: this.baseWidth
1072
+ });
1073
+ for (const g of this.geometry.groups) {
1074
+ if (!(g in this.colors)) this.colors[g] = FALLBACK_COLOR;
1075
+ }
1076
+ if (this.buffer && this.gl) {
1077
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffer);
1078
+ this.gl.bufferData(this.gl.ARRAY_BUFFER, this.geometry.vertices, this.gl.STATIC_DRAW);
1006
1079
  }
1007
1080
  }
1008
1081
  onRemove(_map, gl) {
@@ -1159,7 +1232,7 @@ var Map2 = class {
1159
1232
  if (!isWebGLAvailable()) {
1160
1233
  throw new WebGLUnavailableError();
1161
1234
  }
1162
- let style = osmRasterStyle();
1235
+ let style = localBasemapStyle();
1163
1236
  if (options.style) {
1164
1237
  style = options.style;
1165
1238
  } else if (options.tianditu) {
@@ -1321,7 +1394,10 @@ var Map2 = class {
1321
1394
  addGlowLayer(opts) {
1322
1395
  const layer = new CustomLineLayer(opts);
1323
1396
  this._map.addLayer(layer);
1324
- return layer.id;
1397
+ return {
1398
+ id: layer.id,
1399
+ setLines: (lines) => layer.setLines(lines)
1400
+ };
1325
1401
  }
1326
1402
  /**
1327
1403
  * 挂载 LOD 控制器(T7 / F-1.7)。
@@ -1391,11 +1467,13 @@ exports.createTransformer = createTransformer;
1391
1467
  exports.default = src_default;
1392
1468
  exports.fromWgs84 = fromWgs84;
1393
1469
  exports.gcj02ToWgs84 = gcj02ToWgs84;
1470
+ exports.geoqRasterStyle = geoqRasterStyle;
1394
1471
  exports.getGlobalConfig = getGlobalConfig;
1395
1472
  exports.glowPasses = glowPasses;
1396
1473
  exports.installServiceWorker = installServiceWorker;
1397
1474
  exports.isInChina = isInChina;
1398
1475
  exports.isWebGLAvailable = isWebGLAvailable;
1476
+ exports.localBasemapStyle = localBasemapStyle;
1399
1477
  exports.offlineGeoJSONSource = offlineGeoJSONSource;
1400
1478
  exports.offlineSourceTiles = offlineSourceTiles;
1401
1479
  exports.offlineTileUrl = offlineTileUrl;