From c738baf2aad2cb01c1647a6c3cb88a4d3fc9640f Mon Sep 17 00:00:00 2001 From: zhaoyongnian <541231643@qq.com> Date: Thu, 12 May 2022 14:31:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8A=A8=E5=8A=9B=E4=B8=BB=E8=BD=B4?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../power/components/screen-org-map.vue | 122 +++++++++++++++++- .../visual/plugin/power/organization.vue | 121 ++++++++++------- 2 files changed, 188 insertions(+), 55 deletions(-) diff --git a/src/views/modules/visual/plugin/power/components/screen-org-map.vue b/src/views/modules/visual/plugin/power/components/screen-org-map.vue index 177bca7ef..f7e9bb875 100644 --- a/src/views/modules/visual/plugin/power/components/screen-org-map.vue +++ b/src/views/modules/visual/plugin/power/components/screen-org-map.vue @@ -31,6 +31,12 @@ let gaodeMapLayer // 背景地图图层 let markerSource let markerLayer +let markerSource_1 +let markerLayer_1 + +let markerSource_2 +let markerLayer_2 + let parentLayer;//上级组织图层 @@ -130,7 +136,8 @@ export default { orgData: {},//当前组织对象 iconCoordinators: [], parentPolygon: [], - subAgencyArray: [] + subAgencyArray: [], + centerFlag: 'point',//定义中心点的flag point点 fit 自适应 } }, async mounted() { @@ -148,6 +155,8 @@ export default { //加载当前园区的标注 this.loadPolygon() + + this.setMapLocation() }, methods: { initMap () { @@ -179,6 +188,45 @@ export default { // console.log(transform(e.coordinate, 'EPSG:3857', 'EPSG:4326')); }) }, + //设置地图定位的中心点和缩放级别 + setMapLocation () { + if (!this.zoom) { + this.setZoom(this.orgData.agencyLevel) + } + this.centerPoint = [] + + + //如果存在中心点(返回时赋值) + if (parentLayer.getSource().getFeatures()[0]) {//如果是初次进入,不存在下级组织,用父级组织 + this.centerFlag = 'flag_parent' + } else if (polygonLayer.getSource().getFeatures()[0]) {//如果是初次进入,存在下级组织 + this.centerFlag = 'flag_polygon' + } else if (this.orgData.longitude && this.orgData.latitude) { + this.centerPoint.push(this.orgData.longitude) + this.centerPoint.push(this.orgData.latitude) + this.centerFlag = 'point' + } else { + this.centerPoint = centerPointGlobal + this.centerFlag = 'point' + } + // debugger + if (this.centerFlag === 'flag_parent') { + let parentFeatures = parentLayer.getSource().getFeatures()[0] + let polygon = parentFeatures.getGeometry(); + map.getView().fit(polygon, map.getSize()); + this.zoom = map.getView().getZoom() - 1 + + } else if (this.centerFlag === 'flag_polygon') { + let polygonFeatures = polygonLayer.getSource().getFeatures()[0] + let polygon = polygonFeatures.getGeometry(); + map.getView().fit(polygon, map.getSize()); + this.zoom = map.getView().getZoom() - 1 + } else { + mapView.setCenter(this.centerPoint); + } + mapView.setZoom(this.zoom); + }, + firstCenterMap () { this.centerPoint = [] if (this.orgData.longitude && this.orgData.latitude) { @@ -190,6 +238,9 @@ export default { } }, addMarker (list, icon=iconArray[0], scale=1) { + if (markerSource) { + markerSource.clear() + } markerSource = new VectorSource({ // features: new GeoJSON().readFeatures(geojsonObject) }) @@ -245,6 +296,70 @@ export default { markerSource.addFeatures(features) map.addLayer(markerLayer) }, + addMarker_1 (list, icon=iconArray[0], scale=1) { + if (markerSource_1) { + markerSource_1.clear() + } + markerSource_1 = new VectorSource({ + // features: new GeoJSON().readFeatures(geojsonObject) + }) + markerLayer_1 = new VectorLayer({ + source: markerSource_1, + zIndex: 50 + }) + let features = [] + list.forEach((item, index) => { + const point = [parseFloat(item.longitude), parseFloat(item.latitude)] + let marker = new Feature({ + geometry: new Point(point), + properties: { + ...item + } + }) + let iconStyle = new Style({ + image: new Icon({ + scale: scale, + src: icon + }) + }) + marker.setStyle(iconStyle) + features.push(marker) + }) + markerSource_1.addFeatures(features) + map.addLayer(markerLayer_1) + }, + addMarker_2 (list, icon=iconArray[0], scale=1) { + if (markerSource_2) { + markerSource_2.clear() + } + markerSource_2 = new VectorSource({ + // features: new GeoJSON().readFeatures(geojsonObject) + }) + markerLayer_2 = new VectorLayer({ + source: markerSource_2, + zIndex: 50 + }) + let features = [] + list.forEach((item, index) => { + const point = [parseFloat(item.longitude), parseFloat(item.latitude)] + let marker = new Feature({ + geometry: new Point(point), + properties: { + ...item + } + }) + let iconStyle = new Style({ + image: new Icon({ + scale: scale, + src: icon + }) + }) + marker.setStyle(iconStyle) + features.push(marker) + }) + markerSource_2.addFeatures(features) + map.addLayer(markerLayer_2) + }, //加载组织数据 async loadOrgData () { @@ -276,8 +391,6 @@ export default { }, //加载父级组织多边形 loadParentPolygon () { - parentSource.clear()//清空变电站标注 - let featureData = []//标注数据 if (this.parentPolygon && this.parentPolygon.length > 0) {//判断是否存在下级标注 let oneData = {} @@ -435,7 +548,6 @@ export default { parentSource = new VectorSource({ //features: (new GeoJSON()).readFeatures(geojsonObject) }); - parentLayer = new VectorLayer({ source: parentSource, style: parentStyleFunction, @@ -505,9 +617,7 @@ export default { source: iconSource, zIndex: 70 }); - map.addLayer(iconLayer); - }, }, diff --git a/src/views/modules/visual/plugin/power/organization.vue b/src/views/modules/visual/plugin/power/organization.vue index 303424b19..2de996858 100644 --- a/src/views/modules/visual/plugin/power/organization.vue +++ b/src/views/modules/visual/plugin/power/organization.vue @@ -17,6 +17,7 @@ :options="agencytree" v-model="agencyId" :show-all-levels="false" + @change="handleChangeAgencytree" :props="{ expandTrigger: 'hover', emitPath: false, label: 'orgName', value: 'orgId', children: 'subOrgList' }" clearable/> @@ -202,6 +203,7 @@ export default { let params = { axisStructId: this.axisStructId, pageSize: this.pageSize, + agencyId: this.agencyId, pageNo: this.pageNo, } const url = "/pli/power/data/kernelHousehold/list" @@ -284,6 +286,7 @@ export default { getMapData() { const params1 = { axisStructId: this.axisStructId, + agencyId: this.agencyId, limit: 99 } // 党群服务站 @@ -321,7 +324,7 @@ export default { this.xiaozuList.push(ob) }) this.$nextTick(() => { - this.$refs.orgMap.addMarker(this.xiaozuList, lyxzIcon) + this.$refs.orgMap.addMarker_1(this.xiaozuList, lyxzIcon) }) }).catch(err => { this.$message.error(err) @@ -339,7 +342,7 @@ export default { this.zhongxinhuList.push(ob) }) this.$nextTick(() => { - this.$refs.orgMap.addMarker(this.zhongxinhuList, dyzxhIcon) + this.$refs.orgMap.addMarker_2(this.zhongxinhuList, dyzxhIcon) }) }).catch(err => { this.$message.error(err) @@ -353,60 +356,80 @@ export default { // }, //获取组织数据 async getAgencylist () { - const url = '/data/aggregator/org/agencytree' - - let params = { - agencyId: this.agencyId, - client:'gov' - } - const { data, code, msg } = await requestPost(url,params) - if (code === 0) { - let _data - if (data) { - _data = this.removeByOrgType(data, 'agency') - if (_data) { - this.agencytree = this.removeEmptySubOrgList(_data) - this.agencyId = this.agencytree ? this.agencytree[0].orgId : '' - } + const url = '/data/aggregator/org/agencytree' + let params = { + agencyId: this.agencyId, + client:'gov' + } + const { data, code, msg } = await requestPost(url,params) + if (code === 0) { + let _data + if (data) { + _data = this.removeByOrgType(data, 'agency') + if (_data) { + this.agencytree = this.removeEmptySubOrgList(_data) + // 如果有子集就进入循环,如果没有就默认取第一个的id + this.agencyId = this.agencytree[0].subOrgList && this.agencytree[0].subOrgList.length > 0 ? this.setListAgencyId_one(this.agencytree[0].subOrgList) : this.agencytree[0].orgId } - } else { - this.$message.error(msg) } - + } else { + this.$message.error(msg) + } }, - removeByOrgType (orgArray, orgType) { - if (orgArray && orgArray.length > 0) { - for (let p = orgArray.length - 1; p >= 0; p--) { - let orgInfo = orgArray[p] - if (orgInfo) { - if (orgInfo.orgType !== orgType) { - orgArray.splice(p, 1) - } else { - this.removeByOrgType(orgInfo.subOrgList, orgType) - } + removeByOrgType (orgArray, orgType) { + if (orgArray && orgArray.length > 0) { + for (let p = orgArray.length - 1; p >= 0; p--) { + let orgInfo = orgArray[p] + if (orgInfo) { + if (orgInfo.orgType !== orgType) { + orgArray.splice(p, 1) + } else { + this.removeByOrgType(orgInfo.subOrgList, orgType) } } } - return orgArray - }, - removeEmptySubOrgList (orgArray) { - orgArray.forEach((orgInfo) => { - if (orgInfo && orgInfo.subOrgList) { - if (orgInfo.subOrgList.length === 0) { - orgInfo.subOrgList = undefined - } else { - this.removeEmptySubOrgList(orgInfo.subOrgList) - } + } + return orgArray + }, + removeEmptySubOrgList (orgArray) { + orgArray.forEach((orgInfo) => { + if (orgInfo && orgInfo.subOrgList) { + if (orgInfo.subOrgList.length === 0) { + orgInfo.subOrgList = undefined + } else { + this.removeEmptySubOrgList(orgInfo.subOrgList) } - }) - return orgArray; - }, - async handleChangeAgency (value) { - let selAgency = this.$refs["myCascader"].getCheckedNodes()[0].data - // this.agencyName = this.$refs["myCascader"].getCheckedNodes()[0].label - this.agencyName = selAgency.name - this.agencyId = selAgency.agencyId - this.level = selAgency.level === 'grid' ? 'grid' : 'agency' + } + }) + return orgArray; + }, + // 取最后一级组织的第一条数据的 orgId + setListAgencyId_one(subOrgList) { + if (subOrgList[0].subOrgList && subOrgList[0].subOrgList.length > 0) { + this.setAgencyId_two(subOrgList[0].subOrgList) + } else { + return subOrgList[0].orgId + } + }, + setAgencyId_two(subOrgList) { + if (subOrgList[0].subOrgList && subOrgList[0].subOrgList.length > 0) { + this.setListAgencyId_one(subOrgList[0].subOrgList) + } else { + return subOrgList[0].orgId + } + }, + async handleChangeAgencytree() { + this.pageNo = 1 + this.pageSize = 5 + this.total = 0 + this.dangqunList = [] // 党群服务站列表 + this.xiaozuList = [] // 楼院小组地图坐标列表 + this.zhongxinhuList = [] // 党员中心户列表 + this.tableData = [] + this.axisStructId = '' + await this.getStructTree() + await this.getCount() + await this.getMapData() }, }, } From 068d4ccef51fa82fc525afae9d1e12b96affa767 Mon Sep 17 00:00:00 2001 From: zhaoyongnian <541231643@qq.com> Date: Fri, 13 May 2022 14:21:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BB=E6=8E=89clearable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/modules/visual/plugin/power/organization.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/views/modules/visual/plugin/power/organization.vue b/src/views/modules/visual/plugin/power/organization.vue index 2de996858..f317a5713 100644 --- a/src/views/modules/visual/plugin/power/organization.vue +++ b/src/views/modules/visual/plugin/power/organization.vue @@ -18,8 +18,7 @@ v-model="agencyId" :show-all-levels="false" @change="handleChangeAgencytree" - :props="{ expandTrigger: 'hover', emitPath: false, label: 'orgName', value: 'orgId', children: 'subOrgList' }" - clearable/> + :props="{ expandTrigger: 'hover', emitPath: false, label: 'orgName', value: 'orgId', children: 'subOrgList' }"/>