From 9d92c8c9680625ff3f3bb6b1e188348160ebd4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E7=AC=99=E6=AD=8C?= <2277317060@qq.com> Date: Wed, 20 Sep 2023 16:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=B5=E5=AD=90=E5=9B=B4?= =?UTF-8?q?=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../electronicFence/editElectronicFence.vue | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/ruoyi-ui/src/views/business/electronicFence/editElectronicFence.vue b/ruoyi-ui/src/views/business/electronicFence/editElectronicFence.vue index fc0fc56..cf73a38 100644 --- a/ruoyi-ui/src/views/business/electronicFence/editElectronicFence.vue +++ b/ruoyi-ui/src/views/business/electronicFence/editElectronicFence.vue @@ -54,7 +54,6 @@ import { delElectronicFence, addElectronicFence, updateElectronicFence, - getEditedScenes } from "@/api/business/electronicFence"; let map = null @@ -103,25 +102,29 @@ export default { } }, created() { - getEditedScenes().then(response => { - this.editedScenes = response.data; - }); }, - mounted() { + async mounted() { + await this.isAMap() this.getEditedElectronicFence(); map = new AMap.Map('map', { zoom: 11, center: [113.4, 23.35], }); + await this.isMapLoading() CircleEditor = new AMap.CircleEditor(map); CircleEditor.on('add', function (data) { let circle = data.target; // CircleEditor.addAdsorbCircles(circle); circle.on('dblclick', () => { CircleEditor.setTarget(circle); + polyEditor.close(); CircleEditor.open(); }) + circle.on('rightclick', () => { + CircleEditor.close(); + map.remove(circle); + }) }) polyEditor = new AMap.PolygonEditor(map); polyEditor.on('add', function (data) { @@ -129,11 +132,42 @@ export default { polyEditor.addAdsorbPolygons(polygon); polygon.on('dblclick', () => { polyEditor.setTarget(polygon); + CircleEditor.close(); polyEditor.open(); }) + + polygon.on('rightclick', () => { + CircleEditor.close(); + polyEditor.close(); + map.remove(polygon); + }) }) }, methods: { + isAMap(){ + return new Promise((a,b)=>{ + let fun = ()=>{ + if(typeof AMap ==='object'){ + a() + }else{ + setTimeout(fun,100) + } + } + fun() + }) + }, + isMapLoading(){ + return new Promise((a,b)=>{ + let fun = ()=>{ + if(map){ + a() + }else{ + setTimeout(fun,100) + } + } + fun() + }) + }, clear() { if (!polyEditor) return CircleEditor.close(); @@ -144,11 +178,13 @@ export default { map.remove(circles) }, createPolygon() { + CircleEditor.close(); polyEditor.close(); polyEditor.setTarget(); polyEditor.open() }, createCircle() { + polyEditor.close(); CircleEditor.close(); CircleEditor.setTarget(); CircleEditor.open() @@ -159,6 +195,10 @@ export default { polyEditor.setTarget(thisPolygon); polyEditor.open(); }) + thisPolygon.on('rightclick', () => { + polyEditor.close(); + map.remove(thisPolygon); + }) map.add(thisPolygon) map.setFitView() }, @@ -168,6 +208,10 @@ export default { CircleEditor.setTarget(thisCircle); CircleEditor.open(); }) + thisCircle.on('rightclick', () => { + CircleEditor.close(); + map.remove(thisCircle); + }) map.add(thisCircle) map.setFitView() },