# Functions

# Graph

Graph(serialized?: Serialized): object

具有深度优先搜索和拓扑排序的图数据结构。

example var graph = Graph() .addEdge("s", "t", 10) .addEdge("s", "y", 5) .addEdge("s", "y", 4) .addEdge("t", "y", 2) .addEdge("y", "t", 3) .addEdge("t", "x", 1) .addEdge("y", "x", 9) .addEdge("y", "z", 2) .addEdge("x", "z", 4) .addEdge("z", "x", 6); var res = graph.shortestPath("s", "z")

# Parameters

Name Type
serialized? Serialized

Returns: object

Name Type
addEdge (u: NodeId, v: NodeId, weight?: EdgeWeight) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
addNode (node: NodeId) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
adjacent (node: NodeId) => NodeId[]
depthFirstSearch (sourceNodes?: NodeId[], includeSourceNodes: boolean, errorOnCycle: boolean) => string[]
deserialize (serialized: Serialized) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
getEdgeWeight (u: NodeId, v: NodeId) => EdgeWeight
hasCycle () => boolean
hasEdge (u: NodeId, v: NodeId) => boolean
indegree (node: NodeId) => number
lowestCommonAncestors (node1: NodeId, node2: NodeId) => string[]
nodes () => NodeId[]
outdegree (node: NodeId) => number
removeEdge (u: NodeId, v: NodeId) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
removeNode (node: NodeId) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
serialize () => Serialized
setEdgeWeight (u: NodeId, v: NodeId, weight: EdgeWeight) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
shortestPath (source: NodeId, destination: NodeId) => string[] & { weight?: number }
topologicalSort (sourceNodes?: NodeId[], includeSourceNodes: boolean) => string[]

# RandomID

RandomID(length?: number): string

生成随机ID

# Parameters

Name Type
length? number

Returns: string


# Scene

Scene(L7: any, map: Map, option?: object): object

L7图层,可参考https://l7.antv.vision/. 返回一个场景对象

# Parameters

Name Type Description
L7 any L7命名空间
map Map
option? object

Returns: object

Name Type
addControl (ctr: any) => void
addFontFace (fontFamily: string, fontPath: string) => void
addIconFont (name: string, fontUnicode: string) => void
addIconFontGlyphs (fontFamily: string, glyphs: any[]) => void
addIconFonts (options: string[][]) => void
addImage (id: string, img: any) => void
addLayer (layer: any) => void
addMarker (marker: any) => void
addMarkerLayer (layer: any) => void
addPopup (popup: any) => void
containerToLngLat (pixel: any) => any
destroy () => void
diasbleShaderPick () => void
enableShaderPick () => void
exportMap (type?: "png" | "jpg") => string
exportPng (type?: "png" | "jpg") => string
fitBounds (bound: any, options?: unknown) => void
getBounds () => any
getCenter (options?: any) => any
getContainer () => null | HTMLElement
getControlByName (name: string) => any
getLayer (id: string) => any
getLayerByName (name: string) => any
getLayers () => any[]
getMapCanvasContainer () => HTMLElement
getMapContainer () => null | HTMLElement
getMapService () => any
getMaxZoom () => number
getMinZoom () => number
getPitch () => number
getPointSizeRange () => Float32Array
getRotation () => number
getServiceContainer () => any
getSize () => [number, number]
getType () => string
getZoom () => number
hasImage (id: string) => boolean
lngLatToContainer (lnglat: any) => any
lngLatToPixel (lnglat: any) => any
off (type: string, handle: (...args: any[]) => void) => void
on (type: string, handle: (...args: any[]) => void) => void
once (type: string, handle: (...args: any[]) => void) => void
panBy (x: number, y: number) => void
panTo (p: any) => void
pixelToLngLat (pixel: any) => any
registerPostProcessingPass (constructor: (...args: any[]) => any, name: string) => void
registerRenderService (render: any) => void
removeAllLayer () => void
removeAllMakers () => void
removeControl (ctr: any) => void
removeImage (id: string) => void
removeLayer (layer: any, parentLayer?: any) => void
removeMarkerLayer (layer: any) => void
render () => void
setBgColor (color: string) => void
setCenter (center: [number, number], options?: any) => void
setEnableRender (flag: boolean) => void
setMapStatus (options: Partial<any>) => void
setMapStyle (style: any) => void
setPitch (pitch: number) => void
setRotation (rotation: number) => void
setZoom (zoom: number) => void
setZoomAndCenter (zoom: number, center: any) => void
zoomIn () => void
zoomOut () => void

# WorkerExpose

WorkerExpose(target: any): void

# Parameters

Name Type
target any

Returns: void


WorkerLink(worker: Worker): any

和一个Worker相关联

# Parameters

Name Type
worker Worker

Returns: any


# WorkerProxy

WorkerProxy(obj: Function | string, funcContext?: Record<string, Function | string>): Function

将独立函数/类移动到工作线程的一种非常简单的方法。 或者,将 worker 中的对象或函数暴露给主线程。 所有调用都是异步的。与 async/await 配合使用效果很好

Example:

function busyAdd(a, b) {
 let st = Date.now();
 while (true) {
   if ((Date.now() - st) > 2000) break;
 }
 return a + b;
}

(async () => {
 let workerAdd = vjmap.WorkerProxy(busyAdd);
 console.log(await workerAdd(10, 20)); //30
 // the busyAdd is executed in a worker so
 // the UI does not get blocked
})();

