| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 87b07aa commit d7f342a
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -257,11 +257,19 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) { | |||
| 257 | 257 | * @function WebMapBase.prototype.setStyle | |
| 258 | 258 | * @description 更新地图样式。 | |
| 259 | 259 | * @param {Object} style - 地图 style 样式 | |
| 260 | + * @param {boolean} preserveMap - 保留地图实例,覆盖图层样式。 | ||
| 260 | 261 | */ | |
| 261 | - setStyle(style) { | ||
| 262 | + setStyle(style, preserveMap = false) { | ||
| 262 | 263 | if (this.map) { | |
| 263 | 264 | this.mapOptions.style = style; | |
| 264 | - this._initWebMap(); | ||
| 265 | + if (preserveMap) { | ||
| 266 | + this.cleanLayers(); | ||
| 267 | + } | ||
| 268 | + if (this._isWebMapV3(style)) { | ||
| 269 | + this.setMapId(style, preserveMap) | ||
| 270 | + return; | ||
| 271 | + } | ||
| 272 | + this._initWebMap(!preserveMap); | ||
| 265 | 273 | } | |
| 266 | 274 | } | |
| 267 | 275 | ||
@@ -454,7 +462,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) { | |||
| 454 | 462 | this._handler.clean(removeMap); | |
| 455 | 463 | this._handler = null; | |
| 456 | 464 | } | |
| 457 | - this.map = null; | ||
| 465 | + removeMap && (this.map = null); | ||
| 458 | 466 | if (this.mapOptions && (this.mapId || this.webMapInfo)) { | |
| 459 | 467 | this.mapOptions.center = null; | |
| 460 | 468 | this.mapOptions.zoom = null; | |
@@ -472,7 +480,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) { | |||
| 472 | 480 | if (!this.map) { | |
| 473 | 481 | return; | |
| 474 | 482 | } | |
| 475 | - const layersToClean = this._cacheCleanLayers.filter(item => !item.reused); | ||
| 483 | + const layersToClean = this._cacheCleanLayers.filter((item) => !item.reused); | ||
| 476 | 484 | this._handler && this._handler.cleanLayers(layersToClean); | |
| 477 | 485 | this._cacheCleanLayers = []; | |
| 478 | 486 | this.clean(false); | |
@@ -538,7 +546,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) { | |||
| 538 | 546 | this.webMapService.setProxy(proxy); | |
| 539 | 547 | } | |
| 540 | 548 | ||
| 541 | - setMapId(mapId) { | ||
| 549 | + setMapId(mapId, preserveMap = false) { | ||
| 542 | 550 | if (typeof mapId === 'string' || typeof mapId === 'number') { | |
| 543 | 551 | this.mapId = mapId; | |
| 544 | 552 | this.webMapInfo = null; | |
@@ -551,7 +559,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) { | |||
| 551 | 559 | return; | |
| 552 | 560 | } | |
| 553 | 561 | setTimeout(() => { | |
| 554 | - this._initWebMap(); | ||
| 562 | + this._initWebMap(!preserveMap); | ||
| 555 | 563 | }, 0); | |
| 556 | 564 | } | |
| 557 | 565 | ||
@@ -601,8 +609,19 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) { | |||
| 601 | 609 | this.fire('layeraddchanged', params); | |
| 602 | 610 | } | |
| 603 | 611 | ||
| 612 | + _isWebMapV3(styleInfo) { | ||
| 613 | + if (!styleInfo.version) { | ||
| 614 | + return false; | ||
| 615 | + } | ||
| 616 | + const subVersions = `${styleInfo.version}`.split('.') | ||
| 617 | + if (subVersions.length <= 1) { | ||
| 618 | + return false; | ||
| 619 | + } | ||
| 620 | + return +subVersions[0] >= 3; | ||
| 621 | + } | ||
| 622 | + | ||
| 604 | 623 | _getMapInfo(mapInfo) { | |
| 605 | - const type = +mapInfo.version.split('.')[0] >= 3 ? 'WebMap3' : 'WebMap2'; | ||
| 624 | + const type = this._isWebMapV3(mapInfo) ? 'WebMap3' : 'WebMap2'; | ||
| 606 | 625 | this._createMap(type, mapInfo); | |
| 607 | 626 | } | |
| 608 | 627 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments