增加了mapworld的实现,amap的经纬度进行了转换
This commit is contained in:
parent
60f617024f
commit
f13906fd18
|
|
@ -12,14 +12,14 @@ export default class AMap implements MapService {
|
|||
type: AmapKeyType;
|
||||
}>);
|
||||
protected getKey(): string;
|
||||
regeo(param: {
|
||||
regeo(params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}): Promise<{
|
||||
poiName: any;
|
||||
areaId: any;
|
||||
}>;
|
||||
geo(param: {
|
||||
geo(params: {
|
||||
name: string;
|
||||
areaId?: string;
|
||||
}): Promise<any>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import assert from 'assert';
|
||||
import AmapSDK from 'oak-external-sdk/lib/AmapSDK';
|
||||
import { WebServiceKeyWeight } from 'oak-external-sdk/lib/types/AMap';
|
||||
import { wgs84togcj02, gcj02towgs84 } from 'oak-domain/lib/utils/geo';
|
||||
export default class AMap {
|
||||
keys;
|
||||
index;
|
||||
|
|
@ -23,38 +24,43 @@ export default class AMap {
|
|||
this.index = (this.index + 1) % this.keys.length;
|
||||
}
|
||||
}
|
||||
async regeo(param) {
|
||||
async regeo(params) {
|
||||
const key = this.getKey();
|
||||
const instance = AmapSDK.getInstance(key);
|
||||
/**
|
||||
* https://lbs.amap.com/api/webservice/guide/api/georegeo
|
||||
*/
|
||||
const { regeocode } = await instance.regeo(param);
|
||||
const gcj02Tudes = wgs84togcj02([params.longitude, params.latitude]);
|
||||
const { regeocode } = await instance.regeo({
|
||||
longitude: gcj02Tudes[0],
|
||||
latitude: gcj02Tudes[1],
|
||||
});
|
||||
return {
|
||||
poiName: regeocode.formatted_address,
|
||||
areaId: regeocode.addressComponent.towncode,
|
||||
};
|
||||
}
|
||||
;
|
||||
async geo(param) {
|
||||
async geo(params) {
|
||||
const key = this.getKey();
|
||||
const instance = AmapSDK.getInstance(key);
|
||||
/**
|
||||
* https://lbs.amap.com/api/webservice/guide/api/georegeo
|
||||
*/
|
||||
const { name, areaId } = param;
|
||||
const { name, areaId } = params;
|
||||
const { geocodes } = await instance.geocode({
|
||||
address: name,
|
||||
city: areaId,
|
||||
});
|
||||
return geocodes.map((ele) => {
|
||||
const { location } = ele;
|
||||
const tudes = location.split(',');
|
||||
const tudes = location.split(',').map((ele) => parseFloat(ele));
|
||||
const wgs84Tudes = gcj02towgs84(tudes);
|
||||
return {
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: parseFloat(tudes[1]),
|
||||
longitude: parseFloat(tudes[0]),
|
||||
longitude: wgs84Tudes[0],
|
||||
latitude: wgs84Tudes[1],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
import { MapService } from "../types/Map";
|
||||
export default class MapWorld implements MapService {
|
||||
private key;
|
||||
constructor(key: string);
|
||||
regeo(params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}): Promise<any>;
|
||||
geo(params: {
|
||||
name: string;
|
||||
areaId?: string;
|
||||
}): Promise<{
|
||||
poiName: string;
|
||||
areaId: string;
|
||||
longitude: number;
|
||||
latitude: number;
|
||||
}[]>;
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import MapWorldSDK from 'oak-external-sdk/lib/MapWorldSDK';
|
||||
export default class MapWorld {
|
||||
key;
|
||||
constructor(key) {
|
||||
this.key = key;
|
||||
}
|
||||
async regeo(params) {
|
||||
const instance = MapWorldSDK.getInstance(this.key);
|
||||
return await instance.regeo(params);
|
||||
}
|
||||
async geo(params) {
|
||||
const instance = MapWorldSDK.getInstance(this.key);
|
||||
const { name, areaId } = params;
|
||||
const result = await instance.geo(name, areaId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
export interface MapService {
|
||||
regeo: (param: {
|
||||
regeo: (params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}) => Promise<{
|
||||
poiName: string;
|
||||
areaId: string;
|
||||
}>;
|
||||
geo: (param: {
|
||||
geo: (params: {
|
||||
name: string;
|
||||
areaId?: string;
|
||||
}) => Promise<Array<{
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ export default class AMap implements MapService {
|
|||
type: AmapKeyType;
|
||||
}>);
|
||||
protected getKey(): string;
|
||||
regeo(param: {
|
||||
regeo(params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}): Promise<{
|
||||
poiName: any;
|
||||
areaId: any;
|
||||
}>;
|
||||
geo(param: {
|
||||
geo(params: {
|
||||
name: string;
|
||||
areaId?: string;
|
||||
}): Promise<any>;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
const AmapSDK_1 = tslib_1.__importDefault(require("oak-external-sdk/lib/AmapSDK"));
|
||||
const AMap_1 = require("oak-external-sdk/lib/types/AMap");
|
||||
const geo_1 = require("oak-domain/lib/utils/geo");
|
||||
class AMap {
|
||||
keys;
|
||||
index;
|
||||
|
|
@ -26,38 +27,43 @@ class AMap {
|
|||
this.index = (this.index + 1) % this.keys.length;
|
||||
}
|
||||
}
|
||||
async regeo(param) {
|
||||
async regeo(params) {
|
||||
const key = this.getKey();
|
||||
const instance = AmapSDK_1.default.getInstance(key);
|
||||
/**
|
||||
* https://lbs.amap.com/api/webservice/guide/api/georegeo
|
||||
*/
|
||||
const { regeocode } = await instance.regeo(param);
|
||||
const gcj02Tudes = (0, geo_1.wgs84togcj02)([params.longitude, params.latitude]);
|
||||
const { regeocode } = await instance.regeo({
|
||||
longitude: gcj02Tudes[0],
|
||||
latitude: gcj02Tudes[1],
|
||||
});
|
||||
return {
|
||||
poiName: regeocode.formatted_address,
|
||||
areaId: regeocode.addressComponent.towncode,
|
||||
};
|
||||
}
|
||||
;
|
||||
async geo(param) {
|
||||
async geo(params) {
|
||||
const key = this.getKey();
|
||||
const instance = AmapSDK_1.default.getInstance(key);
|
||||
/**
|
||||
* https://lbs.amap.com/api/webservice/guide/api/georegeo
|
||||
*/
|
||||
const { name, areaId } = param;
|
||||
const { name, areaId } = params;
|
||||
const { geocodes } = await instance.geocode({
|
||||
address: name,
|
||||
city: areaId,
|
||||
});
|
||||
return geocodes.map((ele) => {
|
||||
const { location } = ele;
|
||||
const tudes = location.split(',');
|
||||
const tudes = location.split(',').map((ele) => parseFloat(ele));
|
||||
const wgs84Tudes = (0, geo_1.gcj02towgs84)(tudes);
|
||||
return {
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: parseFloat(tudes[1]),
|
||||
longitude: parseFloat(tudes[0]),
|
||||
longitude: wgs84Tudes[0],
|
||||
latitude: wgs84Tudes[1],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
import { MapService } from "../types/Map";
|
||||
export default class MapWorld implements MapService {
|
||||
private key;
|
||||
constructor(key: string);
|
||||
regeo(params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}): Promise<any>;
|
||||
geo(params: {
|
||||
name: string;
|
||||
areaId?: string;
|
||||
}): Promise<{
|
||||
poiName: string;
|
||||
areaId: string;
|
||||
longitude: number;
|
||||
latitude: number;
|
||||
}[]>;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
const MapWorldSDK_1 = tslib_1.__importDefault(require("oak-external-sdk/lib/MapWorldSDK"));
|
||||
class MapWorld {
|
||||
key;
|
||||
constructor(key) {
|
||||
this.key = key;
|
||||
}
|
||||
async regeo(params) {
|
||||
const instance = MapWorldSDK_1.default.getInstance(this.key);
|
||||
return await instance.regeo(params);
|
||||
}
|
||||
async geo(params) {
|
||||
const instance = MapWorldSDK_1.default.getInstance(this.key);
|
||||
const { name, areaId } = params;
|
||||
const result = await instance.geo(name, areaId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
exports.default = MapWorld;
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
export interface MapService {
|
||||
regeo: (param: {
|
||||
regeo: (params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}) => Promise<{
|
||||
poiName: string;
|
||||
areaId: string;
|
||||
}>;
|
||||
geo: (param: {
|
||||
geo: (params: {
|
||||
name: string;
|
||||
areaId?: string;
|
||||
}) => Promise<Array<{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { MapService } from "../types/Map";
|
|||
import assert from 'assert';
|
||||
import AmapSDK from 'oak-external-sdk/lib/AmapSDK';
|
||||
import { AmapKeyType, WebServiceKeyWeight } from 'oak-external-sdk/lib/types/AMap';
|
||||
import { wgs84togcj02, gcj02towgs84 } from 'oak-domain/lib/utils/geo';
|
||||
|
||||
export default class AMap implements MapService {
|
||||
keys: Array<{
|
||||
|
|
@ -38,7 +39,7 @@ export default class AMap implements MapService {
|
|||
}
|
||||
}
|
||||
|
||||
async regeo(param: {
|
||||
async regeo(params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}) {
|
||||
|
|
@ -48,7 +49,11 @@ export default class AMap implements MapService {
|
|||
/**
|
||||
* https://lbs.amap.com/api/webservice/guide/api/georegeo
|
||||
*/
|
||||
const { regeocode } = await instance.regeo(param)
|
||||
const gcj02Tudes = wgs84togcj02([params.longitude, params.latitude]);
|
||||
const { regeocode } = await instance.regeo({
|
||||
longitude: gcj02Tudes[0],
|
||||
latitude: gcj02Tudes[1],
|
||||
})
|
||||
|
||||
return {
|
||||
poiName: regeocode.formatted_address,
|
||||
|
|
@ -56,14 +61,14 @@ export default class AMap implements MapService {
|
|||
}
|
||||
};
|
||||
|
||||
async geo(param: { name: string; areaId?: string }) {
|
||||
async geo(params: { name: string; areaId?: string }) {
|
||||
const key = this.getKey();
|
||||
const instance = AmapSDK.getInstance(key);
|
||||
|
||||
/**
|
||||
* https://lbs.amap.com/api/webservice/guide/api/georegeo
|
||||
*/
|
||||
const { name, areaId } = param;
|
||||
const { name, areaId } = params;
|
||||
const { geocodes } = await instance.geocode({
|
||||
address: name,
|
||||
city: areaId,
|
||||
|
|
@ -72,12 +77,15 @@ export default class AMap implements MapService {
|
|||
return geocodes.map(
|
||||
(ele: any) => {
|
||||
const { location } = ele;
|
||||
const tudes = location.split(',');
|
||||
const tudes = location.split(',').map(
|
||||
(ele: string) => parseFloat(ele)
|
||||
);
|
||||
const wgs84Tudes = gcj02towgs84(tudes);
|
||||
return {
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: parseFloat(tudes[1]),
|
||||
longitude: parseFloat(tudes[0]),
|
||||
longitude: wgs84Tudes[0],
|
||||
latitude: wgs84Tudes[1],
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
import { MapService } from "../types/Map";
|
||||
import assert from 'assert';
|
||||
import MapWorldSDK from 'oak-external-sdk/lib/MapWorldSDK';
|
||||
import { AmapKeyType, WebServiceKeyWeight } from 'oak-external-sdk/lib/types/AMap';
|
||||
|
||||
export default class MapWorld implements MapService {
|
||||
private key: string;
|
||||
|
||||
constructor(key: string) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
async regeo(params: { latitude: number; longitude: number; }) {
|
||||
const instance = MapWorldSDK.getInstance(this.key);
|
||||
return await instance.regeo(params);
|
||||
}
|
||||
|
||||
async geo(params: { name: string; areaId?: string }) {
|
||||
const instance = MapWorldSDK.getInstance(this.key);
|
||||
|
||||
const { name, areaId} = params;
|
||||
const result = await instance.geo(name, areaId);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity';
|
|||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
|
||||
export interface MapService {
|
||||
regeo: (param: {
|
||||
regeo: (params: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}) => Promise<{
|
||||
|
|
@ -11,7 +11,7 @@ export interface MapService {
|
|||
areaId: string;
|
||||
}>;
|
||||
|
||||
geo: (param: {
|
||||
geo: (params: {
|
||||
name: string;
|
||||
areaId?: string;
|
||||
}) => Promise<
|
||||
|
|
|
|||
Loading…
Reference in New Issue