class Adder {
constructor() {
  this.count = 0;
}
add(a, b) {
 this.count++;
  return a + b;
}
}

(async () => {
let WAdder = vjmap.WorkerProxy(Adder);
let a = await new WAdder(); // instance created/running in worker
console.log(await a.count); // 0
console.log(await a.add(10, 20)); // 30
console.log(await a.count); // 1
})();

// or:
// worker.js

importScripts('https://cdn.jsdelivr.net/npm/moment@2.20.1/moment.min.js', '../dist/workly.js');
function friendlyTime(value) {
return moment(value).calendar(null, {
  sameDay: function (now) {
   if (now - this < 1000 * 60) {
      return "[Just now]";
   } else if (now - this < 1000 * 60 * 60) {
      return "[" + Math.round((now - this) / (1000 * 60)) + " mins ago]";
   } else {
     return '[Today at] LT'
   }
 }
});
}
vjmap.WorkerExpose(friendlyTime);
main.js

(async () => {
let w = vjmap.WorkerProxy("./worker.js");
let now = Date.now();
console.log(now);
console.log(await w(now));
console.log(await w(now - (24 * 60 * 60 * 1000)));
console.log(await w(now - (4 * 24 * 60 * 60 * 1000)));
})();

 function randAdd(a, b) {
     return randInt(a, b)  + 1000; // randInt这个函数是上下文传递进来的
 }

let randAddFunc = vjmap.WorkerProxy(randAdd, {
   randInt: vjmap.randInt // 把主进程库的函数做为上下文传进去
});
console.log(await randAddFunc(100, 300));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

# Parameters

Name Type Description
obj Function | string
funcContext? Record<string, Function | string> 函数上下文,如果传入的obj是函数的话,需要把obj中函数里调用的函数名称和函数方法传进来

Returns: Function


# _getEdgeIntersection

_getEdgeIntersection(a: GeoPoint, b: GeoPoint, code: number, bounds: GeoBounds): GeoPoint

# Parameters

Name Type
a GeoPoint
b GeoPoint
code number
bounds GeoBounds

Returns: GeoPoint


# addScript

addScript(scripts: ScriptDefaultOptions | ScriptDefaultOptions[]): Promise<unknown[]>

将脚本注入. 脚本选项信息: strategy: 用于运行 JavaScript 的策略。可以是injectevalhref。默认自动检测. injectLocation: 用于注入资源的位置的 document.querySelector 参数。默认为 head. async: 异步加载脚本 src: 脚本的来源

method

async

example // you can add multiple loads awit addScript([{ src: "https://code.jquery.com/jquery-3.5.0.js" }, { src: "https://code.jquery.com/jquery-3.2.0.js", async: true }, { src: "https://code.jquery.com/jquery-3.3.0.js", async: true, injectLocation: '#main div.test', }, { src: "https://code.jquery.com/jquery-3.4.0.js", strategy: 'eval', }, { // link tag // css autodetected src: "https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap-grid.min.css", }])

# Parameters

Name Type Description
scripts ScriptDefaultOptions | ScriptDefaultOptions[] Options for a script

Returns: Promise<unknown[]>


# animateVectorLayer

Const animateVectorLayer(map: Map, layerId: string, options?: IAnimateVectorLayerOptions, layerType?: number): IAnimateVectorLayerResult

创建矢量图层动画图层

# Parameters

Name Type Default value Description
map Map - 地图对象
layerId string - 矢量图层id
options IAnimateVectorLayerOptions {} 选项
layerType? number - 图层类型 0 线 1 填充 2 符号点

Returns: IAnimateVectorLayerResult


# applyMixins

applyMixins(derivedCtor: any, baseCtors: any[]): void

Copy methods and properties from one prototype into another.

see https://www.typescriptlang.org/docs/handbook/mixins.html

# Parameters

Name Type Description
derivedCtor any Class to mix methods and properties into.
baseCtors any[] Class to take all methods and properties from.

Returns: void


# applyMixinsWithoutProperties

applyMixinsWithoutProperties(derivedCtor: any, baseCtors: any[]): void

Copy methods from one prototype into another.

see https://www.typescriptlang.org/docs/handbook/mixins.html

# Parameters

Name Type Description
derivedCtor any Class to mix methods into.
baseCtors any[] Class to take all methods from.

Returns: void


# bufferConvexPolygon

bufferConvexPolygon(ring: GeoPoint[], buffer: number): GeoPoint[]

取一个凸环并通过在其周围应用缓冲区将其向外扩展。 此功能假定环是顺时针缠绕的。

# Parameters

Name Type
ring GeoPoint[]
buffer number

Returns: GeoPoint[]


# buildTopoGraph

buildTopoGraph(lines: { id?: string ; points: GeoPoint[] ; weight?: number }[], precision?: number, hasDirection?: boolean): object

根据多条多段线,建立topo

# Parameters

Name Type Description
lines { id?: string ; points: GeoPoint[] ; weight?: number }[] 坐标,请转成几何坐标,再传入
precision? number 误差,小数点后几位, 以为相同, 如果两个点的坐标距离小于此值,则认为是同一个节点
hasDirection? boolean 是否考虑方向

Returns: object

