Browse Source

事发选点适配移动端

Hwf 6 tháng trước cách đây
mục cha
commit
1ecc31ccd8

+ 15 - 0
src/views/event/PositionSelect.vue

@@ -190,6 +190,15 @@ function handlePanTo(index) {
   setMarks(lnglat);
   closeSearchList();
 }
+const updateForm = (position) => {
+  form.longitude = position[0];
+  form.latitude = position[1];
+  geocoder.getAddress(position, (status, result) => {
+    if (status === 'complete' && result.info === 'OK') {
+      form.address = result.regeocode.formattedAddress;
+    }
+  });
+};
 const initMap = async () => {
   let position = [110.925175, 21.678955];
   const AMap = await AMapLoader.load({
@@ -211,6 +220,7 @@ const initMap = async () => {
   ContextMenu();
   map.on('rightclick', handleRightclick);
   map.on('complete', () => {
+    updateForm(position);
     setMarks(position);
   });
 };
@@ -228,6 +238,7 @@ function ContextMenu() {
             form.address = result.regeocode.formattedAddress;
           }
         });
+        updateForm(lnglat);
         setMarks(lnglat);
       },
       1
@@ -249,9 +260,13 @@ function setMarks(lnglat) {
       imageSize: new AMap.Size(22, 28), //图标大小
       image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png'
     }),
+    draggable: true,
     anchor: 'bottom-center',
     offset: new AMap.Pixel(0, 0)
   });
+  marker.on('dragend', (e) => {
+    updateForm([e.lnglat.lng, e.lnglat.lat]);
+  });
   marker.setMap(map);
 }
 function handleClose() {

+ 15 - 0
src/views/mobileControl/PositionSelect.vue

@@ -191,6 +191,15 @@ function handlePanTo(index) {
   setMarks(lnglat);
   closeSearchList();
 }
+const updateForm = (position) => {
+  form.longitude = position[0];
+  form.latitude = position[1];
+  geocoder.getAddress(position, (status, result) => {
+    if (status === 'complete' && result.info === 'OK') {
+      form.address = result.regeocode.formattedAddress;
+    }
+  });
+};
 const initMap = async () => {
   let position = [110.925175, 21.678955];
   const AMap = await AMapLoader.load({
@@ -212,6 +221,7 @@ const initMap = async () => {
   ContextMenu();
   map.on('rightclick', handleRightclick);
   map.on('complete', () => {
+    updateForm(position);
     setMarks(position);
   });
 };
@@ -229,6 +239,7 @@ function ContextMenu() {
             form.address = result.regeocode.formattedAddress;
           }
         });
+        updateForm(lnglat);
         setMarks(lnglat);
       },
       1
@@ -250,9 +261,13 @@ function setMarks(lnglat) {
       imageSize: new AMap.Size(22, 28), //图标大小
       image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png'
     }),
+    draggable: true,
     anchor: 'bottom-center',
     offset: new AMap.Pixel(0, 0)
   });
+  marker.on('dragend', (e) => {
+    updateForm([e.lnglat.lng, e.lnglat.lat]);
+  });
   marker.setMap(map);
 }
 function handleClose() {