@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
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
compileStyleFilter,
|
|
7
|
+
getCompiledStyleProperty,
|
|
8
|
+
getStylePropertyReference
|
|
9
|
+
} from './style-expression';
|
|
10
|
+
|
|
11
|
+
type GlobalProperties = {
|
|
12
|
+
zoom?: number;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type GeometryLike = {
|
|
17
|
+
type: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type FeatureLike = {
|
|
21
|
+
type?: number | string;
|
|
22
|
+
geometry?: GeometryLike;
|
|
23
|
+
properties?: Record<string, unknown>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type FilterFeaturesOptions = {
|
|
27
|
+
features: FeatureLike[];
|
|
28
|
+
filter: unknown[];
|
|
29
|
+
globalProperties?: GlobalProperties;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type FindFeaturesStyledByLayerOptions = {
|
|
33
|
+
features: Record<string, Record<string, FeatureLike[]>>;
|
|
34
|
+
layer: {
|
|
35
|
+
source?: string;
|
|
36
|
+
'source-layer'?: string;
|
|
37
|
+
filter?: unknown[];
|
|
38
|
+
};
|
|
39
|
+
globalProperties?: GlobalProperties;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type PropertyReference = Record<string, unknown> | null;
|
|
43
|
+
|
|
44
|
+
type VisitedProperty = {
|
|
45
|
+
layer: Record<string, any>;
|
|
46
|
+
path: string[];
|
|
47
|
+
key: string;
|
|
48
|
+
value: unknown;
|
|
49
|
+
reference: PropertyReference;
|
|
50
|
+
set: (value: unknown) => void;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type VisitOptions = {
|
|
54
|
+
paint?: boolean;
|
|
55
|
+
layout?: boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Applies a Mapbox style-spec filter expression to a set of features.
|
|
60
|
+
*/
|
|
61
|
+
export function filterFeatures({
|
|
62
|
+
features,
|
|
63
|
+
filter,
|
|
64
|
+
globalProperties = {}
|
|
65
|
+
}: FilterFeaturesOptions): FeatureLike[] {
|
|
66
|
+
if (!features || features.length === 0) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const filterFn = compileStyleFilter(filter);
|
|
71
|
+
|
|
72
|
+
// `compileStyleFilter` derives the geometry type itself, so the features are not modified.
|
|
73
|
+
return features.filter(feature => filterFn(globalProperties, feature));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Finds the source-layer features that participate in a particular style layer
|
|
78
|
+
* and applies the layer's filter expression when present.
|
|
79
|
+
*/
|
|
80
|
+
export function findFeaturesStyledByLayer({
|
|
81
|
+
features,
|
|
82
|
+
layer,
|
|
83
|
+
globalProperties
|
|
84
|
+
}: FindFeaturesStyledByLayerOptions): FeatureLike[] {
|
|
85
|
+
const sourceLayerFeatures = features[layer.source || '']?.[layer['source-layer'] || ''];
|
|
86
|
+
if (!sourceLayerFeatures) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (layer.filter && layer.filter.length > 0) {
|
|
91
|
+
return filterFeatures({
|
|
92
|
+
features: sourceLayerFeatures,
|
|
93
|
+
filter: layer.filter,
|
|
94
|
+
globalProperties
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return sourceLayerFeatures;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Evaluates paint properties for a style layer at the requested zoom.
|
|
103
|
+
*/
|
|
104
|
+
export function parseProperties(
|
|
105
|
+
layer: Record<string, any>,
|
|
106
|
+
globalProperties: GlobalProperties
|
|
107
|
+
): Array<Record<string, unknown>> {
|
|
108
|
+
const layerProperties: Array<Record<string, unknown>> = [];
|
|
109
|
+
visitProperties(layer, {paint: true}, property => {
|
|
110
|
+
layerProperties.push(parseProperty(property, globalProperties));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return layerProperties;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Walks layout and paint properties for a style layer.
|
|
118
|
+
*/
|
|
119
|
+
function visitProperties(
|
|
120
|
+
layer: Record<string, any>,
|
|
121
|
+
options: VisitOptions,
|
|
122
|
+
callback: (property: VisitedProperty) => void
|
|
123
|
+
): void {
|
|
124
|
+
function inner(targetLayer: Record<string, any>, propertyType: 'paint' | 'layout') {
|
|
125
|
+
const properties = targetLayer[propertyType];
|
|
126
|
+
if (!properties) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Object.keys(properties).forEach(key => {
|
|
131
|
+
callback({
|
|
132
|
+
layer: targetLayer,
|
|
133
|
+
path: [targetLayer.id, propertyType, key],
|
|
134
|
+
key,
|
|
135
|
+
value: properties[key],
|
|
136
|
+
reference: getStylePropertyReference(key),
|
|
137
|
+
set(value) {
|
|
138
|
+
properties[key] = value;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (options.paint) {
|
|
145
|
+
inner(layer, 'paint');
|
|
146
|
+
}
|
|
147
|
+
if (options.layout) {
|
|
148
|
+
inner(layer, 'layout');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Evaluates a single style property expression.
|
|
154
|
+
*/
|
|
155
|
+
function parseProperty(
|
|
156
|
+
property: VisitedProperty,
|
|
157
|
+
globalProperties: GlobalProperties
|
|
158
|
+
): Record<string, unknown> {
|
|
159
|
+
const compiled = getCompiledStyleProperty(property.layer, property.key);
|
|
160
|
+
return {
|
|
161
|
+
[property.key]: compiled?.evaluateWithGlobals({
|
|
162
|
+
...globalProperties,
|
|
163
|
+
zoom: globalProperties.zoom ?? 0
|
|
164
|
+
})
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export {colorToArray} from './style-expression';
|