Name Type
graph object
graph.addEdge (u: NodeId, v: NodeId, weight?: EdgeWeight) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
graph.addNode (node: NodeId) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
graph.adjacent (node: NodeId) => NodeId[]
graph.depthFirstSearch (sourceNodes?: NodeId[], includeSourceNodes: boolean, errorOnCycle: boolean) => string[]
graph.deserialize (serialized: Serialized) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
graph.getEdgeWeight (u: NodeId, v: NodeId) => EdgeWeight
graph.hasCycle () => boolean
graph.hasEdge (u: NodeId, v: NodeId) => boolean
graph.indegree (node: NodeId) => number
graph.lowestCommonAncestors (node1: NodeId, node2: NodeId) => string[]
graph.nodes () => NodeId[]
graph.outdegree (node: NodeId) => number
graph.removeEdge (u: NodeId, v: NodeId) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
graph.removeNode (node: NodeId) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
graph.serialize () => Serialized
graph.setEdgeWeight (u: NodeId, v: NodeId, weight: EdgeWeight) => { addNode: (node: string) => ...; removeNode: (node: string) => ...; nodes: () => string[]; adjacent: (node: string) => string[]; addEdge: (u: string, v: string, weight?: number | undefined) => ...; ... 12 more ...; deserialize: (serialized: Serialized) => ...; }
graph.shortestPath (source: NodeId, destination: NodeId) => string[] & { weight?: number }
graph.topologicalSort (sourceNodes?: NodeId[], includeSourceNodes: boolean) => string[]
topo any

, lowestCommonAncestors: (node1: NodeId, node2: NodeId) => NodeId[], shortestPath: (source: NodeId, destination: NodeId) => NodeId[] & {weight?: EdgeWeight}, setEdgeWeight: (u: NodeId, v: NodeId, weight: EdgeWeight) => {topologicalSort: (sourceNodes?: NodeId[], includeSourceNodes?: boolean) => ...[], addNode: (node: NodeId) => any, lowestCommonAncestors: (node1: NodeId, node2: NodeId) => ...[], shortestPath: (source: NodeId, destination: NodeId) => ... & ..., setEdgeWeight: (u: NodeId, v: NodeId, weight: EdgeWeight) => any, adjacent: (node: NodeId) => NodeId[], depthFirstSearch: (sourceNodes?: NodeId[], includeSourceNodes?: boolean, errorOnCycle?: boolean) => ...[], hasCycle: () => boolean, getEdgeWeight: (u: NodeId, v: NodeId) => EdgeWeight, serialize: () => Serialized, removeEdge: (u: NodeId, v: NodeId) => any, ...}, adjacent: (node: NodeId) => NodeId[], depthFirstSearch: (sourceNodes?: NodeId[], includeSourceNodes?: boolean, errorOnCycle?: boolean) => NodeId[], hasCycle: () => boolean, getEdgeWeight: (u: NodeId, v: NodeId) => EdgeWeight, serialize: () => Serialized, removeEdge: (u: NodeId, v: NodeId) => {topologicalSort: (sourceNodes?: NodeId[], includeSourceNodes?: boolean) => ...[], addNode: (node: NodeId) => any, lowestCommonAncestors: (node1: NodeId, node2: NodeId) => ...[], shortestPath: (source: NodeId, destination: NodeId) => ... & ..., setEdgeWeight: (u: NodeId, v: NodeId, weight: EdgeWeight) => any, adjacent: (node: NodeId) => NodeId[], depthFirstSearch: (sourceNodes?: NodeId[], includeSourceNodes?: boolean, errorOnCycle?: boolean) => ...[], hasCycle: () => boolean, getEdgeWeight: (u: NodeId, v: NodeId) => EdgeWeight, serialize: () => Serialized, removeEdge: (u: NodeId, v: NodeId) => any, ...}, ...}}}


# buildTransformer

buildTransformer(src: number[], dest: number[]): undefined | number[]

Usage:

const transformer = buildTransformer(
    [10, 44, 100, 44, 100, 300, 10, 300],
    [50, 54, 130, 14, 140, 330, 14, 220]
);
1
2
3
4

# Parameters

Name Type Description
src number[] source four points, [x0, y0, x1, y1, x2, y2, x3, y3]
dest number[] destination four points, [x0, y0, x1, y1, x2, y2, x3, y3]

Returns: undefined | number[]

transformer If fail, return null/undefined.


# buildTransformerMatrix3d

buildTransformerMatrix3d(src: number[], dest: number[]): undefined | string

透视投影转3d css 矩阵 Usage:

const transformer = buildTransformerMatrix3d(
    [10, 44, 100, 44, 100, 300, 10, 300],
    [50, 54, 130, 14, 140, 330, 14, 220]
);
1
2
3
4

# Parameters

Name Type Description
src number[] source four points, [x0, y0, x1, y1, x2, y2, x3, y3]
dest number[] destination four points, [x0, y0, x1, y1, x2, y2, x3, y3]

Returns: undefined | string


# calcPolygonArea

calcPolygonArea(points: GeoPoint[]): number

计算多边形面积

# Parameters

Name Type
points GeoPoint[]

Returns: number


# calculateSignedArea

calculateSignedArea(ring: GeoPoint[]): number

返回多边形的有符号的面积。正区域为外环,具有顺时针绕组。负区域为内环,按逆时针顺序排列。

# Parameters

Name Type
ring GeoPoint[]

Returns: number


# clipPolygon

clipPolygon(points: GeoPoint[], bounds: GeoBounds): GeoPoint[]

根据范围裁剪多边形

# Parameters

Name Type
points GeoPoint[]
bounds GeoBounds

Returns: GeoPoint[]


