ソースを参照

⚙ 移除高德,使用自建逆地址编码

快乐的梦鱼 1 ヶ月 前
コミット
36de5e11a1

+ 0 - 86
src/api/map/AMapApi.ts

@@ -1,86 +0,0 @@
-import { DataModel, transformArrayDataModel, type NewDataModel } from '@imengyu/js-request-transform';
-import { AMapServerRequestModule } from '../RequestModules';
-import { type QueryParams } from '@imengyu/imengyu-utils';
-
-export class Poi extends DataModel<Poi> {
-  constructor() {
-    super(Poi, "Poi");
-    this.setNameMapperCase('Camel', 'Snake');
-    this._convertTable = {
-      location: { clientSide: 'splitCommaArray' },
-    };
-    this._convertKeyType = (key, direction) => {
-      if (key.endsWith('Time'))
-        return {
-          clientSide: 'date',
-          serverSide: 'string',
-        };
-      return undefined;
-    };
-  }
-  name = '';
-  location = [] as number[];
-  type = '';
-  address = '';
-  cityname = '';
-}
-
-export class AMapApi extends AMapServerRequestModule<DataModel> {
-
-  constructor() {
-    super();
-  }
-
-
-  searchPoi(name: string, page = 1, size = 10, querys?: QueryParams) {
-    return this.get(`/v3/place/text?keywords=${encodeURIComponent(name)}&citylimit=true&offset=${size}&page=${page}`, `搜索POI ${name} 第${page}页`, {
-      ...querys,
-    })
-      .then(res => transformArrayDataModel(Poi, res.data ?? [], ''))
-      .catch(e => { throw e });
-  }
-  async regeo(lat: number, lng: number, querys?: QueryParams) {
-    const data = (await this.get<any>(`/v3/geocode/regeo`, `查询经纬度(${lat}, ${lng})所属区县`, {
-      location: `${lng},${lat}`,
-      ...querys,
-    }));
-    return data.raw.regeocode.addressComponent as {
-      country: string,
-      province: string,
-      city: string,
-      district: string,
-      adcode: string,
-      township: string,
-      citycode: string,
-      towncode: string,
-    }
-  }
-  regeoAddress(lat: number, lng: number, querys?: QueryParams) {
-    return this.get(`/v3/geocode/regeo`, `查询经纬度(${lat}, ${lng})地址`, {
-      location: `${lng},${lat}`,
-      ...querys,
-    })
-      .then(res => (res.data as any).regeocode.formatted_address as string)
-      .catch(e => { throw e });
-  }
-  loadCityData() {
-    return new Promise((resolve, reject) => {
-      uni.request({
-        url: 'https://mn.wenlvti.net/app_static/xiangyuan/data/ChinaCityData.slim.json',
-        method: 'GET',
-        success(result) {
-          if (result.statusCode === 200) {
-            resolve(result.data);
-          } else {
-            reject(new Error(`请求失败,状态码:${result.statusCode}`));
-          }
-        },
-        fail(error) {
-          reject(error);
-        }
-      })
-    });
-  }
-}
-
-export default new AMapApi();

+ 22 - 0
src/api/map/MapApi.ts

