@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.
- package/README.md +34 -2
- package/THIRD-PARTY-NOTICES.md +205 -0
- package/dist/geojson-worker.js +2160 -0
- package/dist/geojson-worker.js.map +6 -0
- package/dist/index.cjs +11388 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.js +11369 -0
- package/dist/index.js.map +6 -0
- package/dist/map-style.cjs +445 -0
- package/dist/map-style.cjs.map +6 -0
- package/dist/map-style.js +431 -0
- package/dist/map-style.js.map +6 -0
- package/dist/types/arabic-shaping.d.ts +7 -0
- package/dist/types/atmosphere-layer.d.ts +10 -0
- package/dist/types/basemap-layer.d.ts +150 -0
- package/dist/types/bidi.d.ts +8 -0
- package/dist/types/circle-layer.d.ts +49 -0
- package/dist/types/fill-extrusion-lighting-extension.d.ts +49 -0
- package/dist/types/fill-outline-extension.d.ts +22 -0
- package/dist/types/fill-pattern.d.ts +99 -0
- package/dist/types/fill-style-extensions.d.ts +100 -0
- package/dist/types/geojson-source.d.ts +29 -0
- package/dist/types/geojson-tiler.d.ts +48 -0
- package/dist/types/geojson-worker.d.ts +40 -0
- package/dist/types/globe-horizon-extension.d.ts +61 -0
- package/dist/types/globe-layers.d.ts +239 -0
- package/dist/types/globe-line-angle-extension.d.ts +37 -0
- package/dist/types/glyph-font-renderer.d.ts +37 -0
- package/dist/types/glyph-pbf.d.ts +37 -0
- package/dist/types/glyph-store.d.ts +103 -0
- package/dist/types/grid-index.d.ts +47 -0
- package/dist/types/hillshade-layer.d.ts +154 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/is-globe-viewport.d.ts +2 -0
- package/dist/types/label-font-renderer.d.ts +18 -0
- package/dist/types/label-placement.d.ts +247 -0
- package/dist/types/label-text-layer.d.ts +231 -0
- package/dist/types/line-blur-extension.d.ts +73 -0
- package/dist/types/line-glyphs.d.ts +60 -0
- package/dist/types/line-placement.d.ts +93 -0
- package/dist/types/map-style-loader.d.ts +48 -0
- package/dist/types/map-style-schema.d.ts +72 -0
- package/dist/types/map-style.d.ts +6 -0
- package/dist/types/mapbox-style.d.ts +40 -0
- package/dist/types/mvt-label-layer.d.ts +923 -0
- package/dist/types/polylabel.d.ts +17 -0
- package/dist/types/raster-color-extension.d.ts +146 -0
- package/dist/types/shared-texture.d.ts +34 -0
- package/dist/types/sort-key.d.ts +10 -0
- package/dist/types/sprite.d.ts +82 -0
- package/dist/types/style-accessor.d.ts +45 -0
- package/dist/types/style-expression.d.ts +83 -0
- package/dist/types/style-resolver.d.ts +94 -0
- package/dist/types/text-font.d.ts +36 -0
- package/dist/types/text-halo-blur-extension.d.ts +55 -0
- package/dist/types/text-layout.d.ts +71 -0
- package/dist/types/util.d.ts +22 -0
- package/dist/types/zoom-paint-extension.d.ts +72 -0
- package/package.json +80 -3
- package/src/arabic-shaping.ts +366 -0
- package/src/atmosphere-layer.ts +19 -0
- package/src/basemap-layer.ts +533 -0
- package/src/bidi.ts +199 -0
- package/src/circle-layer.ts +191 -0
- package/src/fill-extrusion-lighting-extension.ts +206 -0
- package/src/fill-outline-extension.ts +70 -0
- package/src/fill-pattern.ts +400 -0
- package/src/fill-style-extensions.ts +177 -0
- package/src/geojson-source.ts +318 -0
- package/src/geojson-tiler.ts +185 -0
- package/src/geojson-worker.ts +98 -0
- package/src/globe-horizon-extension.ts +64 -0
- package/src/globe-layers.ts +3487 -0
- package/src/globe-line-angle-extension.ts +131 -0
- package/src/glyph-font-renderer.ts +173 -0
- package/src/glyph-pbf.ts +164 -0
- package/src/glyph-store.ts +326 -0
- package/src/grid-index.ts +177 -0
- package/src/hillshade-layer.ts +775 -0
- package/src/index.ts +18 -0
- package/src/is-globe-viewport.ts +24 -0
- package/src/label-font-renderer.ts +159 -0
- package/src/label-placement.ts +727 -0
- package/src/label-text-layer.ts +913 -0
- package/src/line-blur-extension.ts +237 -0
- package/src/line-glyphs.ts +364 -0
- package/src/line-placement.ts +446 -0
- package/src/map-style-loader.ts +56 -0
- package/src/map-style-schema.ts +83 -0
- package/src/map-style.ts +23 -0
- package/src/mapbox-style.ts +168 -0
- package/src/mvt-label-layer.ts +3744 -0
- package/src/polylabel.ts +312 -0
- package/src/raster-color-extension.ts +245 -0
- package/src/shared-texture.ts +153 -0
- package/src/sort-key.ts +63 -0
- package/src/sprite.ts +244 -0
- package/src/style-accessor.ts +95 -0
- package/src/style-expression.ts +327 -0
- package/src/style-resolver.ts +301 -0
- package/src/text-font.ts +150 -0
- package/src/text-halo-blur-extension.ts +115 -0
- package/src/text-layout.ts +441 -0
- package/src/util.ts +47 -0
- 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
|
+
}
|