# clipSegment

clipSegment(a: GeoPoint, b: GeoPoint, bounds: GeoBounds): GeoPoint[] | Boolean

根据范围裁剪线段

# Parameters

Name Type
a GeoPoint
b GeoPoint
bounds GeoBounds

Returns: GeoPoint[] | Boolean


# cloneDeep

cloneDeep<T>(obj: T): T

Deep clone of object.

Like JSON.parse(JSON.stringify(obj)), but supports basic javascript types (string, number, object), Date and RegExps and cycles.

Throws error if enounters object with prototype assuming that in general class instances cannot be reliably cloned by generic algorithm.

# Type parameters

Name
T

# Parameters

Name Type
obj T

Returns: T


# closestPointOnPolyline

closestPointOnPolyline(p: GeoPoint, points: GeoPoint[]): object

点到多段线的最近点

# Parameters

Name Type
p GeoPoint
points GeoPoint[]

Returns: object

Name Type
closestIndex number
closestLength number
closestPoint GeoPoint
closestPrePointDist number

# closestPointOnPolylines

closestPointOnPolylines(p: GeoPoint, lines: GeoPoint[][]): object

点到多条线的最近点

# Parameters

Name Type
p GeoPoint
lines GeoPoint[][]

Returns: object

Name Type
closestIndex number
closestLength number
closestPoint GeoPoint
closestPointIndex number
closestPrePointDist number

# closestPointOnSegment

closestPointOnSegment(p: GeoPoint, p1: GeoPoint, p2: GeoPoint): GeoPoint

点到线段的最近点

# Parameters

Name Type
p GeoPoint
p1 GeoPoint
p2 GeoPoint

Returns: GeoPoint


# coordTransfromByFourParamter

coordTransfromByFourParamter(pt: GeoPoint, param: { dx: number ; dy: number ; rotate: number ; scale: number }): GeoPoint

通过四参数进行坐标转换

# Parameters

Name Type Description
pt GeoPoint
param object 四参数
param.dx number -
param.dy number -
param.rotate number -
param.scale number -

Returns: GeoPoint


# coordTransfromByInvFourParamter

coordTransfromByInvFourParamter(pt: GeoPoint, param: { dx: number ; dy: number ; rotate: number ; scale: number }): GeoPoint

通过四参数反算进行坐标转换

# Parameters

Name Type Description
pt GeoPoint
param object 四参数
param.dx number -
param.dy number -
param.rotate number -
param.scale number -

Returns: GeoPoint


# coordTransfromGetFourParamter

coordTransfromGetFourParamter(srcArr: GeoPoint[], destArr: GeoPoint[], isSetRotateZero: boolean, isConsiderPointOrder?: boolean): object

坐标转换得到四参数

# Parameters

Name Type Description
srcArr GeoPoint[] 原始点数组
destArr GeoPoint[] 目标点数组
isSetRotateZero boolean 是否设置旋转为零,默认false,如果为true,则只考虑平移和缩放
isConsiderPointOrder? boolean 不考虑点的次序(这样旋转角度方向总是上面,在-180,180之间)

Returns: object

Name Type
dx number
dy number
rotate number
scale number

# createAnimateFillLayer

createAnimateFillLayer(map: Map, path: LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any, options?: IAnimateFillLayerOptions): ICreateFillAnimateLayerResult

创建多边形动画图层

# Parameters

Name Type Default value Description
map Map - 地图对象
path LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any - 线坐标(lngLat)
options IAnimateFillLayerOptions {} 选项

Returns: ICreateFillAnimateLayerResult


# createAnimateImages

createAnimateImages(options?: ICreateAnimateImagesOptions): ImageData[]

创建动画图片集

# Parameters

Name Type Description
options? ICreateAnimateImagesOptions 选项

Returns: ImageData[]


# createAnimateLineLayer

createAnimateLineLayer(map: Map, path: LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any, options?: IAnimateLineLayerOptions): ICreateLineAnimateLayerResult

创建多段线动画图层

# Parameters

Name Type Description
map Map 地图对象
path LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any 线坐标(lngLat)
options? IAnimateLineLayerOptions 选项

Returns: ICreateLineAnimateLayerResult


# createAnimateSymbolLayer

createAnimateSymbolLayer(map: Map, path: PointGeoJsonInput | PointGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike | any, options?: IAnimateSymbolLayerOptions): ICreateSymbolAnimateLayerResult

创建符号动画图层

# Parameters

Name Type Description
map Map 地图对象
path PointGeoJsonInput | PointGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike | any 符号坐标(lngLat)
options? IAnimateSymbolLayerOptions 选项

Returns: ICreateSymbolAnimateLayerResult


# createAntPathAnimateImages

createAntPathAnimateImages(options?: ICreateAntPathAnimateLineLayerOptions): ImageData[]

创建蚂蚁线动画图像集

# Parameters

Name Type Description
options? ICreateAntPathAnimateLineLayerOptions 选项

Returns: ImageData[]


# createAntPathAnimateLineLayer

createAntPathAnimateLineLayer(map: Map, path: LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any, options?: ICreateAntPathAnimateLineLayerOptions): ICreateLineAnimateLayerResult

创建蚂蚁线动画线图层

# Parameters

Name Type Default value Description
map Map - 地图对象
path LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any - 线坐标(lngLat)
options ICreateAntPathAnimateLineLayerOptions {} 选项

Returns: ICreateLineAnimateLayerResult


