| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dd7d869 commit 5851e54
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,25 @@ export function createMapClassExtending(SuperClass = class {}) { | |||
| 38 | 38 | this._sourceListModel && this._sourceListModel.toggleLayerVisible(layerId, visible); | |
| 39 | 39 | } | |
| 40 | 40 | ||
| 41 | + rectifyLayersOrder(appreciableLayers, topLayerBeforeId) { | ||
| 42 | + const renderLayers = appreciableLayers | ||
| 43 | + .filter((item) => !item.reused) | ||
| 44 | + .reduce((layers, layer) => { | ||
| 45 | + return layers.concat(layer.renderLayers); | ||
| 46 | + }, []); | ||
| 47 | + const exsitLayers = renderLayers.filter((layerId) => !!this.map.getLayer(layerId)); | ||
| 48 | + for (let index = exsitLayers.length - 1; index > -1; index--) { | ||
| 49 | + const targetlayerId = exsitLayers[index]; | ||
| 50 | + const afterLayers = exsitLayers.slice(index + 1); | ||
| 51 | + let beforLayerId = afterLayers.find((id) => this.map.style._layers[id]); | ||
| 52 | + if (!afterLayers.length) { | ||
| 53 | + beforLayerId = topLayerBeforeId; | ||
| 54 | + } | ||
| 55 | + this.map.moveLayer(targetlayerId, beforLayerId); | ||
| 56 | + } | ||
| 57 | + return exsitLayers; | ||
| 58 | + } | ||
| 59 | + | ||
| 41 | 60 | echartsLayerResize() {} | |
| 42 | 61 | ||
| 43 | 62 | updateOverlayLayer() {} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -416,6 +416,15 @@ | |||
| 416 | 416 | getWebMapType() { | |
| 417 | 417 | return this.type; | |
| 418 | 418 | } | |
| 419 | + | ||
| 420 | + /** | ||
| 421 | + * @version 11.3.0 | ||
| 422 | + * @function WebMapBase.prototype.rectifyLayersOrder | ||
| 423 | + * @description 根据已知顺序的可感知图层,对地图上图顺序进行排序。 | ||
| 424 | + */ | ||
| 425 | + rectifyLayersOrder(appreciableLayers, topLayerBeforeId) { | ||
| 426 | + this._handler && this._handler.rectifyLayersOrder(appreciableLayers, topLayerBeforeId); | ||
| 427 | + } | ||
| 419 | 428 | ||
| 420 | 429 | /** | |
| 421 | 430 | * @version 11.2.1 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2235,7 +2235,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 2235 | 2235 | this._changeSourceListModel(); | |
| 2236 | 2236 | const appreciableLayers = this.getLayers(); | |
| 2237 | 2237 | const layerOptions = this._getSelfAppreciableLayers(appreciableLayers); | |
| 2238 | - this._rectifyLayersOrder(layerOptions.layers); | ||
| 2238 | + this.rectifyLayersOrder(layerOptions.layers); | ||
| 2239 | 2239 | this.fire('mapcreatesucceeded', { | |
| 2240 | 2240 | ...layerOptions, | |
| 2241 | 2241 | map: this.map, | |
@@ -2244,22 +2244,11 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 2244 | 2244 | } | |
| 2245 | 2245 | } | |
| 2246 | 2246 | ||
| 2247 | - _rectifyLayersOrder(appreciableLayers, topLayerBeforeId) { | ||
| 2248 | - const renderLayers = appreciableLayers | ||
| 2249 | - .filter((item) => !item.reused) | ||
| 2250 | - .reduce((layers, layer) => { | ||
| 2251 | - return layers.concat(layer.renderLayers); | ||
| 2252 | - }, []); | ||
| 2247 | + rectifyLayersOrder(appreciableLayers, topLayerBeforeId) { | ||
| 2248 | + const exsitLayers = super.rectifyLayersOrder(appreciableLayers, topLayerBeforeId); | ||
| 2253 | 2249 | const labelLayerIds = []; | |
| 2254 | - const exsitLayers = renderLayers.filter((layerId) => !!this.map.getLayer(layerId)); | ||
| 2255 | 2250 | for (let index = exsitLayers.length - 1; index > -1; index--) { | |
| 2256 | 2251 | const targetlayerId = exsitLayers[index]; | |
| 2257 | - const afterLayers = exsitLayers.slice(index + 1); | ||
| 2258 | - let beforLayerId = afterLayers.find((id) => this.map.style._layers[id]); | ||
| 2259 | - if (!afterLayers.length) { | ||
| 2260 | - beforLayerId = topLayerBeforeId; | ||
| 2261 | - } | ||
| 2262 | - this.map.moveLayer(targetlayerId, beforLayerId); | ||
| 2263 | 2252 | const labelLayerId = this._getSymbolLabelLayerName(targetlayerId); | |
| 2264 | 2253 | if (this.map.getLayer(labelLayerId)) { | |
| 2265 | 2254 | labelLayerIds.push(labelLayerId); | |
@@ -2781,7 +2770,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { | |||
| 2781 | 2770 | const appreciableLayers = this.getLayers(); | |
| 2782 | 2771 | const selfAppreciableLayers = this.getSelfAppreciableLayers(appreciableLayers); | |
| 2783 | 2772 | const topLayerBeforeId = this._findTopLayerBeforeId(selfAppreciableLayers); | |
| 2784 | - this._rectifyLayersOrder(selfAppreciableLayers, topLayerBeforeId); | ||
| 2773 | + this.rectifyLayersOrder(selfAppreciableLayers, topLayerBeforeId); | ||
| 2785 | 2774 | this.fire('layeraddchanged', this._getSelfAppreciableLayers(appreciableLayers)); | |
| 2786 | 2775 | } | |
| 2787 | 2776 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1263,4 +1263,27 @@ describe('mapboxgl_WebMap', () => { | |||
| 1263 | 1263 | }; | |
| 1264 | 1264 | datavizWebmap.once('mapcreatesucceeded', callback); | |
| 1265 | 1265 | }); | |
| 1266 | + | ||
| 1267 | + it('rectifyLayersOrder', (done) => { | ||
| 1268 | + const commonOption = { | ||
| 1269 | + server: 'http://fack:8190/iportal/', | ||
| 1270 | + target: 'map', | ||
| 1271 | + withCredentials: false | ||
| 1272 | + }; | ||
| 1273 | + datavizWebmap = new WebMap( | ||
| 1274 | + '', | ||
| 1275 | + { ...commonOption }, | ||
| 1276 | + mapOptionsList[0] | ||
| 1277 | + ); | ||
| 1278 | + const callback = function ({map}) { | ||
| 1279 | + let layers = datavizWebmap.getLayers(); | ||
| 1280 | + expect(layers.length).toBe(2); | ||
| 1281 | + let newLayers = [layers[1], layers[0]]; | ||
| 1282 | + datavizWebmap.rectifyLayersOrder(newLayers); | ||
| 1283 | + const layersOnMap = map.getStyle().layers; | ||
| 1284 | + expect(layersOnMap[0].id).toBe('未命名数据') | ||
| 1285 | + done(); | ||
| 1286 | + }; | ||
| 1287 | + datavizWebmap.once('mapcreatesucceeded', callback); | ||
| 1288 | + }); | ||
| 1266 | 1289 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1244,4 +1244,27 @@ describe('maplibregl_WebMap', () => { | |||
| 1244 | 1244 | }; | |
| 1245 | 1245 | datavizWebmap.once('mapcreatesucceeded', callback); | |
| 1246 | 1246 | }); | |
| 1247 | + | ||
| 1248 | + it('rectifyLayersOrder', (done) => { | ||
| 1249 | + const commonOption = { | ||
| 1250 | + server: 'http://fack:8190/iportal/', | ||
| 1251 | + target: 'map', | ||
| 1252 | + withCredentials: false | ||
| 1253 | + }; | ||
| 1254 | + datavizWebmap = new WebMap( | ||
| 1255 | + '', | ||
| 1256 | + { ...commonOption }, | ||
| 1257 | + mapOptionsList[0] | ||
| 1258 | + ); | ||
| 1259 | + const callback = function ({map}) { | ||
| 1260 | + let layers = datavizWebmap.getLayers(); | ||
| 1261 | + expect(layers.length).toBe(2); | ||
| 1262 | + let newLayers = [layers[1], layers[0]]; | ||
| 1263 | + datavizWebmap.rectifyLayersOrder(newLayers); | ||
| 1264 | + const layersOnMap = map.getStyle().layers; | ||
| 1265 | + expect(layersOnMap[0].id).toBe('未命名数据') | ||
| 1266 | + done(); | ||
| 1267 | + }; | ||
| 1268 | + datavizWebmap.once('mapcreatesucceeded', callback); | ||
| 1269 | + }); | ||
| 1247 | 1270 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments