@tangram.gl/basemap-layers 0.0.0-stage → 0.0.1

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 (105) hide show
  1. package/README.md +34 -2
  2. package/THIRD-PARTY-NOTICES.md +205 -0
  3. package/dist/geojson-worker.js +2160 -0
  4. package/dist/geojson-worker.js.map +6 -0
  5. package/dist/index.cjs +11388 -0
  6. package/dist/index.cjs.map +6 -0
  7. package/dist/index.js +11369 -0
  8. package/dist/index.js.map +6 -0
  9. package/dist/map-style.cjs +445 -0
  10. package/dist/map-style.cjs.map +6 -0
  11. package/dist/map-style.js +431 -0
  12. package/dist/map-style.js.map +6 -0
  13. package/dist/types/arabic-shaping.d.ts +7 -0
  14. package/dist/types/atmosphere-layer.d.ts +10 -0
  15. package/dist/types/basemap-layer.d.ts +150 -0
  16. package/dist/types/bidi.d.ts +8 -0
  17. package/dist/types/circle-layer.d.ts +49 -0
  18. package/dist/types/fill-extrusion-lighting-extension.d.ts +49 -0
  19. package/dist/types/fill-outline-extension.d.ts +22 -0
  20. package/dist/types/fill-pattern.d.ts +99 -0
  21. package/dist/types/fill-style-extensions.d.ts +100 -0
  22. package/dist/types/geojson-source.d.ts +29 -0
  23. package/dist/types/geojson-tiler.d.ts +48 -0
  24. package/dist/types/geojson-worker.d.ts +40 -0
  25. package/dist/types/globe-horizon-extension.d.ts +61 -0
  26. package/dist/types/globe-layers.d.ts +239 -0
  27. package/dist/types/globe-line-angle-extension.d.ts +37 -0
  28. package/dist/types/glyph-font-renderer.d.ts +37 -0
  29. package/dist/types/glyph-pbf.d.ts +37 -0
  30. package/dist/types/glyph-store.d.ts +103 -0
  31. package/dist/types/grid-index.d.ts +47 -0
  32. package/dist/types/hillshade-layer.d.ts +154 -0
  33. package/dist/types/index.d.ts +9 -0
  34. package/dist/types/is-globe-viewport.d.ts +2 -0
  35. package/dist/types/label-font-renderer.d.ts +18 -0
  36. package/dist/types/label-placement.d.ts +247 -0
  37. package/dist/types/label-text-layer.d.ts +231 -0
  38. package/dist/types/line-blur-extension.d.ts +73 -0
  39. package/dist/types/line-glyphs.d.ts +60 -0
  40. package/dist/types/line-placement.d.ts +93 -0
  41. package/dist/types/map-style-loader.d.ts +48 -0
  42. package/dist/types/map-style-schema.d.ts +72 -0
  43. package/dist/types/map-style.d.ts +6 -0
  44. package/dist/types/mapbox-style.d.ts +40 -0
  45. package/dist/types/mvt-label-layer.d.ts +923 -0
  46. package/dist/types/polylabel.d.ts +17 -0
  47. package/dist/types/raster-color-extension.d.ts +146 -0
  48. package/dist/types/shared-texture.d.ts +34 -0
  49. package/dist/types/sort-key.d.ts +10 -0
  50. package/dist/types/sprite.d.ts +82 -0
  51. package/dist/types/style-accessor.d.ts +45 -0
  52. package/dist/types/style-expression.d.ts +83 -0
  53. package/dist/types/style-resolver.d.ts +94 -0
  54. package/dist/types/text-font.d.ts +36 -0
  55. package/dist/types/text-halo-blur-extension.d.ts +55 -0
  56. package/dist/types/text-layout.d.ts +71 -0
  57. package/dist/types/util.d.ts +22 -0
  58. package/dist/types/zoom-paint-extension.d.ts +72 -0
  59. package/package.json +80 -3
  60. package/src/arabic-shaping.ts +366 -0
  61. package/src/atmosphere-layer.ts +19 -0
  62. package/src/basemap-layer.ts +533 -0
  63. package/src/bidi.ts +199 -0
  64. package/src/circle-layer.ts +191 -0
  65. package/src/fill-extrusion-lighting-extension.ts +206 -0
  66. package/src/fill-outline-extension.ts +70 -0
  67. package/src/fill-pattern.ts +400 -0
  68. package/src/fill-style-extensions.ts +177 -0
  69. package/src/geojson-source.ts +318 -0
  70. package/src/geojson-tiler.ts +185 -0
  71. package/src/geojson-worker.ts +98 -0
  72. package/src/globe-horizon-extension.ts +64 -0
  73. package/src/globe-layers.ts +3487 -0
  74. package/src/globe-line-angle-extension.ts +131 -0
  75. package/src/glyph-font-renderer.ts +173 -0
  76. package/src/glyph-pbf.ts +164 -0
  77. package/src/glyph-store.ts +326 -0
  78. package/src/grid-index.ts +177 -0
  79. package/src/hillshade-layer.ts +775 -0
  80. package/src/index.ts +18 -0
  81. package/src/is-globe-viewport.ts +24 -0
  82. package/src/label-font-renderer.ts +159 -0
  83. package/src/label-placement.ts +727 -0
  84. package/src/label-text-layer.ts +913 -0
  85. package/src/line-blur-extension.ts +237 -0
  86. package/src/line-glyphs.ts +364 -0
  87. package/src/line-placement.ts +446 -0
  88. package/src/map-style-loader.ts +56 -0
  89. package/src/map-style-schema.ts +83 -0
  90. package/src/map-style.ts +23 -0
  91. package/src/mapbox-style.ts +168 -0
  92. package/src/mvt-label-layer.ts +3744 -0
  93. package/src/polylabel.ts +312 -0
  94. package/src/raster-color-extension.ts +245 -0
  95. package/src/shared-texture.ts +153 -0
  96. package/src/sort-key.ts +63 -0
  97. package/src/sprite.ts +244 -0
  98. package/src/style-accessor.ts +95 -0
  99. package/src/style-expression.ts +327 -0
  100. package/src/style-resolver.ts +301 -0
  101. package/src/text-font.ts +150 -0
  102. package/src/text-halo-blur-extension.ts +115 -0
  103. package/src/text-layout.ts +441 -0
  104. package/src/util.ts +47 -0
  105. package/src/zoom-paint-extension.ts +207 -0
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** Runtime exports for `@deck.gl-community/basemap-layers`. */
6
+ export {BasemapLayer} from './basemap-layer';
7
+ export {
8
+ createDemTileset,
9
+ getBasemapLayers,
10
+ getGlobeBaseLayers,
11
+ getGlobeTopLayers
12
+ } from './globe-layers';
13
+ export {getSpriteIconMapping, getSpriteSources, loadSpriteAtlases} from './sprite';
14
+ export type {SpriteAtlas, SpriteIconMappingEntry, SpriteSource} from './sprite';
15
+ export {getLabelFont} from './text-font';
16
+ export type {LabelFont, LabelFontFamily} from './text-font';
17
+ export {GlyphStore} from './glyph-store';
18
+ export type {GlyphStoreOptions} from './glyph-store';
@@ -0,0 +1,24 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // deck.gl-community
6
+ // SPDX-License-Identifier: MIT
7
+ // Copyright (c) vis.gl contributors
8
+
9
+ import {_GlobeViewport as GlobeViewport} from '@deck.gl/core';
10
+
11
+ // Copied from deck.gl-community geo-layers: the published 9.4.x does not export this yet.
12
+ const PROJECTION_MODE_GLOBE = 2;
13
+
14
+ /** Detect a globe projection, including across copies of deck.gl. */
15
+ export function isGlobeViewport(viewport: unknown): boolean {
16
+ if (!viewport || typeof viewport !== 'object') {
17
+ return false;
18
+ }
19
+ const {projectionMode} = viewport as {projectionMode?: unknown};
20
+ if (typeof projectionMode === 'number') {
21
+ return projectionMode === PROJECTION_MODE_GLOBE;
22
+ }
23
+ return viewport instanceof GlobeViewport;
24
+ }
@@ -0,0 +1,159 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // deck.gl-community
6
+ // SPDX-License-Identifier: MIT
7
+ // Copyright (c) vis.gl contributors
8
+
9
+ import TinySDF from '@mapbox/tiny-sdf';
10
+ import type {TextLayerProps} from '@deck.gl/layers';
11
+
12
+ type GetFontRenderer = NonNullable<TextLayerProps['_getFontRenderer']>;
13
+ type FontRenderer = ReturnType<GetFontRenderer>;
14
+ type FontSettings = Parameters<GetFontRenderer>[0];
15
+
16
+ /** `TextLayer`'s font metrics where `measureText` gives no bounding box, as shares of the size. */
17
+ const DEFAULT_ASCENT = 0.9;
18
+ const DEFAULT_DESCENT = 0.3;
19
+
20
+ /**
21
+ * Splits `TextLayer`'s `fontWeight`, which may carry a style in front of the weight (`italic 400`,
22
+ * see `getTextLayerFontWeight`), into a CSS font style and weight.
23
+ */
24
+ function getFontStyle(fontWeight: string | number): {fontStyle: string; fontWeight: string} {
25
+ const match = /^(italic|oblique)\s+(.*)$/.exec(String(fontWeight));
26
+ return match
27
+ ? {fontStyle: match[1], fontWeight: match[2]}
28
+ : {fontStyle: 'normal', fontWeight: String(fontWeight)};
29
+ }
30
+
31
+ /**
32
+ * TinySDF's drawing context, through which every glyph that reaches left of its origin is drawn
33
+ * `shift` whole pixels to the right and measured as if it did not: TinySDF then keeps all its ink,
34
+ * whatever its version. `shift` is set by `getLabelFontRenderer` before each glyph.
35
+ */
36
+ function getShiftingContext(context: CanvasRenderingContext2D, shift: {pixels: number}) {
37
+ return new Proxy(context, {
38
+ get(target, property) {
39
+ if (property === 'measureText') {
40
+ return (text: string) => {
41
+ const metrics = target.measureText(text);
42
+ const pixels =
43
+ metrics.actualBoundingBoxLeft > 0 ? Math.ceil(metrics.actualBoundingBoxLeft) : 0;
44
+ shift.pixels = pixels;
45
+ return {
46
+ width: metrics.width,
47
+ actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
48
+ actualBoundingBoxDescent: metrics.actualBoundingBoxDescent,
49
+ actualBoundingBoxLeft: metrics.actualBoundingBoxLeft - pixels,
50
+ actualBoundingBoxRight: metrics.actualBoundingBoxRight + pixels,
51
+ fontBoundingBoxAscent: metrics.fontBoundingBoxAscent,
52
+ fontBoundingBoxDescent: metrics.fontBoundingBoxDescent
53
+ };
54
+ };
55
+ }
56
+ if (property === 'fillText') {
57
+ return (text: string, x: number, y: number) => target.fillText(text, x + shift.pixels, y);
58
+ }
59
+ const value = Reflect.get(target, property, target);
60
+ return typeof value === 'function' ? value.bind(target) : value;
61
+ },
62
+ set(target, property, value) {
63
+ return Reflect.set(target, property, value, target);
64
+ }
65
+ });
66
+ }
67
+
68
+ /**
69
+ * The signed distance field font renderer of label text: `TextLayer`'s own, with the same TinySDF,
70
+ * but keeping the part of a glyph left of its origin. `TextLayer` takes a glyph's origin at the left
71
+ * edge of the distance field TinySDF draws: TinySDF 2.0 cuts off the left of `f`, `j`, `y` and other
72
+ * italic glyphs that reach behind their origin, and TinySDF 2.2 and later draw every glyph from the
73
+ * left edge of its ink (`glyphLeft`), which `TextLayer` then draws off its origin.
74
+ *
75
+ * `TextLayer` leaves `fontSettings.buffer` atlas pixels before each glyph's origin, so the distance
76
+ * field left of a glyph is cut by the length of its overhang: a glyph keeps all its ink, and a halo
77
+ * reaches `buffer` minus the overhang atlas pixels left of it (9 of 18 for Noto Sans Italic `j` in
78
+ * a 64 px atlas, 1.7 px on 12 px text).
79
+ */
80
+ export function getLabelFontRenderer(settings: FontSettings): FontRenderer {
81
+ const {fontSize, buffer, radius, cutoff, fontFamily} = settings;
82
+ const {fontStyle, fontWeight} = getFontStyle(settings.fontWeight);
83
+ const tinySDF: any = new TinySDF({
84
+ fontSize,
85
+ buffer,
86
+ radius,
87
+ cutoff,
88
+ fontFamily,
89
+ fontWeight,
90
+ fontStyle
91
+ });
92
+ const shift = {pixels: 0};
93
+ tinySDF.ctx = getShiftingContext(tinySDF.ctx, shift);
94
+ const context = document.createElement('canvas').getContext('2d')!;
95
+ context.font = `${fontStyle} ${fontWeight} ${fontSize}px ${fontFamily}`;
96
+
97
+ return {
98
+ // As `TextLayer` measures, but for the width of a glyph that reaches left of its origin.
99
+ measure(char?: string) {
100
+ if (char === undefined) {
101
+ const metrics = context.measureText('A');
102
+ return metrics.fontBoundingBoxAscent
103
+ ? {
104
+ advance: 0,
105
+ width: 0,
106
+ ascent: Math.ceil(metrics.fontBoundingBoxAscent),
107
+ descent: Math.ceil(metrics.fontBoundingBoxDescent)
108
+ }
109
+ : {
110
+ advance: 0,
111
+ width: 0,
112
+ ascent: fontSize * DEFAULT_ASCENT,
113
+ descent: fontSize * DEFAULT_DESCENT
114
+ };
115
+ }
116
+ const metrics = context.measureText(char);
117
+ if (!metrics.actualBoundingBoxAscent) {
118
+ return {
119
+ advance: metrics.width,
120
+ width: metrics.width,
121
+ ascent: fontSize * DEFAULT_ASCENT,
122
+ descent: fontSize * DEFAULT_DESCENT
123
+ };
124
+ }
125
+ // `TextLayer` takes `right - left`, which for a glyph reaching left of its origin (`left` > 0)
126
+ // is short of its ink by twice the overhang. The cell must also hold what `draw` returns from
127
+ // TinySDF 2.0, which sizes the shifted glyph from its rounded shift: `right - left + shift`.
128
+ const {actualBoundingBoxLeft: inkLeft, actualBoundingBoxRight: inkRight} = metrics;
129
+ const width =
130
+ inkLeft > 0
131
+ ? Math.max(
132
+ Math.ceil(inkRight + inkLeft),
133
+ Math.ceil(inkRight - inkLeft + Math.ceil(inkLeft))
134
+ )
135
+ : Math.ceil(inkRight - inkLeft);
136
+ return {
137
+ advance: metrics.width,
138
+ width,
139
+ ascent: Math.ceil(metrics.actualBoundingBoxAscent),
140
+ descent: Math.ceil(metrics.actualBoundingBoxDescent)
141
+ };
142
+ },
143
+ draw(char: string) {
144
+ const glyph = tinySDF.draw(char);
145
+ // The glyph's origin is `shift.pixels` right of the buffer (and `glyphLeft` left of it, from
146
+ // TinySDF 2.2); that many columns of distance field are cut from the left.
147
+ const cut = Math.min(shift.pixels, Math.max(0, glyph.width - 1));
148
+ const width = Math.max(1, glyph.width - cut);
149
+ const height = Math.max(1, glyph.height);
150
+ const data = new ImageData(width, height);
151
+ for (let y = 0; y < glyph.height; y++) {
152
+ for (let x = 0; x < width; x++) {
153
+ data.data[4 * (y * width + x) + 3] = glyph.data[y * glyph.width + x + cut];
154
+ }
155
+ }
156
+ return {data, left: buffer + shift.pixels - (glyph.glyphLeft || 0) - cut, top: buffer};
157
+ }
158
+ };
159
+ }