From 64dddfef02bf8430c9c9983eccccf86a88f96b89 Mon Sep 17 00:00:00 2001 From: aixianling Date: Wed, 8 Jun 2022 14:57:30 +0800 Subject: [PATCH] BUG 30074 --- src/project/beta/AppGridManagement/Map.vue | 154 ++++++++------------- 1 file changed, 56 insertions(+), 98 deletions(-) diff --git a/src/project/beta/AppGridManagement/Map.vue b/src/project/beta/AppGridManagement/Map.vue index 5b331442..dc12478d 100644 --- a/src/project/beta/AppGridManagement/Map.vue +++ b/src/project/beta/AppGridManagement/Map.vue @@ -23,7 +23,7 @@
网格长 - {{ [item.name,item.phone].join(" ") }} + {{ [item.name, item.phone].join(" ") }}
@@ -32,11 +32,11 @@ 网格长 {{ item.name }}  {{ item.phone }} + v-if="item.phone"> - + @@ -65,43 +65,14 @@ export default { created() { this.$dict.load('girdType') this.areaId = this.user.areaId - // this.getLeafNodes() - uni.$on('goback', e => { - this.getGridList(e.id, true) - }) }, onShow() { document.title = "网格管理" }, - methods: { - toChoose () { - uni.navigateTo({ - url: './SelectGird?isFormMap=1' - }) - }, - getLeafNodes() { - this.$http.post(`/app/appgirdinfo/queryGirdMemberGirdsById`).then((res) => { - if (res?.data) { - this.treeList = res.data - - const arr = res.data.filter(v => v.points).map(e => { - return { - id: e.id, - girdName: e.girdName, - points: e.points.map(p => [p.lng, p.lat]) - } - }) - - arr.length > 0 && this.renderGridMap(arr) - } - }) - }, - - getGridList (id) { + getGridList(id) { this.$loading() this.$http.post(`/app/appgirdinfo/queryChildGirdInfoByGirdId?girdId=${id}`).then((res) => { - this.$hideLoading() if (res?.data) { const arr = res.data.map(v => { return { @@ -112,12 +83,11 @@ export default { }) this.renderGridMap(arr) } - }).catch(() => { + }).finally(() => { this.$hideLoading() }) }, - - getGridInfo (id, flag) { + getGridInfo(id, flag) { this.$loading() this.$http.post(`/app/appgirdinfo/queryDetailById?id=${id}`).then((res) => { this.$hideLoading() @@ -142,7 +112,6 @@ export default { this.$hideLoading() }) }, - renderGridMap(paths, count = 0) { let {map, lib: TMap, $refs: {AiTMap: {fitBounds}}} = this if (TMap) { @@ -157,58 +126,54 @@ export default { } if (paths?.length > 0) { let bounds = [] - paths.forEach((path, i) => { - let color = colors[i % colors.length] - let polygon = new TMap.MultiPolygon({ - map, styles: { - default: new TMap.PolygonStyle({ - showBorder: true, - borderColor: '#5088FF', - borderWidth: 2, - color: this.$colorUtils.Hex2RGBA('#5088FF', 0.1) - }) - }, - id: path.id, - geometries: [{paths: path.points.map(e => new TMap.LatLng(e[1], e[0]))}] - }) - this.polygons.push(polygon) - bounds.push(fitBounds(path.points.map(e => new TMap.LatLng(e[1], e[0])))) - - polygon.on('click', e => { - const id = e.target.id - this.getGridInfo(id) - }) - - const points = path.points.map(e => new TMap.LatLng(e[1], e[0])) - - var position = TMap.geometry.computeCentroid(points) - - let label = new TMap.MultiLabel({ - id: `label~${path.id}`, - data: path.id, - map: map, - styles: { - building: new TMap.LabelStyle({ - color: '#3777FF', - size: 20, - alignment: 'center', - verticalAlignment: 'middle' - }) - }, - geometries: [ - { - id: `label-class-${i}`, - styleId: 'building', - position: position, - content: path.girdName, - } - ] - }) - this.labels.push(label) - label.on('click', e => { - this.getGridInfo(e.target.id.split('~')[1]) - }); + if(path.points?.length>0){ + let polygon = new TMap.MultiPolygon({ + map, styles: { + default: new TMap.PolygonStyle({ + showBorder: true, + borderColor: '#5088FF', + borderWidth: 2, + color: this.$colorUtils.Hex2RGBA('#5088FF', 0.1) + }) + }, + id: path.id, + geometries: [{paths: path.points.map(e => new TMap.LatLng(e[1], e[0]))}] + }) + this.polygons.push(polygon) + bounds.push(fitBounds(path.points.map(e => new TMap.LatLng(e[1], e[0])))) + polygon.on('click', e => { + const id = e.target.id + this.getGridInfo(id) + }) + const points = path.points.map(e => new TMap.LatLng(e[1], e[0])) + const position = TMap.geometry.computeCentroid(points) + let label = new TMap.MultiLabel({ + id: `label~${path.id}`, + data: path.id, + map: map, + styles: { + building: new TMap.LabelStyle({ + color: '#3777FF', + size: 20, + alignment: 'center', + verticalAlignment: 'middle' + }) + }, + geometries: [ + { + id: `label-class-${i}`, + styleId: 'building', + position, + content: path.girdName, + } + ] + }) + this.labels.push(label) + label.on('click', e => { + this.getGridInfo(e.target.id.split('~')[1]) + }); + } }) bounds = bounds.reduce((a, b) => { return fitBounds([ @@ -234,16 +199,9 @@ export default { callPhone(phone) { uni.makePhoneCall({phoneNumber: phone}) }, - handleSelect(e) { - if (e?.points?.length > 0) { - this.form = e - const points = e.points.map(e => new TMap.LatLng(e.lat, e.lng)) - var position = TMap.geometry.computeCentroid(points) - this.map.setCenter(position) - this.map.setZoom(18) - } else { - this.$u.toast("所选网格没有标绘!") - } + handleSelectGird(v) { + this.form = v || {} + this.getGridList(v?.id, true) }, } }