vue-openlayers-plugin 1.0.69 → 1.0.70

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.
@@ -41751,7 +41751,7 @@ function checkProj$1(item) {
41751
41751
  item
41752
41752
  );
41753
41753
  }
41754
- function proj4$3(fromProjOrToProj, toProjOrCoord, coord) {
41754
+ function proj4$2(fromProjOrToProj, toProjOrCoord, coord) {
41755
41755
  var fromProj;
41756
41756
  var toProj;
41757
41757
  var single = false;
@@ -45755,7 +45755,7 @@ function includedProjections$1(proj42) {
45755
45755
  proj42.Proj.projections.add(eqearth$1);
45756
45756
  proj42.Proj.projections.add(bonne$1);
45757
45757
  }
45758
- const proj4$1 = Object.assign(proj4$3, {
45758
+ const proj4$1 = Object.assign(proj4$2, {
45759
45759
  defaultDatum: "WGS84",
45760
45760
  Proj: Projection$3,
45761
45761
  WGS84: new Projection$3("WGS84"),
@@ -45768,10 +45768,6 @@ const proj4$1 = Object.assign(proj4$3, {
45768
45768
  version: "__VERSION__"
45769
45769
  });
45770
45770
  includedProjections$1(proj4$1);
45771
- const proj4$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
45772
- __proto__: null,
45773
- default: proj4$1
45774
- }, Symbol.toStringTag, { value: "Module" }));
45775
45771
  let registered$1 = null;
45776
45772
  function register$3(proj42) {
45777
45773
  registered$1 = proj42;
@@ -464555,12 +464551,13 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464555
464551
  return feature2;
464556
464552
  }
464557
464553
  setupEPSG4490() {
464558
- (void 0)("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs +type=crs");
464559
- register$3(proj4$2);
464554
+ proj4$1.defs("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs +type=crs");
464555
+ register$3(proj4$1);
464560
464556
  console.log("EPSG:4490投影已注册");
464561
464557
  }
464562
464558
  async createLayer() {
464563
464559
  var _a3;
464560
+ debugger;
464564
464561
  const projection2 = this.resolveProjection();
464565
464562
  const config = this.config;
464566
464563
  const sourceOptions = config.autoFetchMetadata === true ? await this.buildSourceOptionsWithMetadata(projection2) : await this.buildSourceOptions(projection2);
@@ -464571,19 +464568,12 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464571
464568
  opacity: config.opacity
464572
464569
  });
464573
464570
  const source = new TileSuperMapRest(sourceOptions);
464574
- source.on("tileloadstart", () => {
464575
- console.log(`🔄 SuperMap图层 ${config.name} 开始加载瓦片`);
464576
- });
464577
- source.on("tileloadend", () => {
464578
- console.log(`✅ SuperMap图层 ${config.name} 瓦片加载完成`);
464579
- });
464580
464571
  source.on("tileloaderror", (event) => {
464581
464572
  var _a4, _b3;
464582
464573
  const img = (_b3 = (_a4 = event == null ? void 0 : event.tile) == null ? void 0 : _a4.getImage) == null ? void 0 : _b3.call(_a4);
464583
464574
  const src2 = img == null ? void 0 : img.src;
464584
- console.error(`❌ SuperMap图层 ${config.name} 瓦片加载失败:`, event);
464585
464575
  if (src2)
464586
- console.error(`失败瓦片URL: ${src2}`);
464576
+ console.error(`瓦片加载失败: ${src2}`);
464587
464577
  });
464588
464578
  const tileLayer = new TileLayer$2({
464589
464579
  source,
@@ -464592,6 +464582,10 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464592
464582
  // opacity: (config.opacity || 100) / 100,
464593
464583
  });
464594
464584
  this.layer = tileLayer;
464585
+ if (config.autoFetchMetadata === true) {
464586
+ this.fetchAndUpdateTileGrid(source).catch(() => {
464587
+ });
464588
+ }
464595
464589
  console.log(`SuperMap图层 ${config.name} 创建完成:`, {
464596
464590
  visible: tileLayer.getVisible(),
464597
464591
  opacity: tileLayer.getOpacity(),
@@ -464610,23 +464604,17 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464610
464604
  extent: mapExtent,
464611
464605
  projection: mapView.getProjection().getCode()
464612
464606
  });
464613
- if (config.center && config.center.length >= 2) {
464614
- const layerCenter = config.center;
464615
- const isInView = layerCenter[0] >= mapExtent[0] && layerCenter[0] <= mapExtent[2] && layerCenter[1] >= mapExtent[1] && layerCenter[1] <= mapExtent[3];
464616
- console.log(
464617
- `图层中心点 [${layerCenter[0]}, ${layerCenter[1]}] 是否在当前视图内: ${isInView}`
464618
- );
464619
- if (!isInView) {
464620
- console.warn(
464621
- `⚠️ 图层 ${config.name} 的中心点不在当前地图视图范围内,可能需要缩放到图层位置`
464622
- );
464623
- }
464607
+ if (this.map && config.center && config.center.length >= 2) {
464608
+ this.map.getView().setCenter(config.center);
464624
464609
  }
464625
464610
  }
464626
464611
  tileLayer.on("postrender", () => this.tryApplyStyles());
464627
464612
  source.on("tileloadend", () => this.tryApplyStyles());
464628
464613
  return tileLayer;
464629
464614
  }
464615
+ applyFilters() {
464616
+ console.warn("TileSuperMapRestHandler a ");
464617
+ }
464630
464618
  tryApplyStyles() {
464631
464619
  if (this.styleApplied || this.styleApplyAttempts >= this.maxStyleApplyAttempts)
464632
464620
  return;
@@ -464659,18 +464647,20 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464659
464647
  }
464660
464648
  }
