Skip to content

Commit

Permalink
修改图层列表、图层颜色组件支持webmap3.0 review by xiongjj
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Apr 8, 2024
1 parent 1c0f7cc commit b64b211
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 289 deletions.
11 changes: 6 additions & 5 deletions src/common/_utils/iPortalDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ export default class iPortalDataService extends Events {
* @param {Object} [queryInfo.attributeFilter] - 属性过滤条件。
* @param {Object} [queryInfo.keyWord] - 筛选关键字。
*/
getData(queryInfo, preferContent = false) {
if (!this.url) {
getData(queryInfo = {}, preferContent = false) {
if (this.dataType === 'STRUCTUREDDATA') {
this._getStructureDatafromContent();
return;
}
let datasetUrl = this.url;
if (this.dataType === 'STRUCTUREDDATA') {
this._getStructureDatafromContent(datasetUrl, queryInfo);

if (!this.url) {
return;
}
let datasetUrl = this.url;

if (preferContent) {
this._getDatafromContent(datasetUrl, queryInfo);
Expand Down
14 changes: 6 additions & 8 deletions src/mapboxgl/_types/map-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ export default new Vue({
map
});
const sourceList = sourceListModel.getSourceList();
for (let key in sourceList) {
if (key) {
let layers = sourceList[key].layers || [];
layers.forEach(item => {
if (item.source && item.type !== 'raster') {
sources.push(item.source);
}
});
for (let item of sourceList) {
if (item) {
let layer = item.layer;
if (layer.source && layer.type !== 'raster') {
sources.push(layer.source);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mapboxgl/attributes/AttributesViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class FeatureTableViewModel extends mapboxgl.Evented {
if (this.useDataset()) {
let datas = await this._getFeaturesFromDataset();
features = datas.features;
!this.totalCount && (this.totalCount = datas.totalCount);
this.totalCount = datas.totalCount;
if (this.canLazyLoad()) {
if (this.dataset.url !== this.prevDatasetUrl) {
let arr = this.dataset.dataName[0].split(':');
Expand Down
112 changes: 20 additions & 92 deletions src/mapboxgl/layer-select/LayerSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,120 +95,48 @@ class LayerSelect extends Mixins(MapGetter, Theme) {
this.$emit('changedata', { id, type });
}
handleDatas(sourceList): treeSelectDataOption[] {
createLayersTreeData(layerCatalog) {
const treeData: treeSelectDataOption[] = [];
this.sourceListDataCache = {};
Object.keys(sourceList).forEach((sourceName, sIndex) => {
let { id, type, visibility } = sourceList[sourceName];
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(sourceList[sourceName], 'source', this.map) || {};
let res = this.filter(layerType, type, this.map) || {};
disabled = res.disabled;
selectable = res.selectable;
if (typeof res.show === 'boolean' && res.show === false) {
return;
}
}
const sourceValue = `${sourceName}+source`;
const layerValue = `${id}+${type}`;
const sourceInfo: treeSelectDataOption = {
title: sourceName,
value: sourceValue,
key: `${sIndex}`,
title: title,
value: layerValue,
key: layer.id,
disabled: !!disabled,
selectable: selectable
};
this.sourceListDataCache[sourceValue] = {
if(type === 'group') {
sourceInfo.children = this.createLayersTreeData(layer.children);
}
this.sourceListDataCache[layerValue] = {
id,
type,
visibility
type: layerType,
visibility: visible ? 'visible' : 'none'
};
if (sourceList[sourceName].sourceLayerList) {
const sourceChildren = [];
Object.keys(sourceList[sourceName].sourceLayerList).forEach((sourceLayerName, slIndex) => {
let disabled = false;
let selectable = true;
const sourceLayerOption = {
id: null,
source: id,
sourceLayer: sourceLayerName
};
if (this.filter) {
let res = this.filter(sourceLayerOption, 'sourceLayer', this.map) || {};
disabled = res.disabled;
selectable = res.selectable;
if (typeof res.show === 'boolean' && res.show === false) {
return;
}
}
const sourceLayerValue = `${sourceLayerName}+sourceLayer`;
const sourceLayerInfo: treeSelectDataOption = {
title: sourceLayerName,
value: sourceLayerValue,
key: `${sIndex}-${slIndex}`,
disabled: !!disabled,
selectable
};
this.sourceListDataCache[sourceLayerValue] = sourceLayerOption;
let layers: layerOption[] = sourceList[sourceName].sourceLayerList[sourceLayerName];
const sourceLayerChildren = this.handleLayers(layers, `${sIndex}-${slIndex}`);
if (sourceLayerChildren.length) {
sourceLayerInfo.children = sourceLayerChildren;
}
sourceChildren.push(sourceLayerInfo);
});
if (sourceChildren.length) {
sourceInfo.children = sourceChildren;
}
} else {
let layers: layerOption[] = sourceList[sourceName].layers;
const layerChildren = this.handleLayers(layers, sIndex);
if (layerChildren.length) {
sourceInfo.children = layerChildren;
}
}
treeData.push(sourceInfo);
});
return treeData;
}
handleLayers(layers: layerOption[], keyString: number | string): treeSelectDataOption[] {
const layerChildren = [];
layers.forEach((layerInfo, lIndex) => {
let { id, maxzoom, minzoom, source, sourceLayer, type, visibility } = layerInfo;
let disabled = false;
let selectable = true;
if (this.filter) {
let res = this.filter(layerInfo, 'layer', this.map) || {};
disabled = res.disabled;
selectable = res.selectable;
if (typeof res.show === 'boolean' && res.show === false) {
return;
}
}
const layerValue = `${layerInfo.id}+layer`;
layerChildren.push({
title: layerInfo.id,
value: layerValue,
key: `${keyString}-${lIndex}`,
disabled: !!disabled,
selectable
});
this.sourceListDataCache[layerValue] = {
id,
maxzoom,
minzoom,
source,
sourceLayer,
type,
visibility
};
});
return layerChildren;
handleDatas(sourceList): treeSelectDataOption[] {
let treeData: treeSelectDataOption[] = [];
this.sourceListDataCache = {};
treeData = this.createLayersTreeData(sourceList);
return treeData;
}
getPopupContainer(triggerNode) {
Expand Down
9 changes: 3 additions & 6 deletions src/mapboxgl/layer-select/LayerSelectViewModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mapboxgl from 'vue-iclient/static/libs/mapboxgl/mapbox-gl-enhance';
import SourceListModel from 'vue-iclient/src/mapboxgl/web-map/SourceListModel';

/**
* @class LayerSelectViewModel
Expand All @@ -18,16 +17,14 @@ class LayerSelectViewModel extends mapboxgl.Evented {
}

_updateLayers() {
const sourceListModel = new SourceListModel({
map: this.map
});
const sourceList = sourceListModel.getSourceList();
const sourceList = this.webmap.getLayerList();
this.fire('layersupdated', { sourceList });
}

setMap(mapInfo: mapInfoType) {
const { map } = mapInfo;
const { map, webmap } = mapInfo;
this.map = map;
this.webmap = webmap;
this.map.on('styledata', this.updateFn);
this._updateLayers();
}
Expand Down
48 changes: 48 additions & 0 deletions src/mapboxgl/web-map/GroupUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class GroupUtil {
getGroupVisible(catalogs, item) {
const rootGroup = this.getRootGroup(catalogs, item);
if (!rootGroup) return true;

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

return this.getGroupVisible(children, item);
}

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));
}

// 是否是当前图层组的 子图层/子图层组
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));
}

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));
}
return targetItems;
}
}
export default GroupUtil;
105 changes: 105 additions & 0 deletions src/mapboxgl/web-map/LayerGroup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<div>
<sm-collapse
v-for="(item, index) in layerCatalog"
:key="index"
:bordered="false"
class="sm-component-layer-list__collapse"
>
<sm-collapse-panel v-if="item.type === 'group'" class="sm-component-layer-list__collapseitem" :showArrow="false">
<template slot="header">
<div
class="header-wrap"
:class="{
'header-wrap': true,
'sm-component-layer-list__disabled': !item.visible
}"
>
<div class="header-text">
<i
:class="item.visible ? 'sm-components-icon-partially-visible' : 'sm-components-icon-hidden'"
@click.stop="toggleItemVisibility(item)"
/>
<span class="add-ellipsis">{{ item.title }}</span>
</div>
<i class="sm-components-icon-solid-triangle-right header-arrow" />
<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>
</sm-collapse-panel>

<div
v-else
:class="{
'sm-component-layer-list__elcarditem': true,
'sm-component-layer-list__disabled': !item.visible
}"
>
<div class="sm-component-layer-list__layer">
<i
:class="item.visible ? 'sm-components-icon-visible' : 'sm-components-icon-hidden'"
@click.stop="toggleItemVisibility(item)"
/>
<div class="sm-component-layer-list__layergroupname add-ellipsis" :title="item.title">{{ item.title }}</div>
</div>
<div v-if="attributesEnabled(item)" class="sm-component-layer-list__attributes">
<i
:class="attributesIconClass"
:style="!item.visible && { cursor: 'not-allowed' }"
@click.stop="item.visible && toggleAttributesVisibility($event, item)"
/>
</div>
</div>
</sm-collapse>
</div>
</template>

<script>
import Theme from 'vue-iclient/src/common/_mixin/Theme';
export default {
name: 'LayerGroup',
mixins: [Theme],
props: {
layerCatalog: {
type: Array,
default() {
return [];
}
},
attributes: {
type: Object,
default() {
return {};
}
},
checkAttributesEnabled: {
type: Function
}
},
computed: {
attributesIconClass() {
return (this.attributes && this.attributes.iconClass) || 'sm-components-icon-attribute';
},
attributesEnabled() {
return (item) => {
return this.attributes.enabled && (item.type === 'basic' && this.checkAttributesEnabled(item));
};
}
},
methods: {
toggleItemVisibility(item) {
this.$emit('toggleItemVisibility', item);
item.visible = !item.visible;
},
toggleAttributesVisibility(e, item) {
const { title, id } = item;
this.$emit('toggleAttributesVisibility', e, id, title);
}
}
};
</script>

<style>
</style>
Loading

0 comments on commit b64b211

Please sign in to comment.