# createArrowAnimateImages

createArrowAnimateImages(options?: ICreateArrowAnimateLineLayerOptions): ImageData[]

创建箭头动画图像集

# Parameters

Name Type Description
options? ICreateArrowAnimateLineLayerOptions 选项

Returns: ImageData[]


# createArrowAnimateLineLayer

createArrowAnimateLineLayer(map: Map, path: LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any, options?: ICreateArrowAnimateLineLayerOptions): ICreateLineAnimateLayerResult

创建箭头动画线图层

# Parameters

Name Type Description
map Map 地图对象
path LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any 线坐标(lngLat)
options? ICreateArrowAnimateLineLayerOptions 选项

Returns: ICreateLineAnimateLayerResult


# createFrameAnimation

createFrameAnimation(callback: (status: FrameAnimationStatus) => boolean, fps?: number, stopCallBack?: (status: FrameAnimationStatus) => void): FrameAnimation

创建一个 FrameAnimation 对象来启动和停止你的动画功能.

example const count = 0;

const animation = createFrameAnimation(() => { context.clearRect(0, 0, width, height); context.font = "4rem monospace"; context.textAlign = 'center'; context.fillText(count, width / 2, height / 2);

count++; });

animation.start();

# Parameters

Name Type Description
callback (status: FrameAnimationStatus) => boolean 处理动画的回调,如果返回true,表示结束动画,返回false表示继续动画, .
fps? number 一秒运行多少帧,用来控制速度,如为0,则默认为系统帧率
stopCallBack? (status: FrameAnimationStatus) => void 结束动画的回调,参数表示是取消(true),还是正常结束(false)

Returns: FrameAnimation

| boolean}


# createLineGeoJson

createLineGeoJson(input: LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any): GeoJsonGeomertry

创建geoson格式的线

# Parameters

Name Type
input LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any

Returns: GeoJsonGeomertry


# createMarker

createMarker(options?: createMarkerOptions): Marker

创建一个Makrer对象,相当于new Marker()

# Parameters

Name Type
options? createMarkerOptions

Returns: Marker


# createObjectOffset

createObjectOffset(): object

Returns: object

Name Type
data (vertices: any) => any
margin (dist: number) => any
offset (dist: number) => any
offsetLines (dist: number) => any
padding (dist: number) => any

# createObjectPolygonUtil

createObjectPolygonUtil(): object

Returns: object

Name Type
diff (polygonA: Number[][], polygonB: Number[][]) => null | Number[][]
intersection (polygonA: Number[][], polygonB: Number[][]) => null | Number[][]
union (polygonA: Number[][], polygonB: Number[][]) => null | Number[][]

# createPointGeoJson

createPointGeoJson(input: PointGeoJsonInput | PointGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike | any): GeoJsonGeomertry

创建geoson格式的点

# Parameters

Name Type
input PointGeoJsonInput | PointGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike | any

Returns: GeoJsonGeomertry


# createPolygonGeoJson

createPolygonGeoJson(input: LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any): GeoJsonGeomertry

创建geoson格式的多边形

# Parameters

Name Type
input LineGeoJsonInput | LineGeoJsonInput[] | GeoJsonGeomertry | GeoPointLike[] | any

Returns: GeoJsonGeomertry


# degToRad

degToRad(a: number): number

角度转弧度

# Parameters

Name Type
a number

Returns: number


# entColorToHtmlColor

entColorToHtmlColor(color: number | string, darkMode?: boolean, alpha?: number): string

实体颜色转html颜色

# Parameters

Name Type Description
color number | string 实体颜色
darkMode? boolean 样式是否为暗黑框
alpha? number 透明度的值

Returns: string


# equals

equals(a: number, b: number): boolean

Tests whether or not the arguments have approximately the same value, within an absolute or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less than or equal to 1.0, and a relative tolerance is used for larger values)

# Parameters

Name Type Description
a number The first number to test.
b number The second number to test.

Returns: boolean

True if the numbers are approximately equal, false otherwise.


# findShortestPath

findShortestPath(startPoint: GeoPoint, endPoint: GeoPoint, lines: { id?: string ; points: GeoPoint[] ; weight?: number }[], precision?: number, hasDirection?: boolean): { endPoint: { closestIndex: number ; closestLength: number ; closestPoint: GeoPoint ; closestPointIndex: number ; closestPrePointDist: number } ; error: undefined ; route: any[] ; routeDetail: { index: any ; points: any[] ; reverse: boolean = false }[] ; startPoint: { closestIndex: number ; closestLength: number ; closestPoint: GeoPoint ; closestPointIndex: number ; closestPrePointDist: number } } | { endPoint: undefined ; error: any ; route: undefined ; routeDetail: undefined ; startPoint: undefined }

给定所有路线、起始点、终点生成最短路径

# Parameters

Name Type Description
startPoint GeoPoint 起点
endPoint GeoPoint 终点
lines { id?: string ; points: GeoPoint[] ; weight?: number }[] 坐标,请转成几何坐标,再传入
precision? number 误差,小数点后几位, 以为相同, 如果两个点的坐标距离小于此值,则认为是同一个节点
hasDirection? boolean 是否考虑方向

Returns: { endPoint: { closestIndex: number ; closestLength: number ; closestPoint: GeoPoint ; closestPointIndex: number ; closestPrePointDist: number } ; error: undefined ; route: any[] ; routeDetail: { index: any ; points: any[] ; reverse: boolean = false }[] ; startPoint: { closestIndex: number ; closestLength: number ; closestPoint: GeoPoint ; closestPointIndex: number ; closestPrePointDist: number } } | { endPoint: undefined ; error: any ; route: undefined ; routeDetail: undefined ; startPoint: undefined }


