canvas-globe 1.2.0 → 1.4.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/types/index.d.ts CHANGED
@@ -32,6 +32,20 @@ export interface ClusterMarker {
32
32
  lon: number;
33
33
  }
34
34
 
35
+ /** Synthetic marker produced by the `hexBins` density layer. */
36
+ export interface HexBinMarker {
37
+ hexBin: true;
38
+ /** Number of source markers in the cell. */
39
+ markerCount: number;
40
+ /** Number of source markers in the cell. */
41
+ count: number;
42
+ /** Sum of source marker `count` values, with missing values treated as 1. */
43
+ value: number;
44
+ markers: Marker[];
45
+ lat: number;
46
+ lon: number;
47
+ }
48
+
35
49
  export type Coordinate = { lat: number; lon: number } | [lon: number, lat: number];
36
50
 
37
51
  export interface Arc {
@@ -178,7 +192,7 @@ export interface Handle {
178
192
  stop(): void;
179
193
  }
180
194
 
181
- export interface StoryStep extends Partial<GeoGlobeOptions> {
195
+ export interface StoryStep extends Omit<Partial<GeoGlobeOptions>, "center" | "zoom"> {
182
196
  /** Scroll progress, 0-1. */
183
197
  at: number;
184
198
  center?: [lon: number, lat: number];
@@ -193,6 +207,31 @@ export interface HeatmapOptions {
193
207
  color?: string;
194
208
  }
195
209
 
210
+ export interface HexBinOptions {
211
+ /** Hexagon radius in screen pixels. Default 18. */
212
+ radius?: number;
213
+ /** Ignore cells below this count or summed value. Default 1. */
214
+ minValue?: number;
215
+ /** Colour cells by summed marker values or marker count. Default "sum". */
216
+ value?: "sum" | "count";
217
+ /** Single base colour used when `colorRange` is omitted. */
218
+ color?: string;
219
+ /** Low-to-high colour ramp. */
220
+ colorRange?: string[];
221
+ /** Fill opacity, 0-1. Default 0.82. */
222
+ opacity?: number;
223
+ stroke?: string;
224
+ /** Cell outline width in px. Default 0.8. */
225
+ strokeWidth?: number;
226
+ /** Gap inside each cell in px. Default 1.5. */
227
+ padding?: number;
228
+ /** Draw the selected count/value inside each cell. Default false. */
229
+ showCount?: boolean;
230
+ labelColor?: string;
231
+ /** Hide individual markers beneath the bins. Default true. */
232
+ hideMarkers?: boolean;
233
+ }
234
+
196
235
  export interface SpikeOptions {
197
236
  /** Tallest spike as a fraction of the globe radius. Default 0.28. */
198
237
  height?: number;
@@ -217,6 +256,39 @@ export interface RecordingHandle {
217
256
  stop(): Promise<Blob>;
218
257
  }
219
258
 
259
+ export interface TileCoordinate {
260
+ x: number;
261
+ y: number;
262
+ z: number;
263
+ }
264
+
265
+ export type TileSource = string | CanvasImageSource;
266
+ export type TileProvider = (tile: TileCoordinate) => TileSource | Promise<TileSource>;
267
+
268
+ /** Optional XYZ overview tiles. No request is made unless this option is set. */
269
+ export interface TileLayerOptions {
270
+ /** URL template using {z}, {x}, {y}, and optional {-y}. */
271
+ url?: string;
272
+ /** Alias for a URL template or provider callback. */
273
+ source?: string | TileProvider;
274
+ /** Return a URL or drawable image for one XYZ tile. */
275
+ getTile?: TileProvider;
276
+ /** Fixed overview zoom. Default 2. */
277
+ zoom?: number;
278
+ /** Source tile width/height. Default 256. */
279
+ tileSize?: number;
280
+ /** Maximum composed texture width. Default 2048. */
281
+ maxWidth?: number;
282
+ /** Request ceiling. Default 64, which allows zoom 3. */
283
+ maxTiles?: number;
284
+ opacity?: number;
285
+ /** Painted into the canvas and every export. */
286
+ attribution?: string;
287
+ /** Image CORS mode. Default "anonymous"; null leaves it unset. */
288
+ crossOrigin?: string | null;
289
+ onError?: (error: Error, tile: TileCoordinate | null) => void;
290
+ }
291
+
220
292
  /** Anything `drawImage` accepts, plus a URL or a live stream. */
221
293
  export type MediaSource = string | CanvasImageSource | MediaStream;
222
294
 
@@ -378,7 +450,7 @@ export interface RenderMarkerContext {
378
450
  globe: GeoGlobe;
379
451
  }
380
452
 
381
- export type TooltipKind = "marker" | "cluster" | "country";
453
+ export type TooltipKind = "marker" | "cluster" | "hex-bin" | "country";
382
454
 
383
455
  export interface GeoGlobeOptions {
384
456
  /** Commercial license key supplied after purchase. */
@@ -387,8 +459,6 @@ export interface GeoGlobeOptions {
387
459
  mode?: "globe" | "map";
388
460
  /** Flat-map projection. Default "equirectangular". */
389
461
  projection?: MapProjection;
390
- /** Built-in theme name or a partial theme object. Default "atlas". */
391
- theme?: ThemeName | Partial<Theme>;
392
462
  /** Named bundle of theme + render style, applied under your own options. */
393
463
  preset?: PresetName;
394
464
  /** Theme name, a partial theme, "auto" for the OS colour scheme, or "css"
@@ -408,6 +478,8 @@ export interface GeoGlobeOptions {
408
478
  texture?: string | CanvasImageSource | null;
409
479
  /** Pixel step for the texture pass; higher is faster. Default "auto". */
410
480
  textureQuality?: "auto" | number;
481
+ /** Optional XYZ overview tiles. The default configuration performs no requests. */
482
+ tileLayer?: string | TileProvider | TileLayerOptions | TileLayer | null;
411
483
  /** Frame a single country, optionally dropping the rest of the world. */
412
484
  focus?: string | FocusSpec | null;
413
485
  /** Media painted inside each country's outline, keyed by ISO, id or name. */
@@ -428,6 +500,8 @@ export interface GeoGlobeOptions {
428
500
  transparentBackground?: boolean;
429
501
  /** Additive density blobs instead of, or under, markers. */
430
502
  heatmap?: boolean | HeatmapOptions;
503
+ /** Screen-space hexagonal aggregation for dense marker datasets. */
504
+ hexBins?: boolean | HexBinOptions;
431
505
  /** Bars standing off the surface, scaled by each marker's `count`. */
432
506
  spikes?: boolean | SpikeOptions;
433
507
  /** Text labels with collision avoidance. */
@@ -496,13 +570,13 @@ export interface GeoGlobeOptions {
496
570
  /** Frame cap. Default 30. */
497
571
  fps?: number;
498
572
  /** Built-in tooltip. `true` uses the default text, or pass a formatter. */
499
- tooltip?: boolean | ((target: Marker | ClusterMarker | CountryShape, kind: TooltipKind) => string);
573
+ tooltip?: boolean | ((target: Marker | ClusterMarker | HexBinMarker | CountryShape, kind: TooltipKind) => string);
500
574
  /** Honour `prefers-reduced-motion`. Default true. */
501
575
  respectReducedMotion?: boolean;
502
576
  /** Accessible name for the canvas. */
503
577
  ariaLabel?: string;
504
- onHover?: (marker: Marker | ClusterMarker | null, position: { x: number; y: number } | null) => void;
505
- onClick?: (marker: Marker | ClusterMarker, position: { x: number; y: number }) => void;
578
+ onHover?: (marker: Marker | ClusterMarker | HexBinMarker | null, position: { x: number; y: number } | null) => void;
579
+ onClick?: (marker: Marker | ClusterMarker | HexBinMarker, position: { x: number; y: number }) => void;
506
580
  onCountryHover?: (country: CountryShape | null, position: { x: number; y: number } | null) => void;
507
581
  onCountryClick?: (country: CountryShape, position: { x: number; y: number }) => void;
508
582
  onRender?: (instance: GeoGlobe) => void;
@@ -563,6 +637,8 @@ export declare class GeoGlobe {
563
637
  setLandStyle(style: LandStyle): this;
564
638
  /** Equirectangular image painted onto the sphere; null removes it. */
565
639
  setTexture(source: string | CanvasImageSource | null): this;
640
+ /** Optional XYZ overview tiles; null removes the layer. */
641
+ setTileLayer(source: GeoGlobeOptions["tileLayer"]): this;
566
642
  /** Frames a country and, with `isolate`, drops the rest of the world away. */
567
643
  focusOn(country: string | FocusSpec | null, opts?: Partial<FocusSpec> & FlyToOptions): this;
568
644
  clearFocus(): this;
@@ -742,6 +818,18 @@ export declare class SphereTexture {
742
818
  readonly error: Error | null;
743
819
  }
744
820
 
821
+ /** Cached XYZ tiles composed into the raster used by globe and map modes. */
822
+ export declare class TileLayer {
823
+ constructor(source: string | TileProvider | TileLayerOptions, options?: { onLoad?: (layer: TileLayer) => void });
824
+ readonly ready: boolean;
825
+ readonly error: Error | null;
826
+ readonly attribution: string;
827
+ readonly stats: { loaded: number; failed: number; total: number; cached: number };
828
+ destroy(): void;
829
+ }
830
+
831
+ export declare function tileUrl(template: string, tile: TileCoordinate): string;
832
+
745
833
  /** A drawable media source: image, GIF, video, canvas or live stream. */
746
834
  export declare class Media {
747
835
  constructor(spec: MediaSource | MediaSpec, onReady?: (media: Media) => void);
@@ -1,8 +1,8 @@
1
- import type { Arc, CountryShape, GeoGlobe, GeoGlobeOptions, Marker, ClusterMarker, FlyToOptions } from "./index.js";
1
+ import type { Arc, CountryShape, GeoGlobe, GeoGlobeOptions, Marker, ClusterMarker, HexBinMarker, FlyToOptions } from "./index.js";
2
2
 
3
3
  export interface GeoGlobeEventMap {
4
- "geo-hover": CustomEvent<{ marker: Marker | ClusterMarker | null; pos: { x: number; y: number } | null }>;
5
- "geo-click": CustomEvent<{ marker: Marker | ClusterMarker; pos: { x: number; y: number } }>;
4
+ "geo-hover": CustomEvent<{ marker: Marker | ClusterMarker | HexBinMarker | null; pos: { x: number; y: number } | null }>;
5
+ "geo-click": CustomEvent<{ marker: Marker | ClusterMarker | HexBinMarker; pos: { x: number; y: number } }>;
6
6
  "geo-country-hover": CustomEvent<{ country: CountryShape | null; pos: { x: number; y: number } | null }>;
7
7
  "geo-country-click": CustomEvent<{ country: CountryShape; pos: { x: number; y: number } }>;
8
8
  "geo-render": CustomEvent<{ globe: GeoGlobe }>;