@bitbaum/geo-kit 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -2
- package/dist/map/camera.d.ts +86 -0
- package/dist/map/camera.js +118 -0
- package/dist/map/controller.d.ts +72 -0
- package/dist/map/controller.js +344 -0
- package/dist/map/cull.d.ts +28 -0
- package/dist/map/cull.js +46 -0
- package/dist/map/index.d.ts +17 -0
- package/dist/map/index.js +17 -0
- package/dist/map/motion.d.ts +29 -0
- package/dist/map/motion.js +58 -0
- package/dist/map/paint.d.ts +66 -0
- package/dist/map/paint.js +174 -0
- package/dist/map/pick.d.ts +17 -0
- package/dist/map/pick.js +34 -0
- package/dist/map/shapes.d.ts +59 -0
- package/dist/map/shapes.js +105 -0
- package/dist/map/trace.d.ts +37 -0
- package/dist/map/trace.js +73 -0
- package/package.json +27 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The map's fast path. d3's projection stream spends several sin/cos per
|
|
3
|
+
* vertex per frame (rotate, clip, project); on a phone that is the frame
|
|
4
|
+
* budget. Here every vertex is turned into a unit vector once, at load, and a
|
|
5
|
+
* frame is three dot products per vertex against the view's basis — the same
|
|
6
|
+
* orthographic projection d3 draws (tested against it), without the trig.
|
|
7
|
+
*
|
|
8
|
+
* Behind the globe a polygon's vertices are pulled onto the limb, so a
|
|
9
|
+
* country crossing the horizon fills up to the edge; a line breaks there.
|
|
10
|
+
* Picking and one-off outlines still use d3 (pick.ts, paint.ts).
|
|
11
|
+
*/
|
|
12
|
+
import type { Position } from "geojson";
|
|
13
|
+
/** x, y, z triples of unit vectors. */
|
|
14
|
+
export type Packed = Float64Array;
|
|
15
|
+
export declare function pack(coords: Position[]): Packed;
|
|
16
|
+
/** The view's basis: east and north on screen, forward toward the reader. */
|
|
17
|
+
export interface Basis {
|
|
18
|
+
e: [number, number, number];
|
|
19
|
+
n: [number, number, number];
|
|
20
|
+
f: [number, number, number];
|
|
21
|
+
cx: number;
|
|
22
|
+
cy: number;
|
|
23
|
+
r: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function basisOf(center: [number, number], cx: number, cy: number, r: number): Basis;
|
|
26
|
+
/** [x, y, depth]: depth < 0 is behind the globe. For tests and markers. */
|
|
27
|
+
export declare function project(b: Basis, lon: number, lat: number): [number, number, number];
|
|
28
|
+
interface Pen {
|
|
29
|
+
moveTo(x: number, y: number): void;
|
|
30
|
+
lineTo(x: number, y: number): void;
|
|
31
|
+
closePath(): void;
|
|
32
|
+
}
|
|
33
|
+
/** A closed ring; vertices behind the globe are pulled onto the limb. */
|
|
34
|
+
export declare function traceRing(pen: Pen, ring: Packed, b: Basis): void;
|
|
35
|
+
/** An open line; it breaks where it passes behind the globe. */
|
|
36
|
+
export declare function traceLine(pen: Pen, line: Packed, b: Basis): void;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const RAD = Math.PI / 180;
|
|
2
|
+
export function pack(coords) {
|
|
3
|
+
const out = new Float64Array(coords.length * 3);
|
|
4
|
+
coords.forEach(([lon = 0, lat = 0], i) => {
|
|
5
|
+
const l = lon * RAD;
|
|
6
|
+
const p = lat * RAD;
|
|
7
|
+
out[i * 3] = Math.cos(p) * Math.cos(l);
|
|
8
|
+
out[i * 3 + 1] = Math.cos(p) * Math.sin(l);
|
|
9
|
+
out[i * 3 + 2] = Math.sin(p);
|
|
10
|
+
});
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
export function basisOf(center, cx, cy, r) {
|
|
14
|
+
const l = center[0] * RAD;
|
|
15
|
+
const p = center[1] * RAD;
|
|
16
|
+
return {
|
|
17
|
+
e: [-Math.sin(l), Math.cos(l), 0],
|
|
18
|
+
n: [-Math.sin(p) * Math.cos(l), -Math.sin(p) * Math.sin(l), Math.cos(p)],
|
|
19
|
+
f: [Math.cos(p) * Math.cos(l), Math.cos(p) * Math.sin(l), Math.sin(p)],
|
|
20
|
+
cx,
|
|
21
|
+
cy,
|
|
22
|
+
r,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** [x, y, depth]: depth < 0 is behind the globe. For tests and markers. */
|
|
26
|
+
export function project(b, lon, lat) {
|
|
27
|
+
const [x = 0, y = 0, z = 0] = pack([[lon, lat]]);
|
|
28
|
+
const u = b.e[0] * x + b.e[1] * y + b.e[2] * z;
|
|
29
|
+
const v = b.n[0] * x + b.n[1] * y + b.n[2] * z;
|
|
30
|
+
return [b.cx + b.r * u, b.cy - b.r * v, b.f[0] * x + b.f[1] * y + b.f[2] * z];
|
|
31
|
+
}
|
|
32
|
+
/** A closed ring; vertices behind the globe are pulled onto the limb. */
|
|
33
|
+
export function traceRing(pen, ring, b) {
|
|
34
|
+
const { e, n, f, cx, cy, r } = b;
|
|
35
|
+
for (let i = 0; i < ring.length; i += 3) {
|
|
36
|
+
const x = ring[i];
|
|
37
|
+
const y = ring[i + 1];
|
|
38
|
+
const z = ring[i + 2];
|
|
39
|
+
let u = e[0] * x + e[1] * y + e[2] * z;
|
|
40
|
+
let v = n[0] * x + n[1] * y + n[2] * z;
|
|
41
|
+
if (f[0] * x + f[1] * y + f[2] * z < 0) {
|
|
42
|
+
const m = Math.hypot(u, v) || 1;
|
|
43
|
+
u /= m;
|
|
44
|
+
v /= m;
|
|
45
|
+
}
|
|
46
|
+
if (i === 0)
|
|
47
|
+
pen.moveTo(cx + r * u, cy - r * v);
|
|
48
|
+
else
|
|
49
|
+
pen.lineTo(cx + r * u, cy - r * v);
|
|
50
|
+
}
|
|
51
|
+
pen.closePath();
|
|
52
|
+
}
|
|
53
|
+
/** An open line; it breaks where it passes behind the globe. */
|
|
54
|
+
export function traceLine(pen, line, b) {
|
|
55
|
+
const { e, n, f, cx, cy, r } = b;
|
|
56
|
+
let down = false;
|
|
57
|
+
for (let i = 0; i < line.length; i += 3) {
|
|
58
|
+
const x = line[i];
|
|
59
|
+
const y = line[i + 1];
|
|
60
|
+
const z = line[i + 2];
|
|
61
|
+
if (f[0] * x + f[1] * y + f[2] * z < 0) {
|
|
62
|
+
down = false;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const px = cx + r * (e[0] * x + e[1] * y + e[2] * z);
|
|
66
|
+
const py = cy - r * (n[0] * x + n[1] * y + n[2] * z);
|
|
67
|
+
if (down)
|
|
68
|
+
pen.lineTo(px, py);
|
|
69
|
+
else
|
|
70
|
+
pen.moveTo(px, py);
|
|
71
|
+
down = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitbaum/geo-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Versioned, on-demand geography resources and sourced boundary assertions for web applications.",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Versioned, on-demand geography resources and sourced boundary assertions for web applications, and a Canvas 2D renderer for them (globe or map).",
|
|
5
5
|
"author": "BitBaum",
|
|
6
6
|
"homepage": "https://github.com/bitbaum/geo-kit#readme",
|
|
7
7
|
"repository": {
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"import": "./dist/index.js",
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./map": {
|
|
29
|
+
"types": "./dist/map/index.d.ts",
|
|
30
|
+
"import": "./dist/map/index.js",
|
|
31
|
+
"default": "./dist/map/index.js"
|
|
27
32
|
}
|
|
28
33
|
},
|
|
29
34
|
"files": [
|
|
@@ -43,8 +48,27 @@
|
|
|
43
48
|
"pack:check": "node scripts/check-pack.mjs",
|
|
44
49
|
"verify": "pnpm run typecheck && pnpm run test && pnpm run build && pnpm run pack:check"
|
|
45
50
|
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"d3-geo": "^3.1.0",
|
|
53
|
+
"topojson-client": "^3.1.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"d3-geo": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"topojson-client": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
46
63
|
"devDependencies": {
|
|
64
|
+
"@types/d3-geo": "^3.1.1",
|
|
65
|
+
"@types/geojson": "^7946.0.16",
|
|
47
66
|
"@types/node": "^22.0.0",
|
|
48
|
-
"
|
|
67
|
+
"@types/topojson-client": "^3.1.5",
|
|
68
|
+
"@types/topojson-specification": "^1.0.5",
|
|
69
|
+
"d3-geo": "3.1.1",
|
|
70
|
+
"topojson-client": "3.1.0",
|
|
71
|
+
"typescript": "^5.8.0",
|
|
72
|
+
"world-atlas": "2.0.2"
|
|
49
73
|
}
|
|
50
74
|
}
|