@teeechina/teee-map 0.0.33 → 0.0.34

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/teee-map.mjs CHANGED
@@ -41971,7 +41971,7 @@ function zn(e, t) {
41971
41971
  });
41972
41972
  }
41973
41973
  function Bn() {
41974
- this.stashFeatures.clear(), this.map && (this.map.remove(), console.log("地图实例已移除"));
41974
+ this.invalidateStashReady(), this.stashFeatures.clear(), this.map && (this.map.remove(), console.log("地图实例已移除"));
41975
41975
  }
41976
41976
  function Vn(e, t, n) {
41977
41977
  let r = 2 ** n, i = Math.floor((e + 180) / 360 * r), a = t * Math.PI / 180;
@@ -42683,7 +42683,7 @@ function $n(e) {
42683
42683
  //#endregion
42684
42684
  //#region src/teee-map/utils/geojsonLayerTool.ts
42685
42685
  function er() {
42686
- this.mapConfigs && (this.mapConfigs.layers ?? []).forEach((e) => {
42686
+ this.mapConfigs && this.stashFeatures.size !== 0 && (this.mapConfigs.layers ?? []).forEach((e) => {
42687
42687
  let t = `geojson_${e}`;
42688
42688
  this.map.getSource(t) && this.stashFeatures.forEach((n) => {
42689
42689
  n.sourceLayer !== t || !n.properties || this.initGeoJsonFeatureState({ properties: n.properties }, e);
@@ -42691,7 +42691,7 @@ function er() {
42691
42691
  });
42692
42692
  }
42693
42693
  function tr() {
42694
- if (this.mixingMapConfigs.size !== 0) for (let [e, t] of this.mixingMapConfigs) {
42694
+ if (this.mixingMapConfigs.size !== 0 && this.stashFeatures.size !== 0) for (let [e, t] of this.mixingMapConfigs) {
42695
42695
  let n = t.type;
42696
42696
  (t.layers ?? []).forEach((t) => {
42697
42697
  let r = `geojson_${n}_${e}_${t}`;
@@ -52302,6 +52302,9 @@ var ic = class e {
52302
52302
  stashFeatures = /* @__PURE__ */ new Map();
52303
52303
  layerFeaturesCache = /* @__PURE__ */ new Map();
52304
52304
  _activeBlinkCleanup = null;
52305
+ _stashReady = Promise.resolve();
52306
+ _stashReadyResolve = null;
52307
+ _stashReadyReject = null;
52305
52308
  constructor(e) {
52306
52309
  let t = {
52307
52310
  version: 8,
@@ -52319,7 +52322,36 @@ var ic = class e {
52319
52322
  this.cursorTool = new Bs.cursor(this.map), this.drawTool = new Bs.draw(this), this.injectTeeeGeoJson = Bs.injectTeeeGeoJson, this.snaps = new Bs.snaps(this), this.drawRoute = new Bs.drawRoute(this);
52320
52323
  });
52321
52324
  }
52325
+ resetStashReady() {
52326
+ this._stashReadyResolve?.(), this._stashReady = new Promise((e, t) => {
52327
+ this._stashReadyResolve = e, this._stashReadyReject = t;
52328
+ }), this._stashReady.catch(() => {});
52329
+ }
52330
+ markStashReady() {
52331
+ this._stashReadyResolve?.(), this._stashReadyResolve = null, this._stashReadyReject = null;
52332
+ }
52333
+ invalidateStashReady(e) {
52334
+ this._stashReadyReject?.(Error(e ?? "TeeeMap 已销毁:要素缓存不会再就绪")), this._stashReadyResolve = null, this._stashReadyReject = null;
52335
+ }
52336
+ whenStashed(e = 3e4) {
52337
+ return e <= 0 ? this._stashReady : new Promise((t, n) => {
52338
+ let r = setTimeout(() => {
52339
+ n(/* @__PURE__ */ Error(`whenStashed 超时(${e}ms):要素缓存未在预期时间内就绪`));
52340
+ }, e);
52341
+ this._stashReady.then(() => {
52342
+ clearTimeout(r), t();
52343
+ }, (e) => {
52344
+ clearTimeout(r), n(e);
52345
+ });
52346
+ });
52347
+ }
52348
+ onStashReady(e, t) {
52349
+ this.whenStashed().then(e).catch((e) => {
52350
+ t ? t(e) : console.error("onStashReady: 等待要素缓存就绪失败", e);
52351
+ });
52352
+ }
52322
52353
  initMap(e, t = !1) {
52354
+ this.resetStashReady();
52323
52355
  let n = async () => {
52324
52356
  try {
52325
52357
  if (console.log(`开始构建业务地图: ${e.id}`), Array.isArray(e.source)) if (t) {
@@ -52358,7 +52390,9 @@ var ic = class e {
52358
52390
  }
52359
52391
  }, r = () => {
52360
52392
  this.map.once("idle", () => {
52361
- t ? this.stashMixMapAllFeature() : this.stashAllFeature();
52393
+ (t ? this.stashMixMapAllFeature() : this.stashAllFeature()).catch((t) => {
52394
+ console.error(`要素缓存失败: ${e.id}`, t);
52395
+ }).finally(() => this.markStashReady());
52362
52396
  });
52363
52397
  };
52364
52398
  this.map.loaded() ? n().then(r) : this.map.on("load", () => {
@@ -52366,6 +52400,7 @@ var ic = class e {
52366
52400
  });
52367
52401
  }
52368
52402
  async initMixMap(e) {
52403
+ this.resetStashReady();
52369
52404
  let t = async () => {
52370
52405
  let t = await rt();
52371
52406
  console.log(`图标列表 (${t.length}):`, t), t.forEach((e) => {
@@ -52399,11 +52434,17 @@ var ic = class e {
52399
52434
  let e = c.geometry;
52400
52435
  this.mapDir = e.coordinates[0][0] - e.coordinates[1][0] > 0 ? "left" : "right";
52401
52436
  }
52402
- this.stashMixMapAllFeature(), Bs.geojson(this);
52437
+ await this.stashMixMapAllFeature(), Bs.geojson(this);
52438
+ }, n = async () => {
52439
+ try {
52440
+ await t();
52441
+ } catch (e) {
52442
+ console.error("混合地图构建失败", e);
52443
+ } finally {
52444
+ this.markStashReady();
52445
+ }
52403
52446
  };
52404
- this.map.loaded() ? t() : this.map.on("load", () => {
52405
- t();
52406
- });
52447
+ this.map.loaded() ? n() : this.map.once("load", () => void n());
52407
52448
  }
52408
52449
  createCTCMap(e, t, n) {
52409
52450
  let r = Vs.ctc(e, t, n);
@@ -52731,7 +52772,7 @@ var ic = class e {
52731
52772
  return this.mapConfigs;
52732
52773
  }
52733
52774
  destroy() {
52734
- this._activeBlinkCleanup?.(), this._activeBlinkCleanup = null, this.stashFeatures.clear(), this.layerFeaturesCache.clear(), this.mixingMapConfigs.clear(), this.map.remove();
52775
+ this._activeBlinkCleanup?.(), this._activeBlinkCleanup = null, this.invalidateStashReady(), this.stashFeatures.clear(), this.layerFeaturesCache.clear(), this.mixingMapConfigs.clear(), this.map.remove();
52735
52776
  }
52736
52777
  async stashMixMapAllFeature() {
52737
52778
  if (this.mixingMapConfigs.size !== 0) for (let [e, t] of this.mixingMapConfigs) {