Skip to content

Commit 00cd45f

Browse files
committed
feat(Map): add coordsType props. #340
1 parent ca628f0 commit 00cd45f

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

packages/map/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export default Demo;
259259
| maxZoom | 地图允许展示的最大级别 | `number` | - |
260260
| mapType | 地图类型 | MapType | `BMAP_NORMAL_MAP` |
261261
| mapStyle | 设置地图样式 | `MapStyle` | - |
262+
| coordsType | 指定输入输出的坐标类型 | `CoordsType` | - |
262263
| defaultCursor | 设置地图默认的鼠标指针样式。参数 `cursor` 应符合 CSS 的 `cursor` 属性规范 | `string` | - |
263264
| draggingCursor | 设置拖拽地图时的鼠标指针样式。参数 `cursor` 应符合 CSS 的 `cursor` 属性规范 | `string` | - |
264265
| panorama | 将全景实例与Map类进行绑定 | `Panorama` | - |

packages/map/src/useMap.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ export interface MapChildProps {
2727
export interface UseMap extends MapProps, MapChildProps {}
2828

2929
export function useMap(props: UseMap = {}) {
30-
const { widget, minZoom, maxZoom, mapType, enableHighResolution, enableAutoResize, enableMapClick } = props;
30+
const { widget, minZoom, maxZoom, mapType, coordsType, enableHighResolution, enableAutoResize, enableMapClick } =
31+
props;
3132
const [map, setMap] = useState<BMap.Map>();
3233
const [zoom, setZoom] = useState(props.zoom || 15);
3334
const [container, setContainer] = useState<HTMLDivElement | null | undefined>(props.container);
3435
const { dispatch } = useContext(Context);
3536
useMemo(() => {
3637
if (container && !map && BMap) {
3738
const instance = new BMap.Map(container, {
39+
coordsType: coordsType,
3840
minZoom,
3941
maxZoom,
4042
mapType,

packages/types/src/core.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,23 @@ declare namespace BMap {
469469
* 是否开启底图可点功能
470470
*/
471471
enableMapClick?: boolean;
472+
/**
473+
* 指定输入输出的坐标类型,`BMAP_COORD_GCJ02`为`gcj02`坐标,`BMAP_COORD_BD09`为`bd09`坐标,默认为`BMAP_COORD_BD09`。
474+
* 指定完成后API将以指定的坐标类型处理您传入的坐标
475+
* @link https://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference_3_0.html
476+
*/
477+
coordsType?: CoordsType; //'bd09ll' | 'bd09mc' | 'gcj02' | 'wgs84';
472478
}
479+
/**
480+
* 此常量用于指定输入输出的坐标类型。
481+
* - `BMAP_COORD_GCJ02` 为`gcj02`坐标。
482+
* - `BMAP_COORD_BD09` 为`bd09`坐标。
483+
* - `BMAP_COORD_WGS84` 为`wgs84`坐标。
484+
* - `BMAP_COORD_EPSG3857` 为`epsg3857`坐标。
485+
* - `BMAP_COORD_GCJ02MERCATOR` 为`gcj02mercator`坐标。
486+
* - `BMAP_COORD_MERCATOR` 为`mercator`坐标。
487+
*/
488+
type CoordsType = string;
473489
/**
474490
* 此类代表视野,不可实例化,通过对象字面量形式表示。
475491
*/
@@ -525,3 +541,26 @@ declare namespace BMap {
525541
type MapStyleV2 = { styleJson: MapStyleItem[] } | { styleId: string };
526542
}
527543
declare const BMAP_API_VERSION: BMap.APIVersion;
544+
545+
/**
546+
* 此常量用于指定输入输出的坐标类型。
547+
* - `BMAP_COORD_GCJ02` 为`gcj02`坐标。
548+
* - `BMAP_COORD_BD09` 为`bd09`坐标。
549+
* - `BMAP_COORD_WGS84` 为`wgs84`坐标。
550+
* - `BMAP_COORD_EPSG3857` 为`epsg3857`坐标。
551+
* - `BMAP_COORD_GCJ02MERCATOR` 为`gcj02mercator`坐标。
552+
* - `BMAP_COORD_MERCATOR` 为`mercator`坐标。
553+
*/
554+
555+
/** `BMAP_COORD_GCJ02` 为`gcj02`坐标。 */
556+
declare const BMAP_COORD_GCJ02: BMap.CoordsType;
557+
/** `BMAP_COORD_BD09` 为`bd09`坐标。 */
558+
declare const BMAP_COORD_BD09: BMap.CoordsType;
559+
/** `BMAP_COORD_WGS84` 为`wgs84`坐标。 */
560+
declare const BMAP_COORD_WGS84: BMap.CoordsType;
561+
/** `BMAP_COORD_EPSG3857` 为`epsg3857`坐标。 */
562+
declare const BMAP_COORD_EPSG3857: BMap.CoordsType;
563+
/** `BMAP_COORD_GCJ02MERCATOR` 为`gcj02mercator`坐标。 */
564+
declare const BMAP_COORD_GCJ02MERCATOR: BMap.CoordsType;
565+
/** `BMAP_COORD_MERCATOR` 为`mercator`坐标。 */
566+
declare const BMAP_COORD_MERCATOR: BMap.CoordsType;

0 commit comments

Comments
 (0)