464661
464649
  resolveProjection() {
464662
- var _a3;
464650
+ var _a3, _b3;
464663
464651
  let projection2 = null;
464664
- if (this.config.projection) {
464665
- projection2 = get$b(this.config.projection);
464666
- if (!projection2 && this.config.projection === "EPSG:4490") {
464652
+ const projectionCode = this.config.projection;
464653
+ if (projectionCode) {
464654
+ projection2 = get$b(projectionCode);
464655
+ if (!projection2 && projectionCode === "EPSG:4490") {
464667
464656
  this.setupEPSG4490();
464668
464657
  projection2 = get$b("EPSG:4490");
464669
464658
  }
464670
464659
  }
464671
464660
  if (!projection2) {
464672
- projection2 = ((_a3 = this.map) == null ? void 0 : _a3.getView().getProjection()) || get$b("EPSG:4326");
464673
- console.log(`使用投影: ${projection2.getCode()}`);
464661
+ projection2 = ((_a3 = this.map) == null ? void 0 : _a3.getView().getProjection()) || get$b("EPSG:3857");
464662
+ const code = ((_b3 = projection2 == null ? void 0 : projection2.getCode) == null ? void 0 : _b3.call(projection2)) || "EPSG:3857";
464663
+ console.log(`图层 '${this.config.name}' 未指定投影,回退到: ${code}`);
464674
464664
  }
464675
464665
  return projection2;
464676
464666
  }
@@ -464678,14 +464668,11 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464678
464668
  const config = this.config;
464679
464669
  const sourceOptions = {
464680
464670
  url: config.url,
464681
- wrapX: config.wrapX ?? true,
464682
- format: config.format || "webp",
464671
+ wrapX: config.wrapX ?? false,
464672
+ format: config.format || "png",
464683
464673
  transparent: config.transparent ?? true,
464684
464674
  crossOrigin: config.crossOrigin || "anonymous"
464685
464675
  };
464686
- const tileGrid = await this.createTileGrid(projection2.getCode(), config);
464687
- if (tileGrid)
464688
- sourceOptions.tileGrid = tileGrid;
464689
464676
  if (config.serverType)
464690
464677
  sourceOptions.serverType = config.serverType;
464691
464678
  if (config.cacheEnabled !== void 0)
@@ -464696,55 +464683,51 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464696
464683
  const config = this.config;
464697
464684
  const sourceOptions = {
464698
464685
  url: config.url,
464699
- wrapX: true,
464686
+ wrapX: false,
464700
464687
  format: config.format || "webp",
464701
464688
  crossOrigin: config.crossOrigin || "anonymous",
464702
464689
  transparent: config.transparent ?? true,
464703
464690
  cacheEnabled: config.cacheEnabled ?? true
464704
464691
  };
464705
- try {
464706
- let mapJsonUrl = config.url;
464707
- if (mapJsonUrl.includes("/rest/maps/")) {
464708
- const match2 = mapJsonUrl.match(/(.*\/rest\/maps\/[^/]+)/);
464709
- if (match2 && match2.length > 1) {
464710
- mapJsonUrl = match2[1] + ".json";
464711
- } else {
464712
- console.warn("无法从URL中提取map.json路径,跳过元数据获取");
464713
- return sourceOptions;
464714
- }
464692
+ let mapJsonUrl = config.url;
464693
+ let canFetchMetadata = false;
464694
+ if (mapJsonUrl.includes("/rest/maps/")) {
464695
+ const match2 = mapJsonUrl.match(/(.*\/rest\/maps\/[^/]+)/);
464696
+ if (match2 && match2.length > 1) {
464697
+ mapJsonUrl = match2[1] + ".json";
464698
+ canFetchMetadata = true;
464715
464699
  }
464716
- console.log(`正在获取SuperMap服务元数据: ${mapJsonUrl}`);
464717
- console.log(`原始URL: ${config.url}`);
464718
- const response = await fetch(mapJsonUrl);
464719
- if (response.ok) {
464720
- const mapJson = await response.json();
464721
- console.log("获取到的map.json数据:", mapJson);
464722
- const options = TileSuperMapRest.optionsFromMapJSON(config.url, mapJson);
464723
- if (options == null ? void 0 : options.tileGrid) {
464724
- sourceOptions.tileGrid = options.tileGrid;
464725
- if (options.extent)
464726
- sourceOptions.extent = options.extent;
464727
- console.log("✅ 使用 optionsFromMapJSON 构建 tileGrid");
464728
- } else {
464729
- console.warn("map.json 未提供有效 tileGrid,回退到默认配置");
464730
- const tileGrid = await this.createTileGrid(projection2.getCode(), config);
464731
- if (tileGrid)
464732
- sourceOptions.tileGrid = tileGrid;
464700
+ }
464701
+ if (canFetchMetadata) {
464702
+ try {
464703
+ console.log(`正在获取SuperMap服务元数据: ${mapJsonUrl}`);
464704
+ const response = await fetch(mapJsonUrl);
464705
+ if (response.ok) {
464706
+ const mapJson = await response.json();
464707
+ console.log("获取到的map.json数据:", mapJson);
464708
+ const options = TileSuperMapRest.optionsFromMapJSON(
464709
+ config.url,
464710
+ mapJson
464711
+ );
464712
+ if (options == null ? void 0 : options.tileGrid) {
464713
+ sourceOptions.tileGrid = options.tileGrid;
464714
+ if (options.extent)
464715
+ sourceOptions.extent = options.extent;
464716
+ console.log("✅ 使用 optionsFromMapJSON 构建 tileGrid 成功");
464717
+ } else {
464718
+ console.warn("map.json 未提供有效 tileGrid,将回退到手动创建");
464719
+ }
464733
464720
  }
464734
- } else {
464735
- console.warn(`无法获取map.json (${response.status}), 使用默认配置`);
464736
- const tileGrid = await this.createTileGrid(
464737
- projection2.getCode(),
464738
- config
464739
- );
464740
- if (tileGrid)
464741
- sourceOptions.tileGrid = tileGrid;
464721
+ } catch (error2) {
464722
+ console.error("获取或解析map.json时出错,将回退到手动创建:", error2);
464742
464723
  }
464743
- } catch (error2) {
464744
- console.error("获取map.json时出错:", error2);
464724
+ }
464725
+ if (!sourceOptions.tileGrid) {
464726
+ console.warn("未能从元数据创建tileGrid,执行手动创建作为备用方案");
464745
464727
  const tileGrid = await this.createTileGrid(projection2.getCode(), config);
464746
- if (tileGrid)
464728
+ if (tileGrid) {
464747
464729
  sourceOptions.tileGrid = tileGrid;
464730
+ }
464748
464731
  }
464749
464732
  if (config.serverType)
464750
464733
  sourceOptions.serverType = config.serverType;
@@ -464819,6 +464802,30 @@ class TileSuperMapRestHandler extends BaseLayer$2 {
464819
464802
  (_a3 = source.setExtent) == null ? void 0 : _a3.call(source, options.extent);
464820
464803
  }
464821
464804
  source.changed();
464805
+ if (this.map) {
464806
+ const view = this.map.getView();
464807
+ const resolutions = options.tileGrid.getResolutions();
464808
+ if (view && resolutions && resolutions.length) {
464809
+ const currentRes = view.getResolution();
464810
+ if (typeof currentRes === "number") {
464811
+ let nearest = resolutions[0];
464812
+ let minDiff = Math.abs(currentRes - nearest);
464813
+ for (let i = 1; i < resolutions.length; i++) {
464814
+ const diff = Math.abs(currentRes - resolutions[i]);
464815
+ if (diff < minDiff) {
464816
+ minDiff = diff;
464817
+ nearest = resolutions[i];
464818
+ }
464819
+ }
464820
+ view.setResolution(nearest);
464821
+ } else {
464822
+ const zoom = view.getZoom();
464823
+ if (typeof zoom === "number") {
464824
+ view.setZoom(Math.round(zoom));
464825
+ }
464826
+ }
464827
+ }
464828
+ }
464822
464829
  } else {
464823
464830
  console.warn("从map.json中未能获取到有效的tileGrid配置");
464824
464831
  }
@@ -491455,7 +491462,7 @@ function(t3) {
491455
491462
  */
491456
491463
  function(t3) {
491457
491464
  function e8() {
491458
- return (n.canvg ? Promise.resolve(n.canvg) : import("./index.es-09c58559.mjs")).catch(function(t4) {
491465
+ return (n.canvg ? Promise.resolve(n.canvg) : import("./index.es-60380a58.mjs")).catch(function(t4) {
491459
491466
  return Promise.reject(new Error("Could not load canvg: " + t4));
491460
491467
  }).then(function(t4) {
491461
491468
  return t4.default ? t4.default : t4;
@@ -1,4 +1,4 @@
1
- import { c as commonjsGlobal, R as RGBColor, r as requestAnimationFrame, _ as _asyncToGenerator, a as _, p as processCanvasRGBA, b as _defineProperty } from "./index-b61cd0bb.mjs";
1
+ import { c as commonjsGlobal, R as RGBColor, r as requestAnimationFrame, _ as _asyncToGenerator, a as _, p as processCanvasRGBA, b as _defineProperty } from "./index-5d51e04b.mjs";
2
2
  import "vue";
3
3
  import "ol";
4
4
  var check = function(it) {
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A, B, e, d, D, a2, a3, w, z, a7, a6, I, H, Z, $, L, J, K, a4, j, M, a0, a1, X, Y, U, W, Q, S, P, C, F, G, N, O, a8, f, T, E, V, y, k, q, u, g, m, h, x, s, n, o, a5, i, t, l, v } from "./index-b61cd0bb.mjs";
1
+ import { A, B, e, d, D, a2, a3, w, z, a7, a6, I, H, Z, $, L, J, K, a4, j, M, a0, a1, X, Y, U, W, Q, S, P, C, F, G, N, O, a8, f, T, E, V, y, k, q, u, g, m, h, x, s, n, o, a5, i, t, l, v } from "./index-5d51e04b.mjs";
2
2
  import "vue";
3
3
  import "ol";
4
4
  export {
package/lib/index.umd.js CHANGED
@@ -41707,7 +41707,7 @@ var __publicField = (obj, key, value) => {
41707
41707
  item
41708
41708
  );
41709
41709
  }
41710
- function proj4$3(fromProjOrToProj, toProjOrCoord, coord) {
41710
+ function proj4$2(fromProjOrToProj, toProjOrCoord, coord) {
41711
41711
  var fromProj;
41712
41712
  var toProj;
41713
41713
  var single = false;
@@ -45707,7 +45707,7 @@ var __publicField = (obj, key, value) => {
45707
45707
  proj42.Proj.projections.add(eqearth$1);
45708
45708
  proj42.Proj.projections.add(bonne$1);
45709
45709
  }
45710
- const proj4$1 = Object.assign(proj4$3, {
45710
+ const proj4$1 = Object.assign(proj4$2, {
45711
45711
  defaultDatum: "WGS84",
45712
45712
  Proj: Projection$3,
45713
45713
  WGS84: new Projection$3("WGS84"),
@@ -45720,10 +45720,6 @@ var __publicField = (obj, key, value) => {
45720
45720
  version: "__VERSION__"
45721
45721
  });
45722
45722
  includedProjections$1(proj4$1);
45723
- const proj4$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
45724
- __proto__: null,
45725
- default: proj4$1
45726
- }, Symbol.toStringTag, { value: "Module" }));
45727
45723
  let registered$1 = null;
45728
45724
  function register$3(proj42) {
45729
45725
  registered$1 = proj42;
@@ -465331,12 +465327,13 @@ ${this.attributes_.map(
465331
465327
  return feature2;
465332
465328
  }
465333
465329
  setupEPSG4490() {
465334
- (void 0)("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs +type=crs");
465335
- register$3(proj4$2);
465330
+ proj4$1.defs("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs +type=crs");
465331
+ register$3(proj4$1);
465336
465332
  console.log("EPSG:4490投影已注册");
465337
465333
  }
465338
465334
  async createLayer() {
465339
465335
  var _a3;
465336
+ debugger;
465340
465337
  const projection2 = this.resolveProjection();
465341
465338
  const config = this.config;
465342
465339
  const sourceOptions = config.autoFetchMetadata === true ? await this.buildSourceOptionsWithMetadata(projection2) : await this.buildSourceOptions(projection2);
@@ -465347,19 +465344,12 @@ ${this.attributes_.map(
465347
465344
  opacity: config.opacity
465348
465345
  });
465349
465346
  const source = new TileSuperMapRest(sourceOptions);
465350
- source.on("tileloadstart", () => {
465351
- console.log(`🔄 SuperMap图层 ${config.name} 开始加载瓦片`);
465352
- });
465353
- source.on("tileloadend", () => {
465354
- console.log(`✅ SuperMap图层 ${config.name} 瓦片加载完成`);
465355
- });
465356
465347
  source.on("tileloaderror", (event) => {
465357
465348
  var _a4, _b3;
465358
465349
  const img = (_b3 = (_a4 = event == null ? void 0 : event.tile) == null ? void 0 : _a4.getImage) == null ? void 0 : _b3.call(_a4);
465359
465350
  const src2 = img == null ? void 0 : img.src;
465360
- console.error(`❌ SuperMap图层 ${config.name} 瓦片加载失败:`, event);
465361
465351
  if (src2)
465362
- console.error(`失败瓦片URL: ${src2}`);
465352
+ console.error(`瓦片加载失败: ${src2}`);
465363
465353
  });
465364
465354
  const tileLayer = new TileLayer$2({
465365
465355
  source,
@@ -465368,6 +465358,10 @@ ${this.attributes_.map(
465368
465358
  // opacity: (config.opacity || 100) / 100,
465369
465359
  });
465370
465360
  this.layer = tileLayer;
465361
+ if (config.autoFetchMetadata === true) {
465362
+ this.fetchAndUpdateTileGrid(source).catch(() => {
465363
+ });
465364
+ }
465371
465365
  console.log(`SuperMap图层 ${config.name} 创建完成:`, {
465372
465366
  visible: tileLayer.getVisible(),
465373
465367
  opacity: tileLayer.getOpacity(),
@@ -465386,23 +465380,17 @@ ${this.attributes_.map(
465386
465380
  extent: mapExtent,
465387
465381
  projection: mapView.getProjection().getCode()
465388
465382
  });
465389
- if (config.center && config.center.length >= 2) {
465390
- const layerCenter = config.center;
465391
- const isInView = layerCenter[0] >= mapExtent[0] && layerCenter[0] <= mapExtent[2] && layerCenter[1] >= mapExtent[1] && layerCenter[1] <= mapExtent[3];
465392
- console.log(
465393
- `图层中心点 [${layerCenter[0]}, ${layerCenter[1]}] 是否在当前视图内: ${isInView}`
465394
- );
465395
- if (!isInView) {
465396
- console.warn(
465397
- `⚠️ 图层 ${config.name} 的中心点不在当前地图视图范围内,可能需要缩放到图层位置`
465398
- );
465399
- }
465383
+ if (this.map && config.center && config.center.length >= 2) {
465384
+ this.map.getView().setCenter(config.center);
465400
465385
  }
465401
465386
  }
465402
465387
  tileLayer.on("postrender", () => this.tryApplyStyles());
465403
465388
  source.on("tileloadend", () => this.tryApplyStyles());
465404
465389
  return tileLayer;
465405
465390
  }
465391
+ applyFilters() {
465392
+ console.warn("TileSuperMapRestHandler a ");
465393
+ }
465406
465394
  tryApplyStyles() {
465407
465395
  if (this.styleApplied || this.styleApplyAttempts >= this.maxStyleApplyAttempts)
465408
465396
  return;
@@ -465435,18 +465423,20 @@ ${this.attributes_.map(
465435
465423
  }
465436
465424
  }
465437
465425
  resolveProjection() {
465438
- var _a3;
465426
+ var _a3, _b3;
465439
465427
  let projection2 = null;
465440
- if (this.config.projection) {
465441
- projection2 = get$c(this.config.projection);
465442
- if (!projection2 && this.config.projection === "EPSG:4490") {
465428
+ const projectionCode = this.config.projection;
465429
+ if (projectionCode) {
465430
+ projection2 = get$c(projectionCode);
465431
+ if (!projection2 && projectionCode === "EPSG:4490") {
465443
465432
  this.setupEPSG4490();
465444
465433
  projection2 = get$c("EPSG:4490");
465445
465434
  }
465446
465435
  }
465447
465436
  if (!projection2) {
465448
- projection2 = ((_a3 = this.map) == null ? void 0 : _a3.getView().getProjection()) || get$c("EPSG:4326");
465449
- console.log(`使用投影: ${projection2.getCode()}`);
465437
+ projection2 = ((_a3 = this.map) == null ? void 0 : _a3.getView().getProjection()) || get$c("EPSG:3857");
465438
+ const code = ((_b3 = projection2 == null ? void 0 : projection2.getCode) == null ? void 0 : _b3.call(projection2)) || "EPSG:3857";
465439
+ console.log(`图层 '${this.config.name}' 未指定投影,回退到: ${code}`);
465450
465440
  }
465451
465441
  return projection2;
465452
465442
  }
@@ -465454,14 +465444,11 @@ ${this.attributes_.map(
465454
465444
  const config = this.config;
465455
465445
  const sourceOptions = {
465456
465446
  url: config.url,
465457
- wrapX: config.wrapX ?? true,
465458
- format: config.format || "webp",
465447
+ wrapX: config.wrapX ?? false,
465448
+ format: config.format || "png",
465459
465449
  transparent: config.transparent ?? true,
465460
465450
  crossOrigin: config.crossOrigin || "anonymous"
465461
465451
  };
465462
- const tileGrid = await this.createTileGrid(projection2.getCode(), config);
465463
- if (tileGrid)
465464
- sourceOptions.tileGrid = tileGrid;
465465
465452
  if (config.serverType)
465466
465453
  sourceOptions.serverType = config.serverType;
465467
465454
  if (config.cacheEnabled !== void 0)
@@ -465472,55 +465459,51 @@ ${this.attributes_.map(
465472
465459
  const config = this.config;
465473
465460
  const sourceOptions = {
465474
465461
  url: config.url,
465475
- wrapX: true,
465462
+ wrapX: false,
465476
465463
  format: config.format || "webp",
465477
465464
  crossOrigin: config.crossOrigin || "anonymous",
465478
465465
  transparent: config.transparent ?? true,
465479
465466
  cacheEnabled: config.cacheEnabled ?? true
465480
465467
  };
465481
- try {
465482
- let mapJsonUrl = config.url;
465483
- if (mapJsonUrl.includes("/rest/maps/")) {
465484
- const match2 = mapJsonUrl.match(/(.*\/rest\/maps\/[^/]+)/);
465485
- if (match2 && match2.length > 1) {
465486
- mapJsonUrl = match2[1] + ".json";
465487
- } else {
465488
- console.warn("无法从URL中提取map.json路径,跳过元数据获取");
465489
- return sourceOptions;
465490
- }
465468
+ let mapJsonUrl = config.url;
465469
+ let canFetchMetadata = false;
465470
+ if (mapJsonUrl.includes("/rest/maps/")) {
465471
+ const match2 = mapJsonUrl.match(/(.*\/rest\/maps\/[^/]+)/);
465472
+ if (match2 && match2.length > 1) {
465473
+ mapJsonUrl = match2[1] + ".json";
465474
+ canFetchMetadata = true;
465491
465475
  }
465492
- console.log(`正在获取SuperMap服务元数据: ${mapJsonUrl}`);
465493
- console.log(`原始URL: ${config.url}`);
465494
- const response = await fetch(mapJsonUrl);
465495
- if (response.ok) {
465496
- const mapJson = await response.json();
465497
- console.log("获取到的map.json数据:", mapJson);
465498
- const options = TileSuperMapRest.optionsFromMapJSON(config.url, mapJson);
465499
- if (options == null ? void 0 : options.tileGrid) {
465500
- sourceOptions.tileGrid = options.tileGrid;
465501
- if (options.extent)
465502
- sourceOptions.extent = options.extent;
465503
- console.log("✅ 使用 optionsFromMapJSON 构建 tileGrid");
465504
- } else {
465505
- console.warn("map.json 未提供有效 tileGrid,回退到默认配置");
465506
- const tileGrid = await this.createTileGrid(projection2.getCode(), config);
465507
- if (tileGrid)
465508
- sourceOptions.tileGrid = tileGrid;
465476
+ }
465477
+ if (canFetchMetadata) {
465478
+ try {
465479
+ console.log(`正在获取SuperMap服务元数据: ${mapJsonUrl}`);
465480
+ const response = await fetch(mapJsonUrl);
465481
+ if (response.ok) {
465482
+ const mapJson = await response.json();
465483
+ console.log("获取到的map.json数据:", mapJson);
465484
+ const options = TileSuperMapRest.optionsFromMapJSON(
465485
+ config.url,
465486
+ mapJson
465487
+ );
465488
+ if (options == null ? void 0 : options.tileGrid) {
465489
+ sourceOptions.tileGrid = options.tileGrid;
465490
+ if (options.extent)
465491
+ sourceOptions.extent = options.extent;
465492
+ console.log("✅ 使用 optionsFromMapJSON 构建 tileGrid 成功");
465493
+ } else {
465494
+ console.warn("map.json 未提供有效 tileGrid,将回退到手动创建");
465495
+ }
465509
465496
  }
465510
- } else {
465511
- console.warn(`无法获取map.json (${response.status}), 使用默认配置`);
465512
- const tileGrid = await this.createTileGrid(
465513
- projection2.getCode(),
465514
- config
465515
- );
465516
- if (tileGrid)
465517
- sourceOptions.tileGrid = tileGrid;
465497
+ } catch (error2) {
465498
+ console.error("获取或解析map.json时出错,将回退到手动创建:", error2);
465518
465499
  }
465519
- } catch (error2) {
465520
- console.error("获取map.json时出错:", error2);
465500
+ }
465501
+ if (!sourceOptions.tileGrid) {
465502
+ console.warn("未能从元数据创建tileGrid,执行手动创建作为备用方案");
465521
465503
  const tileGrid = await this.createTileGrid(projection2.getCode(), config);
465522
- if (tileGrid)
465504
+ if (tileGrid) {
465523
465505
  sourceOptions.tileGrid = tileGrid;
465506
+ }
465524
465507
  }
465525
465508
  if (config.serverType)
465526
465509
  sourceOptions.serverType = config.serverType;
@@ -465595,6 +465578,30 @@ ${this.attributes_.map(
465595
465578
  (_a3 = source.setExtent) == null ? void 0 : _a3.call(source, options.extent);
465596
465579
  }
465597
465580
  source.changed();
465581
+ if (this.map) {
465582
+ const view = this.map.getView();
465583
+ const resolutions = options.tileGrid.getResolutions();
465584
+ if (view && resolutions && resolutions.length) {
465585
+ const currentRes = view.getResolution();
465586
+ if (typeof currentRes === "number") {
465587
+ let nearest = resolutions[0];
465588
+ let minDiff = Math.abs(currentRes - nearest);
465589
+ for (let i2 = 1; i2 < resolutions.length; i2++) {
465590
+ const diff = Math.abs(currentRes - resolutions[i2]);
465591
+ if (diff < minDiff) {
465592
+ minDiff = diff;
465593
+ nearest = resolutions[i2];
465594
+ }
465595
+ }
465596
+ view.setResolution(nearest);
465597
+ } else {
465598
+ const zoom = view.getZoom();
465599
+ if (typeof zoom === "number") {
465600
+ view.setZoom(Math.round(zoom));
465601
+ }
465602
+ }
465603
+ }
465604
+ }
465598
465605
  } else {
465599
465606
  console.warn("从map.json中未能获取到有效的tileGrid配置");
465600
465607
  }