@celljs/ta-geo 0.0.0-stage → 4.31.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.
@@ -0,0 +1,42 @@
1
+ import type { LonLat } from './geo-grid.js';
2
+ import type { Fetcher } from './geo-tiles.js';
3
+ export type WeatherKind = 'clear' | 'cloudy' | 'overcast' | 'fog' | 'drizzle' | 'rain' | 'snow' | 'storm';
4
+ export interface GeoWeatherNow {
5
+ kind: WeatherKind;
6
+ /** The code of the World Meteorological Organization. */
7
+ code: number;
8
+ /** °C. */
9
+ temperature: number;
10
+ /** How much of the sky is cloud, 0 to 1. */
11
+ cloud: number;
12
+ /** Km/h. */
13
+ wind: number;
14
+ /** Mm in the last hour. */
15
+ precipitation: number;
16
+ /** Metres of snow on the ground. */
17
+ snowDepth: number;
18
+ day: boolean;
19
+ /** The hours of the place's clock the sun rises and sets at. */
20
+ sunrise: number;
21
+ sunset: number;
22
+ /** Seconds the place's clock is ahead of UTC. */
23
+ offset: number;
24
+ /** When it was read (ms). */
25
+ at: number;
26
+ }
27
+ export declare namespace GeoWeatherUtil {
28
+ function kindOf(code: number, cloud?: number): WeatherKind;
29
+ /** The hour of the place's clock (0 to 24). */
30
+ function hoursAt(offset: number, now?: number): number;
31
+ /** `2026-11-23T06:31` as hours (6.52); none for what is not a time. */
32
+ function hoursOf(local: unknown): number | undefined;
33
+ }
34
+ export declare class GeoWeather {
35
+ protected readonly fetcher: Fetcher;
36
+ protected readonly base: string;
37
+ protected readonly clock: () => number;
38
+ protected readonly kept: Map<string, Promise<GeoWeatherNow>>;
39
+ constructor(fetcher?: Fetcher, base?: string, clock?: () => number);
40
+ now(place: LonLat): Promise<GeoWeatherNow>;
41
+ protected read(key: string, lat: string, lon: string): Promise<GeoWeatherNow>;
42
+ }
@@ -0,0 +1,99 @@
1
+ /** Kept this long for the same square. */
2
+ const KEPT_MS = 15 * 60000;
3
+ export var GeoWeatherUtil;
4
+ (function (GeoWeatherUtil) {
5
+ function kindOf(code, cloud = 0) {
6
+ if (code >= 95) {
7
+ return 'storm';
8
+ }
9
+ if ((code >= 71 && code <= 77) || code === 85 || code === 86) {
10
+ return 'snow';
11
+ }
12
+ if ((code >= 61 && code <= 67) || (code >= 80 && code <= 82)) {
13
+ return 'rain';
14
+ }
15
+ if (code >= 51 && code <= 57) {
16
+ return 'drizzle';
17
+ }
18
+ if (code === 45 || code === 48) {
19
+ return 'fog';
20
+ }
21
+ if (code === 3 || cloud >= 0.85) {
22
+ return 'overcast';
23
+ }
24
+ return code === 2 || cloud >= 0.4 ? 'cloudy' : 'clear';
25
+ }
26
+ GeoWeatherUtil.kindOf = kindOf;
27
+ /** The hour of the place's clock (0 to 24). */
28
+ function hoursAt(offset, now = Date.now()) {
29
+ const seconds = now / 1000 + offset;
30
+ return (((seconds / 3600) % 24) + 24) % 24;
31
+ }
32
+ GeoWeatherUtil.hoursAt = hoursAt;
33
+ /** `2026-11-23T06:31` as hours (6.52); none for what is not a time. */
34
+ function hoursOf(local) {
35
+ const match = typeof local === 'string' ? /T(\d{2}):(\d{2})/.exec(local) : null;
36
+ return match ? Number(match[1]) + Number(match[2]) / 60 : undefined;
37
+ }
38
+ GeoWeatherUtil.hoursOf = hoursOf;
39
+ })(GeoWeatherUtil || (GeoWeatherUtil = {}));
40
+ export class GeoWeather {
41
+ constructor(fetcher = (url, init) => fetch(url, init), base = 'https://api.open-meteo.com/v1/forecast', clock = Date.now) {
42
+ this.fetcher = fetcher;
43
+ this.base = base;
44
+ this.clock = clock;
45
+ this.kept = new Map();
46
+ }
47
+ now(place) {
48
+ const lat = place.lat.toFixed(2);
49
+ const lon = place.lon.toFixed(2);
50
+ const key = `${lat},${lon}`;
51
+ const kept = this.kept.get(key);
52
+ if (kept) {
53
+ return kept.then(weather => (this.clock() - weather.at < KEPT_MS ? weather : this.read(key, lat, lon)));
54
+ }
55
+ return this.read(key, lat, lon);
56
+ }
57
+ read(key, lat, lon) {
58
+ const fields = 'temperature_2m,weather_code,cloud_cover,wind_speed_10m,precipitation,snow_depth,is_day';
59
+ const url = `${this.base}?latitude=${lat}&longitude=${lon}&current=${fields}&daily=sunrise,sunset&forecast_days=1&timezone=auto`;
60
+ const made = this.fetcher(url)
61
+ .then(response => {
62
+ if (!response.ok) {
63
+ throw new Error(`Weather: HTTP ${response.status}`);
64
+ }
65
+ return response.json();
66
+ })
67
+ .then(reply => {
68
+ var _a, _b, _c, _d;
69
+ var _e, _f, _g, _h, _j, _k, _l, _m;
70
+ const now = reply.current;
71
+ if (!now || typeof now.weather_code !== 'number') {
72
+ throw new Error('Weather: nothing now');
73
+ }
74
+ const cloud = Math.max(0, Math.min(1, ((_e = now.cloud_cover) !== null && _e !== void 0 ? _e : 0) / 100));
75
+ return {
76
+ kind: GeoWeatherUtil.kindOf(now.weather_code, cloud),
77
+ code: now.weather_code,
78
+ temperature: (_f = now.temperature_2m) !== null && _f !== void 0 ? _f : 0,
79
+ cloud,
80
+ wind: (_g = now.wind_speed_10m) !== null && _g !== void 0 ? _g : 0,
81
+ precipitation: (_h = now.precipitation) !== null && _h !== void 0 ? _h : 0,
82
+ snowDepth: (_j = now.snow_depth) !== null && _j !== void 0 ? _j : 0,
83
+ day: now.is_day !== 0,
84
+ sunrise: (_k = GeoWeatherUtil.hoursOf((_b = (_a = reply.daily) === null || _a === void 0 ? void 0 : _a.sunrise) === null || _b === void 0 ? void 0 : _b[0])) !== null && _k !== void 0 ? _k : 6,
85
+ sunset: (_l = GeoWeatherUtil.hoursOf((_d = (_c = reply.daily) === null || _c === void 0 ? void 0 : _c.sunset) === null || _d === void 0 ? void 0 : _d[0])) !== null && _l !== void 0 ? _l : 18.5,
86
+ offset: (_m = reply.utc_offset_seconds) !== null && _m !== void 0 ? _m : 0,
87
+ at: this.clock(),
88
+ };
89
+ });
90
+ made.catch(() => this.kept.delete(key));
91
+ this.kept.delete(key);
92
+ this.kept.set(key, made);
93
+ while (this.kept.size > 64) {
94
+ this.kept.delete(this.kept.keys().next().value);
95
+ }
96
+ return made;
97
+ }
98
+ }
99
+ //# sourceMappingURL=geo-weather.js.map
package/esm/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './geo-elevation.js';
2
+ export * from './geo-grid.js';
3
+ export * from './geo-mvt.js';
4
+ export * from './geo-pixels.js';
5
+ export * from './geo-places.js';
6
+ export * from './geo-raster.js';
7
+ export * from './geo-tiles.js';
8
+ export * from './geo-weather.js';
package/esm/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from './geo-elevation.js';
2
+ export * from './geo-grid.js';
3
+ export * from './geo-mvt.js';
4
+ export * from './geo-pixels.js';
5
+ export * from './geo-places.js';
6
+ export * from './geo-raster.js';
7
+ export * from './geo-tiles.js';
8
+ export * from './geo-weather.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,43 @@
1
+ import { type LonLat, type Plot } from './geo-grid';
2
+ import type { Fetcher } from './geo-tiles';
3
+ /** Columns between two points of the lattice: a quarter of a plot. */
4
+ export declare const RELIEF_STEP = 128;
5
+ export interface ElevationSource {
6
+ /** The height above the sea of each place, in metres. */
7
+ read(places: LonLat[]): Promise<number[]>;
8
+ }
9
+ export declare class OpenMeteoElevation implements ElevationSource {
10
+ protected readonly fetcher: Fetcher;
11
+ protected readonly base: string;
12
+ constructor(fetcher?: Fetcher, base?: string);
13
+ read(places: LonLat[]): Promise<number[]>;
14
+ }
15
+ /** The ground of a plot: metres above the low ground of its region. */
16
+ export interface PlotRelief {
17
+ /** At the points of the lattice on and in the plot, (PER_PLOT + 1)² of them, row by row from the north-west. */
18
+ readonly lattice: Float32Array;
19
+ /** At a column of the plot (0 to 511 each way), between the points round it. */
20
+ at(x: number, z: number): number;
21
+ }
22
+ interface Waiting {
23
+ ix: number;
24
+ iz: number;
25
+ resolve(metres: number): void;
26
+ reject(error: unknown): void;
27
+ }
28
+ export declare class GeoElevation {
29
+ protected readonly source: ElevationSource;
30
+ protected readonly points: Map<string, Promise<number>>;
31
+ protected waiting: Waiting[];
32
+ protected timer?: ReturnType<typeof setTimeout>;
33
+ constructor(source?: ElevationSource);
34
+ /** The ground of a plot; it fails when the heights cannot be read (the next time asks again). */
35
+ plot({ px, pz }: Plot): Promise<PlotRelief>;
36
+ /** The ground between the points of a lattice of a plot. */
37
+ static relief(lattice: Float32Array): PlotRelief;
38
+ /** The height of a point of the lattice, read with others asked at the same time. */
39
+ protected point(ix: number, iz: number): Promise<number>;
40
+ protected flush(): void;
41
+ }
42
+ export {};
43
+ //# sourceMappingURL=geo-elevation.d.ts.map
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeoElevation = exports.OpenMeteoElevation = exports.RELIEF_STEP = void 0;
4
+ const geo_grid_1 = require("./geo-grid");
5
+ // How high the ground is (GeoElevation): heights read at the points of one lattice over the whole earth, a point
6
+ // every RELIEF_STEP columns, so that two plots side by side read the same points on their edge and fit; of each
7
+ // point the lowest of it and the eight round it, which takes away the buildings and trees the model of the
8
+ // surface has in it and leaves the hills; then less a datum, the low ground of the region (the lowest of nine
9
+ // points round each corner of a much coarser lattice, between them in a straight line), so that a city by the sea
10
+ // and one on a plateau both stand on their own ground. The same points give the same heights on every device: what
11
+ // each makes of a place, the others make too. Open-Meteo by default (Copernicus DEM, 90 m), free and without a key.
12
+ /** Columns between two points of the lattice: a quarter of a plot. */
13
+ exports.RELIEF_STEP = 128;
14
+ /** Points of the lattice between two corners of the datum's (about 30 km at the equator). */
15
+ const DATUM_STEPS = 256;
16
+ const PER_PLOT = geo_grid_1.PLOT_SIZE / exports.RELIEF_STEP;
17
+ /** Points asked in one request at most. */
18
+ const BATCH = 100;
19
+ /** Points kept, the latest read. */
20
+ const KEPT = 20000;
21
+ class OpenMeteoElevation {
22
+ constructor(fetcher = (url, init) => fetch(url, init), base = 'https://api.open-meteo.com/v1/elevation') {
23
+ this.fetcher = fetcher;
24
+ this.base = base;
25
+ }
26
+ async read(places) {
27
+ const latitude = places.map(each => each.lat.toFixed(5)).join(',');
28
+ const longitude = places.map(each => each.lon.toFixed(5)).join(',');
29
+ const response = await this.fetcher(`${this.base}?latitude=${latitude}&longitude=${longitude}`);
30
+ if (!response.ok) {
31
+ throw new Error(`Elevation: HTTP ${response.status}`);
32
+ }
33
+ const json = (await response.json());
34
+ if (!Array.isArray(json.elevation) || json.elevation.length !== places.length) {
35
+ throw new Error('Elevation: no heights');
36
+ }
37
+ return json.elevation.map(value => (typeof value === 'number' && Number.isFinite(value) ? value : 0));
38
+ }
39
+ }
40
+ exports.OpenMeteoElevation = OpenMeteoElevation;
41
+ class GeoElevation {
42
+ constructor(source = new OpenMeteoElevation()) {
43
+ this.source = source;
44
+ this.points = new Map();
45
+ this.waiting = [];
46
+ }
47
+ /** The ground of a plot; it fails when the heights cannot be read (the next time asks again). */
48
+ async plot({ px, pz }) {
49
+ const ix0 = px * PER_PLOT;
50
+ const iz0 = pz * PER_PLOT;
51
+ const side = PER_PLOT + 1;
52
+ // Every point asked at once, so that they go in one request.
53
+ const raw = new Map();
54
+ const ask = (ix, iz) => {
55
+ const key = `${ix},${iz}`;
56
+ let known = raw.get(key);
57
+ if (!known) {
58
+ known = this.point(ix, iz);
59
+ raw.set(key, known);
60
+ }
61
+ return known;
62
+ };
63
+ for (let iz = iz0 - 1; iz <= iz0 + side; iz++) {
64
+ for (let ix = ix0 - 1; ix <= ix0 + side; ix++) {
65
+ ask(ix, iz);
66
+ }
67
+ }
68
+ const corners = new Map();
69
+ const corner = (jx, jz) => {
70
+ const key = `${jx},${jz}`;
71
+ let known = corners.get(key);
72
+ if (!known) {
73
+ const half = DATUM_STEPS / 2;
74
+ const nine = [];
75
+ for (let b = -1; b <= 1; b++) {
76
+ for (let a = -1; a <= 1; a++) {
77
+ nine.push(ask(jx * DATUM_STEPS + a * half, jz * DATUM_STEPS + b * half));
78
+ }
79
+ }
80
+ known = Promise.all(nine).then(values => Math.min(...values));
81
+ corners.set(key, known);
82
+ }
83
+ return known;
84
+ };
85
+ const lattice = new Float32Array(side * side);
86
+ const datums = [];
87
+ for (let iz = iz0; iz < iz0 + side; iz++) {
88
+ for (let ix = ix0; ix < ix0 + side; ix++) {
89
+ const jx = Math.floor(ix / DATUM_STEPS);
90
+ const jz = Math.floor(iz / DATUM_STEPS);
91
+ const tx = ix / DATUM_STEPS - jx;
92
+ const tz = iz / DATUM_STEPS - jz;
93
+ datums.push(Promise.all([corner(jx, jz), corner(jx + 1, jz), corner(jx, jz + 1), corner(jx + 1, jz + 1)]).then(([a, b, c, d]) => (a * (1 - tx) + b * tx) * (1 - tz) + (c * (1 - tx) + d * tx) * tz));
94
+ }
95
+ }
96
+ const [heights, datum] = await Promise.all([Promise.all([...raw.values()]), Promise.all(datums)]);
97
+ const keys = [...raw.keys()];
98
+ const metres = new Map(keys.map((key, k) => [key, heights[k]]));
99
+ const height = (ix, iz) => { var _a; return (_a = metres.get(`${ix},${iz}`)) !== null && _a !== void 0 ? _a : 0; };
100
+ for (let row = 0; row < side; row++) {
101
+ for (let col = 0; col < side; col++) {
102
+ let low = Number.POSITIVE_INFINITY;
103
+ for (let b = -1; b <= 1; b++) {
104
+ for (let a = -1; a <= 1; a++) {
105
+ low = Math.min(low, height(ix0 + col + a, iz0 + row + b));
106
+ }
107
+ }
108
+ lattice[row * side + col] = Math.max(0, low - datum[row * side + col]);
109
+ }
110
+ }
111
+ return GeoElevation.relief(lattice);
112
+ }
113
+ /** The ground between the points of a lattice of a plot. */
114
+ static relief(lattice) {
115
+ const side = PER_PLOT + 1;
116
+ return {
117
+ lattice,
118
+ at(x, z) {
119
+ const fx = Math.min(PER_PLOT - 1e-6, Math.max(0, (x + 0.5) / exports.RELIEF_STEP));
120
+ const fz = Math.min(PER_PLOT - 1e-6, Math.max(0, (z + 0.5) / exports.RELIEF_STEP));
121
+ const ix = Math.floor(fx);
122
+ const iz = Math.floor(fz);
123
+ const tx = fx - ix;
124
+ const tz = fz - iz;
125
+ const v = (c, r) => lattice[(iz + r) * side + ix + c];
126
+ return (v(0, 0) * (1 - tx) + v(1, 0) * tx) * (1 - tz) + (v(0, 1) * (1 - tx) + v(1, 1) * tx) * tz;
127
+ },
128
+ };
129
+ }
130
+ /** The height of a point of the lattice, read with others asked at the same time. */
131
+ point(ix, iz) {
132
+ const key = `${ix},${iz}`;
133
+ const known = this.points.get(key);
134
+ if (known) {
135
+ return known;
136
+ }
137
+ const made = new Promise((resolve, reject) => {
138
+ var _a;
139
+ this.waiting.push({ ix, iz, resolve, reject });
140
+ (_a = this.timer) !== null && _a !== void 0 ? _a : (this.timer = setTimeout(() => this.flush(), 0));
141
+ });
142
+ made.catch(() => this.points.delete(key));
143
+ this.points.set(key, made);
144
+ while (this.points.size > KEPT) {
145
+ this.points.delete(this.points.keys().next().value);
146
+ }
147
+ return made;
148
+ }
149
+ flush() {
150
+ this.timer = undefined;
151
+ const all = this.waiting;
152
+ this.waiting = [];
153
+ for (let start = 0; start < all.length; start += BATCH) {
154
+ const batch = all.slice(start, start + BATCH);
155
+ const places = batch.map(each => geo_grid_1.GeoGrid.toLonLat({ x: each.ix * exports.RELIEF_STEP, z: each.iz * exports.RELIEF_STEP }));
156
+ const read = (tries) => this.source.read(places).catch(error => (tries > 0 ? read(tries - 1) : Promise.reject(error)));
157
+ read(1).then(values => {
158
+ for (const [k, each] of batch.entries()) {
159
+ each.resolve(values[k]);
160
+ }
161
+ }, error => {
162
+ for (const each of batch) {
163
+ each.reject(error);
164
+ }
165
+ });
166
+ }
167
+ }
168
+ }
169
+ exports.GeoElevation = GeoElevation;
170
+ //# sourceMappingURL=geo-elevation.js.map
@@ -0,0 +1,51 @@
1
+ /** The zoom of a plot. */
2
+ export declare const PLOT_ZOOM = 16;
3
+ /** Columns across a plot. */
4
+ export declare const PLOT_SIZE = 512;
5
+ /** The zoom of a column: a pixel of a plot. */
6
+ export declare const COLUMN_ZOOM: number;
7
+ export interface LonLat {
8
+ lon: number;
9
+ lat: number;
10
+ }
11
+ /** A point of the grid, in columns: x east, z south, from the north-west corner of the earth. */
12
+ export interface GridPoint {
13
+ x: number;
14
+ z: number;
15
+ }
16
+ /** A plot: a tile of zoom 16. */
17
+ export interface Plot {
18
+ px: number;
19
+ pz: number;
20
+ }
21
+ /** A tile of a zoom of the maps of the web. */
22
+ export interface MapTile {
23
+ z: number;
24
+ x: number;
25
+ y: number;
26
+ }
27
+ export declare namespace GeoGrid {
28
+ /** Where a place is on the grid, in columns (not whole). */
29
+ function toGrid({ lon, lat }: LonLat): GridPoint;
30
+ /** The place at a point of the grid. */
31
+ function toLonLat({ x, z }: GridPoint): LonLat;
32
+ /** The plot a point is in. */
33
+ function plotOf({ x, z }: GridPoint): Plot;
34
+ /** A plot by its name, `16/x/y` as the maps of the web name its tile. */
35
+ function key({ px, pz }: Plot): string;
36
+ function parse(key: string): Plot | undefined;
37
+ /** The tile of a lower zoom the plot is in, and where in it, as a fraction of the tile (0 to 1). */
38
+ function tileOf({ px, pz }: Plot, zoom: number): {
39
+ tile: MapTile;
40
+ left: number;
41
+ top: number;
42
+ size: number;
43
+ };
44
+ /** The metres a column is across at a latitude. */
45
+ function metresPerColumn(lat: number): number;
46
+ /** The plots around one, `ring` away at most, nearest first. */
47
+ function around(plot: Plot, ring: number): Plot[];
48
+ /** A place made coarse: the middle of its tile of `zoom` (12: about ten kilometres), to tell others roughly where. */
49
+ function coarse(place: LonLat, zoom: number): LonLat;
50
+ }
51
+ //# sourceMappingURL=geo-grid.d.ts.map
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ // The earth as one grid (GeoGrid): Web Mercator, as the maps of the web draw it, cut into plots, the tiles of
3
+ // zoom 16, each of 512 × 512 columns. A column is a pixel of zoom 25 (about a metre: 1.19 m at the equator, 1.1 m
4
+ // at 22°), so that every device names the same place by the same numbers and what each makes of it fits beside what
5
+ // the others make, with nothing to agree on.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.GeoGrid = exports.COLUMN_ZOOM = exports.PLOT_SIZE = exports.PLOT_ZOOM = void 0;
8
+ /** The zoom of a plot. */
9
+ exports.PLOT_ZOOM = 16;
10
+ /** Columns across a plot. */
11
+ exports.PLOT_SIZE = 512;
12
+ /** The zoom of a column: a pixel of a plot. */
13
+ exports.COLUMN_ZOOM = exports.PLOT_ZOOM + 9;
14
+ const COLUMNS = 2 ** exports.COLUMN_ZOOM;
15
+ /** The earth's circumference at the equator, in metres (WGS 84). */
16
+ const EQUATOR = 40075016.686;
17
+ /** How far north and south Web Mercator goes. */
18
+ const MAX_LAT = 85.05112878;
19
+ var GeoGrid;
20
+ (function (GeoGrid) {
21
+ /** Where a place is on the grid, in columns (not whole). */
22
+ function toGrid({ lon, lat }) {
23
+ const clamped = Math.max(-MAX_LAT, Math.min(MAX_LAT, lat));
24
+ const rad = (clamped * Math.PI) / 180;
25
+ const x = ((lon + 180) / 360) * COLUMNS;
26
+ const z = ((1 - Math.log(Math.tan(rad) + 1 / Math.cos(rad)) / Math.PI) / 2) * COLUMNS;
27
+ return { x, z };
28
+ }
29
+ GeoGrid.toGrid = toGrid;
30
+ /** The place at a point of the grid. */
31
+ function toLonLat({ x, z }) {
32
+ const lon = (x / COLUMNS) * 360 - 180;
33
+ const n = Math.PI - (2 * Math.PI * z) / COLUMNS;
34
+ const lat = (180 / Math.PI) * Math.atan(Math.sinh(n));
35
+ return { lon, lat };
36
+ }
37
+ GeoGrid.toLonLat = toLonLat;
38
+ /** The plot a point is in. */
39
+ function plotOf({ x, z }) {
40
+ return { px: Math.floor(x / exports.PLOT_SIZE), pz: Math.floor(z / exports.PLOT_SIZE) };
41
+ }
42
+ GeoGrid.plotOf = plotOf;
43
+ /** A plot by its name, `16/x/y` as the maps of the web name its tile. */
44
+ function key({ px, pz }) {
45
+ return `${exports.PLOT_ZOOM}/${px}/${pz}`;
46
+ }
47
+ GeoGrid.key = key;
48
+ function parse(key) {
49
+ const match = /^16\/(\d+)\/(\d+)$/.exec(key);
50
+ if (!match) {
51
+ return undefined;
52
+ }
53
+ const plot = { px: Number(match[1]), pz: Number(match[2]) };
54
+ return plot.px < 2 ** exports.PLOT_ZOOM && plot.pz < 2 ** exports.PLOT_ZOOM ? plot : undefined;
55
+ }
56
+ GeoGrid.parse = parse;
57
+ /** The tile of a lower zoom the plot is in, and where in it, as a fraction of the tile (0 to 1). */
58
+ function tileOf({ px, pz }, zoom) {
59
+ const shift = exports.PLOT_ZOOM - zoom;
60
+ const per = 2 ** shift;
61
+ return {
62
+ tile: { z: zoom, x: Math.floor(px / per), y: Math.floor(pz / per) },
63
+ left: (px % per) / per,
64
+ top: (pz % per) / per,
65
+ size: 1 / per,
66
+ };
67
+ }
68
+ GeoGrid.tileOf = tileOf;
69
+ /** The metres a column is across at a latitude. */
70
+ function metresPerColumn(lat) {
71
+ return (EQUATOR * Math.cos((lat * Math.PI) / 180)) / COLUMNS;
72
+ }
73
+ GeoGrid.metresPerColumn = metresPerColumn;
74
+ /** The plots around one, `ring` away at most, nearest first. */
75
+ function around(plot, ring) {
76
+ const out = [];
77
+ for (let dz = -ring; dz <= ring; dz++) {
78
+ for (let dx = -ring; dx <= ring; dx++) {
79
+ out.push({ px: plot.px + dx, pz: plot.pz + dz });
80
+ }
81
+ }
82
+ return out.sort((a, b) => Math.hypot(a.px - plot.px, a.pz - plot.pz) - Math.hypot(b.px - plot.px, b.pz - plot.pz));
83
+ }
84
+ GeoGrid.around = around;
85
+ /** A place made coarse: the middle of its tile of `zoom` (12: about ten kilometres), to tell others roughly where. */
86
+ function coarse(place, zoom) {
87
+ const per = 2 ** (exports.COLUMN_ZOOM - zoom);
88
+ const { x, z } = toGrid(place);
89
+ return toLonLat({ x: (Math.floor(x / per) + 0.5) * per, z: (Math.floor(z / per) + 0.5) * per });
90
+ }
91
+ GeoGrid.coarse = coarse;
92
+ })(GeoGrid || (exports.GeoGrid = GeoGrid = {}));
93
+ //# sourceMappingURL=geo-grid.js.map
@@ -0,0 +1,18 @@
1
+ export type MvtValue = string | number | boolean;
2
+ export interface MvtFeature {
3
+ /** 1 a point, 2 a line, 3 a polygon. */
4
+ type: 1 | 2 | 3;
5
+ properties: Record<string, MvtValue>;
6
+ /** Points: one part of points; lines: a part each; polygons: rings, each outer one before its holes. */
7
+ geometry: [number, number][][];
8
+ }
9
+ export interface MvtLayer {
10
+ name: string;
11
+ extent: number;
12
+ features: MvtFeature[];
13
+ }
14
+ export declare namespace GeoMvt {
15
+ /** The layers of a tile, by name. */
16
+ function decode(bytes: Uint8Array): Map<string, MvtLayer>;
17
+ }
18
+ //# sourceMappingURL=geo-mvt.d.ts.map