@antv/l7-utils
Advanced tools
Comparing version 2.21.8 to 2.21.9-beta.0
@@ -5,3 +5,2 @@ export * from './ajax'; | ||
export * from './config'; | ||
export * from './cull'; | ||
export * as DOM from './dom'; | ||
@@ -15,5 +14,5 @@ export * from './env'; | ||
export * from './lru_cache'; | ||
export * from './interface/map'; | ||
export * from './math'; | ||
export * as Satistics from './statistics'; | ||
export * from './tileset-manager'; | ||
export declare function defaultValue(v1: any, v2: any): any; |
@@ -6,3 +6,2 @@ // src/index.ts | ||
export * from "./config"; | ||
export * from "./cull"; | ||
import * as DOM from "./dom"; | ||
@@ -16,3 +15,3 @@ export * from "./env"; | ||
export * from "./lru_cache"; | ||
export * from "./interface/map"; | ||
export * from "./math"; | ||
import * as Satistics from "./statistics"; | ||
@@ -19,0 +18,0 @@ export * from "./tileset-manager"; |
@@ -1,3 +0,2 @@ | ||
import { MapType } from '../interface/map'; | ||
import type { Point } from './interface'; | ||
export declare function arcLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, mapVersion: MapType | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; | ||
export declare function arcLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; |
// src/lineAtOffset/arc.ts | ||
import { amap2Project, amap2UnProject } from "../geo"; | ||
import { MapType } from "../interface/map"; | ||
function arcLineAtOffset(source, target, offset, thetaOffset, mapVersion, segmentNumber = 30, autoFit) { | ||
function arcLineAtOffset(source, target, offset, thetaOffset, segmentNumber = 30, autoFit) { | ||
let pointOffset = offset; | ||
@@ -10,5 +8,5 @@ if (autoFit) { | ||
if (!thetaOffset) { | ||
return interpolate(source, target, pointOffset, 0.314, mapVersion); | ||
return interpolate(source, target, pointOffset, 0.314); | ||
} else { | ||
return interpolate(source, target, pointOffset, thetaOffset, mapVersion); | ||
return interpolate(source, target, pointOffset, thetaOffset); | ||
} | ||
@@ -32,16 +30,7 @@ } | ||
} | ||
function interpolate(source, target, offset, thetaOffset, mapVersion) { | ||
if (mapVersion === MapType["GAODE2.x"]) { | ||
const sourceFlat = amap2Project(source[0], source[1]); | ||
const targetFlat = amap2Project(target[0], target[1]); | ||
const mid = midPoint(sourceFlat, targetFlat, thetaOffset); | ||
const x = [sourceFlat[0], mid[0], targetFlat[0]]; | ||
const y = [sourceFlat[1], mid[1], targetFlat[1]]; | ||
return [...amap2UnProject(bezier3(x, offset), bezier3(y, offset)), 0]; | ||
} else { | ||
const mid = midPoint(source, target, thetaOffset); | ||
const x = [source[0], mid[0], target[0]]; | ||
const y = [source[1], mid[1], target[1]]; | ||
return [bezier3(x, offset), bezier3(y, offset), 0]; | ||
} | ||
function interpolate(source, target, offset, thetaOffset) { | ||
const mid = midPoint(source, target, thetaOffset); | ||
const x = [source[0], mid[0], target[0]]; | ||
const y = [source[1], mid[1], target[1]]; | ||
return [bezier3(x, offset), bezier3(y, offset), 0]; | ||
} | ||
@@ -48,0 +37,0 @@ export { |
@@ -1,4 +0,3 @@ | ||
import type { MapType } from '../interface/map'; | ||
import type { Point } from './interface'; | ||
export declare function greatCircleLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, mapVersion: MapType | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; | ||
export declare function interpolate(s: Point, t: Point, offset: number, mapVersion: string | undefined): number[]; | ||
export declare function greatCircleLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; | ||
export declare function interpolate(s: Point, t: Point, offset: number): number[]; |
// src/lineAtOffset/greatCircle.ts | ||
import { degreesToRadians, radiansToDegrees } from "@turf/helpers"; | ||
import { calDistance } from "../geo"; | ||
function greatCircleLineAtOffset(source, target, offset, thetaOffset, mapVersion, segmentNumber = 30, autoFit) { | ||
function greatCircleLineAtOffset(source, target, offset, thetaOffset, segmentNumber = 30, autoFit) { | ||
let pointOffset = offset; | ||
@@ -9,18 +8,4 @@ if (autoFit) { | ||
} | ||
return interpolate(source, target, pointOffset, mapVersion); | ||
return interpolate(source, target, pointOffset); | ||
} | ||
function midPoint(source, target) { | ||
const center = [target[0] - source[0], target[1] - source[1]]; | ||
const r = calDistance(center, [0, 0]); | ||
const theta = Math.atan2(center[1], center[0]); | ||
const thetaOffset = 0.314; | ||
const r2 = r / 2 / Math.cos(thetaOffset); | ||
const theta2 = theta + thetaOffset; | ||
const mid = [r2 * Math.cos(theta2) + source[0], r2 * Math.sin(theta2) + source[1]]; | ||
return mid; | ||
} | ||
function bezier3(arr, t) { | ||
const ut = 1 - t; | ||
return (arr[0] * ut + arr[1] * t) * ut + (arr[1] * ut + arr[2] * t) * t; | ||
} | ||
function getAngularDist(source, target) { | ||
@@ -32,32 +17,25 @@ const delta = [source[0] - target[0], source[1] - target[1]]; | ||
} | ||
function interpolate(s, t, offset, mapVersion) { | ||
function interpolate(s, t, offset) { | ||
const source = [degreesToRadians(s[0]), degreesToRadians(s[1])]; | ||
const target = [degreesToRadians(t[0]), degreesToRadians(t[1])]; | ||
if (mapVersion === "GAODE2.x") { | ||
const mid = midPoint(source, target); | ||
const x = [source[0], mid[0], target[0]]; | ||
const y = [source[1], mid[1], target[1]]; | ||
return [bezier3(x, offset), bezier3(y, offset), 0]; | ||
} else { | ||
const angularDist = getAngularDist(source, target); | ||
if (Math.abs(angularDist - Math.PI) < 1e-3) { | ||
return [ | ||
(1 - offset) * source[0] + offset * target[0], | ||
(1 - offset) * source[1] + offset * target[1] | ||
]; | ||
} | ||
const a = Math.sin((1 - offset) * angularDist) / Math.sin(angularDist); | ||
const b = Math.sin(offset * angularDist) / Math.sin(angularDist); | ||
const sinSource = [Math.sin(source[0]), Math.sin(source[1])]; | ||
const cosSource = [Math.cos(source[0]), Math.cos(source[1])]; | ||
const sinTarget = [Math.sin(target[0]), Math.sin(target[1])]; | ||
const cosTarget = [Math.cos(target[0]), Math.cos(target[1])]; | ||
const x = a * cosSource[1] * cosSource[0] + b * cosTarget[1] * cosTarget[0]; | ||
const y = a * cosSource[1] * sinSource[0] + b * cosTarget[1] * sinTarget[0]; | ||
const z = a * sinSource[1] + b * sinTarget[1]; | ||
const angularDist = getAngularDist(source, target); | ||
if (Math.abs(angularDist - Math.PI) < 1e-3) { | ||
return [ | ||
radiansToDegrees(Math.atan2(y, x)), | ||
radiansToDegrees(Math.atan2(z, Math.sqrt(x * x + y * y))) | ||
(1 - offset) * source[0] + offset * target[0], | ||
(1 - offset) * source[1] + offset * target[1] | ||
]; | ||
} | ||
const a = Math.sin((1 - offset) * angularDist) / Math.sin(angularDist); | ||
const b = Math.sin(offset * angularDist) / Math.sin(angularDist); | ||
const sinSource = [Math.sin(source[0]), Math.sin(source[1])]; | ||
const cosSource = [Math.cos(source[0]), Math.cos(source[1])]; | ||
const sinTarget = [Math.sin(target[0]), Math.sin(target[1])]; | ||
const cosTarget = [Math.cos(target[0]), Math.cos(target[1])]; | ||
const x = a * cosSource[1] * cosSource[0] + b * cosTarget[1] * cosTarget[0]; | ||
const y = a * cosSource[1] * sinSource[0] + b * cosTarget[1] * sinTarget[0]; | ||
const z = a * sinSource[1] + b * sinTarget[1]; | ||
return [ | ||
radiansToDegrees(Math.atan2(y, x)), | ||
radiansToDegrees(Math.atan2(z, Math.sqrt(x * x + y * y))) | ||
]; | ||
} | ||
@@ -64,0 +42,0 @@ export { |
@@ -45,3 +45,3 @@ var __defProp = Object.defineProperty; | ||
function getLineOffsetPosition(feature, option) { | ||
const { offset, shape, thetaOffset, mapVersion, segmentNumber = 30, autoFit = true } = option; | ||
const { offset, shape, thetaOffset, segmentNumber = 30, autoFit = true } = option; | ||
const { coordinates } = feature; | ||
@@ -70,3 +70,2 @@ if (shape === "line") { | ||
linetheatOffset, | ||
mapVersion, | ||
segmentNumber, | ||
@@ -73,0 +72,0 @@ autoFit |
@@ -1,2 +0,1 @@ | ||
import type { MapType } from '../interface/map'; | ||
export type Source = any; | ||
@@ -9,3 +8,2 @@ export type ILineShape = 'line' | 'arc' | 'arc3d' | 'greatcircle'; | ||
shape: ILineShape; | ||
mapVersion: MapType; | ||
thetaOffset?: IThetaOffset; | ||
@@ -12,0 +10,0 @@ featureId?: number | undefined; |
@@ -69,2 +69,3 @@ /// <reference types="lodash" /> | ||
camelCase: (string?: string | undefined) => string; | ||
uniqueId: (prefix?: string | undefined) => string; | ||
}; |
@@ -23,2 +23,3 @@ // src/lodash-adapter.ts | ||
import camelCase from "lodash/camelCase"; | ||
import uniqueId from "lodash/uniqueId"; | ||
var lodashUtil = { | ||
@@ -45,3 +46,4 @@ isNil, | ||
isUndefined, | ||
camelCase | ||
camelCase, | ||
uniqueId | ||
}; | ||
@@ -48,0 +50,0 @@ export { |
export declare function isNumber(n: any): boolean; | ||
/** | ||
* Calculate the low part of a WebGL 64 bit float | ||
* @param x {number} - the input float number | ||
* @returns {number} - the lower 32 bit of the number | ||
*/ | ||
export declare function fp64LowPart(x: number): number; |
@@ -5,4 +5,8 @@ // src/math.ts | ||
} | ||
function fp64LowPart(x) { | ||
return x - Math.fround(x); | ||
} | ||
export { | ||
fp64LowPart, | ||
isNumber | ||
}; |
@@ -5,3 +5,2 @@ export * from './ajax'; | ||
export * from './config'; | ||
export * from './cull'; | ||
export * as DOM from './dom'; | ||
@@ -15,5 +14,5 @@ export * from './env'; | ||
export * from './lru_cache'; | ||
export * from './interface/map'; | ||
export * from './math'; | ||
export * as Satistics from './statistics'; | ||
export * from './tileset-manager'; | ||
export declare function defaultValue(v1: any, v2: any): any; |
@@ -45,3 +45,2 @@ var __create = Object.create; | ||
__reExport(src_exports, require("./config"), module.exports); | ||
__reExport(src_exports, require("./cull"), module.exports); | ||
var DOM = __toESM(require("./dom")); | ||
@@ -55,3 +54,3 @@ __reExport(src_exports, require("./env"), module.exports); | ||
__reExport(src_exports, require("./lru_cache"), module.exports); | ||
__reExport(src_exports, require("./interface/map"), module.exports); | ||
__reExport(src_exports, require("./math"), module.exports); | ||
var Satistics = __toESM(require("./statistics")); | ||
@@ -77,3 +76,2 @@ __reExport(src_exports, require("./tileset-manager"), module.exports); | ||
...require("./config"), | ||
...require("./cull"), | ||
...require("./env"), | ||
@@ -85,4 +83,4 @@ ...require("./event"), | ||
...require("./lru_cache"), | ||
...require("./interface/map"), | ||
...require("./math"), | ||
...require("./tileset-manager") | ||
}); |
@@ -1,3 +0,2 @@ | ||
import { MapType } from '../interface/map'; | ||
import type { Point } from './interface'; | ||
export declare function arcLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, mapVersion: MapType | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; | ||
export declare function arcLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; |
@@ -25,5 +25,3 @@ var __defProp = Object.defineProperty; | ||
module.exports = __toCommonJS(arc_exports); | ||
var import_geo = require("../geo"); | ||
var import_map = require("../interface/map"); | ||
function arcLineAtOffset(source, target, offset, thetaOffset, mapVersion, segmentNumber = 30, autoFit) { | ||
function arcLineAtOffset(source, target, offset, thetaOffset, segmentNumber = 30, autoFit) { | ||
let pointOffset = offset; | ||
@@ -34,5 +32,5 @@ if (autoFit) { | ||
if (!thetaOffset) { | ||
return interpolate(source, target, pointOffset, 0.314, mapVersion); | ||
return interpolate(source, target, pointOffset, 0.314); | ||
} else { | ||
return interpolate(source, target, pointOffset, thetaOffset, mapVersion); | ||
return interpolate(source, target, pointOffset, thetaOffset); | ||
} | ||
@@ -56,16 +54,7 @@ } | ||
} | ||
function interpolate(source, target, offset, thetaOffset, mapVersion) { | ||
if (mapVersion === import_map.MapType["GAODE2.x"]) { | ||
const sourceFlat = (0, import_geo.amap2Project)(source[0], source[1]); | ||
const targetFlat = (0, import_geo.amap2Project)(target[0], target[1]); | ||
const mid = midPoint(sourceFlat, targetFlat, thetaOffset); | ||
const x = [sourceFlat[0], mid[0], targetFlat[0]]; | ||
const y = [sourceFlat[1], mid[1], targetFlat[1]]; | ||
return [...(0, import_geo.amap2UnProject)(bezier3(x, offset), bezier3(y, offset)), 0]; | ||
} else { | ||
const mid = midPoint(source, target, thetaOffset); | ||
const x = [source[0], mid[0], target[0]]; | ||
const y = [source[1], mid[1], target[1]]; | ||
return [bezier3(x, offset), bezier3(y, offset), 0]; | ||
} | ||
function interpolate(source, target, offset, thetaOffset) { | ||
const mid = midPoint(source, target, thetaOffset); | ||
const x = [source[0], mid[0], target[0]]; | ||
const y = [source[1], mid[1], target[1]]; | ||
return [bezier3(x, offset), bezier3(y, offset), 0]; | ||
} | ||
@@ -72,0 +61,0 @@ // Annotate the CommonJS export names for ESM import in node: |
@@ -1,4 +0,3 @@ | ||
import type { MapType } from '../interface/map'; | ||
import type { Point } from './interface'; | ||
export declare function greatCircleLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, mapVersion: MapType | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; | ||
export declare function interpolate(s: Point, t: Point, offset: number, mapVersion: string | undefined): number[]; | ||
export declare function greatCircleLineAtOffset(source: Point, target: Point, offset: number, thetaOffset: number | undefined, segmentNumber: number | undefined, autoFit: boolean): number[]; | ||
export declare function interpolate(s: Point, t: Point, offset: number): number[]; |
@@ -27,4 +27,3 @@ var __defProp = Object.defineProperty; | ||
var import_helpers = require("@turf/helpers"); | ||
var import_geo = require("../geo"); | ||
function greatCircleLineAtOffset(source, target, offset, thetaOffset, mapVersion, segmentNumber = 30, autoFit) { | ||
function greatCircleLineAtOffset(source, target, offset, thetaOffset, segmentNumber = 30, autoFit) { | ||
let pointOffset = offset; | ||
@@ -34,18 +33,4 @@ if (autoFit) { | ||
} | ||
return interpolate(source, target, pointOffset, mapVersion); | ||
return interpolate(source, target, pointOffset); | ||
} | ||
function midPoint(source, target) { | ||
const center = [target[0] - source[0], target[1] - source[1]]; | ||
const r = (0, import_geo.calDistance)(center, [0, 0]); | ||
const theta = Math.atan2(center[1], center[0]); | ||
const thetaOffset = 0.314; | ||
const r2 = r / 2 / Math.cos(thetaOffset); | ||
const theta2 = theta + thetaOffset; | ||
const mid = [r2 * Math.cos(theta2) + source[0], r2 * Math.sin(theta2) + source[1]]; | ||
return mid; | ||
} | ||
function bezier3(arr, t) { | ||
const ut = 1 - t; | ||
return (arr[0] * ut + arr[1] * t) * ut + (arr[1] * ut + arr[2] * t) * t; | ||
} | ||
function getAngularDist(source, target) { | ||
@@ -57,32 +42,25 @@ const delta = [source[0] - target[0], source[1] - target[1]]; | ||
} | ||
function interpolate(s, t, offset, mapVersion) { | ||
function interpolate(s, t, offset) { | ||
const source = [(0, import_helpers.degreesToRadians)(s[0]), (0, import_helpers.degreesToRadians)(s[1])]; | ||
const target = [(0, import_helpers.degreesToRadians)(t[0]), (0, import_helpers.degreesToRadians)(t[1])]; | ||
if (mapVersion === "GAODE2.x") { | ||
const mid = midPoint(source, target); | ||
const x = [source[0], mid[0], target[0]]; | ||
const y = [source[1], mid[1], target[1]]; | ||
return [bezier3(x, offset), bezier3(y, offset), 0]; | ||
} else { | ||
const angularDist = getAngularDist(source, target); | ||
if (Math.abs(angularDist - Math.PI) < 1e-3) { | ||
return [ | ||
(1 - offset) * source[0] + offset * target[0], | ||
(1 - offset) * source[1] + offset * target[1] | ||
]; | ||
} | ||
const a = Math.sin((1 - offset) * angularDist) / Math.sin(angularDist); | ||
const b = Math.sin(offset * angularDist) / Math.sin(angularDist); | ||
const sinSource = [Math.sin(source[0]), Math.sin(source[1])]; | ||
const cosSource = [Math.cos(source[0]), Math.cos(source[1])]; | ||
const sinTarget = [Math.sin(target[0]), Math.sin(target[1])]; | ||
const cosTarget = [Math.cos(target[0]), Math.cos(target[1])]; | ||
const x = a * cosSource[1] * cosSource[0] + b * cosTarget[1] * cosTarget[0]; | ||
const y = a * cosSource[1] * sinSource[0] + b * cosTarget[1] * sinTarget[0]; | ||
const z = a * sinSource[1] + b * sinTarget[1]; | ||
const angularDist = getAngularDist(source, target); | ||
if (Math.abs(angularDist - Math.PI) < 1e-3) { | ||
return [ | ||
(0, import_helpers.radiansToDegrees)(Math.atan2(y, x)), | ||
(0, import_helpers.radiansToDegrees)(Math.atan2(z, Math.sqrt(x * x + y * y))) | ||
(1 - offset) * source[0] + offset * target[0], | ||
(1 - offset) * source[1] + offset * target[1] | ||
]; | ||
} | ||
const a = Math.sin((1 - offset) * angularDist) / Math.sin(angularDist); | ||
const b = Math.sin(offset * angularDist) / Math.sin(angularDist); | ||
const sinSource = [Math.sin(source[0]), Math.sin(source[1])]; | ||
const cosSource = [Math.cos(source[0]), Math.cos(source[1])]; | ||
const sinTarget = [Math.sin(target[0]), Math.sin(target[1])]; | ||
const cosTarget = [Math.cos(target[0]), Math.cos(target[1])]; | ||
const x = a * cosSource[1] * cosSource[0] + b * cosTarget[1] * cosTarget[0]; | ||
const y = a * cosSource[1] * sinSource[0] + b * cosTarget[1] * sinTarget[0]; | ||
const z = a * sinSource[1] + b * sinTarget[1]; | ||
return [ | ||
(0, import_helpers.radiansToDegrees)(Math.atan2(y, x)), | ||
(0, import_helpers.radiansToDegrees)(Math.atan2(z, Math.sqrt(x * x + y * y))) | ||
]; | ||
} | ||
@@ -89,0 +67,0 @@ // Annotate the CommonJS export names for ESM import in node: |
@@ -66,3 +66,3 @@ var __defProp = Object.defineProperty; | ||
function getLineOffsetPosition(feature, option) { | ||
const { offset, shape, thetaOffset, mapVersion, segmentNumber = 30, autoFit = true } = option; | ||
const { offset, shape, thetaOffset, segmentNumber = 30, autoFit = true } = option; | ||
const { coordinates } = feature; | ||
@@ -91,3 +91,2 @@ if (shape === "line") { | ||
linetheatOffset, | ||
mapVersion, | ||
segmentNumber, | ||
@@ -94,0 +93,0 @@ autoFit |
@@ -1,2 +0,1 @@ | ||
import type { MapType } from '../interface/map'; | ||
export type Source = any; | ||
@@ -9,3 +8,2 @@ export type ILineShape = 'line' | 'arc' | 'arc3d' | 'greatcircle'; | ||
shape: ILineShape; | ||
mapVersion: MapType; | ||
thetaOffset?: IThetaOffset; | ||
@@ -12,0 +10,0 @@ featureId?: number | undefined; |
@@ -69,2 +69,3 @@ /// <reference types="lodash" /> | ||
camelCase: (string?: string | undefined) => string; | ||
uniqueId: (prefix?: string | undefined) => string; | ||
}; |
@@ -56,2 +56,3 @@ var __create = Object.create; | ||
var import_camelCase = __toESM(require("lodash/camelCase")); | ||
var import_uniqueId = __toESM(require("lodash/uniqueId")); | ||
var lodashUtil = { | ||
@@ -78,3 +79,4 @@ isNil: import_isNil.default, | ||
isUndefined: import_isUndefined.default, | ||
camelCase: import_camelCase.default | ||
camelCase: import_camelCase.default, | ||
uniqueId: import_uniqueId.default | ||
}; | ||
@@ -81,0 +83,0 @@ // Annotate the CommonJS export names for ESM import in node: |
export declare function isNumber(n: any): boolean; | ||
/** | ||
* Calculate the low part of a WebGL 64 bit float | ||
* @param x {number} - the input float number | ||
* @returns {number} - the lower 32 bit of the number | ||
*/ | ||
export declare function fp64LowPart(x: number): number; |
@@ -22,2 +22,3 @@ var __defProp = Object.defineProperty; | ||
__export(math_exports, { | ||
fp64LowPart: () => fp64LowPart, | ||
isNumber: () => isNumber | ||
@@ -29,5 +30,9 @@ }); | ||
} | ||
function fp64LowPart(x) { | ||
return x - Math.fround(x); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
fp64LowPart, | ||
isNumber | ||
}); |
{ | ||
"name": "@antv/l7-utils", | ||
"version": "2.21.8", | ||
"version": "2.21.9-beta.0", | ||
"description": "Utils for L7", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
232627
114
6769
2