diff --git a/components/layer-checkbox.vue b/components/layer-checkbox.vue new file mode 100644 index 0000000..2d2d925 --- /dev/null +++ b/components/layer-checkbox.vue @@ -0,0 +1,74 @@ + + + + + \ No newline at end of file diff --git a/main.js b/main.js index 5fc19d9..6224581 100644 --- a/main.js +++ b/main.js @@ -2,8 +2,10 @@ import Vue from 'vue' import App from './App' import imageButton from './components/image-button.vue' import customAttr from './components/custom-attr.vue' +import layerCheckbox from './components/layer-checkbox' Vue.component('image-button', imageButton) Vue.component('custom-attr', customAttr) +Vue.component('layer-checkbox', layerCheckbox) Vue.config.productionTip = false App.mpType = 'app' diff --git a/pages/index/index.vue b/pages/index/index.vue index e60a6f1..746ee77 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -32,14 +32,19 @@ 图层叠加 - - + + + + - 详情 + {{currentClickLayerItem?currentClickLayerItem.text:''}}详情 关闭 @@ -106,35 +111,54 @@ mapData: { center: [102.45438, 32.53223] }, + currentLayers: [], currentLayer: null, layerItems: [{ - text: '生态修复工程图层', - value: 'stxfgc' + text: '生态修复工程', + value: 'stxfgc', + icon: 'stxfgc', + zIndex: 99, + detailUrl: '/stxh/details' }, { - text: '征占用图层', - value: 'cdzzy_view' + text: '征占用', + value: 'cdzzy_view', + icon: 'zzy', + zIndex: 88, + detailUrl: '/cdzhy/details' }, { - text: '非法占用图层', - value: 'ffzy_layer' + text: '非法占用', + value: 'ffzy_layer', + icon: 'ffzy', + zIndex: 77, + detailUrl: '/cdzhy/ffzyDetails' }, { - text: '草地图层', - value: 't_grassland_result' + text: '草地', + value: 't_grassland_result', + icon: 'cd', + zIndex: 66, + detailUrl: '/cdzy/cdDetails' }], detailItems: [], detailGroups: [], currentGroupTab: null, token: '', - measureStatus: '' + measureStatus: '', + currentClickLayerItem: null } }, watch: { - currentLayer(newVal, oldVal) { + currentLayers(newVal, oldVal) { const map = this.$map; console.log(newVal, oldVal, map); - this.$refs.popup.close() if (newVal) { this.mapData = { - layerName: newVal + layerOpts: newVal?.map(val => { + const item = this.layerItems.find(l => l.value === val); + return { + layerName: val, + ...item + } + }) } } @@ -149,6 +173,14 @@ }) }, methods: { + checkLayer(value) { + const index = this.currentLayers.findIndex(l => l === value); + if (index > -1) { + this.currentLayers.splice(index, 1); + } else { + this.currentLayers.push(value) + } + }, closeMeasureStatus() { this.measureStatus = '' this.mapData = {} @@ -177,7 +209,9 @@ }, showFfzy(id) { console.log(id) - this.currentLayer = 'ffzy_layer' + if (!this.currentLayers.find(l => l === 'ffzy_layer')) { + this.currentLayers.push('ffzy_layer') + } uni.request({ url: `${helper.serverUrl}/ffzy/ffzy/${id}`, header: { @@ -292,72 +326,66 @@ showLayerModal() { this.$refs.popup.open('bottom') }, + _request(index, wkt, apis, callback) { + if (apis[index]) { + uni.request({ + url: `${helper.mgServerUrl}${apis[index]}?wkt=${wkt}`, + success: (resp2) => { + console.log(resp2) + if (resp2?.data?.data?.dyColumn?.length > 0) { + const layerItem = this.layerItems.find(item => item.detailUrl === apis[index]); + this.currentClickLayerItem = layerItem; + callback(resp2?.data?.data, layerItem) + } else { + this._request(++index, wkt, apis, callback) + } + } + }) + } else { + callback(); + } + }, requestDetail({ - wkt, - url + wkt }) { - uni.request({ - url, - success: (resp) => { - console.log(resp?.data?.features?.[0]) - if (resp?.data?.features?.[0]) { + // if (resp?.data?.features?.[0]) { + // this.mapData = { + // highLightData: resp?.data?.features?.[0] + // } + + // } + const apis = []; + this.layerItems.forEach(item => { + const layerStr = this.currentLayers.find(l => l === item.value); + if (layerStr) { + apis.push(item.detailUrl); + } + }); + this._request(0, wkt, apis, (resp) => { + if (resp) { + if (resp.geom) { this.mapData = { - highLightData: resp?.data?.features?.[0] - } - let apiStr = ''; - switch (this.currentLayer) { - case 'stxfgc': - apiStr = '/stxh/details'; - break; - case 't_grassland_result': - apiStr = '/cdzy/cdDetails'; - break; - case 'cdzzy_view': - apiStr = '/cdzhy/details'; - break; - case 'ffzy_layer': - apiStr = '/cdzhy/ffzyDetails'; - break; + highLightWkt: resp.geom } - if (apiStr) { - uni.request({ - url: `${helper.mgServerUrl}${apiStr}?wkt=${wkt}`, - success: (resp2) => { - console.log(resp2) - const groups = _.groupBy(resp2?.data?.data - .dyColumn, 'tab'); - this.detailGroups = _.keys(groups).map(key => { - return { - tab: key, - children: groups[key]?.map(item => { - return { - ...item, - value: item.value || '' - } - }) - } - }); - this.currentGroupTab = this.detailGroups?.[0]?.tab; - this.$refs.popupDetail.open('bottom'); + + } + const groups = _.groupBy(resp.dyColumn, 'tab'); + this.detailGroups = _.keys(groups).map(key => { + return { + tab: key, + children: groups[key]?.map(item => { + return { + ...item, + value: item.value || '' } }) } - } - // const props = resp?.data?.features?.[0]?.properties; - // if (helper.layerDetails[this.currentLayer]) { - // this.detailItems = helper.layerDetails[this.currentLayer].map(item => { - // return { - // ...item, - // value: props[item.field] - // } - // }); - // this.$refs.popupDetail.open('bottom'); - // } - }, - fail: (resp) => { - console.log(resp) + }); + this.currentGroupTab = this.detailGroups?.[0]?.tab; + this.$refs.popupDetail.open('bottom'); + } - }) + }); } } } @@ -446,30 +474,49 @@ maxZoom: 18 }); } - if (newValue.layerName) { - const layer = new Image({ - id: 'business-layer', - source: new ImageWMS({ - ratio: 1, - url: `${helper.geoserverUrl}/geoserver/yzt/wms`, - params: { - 'FORMAT': 'image/png', - 'VERSION': '1.1.1', - "STYLES": '', - "LAYERS": `yzt:${newValue.layerName}`, - "exceptions": 'application/vnd.ogc.se_inimage', - } + if (newValue.layerOpts) { + const businessLayers = map.getAllLayers().filter(l => { + return l.get('businessId') === 'business-layer'; + }) || [] + const layers = newValue.layerOpts.map(opt => { + let layer = businessLayers.find(l => { + return l.get('businessName') === opt.layerName; }) - }); + if (!layer) { + layer = new Image({ + businessId: 'business-layer', + businessName: opt.layerName, + source: new ImageWMS({ + ratio: 1, + url: `${helper.geoserverUrl}/geoserver/yzt/wms`, + params: { + 'FORMAT': 'image/png', + 'VERSION': '1.1.1', + "STYLES": '', + "LAYERS": `yzt:${opt.layerName}`, + "exceptions": 'application/vnd.ogc.se_inimage', + } + }), + zIndex: opt.zIndex + }); + businessLayers.push(layer); + map.addLayer(layer); + } else { + layer.setVisible(true) + } + return layer; + }) vectorLayer.getSource().clear(); - map.removeLayer(map.getAllLayers().find(layer => { - - return layer.get('id') === 'business-layer' - })) - map.addLayer(layer); + businessLayers.forEach(layer => { + const index = newValue.layerOpts.findIndex(opt => opt.layerName === layer.get( + 'businessName')); + if (index === -1) { + layer.setVisible(false); + } + }) } - if (newValue.highLightData) { - const feature = new GeoJSON().readFeature(newValue.highLightData) + if (newValue.highLightWkt) { + const feature = new WKT().readFeature(newValue.highLightWkt) feature.setStyle(new Style({ fill: new Fill({ color: 'rgba(0,0,0,0)', @@ -547,7 +594,7 @@ vectorLayer = new VectorLayer({ id: 'v-layer', source: new VectorSource(), - zIndex: 99 + zIndex: 999 }) map.addLayer(vectorLayer); map.on('singleclick', evt => { @@ -557,28 +604,25 @@ }) }, showByWkt(coordinate) { - const source = map.getAllLayers().find(l => l.get('id') === 'business-layer')?.getSource(); - if (source) { - const view = map.getView(); - const viewResolution = view.getResolution(); - const [x1] = map.getCoordinateFromPixel([0, 0]); - const [x2] = map.getCoordinateFromPixel([10, 0]); - const radius = x2 - x1; - const circle = new Circle(coordinate, radius); - const polygon = fromCircle(circle); - const wkt = new WKT().writeGeometry(polygon); - const url = source.getFeatureInfoUrl( - coordinate, viewResolution, view.getProjection(), { - 'INFO_FORMAT': 'application/json', - 'FEATURE_COUNT': 50 - }); - if (url) { - this.ownerInstance?.callMethod('requestDetail', { - wkt: wkt, - url - }) - } - } + // const source = map.getAllLayers().find(l => l.get('id') === 'business-layer')?.getSource(); + // if (source) { + const view = map.getView(); + const viewResolution = view.getResolution(); + const [x1] = map.getCoordinateFromPixel([0, 0]); + const [x2] = map.getCoordinateFromPixel([10, 0]); + const radius = x2 - x1; + const circle = new Circle(coordinate, radius); + const polygon = fromCircle(circle); + const wkt = new WKT().writeGeometry(polygon); + // const url = source.getFeatureInfoUrl( + // coordinate, viewResolution, view.getProjection(), { + // 'INFO_FORMAT': 'application/json', + // 'FEATURE_COUNT': 50 + // }); + this.ownerInstance?.callMethod('requestDetail', { + wkt: wkt + }) + // } } } } diff --git a/static/layer-cd.png b/static/layer-cd.png new file mode 100644 index 0000000..e4acca8 Binary files /dev/null and b/static/layer-cd.png differ diff --git a/static/layer-ffzy.png b/static/layer-ffzy.png new file mode 100644 index 0000000..bd55172 Binary files /dev/null and b/static/layer-ffzy.png differ diff --git a/static/layer-stxfgc.png b/static/layer-stxfgc.png new file mode 100644 index 0000000..205e821 Binary files /dev/null and b/static/layer-stxfgc.png differ diff --git a/static/layer-zzy.png b/static/layer-zzy.png new file mode 100644 index 0000000..07bd5cc Binary files /dev/null and b/static/layer-zzy.png differ