# geoBounds

geoBounds(min?: GeoPoint, max?: GeoPoint): GeoBounds

new一个GeoBounds实例

# Parameters

Name Type
min? GeoPoint
max? GeoPoint

Returns: GeoBounds


# geoPoint

geoPoint(input: GeoPointLike): GeoPoint

new一个GeoPoint实例

# Parameters

Name Type
input GeoPointLike

Returns: GeoPoint


# getCircleFeature

getCircleFeature(center: GeoPointLike, radius: number, points?: number, startAngle?: number, endAngle?: number, includeCenterWhenArc?: boolean): GeoJsonGeomertry

得到圆或圆弧的离散化的多边形的geojson的形式

# Parameters

Name Type Default value Description
center GeoPointLike - 中心点
radius number - 半径
points number 360 离散化的个数
startAngle number 0 开始角度
endAngle number 360 结束角度
includeCenterWhenArc boolean true 如果是圆弧时,最后一个点加上中心点

Returns: GeoJsonGeomertry

, type: string, properties: {}}}


# getCirclePolygonCoordinates

getCirclePolygonCoordinates(center: GeoPointLike, radius: number, points?: number, startAngle?: number, endAngle?: number, includeCenterWhenArc?: boolean): number[][]

得到圆或圆弧的离散化的多边形的点

# Parameters

Name Type Default value Description
center GeoPointLike - 中心点
radius number - 半径
points number 360 离散化的个数
startAngle number 0 开始角度
endAngle number 360 结束角度
includeCenterWhenArc boolean true 如果是圆弧时,最后一个点加上中心点

Returns: number[][]


# getEllipseFeature

getEllipseFeature(center: GeoPointLike, majorAxisRadius: number, minorAxisRadius: number, points?: number, startAngle?: number, endAngle?: number, includeCenterWhenArc?: boolean): GeoJsonGeomertry

得到圆或圆弧的离散化的多边形的geojson的形式

# Parameters

Name Type Default value Description
center GeoPointLike - 中心点
majorAxisRadius number - -
minorAxisRadius number - -
points number 360 离散化的个数
startAngle number 0 开始角度
endAngle number 360 结束角度
includeCenterWhenArc boolean true 如果是圆弧时,最后一个点加上中心点

Returns: GeoJsonGeomertry

, type: string, properties: {}}}


# getEllipsePolygonCoordinates

getEllipsePolygonCoordinates(center: GeoPointLike, majorAxisRadius: number, minorAxisRadius: number, points?: number, startAngle?: number, endAngle?: number, includeCenterWhenArc?: boolean): number[][]

得到椭圆或椭圆弧的离散化的多边形的点

# Parameters

Name Type Default value Description
center GeoPointLike - 中心点
majorAxisRadius number - 长轴半径
minorAxisRadius number - 短轴半径
points number 360 离散化的个数
startAngle number 0 开始角度
endAngle number 360 结束角度
includeCenterWhenArc boolean true 如果是椭/圆弧时,最后一个点加上中心点

Returns: number[][]


# getEnvelopBounds

getEnvelopBounds(envelop: string, prj: any): GeoBounds

根据外包矩形创建 GeoBounds.

Example:

const b = vjmap.getEnvelopBounds('POLYGON((3466315.697899 6704304.297588, 3466315.697899 7784496.211226, 4546475.901198 7784496.211226, 4546475.901198 6704304.297588, 3466315.697899 6704304.297588))', prj);
1

# Parameters

Name Type
envelop string
prj any

Returns: GeoBounds


# getGeoBounds

getGeoBounds<T>(data: T | string): GeoBounds

获取一个geojson的

# Type parameters

Name Type
T GeoPoint | Feature<Geometry | GeometryCollection, Properties> | FeatureCollection<Geometry | GeometryCollection, Properties> | Geometry | GeometryCollection | [number, number] | [number, number, number] | { x: number ; y: number ; z?: number } | { lat: number ; lng: number } | { lat: number ; lon: number } | GeoPointLike[]

# Parameters

Name Type Description
data T | string 输入值

Returns: GeoBounds

获取的范围值


# getOptionValue

getOptionValue<T>(a: T): T

Get first defined value.

Specialized "replacement" for a || b || c used frequently to get value from various sources (defaults, configs constants). In contrast to ||, this function provides proper typing for usual use cases (constant as last argument) and correct treatment of null and undefined.

If last parameter is "defined" then return type is T, otherwise return type is T | undefined.

Usage example:

interface Config {
    x?: number;
}
const someConfig: Config = {};
const val: number | undefined = undefined;
const DEFAULT = 5;
const x = getOptionValue(val, someConfig.x, DEFAULT);
    // typeof x === 'number' because DEFAULT is defined
const y = getOptionValue(val, someConfig.x);
    // typeof y === 'number | undefined' because someConfig.x is possibly undefined

# Type parameters

Name
T

# Parameters

Name Type
a T

Returns: T

getOptionValue<T>(a: T | undefined, b: T): T

# Type parameters

Name
T

# Parameters

Name Type
a T | undefined
b T

Returns: T

getOptionValue<T>(a: T | undefined, b: T | undefined, c: T): T

# Type parameters

