@versatiles/svg-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 +5842 -146
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -2738,6 +2738,12 @@ declare class Feature implements Feature$1 {
2738
2738
  * clipped edges along the tile border are not part of the outline.
2739
2739
  */
2740
2740
  readonly outline?: Geometry;
2741
+ /**
2742
+ * For each line of the geometry, how far along the line in its tile it starts, in pixels
2743
+ * — where the line was clipped to its tile, which cut off its start. A dash pattern
2744
+ * starts where the line in the tile does.
2745
+ */
2746
+ readonly lineStarts?: number[];
2741
2747
  constructor(opt: {
2742
2748
  type: 'LineString' | 'Point' | 'Polygon';
2743
2749
  id?: unknown;
@@ -2745,6 +2751,7 @@ declare class Feature implements Feature$1 {
2745
2751
  patterns?: Patterns;
2746
2752
  geometry: Geometry;
2747
2753
  outline?: Geometry;
2754
+ lineStarts?: number[];
2748
2755
  });
2749
2756
  getBbox(): Bbox;
2750
2757
  doesOverlap(bbox: Bbox): boolean;
@@ -2771,6 +2778,18 @@ interface Padding {
2771
2778
  left?: number;
2772
2779
  }
2773
2780
 
2781
+ /**
2782
+ * The dashes of a line with `line-dasharray`, shared by every backend, as MapLibre GL JS
2783
+ * draws them (`line_sdf.vertex.glsl`, `LineAtlas`).
2784
+ */
2785
+ /** A dash pattern in pixels. */
2786
+ interface LineDash {
2787
+ /** The lengths of dashes and gaps in turn, starting with a dash: an even number of them. */
2788
+ lengths: number[];
2789
+ /** How far into the pattern a line starts. */
2790
+ offset: number;
2791
+ }
2792
+
2774
2793
  /**
2775
2794
  * A drawing surface the render pipeline paints a map onto. It only describes *how* to
2776
2795
  * draw; how the result is handed back is up to the backend, because those differ in
@@ -2887,14 +2906,15 @@ interface LineStyle {
2887
2906
  blur: number;
2888
2907
  cap: 'butt' | 'round' | 'square';
2889
2908
  color: Color;
2890
- dasharray?: number[];
2909
+ /** `line-dasharray`, in pixels (see `dashPattern`). */
2910
+ dash?: LineDash;
2891
2911
  join: 'bevel' | 'miter' | 'round';
2892
2912
  miterLimit: number;
2893
2913
  offset: number;
2894
2914
  opacity: number;
2895
2915
  translate: [number, number];
2896
2916
  width: number;
2897
- /** `line-pattern`: drawn instead of `color` and `dasharray`. */
2917
+ /** `line-pattern`: drawn instead of `color` and `dash`. */
2898
2918
  pattern?: LinePattern;
2899
2919
  }
2900
2920
  /**
@@ -3048,11 +3068,19 @@ interface FetchResponse {
3048
3068
  arrayBuffer(): Promise<ArrayBuffer>;
3049
3069
  json(): Promise<unknown>;
3050
3070
  }
3071
+ /**
3072
+ * The part of `fetch`'s `RequestInit` the renderer passes. It sends request headers only
3073
+ * to read part of a file: a `Range` header for a PMTiles archive.
3074
+ */
3075
+ interface FetchRequestInit {
3076
+ headers?: Record<string, string>;
3077
+ }
3051
3078
  /**
3052
3079
  * Loads a URL, like `fetch`: the renderer loads tiles, sprites, TileJSON documents and GeoJSON data through it. It is called
3053
- * with the URL only, and should resolve to a `Response`.
3080
+ * with the URL, and for part of a file with request headers as well, and should resolve to
3081
+ * a `Response`.
3054
3082
  */
3055
- type FetchFunction = (url: string) => Promise<FetchResponse>;
3083
+ type FetchFunction = (url: string, init?: FetchRequestInit) => Promise<FetchResponse>;
3056
3084
 
3057
3085
  /** Options for {@link SVGMapRenderer}: what stays the same for every view of the map. */
3058
3086
  interface SVGMapRendererOptions {
@@ -3063,7 +3091,9 @@ interface SVGMapRendererOptions {
3063
3091
  * (`url: '.../tiles.json'`), which is fetched once, like the sprite, with
3064
3092
  * {@link SVGMapRendererOptions.fetch}. As in MapLibre GL JS, `tiles`, `minzoom`,
3065
3093
  * `maxzoom` and the like come from the document unless the style sets them, and
3066
- * relative tile URLs are resolved against the document's URL. A GeoJSON source's `data`
3094
+ * relative tile URLs are resolved against the document's URL. A PMTiles archive
3095
+ * (`url: 'pmtiles://https://.../tiles.pmtiles'`) is read as with the `pmtiles` protocol in
3096
+ * MapLibre GL JS, which needs no setup here. A GeoJSON source's `data`
3067
3097
  * may be a URL too. A source whose TileJSON or GeoJSON cannot be loaded is left out, and
3068
3098
  * the next render tries again.
3069
3099
  */
@@ -3110,6 +3140,9 @@ interface SVGMapRendererOptions {
3110
3140
  * Loads tiles, sprites, TileJSON documents and GeoJSON data, like `fetch`, which is the default. Pass your own to send
3111
3141
  * headers, go through a proxy, or keep tiles in a cache on disk.
3112
3142
  *
3143
+ * It is called with the URL only, except to read part of a file, a PMTiles archive: then
3144
+ * also with `{ headers: { Range: 'bytes=…' } }`, which it should pass on.
3145
+ *
3113
3146
  * It must return a real `Response`, and its status matters: a 404 or 204 means the
3114
3147
  * server has no such tile, which is remembered (see {@link SVGMapRendererOptions.tileCacheSize}); any other
3115
3148
  * error status, or a rejected promise, counts as failed, and the next render tries
@@ -3219,7 +3252,7 @@ declare class SVGMapRenderer {
3219
3252
  */
3220
3253
  renderSVG(view?: ViewOptions): Promise<string>;
3221
3254
  /**
3222
- * Forgets the fetched tiles, sprite, TileJSON documents and GeoJSON data, so the next render fetches them again, e.g.
3255
+ * Forgets the fetched tiles, sprite, TileJSON documents, PMTiles directories and GeoJSON data, so the next render fetches them again, e.g.
3223
3256
  * after they were updated on the server, or to free their memory.
3224
3257
  */
3225
3258
  clearCache(): void;
@@ -3310,4 +3343,4 @@ interface RenderToSVGOptions extends Omit<SVGMapRendererOptions, 'tileCacheSize'
3310
3343
  declare function renderToSVG(options: RenderToSVGOptions): Promise<string>;
3311
3344
 
3312
3345
  export { SVGMapRenderer, renderToSVG };
3313
- export type { FetchFunction, FetchResponse, GlobalState, RenderToSVGOptions, SVGMapRendererOptions, ViewOptions };
3346
+ export type { FetchFunction, FetchRequestInit, FetchResponse, GlobalState, RenderToSVGOptions, SVGMapRendererOptions, ViewOptions };