Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Apr 16, 2024
1 parent 780e6f3 commit 02c4a52
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 226 deletions.
5 changes: 2 additions & 3 deletions src/mapboxgl/layer-select/LayerSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ class LayerSelect extends Mixins(MapGetter, Theme) {
const treeData: treeSelectDataOption[] = [];
layerCatalog.forEach(layer => {
let { id, title, type, visible } = layer;
let layerType = layer.layer?.type;
let disabled = false;
let selectable = true;
if (this.filter) {
let res = this.filter(layerType, type, this.map) || {};
let res = this.filter(type, this.map) || {};
disabled = res.disabled;
selectable = res.selectable;
Expand All @@ -124,7 +123,7 @@ class LayerSelect extends Mixins(MapGetter, Theme) {
}
this.sourceListDataCache[layerValue] = {
id,
type: layerType,
type,
visibility: visible ? 'visible' : 'none'
};
treeData.push(sourceInfo);
Expand Down
80 changes: 41 additions & 39 deletions src/mapboxgl/web-map/GroupUtil.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
class GroupUtil {
getGroupVisible(catalogs, item) {
const rootGroup = this.getRootGroup(catalogs, item);
if (!rootGroup) return true;
export function getGroupVisible(catalogs, item) {
const rootGroup = getRootGroup(catalogs, item);
if (!rootGroup) return true;

const { visible, children } = rootGroup;
if (!visible) return false;
const {
visible,
children
} = rootGroup;
if (!visible) return false;

return this.getGroupVisible(children, item);
}
return getGroupVisible(children, item);
}

getRootGroup(catalogs, item) {
const isRootItem = catalogs.find(c => (c.id === item.id));
if (isRootItem) return; // 说明是顶层,不存在父图层组
function getRootGroup(catalogs, item) {
const isRootItem = catalogs.find(c => (c.id === item.id));
if (isRootItem) return; // 说明是顶层,不存在父图层组

// 图层组中的图层/图层组
const groups = catalogs.filter(catalog => catalog.type === 'group');
return groups.find((g) => this.isChild(g, item));
}
// 图层组中的图层/图层组
const groups = catalogs.filter(catalog => catalog.type === 'group');
return groups.find((g) => isChild(g, item));
}

// 是否是当前图层组的 子图层/子图层组
isChild(group, child) {
const { children } = group;
const target = children.find((c) => c.id === child.id);
if (target) return true;
// 是否是当前图层组的 子图层/子图层组
function isChild(group, child) {
const {
children
} = group;
const target = children.find((c) => c.id === child.id);
if (target) return true;

const childrenGroup = children.filter(catalog => catalog.type === 'group');
return !!childrenGroup.find((c) => this.isChild(c, child));
}
const childrenGroup = children.filter(catalog => catalog.type === 'group');
return !!childrenGroup.find((c) => isChild(c, child));
}

getGroupChildrenLayers(layerGroup) {
const targetItems = [];
for (const item of layerGroup) {
// 图层组和图层都只选择可见的
if (item.visible === false) continue;

if (item.type !== 'group') {
targetItems.push(item);
continue;
}
// 图层组
const group = item;
targetItems.push(...this.getGroupChildrenLayers(group.children));
export function getGroupChildrenLayers(layerGroup) {
const targetItems = [];
for (const item of layerGroup) {
// 图层组和图层都只选择可见的
if (item.visible === false) continue;

if (item.type !== 'group') {
targetItems.push(item);
continue;
}
return targetItems;
// 图层组
const group = item;
targetItems.push(...getGroupChildrenLayers(group.children));
}
}
export default GroupUtil;
return targetItems;
}
12 changes: 5 additions & 7 deletions src/mapboxgl/web-map/LayerGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<i class="sm-components-icon-solid-triangle-down header-arrow" />
</div>
</template>
<layer-group v-on="$listeners" :layerCatalog="item.children" :attributes="attributes" :checkAttributesEnabled="checkAttributesEnabled"></layer-group>
<layer-group v-on="$listeners" :layerCatalog="item.children" :attributes="attributes" ></layer-group>
</sm-collapse-panel>

<div
Expand Down Expand Up @@ -79,9 +79,6 @@ export default {
default() {
return {};
}
},
checkAttributesEnabled: {
type: Function
}
},
computed: {
Expand All @@ -90,7 +87,9 @@ export default {
},
attributesEnabled() {
return (item) => {
return this.attributes.enabled && (item.type === 'basic' && this.checkAttributesEnabled(item));
const isGeojson = item.renderSource.type === 'geojson';
const isStructureData = item.dataSource.type === 'STRUCTURE_DATA';
return this.attributes.enabled && (isGeojson || isStructureData);
};
}
},
Expand All @@ -100,8 +99,7 @@ export default {
item.visible = !item.visible;
},
toggleAttributesVisibility(e, item) {
const { title, id } = item;
this.$emit('toggleAttributesVisibility', e, id, title);
this.$emit('toggleAttributesVisibility', e, item);
}
}
};
Expand Down
38 changes: 0 additions & 38 deletions src/mapboxgl/web-map/LayerListModel.js

This file was deleted.

43 changes: 19 additions & 24 deletions src/mapboxgl/web-map/SourceListModel.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import SourceModel from 'vue-iclient/src/mapboxgl/web-map/SourceModel';
import LayerModel from 'vue-iclient/src/mapboxgl/web-map/LayerModel';
import GroupUtil from 'vue-iclient/src/mapboxgl/web-map/GroupUtil';

class SourceListModel extends GroupUtil {
class SourceListModel {
constructor(options) {
super();
this.map = options.map;
this.mapInfo = options.mapInfo;
this.style = this.map.getStyle();
this.layers = this.map.getStyle().layers;
this.overlayLayers = this.map.overlayLayersManager;
Expand All @@ -20,7 +19,7 @@ class SourceListModel extends GroupUtil {
getSourceList() {
let sourceList = [];
for (let item of this.sourceList) {
if (item && this.excludeSource(item.id)) {
if (item.id && this.excludeSource(item.id)) {
sourceList.push(item);
}
}
Expand All @@ -46,27 +45,10 @@ class SourceListModel extends GroupUtil {
return true;
}

getLegendStyle(sourceName) {
if (sourceName) {
return this.sourceList[sourceName] ? this.sourceList[sourceName].style : '';
}
const sourceList = Object.values(this.sourceList) || [];
const styles = sourceList.filter(item => !!item.style);
return styles;
}

getLayers() {
return this.detailLayers;
}

getLayersBySourceLayer(sourceName, sourceLayer) {
return this.sourceList[sourceName].sourceLayerList[sourceLayer];
}

getSourceLayersBySource(sourceName) {
return this.sourceList[sourceName].sourceLayerList;
}

addSourceStyle(sourceName, sourceStyle) {
if (this.sourceList[sourceName]) {
this.sourceList[sourceName].style = sourceStyle;
Expand Down Expand Up @@ -95,15 +77,28 @@ class SourceListModel extends GroupUtil {
this.detailLayers.forEach(layer => {
let matchItem = this.sourceList.find(item => item.id === layer.source);
if (!matchItem) {
const layerInfo = this.mapInfo?.layers.find(layerItem => layer.id === layerItem.layerID) || {};
const {
dataSource = {}, themeSetting = {}
} = layerInfo;
const source = this.map.getSource(layer.source);
const sourceListItem = new SourceModel({
source: layer.source
dataSource,
source: layer.source,
type: layer.type,
renderSource: {
id: layer.source,
type: source && source.type,
sourceLayer: layer['source-layer']
},
themeSetting
});
this.sourceList.unshift(sourceListItem);
this.sourceNames.push(layer.source);
matchItem = sourceListItem;
}
matchItem.addLayer(new LayerModel(layer), layer.sourceLayer);
matchItem.addLayer(new LayerModel(layer), layer['source-layer']);
});
}
}
export default SourceListModel;
export default SourceListModel;
44 changes: 32 additions & 12 deletions src/mapboxgl/web-map/SourceModel.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
class SourceModel {
constructor(options) {
this.dataSource = options.dataSource;
this.id = options.source;
this.title = options.source;
this.children = [];
this.sourceType = options.sourceType;
this.renderSource = options.renderSource;
this.renderLayers = [];
this.type = options.type;
this.themeSetting = options.themeSetting;
}

addLayer(layer) {
this.children.push({
id: layer.id,
title: layer.id,
visible: layer.visibility === 'visible',
type: 'basic',
layer: layer
});
this.type = this.children.length > 1 ? 'group' : 'basic';
this.layer = this.type === 'basic' ? layer : undefined;
addLayer(layer, sourceLayer) {
if (sourceLayer) {
if(!this.children) {
this.children = [];
}
let matchSourceLayer = this.children.find(child => child.id === sourceLayer);
if (!matchSourceLayer) {
const sourceLayerItem = ({
dataSource: {},
id: sourceLayer,
title: sourceLayer,
visible: layer.visibility === 'visible',
type: layer.type,
renderSource: {
id: layer.source,
type: layer.type === 'geojson' ? 'geojson' : (layer.type === 'raster' ? 'raster' : 'vector'),
sourceLayer: layer.sourceLayer
},
renderLayers: [],
themeSetting: {}
});
this.children.push(sourceLayerItem);
matchSourceLayer = sourceLayerItem;
}
matchSourceLayer.renderLayers.push(layer.id);
this.type = 'group';
}
this.renderLayers.push(layer.id);
if (layer.visibility === 'visible' || this.visible) {
this.visible = true;
} else {
Expand Down
Loading

0 comments on commit 02c4a52

Please sign in to comment.