|
@@ -22,11 +22,12 @@ import { ref, watchEffect } from "vue";
|
|
import { QuiskExpose } from "@/helper/mount";
|
|
import { QuiskExpose } from "@/helper/mount";
|
|
import { debounce } from "@/util";
|
|
import { debounce } from "@/util";
|
|
|
|
|
|
-export type MapImage = { blob: Blob | null };
|
|
|
|
-type MapInfo = { lat: number; lng: number; zoom: number };
|
|
|
|
|
|
+export type MapImage = { blob: Blob | null; search: MapInfo | null };
|
|
|
|
+type MapInfo = { lat: number; lng: number; zoom: number; text: string };
|
|
|
|
|
|
const keyword = ref("");
|
|
const keyword = ref("");
|
|
const info = ref<MapInfo>();
|
|
const info = ref<MapInfo>();
|
|
|
|
+const searchInfo = ref<MapInfo>();
|
|
|
|
|
|
const mapEl = ref<HTMLDivElement>();
|
|
const mapEl = ref<HTMLDivElement>();
|
|
const resultEl = ref<HTMLDivElement>();
|
|
const resultEl = ref<HTMLDivElement>();
|
|
@@ -37,7 +38,7 @@ watchEffect(async (onCleanup) => {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
const AMap = await AMapLoader.load({
|
|
const AMap = await AMapLoader.load({
|
|
- plugins: ["AMap.PlaceSearch"],
|
|
|
|
|
|
+ plugins: ["AMap.PlaceSearch", "AMap.Event"],
|
|
key: "e661b00bdf2c44cccf71ef6070ef41b8",
|
|
key: "e661b00bdf2c44cccf71ef6070ef41b8",
|
|
version: "2.0",
|
|
version: "2.0",
|
|
});
|
|
});
|
|
@@ -50,15 +51,40 @@ watchEffect(async (onCleanup) => {
|
|
});
|
|
});
|
|
const placeSearch = new AMap.PlaceSearch({
|
|
const placeSearch = new AMap.PlaceSearch({
|
|
pageSize: 5,
|
|
pageSize: 5,
|
|
|
|
+ showCover: false,
|
|
pageIndex: 1,
|
|
pageIndex: 1,
|
|
map: map,
|
|
map: map,
|
|
panel: resultEl.value,
|
|
panel: resultEl.value,
|
|
autoFitView: true,
|
|
autoFitView: true,
|
|
});
|
|
});
|
|
|
|
+ const setSearch = (data) => {
|
|
|
|
+ searchInfo.value = {
|
|
|
|
+ text: data.pname + data.cityname + data.adname + data.address,
|
|
|
|
+ lat: data.location.lat,
|
|
|
|
+ lng: data.location.lng,
|
|
|
|
+ zoom: 0,
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ placeSearch.on("listElementClick", (e) => {
|
|
|
|
+ setSearch(e.data);
|
|
|
|
+ });
|
|
|
|
+ placeSearch.on("complete", function (result) {
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ const markers = map.getAllOverlays("marker");
|
|
|
|
+ for (const marker of markers) {
|
|
|
|
+ marker.on("click", () => {
|
|
|
|
+ setSearch(marker._data);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }, 500);
|
|
|
|
+ });
|
|
|
|
+
|
|
const getMapInfo = (): MapInfo => {
|
|
const getMapInfo = (): MapInfo => {
|
|
var zoom = map.getZoom(); //获取当前地图级别
|
|
var zoom = map.getZoom(); //获取当前地图级别
|
|
var center = map.getCenter();
|
|
var center = map.getCenter();
|
|
return {
|
|
return {
|
|
|
|
+ text: "",
|
|
zoom,
|
|
zoom,
|
|
lat: center.lat,
|
|
lat: center.lat,
|
|
lng: center.lng,
|
|
lng: center.lng,
|
|
@@ -87,9 +113,9 @@ defineExpose<QuiskExpose>({
|
|
return new Promise<MapImage>((resolve) => {
|
|
return new Promise<MapImage>((resolve) => {
|
|
if (mapEl.value) {
|
|
if (mapEl.value) {
|
|
const canvas = mapEl.value.querySelector("canvas") as HTMLCanvasElement;
|
|
const canvas = mapEl.value.querySelector("canvas") as HTMLCanvasElement;
|
|
- canvas.toBlob((blob) => resolve({ blob }));
|
|
|
|
|
|
+ canvas.toBlob((blob) => resolve({ blob, search: searchInfo.value! }));
|
|
} else {
|
|
} else {
|
|
- resolve({ blob: null });
|
|
|
|
|
|
+ resolve({ blob: null, search: null });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|