@teeechina/teee-map 0.0.1 → 0.0.3

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 ADDED
@@ -0,0 +1,3 @@
1
+ # teee-map-sdk
2
+
3
+ 基于teee-map的npm发布版本
package/dist/teee-map.mjs CHANGED
@@ -33764,11 +33764,18 @@ var l = async () => {
33764
33764
  })
33765
33765
  ];
33766
33766
  }, b = {
33767
- ctc: (e) => ({
33768
- type: "vector",
33767
+ geojson: (e) => ({
33768
+ type: "geojson",
33769
+ data: e || {
33770
+ type: "FeatureCollection",
33771
+ features: []
33772
+ }
33773
+ }),
33774
+ raster: (e) => ({
33775
+ type: "raster",
33769
33776
  tiles: [e],
33770
33777
  scheme: "tms",
33771
- promoteId: "code"
33778
+ tileSize: 256
33772
33779
  }),
33773
33780
  graph: (e) => ({
33774
33781
  type: "vector",
@@ -33776,17 +33783,26 @@ var l = async () => {
33776
33783
  scheme: "tms",
33777
33784
  promoteId: "code"
33778
33785
  }),
33779
- raster: (e) => ({
33780
- type: "raster",
33781
- tiles: [e],
33782
- scheme: "tms",
33783
- tileSize: 256
33784
- }),
33785
33786
  geom: (e) => ({
33786
33787
  type: "vector",
33787
33788
  tiles: [e],
33788
33789
  scheme: "tms",
33789
33790
  promoteId: "code"
33791
+ }),
33792
+ image: (e, t) => ({
33793
+ type: "image",
33794
+ url: e,
33795
+ coordinates: t
33796
+ }),
33797
+ video: (e, t) => ({
33798
+ type: "video",
33799
+ urls: e,
33800
+ coordinates: t
33801
+ }),
33802
+ canvas: (e, t) => ({
33803
+ type: "canvas",
33804
+ canvas: e,
33805
+ coordinates: t
33790
33806
  })
33791
33807
  }, x = {
33792
33808
  background: (e, t) => ({
@@ -34617,7 +34633,7 @@ var l = async () => {
34617
34633
  22,
34618
34634
  15
34619
34635
  ],
34620
- "text-font": ["Arial Unicode MS Bold"],
34636
+ "text-font": ["Open Sans Regular"],
34621
34637
  "text-anchor": "top",
34622
34638
  "text-offset": [0, .5],
34623
34639
  "symbol-placement": "point",
@@ -35052,7 +35068,7 @@ var l = async () => {
35052
35068
  13
35053
35069
  ]
35054
35070
  ],
35055
- "text-font": ["Arial Unicode MS Bold"],
35071
+ "text-font": ["Open Sans Regular"],
35056
35072
  "text-anchor": [
35057
35073
  "case",
35058
35074
  [
@@ -35139,7 +35155,7 @@ var l = async () => {
35139
35155
  "界",
35140
35156
  "门"
35141
35157
  ],
35142
- "text-font": ["Arial Unicode MS Bold"],
35158
+ "text-font": ["Open Sans Regular"],
35143
35159
  "text-size": [
35144
35160
  "interpolate",
35145
35161
  ["linear"],
@@ -35327,26 +35343,32 @@ var l = async () => {
35327
35343
  Array.isArray(n) ? t.push(...n) : t.push(n);
35328
35344
  } else console.warn(`图层 ${n} 尚未实现`);
35329
35345
  }), t;
35330
- }
35346
+ },
35347
+ raster: (e) => [{
35348
+ id: `${e}_raster_layer`,
35349
+ type: "raster",
35350
+ source: e,
35351
+ paint: { "raster-opacity": 1 }
35352
+ }]
35331
35353
  };
35332
35354
  //#endregion
35333
- //#region src/utils/ctcTool.ts
35334
- function D(e) {
35335
- if (!e.mapConfigs) return;
35336
- let t = e.mapConfigs.id;
35337
- e.mapConfigs.sourceLayers.forEach((n) => {
35338
- n.includes("switch") ? e.map.querySourceFeatures(t, { sourceLayer: n }).forEach((t) => {
35339
- let n = {
35355
+ //#region src/teee-map/utils/ctcTool.ts
35356
+ function D() {
35357
+ if (!this.mapConfigs) return;
35358
+ let e = this.mapConfigs.id;
35359
+ this.mapConfigs.sourceLayers.forEach((t) => {
35360
+ t.includes("switch") ? this.map.querySourceFeatures(e, { sourceLayer: t }).forEach((e) => {
35361
+ let t = {
35340
35362
  state: "",
35341
35363
  select: !1,
35342
35364
  visiable: !0,
35343
35365
  subState1: "",
35344
35366
  subState2: "",
35345
35367
  subState3: ""
35346
- }, r = t.properties;
35347
- n.state = "2", e.updateFeatureState(r.code, n);
35348
- }) : n.includes("signal") ? e.map.querySourceFeatures(t, { sourceLayer: n }).forEach((t) => {
35349
- let n = t.properties, r = n.attach || 0, i = n.func_type, a = {
35368
+ }, n = e.properties;
35369
+ t.state = "2", this.updateFeatureState(n.code, t);
35370
+ }) : t.includes("signal") ? this.map.querySourceFeatures(e, { sourceLayer: t }).forEach((e) => {
35371
+ let t = e.properties, n = t.attach || 0, r = t.func_type, i = {
35350
35372
  state: "",
35351
35373
  select: !1,
35352
35374
  visiable: !0,
@@ -35354,56 +35376,166 @@ function D(e) {
35354
35376
  subState2: "",
35355
35377
  subState3: ""
35356
35378
  };
35357
- i == 1 && r == 0 || (i == 2 || i == 3) && r == 0 || (i == 2 || i == 3 || i == 11) && r == 1 ? (a.state = "red", a.subState1 = "blue", e.updateFeatureState(n.code, a)) : (i == 4 || i == 5 || i == 12) && r == 0 ? (a.state = "blue", a.subState1 = "green", e.updateFeatureState(n.code, a)) : i == 6 && r == 0 || (i == 7 || i == 11) && r == 0 ? (a.state = "red", a.subState1 = "blue", e.updateFeatureState(n.code, a)) : (a.state = "", a.subState1 = "grey", e.updateFeatureState(n.code, a));
35358
- }) : n.includes("track") && e.map.querySourceFeatures(t, { sourceLayer: n }).forEach((t) => {
35359
- let n = {
35379
+ r == 1 && n == 0 || (r == 2 || r == 3) && n == 0 || (r == 2 || r == 3 || r == 11) && n == 1 ? (i.state = "red", i.subState1 = "blue", this.updateFeatureState(t.code, i)) : (r == 4 || r == 5 || r == 12) && n == 0 ? (i.state = "blue", i.subState1 = "green", this.updateFeatureState(t.code, i)) : r == 6 && n == 0 || (r == 7 || r == 11) && n == 0 ? (i.state = "red", i.subState1 = "blue", this.updateFeatureState(t.code, i)) : (i.state = "", i.subState1 = "grey", this.updateFeatureState(t.code, i));
35380
+ }) : t.includes("track") && this.map.querySourceFeatures(e, { sourceLayer: t }).forEach((e) => {
35381
+ let t = {
35360
35382
  state: "",
35361
35383
  select: "",
35362
35384
  visiable: !0,
35363
35385
  subState1: "",
35364
35386
  subState2: "",
35365
35387
  subState3: ""
35366
- }, r = t.properties;
35367
- e.updateFeatureState(r.code, n);
35388
+ }, n = e.properties;
35389
+ this.updateFeatureState(n.code, t);
35368
35390
  });
35369
35391
  });
35370
35392
  }
35371
35393
  function O(e) {
35372
35394
  e.map.once("idle", () => {
35373
- console.log("地图瓦片加载完成"), e && (D(e), e.map.moveLayer(`${e.mapConfigs.id}_${e.mapConfigs.sourceLayers[e.mapConfigs.layers.indexOf("track")]}_lock`));
35395
+ e && (setTimeout(() => {
35396
+ e.initState();
35397
+ }, 1e3), e.map.moveLayer(`${e.mapConfigs.id}_${e.mapConfigs.sourceLayers[e.mapConfigs.layers.indexOf("track")]}_lock`));
35398
+ }), e.initState = D;
35399
+ }
35400
+ //#endregion
35401
+ //#region src/teee-map/utils/baseTool.ts
35402
+ function k(e, t) {
35403
+ let n = this.map;
35404
+ if (n && !n.getSource(e)) {
35405
+ let r = b.graph(t);
35406
+ n.addSource(e, r);
35407
+ }
35408
+ }
35409
+ function A(e, t) {
35410
+ let n = this.map;
35411
+ if (n && !n.getSource(e)) {
35412
+ let r = b.raster(t);
35413
+ n.addSource(e, r);
35414
+ }
35415
+ }
35416
+ function ee(e, t) {
35417
+ let n = this.map;
35418
+ if (!n) {
35419
+ console.error("地图实例未初始化");
35420
+ return;
35421
+ }
35422
+ try {
35423
+ if (n.getSource(e)) console.warn(`源已存在,跳过添加: ${e}`);
35424
+ else {
35425
+ let r = t ? b.geojson(t) : b.geojson();
35426
+ n.addSource(e, r), console.log(`成功添加 GeoJSON 源: ${e}`);
35427
+ }
35428
+ } catch (t) {
35429
+ console.error(` 添加源失败 [${e}]:`, t);
35430
+ }
35431
+ }
35432
+ function te(e) {
35433
+ let t = this.map;
35434
+ if (t) if (t.getSource(e)) try {
35435
+ (t.getStyle().layers || []).filter((t) => {
35436
+ if ("source" in t) return t.source === e;
35437
+ }).forEach((e) => {
35438
+ t.removeLayer(e.id), console.log(`移除关联图层: ${e.id}`);
35439
+ }), t.removeSource(e), console.log(`成功移除源: ${e}`);
35440
+ } catch (t) {
35441
+ console.error(`移除源失败 [${e}]:`, t);
35442
+ }
35443
+ else console.warn(`源不存在,无法移除: ${e}`);
35444
+ }
35445
+ function j(e, t) {
35446
+ let n = this.map;
35447
+ if (!n) return;
35448
+ let r = n.getSource(e);
35449
+ r ? (r.setData(t), console.log(`更新源数据: ${e}`)) : this.addGeoJsonSource(e, t);
35450
+ }
35451
+ function ne(e, t, n = "fill", r, i) {
35452
+ let a = this.map;
35453
+ if (!a) return;
35454
+ if (!a.getSource(t)) {
35455
+ console.error(`无法添加图层: 源 '${t}' 不存在`);
35456
+ return;
35457
+ }
35458
+ a.getLayer(e) && a.removeLayer(e);
35459
+ let o = {};
35460
+ n === "fill" && (o["fill-color"] = "#3b82f6"), n === "line" && (o["line-color"] = "#3b82f6"), n === "circle" && (o["circle-color"] = "#3b82f6");
35461
+ let s = {
35462
+ id: e,
35463
+ type: n,
35464
+ source: t,
35465
+ paint: {
35466
+ ...o,
35467
+ ...r
35468
+ },
35469
+ layout: i || {}
35470
+ };
35471
+ a.addLayer(s);
35472
+ }
35473
+ function re(e, t) {
35474
+ let n = this.map;
35475
+ n && (n.getLayer(e) ? (Object.keys(t).forEach((r) => {
35476
+ n.setPaintProperty(e, r, t[r]);
35477
+ }), console.log(`样式已更新: ${e}`)) : console.warn(` 图层不存在,无法更新样式: ${e}`));
35478
+ }
35479
+ function ie(e) {
35480
+ let t = this.map;
35481
+ t && (t.getLayer(e) ? (t.removeLayer(e), console.log(`图层已移除: ${e}`)) : console.warn(` 图层不存在,无法删除: ${e}`));
35482
+ }
35483
+ function M(e, t) {
35484
+ let n = this.map;
35485
+ if (!n) return;
35486
+ let r = Array.isArray(e) ? e : [e];
35487
+ n.on("click", (e) => {
35488
+ let i = n.queryRenderedFeatures(e.point, { layers: r });
35489
+ if (!i.length) return;
35490
+ let a = i[0];
35491
+ t(a, e.lngLat);
35492
+ }), n.on("mouseenter", r[r.length - 1], () => {
35493
+ n.getCanvas().style.cursor = "pointer";
35494
+ }), n.on("mouseleave", r[r.length - 1], () => {
35495
+ n.getCanvas().style.cursor = "";
35374
35496
  });
35375
35497
  }
35498
+ function ae() {
35499
+ this.map &&= null, this.mapConfigs &&= null, this.stashFeatures.clear(), this.map && (this.map.remove(), console.log("地图实例已移除"));
35500
+ }
35501
+ function oe(e) {
35502
+ e.addGeoJsonSource = ee, e.addVectorTileSource = k, e.addRasterTileSource = A, e.updateGeoJsonSource = j, e.removeSource = te, e.addGeoJsonLayer = ne, e.updateLayerStyle = re, e.removeLayer = ie, e.onFeatureClick = M, e.destroy = ae;
35503
+ }
35376
35504
  //#endregion
35377
- //#region src/utils/index.ts
35378
- var k = { ctc: O }, A = {
35505
+ //#region src/teee-map/utils/index.ts
35506
+ var se = {
35507
+ base: oe,
35508
+ ctc: O
35509
+ }, N = {
35379
35510
  ctc: (e, t, n) => ({
35380
35511
  id: "ctc",
35381
35512
  sourceUrl: t,
35382
35513
  layers: n,
35383
35514
  sourceLayers: n.map((t) => t === "switch_loc" ? `${e}_SG_t_${t}` : `${e}_SG_t_${t}_graph`)
35384
35515
  }),
35385
- raster: (e, t) => ({
35516
+ raster: (e) => ({
35386
35517
  id: "raster",
35387
35518
  sourceUrl: e,
35388
- center: t,
35389
35519
  zoom: 20
35390
35520
  }),
35391
- geom: (e, t) => {
35392
- let n = t.map((t) => t === "switch_loc" ? `${e}_t_${t}` : `${e}_t_${t}_geom`);
35393
- return {
35394
- id: "geom",
35395
- sourceUrl: `http://css.teeechina.com:20902/wapian/1.0.0/teee:${e}_station_geom@EPSG%3A900913@pbf/{z}/{x}/{y}`,
35396
- layers: t,
35397
- sourceLayers: n
35398
- };
35399
- },
35521
+ geom: (e, t, n) => ({
35522
+ id: "geom",
35523
+ sourceUrl: t,
35524
+ layers: n,
35525
+ sourceLayers: n.map((t) => t === "switch_loc" ? `${e}_t_${t}` : `${e}_t_${t}_geom`)
35526
+ }),
35400
35527
  graph: (e, t, n) => ({
35401
35528
  id: "graph",
35402
35529
  sourceUrl: t,
35403
35530
  layers: n,
35404
35531
  sourceLayers: n.map((t) => t === "switch_loc" ? `${e}_t_${t}` : `${e}_t_${t}_graph`)
35532
+ }),
35533
+ geojson: (e) => ({ id: e }),
35534
+ rswp: (e) => ({
35535
+ id: "rswp",
35536
+ sourceUrl: e
35405
35537
  })
35406
- }, ee = class {
35538
+ }, ce = class {
35407
35539
  constructor(e) {
35408
35540
  this.stashFeatures = /* @__PURE__ */ new Map();
35409
35541
  let t = {
@@ -35414,17 +35546,16 @@ var k = { ctc: O }, A = {
35414
35546
  this.map = new c.default.Map({
35415
35547
  container: e,
35416
35548
  style: t,
35417
- center: [.09632598385281314, .05599149797940485],
35418
- zoom: 14.4
35549
+ center: [0, 0],
35550
+ zoom: 14
35551
+ }), this.map.on("load", () => {
35552
+ se.base(this);
35419
35553
  });
35420
35554
  }
35421
- destroy() {
35422
- this.map &&= null, this.mapConfigs &&= null, this.stashFeatures.clear();
35423
- }
35424
35555
  initMap(e) {
35425
35556
  this.map.on("load", async () => {
35426
35557
  try {
35427
- if (console.log(`开始初始化地图: ${e.id}`), this.map.getSource(e.id) ? console.warn(`地图源已存在,跳过添加: ${e.id}`) : this.map.addSource(e.id, e.source), (await y()).forEach((e) => {
35558
+ if (console.log(`开始构建业务地图: ${e.id}`), this.map.getSource(e.id) ? console.warn(`地图源已存在,跳过添加: ${e.id}`) : this.map.addSource(e.id, e.source), e.subSourceId && (this.map.getSource(e.subSourceId) ? console.warn(`地图源已存在,跳过添加: ${e.subSourceId}`) : this.map.addSource(e.subSourceId, e.subSource)), (await y()).forEach((e) => {
35428
35559
  this.map.hasImage(e.id) ? console.warn(`图标已存在,跳过添加: ${e.id}`) : this.map.addImage(e.id, e.image);
35429
35560
  }), e.layers) {
35430
35561
  let t = 0;
@@ -35440,41 +35571,54 @@ var k = { ctc: O }, A = {
35440
35571
  console.error(`地图初始化失败: ${e.id}`, t), t instanceof Error && console.error(`错误详情: ${t.message}`);
35441
35572
  }
35442
35573
  }), this.map.once("idle", () => {
35443
- console.log("地图执行地图方法"), this.stashAllFeature();
35574
+ setTimeout(() => {
35575
+ this.stashAllFeature();
35576
+ }, 800);
35444
35577
  });
35445
35578
  }
35446
35579
  createCTCMap(e, t, n) {
35447
- this.mapConfigs = A.ctc(e, t, n);
35448
- let r = b.ctc(this.mapConfigs.sourceUrl), i = E.ctc(this.mapConfigs), a = {
35580
+ this.mapConfigs = N.ctc(e, t, n);
35581
+ let r = b.graph(this.mapConfigs.sourceUrl), i = E.ctc(this.mapConfigs), a = {
35449
35582
  id: this.mapConfigs.id,
35450
35583
  source: r,
35451
35584
  layers: i
35452
35585
  };
35453
- this.initMap(a), k.ctc(this);
35586
+ this.initMap(a), se.ctc(this);
35587
+ }
35588
+ createRSWPMap(e) {
35589
+ let t = N.rswp(e), n = b.raster(t.sourceUrl), r = E.raster(t.id), i = N.geojson("rswp-geojson"), a = b.geojson(), o = {
35590
+ id: t.id,
35591
+ source: n,
35592
+ subSourceId: i.id,
35593
+ subSource: a,
35594
+ layers: r
35595
+ };
35596
+ this.mapConfigs = t, this.mapConfigs.subSourceId = i.id, this.initMap(o);
35454
35597
  }
35455
35598
  createGraphMap(e, t, n) {
35456
- this.mapConfigs = A.graph(e, t, n);
35599
+ this.mapConfigs = N.graph(e, t, n);
35457
35600
  let r = b.graph(this.mapConfigs.sourceUrl), i = E.ctc(this.mapConfigs), a = {
35458
35601
  id: this.mapConfigs.id,
35459
35602
  source: r,
35460
35603
  layers: i
35461
35604
  };
35462
- this.initMap(a), k.ctc(this);
35605
+ this.initMap(a), se.ctc(this);
35463
35606
  }
35464
- createGeomMap(e, t) {
35465
- this.mapConfigs = A.geom(e, t);
35466
- let n = b.geom(this.mapConfigs.sourceUrl), r = E.geom(this.mapConfigs), i = {
35607
+ createGeomMap(e, t, n) {
35608
+ this.mapConfigs = N.geom(e, t, n);
35609
+ let r = b.geom(this.mapConfigs.sourceUrl), i = E.geom(this.mapConfigs), a = {
35467
35610
  id: this.mapConfigs.id,
35468
- source: n,
35469
- layers: r
35611
+ source: r,
35612
+ layers: i
35470
35613
  };
35471
- this.initMap(i);
35614
+ this.initMap(a);
35472
35615
  }
35473
- createRasterMap(e, t) {
35474
- this.mapConfigs = A.raster(e, t);
35475
- let n = b.raster(this.mapConfigs.sourceUrl), r = {
35616
+ createRasterMap(e) {
35617
+ this.mapConfigs = N.raster(e);
35618
+ let t = b.raster(this.mapConfigs.sourceUrl), n = E.raster(this.mapConfigs.id), r = {
35476
35619
  id: this.mapConfigs.id,
35477
- source: n
35620
+ source: t,
35621
+ layers: n
35478
35622
  };
35479
35623
  this.initMap(r);
35480
35624
  }
@@ -35495,10 +35639,6 @@ var k = { ctc: O }, A = {
35495
35639
  });
35496
35640
  });
35497
35641
  }
35498
- hoverFeatureSelect() {}
35499
- initState() {
35500
- D(this);
35501
- }
35502
35642
  updateFeatureState(e, t) {
35503
35643
  if (!this.mapConfigs) return;
35504
35644
  let n = this.mapConfigs.id;
@@ -35512,4 +35652,4 @@ var k = { ctc: O }, A = {
35512
35652
  }
35513
35653
  };
35514
35654
  //#endregion
35515
- export { ee as TeeeMap };
35655
+ export { ce as TeeeMap, ce as default };