|
@@ -5,12 +5,22 @@
|
|
|
<el-button :icon="Search" />
|
|
|
</template>
|
|
|
</el-input>
|
|
|
- <div class="search-result" v-show="keyword" ref="resultEl"></div>
|
|
|
+ <div class="rrr">
|
|
|
+ <div class="search-result" v-show="keyword && showSearch" ref="resultEl"></div>
|
|
|
+ <div class="search-sh" v-show="keyword">
|
|
|
+ <el-button style="width: 100%" @click="showSearch = !showSearch">
|
|
|
+ {{ showSearch ? "收起" : "展开" }}搜索结果
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- <div class="def-select-map" ref="mapEl"></div>
|
|
|
+ <div class="def-select-map-layout">
|
|
|
+ <div class="def-select-map" ref="mapEl"></div>
|
|
|
+ </div>
|
|
|
+
|
|
|
<div class="def-map-info" v-if="info">
|
|
|
- <p><span>经度</span>{{ info.lat }}</p>
|
|
|
- <p><span>维度</span>{{ info.lng }}</p>
|
|
|
+ <p><span>纬度</span>{{ info.lat }}</p>
|
|
|
+ <p><span>经度</span>{{ info.lng }}</p>
|
|
|
<p><span>缩放级别</span>{{ info.zoom }}</p>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -22,11 +32,19 @@ import { ref, watchEffect } from "vue";
|
|
|
import { QuiskExpose } from "@/helper/mount";
|
|
|
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 showSearch = ref(true);
|
|
|
const info = ref<MapInfo>();
|
|
|
+const searchInfo = ref<MapInfo>();
|
|
|
+
|
|
|
+watchEffect(() => {
|
|
|
+ if (keyword.value) {
|
|
|
+ showSearch.value = true;
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
const mapEl = ref<HTMLDivElement>();
|
|
|
const resultEl = ref<HTMLDivElement>();
|
|
@@ -37,7 +55,7 @@ watchEffect(async (onCleanup) => {
|
|
|
return;
|
|
|
}
|
|
|
const AMap = await AMapLoader.load({
|
|
|
- plugins: ["AMap.PlaceSearch"],
|
|
|
+ plugins: ["AMap.PlaceSearch", "AMap.Event"],
|
|
|
key: "e661b00bdf2c44cccf71ef6070ef41b8",
|
|
|
version: "2.0",
|
|
|
});
|
|
@@ -50,23 +68,54 @@ watchEffect(async (onCleanup) => {
|
|
|
});
|
|
|
const placeSearch = new AMap.PlaceSearch({
|
|
|
pageSize: 5,
|
|
|
+ showCover: false,
|
|
|
pageIndex: 1,
|
|
|
map: map,
|
|
|
panel: resultEl.value,
|
|
|
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);
|
|
|
+ showSearch.value = false;
|
|
|
+ });
|
|
|
+
|
|
|
+ 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 => {
|
|
|
var zoom = map.getZoom(); //获取当前地图级别
|
|
|
var center = map.getCenter();
|
|
|
return {
|
|
|
+ text: "",
|
|
|
zoom,
|
|
|
lat: center.lat,
|
|
|
lng: center.lng,
|
|
|
};
|
|
|
};
|
|
|
//绑定地图移动与缩放事件
|
|
|
- map.on("moveend", () => (info.value = getMapInfo()));
|
|
|
- map.on("zoomend", () => (info.value = getMapInfo()));
|
|
|
+ map.on("moveend", () => {
|
|
|
+ info.value = getMapInfo();
|
|
|
+ });
|
|
|
+ map.on("zoomend", () => {
|
|
|
+ info.value = getMapInfo();
|
|
|
+ });
|
|
|
searchAMap.value = placeSearch;
|
|
|
|
|
|
onCleanup(() => {
|
|
@@ -87,9 +136,9 @@ defineExpose<QuiskExpose>({
|
|
|
return new Promise<MapImage>((resolve) => {
|
|
|
if (mapEl.value) {
|
|
|
const canvas = mapEl.value.querySelector("canvas") as HTMLCanvasElement;
|
|
|
- canvas.toBlob((blob) => resolve({ blob }));
|
|
|
+ canvas.toBlob((blob) => resolve({ blob, search: searchInfo.value! }));
|
|
|
} else {
|
|
|
- resolve({ blob: null });
|
|
|
+ resolve({ blob: null, search: null });
|
|
|
}
|
|
|
});
|
|
|
},
|
|
@@ -104,11 +153,15 @@ defineExpose<QuiskExpose>({
|
|
|
z-index: 2;
|
|
|
}
|
|
|
|
|
|
-.search-result {
|
|
|
+.rrr {
|
|
|
position: absolute;
|
|
|
left: 0;
|
|
|
right: 0;
|
|
|
z-index: 1;
|
|
|
+}
|
|
|
+
|
|
|
+.search-sh,
|
|
|
+.search-result {
|
|
|
overflow: hidden;
|
|
|
|
|
|
&.show {
|
|
@@ -134,9 +187,19 @@ defineExpose<QuiskExpose>({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-.def-select-map {
|
|
|
- width: 540px;
|
|
|
- height: 390px;
|
|
|
+.def-select-map-layout {
|
|
|
+ --scale: 1.5;
|
|
|
+ width: 100%;
|
|
|
+ padding-top: calc((390 / 540) * 100%);
|
|
|
+ position: relative;
|
|
|
z-index: 1;
|
|
|
}
|
|
|
+
|
|
|
+.def-select-map {
|
|
|
+ position: absolute;
|
|
|
+ left: 0;
|
|
|
+ top: 0;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
</style>
|