@versatiles/png-renderer 2.2.1 → 2.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +40 -7
  2. package/dist/index.js +5858 -147
  3. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -2741,6 +2741,12 @@ declare class Feature implements Feature$1 {
2741
2741
  * clipped edges along the tile border are not part of the outline.
2742
2742
  */
2743
2743
  readonly outline?: Geometry;
2744
+ /**
2745
+ * For each line of the geometry, how far along the line in its tile it starts, in pixels
2746
+ * — where the line was clipped to its tile, which cut off its start. A dash pattern
2747
+ * starts where the line in the tile does.
2748
+ */
2749
+ readonly lineStarts?: number[];
2744
2750
  constructor(opt: {
2745
2751
  type: 'LineString' | 'Point' | 'Polygon';
2746
2752
  id?: unknown;
@@ -2748,6 +2754,7 @@ declare class Feature implements Feature$1 {
2748
2754
  patterns?: Patterns;
2749
2755
  geometry: Geometry;
2750
2756
  outline?: Geometry;
2757
+ lineStarts?: number[];
2751
2758
  });
2752
2759
  getBbox(): Bbox;
2753
2760
  doesOverlap(bbox: Bbox): boolean;
@@ -2774,6 +2781,18 @@ interface Padding {
2774
2781
  left?: number;
2775
2782
  }
2776
2783
 
2784
+ /**
2785
+ * The dashes of a line with `line-dasharray`, shared by every backend, as MapLibre GL JS
2786
+ * draws them (`line_sdf.vertex.glsl`, `LineAtlas`).
2787
+ */
2788
+ /** A dash pattern in pixels. */
2789
+ interface LineDash {
2790
+ /** The lengths of dashes and gaps in turn, starting with a dash: an even number of them. */
2791
+ lengths: number[];
2792
+ /** How far into the pattern a line starts. */
2793
+ offset: number;
2794
+ }
2795
+
2777
2796
  /**
2778
2797
  * A drawing surface the render pipeline paints a map onto. It only describes *how* to
2779
2798
  * draw; how the result is handed back is up to the backend, because those differ in
@@ -2890,14 +2909,15 @@ interface LineStyle {
2890
2909
  blur: number;
2891
2910
  cap: 'butt' | 'round' | 'square';
2892
2911
  color: Color;
2893
- dasharray?: number[];
2912
+ /** `line-dasharray`, in pixels (see `dashPattern`). */
2913
+ dash?: LineDash;
2894
2914
  join: 'bevel' | 'miter' | 'round';
2895
2915
  miterLimit: number;
2896
2916
  offset: number;
2897
2917
  opacity: number;
2898
2918
  translate: [number, number];
2899
2919
  width: number;
2900
- /** `line-pattern`: drawn instead of `color` and `dasharray`. */
2920
+ /** `line-pattern`: drawn instead of `color` and `dash`. */
2901
2921
  pattern?: LinePattern;
2902
2922
  }
2903
2923
  /**
@@ -3051,11 +3071,19 @@ interface FetchResponse {
3051
3071
  arrayBuffer(): Promise<ArrayBuffer>;
3052
3072
  json(): Promise<unknown>;
3053
3073
  }
3074
+ /**
3075
+ * The part of `fetch`'s `RequestInit` the renderer passes. It sends request headers only
3076
+ * to read part of a file: a `Range` header for a PMTiles archive.
3077
+ */
3078
+ interface FetchRequestInit {
3079
+ headers?: Record<string, string>;
3080
+ }
3054
3081
  /**
3055
3082
  * Loads a URL, like `fetch`: the renderer loads tiles, sprites, TileJSON documents and GeoJSON data through it. It is called
3056
- * with the URL only, and should resolve to a `Response`.
3083
+ * with the URL, and for part of a file with request headers as well, and should resolve to
3084
+ * a `Response`.
3057
3085
  */
3058
- type FetchFunction = (url: string) => Promise<FetchResponse>;
3086
+ type FetchFunction = (url: string, init?: FetchRequestInit) => Promise<FetchResponse>;
3059
3087
 
3060
3088
  /** Options for {@link SVGMapRenderer}: what stays the same for every view of the map. */
3061
3089
  interface SVGMapRendererOptions {
@@ -3066,7 +3094,9 @@ interface SVGMapRendererOptions {
3066
3094
  * (`url: '.../tiles.json'`), which is fetched once, like the sprite, with
3067
3095
  * {@link SVGMapRendererOptions.fetch}. As in MapLibre GL JS, `tiles`, `minzoom`,
3068
3096
  * `maxzoom` and the like come from the document unless the style sets them, and
3069
- * relative tile URLs are resolved against the document's URL. A GeoJSON source's `data`
3097
+ * relative tile URLs are resolved against the document's URL. A PMTiles archive
3098
+ * (`url: 'pmtiles://https://.../tiles.pmtiles'`) is read as with the `pmtiles` protocol in
3099
+ * MapLibre GL JS, which needs no setup here. A GeoJSON source's `data`
3070
3100
  * may be a URL too. A source whose TileJSON or GeoJSON cannot be loaded is left out, and
3071
3101
  * the next render tries again.
3072
3102
  */
@@ -3113,6 +3143,9 @@ interface SVGMapRendererOptions {
3113
3143
  * Loads tiles, sprites, TileJSON documents and GeoJSON data, like `fetch`, which is the default. Pass your own to send
3114
3144
  * headers, go through a proxy, or keep tiles in a cache on disk.
3115
3145
  *
3146
+ * It is called with the URL only, except to read part of a file, a PMTiles archive: then
3147
+ * also with `{ headers: { Range: 'bytes=…' } }`, which it should pass on.
3148
+ *
3116
3149
  * It must return a real `Response`, and its status matters: a 404 or 204 means the
3117
3150
  * server has no such tile, which is remembered (see {@link SVGMapRendererOptions.tileCacheSize}); any other
3118
3151
  * error status, or a rejected promise, counts as failed, and the next render tries
@@ -3222,7 +3255,7 @@ declare class SVGMapRenderer {
3222
3255
  */
3223
3256
  renderSVG(view?: ViewOptions): Promise<string>;
3224
3257
  /**
3225
- * Forgets the fetched tiles, sprite, TileJSON documents and GeoJSON data, so the next render fetches them again, e.g.
3258
+ * Forgets the fetched tiles, sprite, TileJSON documents, PMTiles directories and GeoJSON data, so the next render fetches them again, e.g.
3226
3259
  * after they were updated on the server, or to free their memory.
3227
3260
  */
3228
3261
  clearCache(): void;
@@ -3485,4 +3518,4 @@ declare class PNGMapRenderer extends SVGMapRenderer {
3485
3518
  }
3486
3519
 
3487
3520
  export { PNGMapRenderer, SVGMapRenderer, renderToCanvas, renderToPNG, renderToSVG };
3488
- export type { FetchFunction, FetchResponse, GlobalState, PNGMapRendererOptions, PNGViewOptions, RenderToPNGOptions, RenderToSVGOptions, SVGMapRendererOptions, ViewOptions };
3521
+ export type { FetchFunction, FetchRequestInit, FetchResponse, GlobalState, PNGMapRendererOptions, PNGViewOptions, RenderToPNGOptions, RenderToSVGOptions, SVGMapRendererOptions, ViewOptions };