Name
T

# Parameters

Name Type
a T | undefined
b T | undefined
c T

Returns: T

getOptionValue<T>(a: T | undefined, b: T | undefined, c: T | undefined, d: T): T

# Type parameters

Name
T

# Parameters

Name Type
a T | undefined
b T | undefined
c T | undefined
d T

Returns: T

getOptionValue<T>(...values: (T | undefined)[]): T | undefined

# Type parameters

Name
T

# Parameters

Name Type
...values (T | undefined)[]

Returns: T | undefined


# hexToBinStr

hexToBinStr(strHex: string, isPadding?: boolean, reverse?: boolean): string

十六进制字符串转二进制字符串(可用于协同图形,图层开头显示设置的转换)

# Parameters

Name Type Default value Description
strHex string - 十进制的内容
isPadding boolean true 前面是否自动0,默认true
reverse boolean true 结果倒序,默认true

Returns: string


# htmlColorToEntColor

htmlColorToEntColor(color: string): number

html颜色转实体颜色

# Parameters

Name Type Description
color string html

Returns: number


# interpolateLineRange

interpolateLineRange(points: GeoPointLike[] | any, number: number, isLngLat?: boolean, offsetDist?: number, minGap?: number, includeSrcPoint?: boolean): any[]

# Parameters

Name Type Default value Description
points GeoPointLike[] | any - 要插值的(多段)线的顶点(输入必须为经纬度).
number number - 沿线插入的点数;这包括端点,并且有效最小值为 2(如果给出较小的数字,则仍将返回端点).
isLngLat boolean false 点坐标序列是否是经纬度坐标
offsetDist number 0 一个可选的垂直距离,用于从线段偏移每个点,否则它会位于.
minGap number 0 在后续插值点之间保持可选的最小间隙;如果一组“number”点的后续点之间的投影间隙低于此值,则“number”将减小到合适的值.
includeSrcPoint boolean true 包括原有点

Returns: any[]


# interpolatePointsByRatio

interpolatePointsByRatio(points: GeoPointLike[] | any, ratio: number, isLngLat?: boolean): any[]

通过比例(0-1)的值,得到坐标序列的点坐标的值

# Parameters

Name Type Default value
points GeoPointLike[] | any -
ratio number -
isLngLat boolean false

Returns: any[]


# isClosedPolygon

isClosedPolygon(points: GeoPoint[]): boolean

多边形是否闭合

# Parameters

Name Type
points GeoPoint[]

Returns: boolean


# isCounterClockwise

isCounterClockwise(a: GeoPoint, b: GeoPoint, c: GeoPoint): boolean

指示提供的点是按逆时针(真)还是顺时针(假)顺序排列

# Parameters

Name Type
a GeoPoint
b GeoPoint
c GeoPoint

Returns: boolean


# isGeoPointLike

isGeoPointLike(geoPoint: any): geoPoint is GeoPointLike

A GeoPointLike object, an array of two numbers representing longitude and latitude, or an object with lng and lat or lon and lat properties.

Example:

const center = { lat: 53.3, lng: 13.4 };
mapView.geoCenter = GeoCoordinates.fromLatLng(center);
1
2

# Parameters

Name Type
geoPoint any

Returns: geoPoint is GeoPointLike


# isPointInPolygon

Const isPointInPolygon(pos: GeoPoint, polygon: GeoPoint[]): boolean

判断点是否在多边形内。

# Parameters

Name Type Description
pos GeoPoint
polygon GeoPoint[] 多边形坐标

Returns: boolean


# isZero

isZero(value: number, precision?: number): boolean

判断是否为零

# Parameters

Name Type Description
value number
precision? number 精度,缺省1e-6

Returns: boolean


# kebabCase

Const kebabCase(s: any): any

# Parameters

Name Type
s any

Returns: any


# lineSplit

lineSplit(line: GeoPoint[], splitLine: GeoPoint[], dotErr?: number): GeoPoint[][]

线被另外一条线分开多条线段,返回新的线段

# Parameters

Name Type Description
line GeoPoint[]
splitLine GeoPoint[]
dotErr? number 允许误差的小数点后几位,默认6位

Returns: GeoPoint[][]


# metersPerPixel

metersPerPixel(zoomLevel: number, latitude?: number): number

求不同级级别下,每米表示多少像素

# Parameters

Name Type Description
zoomLevel number 级别从0表示
latitude? number 纬度

Returns: number


# multiLineSplit

multiLineSplit(lines: GeoPoint[][], dotErr?: number): GeoPoint[][]

多条线之间根据交点相互分开,返回相交后的所有线段,请确保每条线段不要自相交

# Parameters

Name Type Description
lines GeoPoint[][]
dotErr? number 允许误差的小数点后几位,默认6位

Returns: GeoPoint[][]


# offsetPointLine

offsetPointLine(points: GeoPoint[], distance: number): any[]

# Parameters

Name Type
points GeoPoint[]
distance number

Returns: any[]


# offsetPoints

offsetPoints(pts: GeoPointLike[], options: { offset: number ; smoothFactor?: number }): any[]

# Parameters

Name Type
pts GeoPointLike[]
options object
options.offset number
options.smoothFactor? number

Returns: any[]


# openMapDarkStyle

openMapDarkStyle(): IMapStyleParam

打开地图的深色背景样式,值为 {backcolor: 0}

Returns: IMapStyleParam


# openMapLightStyle

openMapLightStyle(): IMapStyleParam

