bill 4 月之前
父节点
当前提交
913afd427c
共有 5 个文件被更改,包括 63 次插入19 次删除
  1. 1 1
      .env
  2. 5 0
      .env.development
  3. 7 2
      src/components/global-search/map.vue
  4. 49 16
      src/store/map.ts
  5. 1 0
      src/vite-env.d.ts

+ 1 - 1
.env

@@ -2,4 +2,4 @@ VITE_LASER_HOST=
 VITE_LASER_OSS=/laser-data
 VITE_OSS=/oss
 VITE_PANO_OSS=/oss
-
+VITE_MAP_PLATFORM=jm

+ 5 - 0
.env.development

@@ -0,0 +1,5 @@
+VITE_LASER_HOST=
+VITE_LASER_OSS=/laser-data
+VITE_OSS=/oss
+VITE_PANO_OSS=/oss
+VITE_MAP_PLATFORM=gaode

+ 7 - 2
src/components/global-search/map.vue

@@ -1,10 +1,15 @@
 <template>
-  <p @click="flyLatLng(data.latlng)">{{ data.address }}</p>
+  <p @click="fly">{{ data.address }}</p>
 </template>
 
 <script lang="ts" setup>
 import { flyLatLng } from "@/hook/use-fly";
 import { Address } from "@/store/map";
 
-defineProps<{ data: Address }>();
+const props = defineProps<{ data: Address }>();
+
+const fly = () => {
+  console.log("fly", props.data.latlng);
+  flyLatLng(props.data.latlng);
+};
 </script>

+ 49 - 16
src/store/map.ts

@@ -1,38 +1,71 @@
 import { params } from "@/env";
 
-export type Address = { address: string; latlng: number[], id: string };
+export type Address = { address: string; latlng: number[]; id: string };
 const platform = {
   gaode(val: string) {
     const key = params.mapKey || "3bddec1685d461c2271a6099cde02fd2";
-    return fetch(
-      `https://restapi.amap.com/v3/geocode/geo?address=${encodeURIComponent(
-        val
-      )}&key=${key}`
-    )
+    const url = `https://restapi.amap.com/v3/geocode/geo?address=${encodeURIComponent(
+      val
+    )}&key=${key}`;
+    return fetch(url)
       .then((res) => res.json())
       .then((res) => {
         if (res.info !== "OK") {
           throw res.info;
         }
-        console.log(res)
-        const items = res.geocodes.map((item: any) => ({
-          id: item.location,
-          address: item.formatted_address,
-          latlng: item.location
-            .split(",")
-            .map((item: string) => Number(item.trim())),
-        })).slice(0, 10);
+        console.log(res);
+        const items = res.geocodes
+          .map((item: any) => ({
+            id: item.location,
+            address: item.formatted_address,
+            latlng: item.location
+              .split(",")
+              .map((item: string) => Number(item.trim())),
+          }))
+          .slice(0, 10);
         return items;
       });
   },
+  async jm(val: string) {
+    const tipParams = new URLSearchParams();
+    tipParams.set("basic", "y");
+    tipParams.set("key", val);
+    tipParams.set("location", "113.05,22.61");
+
+    const keyList = (await fetch(`/s/api/gettips?${tipParams.toString()}`)
+      .then((res) => res.json())
+      .then((res) => res.data)) as { name: string }[];
+
+    // const keyList = [{name: '港湾一号'},{name: '港湾二号'},]
+
+    const items: Address[] = [];
+    const reqs = keyList.map(({ name }) => {
+      const params = new URLSearchParams();
+      params.set("name", name);
+      return fetch(`/s/api/gettips_name?${params.toString()}`)
+        .then((res) => res.json())
+        .then((res) => res.data)
+        .then((data) => {
+          items.push({
+            latlng: [Number(data.lat), Number(data.lng)],
+            address: name,
+            id: data.lat.toString() + "," + data.lng.toString(),
+          });
+        });
+    });
+
+    await Promise.all(reqs)
+    return items
+  },
 };
 
 export const searchAddress = (val: string): Promise<Address[]> => {
-  if (!val) return Promise.resolve([])
+  if (!val) return Promise.resolve([]);
+  console.log(import.meta.env.VITE_MAP_PLATFORM)
   const p = (
     params.mapPlatform && params.mapPlatform in platform
       ? params.mapPlatform
-      : "gaode"
+      : import.meta.env.VITE_MAP_PLATFORM
   ) as keyof typeof platform;
 
   return platform[p](val);

+ 1 - 0
src/vite-env.d.ts

@@ -11,6 +11,7 @@ interface ImportMetaEnv {
   readonly VITE_LASER_OSS: string
   readonly VITE_PANO_OSS: string
   readonly VITE_OSS: string
+  readonly VITE_MAP_PLATFORM: string
   
 }