|
@@ -10,7 +10,7 @@ export default defineComponent({
|
|
|
},
|
|
|
emits: ["change"],
|
|
|
setup(props, { emit }) {
|
|
|
- // const AMap = ref(AMap);
|
|
|
+ // const AMap = ref();
|
|
|
const map = ref();
|
|
|
const marker = ref();
|
|
|
const geocoder = ref();
|
|
@@ -31,7 +31,7 @@ export default defineComponent({
|
|
|
}
|
|
|
|
|
|
function updateLnglat() {
|
|
|
- marker.value.setPosition(state.lnglat);
|
|
|
+ marker.value?.setPosition(state.lnglat);
|
|
|
map.value.add(marker.value);
|
|
|
map.value.setZoomAndCenter(11, state.lnglat);
|
|
|
emit("change", { address: state.address, lnglat: state.lnglat });
|
|
@@ -70,7 +70,7 @@ export default defineComponent({
|
|
|
autoComplete.value.search(
|
|
|
state.address,
|
|
|
function (status: any, result: any) {
|
|
|
- if (status === "complete" && result.regeocode) {
|
|
|
+ if (status === "complete") {
|
|
|
// 搜索成功时,result即是对应的匹配数据
|
|
|
state.tips = result.tips || [];
|
|
|
state.visible = true;
|
|
@@ -83,13 +83,8 @@ export default defineComponent({
|
|
|
};
|
|
|
|
|
|
const initMap = () => {
|
|
|
- map.value = new AMap.Map("mapJsContainer", {
|
|
|
- viewMode: "3D", //是否为3D地图模式
|
|
|
- zoom: 11, //初始化地图级别
|
|
|
- center: state.lnglat, //初始化地图中心点位置
|
|
|
- });
|
|
|
// AMapLoader.load({
|
|
|
- // key: "e8d3513c8551b20ec90b991249fa59a1", // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
+ // key: "389e81c4c61fd6dff4ab8f742af82e5f", // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
// version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
|
// plugins: ["AMap.Scale", "AMap.ToolBar", "AMap.MouseTool"], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
|
// Loca: {
|
|
@@ -97,13 +92,21 @@ export default defineComponent({
|
|
|
// },
|
|
|
// })
|
|
|
// .then((res) => {
|
|
|
+ // AMap.value = res;
|
|
|
+ map.value = new AMap.Map("mapJsContainer", {
|
|
|
+ // viewMode: "3D", //是否为3D地图模式
|
|
|
+ zoom: 11, //初始化地图级别
|
|
|
+ center: state.lnglat, //初始化地图中心点位置
|
|
|
+ });
|
|
|
|
|
|
AMap.plugin(
|
|
|
["AMap.Geocoder", "AMap.AutoComplete", "AMap.ToolBar"],
|
|
|
() => {
|
|
|
// 使用geocoder做地理/逆地理编码
|
|
|
geocoder.value = new AMap.Geocoder();
|
|
|
- autoComplete.value = new AMap.AutoComplete({ city: "全国" });
|
|
|
+ autoComplete.value = new AMap.AutoComplete({
|
|
|
+ city: "全国",
|
|
|
+ });
|
|
|
|
|
|
const toolbar = new AMap.ToolBar({ position: "LT" }); // 缩放工具条实例化
|
|
|
map.value.addControl(toolbar);
|
|
@@ -136,6 +139,9 @@ export default defineComponent({
|
|
|
watch(
|
|
|
() => [props.value],
|
|
|
() => {
|
|
|
+ const { lnglat } = props.value;
|
|
|
+ if (state.lnglat[0] == lnglat[0] && state.lnglat[1] == lnglat[1])
|
|
|
+ return;
|
|
|
state.address = props.value.address;
|
|
|
state.lnglat = props.value.lnglat;
|
|
|
updateLnglat();
|
|
@@ -149,10 +155,10 @@ export default defineComponent({
|
|
|
value={state.address}
|
|
|
placeholder="请输入地名"
|
|
|
class="w-1/1"
|
|
|
- onSearch={searchAddress}
|
|
|
+ // onSearch={searchAddress}
|
|
|
onChange={(e) => {
|
|
|
state.address = e.target.value || "";
|
|
|
- // searchAddress();
|
|
|
+ searchAddress();
|
|
|
}}
|
|
|
/>
|
|
|
{state.visible && (
|