|
@@ -214,6 +214,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 = () => {
|
|
|
let position = [110.925175, 21.678955];
|
|
|
AMapLoader.load({
|
|
@@ -237,6 +246,7 @@ const initMap = () => {
|
|
|
map.on('rightclick', handleRightclick);
|
|
|
handleResize();
|
|
|
map.on('complete', () => {
|
|
|
+ updateForm(position);
|
|
|
setMarks(position);
|
|
|
});
|
|
|
});
|
|
@@ -249,12 +259,8 @@ function ContextMenu() {
|
|
|
form.longitude = lnglatPosition.value[0];
|
|
|
form.latitude = lnglatPosition.value[1];
|
|
|
contextMenu.close();
|
|
|
- let lnglat = [form.longitude, form.latitude];
|
|
|
- geocoder.getAddress(lnglat, (status, result) => {
|
|
|
- if (status === 'complete' && result.info === 'OK') {
|
|
|
- form.address = result.regeocode.formattedAddress;
|
|
|
- }
|
|
|
- });
|
|
|
+ const lnglat = [form.longitude, form.latitude];
|
|
|
+ updateForm(lnglat);
|
|
|
setMarks(lnglat);
|
|
|
},
|
|
|
1
|
|
@@ -276,9 +282,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() {
|