实用工具方法
createMouseTips 跟随鼠标移动的提示 UI
- Globe 对象上已经挂载了一个 MouseTips
typescript
const createMouseTips: (globe: Globe) => MouseTips
export type MouseTips = {
(text: string): void
clear(): void
}PrimitiveAggregation 基础聚合方法
- 只有 MapEntityCollection 图形集合类 可以使用此方法
tar传入图形聚合类, 返回解除聚合方法
typescript
const PrimitiveAggregation: (tar: any) => false | (() => void)SetEntityJump 设置图形跳动
- entity 从 图形对象的
instancesymbol 属性获取 有导出 instance
typescript
/**
*@description 设置Entity跳动
*@description 设置上下跳动,同时设置旋转和跳动时,`旋转要在跳动上面`,否则无效
*@param entity Entity
*@param minHeight 最小搞得
*@param maxHeight 最大高度
*@param speed 速度
*@return 结束跳动函数,传递结束跳动的笛卡尔坐标
*/
function SetEntityJump(entity: Entity, minHeight: number, maxHeight: number, speed: number): ((position?: Cartesian3) => void) | undefinedSetEntityRotate 设置图形旋转
- entity 从 图形对象的
instancesymbol 属性获取 有导出 instance
typescript
/**
*@description 设置Entity对象旋转
*@param entity Entity对象
*@param speed 旋转速度
*@return 取消旋转函数,可传递停止后的航向
*/
function SetEntityRotate(entity: Entity, speed?: number): ((heading?: number) => void) | undefinedChain 责任链类
- 简化代码结构
- 自由组合
typescript
class Chain<T extends any[]>checkHtml 检查是字符串知否存在标签元素
typescript
const checkHtml: (string: string) => booleancond 条件函数 参考 lodash cond 用法
typescript
function cond<R, T extends any[]>(pairs: Array<CondPairUnary<R, T>>): (...Args: T) => R
type CondPairUnary<R, T extends any[]> = [(...val: T) => boolean, (...val: T) => R]debounce 防抖函数
fn要执行的函数wait要延迟的毫秒数options.leading是否先调用一次options.maxWait最大延迟执行时间 毫秒options.trailing最后调用一次
typescript
const debounce: <T extends (...args: any[]) => any>(
fn: T,
wait: number,
options?: {
leading?: boolean
maxWait?: number
trailing?: boolean
}
) => {
(this: any, ...args: Parameters<T>): ReturnType<T>
cancel: () => void
}downloadFile 文件下载(仅限小文件,大文件推荐流式传输)
file要下载的文件,字符串,,Buffer Blob 都可以name文件名称type文件 MIME 类型
typescript
function downloadFile(file: file, name: string, type: string): voidexpandString 字符串工具扩充(可以处理 生僻字,一般 emoji 表情字符)
pointLength获取字符串码点的长度typescript(method) pointLength(str: string): numberpointAt获取对应位置码点的字符typescript(method) pointAt(str: string, index: number): string | undefinedsliceByPoint按码点截取字符串typescript(method) sliceByPoint(str: string, start?: number, end?: number): string
guid guid 生成
typescript
const guid: () => stringTime 时间处理工具对象
formData格式话时间timeDate 对象template字符串模板
typescript/** * @description 格式化日期 时分秒 * @param time 时间对象 * @param template 替换模板 YYYY年 MM月 DD日 HH小时 mm分钟 ss秒 a中午 上午 下午 晚上 * @template :YY对应24 YYYY对应2024 HH 24小时 hh 12小时 M 这种单个的不补零 MM 这种成对的补零 * @return 格式化后的日期字符串 * @example Time.formData(new Date(), 'YYYY年MM月DD日 HH:mm:ss') // 2024年02月02日 17:44:33 * @example Time.formData(new Date(), 'YY-M-DD') // 24-2-02 */ (method) formData(time: Date, template?: string): string
getTag 获取对象标签字符串
typescript
const getTag: (val: any) => stringisBoolean 检查是否是布尔值
typescript
const isBoolean: (value: any) => value is booleanisArray 检查是否是数组
typescript
const isArray: (value: any) => value is any[]isArrayLike 检查是否是类数组
typescript
const isArrayLike: (value: any) => value is { length: number }isArrayLikeObject 检查值是否是类数组对象
typescript
const isArrayLikeObject: (value: any) => value is { length: number }isObject 检查是否是对象,在这里函数不认为是一个对象
typescript
const isObject: <T extends object>(value: any) => value is TisNumber 检查是否是数字
typescript
const isNumber: (value: any) => value is numberisString 检查是否是字符串
typescript
const isString: (value: any) => value is stringisSymbol 检查是否是 symbol
typescript
const isSymbol: (value: any) => value is symbolisFunction 检查是否是函数
typescript
const isFunction: (value: any) => value is (...args: any[]) => anyhas 检查是否是对象本身的属性
typescript
const has: (object: object, key: string | symbol) => booleanhasIn 检查是否是对象本身的属性
typescript
const hasIn: (object: object, key: string | symbol) => booleandefined 检查是否定义
typescript
const defined: <T>(val: T) => val is NonNullable<T>notDefined 检查是否是未定义的
typescript
const notDefined: (a: any) => a is null | undefineddefineValue 检查是否定义并设置默认值
typescript
const defineValue: <T>(val: T, defaultValue: NonNullable<T>) => NonNullable<T>isNaN 检查是否是 NaN
typescript
const isNaN: (value: any) => value is numberisNull 检查是否为 null
typescript
const isNull: (value: any) => value is nulleq 检查两个值是否相等
typescript
const eq: <T>(value: any, other: T) => value is Tintersection 计算连个数组之间的交集
typescript
function intersection<T>(array1: T[], array2: T[]): T[]difference 计算两个数组之间的差集
typescript
function difference<T>(array1: T[], array2: T[]): T[]symmetricDifference 计算数组对称差集
type
function symmetricDifference<T>(array1: T[], array2: T[]): T[]complement 计算连个数组之间的补集
typescript
function complement<T>(array1: T[], array2: T[]): T[]groupBy 数组分组
array要分组的数组key分组的属性
typescript
const groupBy: <T extends object>(array: T[], key: string | symbol) => {}uniq 数组去重
typescript
const uniq: <T>(array: T[]) => T[]CalAreaOfTriangle 计算三角形的面积
- 三角形点位坐标
typescript
const CalAreaOfTriangle: (pos1: Cartesian3, pos2: Cartesian3, pos3: Cartesian3) => numbercheckLngLat 检查经纬度边界范围是否正确
typescript
const checkLngLat: (type: 'lng' | 'lat', degree: number) => booleancomputedCenter 获取两点之间的中心点
- 有两个函数重载
typescript
type Point = { lng: number; lat: number }
export function computedCenter(positions: Array<[number, number, number?]>): { lng: number; lat: number }
export function computedCenter(pos1: Point, pos2: Point): { lng: number; lat: number }computedPolygonCenter 获取多边形中心点
- 有两个函数重载
typescript
export function computedPolygonCenter(points: Array<[number, number, number?]>): { lng: number; lat: number; height: number }
export function computedPolygonCenter(points: Array<{ lng: number; lat: number; height?: number }>): { lng: number; lat: number; height: number }getArcPoints 生成弧形坐标
option.center中心点坐标option.radius半径option.startAngle起始角度 (正北方向为 0 度,顺时针旋转)option.rotationAngle需要旋转的角度option.height高度option.density生成的点数量
typescript
const getArcPoints: (option: {
center: {
lng: number
lat: number
}
radius:
| number
| {
x: number
y: number
}
startAngle: number
rotationAngle: number
height?: number
density?: number
}) => [number, number, (number | undefined)?][]haversine 计算两点之间的距离(米)
lon1经度lat1纬度lon2经度lat2纬度
typescript
function haversine(lon1: number, lat1: number, lon2: number, lat2: number): numbergetIntersectionPoint 判断两条线段是否相交
typescript
type Position = [number, number, number?]
const getIntersectionPoint: (line: [Position, Position], line2: [Position, Position]) => false | number[]isPointInPolygon 判断点是否在多变形内
point点坐标 顺序经度纬度高度polygon面坐标
typescript
function isPointInPolygon(point: [number, number, number?], polygon: [number, number, number?][]): boolean | undefinedisSelfIntersecting 判断是否是自相交面
typescript
const isSelfIntersecting: (polygon: [number, number, number?][]) => booleanmakeUpPoints 对两个经纬度坐标进行补点
typescript
type Coord = { lng: number; lat: number; height?: number }
type MakeUpPointsOptions = {
/** 开始坐标 */
startCoord: Coord
/** 结束坐标 */
endCoord: Coord
/** 补点数量,默认为100个点,如果为0或负数,则不补点 */
num?: number
/** 坐标类型 */
type: 'cartesian3'
}
type MakeUpPointsOptions2 = { type?: 'cartographic' } & Omit<MakeUpPointsOptions, 'type'>
export function makeUpPoints(Otions: MakeUpPointsOptions2): number[][]
export function makeUpPoints(Otions: MakeUpPointsOptions): Cartesian3[]PolygonArea 计算多边形面积
typescript
const PolygonArea: (polygon: [number, number, number?][]) => numbersimplify 坐标简化
points坐标tolerance精度highestQuality是否保留最高精度,默认为 false,保留精度较低的点
typescript
const simplify: (points: [number, number, number?][], tolerance?: number, highestQuality?: boolean) => [number, number, (number | undefined)?][]GeoJson
getCoord 从 geojson 或数组获取点坐标
typescript
interface Feature<G extends Geometry | null = Geometry, P = GeoJsonProperties> extends GeoJsonObject {
type: 'Feature'
geometry: G
id?: string | number | undefined
properties: P
}
function getCoord(coord: Feature<Point, GeoJsonProperties> | Point | Position): PositiongetGeom 得到几何对象
typescript
type GeoJsonProperties = { [name: string]: any } | null
function getGeom<G extends Geometry>(polygon: Feature<G, GeoJsonProperties> | G): Gfeature 生成 feature 对象
typescript
function feature<G extends Geometry, P extends GeoJsonProperties = GeoJsonProperties>(
geom: G | null,
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<G, P>featureCollection 生成 featureCollection 对象
typescript
function featureCollection<G extends Geometry, P extends GeoJsonProperties>(
features: Array<Feature<G, P>>,
options?: {
bbox?: BBox
id?: Id
}
): FeatureCollection<G, P>geometry 创建 geojson 几何体
typescript
function geometry(type: 'Point', coordinates: Position): Point
function geometry(type: 'LineString', coordinates: Position[]): LineString
function geometry(type: 'Polygon', coordinates: Position[][]): Polygon
function geometry(type: 'MultiPoint', coordinates: Position[]): MultiPoint
function geometry(type: 'MultiLineString', coordinates: Position[][]): MultiLineString
function geometry(type: 'MultiPolygon', coordinates: Position[][][]): MultiPolygongeometryCollection 创建多几何体 geojson
typescript
function geometryCollection<P extends GeoJsonProperties>(
geomerties: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>,
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<GeometryCollection, P>pointToGeojson 创建点 geojson
typescript
function pointToGeojson<P extends GeoJsonProperties>(
coord: Position,
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<Point, P>pointsToGeojson 创建多特征点 geojson
typescript
function pointsToGeojson<P extends GeoJsonProperties>(
coord: Position[],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): FeatureCollection<Point, P>multiPointToGeojson 创建多点 geojson
typescript
function multiPointToGeojson<P extends GeoJsonProperties>(
coord: Position[],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<MultiPoint, P>polygonToGeojson 创建面 geojson
typescript
function polygonToGeojson<P extends GeoJsonProperties>(
coord: Position[][],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<Polygon, P>polygonsToGeojson 创建多特征面 geojson
typescript
function polygonsToGeojson<P extends GeoJsonProperties>(
coord: Position[][][],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): FeatureCollection<Polygon, P>multiPolygonToGeojson 创建多面 geojson
typescript
function multiPolygonToGeojson<P extends GeoJsonProperties>(
coord: Position[][][],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<MultiPolygon, P>lineToGeojson 创建线 GeoJson
typescript
function lineToGeojson<P extends GeoJsonProperties>(
coord: Position[],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<LineString, P>linesToGeojson 创建多特征线 geojson
typescript
function linesToGeojson<P extends GeoJsonProperties>(
coord: Position[][],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): FeatureCollection<LineString, P>multiLineToGeojson 创建多线 geojson
typescript
function multiLineToGeojson<P extends GeoJsonProperties>(
coord: Position[][],
properties?: P,
options?: {
bbox?: BBox
id?: Id
}
): Feature<MultiLineString, P>