Skip to content

数据类型参考 ​

所有类型均可从 scene-mapping-gis/2d 导入。

本页前半部分是 2D 类型;3D 类型可从 scene-mapping-gis/3d 导入。

坐标 ​

ts
interface TMapPoint {
  lng: number;
  lat: number;
}

type TMapPositionInput = TMapPoint | [number, number] | string;
type TMapBoundsInput = [TMapPoint, TMapPoint];
type TMapProvider = "tianditu" | "osm" | "custom";

字符串坐标格式为 "116.4074,39.9042"。数组统一按 [lng, lat] 解释。

定位参数 ​

ts
interface TMapLocateOptions {
  position?: TMapPositionInput;
  bounds?: TMapBoundsInput;
  zoom?: number;
  fitBoundsOptions?: Leaflet.FitBoundsOptions;
  setViewOptions?: Leaflet.ZoomPanOptions;
}

bounds 存在时优先使用范围定位;否则必须提供 position。

区域数据 ​

ts
interface TMapPolygonData {
  id: string;
  points: TMapPoint[];
  holes?: TMapPoint[][];
  islands?: TMapPoint[][];
  area?: number;
  pathOptions?: Leaflet.PathOptions;
  selectedPathOptions?: Leaflet.PathOptions;
  properties?: Record<string, any>;
}

interface TMapPolygonChangeEvent {
  polygons: TMapPolygonData[];
  allPolygons: TMapPolygonData[];
}

坐标工具 ​

ts
import { normalizePoint, toLngLat, toPoint } from "scene-mapping-gis/2d";

toPoint(116.4, 39.9);                // { lng: 116.4, lat: 39.9 }
normalizePoint([116.4, 39.9]);       // { lng: 116.4, lat: 39.9 }
normalizePoint("116.4,39.9");       // { lng: 116.4, lat: 39.9 }
toLngLat({ lng: 116.4, lat: 39.9 }); // Leaflet.LatLng

输入校验

normalizePoint 只负责格式归一化,不负责范围校验。来自表单或后端的不可信坐标应在业务层验证经度、纬度和有限数值。

3D 坐标 ​

ts
interface CesiumPosition {
  longitude: number;
  latitude: number;
  height?: number;
}

type CesiumPositionInput = CesiumPosition | [number, number, number?];

经纬度和相机姿态对外统一使用角度,高度统一使用米。

3D Marker ​

ts
interface MarkerPoint {
  longitude: number;
  latitude: number;
  height?: number;
  image?: string;
  text?: string;
  labelColor?: string;
  labelStyle?: MarkerLabelStyle;
  id?: string | number;
  [key: string]: any;
}

拾取结果 ​

ts
interface PickResult {
  windowPosition: Cartesian2;
  position?: CesiumPosition;
  pickedEntity?: Entity;
}

点击天空或无法取得地表坐标时,position 可能为 undefined;未命中 Entity 时,pickedEntity 可能为 undefined。