@deck.gl-community/basemap-layers 9.3.0-beta.2
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/LICENSE +19 -0
- package/README.md +14 -0
- package/dist/atmosphere-layer.d.ts +11 -0
- package/dist/atmosphere-layer.d.ts.map +1 -0
- package/dist/atmosphere-layer.js +15 -0
- package/dist/atmosphere-layer.js.map +1 -0
- package/dist/basemap-layer.d.ts +67 -0
- package/dist/basemap-layer.d.ts.map +1 -0
- package/dist/basemap-layer.js +115 -0
- package/dist/basemap-layer.js.map +1 -0
- package/dist/globe-layers.d.ts +22 -0
- package/dist/globe-layers.d.ts.map +1 -0
- package/dist/globe-layers.js +451 -0
- package/dist/globe-layers.js.map +1 -0
- package/dist/index.cjs +947 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/map-style-loader.d.ts +49 -0
- package/dist/map-style-loader.d.ts.map +1 -0
- package/dist/map-style-loader.js +35 -0
- package/dist/map-style-loader.js.map +1 -0
- package/dist/map-style-schema.d.ts +71 -0
- package/dist/map-style-schema.d.ts.map +1 -0
- package/dist/map-style-schema.js +45 -0
- package/dist/map-style-schema.js.map +1 -0
- package/dist/map-style.cjs +250 -0
- package/dist/map-style.cjs.map +7 -0
- package/dist/map-style.d.ts +7 -0
- package/dist/map-style.d.ts.map +1 -0
- package/dist/map-style.js +6 -0
- package/dist/map-style.js.map +1 -0
- package/dist/mapbox-style.d.ts +41 -0
- package/dist/mapbox-style.d.ts.map +1 -0
- package/dist/mapbox-style.js +113 -0
- package/dist/mapbox-style.js.map +1 -0
- package/dist/mvt-label-layer.d.ts +8142 -0
- package/dist/mvt-label-layer.d.ts.map +1 -0
- package/dist/mvt-label-layer.js +175 -0
- package/dist/mvt-label-layer.js.map +1 -0
- package/dist/style-resolver.d.ts +88 -0
- package/dist/style-resolver.d.ts.map +1 -0
- package/dist/style-resolver.js +63 -0
- package/dist/style-resolver.js.map +1 -0
- package/dist/util.d.ts +21 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +18 -0
- package/dist/util.js.map +1 -0
- package/package.json +60 -0
- package/src/atmosphere-layer.ts +15 -0
- package/src/basemap-layer.ts +183 -0
- package/src/globe-layers.ts +780 -0
- package/src/index.ts +3 -0
- package/src/map-style-loader.ts +52 -0
- package/src/map-style-schema.ts +54 -0
- package/src/map-style.ts +18 -0
- package/src/mapbox-style.ts +196 -0
- package/src/mvt-label-layer.ts +269 -0
- package/src/style-resolver.ts +173 -0
- package/src/util.ts +38 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,947 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __publicField = (obj, key, value) => {
|
|
20
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// dist/index.js
|
|
25
|
+
var dist_exports = {};
|
|
26
|
+
__export(dist_exports, {
|
|
27
|
+
BasemapLayer: () => BasemapLayer,
|
|
28
|
+
getBasemapLayers: () => getBasemapLayers,
|
|
29
|
+
getGlobeBaseLayers: () => getGlobeBaseLayers,
|
|
30
|
+
getGlobeTopLayers: () => getGlobeTopLayers
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(dist_exports);
|
|
33
|
+
|
|
34
|
+
// dist/basemap-layer.js
|
|
35
|
+
var import_core3 = require("@deck.gl/core");
|
|
36
|
+
var import_core4 = require("@loaders.gl/core");
|
|
37
|
+
|
|
38
|
+
// dist/globe-layers.js
|
|
39
|
+
var import_core2 = require("@deck.gl/core");
|
|
40
|
+
var import_geo_layers = require("@deck.gl/geo-layers");
|
|
41
|
+
var import_layers2 = require("@deck.gl/layers");
|
|
42
|
+
var import_mvt = require("@loaders.gl/mvt");
|
|
43
|
+
|
|
44
|
+
// dist/atmosphere-layer.js
|
|
45
|
+
function getGlobeAtmosphereLayer() {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function getGlobeAtmosphereSkyLayer() {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// dist/mvt-label-layer.js
|
|
53
|
+
var import_core = require("@deck.gl/core");
|
|
54
|
+
var import_extensions = require("@deck.gl/extensions");
|
|
55
|
+
var import_layers = require("@deck.gl/layers");
|
|
56
|
+
function evaluateStyleValue(value, zoom) {
|
|
57
|
+
var _a;
|
|
58
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
if (value && typeof value === "object" && Array.isArray(value.stops)) {
|
|
62
|
+
let resolved = (_a = value.stops[0]) == null ? void 0 : _a[1];
|
|
63
|
+
for (const stop of value.stops) {
|
|
64
|
+
if (zoom >= stop[0]) {
|
|
65
|
+
resolved = stop[1];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return resolved;
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
function resolveTokenString(template, properties) {
|
|
73
|
+
if (typeof template !== "string") {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return template.replace(/\{([^}]+)\}/g, (_, token) => {
|
|
77
|
+
const value = properties == null ? void 0 : properties[token];
|
|
78
|
+
return value === null || value === void 0 ? "" : String(value);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function getLineMidpoint(coordinates) {
|
|
82
|
+
if (!Array.isArray(coordinates) || coordinates.length === 0) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return coordinates[Math.floor(coordinates.length / 2)] || coordinates[0] || null;
|
|
86
|
+
}
|
|
87
|
+
function getCollisionPriority(feature) {
|
|
88
|
+
const properties = (feature == null ? void 0 : feature.properties) || {};
|
|
89
|
+
if (properties.capital > 0 || properties.class === "country") {
|
|
90
|
+
return 1e3;
|
|
91
|
+
}
|
|
92
|
+
if (properties.class === "state" || properties.class === "city") {
|
|
93
|
+
return 750;
|
|
94
|
+
}
|
|
95
|
+
if (properties.layerName === "water_name" || properties.layerName === "waterway") {
|
|
96
|
+
return 400;
|
|
97
|
+
}
|
|
98
|
+
return 100;
|
|
99
|
+
}
|
|
100
|
+
var MVTLabelLayer = class extends import_core.CompositeLayer {
|
|
101
|
+
/** Current label-row state. */
|
|
102
|
+
state = void 0;
|
|
103
|
+
/**
|
|
104
|
+
* Extracts the visible label text for a decoded feature.
|
|
105
|
+
*/
|
|
106
|
+
getLabel(feature) {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
const { styleLayer, zoom = 0 } = this.props;
|
|
109
|
+
const textField = evaluateStyleValue((_a = styleLayer == null ? void 0 : styleLayer.layout) == null ? void 0 : _a["text-field"], zoom);
|
|
110
|
+
const label = (_b = resolveTokenString(textField, feature.properties)) == null ? void 0 : _b.trim();
|
|
111
|
+
return label || void 0;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the font size for a decoded feature label.
|
|
115
|
+
*/
|
|
116
|
+
getLabelSize(_feature) {
|
|
117
|
+
var _a;
|
|
118
|
+
const { styleLayer, zoom = 0 } = this.props;
|
|
119
|
+
return Number(evaluateStyleValue((_a = styleLayer == null ? void 0 : styleLayer.layout) == null ? void 0 : _a["text-size"], zoom) || 14);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns the text color for a decoded feature label.
|
|
123
|
+
*/
|
|
124
|
+
getLabelColor(_feature) {
|
|
125
|
+
return this.props.textColor || [255, 255, 255];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Extracts candidate label anchor positions from a feature geometry.
|
|
129
|
+
*/
|
|
130
|
+
getLabelAnchors(feature) {
|
|
131
|
+
const { type, coordinates } = feature.geometry;
|
|
132
|
+
switch (type) {
|
|
133
|
+
case "Point":
|
|
134
|
+
return [coordinates];
|
|
135
|
+
case "MultiPoint":
|
|
136
|
+
return coordinates;
|
|
137
|
+
case "LineString": {
|
|
138
|
+
const midpoint = getLineMidpoint(coordinates);
|
|
139
|
+
return midpoint ? [midpoint] : [];
|
|
140
|
+
}
|
|
141
|
+
case "MultiLineString": {
|
|
142
|
+
const midpoint = getLineMidpoint(coordinates[0]);
|
|
143
|
+
return midpoint ? [midpoint] : [];
|
|
144
|
+
}
|
|
145
|
+
default:
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Recomputes label anchor rows when the source tile data changes.
|
|
151
|
+
*/
|
|
152
|
+
updateState({ changeFlags }) {
|
|
153
|
+
const { data } = this.props;
|
|
154
|
+
if (changeFlags.dataChanged && data) {
|
|
155
|
+
const features = Array.isArray(data) ? data : data.features || [];
|
|
156
|
+
const labelData = features.flatMap((feature, index) => {
|
|
157
|
+
const labelAnchors = this.getLabelAnchors(feature);
|
|
158
|
+
return labelAnchors.map((position) => this.getSubLayerRow({ position }, feature, index));
|
|
159
|
+
});
|
|
160
|
+
this.setState({ labelData });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Renders the optional debug geometry and the text labels.
|
|
165
|
+
*/
|
|
166
|
+
renderLayers() {
|
|
167
|
+
const { config, labelSizeUnits, labelBackground, billboard, renderGeometry } = this.props;
|
|
168
|
+
const layers = [];
|
|
169
|
+
if (renderGeometry) {
|
|
170
|
+
layers.push(new import_layers.GeoJsonLayer({
|
|
171
|
+
...this.props,
|
|
172
|
+
...this.getSubLayerProps({ id: "geojson" }),
|
|
173
|
+
data: this.props.data
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
if (config.labels) {
|
|
177
|
+
const hasBackground = Array.isArray(labelBackground) && labelBackground.length >= 3;
|
|
178
|
+
layers.push(new import_layers.TextLayer({
|
|
179
|
+
...this.getSubLayerProps({ id: "text" }),
|
|
180
|
+
data: this.state.labelData,
|
|
181
|
+
extensions: [...this.props.extensions || [], new import_extensions.CollisionFilterExtension()],
|
|
182
|
+
parameters: {
|
|
183
|
+
depthTest: false
|
|
184
|
+
},
|
|
185
|
+
billboard,
|
|
186
|
+
characterSet: "auto",
|
|
187
|
+
collisionEnabled: true,
|
|
188
|
+
collisionGroup: "basemap-labels",
|
|
189
|
+
getCollisionPriority: this.getSubLayerAccessor((feature) => getCollisionPriority(feature)),
|
|
190
|
+
fontFamily: this.props.fontFamily,
|
|
191
|
+
sizeUnits: labelSizeUnits,
|
|
192
|
+
background: hasBackground,
|
|
193
|
+
getBackgroundColor: hasBackground ? labelBackground : [0, 0, 0, 0],
|
|
194
|
+
getPosition: (d) => d.position,
|
|
195
|
+
getText: this.getSubLayerAccessor((feature) => this.getLabel(feature)),
|
|
196
|
+
getSize: this.getSubLayerAccessor((feature) => this.getLabelSize(feature)),
|
|
197
|
+
getColor: this.getSubLayerAccessor((feature) => this.getLabelColor(feature))
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
return layers;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
/** Deck.gl layer name. */
|
|
204
|
+
__publicField(MVTLabelLayer, "layerName", "MVTLabelLayer");
|
|
205
|
+
/** Default props for {@link MVTLabelLayer}. */
|
|
206
|
+
__publicField(MVTLabelLayer, "defaultProps", {
|
|
207
|
+
...import_layers.GeoJsonLayer.defaultProps,
|
|
208
|
+
billboard: true,
|
|
209
|
+
renderGeometry: false,
|
|
210
|
+
labelSizeUnits: "pixels",
|
|
211
|
+
labelBackground: { type: "color", value: null, optional: true },
|
|
212
|
+
fontFamily: "Monaco, monospace"
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// dist/mapbox-style.js
|
|
216
|
+
var import_mapbox_gl_style_spec = require("@mapbox/mapbox-gl-style-spec");
|
|
217
|
+
var GEOM_TYPES = {
|
|
218
|
+
Point: 1,
|
|
219
|
+
MultiPoint: 1,
|
|
220
|
+
LineString: 2,
|
|
221
|
+
MultiLineString: 2,
|
|
222
|
+
Polygon: 3,
|
|
223
|
+
MultiPolygon: 3
|
|
224
|
+
};
|
|
225
|
+
function filterFeatures({ features, filter, globalProperties = {} }) {
|
|
226
|
+
if (!features || features.length === 0) {
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
const filterFn = (0, import_mapbox_gl_style_spec.featureFilter)(filter).filter;
|
|
230
|
+
return features.filter((feature) => {
|
|
231
|
+
var _a;
|
|
232
|
+
if (![1, 2, 3].includes(Number(feature.type))) {
|
|
233
|
+
feature.type = GEOM_TYPES[((_a = feature.geometry) == null ? void 0 : _a.type) || ""] ?? feature.type;
|
|
234
|
+
}
|
|
235
|
+
return filterFn(globalProperties, feature);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function parseProperties(layer, globalProperties) {
|
|
239
|
+
const layerProperties = [];
|
|
240
|
+
visitProperties(layer, { paint: true }, (property) => {
|
|
241
|
+
layerProperties.push(parseProperty(property, globalProperties));
|
|
242
|
+
});
|
|
243
|
+
return layerProperties;
|
|
244
|
+
}
|
|
245
|
+
function visitProperties(layer, options, callback) {
|
|
246
|
+
function inner(targetLayer, propertyType) {
|
|
247
|
+
const properties = targetLayer[propertyType];
|
|
248
|
+
if (!properties) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
Object.keys(properties).forEach((key) => {
|
|
252
|
+
callback({
|
|
253
|
+
layer: targetLayer,
|
|
254
|
+
path: [targetLayer.id, propertyType, key],
|
|
255
|
+
key,
|
|
256
|
+
value: properties[key],
|
|
257
|
+
reference: getPropertyReference(key),
|
|
258
|
+
set(value) {
|
|
259
|
+
properties[key] = value;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (options.paint) {
|
|
265
|
+
inner(layer, "paint");
|
|
266
|
+
}
|
|
267
|
+
if (options.layout) {
|
|
268
|
+
inner(layer, "layout");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function getPropertyReference(propertyName) {
|
|
272
|
+
for (let i = 0; i < import_mapbox_gl_style_spec.latest.layout.length; i++) {
|
|
273
|
+
for (const key in import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.layout[i]]) {
|
|
274
|
+
if (key === propertyName) {
|
|
275
|
+
return import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.layout[i]][key];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for (let i = 0; i < import_mapbox_gl_style_spec.latest.paint.length; i++) {
|
|
280
|
+
for (const key in import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.paint[i]]) {
|
|
281
|
+
if (key === propertyName) {
|
|
282
|
+
return import_mapbox_gl_style_spec.latest[import_mapbox_gl_style_spec.latest.paint[i]][key];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
function parseProperty(property, globalProperties) {
|
|
289
|
+
const exp = import_mapbox_gl_style_spec.expression.normalizePropertyExpression(property.value, property.reference);
|
|
290
|
+
const result = exp.evaluate(globalProperties);
|
|
291
|
+
if (result instanceof import_mapbox_gl_style_spec.Color) {
|
|
292
|
+
return { [property.key]: result.toArray() };
|
|
293
|
+
}
|
|
294
|
+
return { [property.key]: result };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// dist/map-style-schema.js
|
|
298
|
+
var import_zod = require("zod");
|
|
299
|
+
var BasemapSourceSchema = import_zod.z.object({
|
|
300
|
+
type: import_zod.z.string().optional(),
|
|
301
|
+
url: import_zod.z.string().optional(),
|
|
302
|
+
tiles: import_zod.z.array(import_zod.z.string()).optional(),
|
|
303
|
+
minzoom: import_zod.z.number().optional(),
|
|
304
|
+
maxzoom: import_zod.z.number().optional(),
|
|
305
|
+
tileSize: import_zod.z.number().optional()
|
|
306
|
+
}).catchall(import_zod.z.unknown());
|
|
307
|
+
var BasemapStyleLayerSchema = import_zod.z.object({
|
|
308
|
+
id: import_zod.z.string(),
|
|
309
|
+
type: import_zod.z.string(),
|
|
310
|
+
source: import_zod.z.string().optional(),
|
|
311
|
+
"source-layer": import_zod.z.string().optional(),
|
|
312
|
+
minzoom: import_zod.z.number().optional(),
|
|
313
|
+
maxzoom: import_zod.z.number().optional(),
|
|
314
|
+
filter: import_zod.z.array(import_zod.z.unknown()).optional(),
|
|
315
|
+
paint: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
|
|
316
|
+
layout: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
|
|
317
|
+
}).catchall(import_zod.z.unknown());
|
|
318
|
+
var BasemapStyleSchema = import_zod.z.object({
|
|
319
|
+
version: import_zod.z.number().optional(),
|
|
320
|
+
metadata: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
|
|
321
|
+
sources: import_zod.z.record(import_zod.z.string(), BasemapSourceSchema).optional(),
|
|
322
|
+
layers: import_zod.z.array(BasemapStyleLayerSchema).optional()
|
|
323
|
+
}).catchall(import_zod.z.unknown());
|
|
324
|
+
var ResolvedBasemapStyleSchema = import_zod.z.object({
|
|
325
|
+
version: import_zod.z.number().optional(),
|
|
326
|
+
metadata: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
|
|
327
|
+
sources: import_zod.z.record(import_zod.z.string(), BasemapSourceSchema),
|
|
328
|
+
layers: import_zod.z.array(BasemapStyleLayerSchema)
|
|
329
|
+
}).catchall(import_zod.z.unknown());
|
|
330
|
+
|
|
331
|
+
// dist/style-resolver.js
|
|
332
|
+
function normalizeUrl(url, baseUrl) {
|
|
333
|
+
if (!url) {
|
|
334
|
+
return url;
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
return decodeURI(new URL(url, baseUrl).toString());
|
|
338
|
+
} catch {
|
|
339
|
+
return url;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function normalizeTiles(tiles, baseUrl) {
|
|
343
|
+
return Array.isArray(tiles) ? tiles.map((tile) => normalizeUrl(tile, baseUrl) || tile) : tiles;
|
|
344
|
+
}
|
|
345
|
+
async function fetchJson(url, loadOptions) {
|
|
346
|
+
const fetchFn = (loadOptions == null ? void 0 : loadOptions.fetch) || fetch;
|
|
347
|
+
const response = await fetchFn(url, loadOptions == null ? void 0 : loadOptions.fetchOptions);
|
|
348
|
+
if (!response.ok) {
|
|
349
|
+
throw new Error(`Failed to load basemap resource: ${url} (${response.status})`);
|
|
350
|
+
}
|
|
351
|
+
return await response.json();
|
|
352
|
+
}
|
|
353
|
+
async function resolveSource(source, baseUrl, loadOptions) {
|
|
354
|
+
if (!source) {
|
|
355
|
+
return source;
|
|
356
|
+
}
|
|
357
|
+
const resolvedSource = { ...source };
|
|
358
|
+
let sourceBaseUrl = baseUrl;
|
|
359
|
+
if (resolvedSource.url) {
|
|
360
|
+
const tileJsonUrl = normalizeUrl(resolvedSource.url, baseUrl);
|
|
361
|
+
const tileJson = await fetchJson(tileJsonUrl || resolvedSource.url, loadOptions);
|
|
362
|
+
Object.assign(resolvedSource, tileJson);
|
|
363
|
+
resolvedSource.url = tileJsonUrl;
|
|
364
|
+
sourceBaseUrl = tileJsonUrl;
|
|
365
|
+
}
|
|
366
|
+
if (resolvedSource.tiles) {
|
|
367
|
+
resolvedSource.tiles = normalizeTiles(resolvedSource.tiles, sourceBaseUrl);
|
|
368
|
+
}
|
|
369
|
+
return resolvedSource;
|
|
370
|
+
}
|
|
371
|
+
async function resolveBasemapStyle(style, loadOptions) {
|
|
372
|
+
const styleDefinition = BasemapStyleSchema.parse(typeof style === "string" ? await fetchJson(style, loadOptions) : structuredClone(style));
|
|
373
|
+
const baseUrl = typeof style === "string" ? style : loadOptions == null ? void 0 : loadOptions.baseUrl;
|
|
374
|
+
const resolvedSources = {};
|
|
375
|
+
await Promise.all(Object.entries(styleDefinition.sources || {}).map(async ([sourceId, source]) => {
|
|
376
|
+
resolvedSources[sourceId] = await resolveSource(source, baseUrl, loadOptions) || {};
|
|
377
|
+
}));
|
|
378
|
+
return ResolvedBasemapStyleSchema.parse({
|
|
379
|
+
...styleDefinition,
|
|
380
|
+
sources: resolvedSources,
|
|
381
|
+
layers: [...styleDefinition.layers || []]
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// dist/map-style-loader.js
|
|
386
|
+
var VERSION = true ? "9.3.0-beta.2" : "latest";
|
|
387
|
+
function getMapStyleLoadOptions(options, context) {
|
|
388
|
+
var _a, _b;
|
|
389
|
+
return {
|
|
390
|
+
...options == null ? void 0 : options.mapStyle,
|
|
391
|
+
baseUrl: ((_a = options == null ? void 0 : options.mapStyle) == null ? void 0 : _a.baseUrl) || (context == null ? void 0 : context.url) || (context == null ? void 0 : context.baseUrl),
|
|
392
|
+
fetch: ((_b = options == null ? void 0 : options.mapStyle) == null ? void 0 : _b.fetch) || (context == null ? void 0 : context.fetch)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
var MapStyleLoader = {
|
|
396
|
+
dataType: null,
|
|
397
|
+
batchType: null,
|
|
398
|
+
name: "Map Style",
|
|
399
|
+
id: "map-style",
|
|
400
|
+
module: "basemap-layers",
|
|
401
|
+
version: VERSION,
|
|
402
|
+
worker: false,
|
|
403
|
+
extensions: ["json"],
|
|
404
|
+
mimeTypes: ["application/json", "application/vnd.mapbox.style+json"],
|
|
405
|
+
text: true,
|
|
406
|
+
options: {
|
|
407
|
+
mapStyle: {}
|
|
408
|
+
},
|
|
409
|
+
parse: async (data, options, context) => {
|
|
410
|
+
const text = typeof data === "string" ? data : new TextDecoder().decode(data);
|
|
411
|
+
const style = JSON.parse(text);
|
|
412
|
+
const resolved = await resolveBasemapStyle(style, getMapStyleLoadOptions(options, context));
|
|
413
|
+
return ResolvedBasemapStyleSchema.parse(resolved);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// dist/globe-layers.js
|
|
418
|
+
function logBasemapRuntimeEvent(message, details) {
|
|
419
|
+
import_core2.log.info(`[BasemapLayer] ${message}`, details ?? "")();
|
|
420
|
+
}
|
|
421
|
+
function logBasemapRuntimeError(message, error, details) {
|
|
422
|
+
import_core2.log.error(`[BasemapLayer] ${message}`, details || "", error)();
|
|
423
|
+
}
|
|
424
|
+
function getBackgroundParameters(mode) {
|
|
425
|
+
return mode === "globe" ? { depthTest: true, depthWriteEnabled: true, depthCompare: "less-equal", cullMode: "back" } : { depthTest: false, cullMode: "none" };
|
|
426
|
+
}
|
|
427
|
+
function getTileParameters(mode) {
|
|
428
|
+
return mode === "globe" ? { depthTest: true, depthWriteEnabled: true, depthCompare: "less-equal", cullMode: "back" } : { depthTest: false, cullMode: "none" };
|
|
429
|
+
}
|
|
430
|
+
var BACKGROUND_DATA = [
|
|
431
|
+
[
|
|
432
|
+
[-180, 90],
|
|
433
|
+
[0, 90],
|
|
434
|
+
[180, 90],
|
|
435
|
+
[180, -90],
|
|
436
|
+
[0, -90],
|
|
437
|
+
[-180, -90]
|
|
438
|
+
]
|
|
439
|
+
];
|
|
440
|
+
var BACKGROUND_NORTH_POLE_DATA = [
|
|
441
|
+
[
|
|
442
|
+
[-180, 90],
|
|
443
|
+
[0, 90],
|
|
444
|
+
[180, 90],
|
|
445
|
+
[180, 85],
|
|
446
|
+
[0, 85],
|
|
447
|
+
[-180, 85]
|
|
448
|
+
]
|
|
449
|
+
];
|
|
450
|
+
var SUPPORTED_TYPES = /* @__PURE__ */ new Set(["background", "fill", "line", "symbol", "raster"]);
|
|
451
|
+
var DEFAULT_CONFIG = { atmosphere: false, basemap: true, labels: true };
|
|
452
|
+
function withOpacity(color, opacity = 1) {
|
|
453
|
+
if (!color) {
|
|
454
|
+
return [0, 0, 0, 0];
|
|
455
|
+
}
|
|
456
|
+
const alpha = color.length > 3 ? color[3] <= 1 ? color[3] * 255 : color[3] : 255;
|
|
457
|
+
return [color[0], color[1], color[2], Math.round(alpha * opacity)];
|
|
458
|
+
}
|
|
459
|
+
function getPaint(layer, zoom) {
|
|
460
|
+
const properties = parseProperties(layer, { zoom });
|
|
461
|
+
return Object.fromEntries(properties.map((entry) => [Object.keys(entry)[0], Object.values(entry)[0]]));
|
|
462
|
+
}
|
|
463
|
+
function filterTileFeatures(features, styleLayer, zoom) {
|
|
464
|
+
const sourceLayer = styleLayer["source-layer"];
|
|
465
|
+
const sourceFeatures = sourceLayer ? features.filter((feature) => {
|
|
466
|
+
var _a;
|
|
467
|
+
return ((_a = feature.properties) == null ? void 0 : _a.layerName) === sourceLayer;
|
|
468
|
+
}) : features;
|
|
469
|
+
if (!styleLayer.filter) {
|
|
470
|
+
return sourceFeatures;
|
|
471
|
+
}
|
|
472
|
+
return filterFeatures({
|
|
473
|
+
features: sourceFeatures,
|
|
474
|
+
filter: styleLayer.filter,
|
|
475
|
+
globalProperties: { zoom }
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
function isStyleLayerVisibleAtZoom(styleLayer, zoom, source) {
|
|
479
|
+
const minZoom = styleLayer.minzoom ?? (source == null ? void 0 : source.minzoom) ?? 0;
|
|
480
|
+
const maxZoom = styleLayer.maxzoom ?? (source == null ? void 0 : source.maxzoom) ?? 22;
|
|
481
|
+
return zoom >= minZoom && zoom < maxZoom;
|
|
482
|
+
}
|
|
483
|
+
function getTileFeatures(data) {
|
|
484
|
+
if (Array.isArray(data)) {
|
|
485
|
+
return data;
|
|
486
|
+
}
|
|
487
|
+
if (data && typeof data === "object" && Array.isArray(data.features)) {
|
|
488
|
+
return data.features;
|
|
489
|
+
}
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
function getSubLayerBaseProps(props) {
|
|
493
|
+
const { pickable, visible, opacity, modelMatrix, coordinateSystem, coordinateOrigin, extensions, highlightedObjectIndex, highlightColor, parameters, wrapLongitude } = props;
|
|
494
|
+
return {
|
|
495
|
+
pickable,
|
|
496
|
+
visible,
|
|
497
|
+
opacity,
|
|
498
|
+
modelMatrix,
|
|
499
|
+
coordinateSystem,
|
|
500
|
+
coordinateOrigin,
|
|
501
|
+
extensions,
|
|
502
|
+
highlightedObjectIndex,
|
|
503
|
+
highlightColor,
|
|
504
|
+
parameters,
|
|
505
|
+
wrapLongitude
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
function getLineWidthScale(styleLayer) {
|
|
509
|
+
const sourceLayer = styleLayer["source-layer"] || "";
|
|
510
|
+
const id = styleLayer.id || "";
|
|
511
|
+
if (sourceLayer === "transportation" || sourceLayer === "boundary" || id.includes("road-")) {
|
|
512
|
+
return 0.55;
|
|
513
|
+
}
|
|
514
|
+
if (sourceLayer === "waterway" || sourceLayer === "aeroway") {
|
|
515
|
+
return 0.75;
|
|
516
|
+
}
|
|
517
|
+
return 1;
|
|
518
|
+
}
|
|
519
|
+
function getGlobeFillColor(color, mode) {
|
|
520
|
+
if (mode !== "globe") {
|
|
521
|
+
return color;
|
|
522
|
+
}
|
|
523
|
+
return [color[0], color[1], color[2], 255];
|
|
524
|
+
}
|
|
525
|
+
function getConfig(globe) {
|
|
526
|
+
return { ...DEFAULT_CONFIG, ...(globe == null ? void 0 : globe.config) || {} };
|
|
527
|
+
}
|
|
528
|
+
function createBackgroundLayer({ idPrefix, layer, zoom, mode }) {
|
|
529
|
+
const paint = getPaint(layer, zoom);
|
|
530
|
+
return new import_layers2.SolidPolygonLayer({
|
|
531
|
+
id: `${idPrefix}-${layer.id}`,
|
|
532
|
+
data: BACKGROUND_DATA,
|
|
533
|
+
getPolygon: (d) => d,
|
|
534
|
+
stroked: false,
|
|
535
|
+
filled: true,
|
|
536
|
+
getFillColor: withOpacity(paint["background-color"], paint["background-opacity"] ?? 1),
|
|
537
|
+
parameters: getBackgroundParameters(mode)
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
function createRasterLayer({ idPrefix, layer, source, mode }) {
|
|
541
|
+
return new import_geo_layers.TileLayer({
|
|
542
|
+
id: `${idPrefix}-${layer.id}`,
|
|
543
|
+
data: source.tiles,
|
|
544
|
+
minZoom: layer.minzoom ?? source.minzoom ?? 0,
|
|
545
|
+
maxZoom: layer.maxzoom ?? source.maxzoom ?? 22,
|
|
546
|
+
tileSize: source.tileSize || 512,
|
|
547
|
+
renderSubLayers: (props) => {
|
|
548
|
+
var _a;
|
|
549
|
+
const { west, south, east, north } = ((_a = props.tile) == null ? void 0 : _a.bbox) || {};
|
|
550
|
+
return new import_layers2.BitmapLayer({
|
|
551
|
+
...props,
|
|
552
|
+
_imageCoordinateSystem: import_core2.COORDINATE_SYSTEM.CARTESIAN,
|
|
553
|
+
data: null,
|
|
554
|
+
image: props.data,
|
|
555
|
+
bounds: [west, south, east, north],
|
|
556
|
+
parameters: getTileParameters(mode)
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
onTileError: (error) => {
|
|
560
|
+
logBasemapRuntimeError("Raster tile failed to load", error, {
|
|
561
|
+
layerId: layer.id,
|
|
562
|
+
sourceId: layer.source
|
|
563
|
+
});
|
|
564
|
+
},
|
|
565
|
+
parameters: getTileParameters(mode)
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
var StyledMVTLayer = class extends import_geo_layers.MVTLayer {
|
|
569
|
+
getTileData(loadProps) {
|
|
570
|
+
const data = this.props.data;
|
|
571
|
+
const url = (0, import_geo_layers._getURLFromTemplate)(data, loadProps);
|
|
572
|
+
if (!url) {
|
|
573
|
+
return Promise.reject(new Error("Invalid URL"));
|
|
574
|
+
}
|
|
575
|
+
const loadOptions = this.getLoadOptions();
|
|
576
|
+
const coordinates = this.context.viewport.resolution ? "wgs84" : "local";
|
|
577
|
+
return this.props.fetch(url, {
|
|
578
|
+
propName: "data",
|
|
579
|
+
layer: this,
|
|
580
|
+
signal: loadProps.signal,
|
|
581
|
+
loadOptions: {
|
|
582
|
+
...loadOptions,
|
|
583
|
+
mimeType: "application/x-protobuf",
|
|
584
|
+
mvt: {
|
|
585
|
+
...(loadOptions == null ? void 0 : loadOptions.mvt) || {},
|
|
586
|
+
shape: "geojson",
|
|
587
|
+
coordinates,
|
|
588
|
+
tileIndex: loadProps.index
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
StyledMVTLayer.layerName = "StyledMVTLayer";
|
|
595
|
+
StyledMVTLayer.defaultProps = {
|
|
596
|
+
...import_geo_layers.MVTLayer.defaultProps,
|
|
597
|
+
binary: false,
|
|
598
|
+
loaders: [import_mvt.MVTWorkerLoader]
|
|
599
|
+
};
|
|
600
|
+
function createStyledVectorSubLayer({ idPrefix, sourceId, styleLayer, features, props, zoom, config, mode }) {
|
|
601
|
+
if (features.length === 0) {
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
const paint = getPaint(styleLayer, zoom);
|
|
605
|
+
const opacity = paint[`${styleLayer.type}-opacity`] ?? (styleLayer.type === "fill" ? paint["fill-opacity"] : paint["line-opacity"]) ?? 1;
|
|
606
|
+
const fillColor = withOpacity(paint["fill-color"], opacity);
|
|
607
|
+
const lineColor = withOpacity(paint["line-color"] || paint["fill-outline-color"] || [0, 0, 0, 0], opacity);
|
|
608
|
+
if (styleLayer.type === "symbol") {
|
|
609
|
+
return createSymbolSubLayer({ props, styleLayer, features, config, mode, zoom, opacity, paint });
|
|
610
|
+
}
|
|
611
|
+
return createGeometrySubLayer({ props, styleLayer, features, mode, fillColor, lineColor, paint });
|
|
612
|
+
}
|
|
613
|
+
function createVectorLayerGroup({ idPrefix, sourceId, source, styleLayers, zoom, config, loadOptions, mode }) {
|
|
614
|
+
const minZoom = Math.min(...styleLayers.map((layer) => layer.minzoom ?? source.minzoom ?? 0));
|
|
615
|
+
const maxZoom = Math.max(...styleLayers.map((layer) => layer.maxzoom ?? source.maxzoom ?? 22));
|
|
616
|
+
return new StyledMVTLayer({
|
|
617
|
+
id: `${idPrefix}-${sourceId}`,
|
|
618
|
+
data: source.tiles,
|
|
619
|
+
binary: false,
|
|
620
|
+
minZoom,
|
|
621
|
+
maxZoom,
|
|
622
|
+
tileSize: source.tileSize || 512,
|
|
623
|
+
loadOptions: {
|
|
624
|
+
...loadOptions || {},
|
|
625
|
+
mvt: {
|
|
626
|
+
...(loadOptions == null ? void 0 : loadOptions.mvt) || {},
|
|
627
|
+
shape: "geojson"
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
onTileError: (error) => {
|
|
631
|
+
logBasemapRuntimeError("Vector tile layer failed", error, {
|
|
632
|
+
sourceId
|
|
633
|
+
});
|
|
634
|
+
},
|
|
635
|
+
onTileLoad: (tile) => {
|
|
636
|
+
const features = Array.isArray(tile.content) ? tile.content : [];
|
|
637
|
+
if (features.length === 0) {
|
|
638
|
+
logBasemapRuntimeEvent("Loaded empty vector tile", {
|
|
639
|
+
sourceId,
|
|
640
|
+
tileIndex: tile.index
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
parameters: getTileParameters(mode),
|
|
645
|
+
renderSubLayers: (props) => {
|
|
646
|
+
const features = getTileFeatures(props.data);
|
|
647
|
+
const layers = styleLayers.map((styleLayer) => {
|
|
648
|
+
var _a;
|
|
649
|
+
if (!isStyleLayerVisibleAtZoom(styleLayer, zoom, source)) {
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
const filteredData = filterTileFeatures(features, styleLayer, zoom);
|
|
653
|
+
if (features.length > 0 && filteredData.length === 0) {
|
|
654
|
+
logBasemapRuntimeEvent("Vector tile rendered no matching features", {
|
|
655
|
+
sourceId,
|
|
656
|
+
layerId: styleLayer.id,
|
|
657
|
+
sourceLayer: styleLayer["source-layer"],
|
|
658
|
+
tileIndex: (_a = props.tile) == null ? void 0 : _a.index
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
return createStyledVectorSubLayer({
|
|
662
|
+
idPrefix,
|
|
663
|
+
sourceId,
|
|
664
|
+
styleLayer,
|
|
665
|
+
features: filteredData,
|
|
666
|
+
props,
|
|
667
|
+
zoom,
|
|
668
|
+
config,
|
|
669
|
+
mode
|
|
670
|
+
});
|
|
671
|
+
}).filter((layer) => Boolean(layer));
|
|
672
|
+
return layers;
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
function inferWaterColor(styleLayers, zoom) {
|
|
677
|
+
const waterLayer = styleLayers.find((layer) => layer.type === "fill" && `${layer["source-layer"] || ""}`.includes("water"));
|
|
678
|
+
if (!waterLayer) {
|
|
679
|
+
return [20, 40, 68, 255];
|
|
680
|
+
}
|
|
681
|
+
const paint = getPaint(waterLayer, zoom);
|
|
682
|
+
return withOpacity(paint["fill-color"], paint["fill-opacity"] ?? 1);
|
|
683
|
+
}
|
|
684
|
+
function getVectorSourceGroups(styleLayers, styleDefinition) {
|
|
685
|
+
var _a;
|
|
686
|
+
const groups = /* @__PURE__ */ new Map();
|
|
687
|
+
for (const layer of styleLayers) {
|
|
688
|
+
const sourceId = layer.source;
|
|
689
|
+
const source = sourceId ? (_a = styleDefinition.sources) == null ? void 0 : _a[sourceId] : null;
|
|
690
|
+
if (sourceId && (source == null ? void 0 : source.tiles) && source.type === "vector") {
|
|
691
|
+
appendVectorSourceGroup(groups, sourceId, source, layer);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return [...groups.values()];
|
|
695
|
+
}
|
|
696
|
+
function getBasemapLayers({ idPrefix = "basemap", mode = "map", globe, styleDefinition, zoom = 0, loadOptions }) {
|
|
697
|
+
const config = getConfig(globe);
|
|
698
|
+
const styleLayers = (styleDefinition.layers || []).filter((layer) => SUPPORTED_TYPES.has(layer.type));
|
|
699
|
+
const layers = [];
|
|
700
|
+
logBasemapRuntimeEvent("Generating basemap layers", {
|
|
701
|
+
mode,
|
|
702
|
+
styleLayerCount: styleLayers.length,
|
|
703
|
+
sourceCount: Object.keys(styleDefinition.sources || {}).length
|
|
704
|
+
});
|
|
705
|
+
layers.push(...getGlobePreLayers({ idPrefix, mode, config, styleLayers }));
|
|
706
|
+
if (config.basemap) {
|
|
707
|
+
layers.push(...getBackgroundLayers({ idPrefix, styleLayers, zoom, mode }));
|
|
708
|
+
layers.push(...getVectorLayers({ idPrefix, styleLayers, styleDefinition, zoom, config, loadOptions, mode }));
|
|
709
|
+
layers.push(...getRasterLayers({ idPrefix, styleLayers, styleDefinition, zoom, mode }));
|
|
710
|
+
}
|
|
711
|
+
layers.push(...getGlobePostLayers({ idPrefix, mode, config, styleLayers, zoom }));
|
|
712
|
+
return layers.filter((layer) => Boolean(layer));
|
|
713
|
+
}
|
|
714
|
+
function getGlobeBaseLayers({ globe, styleDefinition, idPrefix = "globe-basemap", zoom = 0, loadOptions }) {
|
|
715
|
+
return getBasemapLayers({ idPrefix, mode: "globe", globe, styleDefinition, zoom, loadOptions });
|
|
716
|
+
}
|
|
717
|
+
function getGlobeTopLayers({ globe }) {
|
|
718
|
+
const { config } = globe;
|
|
719
|
+
return config.atmosphere ? [getGlobeAtmosphereLayer()] : [];
|
|
720
|
+
}
|
|
721
|
+
function createSymbolSubLayer({ props, styleLayer, features, config, mode, zoom, opacity, paint }) {
|
|
722
|
+
return new MVTLabelLayer({
|
|
723
|
+
...getSubLayerBaseProps(props),
|
|
724
|
+
id: `${props.id}-${styleLayer.id}`,
|
|
725
|
+
data: features,
|
|
726
|
+
config,
|
|
727
|
+
mode,
|
|
728
|
+
styleLayer,
|
|
729
|
+
zoom,
|
|
730
|
+
textColor: withOpacity(paint["text-color"], opacity),
|
|
731
|
+
labelBackground: paint["text-halo-color"] ? withOpacity(paint["text-halo-color"], paint["text-halo-width"] ? 255 : opacity) : null,
|
|
732
|
+
billboard: true
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
function createGeometrySubLayer({ props, styleLayer, features, mode, fillColor, lineColor, paint }) {
|
|
736
|
+
const isLine = styleLayer.type === "line";
|
|
737
|
+
const isFill = styleLayer.type === "fill";
|
|
738
|
+
return new import_layers2.GeoJsonLayer({
|
|
739
|
+
...getSubLayerBaseProps(props),
|
|
740
|
+
id: `${props.id}-${styleLayer.id}`,
|
|
741
|
+
data: features,
|
|
742
|
+
stroked: isLine,
|
|
743
|
+
filled: isFill,
|
|
744
|
+
getFillColor: isFill ? getGlobeFillColor(fillColor, mode) : [0, 0, 0, 0],
|
|
745
|
+
getLineColor: lineColor,
|
|
746
|
+
getLineWidth: isLine ? Math.max(0.25, Number(paint["line-width"] ?? 1) * getLineWidthScale(styleLayer)) : 0,
|
|
747
|
+
lineWidthUnits: "pixels",
|
|
748
|
+
lineWidthMinPixels: 0,
|
|
749
|
+
lineWidthMaxPixels: 20,
|
|
750
|
+
lineCapRounded: isLine,
|
|
751
|
+
lineJointRounded: isLine,
|
|
752
|
+
getPointRadius: 0,
|
|
753
|
+
pointRadiusMinPixels: 0,
|
|
754
|
+
parameters: getTileParameters(mode)
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
function getBackgroundLayers({ idPrefix, styleLayers, zoom, mode }) {
|
|
758
|
+
return styleLayers.filter((layer) => layer.type === "background" && isStyleLayerVisibleAtZoom(layer, zoom)).map((layer) => createBackgroundLayer({ idPrefix, layer, zoom, mode }));
|
|
759
|
+
}
|
|
760
|
+
function getVectorLayers({ idPrefix, styleLayers, styleDefinition, zoom, config, loadOptions, mode }) {
|
|
761
|
+
const visibleVectorLayers = styleLayers.filter((layer) => {
|
|
762
|
+
var _a;
|
|
763
|
+
if (!isStyleLayerVisibleAtZoom(layer, zoom, (_a = styleDefinition.sources) == null ? void 0 : _a[layer.source || ""])) {
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
if (layer.type === "symbol") {
|
|
767
|
+
return config.labels;
|
|
768
|
+
}
|
|
769
|
+
return layer.type === "fill" || layer.type === "line";
|
|
770
|
+
});
|
|
771
|
+
return getVectorSourceGroups(visibleVectorLayers, styleDefinition).map((group) => createVectorLayerGroup({
|
|
772
|
+
idPrefix,
|
|
773
|
+
sourceId: group.sourceId,
|
|
774
|
+
source: group.source,
|
|
775
|
+
styleLayers: group.styleLayers,
|
|
776
|
+
zoom,
|
|
777
|
+
config,
|
|
778
|
+
loadOptions,
|
|
779
|
+
mode
|
|
780
|
+
}));
|
|
781
|
+
}
|
|
782
|
+
function getRasterLayers({ idPrefix, styleLayers, styleDefinition, zoom, mode }) {
|
|
783
|
+
var _a, _b;
|
|
784
|
+
const rasterLayers = [];
|
|
785
|
+
for (const layer of styleLayers) {
|
|
786
|
+
if (layer.type === "raster" && isStyleLayerVisibleAtZoom(layer, zoom, (_a = styleDefinition.sources) == null ? void 0 : _a[layer.source || ""])) {
|
|
787
|
+
const source = (_b = styleDefinition.sources) == null ? void 0 : _b[layer.source];
|
|
788
|
+
if (!(source == null ? void 0 : source.tiles)) {
|
|
789
|
+
logBasemapRuntimeEvent("Skipping style layer without resolved tiles", {
|
|
790
|
+
layerId: layer.id,
|
|
791
|
+
sourceId: layer.source
|
|
792
|
+
});
|
|
793
|
+
} else {
|
|
794
|
+
rasterLayers.push(createRasterLayer({ idPrefix, layer, source, mode }));
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
return rasterLayers;
|
|
799
|
+
}
|
|
800
|
+
function appendVectorSourceGroup(groups, sourceId, source, layer) {
|
|
801
|
+
const group = groups.get(sourceId);
|
|
802
|
+
if (group) {
|
|
803
|
+
group.styleLayers.push(layer);
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
groups.set(sourceId, {
|
|
807
|
+
sourceId,
|
|
808
|
+
source,
|
|
809
|
+
styleLayers: [layer]
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
function getGlobePreLayers({ idPrefix, mode, config, styleLayers }) {
|
|
813
|
+
const layers = [];
|
|
814
|
+
if (mode === "globe" && config.atmosphere) {
|
|
815
|
+
layers.push(getGlobeAtmosphereSkyLayer());
|
|
816
|
+
}
|
|
817
|
+
const hasBackground = styleLayers.some((layer) => layer.type === "background");
|
|
818
|
+
if (mode === "globe" && !hasBackground) {
|
|
819
|
+
layers.push(new import_layers2.SolidPolygonLayer({
|
|
820
|
+
id: `${idPrefix}-background-fallback`,
|
|
821
|
+
data: BACKGROUND_DATA,
|
|
822
|
+
getPolygon: (d) => d,
|
|
823
|
+
stroked: false,
|
|
824
|
+
filled: true,
|
|
825
|
+
getFillColor: [10, 24, 46, 255],
|
|
826
|
+
parameters: getBackgroundParameters(mode)
|
|
827
|
+
}));
|
|
828
|
+
}
|
|
829
|
+
return layers;
|
|
830
|
+
}
|
|
831
|
+
function getGlobePostLayers({ idPrefix, mode, config, styleLayers, zoom }) {
|
|
832
|
+
const layers = [];
|
|
833
|
+
if (mode === "globe" && config.basemap) {
|
|
834
|
+
layers.push(new import_layers2.SolidPolygonLayer({
|
|
835
|
+
id: `${idPrefix}-background-north-pole`,
|
|
836
|
+
data: BACKGROUND_NORTH_POLE_DATA,
|
|
837
|
+
getPolygon: (d) => d,
|
|
838
|
+
stroked: false,
|
|
839
|
+
filled: true,
|
|
840
|
+
getFillColor: inferWaterColor(styleLayers, zoom),
|
|
841
|
+
parameters: getBackgroundParameters(mode)
|
|
842
|
+
}));
|
|
843
|
+
}
|
|
844
|
+
if (mode === "globe" && config.atmosphere) {
|
|
845
|
+
layers.push(getGlobeAtmosphereLayer());
|
|
846
|
+
}
|
|
847
|
+
return layers;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// dist/basemap-layer.js
|
|
851
|
+
function logBasemapLayerEvent(message, details) {
|
|
852
|
+
import_core3.log.info(message, details ?? "")();
|
|
853
|
+
}
|
|
854
|
+
function logBasemapLayerError(message, error) {
|
|
855
|
+
import_core3.log.error(`${message}: ${error.message}`)();
|
|
856
|
+
}
|
|
857
|
+
function getMapStyleLoaderOptions(loadOptions) {
|
|
858
|
+
return {
|
|
859
|
+
mapStyle: loadOptions || void 0
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
var BasemapLayer = class extends import_core3.CompositeLayer {
|
|
863
|
+
/** Current layer state. */
|
|
864
|
+
state = void 0;
|
|
865
|
+
/** Initializes the asynchronous style-loading state. */
|
|
866
|
+
initializeState() {
|
|
867
|
+
this.state = {
|
|
868
|
+
resolvedStyle: null,
|
|
869
|
+
loadError: null,
|
|
870
|
+
loadToken: 0
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
/** Reacts to changes in the input style definition. */
|
|
874
|
+
updateState({ props, oldProps, changeFlags }) {
|
|
875
|
+
if (changeFlags.dataChanged || props.style !== oldProps.style || props.loadOptions !== oldProps.loadOptions) {
|
|
876
|
+
this.loadStyle(props.style, props.loadOptions);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Resolves the configured style input and stores the latest successful result
|
|
881
|
+
* in layer state.
|
|
882
|
+
*/
|
|
883
|
+
loadStyle(style, loadOptions) {
|
|
884
|
+
if (!style) {
|
|
885
|
+
const loadToken2 = this.state.loadToken + 1;
|
|
886
|
+
logBasemapLayerEvent("Clearing basemap style");
|
|
887
|
+
this.setState({ resolvedStyle: null, loadError: null, loadToken: loadToken2 });
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
const loadToken = this.state.loadToken + 1;
|
|
891
|
+
this.setState({ loadToken });
|
|
892
|
+
logBasemapLayerEvent("Resolving basemap style", {
|
|
893
|
+
style: typeof style === "string" ? style : "inline-style-object",
|
|
894
|
+
loadToken
|
|
895
|
+
});
|
|
896
|
+
Promise.resolve(typeof style === "string" ? (0, import_core4.load)(style, MapStyleLoader, getMapStyleLoaderOptions(loadOptions)) : MapStyleLoader.parse(new TextEncoder().encode(JSON.stringify(style)).buffer, getMapStyleLoaderOptions(loadOptions))).then((resolvedStyle) => {
|
|
897
|
+
var _a;
|
|
898
|
+
if (this.state.loadToken === loadToken) {
|
|
899
|
+
logBasemapLayerEvent("Resolved basemap style", {
|
|
900
|
+
loadToken,
|
|
901
|
+
sources: Object.keys(resolvedStyle.sources || {}),
|
|
902
|
+
layers: ((_a = resolvedStyle.layers) == null ? void 0 : _a.length) || 0
|
|
903
|
+
});
|
|
904
|
+
this.setState({ resolvedStyle, loadError: null });
|
|
905
|
+
}
|
|
906
|
+
}).catch((error) => {
|
|
907
|
+
if (this.state.loadToken === loadToken) {
|
|
908
|
+
logBasemapLayerError("Failed to resolve basemap style", error);
|
|
909
|
+
this.setState({ resolvedStyle: null, loadError: error });
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
/** Renders the sublayers generated from the resolved style definition. */
|
|
914
|
+
renderLayers() {
|
|
915
|
+
var _a;
|
|
916
|
+
if (!this.state.resolvedStyle) {
|
|
917
|
+
return [];
|
|
918
|
+
}
|
|
919
|
+
return getBasemapLayers({
|
|
920
|
+
idPrefix: this.props.id,
|
|
921
|
+
mode: this.props.mode,
|
|
922
|
+
globe: this.props.globe,
|
|
923
|
+
styleDefinition: this.state.resolvedStyle,
|
|
924
|
+
zoom: ((_a = this.context.viewport) == null ? void 0 : _a.zoom) || 0,
|
|
925
|
+
loadOptions: this.props.loadOptions
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
/** Deck.gl layer name. */
|
|
930
|
+
__publicField(BasemapLayer, "layerName", "BasemapLayer");
|
|
931
|
+
/** Default props for {@link BasemapLayer}. */
|
|
932
|
+
__publicField(BasemapLayer, "defaultProps", {
|
|
933
|
+
mode: "map",
|
|
934
|
+
globe: {
|
|
935
|
+
type: "object",
|
|
936
|
+
value: {
|
|
937
|
+
config: {
|
|
938
|
+
atmosphere: false,
|
|
939
|
+
basemap: true,
|
|
940
|
+
labels: true
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
style: null,
|
|
945
|
+
loadOptions: null
|
|
946
|
+
});
|
|
947
|
+
//# sourceMappingURL=index.cjs.map
|