Skip to content

Commit

Permalink
【feature】图层列表不可拖拽的图层排序
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Sep 27, 2024
1 parent 30a29a8 commit 4a10639
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
22 changes: 19 additions & 3 deletions src/mapboxgl/_types/map-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ export default new Vue({
datas = sortLayerCatalog(datas, _this.customLayerCatalogCache[webmapTarget]);
}
_this.updateLayerCatalogsVisible(datas);
datas = _this.updateImmutableOrderLayers(datas);
}
if (propKey === 'getAppreciableLayers' && _this.customLayerCatalogCache[webmapTarget]) {
const flatterLayers = flattenLayerCatalog(_this.customLayerCatalogCache[webmapTarget]);
datas = sortLayerCatalog(datas, flatterLayers.reverse());
if (propKey === 'getAppreciableLayers') {
if (_this.customLayerCatalogCache[webmapTarget]) {
const flatterLayers = flattenLayerCatalog(_this.customLayerCatalogCache[webmapTarget]);
datas = sortLayerCatalog(datas, flatterLayers.reverse());
}
datas = _this.updateImmutableOrderLayers(datas, true);
}
return () => datas;
}
Expand Down Expand Up @@ -149,5 +153,17 @@ export default new Vue({
this.updateLayerCatalogsVisible(data.children);
}
}
},
updateImmutableOrderLayers(layers, revert) {
let topLayers = layers.filter(item => item.layerOrder && item.layerOrder.toLowerCase() === 'top');
const migrationLayers = topLayers.filter(item => item.type === 'MIGRATION');
const leftTopLayers = topLayers.filter(item => item.type !== 'MIGRATION');
topLayers = migrationLayers.concat(leftTopLayers);
const bottomLayers = layers.filter(item => item.layerOrder && item.layerOrder.toLowerCase() === 'bottom');
const autoLayers = layers.filter(item => !item.layerOrder || item.layerOrder.toLowerCase() === 'auto');
if (revert) {
return bottomLayers.concat(autoLayers, topLayers);
}
return topLayers.concat(autoLayers, bottomLayers);
}
});
2 changes: 2 additions & 0 deletions src/mapboxgl/web-map/LayerGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export default {
if (data.children) {
const children = this.getTreeData(data.children);
data.children = children;
} else if(item.layerOrder !== 'auto') {
data.disabled = true;
}
treeData.push(data);
});
Expand Down
17 changes: 12 additions & 5 deletions src/mapboxgl/web-map/WebMapViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ interface AddlayerssucceededParams {
allLoaded: boolean;
}

interface LayerUpdateChangedParams {
layers: Record<string, any>[];
relevantLayers: Record<string, any>[];
layerCatalog: Record<string, any>[];
}

export default class WebMapViewModel extends Events {
map: mapboxglTypes.Map;

Expand Down Expand Up @@ -201,7 +207,6 @@ export default class WebMapViewModel extends Events {
'mapcreatesucceeded',
'mapcreatefailed',
'layercreatefailed',
'layeraddchanged',
'layerupdatechanged',
'baidumapnotsupport',
'projectionnotmatch',
Expand All @@ -212,7 +217,7 @@ export default class WebMapViewModel extends Events {
this._mapInitializedHandler = this._mapInitializedHandler.bind(this);
this._mapCreateSucceededHandlerHandler = this._mapCreateSucceededHandlerHandler.bind(this);
this._mapBeforeRemoveHandler = this._mapBeforeRemoveHandler.bind(this);
this._layerAddChangedHandler = this._layerAddChangedHandler.bind(this);
this._layerUpdateChangedHandler = this._layerUpdateChangedHandler.bind(this);
this._initWebMap();
}

Expand Down Expand Up @@ -521,8 +526,10 @@ export default class WebMapViewModel extends Events {
this.triggerEvent('addlayerssucceeded', params);
}

private _layerAddChangedHandler({ layers }) {
this._cacheCleanLayers = layers;
private _layerUpdateChangedHandler(params: LayerUpdateChangedParams) {
const { relevantLayers } = params;
this._cacheCleanLayers = relevantLayers;
this.triggerEvent('layerupdatechanged', params);
}

private _createMap() {
Expand All @@ -535,7 +542,7 @@ export default class WebMapViewModel extends Events {
}, {}),
mapinitialized: this._mapInitializedHandler,
mapcreatesucceeded: this._mapCreateSucceededHandlerHandler,
layeraddchanged: this._layerAddChangedHandler,
layerupdatechanged: this._layerUpdateChangedHandler,
mapbeforeremove: this._mapBeforeRemoveHandler
};
this._handler = new mapboxgl.supermap.WebMap(this.mapId, this.options, this.mapOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export default class AnimateMarkerLayerViewModel extends mapboxgl.Evented {
paint: {
'circle-radius': 0,
'circle-opacity': 1
},
metadata: {
SM_Layer_Order: 'Top'
}
});

Expand Down
2 changes: 1 addition & 1 deletion static/libs/iclient-mapboxgl/iclient-mapboxgl.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions test/unit/mocks/mapboxgl_iclient_webmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class WebMap extends Evented {
'mapbeforeremove',
'mapinitialized',
'layercreatefailed',
'layerupdatechanged',
'layeraddchanged'
'layerupdatechanged'
];
this._initWebMap();
if (this.mapOptions) {
Expand Down

0 comments on commit 4a10639

Please sign in to comment.