| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent de1eead commit 9a0a0fb
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,16 +26,16 @@ export function createMapClassExtending(SuperClass = class {}) { | |||
| 26 | 26 | return this._legendList; | |
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | - getSelfAppreciableLayers(appreciableLayers) { | ||
| 30 | - return (this._sourceListModel && this._sourceListModel.getSelfLayers(appreciableLayers)) || []; | ||
| 29 | + getSelfAppreciableLayers() { | ||
| 30 | + return (this._sourceListModel && this._sourceListModel.getSelfLayers(...arguments)) || []; | ||
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | - setLayersVisible(layers, visibility) { | ||
| 34 | - this._sourceListModel && this._sourceListModel.setLayersVisible(layers, visibility); | ||
| 33 | + setLayersVisible() { | ||
| 34 | + this._sourceListModel && this._sourceListModel.setLayersVisible(...arguments); | ||
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | - toggleLayerVisible(layerId, visible) { | ||
| 38 | - this._sourceListModel && this._sourceListModel.toggleLayerVisible(layerId, visible); | ||
| 37 | + toggleLayerVisible() { | ||
| 38 | + this._sourceListModel && this._sourceListModel.toggleLayerVisible(...arguments); | ||
| 39 | 39 | } | |
| 40 | 40 | ||
| 41 | 41 | rectifyLayersOrder(appreciableLayers, topLayerBeforeId) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -392,23 +392,23 @@ | |||
| 392 | 392 | return (this._handler && this._handler.getLayerCatalog()) || []; | |
| 393 | 393 | } | |
| 394 | 394 | ||
| 395 | - setLayersVisible(layers, visibility) { | ||
| 396 | - this._handler && this._handler.setLayersVisible(layers, visibility); | ||
| 395 | + setLayersVisible() { | ||
| 396 | + this._handler && this._handler.setLayersVisible(...arguments); | ||
| 397 | 397 | } | |
| 398 | 398 | ||
| 399 | 399 | /** | |
| 400 | 400 | * @version 11.2.1 | |
| 401 | 401 | * @function WebMapBase.prototype.toggleLayerVisible | |
| 402 | - * @param {string} layerId - 图层 id。 | ||
| 402 | + * @param {string} layer - 图层信息。 | ||
| 403 | 403 | * @param {boolean} visible - 图层是否可见。true 表示显示,false 表示隐藏。 | |
| 404 | 404 | * @description 设置图层显隐。 | |
| 405 | 405 | */ | |
| 406 | - toggleLayerVisible(layerId, visible) { | ||
| 407 | - this._handler && this._handler.toggleLayerVisible(layerId, visible); | ||
| 406 | + toggleLayerVisible() { | ||
| 407 | + this._handler && this._handler.toggleLayerVisible(...arguments); | ||
| 408 | 408 | } | |
| 409 | 409 | ||
| 410 | 410 | /** | |
| 411 | - * @version 11.3.0 | ||
| 411 | + * @version 11.2.1 | ||
| 412 | 412 | * @function WebMapBase.prototype.getWebMapType | |
| 413 | 413 | * @description 获取地图类型。 | |
| 414 | 414 | * @returns {String} 地图类型。 | |
@@ -418,12 +418,14 @@ | |||
| 418 | 418 | } | |
| 419 | 419 | ||
| 420 | 420 | /** | |
| 421 | - * @version 11.3.0 | ||
| 421 | + * @version 11.2.1 | ||
| 422 | 422 | * @function WebMapBase.prototype.rectifyLayersOrder | |
| 423 | + * @param {Array} layers - 图层列表。 | ||
| 424 | + * @param {string} topLayerBeforeId - 图层列表中置顶图层指定的 beforeId。 | ||
| 423 | 425 | * @description 根据已知顺序的可感知图层,对地图上图顺序进行排序。 | |
| 424 | 426 | */ | |
| 425 | - rectifyLayersOrder(appreciableLayers, topLayerBeforeId) { | ||
| 426 | - this._handler && this._handler.rectifyLayersOrder(appreciableLayers, topLayerBeforeId); | ||
| 427 | + rectifyLayersOrder() { | ||
| 428 | + this._handler && this._handler.rectifyLayersOrder(...arguments); | ||
| 427 | 429 | } | |
| 428 | 430 | ||
| 429 | 431 | /** | |
@@ -436,8 +438,8 @@ | |||
| 436 | 438 | * @param {Array} features - 要素信息。 | |
| 437 | 439 | * @param {string} mergeByField - 属性关联字段。 | |
| 438 | 440 | */ | |
| 439 | - updateOverlayLayer(layerInfo, features, mergeByField) { | ||
| 440 | - this._handler && this._handler.updateOverlayLayer(layerInfo, features, mergeByField); | ||
| 441 | + updateOverlayLayer() { | ||
| 442 | + this._handler && this._handler.updateOverlayLayer(...arguments); | ||
| 441 | 443 | } | |
| 442 | 444 | ||
| 443 | 445 | /** | |
@@ -448,8 +450,8 @@ | |||
| 448 | 450 | * @param {Object} [layerInfo] - 复制图层信息。如 id、source、layout | |
| 449 | 451 | * @returns {Array} 复制成功的信图层信息。 | |
| 450 | 452 | */ | |
| 451 | - copyLayer(id, layerInfo) { | ||
| 452 | - return this._handler && this._handler.copyLayer(id, layerInfo); | ||
| 453 | + copyLayer() { | ||
| 454 | + return this._handler && this._handler.copyLayer(...arguments); | ||
| 453 | 455 | } | |
| 454 | 456 | ||
| 455 | 457 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -337,7 +337,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 337 | 337 | } | |
| 338 | 338 | style.layers.forEach(layer => { | |
| 339 | 339 | layer.layout && (layer.layout.visibility = this._getVisibility(layerInfo.visible)); | |
| 340 | - }) | ||
| 340 | + }); | ||
| 341 | 341 | this.map.addStyle(style); | |
| 342 | 342 | const layerIds = []; | |
| 343 | 343 | style.layers.forEach((item) => { | |
@@ -2394,11 +2394,16 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 2394 | 2394 | if (bounds) { | |
| 2395 | 2395 | source.bounds = bounds; | |
| 2396 | 2396 | } | |
| 2397 | + let sourceId = source; | ||
| 2398 | + if (this.map.getSource(layerID) && (!this.map.getLayer(layerID) || !this.checkSameLayer || !this._isSameRasterLayer(layerID, source))) { | ||
| 2399 | + sourceId = `${layerID}_${+new Date()}`; | ||
| 2400 | + this.map.addSource(sourceId, source); | ||
| 2401 | + } | ||
| 2397 | 2402 | this._addLayer( | |
| 2398 | 2403 | { | |
| 2399 | 2404 | id: layerID, | |
| 2400 | 2405 | type: 'raster', | |
| 2401 | - source: source, | ||
| 2406 | + source: sourceId, | ||
| 2402 | 2407 | minzoom: minzoom || 0, | |
| 2403 | 2408 | maxzoom: maxzoom || 22, | |
| 2404 | 2409 | layout: { | |
@@ -2740,7 +2745,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 2740 | 2745 | _addLayer(layerInfo, parentLayerId = layerInfo.id, beforeId) { | |
| 2741 | 2746 | const { id } = layerInfo; | |
| 2742 | 2747 | if (this.map.getLayer(id)) { | |
| 2743 | - if (this.checkSameLayer && this._isSameRasterLayer(id, layerInfo)) { | ||
| 2748 | + if (this.checkSameLayer && this._isSameRasterLayer(id, layerInfo.source)) { | ||
| 2744 | 2749 | this._setCacheLayer({ layerInfo, parentLayerId, id, reused: true, beforeId }); | |
| 2745 | 2750 | return; | |
| 2746 | 2751 | } | |
@@ -2847,8 +2852,8 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 2847 | 2852 | }; | |
| 2848 | 2853 | } | |
| 2849 | 2854 | ||
| 2850 | - _isSameRasterLayer(id, layerInfo) { | ||
| 2851 | - return isSameRasterLayer(layerInfo.source, this.map.getSource(id)); | ||
| 2855 | + _isSameRasterLayer(sourceId, sourceInfo) { | ||
| 2856 | + return isSameRasterLayer(sourceInfo, this.map.getSource(sourceId)); | ||
| 2852 | 2857 | } | |
| 2853 | 2858 | ||
| 2854 | 2859 | _centerValid(center) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,17 +10,12 @@ export class AppreciableLayerBase extends Events { | |||
| 10 | 10 | this.appendLayers = options.appendLayers || false; | |
| 11 | 11 | this.unexpectedSourceNames = ['tdt-search-', 'tdt-route-', 'smmeasure', 'mapbox-gl-draw', 'maplibre-gl-draw', /tracklayer-\d+-line/]; | |
| 12 | 12 | this.layersVisibleMap = new Map(); | |
| 13 | - this.layerCatalogs = []; | ||
| 14 | - this.appreciableLayers = []; | ||
| 15 | 13 | this.eventTypes = ['layerupdatechanged']; | |
| 16 | 14 | this._styleDataUpdatedHandler = this._styleDataUpdatedHandler.bind(this); | |
| 17 | 15 | } | |
| 18 | 16 | ||
| 19 | 17 | setSelfLayers(layers) { | |
| 20 | 18 | this.layers = layers; | |
| 21 | - if (this.appreciableLayers.length > 0) { | ||
| 22 | - this._styleDataUpdatedHandler(); | ||
| 23 | - } | ||
| 24 | 19 | } | |
| 25 | 20 | ||
| 26 | 21 | createAppreciableLayers() { | |
@@ -36,11 +31,13 @@ export class AppreciableLayerBase extends Events { | |||
| 36 | 31 | } | |
| 37 | 32 | ||
| 38 | 33 | getLayerCatalog() { | |
| 39 | - return this.layerCatalogs; | ||
| 34 | + const layerCatalog = this.createLayerCatalogs(); | ||
| 35 | + this._updateLayerCatalogsVisible(layerCatalog); | ||
| 36 | + return layerCatalog; | ||
| 40 | 37 | } | |
| 41 | 38 | ||
| 42 | 39 | getLayers() { | |
| 43 | - return this.appreciableLayers; | ||
| 40 | + return this.createAppreciableLayers(); | ||
| 44 | 41 | } | |
| 45 | 42 | ||
| 46 | 43 | getSelfLayers(appreciableLayers = this.getLayers()) { | |
@@ -50,19 +47,15 @@ export class AppreciableLayerBase extends Events { | |||
| 50 | 47 | ); | |
| 51 | 48 | } | |
| 52 | 49 | ||
| 53 | - toggleLayerVisible(layerId, visible) { | ||
| 54 | - const item = this._findLayerCatalog(this.layerCatalogs, layerId); | ||
| 55 | - if (!item) { | ||
| 56 | - return; | ||
| 57 | - } | ||
| 50 | + toggleLayerVisible(layer, visible) { | ||
| 58 | 51 | const visibility = visible ? 'visible' : 'none'; | |
| 59 | - if (item.type === 'group') { | ||
| 60 | - const visbleId = this._getLayerVisibleId(item); | ||
| 52 | + if (layer.type === 'group') { | ||
| 53 | + const visbleId = this._getLayerVisibleId(layer); | ||
| 61 | 54 | this.layersVisibleMap.set(visbleId, visible); | |
| 62 | - const targetLayers = getLayerInfosFromCatalogs(item.children); | ||
| 55 | + const targetLayers = getLayerInfosFromCatalogs(layer.children); | ||
| 63 | 56 | this.setLayersVisible(targetLayers, visibility); | |
| 64 | 57 | } else { | |
| 65 | - this.setLayersVisible([item], visibility); | ||
| 58 | + this.setLayersVisible([layer], visibility); | ||
| 66 | 59 | } | |
| 67 | 60 | } | |
| 68 | 61 | ||
@@ -74,7 +67,7 @@ export class AppreciableLayerBase extends Events { | |||
| 74 | 67 | (layer.CLASS_INSTANCE && layer.CLASS_INSTANCE.show && layer.CLASS_INSTANCE.hide) | |
| 75 | 68 | ) { | |
| 76 | 69 | visibility === 'visible' ? layer.CLASS_INSTANCE.show() : layer.CLASS_INSTANCE.hide(); | |
| 77 | - this._styleDataUpdatedHandler(); | ||
| 70 | + this.map.style.fire('data', { dataType: 'style' }); | ||
| 78 | 71 | return; | |
| 79 | 72 | } | |
| 80 | 73 | layer.renderLayers.forEach((layerId) => { | |
@@ -98,7 +91,7 @@ export class AppreciableLayerBase extends Events { | |||
| 98 | 91 | if (!this.map) { | |
| 99 | 92 | return; | |
| 100 | 93 | } | |
| 101 | - this._initializeData(); | ||
| 94 | + this._styleDataUpdatedHandler(); | ||
| 102 | 95 | this._registerMapEvent(); | |
| 103 | 96 | } | |
| 104 | 97 | ||
@@ -122,20 +115,19 @@ export class AppreciableLayerBase extends Events { | |||
| 122 | 115 | } | |
| 123 | 116 | ||
| 124 | 117 | _initSourceList(detailLayers) { | |
| 125 | - const datas = detailLayers.reduce((sourceList, layer) => { | ||
| 118 | + const datas = detailLayers.slice().reverse().reduce((sourceList, layer) => { | ||
| 119 | + const id = layer.renderSource.sourceLayer ? `${layer.renderSource.id}-${+new Date()}` : layer.id; | ||
| 126 | 120 | let matchItem = sourceList.find((item) => { | |
| 127 | - const sourceId = layer.renderSource.id || layer.id; | ||
| 128 | - return item.id === sourceId; | ||
| 121 | + return item.id === id; | ||
| 129 | 122 | }); | |
| 130 | 123 | if (!matchItem) { | |
| 131 | - const sourceListItem = new SourceModel(layer); | ||
| 124 | + const sourceListItem = new SourceModel(layer, id); | ||
| 132 | 125 | sourceList.push(sourceListItem); | |
| 133 | 126 | matchItem = sourceListItem; | |
| 134 | 127 | } | |
| 135 | 128 | matchItem.addLayer(layer); | |
| 136 | 129 | return sourceList; | |
| 137 | 130 | }, []); | |
| 138 | - datas.reverse(); | ||
| 139 | 131 | return datas; | |
| 140 | 132 | } | |
| 141 | 133 | ||
@@ -278,23 +270,14 @@ export class AppreciableLayerBase extends Events { | |||
| 278 | 270 | } | |
| 279 | 271 | } | |
| 280 | 272 | ||
| 281 | - _initializeData() { | ||
| 282 | - this.appreciableLayers = this.createAppreciableLayers(); | ||
| 283 | - this.layerCatalogs = this.createLayerCatalogs(); | ||
| 284 | - this._updateLayerCatalogsVisible(this.layerCatalogs); | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | 273 | _registerMapEvent() { | |
| 288 | 274 | this.map.on('styledata', this._styleDataUpdatedHandler); | |
| 289 | 275 | } | |
| 290 | 276 | ||
| 291 | 277 | _styleDataUpdatedHandler() { | |
| 292 | - this._initializeData(); | ||
| 293 | - if (!this._appendLayers) { | ||
| 294 | - this.triggerEvent('layerupdatechanged', { | ||
| 295 | - layers: this.appreciableLayers, | ||
| 296 | - layerCatalog: this.layerCatalogs | ||
| 297 | - }); | ||
| 278 | + this.triggerEvent('layerupdatechanged', { | ||
| 279 | + layers: this.getLayers(), | ||
| 280 | + layerCatalog: this.getLayerCatalog() | ||
| 281 | + }); | ||
| 298 | 282 | } | |
| 299 | 283 | } | |
| 300 | - } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | class SourceModel { | |
| 2 | - constructor(options) { | ||
| 2 | + constructor(options, id) { | ||
| 3 | 3 | this.dataSource = options.dataSource; | |
| 4 | - this.id = options.renderSource.id || options.id; | ||
| 4 | + this.id = id; | ||
| 5 | 5 | this.title = options.title; | |
| 6 | 6 | this.renderSource = options.renderSource; | |
| 7 | 7 | this.renderLayers = []; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,7 +200,14 @@ describe('SourceListV2', () => { | |||
| 200 | 200 | if (this.overlayLayersManager[layerId]) { | |
| 201 | 201 | this.overlayLayersManager.visible = visibility === 'visible'; | |
| 202 | 202 | } | |
| 203 | - }) | ||
| 203 | + }), | ||
| 204 | + style: { | ||
| 205 | + fire(type, options) { | ||
| 206 | + if (type === 'data' && options.dataType === 'style' && mockEvents.styledata) { | ||
| 207 | + mockEvents.styledata(); | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + } | ||
| 204 | 211 | }; | |
| 205 | 212 | }); | |
| 206 | 213 | ||
@@ -440,7 +447,7 @@ describe('SourceListV2', () => { | |||
| 440 | 447 | const layerList = sourceListModel.getLayerCatalog(); | |
| 441 | 448 | expect(layerList.length).toBe(2); | |
| 442 | 449 | expect(layerList[0].children.length).toBe(2); | |
| 443 | - expect(layerList[0].children[1].renderLayers).toEqual(appreciableLayers[2].renderLayers); | ||
| 450 | + expect(layerList[0].children[0].renderLayers).toEqual(appreciableLayers[2].renderLayers); | ||
| 444 | 451 | expect(layerList[0].type).toBe('group'); | |
| 445 | 452 | done(); | |
| 446 | 453 | }); | |
@@ -528,7 +535,7 @@ describe('SourceListV2', () => { | |||
| 528 | 535 | done(); | |
| 529 | 536 | } | |
| 530 | 537 | }); | |
| 531 | - sourceListModel.toggleLayerVisible(layerList[1].id, false); | ||
| 538 | + sourceListModel.toggleLayerVisible(layerList[1], false); | ||
| 532 | 539 | expect(mockEvents.styledata).not.toBeUndefined(); | |
| 533 | 540 | mockEvents.styledata(); | |
| 534 | 541 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -202,7 +202,14 @@ describe('SourceListV3', () => { | |||
| 202 | 202 | if (this.overlayLayersManager[layerId]) { | |
| 203 | 203 | this.overlayLayersManager.visible = visibility === 'visible'; | |
| 204 | 204 | } | |
| 205 | - }) | ||
| 205 | + }), | ||
| 206 | + style: { | ||
| 207 | + fire(type, options) { | ||
| 208 | + if (type === 'data' && options.dataType === 'style' && mockEvents.styledata) { | ||
| 209 | + mockEvents.styledata(); | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + } | ||
| 206 | 213 | }; | |
| 207 | 214 | }); | |
| 208 | 215 | ||
@@ -311,7 +318,7 @@ describe('SourceListV3', () => { | |||
| 311 | 318 | done(); | |
| 312 | 319 | } | |
| 313 | 320 | }); | |
| 314 | - sourceListModel.toggleLayerVisible(layerList[3].id, false); | ||
| 321 | + sourceListModel.toggleLayerVisible(layerList[3], false); | ||
| 315 | 322 | }); | |
| 316 | 323 | ||
| 317 | 324 | it('toggleLayerVisible true', (done) => { | |
@@ -335,11 +342,11 @@ describe('SourceListV3', () => { | |||
| 335 | 342 | let layerList = sourceListModel.getLayerCatalog(); | |
| 336 | 343 | expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3); | |
| 337 | 344 | expect(layerList[3].visible).toBeTruthy(); | |
| 338 | - sourceListModel.toggleLayerVisible(layerList[3].id, false); | ||
| 345 | + sourceListModel.toggleLayerVisible(layerList[3], false); | ||
| 339 | 346 | layerList = sourceListModel.getLayerCatalog(); | |
| 340 | 347 | expect(layerList[3].visible).toBeFalsy(); | |
| 341 | 348 | expect(markerList[layerList[3].id].hide).toHaveBeenCalledTimes(1); | |
| 342 | - sourceListModel.toggleLayerVisible(layerList[3].id, true); | ||
| 349 | + sourceListModel.toggleLayerVisible(layerList[3], true); | ||
| 343 | 350 | layerList = sourceListModel.getLayerCatalog(); | |
| 344 | 351 | expect(layerList[3].visible).toBeTruthy(); | |
| 345 | 352 | expect(markerList[layerList[3].id].show).toHaveBeenCalledTimes(1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1251,7 +1251,7 @@ describe('mapboxgl_WebMap', () => { | |||
| 1251 | 1251 | expect(layers.length).toBe(2); | |
| 1252 | 1252 | expect(layers[0].id).toBe('China4269@DataSource'); | |
| 1253 | 1253 | expect(layers[0].visible).toBeTruthy(); | |
| 1254 | - datavizWebmap.toggleLayerVisible(layers[0].id, false); | ||
| 1254 | + datavizWebmap.toggleLayerVisible(layers[0], false); | ||
| 1255 | 1255 | layers = datavizWebmap.getLayers(); | |
| 1256 | 1256 | expect(layers[0].visible).toBeFalsy(); | |
| 1257 | 1257 | datavizWebmap.once('layerupdatechanged', () => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments