|
@@ -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() {
|