Swanky 2 years ago
parent dcbe31528c
commit cb409b86f8
  1. 21
      components/layer-checkbox.vue
  2. 93
      pages/index/index.vue

@ -1,7 +1,7 @@
<template> <template>
<view class="uni-flex uni-column" style="align-items: center;" @click="valueChange(value)"> <view class="uni-flex uni-column" style="align-items: center;margin-right: 16px;" @click="valueChange(value)">
<view class="content" :class="checked?'checked':''"> <view class="content" :class="checked?'checked':''">
<image :src="'/static/layer-'+icon+'.png'" :class="icon==='cd'?'icon2':'icon'"></image> <image :src="icon.startsWith('http')?icon:'/static/layer-'+icon+'.png'" class="icon" :style="iconStyle"></image>
<uni-icons v-if="checked" type="checkbox-filled" class="check-icon" color="#fff"></uni-icons> <uni-icons v-if="checked" type="checkbox-filled" class="check-icon" color="#fff"></uni-icons>
</view> </view>
<view style="text-align: center;width: 64px;" :class="checked?'checked':''">{{label}}</view> <view style="text-align: center;width: 64px;" :class="checked?'checked':''">{{label}}</view>
@ -13,14 +13,14 @@
name: "layer-checkbox", name: "layer-checkbox",
props: { props: {
label: String, label: String,
value: String, value: Number,
change: Function, change: Function,
icon: String, icon: String,
checked: Boolean checked: Boolean,
}, iconStyle: String
},
data() { data() {
return { return {};
};
}, },
methods: { methods: {
valueChange(value) { valueChange(value) {
@ -38,12 +38,7 @@
.icon2 { .icon2 {
position: absolute; position: absolute;
width: 60px; width: 60px;height: 60px;left: 0;right: 0;top: 0;bottom: 0;
height: 60px;
left: 0;
right: 0;
top: 0;
bottom: 0;
} }
.icon { .icon {

@ -36,10 +36,10 @@
<uni-popup ref="popup" background-color="#fff" @change="popupChange"> <uni-popup ref="popup" background-color="#fff" @change="popupChange">
<view class="popup-title">图层叠加</view> <view class="popup-title">图层叠加</view>
<view class="popup-content uni-flex uni-row" style="align-items: center;justify-content: center;"> <view class="popup-content uni-flex uni-row" style="align-items: center;justify-content: center;">
<view class="uni-flex uni-row" style="justify-content: space-around;flex:1;"> <view class="uni-flex uni-row" style="flex:1;flex-wrap: wrap;">
<layer-checkbox v-for="item in layerItems" :icon="item.icon" :label="item.text" <layer-checkbox v-for="(item,i) in layerItems" :icon="item.icon" :label="item.text" :value="i"
:value="item.value" @change="checkLayer" @change="checkLayer" :checked="currentLayers.indexOf(i)>-1"
:checked="currentLayers.indexOf(item.value)>-1"></layer-checkbox> :iconStyle="item.iconStyle"></layer-checkbox>
</view> </view>
</view> </view>
</uni-popup> </uni-popup>
@ -116,31 +116,7 @@
}, },
currentLayers: [], currentLayers: [],
currentLayer: null, currentLayer: null,
layerItems: [{ layerItems: [],
text: '生态修复工程',
value: 'stxfgc',
icon: 'stxfgc',
zIndex: 99,
detailUrl: '/stxh/appDetails'
}, {
text: '征占用',
value: 'cdzzy_view',
icon: 'zzy',
zIndex: 88,
detailUrl: '/cdzhy/appDetails'
}, {
text: '非法占用',
value: 'ffzy_layer',
icon: 'ffzy',
zIndex: 77,
detailUrl: '/cdzhy/appFfzyDetails'
}, {
text: '草地',
value: 't_grassland_result',
icon: 'cd',
zIndex: 66,
detailUrl: '/cdzy/appDetails'
}],
detailItems: [], detailItems: [],
detailGroups: [], detailGroups: [],
currentGroupTab: null, currentGroupTab: null,
@ -158,9 +134,10 @@
if (newVal) { if (newVal) {
this.mapData = { this.mapData = {
layerOpts: newVal?.map(val => { layerOpts: newVal?.map(val => {
const item = this.layerItems.find(l => l.value === val); const item = this.layerItems[val];
return { return {
layerName: val, layerName: item.value,
layerIndex: val,
...item ...item
} }
}) })
@ -196,10 +173,11 @@
}) })
this.compassHandler = res => { this.compassHandler = res => {
console.log(res)
this.compassNum = res.direction; this.compassNum = res.direction;
} }
uni.onCompassChange(this.compassHandler); uni.onCompassChange(this.compassHandler);
this.loadLayerItems();
}, },
onShow() { onShow() {
uni.startCompass() uni.startCompass()
@ -208,7 +186,34 @@
uni.stopCompass(); uni.stopCompass();
}, },
methods: { methods: {
loadLayerItems() {
uni.request({
url: `${helper.mgServerUrl}/app/config/layer`,
header: {
Authorization: `Bearer ${this.token}`
},
success: (resp) => {
console.log(resp)
if (resp.data.data) {
const item = resp.data.data;
this.layerItems = item?.layerItems.map(layerItem => {
return {
text: layerItem.title,
value: layerItem.layerName,
icon: layerItem.icon,
zIndex: 99,
detailUrl: layerItem.detailUrl,
geoserverUrl: layerItem.geoserverUrl || item.geoserverUrl,
layerWorkspace: layerItem.layerWorkspace || item.layerWorkspace,
...layerItem
}
})
}
},
})
},
checkLayer(value) { checkLayer(value) {
console.log('check', value)
const index = this.currentLayers.findIndex(l => l === value); const index = this.currentLayers.findIndex(l => l === value);
if (index > -1) { if (index > -1) {
this.currentLayers.splice(index, 1); this.currentLayers.splice(index, 1);
@ -251,8 +256,9 @@
}, },
showFfzy(id) { showFfzy(id) {
console.log(id) console.log(id)
if (!this.currentLayers.find(l => l === 'ffzy_layer')) { const ffzyLayerIndex = this.layerItems.findIndex(item => item.value === 'ffzy_layer')
this.currentLayers.push('ffzy_layer') if (!this.currentLayers.find(l => l === ffzyLayerIndex)) {
this.currentLayers.push(ffzyLayerIndex)
} }
uni.request({ uni.request({
url: `${helper.serverUrl}/ffzy/ffzy/${id}`, url: `${helper.serverUrl}/ffzy/ffzy/${id}`,
@ -356,9 +362,9 @@
// } // }
const apis = []; const apis = [];
this.layerItems.forEach(item => { this.layerItems.forEach((item, i) => {
const layerStr = this.currentLayers.find(l => l === item.value); const layerIndex = this.currentLayers.findIndex(l => l === i);
if (layerStr) { if (layerIndex > -1) {
apis.push(item.detailUrl); apis.push(item.detailUrl);
} }
}); });
@ -483,20 +489,21 @@
}) || [] }) || []
const layers = newValue.layerOpts.map(opt => { const layers = newValue.layerOpts.map(opt => {
let layer = businessLayers.find(l => { let layer = businessLayers.find(l => {
return l.get('businessName') === opt.layerName; return l.get('businessIndex') === opt.layerIndex;
}) })
if (!layer) { if (!layer) {
layer = new Image({ layer = new Image({
businessId: 'business-layer', businessId: 'business-layer',
businessName: opt.layerName, businessName: opt.layerName,
businessIndex: opt.layerIndex,
source: new ImageWMS({ source: new ImageWMS({
ratio: 1, ratio: 1,
url: `${helper.geoserverUrl}/geoserver/yzt/wms`, url: `${opt.geoserverUrl}/geoserver/yzt/wms`,
params: { params: {
'FORMAT': 'image/png', 'FORMAT': 'image/png',
'VERSION': '1.1.1', 'VERSION': '1.1.1',
"STYLES": '', "STYLES": opt.layerStyle || '',
"LAYERS": `yzt:${opt.layerName}`, "LAYERS": `${opt.layerWorkspace}:${opt.layerName}`,
"exceptions": 'application/vnd.ogc.se_inimage', "exceptions": 'application/vnd.ogc.se_inimage',
} }
}), }),
@ -511,8 +518,8 @@
}) })
vectorLayer.getSource().clear(); vectorLayer.getSource().clear();
businessLayers.forEach(layer => { businessLayers.forEach(layer => {
const index = newValue.layerOpts.findIndex(opt => opt.layerName === layer.get( const index = newValue.layerOpts.findIndex(opt => opt.layerIndex === layer.get(
'businessName')); 'businessIndex'));
if (index === -1) { if (index === -1) {
layer.setVisible(false); layer.setVisible(false);
} }

Loading…
Cancel
Save