@@ -38,6 +38,28 @@ export class MapCityData extends DataModel<MapCityData> {
 export class MapApi extends MengyuServerRequestModule<MapCityData> {
 
   /**
+   * 逆地址编码,根据经纬度获取详细地址
+   * @param lat 纬度
+   * @param lng 经度
+   * @returns 详细地址
+   */
+  async regeo(lat: number, lng: number) {
+    const data = (await this.post<any>(`https://subserver.wenlvti.net/localgeo/localGeo/getGeo`, `逆地址编码`, {
+      lat: lat.toFixed(6), 
+      lng: lng.toFixed(6), 
+    }));
+    return data.raw as {
+      formatAddress: string,
+      province: string,
+      city: string,
+      district: string,
+      street: string,
+      adcode: string,
+      level: null
+    }
+  }
+
+  /**
    * 快速获取地区编码
    * @param name 地区名称
    * @param city 城市名称(可选,用于消歧)

+ 2 - 3
src/common/components/dynamicf/ComponentConfigs.ts

@@ -1,4 +1,3 @@
-import AMapApi from "@/api/map/AMapApi";
 import MapApi from "@/api/map/MapApi";
 import type { IDynamicFormComponentAdditionalDefine } from "@/components/dynamic";
 
@@ -10,13 +9,13 @@ export default [
     needArrow: true,
     props: {
       loadCityData: () => MapApi.loadCityData(),
-      loadDistrictInfo: (latlon: [number, number]) => AMapApi.regeo(latlon[0], latlon[1]),
+      loadDistrictInfo: (latlon: [number, number]) => MapApi.regeo(latlon[0], latlon[1]),
     },
   },
   {
     name: 'select-address',
     props: {
-      loadFormattedAddress: (latlon: [number, number]) => AMapApi.regeoAddress(latlon[0], latlon[1]),
+      loadFormattedAddress: async (latlon: [number, number]) => (await MapApi.regeo(latlon[0], latlon[1])).formatAddress,
     },
   },
 ] as IDynamicFormComponentAdditionalDefine[];

+ 0 - 1
src/common/config/ApiCofig.ts

@@ -9,7 +9,6 @@ export default {
   },
   mainBodyId: 1,
   platformId: 330,
-  amapServerKey: '8fd09264c33678141f609588c432df0e',
   mapKey: 'QDOBZ-B6N6Q-2LL57-2QZVU-MPHA6-A3B2G',
   bugReport: {
     server: 'https://update-server1.imengyu.top/bug-submit',

+ 2 - 3
src/pages/dig/forms/data/spots.ts

@@ -3,7 +3,6 @@ import { villageCommonContent } from "./common";
 import type { FieldProps } from "@/components/form/Field.vue";
 import type { SingleForm } from "../forms";
 import MapApi from "@/api/map/MapApi";
-import AMapApi from "@/api/map/AMapApi";
 
 export const villageInfoSpotsFormItems : SingleForm = [CommonInfoModel, (form) => ({
   formItems: [
@@ -29,8 +28,8 @@ export const villageInfoSpotsFormItems : SingleForm = [CommonInfoModel, (form) =
             onChange(val: [number, number]) {
               if (form.value.getValueByPath('address'))
                 return;
-              AMapApi.regeoAddress(val[0], val[1]).then(res => {
-                form.value.setValueByPath('address', res);
+              MapApi.regeo(val[0], val[1]).then(res => {
+                form.value.setValueByPath('address', res.formatAddress);
               });
             },
           },

+ 4 - 5
src/pages/home/composeabe/GetCurrentLocation.ts

@@ -1,7 +1,6 @@
 import LightVillageApi from "@/api/light/LightVillageApi";
-import MapApi from "@/api/map/MapApi";
 import RegionApi from "@/api/map/RegionApi";
-import TenMapApi from "@/api/map/TenMapApi";
+import MapApi from "@/api/map/MapApi";
 import { alert, confirm } from "@/components/utils/DialogAction";
 import { useVillageStore } from "@/store/village";
 import { ref } from "vue";
@@ -35,9 +34,9 @@ export function useGetCurrentLocation(
             latitude: res.latitude,
           };
           villageStore.setCurrentLonlat(currentLonlat.value);
-          const address = (await TenMapApi.geocoder(`${res.latitude},${res.longitude}`));
-          const regionRes = (await RegionApi.searchByName(address?.address_component?.city || ''));
-          onCityChanged?.(address?.address_component?.city || '', regionRes.list[0].areaCode, address?.address_component?.district);
+          const address = (await MapApi.regeo(res.latitude, res.longitude));
+          const regionRes = (await RegionApi.searchByName(address?.city || ''));
+          onCityChanged?.(address?.city || '', regionRes.list[0].areaCode, address?.district);
           resolve(currentLonlat.value);
         },
         fail: (err) => {