打开地图的浅色色背景样式,值为 {backcolor: 0xFFFFFF}

Returns: IMapStyleParam


# pick

pick<T, K>(object: T, props: K[]): Pick<T, K>

Pick props from `object.

Runtime version of Pick<T,K>.

# Type parameters

Name Type
T object
K string | number | symbol

# Parameters

Name Type
object T
props K[]

Returns: Pick<T, K>


# pixelValue

pixelValue(meters: number, zoomLevel: number, latitude?: number): number

不同级别下根据米数来求像素值

# Parameters

Name Type Description
meters number
zoomLevel number 级别从0表示
latitude? number 纬度

Returns: number


# pointToSegmentDistance

pointToSegmentDistance(p: GeoPoint, p1: GeoPoint, p2: GeoPoint): number

点到线段的距离

# Parameters

Name Type
p GeoPoint
p1 GeoPoint
p2 GeoPoint

Returns: number


# polygonCentroid

polygonCentroid(vertices: GeoPoint[]): GeoPoint

根据 [x,y] 坐标列表计算多边形的质心。

# Parameters

Name Type Description
vertices GeoPoint[] 顶点坐标

Returns: GeoPoint


# polygonIsClockwise

polygonIsClockwise(points: GeoPoint[]): boolean

根据格林公式判断多边形是否为顺时针

# Parameters

Name Type
points GeoPoint[]

Returns: boolean

false:逆时针


# polylineMarginToPolygon

polylineMarginToPolygon(pts: GeoPointLike[], options: { arcSegments?: number ; offset: number ; smoothFactor?: number }): any

把多段线往外扩展成多边形

# Parameters

Name Type
pts GeoPointLike[]
options object
options.arcSegments? number
options.offset number
options.smoothFactor? number

Returns: any


# radToDeg

radToDeg(a: number): number

弧度转角度

# Parameters

Name Type
a number

Returns: number


# randInt

randInt(n: number, m: number): number

生成一个区间的随机总数

# Parameters

Name Type
n number
m number

Returns: number


# randomColor

randomColor(): string

生成随机颜色

Returns: string


# segmentIntersect

segmentIntersect(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): { ratio: undefined ; result: string = "COLINEAR"; status: boolean = false; x: undefined ; y: undefined } | { ratio: number ; result: undefined = "COLINEAR"; status: boolean = true; x: number ; y: number }

线段相交

# Parameters

Name Type
x1 number
y1 number
x2 number
y2 number
x3 number
y3 number
x4 number
y4 number

Returns: { ratio: undefined ; result: string = "COLINEAR"; status: boolean = false; x: undefined ; y: undefined } | { ratio: number ; result: undefined = "COLINEAR"; status: boolean = true; x: number ; y: number }

| {result: string, status: boolean} | {x: number, y: number, status: boolean, ratio: number} | {result: string, status: boolean}}


# simplify

simplify(points: GeoPoint[], tolerance?: number): GeoPoint[]

简化点坐标

# Parameters

Name Type
points GeoPoint[]
tolerance? number

Returns: GeoPoint[]


# syncMaps

syncMaps(...args: Map[]): function

同步两张地图的移动。

# Parameters

Name Type
...args Map[]

Returns: () => void


# toRadian

toRadian(a: number): number

Convert Degree To Radian

# Parameters

Name Type Description
a number Angle in Degrees

Returns: number


# upperCamelCase

Const upperCamelCase(s: any): any

# Parameters

Name Type
s any

Returns: any


# utf8ToUnicode

utf8ToUnicode(strUtf8: string): string

utf8转unicode

# Parameters

Name Type Description
strUtf8 string utf8的内容

Returns: string


# vectorContour

vectorContour(featureCollection: FeatureCollection, weight: string, breaks: number[], params?: { alpha?: number ; canvas?: HTMLCanvasElement ; colors?: string[] ; extent?: [number, number, number, number] ; model?: "exponential" | "gaussian" | "spherical" ; sigma2?: number ; xlim?: number ; ylim?: number }): object

生成矢量等值面

# Parameters

Name Type Description
featureCollection FeatureCollection -
weight string -
breaks number[] -
params? object params:{ model:'exponential','gaussian','spherical',三选一,默认exponential sigma2: 0, // sigma2是σ²,对应高斯过程的方差参数,也就是这组数据z的距离,方差参数σ²的似然性反映了高斯过程中的误差,并应手动设置。一般设置为 0 ,其他数值设了可能会出空白图 alpha: 100, // Alpha α对应方差函数的先验值,此参数可能控制钻孔扩散范围,越小范围越大,少量点效果明显,但点多了且分布均匀以后改变该数字即基本无效果了,默认设置为100 canvas: HTMLCanvasElement, // 如果要渲染到画布上填这个 xlim: number, // canvas有效 ylim: number, // canvas有效 colors:string[] // canvas有效 等值面分级区间 }
params.alpha? number -
params.canvas? HTMLCanvasElement -
params.colors? string[] -
params.extent? [number, number, number, number] -
params.model? "exponential" | "gaussian" | "spherical" -
params.sigma2? number -
params.xlim? number -
params.ylim? number -

Returns: object

Name Type
alg? any
contour? FeatureCollection
grid? object
grid.grid number[]
grid.m number
grid.n number
grid.x_resolution number
grid.xlim number
grid.y_resolution number
grid.ylim number
grid.zlim number
variogram? any

# Modules

vjmap / Exports / common