@deck.gl-community/layers 0.0.0 → 9.0.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.
Files changed (39) hide show
  1. package/dist/index.cjs +493 -403
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.js +6 -5
  5. package/dist/path-marker-layer/arrow-2d-geometry.d.ts +4 -0
  6. package/dist/path-marker-layer/arrow-2d-geometry.js +58 -0
  7. package/dist/path-marker-layer/create-path-markers.d.ts +18 -0
  8. package/dist/path-marker-layer/create-path-markers.js +78 -0
  9. package/dist/path-marker-layer/path-marker-layer.d.ts +40 -0
  10. package/dist/path-marker-layer/path-marker-layer.js +124 -0
  11. package/dist/path-marker-layer/polyline.d.ts +18 -0
  12. package/dist/path-marker-layer/polyline.js +40 -0
  13. package/dist/path-outline-layer/outline.d.ts +8 -0
  14. package/dist/path-outline-layer/outline.js +100 -0
  15. package/dist/path-outline-layer/path-outline-layer.d.ts +34 -0
  16. package/dist/path-outline-layer/path-outline-layer.js +116 -0
  17. package/dist/tile-source-layer/tile-source-layer.d.ts +43 -0
  18. package/dist/tile-source-layer/tile-source-layer.js +109 -0
  19. package/package.json +33 -20
  20. package/src/index.ts +8 -5
  21. package/src/path-marker-layer/arrow-2d-geometry.ts +65 -0
  22. package/src/path-marker-layer/create-path-markers.ts +122 -0
  23. package/src/path-marker-layer/path-marker-layer.ts +183 -0
  24. package/src/path-marker-layer/polyline.ts +44 -0
  25. package/src/path-outline-layer/outline.ts +107 -0
  26. package/src/path-outline-layer/path-outline-layer.ts +159 -0
  27. package/src/{tile-source-layer.ts → tile-source-layer/tile-source-layer.ts} +34 -26
  28. package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js +0 -193
  29. package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js.map +0 -1
  30. package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js +0 -31
  31. package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js.map +0 -1
  32. package/dist/data-driven-tile-3d-layer/utils/filter-tile.js +0 -146
  33. package/dist/data-driven-tile-3d-layer/utils/filter-tile.js.map +0 -1
  34. package/dist/index.js.map +0 -1
  35. package/dist/tile-source-layer.js +0 -112
  36. package/dist/tile-source-layer.js.map +0 -1
  37. package/src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts +0 -257
  38. package/src/data-driven-tile-3d-layer/utils/colorize-tile.ts +0 -49
  39. package/src/data-driven-tile-3d-layer/utils/filter-tile.ts +0 -175
package/dist/index.cjs CHANGED
@@ -1,26 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __getProtoOf = Object.getPrototypeOf;
8
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __reflectGet = Reflect.get;
11
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
6
  var __export = (target, all) => {
25
7
  for (var name in all)
26
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -34,44 +16,27 @@ var __copyProps = (to, from, except, desc) => {
34
16
  return to;
35
17
  };
36
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
38
- var __async = (__this, __arguments, generator) => {
39
- return new Promise((resolve, reject) => {
40
- var fulfilled = (value) => {
41
- try {
42
- step(generator.next(value));
43
- } catch (e) {
44
- reject(e);
45
- }
46
- };
47
- var rejected = (value) => {
48
- try {
49
- step(generator.throw(value));
50
- } catch (e) {
51
- reject(e);
52
- }
53
- };
54
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
55
- step((generator = generator.apply(__this, __arguments)).next());
56
- });
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
57
22
  };
58
23
 
59
- // src/index.ts
60
- var src_exports = {};
61
- __export(src_exports, {
62
- DataDrivenTile3DLayer: () => DataDrivenTile3DLayer,
63
- TileSourceLayer: () => TileSourceLayer,
64
- colorizeTile: () => colorizeTile,
65
- filterTile: () => filterTile
24
+ // dist/index.js
25
+ var dist_exports = {};
26
+ __export(dist_exports, {
27
+ PathMarkerLayer: () => PathMarkerLayer,
28
+ PathOutlineLayer: () => PathOutlineLayer,
29
+ TileSourceLayer: () => TileSourceLayer
66
30
  });
67
- module.exports = __toCommonJS(src_exports);
31
+ module.exports = __toCommonJS(dist_exports);
68
32
 
69
- // src/tile-source-layer.ts
70
- var import_typed = require("@deck.gl/core/typed");
71
- var import_typed2 = require("@deck.gl/geo-layers/typed");
72
- var import_typed3 = require("@deck.gl/layers/typed");
33
+ // dist/tile-source-layer/tile-source-layer.js
34
+ var import_core = require("@deck.gl/core");
35
+ var import_geo_layers = require("@deck.gl/geo-layers");
36
+ var import_layers = require("@deck.gl/layers");
73
37
  var devicePixelRatio = typeof window !== "undefined" && window.devicePixelRatio || 1;
74
- var TileSourceLayer = class extends import_typed.CompositeLayer {
38
+ var TileSourceLayer = class extends import_core.CompositeLayer {
39
+ state = void 0;
75
40
  initializeState() {
76
41
  this.setState({
77
42
  tileSource: null
@@ -87,7 +52,7 @@ var TileSourceLayer = class extends import_typed.CompositeLayer {
87
52
  const minZoom = (metadata == null ? void 0 : metadata.minZoom) || 0;
88
53
  const maxZoom = (metadata == null ? void 0 : metadata.maxZoom) || 30;
89
54
  return [
90
- new import_typed2.TileLayer({
55
+ new import_geo_layers.TileLayer({
91
56
  // HACK: Trigger new layer via id prop to force clear tile cache
92
57
  id: String(tileSource.url),
93
58
  getTileData: tileSource.getTileData,
@@ -110,406 +75,531 @@ var TileSourceLayer = class extends import_typed.CompositeLayer {
110
75
  ];
111
76
  }
112
77
  };
113
- TileSourceLayer.layerName = "TileSourceLayer";
114
- TileSourceLayer.defaultProps = __spreadProps(__spreadValues({}, import_typed2.TileLayer.defaultProps), {
78
+ __publicField(TileSourceLayer, "layerName", "TileSourceLayer");
79
+ __publicField(TileSourceLayer, "defaultProps", {
80
+ ...import_geo_layers.TileLayer.defaultProps,
115
81
  showTileBorders: true
116
82
  });
117
83
  function renderSubLayers(props) {
118
- const {
119
- tileSource,
120
- showTileBorders,
121
- minZoom,
122
- maxZoom,
123
- tile: {
124
- index: { z: zoom },
125
- bbox: { west, south, east, north }
126
- }
127
- } = props;
84
+ const { tileSource, showTileBorders, minZoom, maxZoom, tile: { index: { z: zoom }, bbox: { west, south, east, north } } } = props;
128
85
  const layers = [];
129
86
  const borderColor = zoom <= minZoom || zoom >= maxZoom ? [255, 0, 0, 255] : [0, 0, 255, 255];
130
87
  switch (tileSource.mimeType) {
131
88
  case "application/vnd.mapbox-vector-tile":
132
- layers.push(
133
- new import_typed3.GeoJsonLayer({
134
- id: `${props.id}-geojson`,
135
- data: props.data,
136
- pickable: true,
137
- getFillColor: [0, 190, 80, 255],
138
- lineWidthScale: 500,
139
- lineWidthMinPixels: 0.5
140
- })
141
- );
89
+ layers.push(new import_layers.GeoJsonLayer({
90
+ id: `${props.id}-geojson`,
91
+ data: props.data,
92
+ pickable: true,
93
+ getFillColor: [0, 190, 80, 255],
94
+ lineWidthScale: 500,
95
+ lineWidthMinPixels: 0.5
96
+ }));
142
97
  break;
143
98
  case "image/png":
144
99
  case "image/jpeg":
145
100
  case "image/webp":
146
101
  case "image/avif":
147
- layers.push(
148
- new import_typed3.BitmapLayer(props, {
149
- data: null,
150
- image: props.data,
151
- bounds: [west, south, east, north],
152
- pickable: true
153
- })
154
- );
102
+ layers.push(new import_layers.BitmapLayer(props, {
103
+ data: null,
104
+ image: props.data,
105
+ bounds: [west, south, east, north],
106
+ pickable: true
107
+ }));
155
108
  break;
156
109
  default:
157
110
  console.error("Unknown tile mimeType", tileSource == null ? void 0 : tileSource.mimeType);
158
111
  }
159
112
  if (showTileBorders) {
160
- layers.push(
161
- new import_typed3.PathLayer({
162
- id: `${props.id}-border`,
163
- data: [
164
- [
165
- [west, north],
166
- [west, south],
167
- [east, south],
168
- [east, north],
169
- [west, north]
170
- ]
171
- ],
172
- getPath: (d) => d,
173
- getColor: borderColor,
174
- widthMinPixels: 4
175
- })
176
- );
113
+ layers.push(new import_layers.PathLayer({
114
+ id: `${props.id}-border`,
115
+ data: [
116
+ [
117
+ [west, north],
118
+ [west, south],
119
+ [east, south],
120
+ [east, north],
121
+ [west, north]
122
+ ]
123
+ ],
124
+ getPath: (d) => d,
125
+ getColor: borderColor,
126
+ widthMinPixels: 4
127
+ }));
177
128
  }
178
129
  return layers;
179
130
  }
180
131
 
181
- // src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts
182
- var import_typed4 = require("@deck.gl/geo-layers/typed");
183
- var import_tiles = require("@loaders.gl/tiles");
184
- var import_core = require("@loaders.gl/core");
132
+ // dist/path-outline-layer/path-outline-layer.js
133
+ var import_layers2 = require("@deck.gl/layers");
134
+ var import_constants = require("@luma.gl/constants");
135
+
136
+ // dist/path-outline-layer/outline.js
137
+ var INITIAL_STATE = {
138
+ outlineEnabled: false,
139
+ outlineRenderShadowmap: false,
140
+ outlineShadowmap: null
141
+ };
142
+ function getUniforms({ outlineEnabled, outlineRenderShadowmap, outlineShadowmap } = INITIAL_STATE) {
143
+ const uniforms = {};
144
+ if (outlineEnabled !== void 0) {
145
+ uniforms.outline_uEnabled = outlineEnabled;
146
+ }
147
+ if (outlineRenderShadowmap !== void 0) {
148
+ uniforms.outline_uRenderOutlines = outlineRenderShadowmap;
149
+ }
150
+ if (outlineShadowmap !== void 0) {
151
+ uniforms.outline_uShadowmap = outlineShadowmap;
152
+ }
153
+ return uniforms;
154
+ }
155
+ var vs = `#version 300 es
156
+ in float instanceZLevel;
157
+ out float outline_vzLevel;
158
+ out vec4 outline_vPosition;
159
+
160
+ // Set the z level for the outline shadowmap rendering
161
+ void outline_setZLevel(float zLevel) {
162
+ outline_vzLevel = zLevel;
163
+ }
164
+
165
+ // Store an adjusted position for texture2DProj
166
+ void outline_setUV(vec4 position) {
167
+ // mat4(
168
+ // 0.5, 0.0, 0.0, 0.0,
169
+ // 0.0, 0.5, 0.0, 0.0,
170
+ // 0.0, 0.0, 0.5, 0.0,
171
+ // 0.5, 0.5, 0.5, 1.0
172
+ // ) * position;
173
+ outline_vPosition = vec4(position.xyz * 0.5 + position.w * 0.5, position.w);
174
+ }
175
+ `;
176
+ var fs = `uniform bool outline_uEnabled;
177
+ uniform bool outline_uRenderOutlines;
178
+ uniform sampler2D outline_uShadowmap;
179
+
180
+ in float outline_vzLevel;
181
+ // in vec2 outline_vUV;
182
+ in vec4 outline_vPosition;
183
+
184
+ out vec4 fragColor;
185
+
186
+ const float OUTLINE_Z_LEVEL_ERROR = 0.01;
187
+
188
+ // Return a darker color in shadowmap
189
+ vec4 outline_filterShadowColor(vec4 color) {
190
+ return vec4(outline_vzLevel / 255., outline_vzLevel / 255., outline_vzLevel / 255., 1.);
191
+ }
192
+
193
+ // Return a darker color if in shadowmap
194
+ vec4 outline_filterDarkenColor(vec4 color) {
195
+ if (outline_uEnabled) {
196
+ float maxZLevel;
197
+ if (outline_vPosition.q > 0.0) {
198
+ maxZLevel = texture2DProj(outline_uShadowmap, outline_vPosition).r * 255.;
199
+ } else {
200
+ discard;
201
+ }
202
+ if (maxZLevel < outline_vzLevel + OUTLINE_Z_LEVEL_ERROR) {
203
+ vec4(color.rgb * 0.5, color.a);
204
+ } else {
205
+ discard;
206
+ }
207
+ }
208
+ return color;
209
+ }
210
+
211
+ // if enabled and rendering outlines - Render depth to shadowmap
212
+ // if enabled and rendering colors - Return a darker color if in shadowmap
213
+ // if disabled, just return color
214
+ vec4 outline_filterColor(vec4 color) {
215
+ if (outline_uEnabled) {
216
+ return outline_uRenderOutlines ?
217
+ outline_filterShadowColor(color) :
218
+ outline_filterDarkenColor(color);
219
+ }
220
+ return color;
221
+ }
222
+ `;
223
+ var outline = {
224
+ name: "outline",
225
+ vs,
226
+ fs,
227
+ getUniforms
228
+ };
229
+
230
+ // dist/path-outline-layer/path-outline-layer.js
231
+ var UNIT = {
232
+ common: 0,
233
+ meters: 1,
234
+ pixels: 2
235
+ };
236
+ function injectShaderCode({ source, code = "" }) {
237
+ const INJECT_CODE = /}[^{}]*$/;
238
+ return source.replace(INJECT_CODE, code.concat("\n}\n"));
239
+ }
240
+ var VS_CODE = ` outline_setUV(gl_Position);
241
+ outline_setZLevel(instanceZLevel);
242
+ `;
243
+ var FS_CODE = ` fragColor = outline_filterColor(fragColor);
244
+ `;
185
245
  var defaultProps = {
186
- colorsByAttribute: null,
187
- filtersByAttribute: null
246
+ getZLevel: () => 0
188
247
  };
189
- var _DataDrivenTile3DLayer = class extends import_typed4.Tile3DLayer {
190
- initializeState() {
248
+ var PathOutlineLayer = class extends import_layers2.PathLayer {
249
+ state = void 0;
250
+ // Override getShaders to inject the outline module
251
+ getShaders() {
252
+ const shaders = super.getShaders();
253
+ return Object.assign({}, shaders, {
254
+ modules: shaders.modules.concat([outline]),
255
+ vs: injectShaderCode({ source: shaders.vs, code: VS_CODE }),
256
+ fs: injectShaderCode({ source: shaders.fs, code: FS_CODE })
257
+ });
258
+ }
259
+ // @ts-expect-error PathLayer is missing LayerContext arg
260
+ initializeState(context) {
191
261
  super.initializeState();
192
262
  this.setState({
193
- colorsByAttribute: this.props.colorsByAttribute,
194
- filtersByAttribute: this.props.filtersByAttribute,
195
- loadingCounter: 0
263
+ outlineFramebuffer: context.device.createFramebuffer({}),
264
+ dummyTexture: context.device.createTexture({})
196
265
  });
197
- }
198
- updateState(params) {
199
- const { props, oldProps, changeFlags } = params;
200
- if (props.data && props.data !== oldProps.data) {
201
- this._loadTileset(props.data);
202
- } else if (props.colorsByAttribute !== oldProps.colorsByAttribute) {
203
- this.setState({
204
- colorsByAttribute: props.colorsByAttribute
205
- });
206
- this._colorizeTileset();
207
- } else if (props.filtersByAttribute !== oldProps.filtersByAttribute) {
208
- this.setState({
209
- filtersByAttribute: props.filtersByAttribute
210
- });
211
- this._filterTileset();
212
- } else if (changeFlags.viewportChanged) {
213
- const { activeViewports } = this.state;
214
- const viewportsNumber = Object.keys(activeViewports).length;
215
- if (viewportsNumber) {
216
- if (!this.state.loadingCounter) {
217
- super._updateTileset(activeViewports);
218
- }
219
- this.state.lastUpdatedViewports = activeViewports;
220
- this.state.activeViewports = {};
266
+ this.state.attributeManager.addInstanced({
267
+ instanceZLevel: {
268
+ size: 1,
269
+ type: import_constants.GL.UNSIGNED_BYTE,
270
+ accessor: "getZLevel"
221
271
  }
222
- } else {
223
- super.updateState(params);
224
- }
272
+ });
225
273
  }
226
- _loadTileset(tilesetUrl) {
227
- return __async(this, null, function* () {
228
- const { loadOptions = {} } = this.props;
229
- let loader = this.props.loader || this.props.loaders;
230
- if (Array.isArray(loader)) {
231
- loader = loader[0];
232
- }
233
- const options = { loadOptions: __spreadValues({}, loadOptions) };
234
- if (loader.preload) {
235
- const preloadOptions = yield loader.preload(tilesetUrl, loadOptions);
236
- if (preloadOptions.headers) {
237
- options.loadOptions.fetch = __spreadProps(__spreadValues({}, options.loadOptions.fetch), {
238
- headers: preloadOptions.headers
239
- });
240
- }
241
- Object.assign(options, preloadOptions);
274
+ // Override draw to add render module
275
+ draw({ moduleParameters = {}, parameters, uniforms, context }) {
276
+ const { jointRounded, capRounded, billboard, miterLimit, widthUnits, widthScale, widthMinPixels, widthMaxPixels } = this.props;
277
+ uniforms = Object.assign({}, uniforms, {
278
+ jointType: Number(jointRounded),
279
+ capType: Number(capRounded),
280
+ billboard,
281
+ widthUnits: UNIT[widthUnits],
282
+ widthScale,
283
+ miterLimit,
284
+ widthMinPixels,
285
+ widthMaxPixels
286
+ });
287
+ const { outlineFramebuffer, dummyTexture } = this.state;
288
+ this.state.model.updateModuleSettings({
289
+ outlineEnabled: true,
290
+ outlineRenderShadowmap: true,
291
+ outlineShadowmap: dummyTexture
292
+ });
293
+ this.state.model.draw({
294
+ uniforms: Object.assign({}, uniforms, {
295
+ jointType: 0,
296
+ widthScale: this.props.widthScale * 1.3
297
+ }),
298
+ parameters: {
299
+ depthTest: false,
300
+ // Biggest value needs to go into buffer
301
+ blendEquation: import_constants.GL.MAX
302
+ },
303
+ framebuffer: outlineFramebuffer
304
+ });
305
+ this.state.model.updateModuleSettings({
306
+ outlineEnabled: true,
307
+ outlineRenderShadowmap: false,
308
+ outlineShadowmap: outlineFramebuffer
309
+ });
310
+ this.state.model.draw({
311
+ uniforms: Object.assign({}, uniforms, {
312
+ jointType: Number(jointRounded),
313
+ capType: Number(capRounded),
314
+ widthScale: this.props.widthScale
315
+ }),
316
+ parameters: {
317
+ depthTest: false
242
318
  }
243
- const tilesetJson = yield (0, import_core.load)(tilesetUrl, loader, options.loadOptions);
244
- const tileset3d = new import_tiles.Tileset3D(tilesetJson, __spreadValues({
245
- onTileLoad: this._onTileLoad.bind(this),
246
- //@ts-expect-error call of private method of the base class
247
- onTileUnload: __superGet(_DataDrivenTile3DLayer.prototype, this, "_onTileUnload").bind(this),
248
- onTileError: this.props.onTileError,
249
- // New code ------------------
250
- onTraversalComplete: this._onTraversalComplete.bind(this)
251
- }, options));
252
- this.setState({
253
- tileset3d,
254
- layerMap: {}
255
- });
256
- __superGet(_DataDrivenTile3DLayer.prototype, this, "_updateTileset").call(this, this.state.activeViewports);
257
- this.props.onTilesetLoad(tileset3d);
258
319
  });
259
320
  }
260
- _onTileLoad(tileHeader) {
261
- const { lastUpdatedViewports } = this.state;
262
- this._colorizeTiles([tileHeader]);
263
- this._filterTiles([tileHeader]);
264
- this.props.onTileLoad(tileHeader);
265
- if (!this.state.colorsByAttribute && !this.state.filtersByAttribute) {
266
- super._updateTileset(lastUpdatedViewports);
267
- this.setNeedsUpdate();
268
- }
269
- }
270
- _onTraversalComplete(selectedTiles) {
271
- this._colorizeTiles(selectedTiles);
272
- this._filterTiles(selectedTiles);
273
- return this.props.onTraversalComplete ? this.props.onTraversalComplete(selectedTiles) : selectedTiles;
321
+ };
322
+ __publicField(PathOutlineLayer, "layerName", "PathOutlineLayer");
323
+ __publicField(PathOutlineLayer, "defaultProps", defaultProps);
324
+
325
+ // dist/path-marker-layer/path-marker-layer.js
326
+ var import_core4 = require("@deck.gl/core");
327
+ var import_layers3 = require("@deck.gl/layers");
328
+ var import_mesh_layers = require("@deck.gl/mesh-layers");
329
+
330
+ // dist/path-marker-layer/arrow-2d-geometry.js
331
+ var import_engine = require("@luma.gl/engine");
332
+ var Arrow2DGeometry = class extends import_engine.Geometry {
333
+ constructor(opts = {}) {
334
+ super(Object.assign({}, opts, {
335
+ attributes: getArrowAttributes(opts),
336
+ topology: "triangle-list"
337
+ }));
274
338
  }
275
- _colorizeTiles(tiles) {
276
- var _a;
277
- if (this.props.customizeColors && ((_a = tiles[0]) == null ? void 0 : _a.type) === import_tiles.TILE_TYPE.MESH) {
278
- const { layerMap, colorsByAttribute } = this.state;
279
- const promises = [];
280
- for (const tile of tiles) {
281
- promises.push(this.props.customizeColors(tile, colorsByAttribute));
282
- }
283
- this.setState({
284
- loadingCounter: this.state.loadingCounter + 1
285
- });
286
- Promise.allSettled(promises).then((result) => {
287
- this.setState({
288
- loadingCounter: this.state.loadingCounter - 1
289
- });
290
- let isTileChanged = false;
291
- for (const item of result) {
292
- if (item.status === "fulfilled" && item.value.isColored) {
293
- isTileChanged = true;
294
- delete layerMap[item.value.id];
295
- }
296
- }
297
- if (isTileChanged && !this.state.loadingCounter) {
298
- super._updateTileset(this.state.activeViewports);
299
- this.setNeedsUpdate();
300
- }
301
- });
302
- }
339
+ };
340
+ function getArrowAttributes({ length = 1, headSize = 0.2, tailWidth = 0.05, tailStart = 0.05 }) {
341
+ const texCoords = [
342
+ // HEAD
343
+ 0.5,
344
+ 1,
345
+ 0,
346
+ 0.5 - headSize / 2,
347
+ 1 - headSize,
348
+ 0,
349
+ 0.5 + headSize / 2,
350
+ 1 - headSize,
351
+ 0,
352
+ 0.5 - tailWidth / 2,
353
+ tailStart,
354
+ 0,
355
+ 0.5 + tailWidth / 2,
356
+ 1 - headSize,
357
+ 0,
358
+ 0.5 + tailWidth / 2,
359
+ tailStart,
360
+ 0,
361
+ 0.5 - tailWidth / 2,
362
+ tailStart,
363
+ 0,
364
+ 0.5 - tailWidth / 2,
365
+ 1 - headSize,
366
+ 0,
367
+ 0.5 + tailWidth / 2,
368
+ 1 - headSize,
369
+ 0
370
+ ];
371
+ const normals = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1];
372
+ const positions = new Array(texCoords.length);
373
+ for (let i = 0; i < texCoords.length / 3; i++) {
374
+ const i3 = i * 3;
375
+ positions[i3 + 0] = (texCoords[i3 + 0] - 0.5) * length;
376
+ positions[i3 + 1] = (texCoords[i3 + 1] - 0.5) * length;
377
+ positions[i3 + 2] = 0;
303
378
  }
304
- _colorizeTileset() {
305
- const { tileset3d } = this.state;
306
- if (tileset3d) {
307
- this._colorizeTiles(tileset3d.selectedTiles);
308
- }
379
+ return {
380
+ positions: { size: 3, value: new Float32Array(positions) },
381
+ normals: { size: 3, value: new Float32Array(normals) },
382
+ texCoords: { size: 2, value: new Float32Array(texCoords) }
383
+ };
384
+ }
385
+
386
+ // dist/path-marker-layer/create-path-markers.js
387
+ var import_core2 = require("@math.gl/core");
388
+ function getLineLength(vPoints) {
389
+ let lineLength = 0;
390
+ for (let i = 0; i < vPoints.length - 1; i++) {
391
+ lineLength += vPoints[i].distance(vPoints[i + 1]);
309
392
  }
310
- _filterTiles(tiles) {
311
- var _a;
312
- if (this.props.filterTile && ((_a = tiles[0]) == null ? void 0 : _a.type) === import_tiles.TILE_TYPE.MESH) {
313
- const { layerMap, filtersByAttribute } = this.state;
314
- const promises = [];
315
- for (const tile of tiles) {
316
- promises.push(this.props.filterTile(tile, filtersByAttribute));
393
+ return lineLength;
394
+ }
395
+ var DEFAULT_COLOR = [0, 0, 0, 255];
396
+ var DEFAULT_DIRECTION = { forward: true, backward: false };
397
+ function createPathMarkers({ data, getPath = (x, context) => x.path, getDirection = (x) => x.direction, getColor = (x) => DEFAULT_COLOR, getMarkerPercentages = (x, info) => [0.5], projectFlat }) {
398
+ const markers = [];
399
+ for (const object of data) {
400
+ const path = getPath(object, null);
401
+ const direction = getDirection(object) || DEFAULT_DIRECTION;
402
+ const color = getColor(object);
403
+ const vPoints = path.map((p) => new import_core2.Vector2(p));
404
+ const vPointsReverse = vPoints.slice(0).reverse();
405
+ const lineLength = getLineLength(vPoints);
406
+ const percentages = getMarkerPercentages(object, { lineLength });
407
+ for (const percentage of percentages) {
408
+ if (direction.forward) {
409
+ const marker = createMarkerAlongPath({
410
+ path: vPoints,
411
+ percentage,
412
+ lineLength,
413
+ color,
414
+ object,
415
+ projectFlat
416
+ });
417
+ markers.push(marker);
317
418
  }
318
- this.setState({
319
- loadingCounter: this.state.loadingCounter + 1
320
- });
321
- Promise.allSettled(promises).then((result) => {
322
- this.setState({
323
- loadingCounter: this.state.loadingCounter - 1
419
+ if (direction.backward) {
420
+ const marker = createMarkerAlongPath({
421
+ path: vPointsReverse,
422
+ percentage,
423
+ lineLength,
424
+ color,
425
+ object,
426
+ projectFlat
324
427
  });
325
- let isTileChanged = false;
326
- for (const item of result) {
327
- if (item.status === "fulfilled" && item.value.isFiltered) {
328
- isTileChanged = true;
329
- delete layerMap[item.value.id];
330
- }
331
- }
332
- if (isTileChanged && !this.state.loadingCounter) {
333
- super._updateTileset(this.state.activeViewports);
334
- this.setNeedsUpdate();
335
- }
336
- });
428
+ markers.push(marker);
429
+ }
337
430
  }
338
431
  }
339
- _filterTileset() {
340
- const { tileset3d } = this.state;
341
- if (tileset3d) {
342
- this._filterTiles(tileset3d.selectedTiles);
432
+ return markers;
433
+ }
434
+ function createMarkerAlongPath({ path, percentage, lineLength, color, object, projectFlat }) {
435
+ const distanceAlong = lineLength * percentage;
436
+ let currentDistance = 0;
437
+ let previousDistance = 0;
438
+ let i = 0;
439
+ for (i = 0; i < path.length - 1; i++) {
440
+ currentDistance += path[i].distance(path[i + 1]);
441
+ if (currentDistance > distanceAlong) {
442
+ break;
343
443
  }
444
+ previousDistance = currentDistance;
344
445
  }
345
- };
346
- var DataDrivenTile3DLayer = _DataDrivenTile3DLayer;
347
- DataDrivenTile3DLayer.layerName = "DataDrivenTile3DLayer";
348
- DataDrivenTile3DLayer.defaultProps = defaultProps;
349
-
350
- // src/data-driven-tile-3d-layer/utils/colorize-tile.ts
351
- var import_i3s = require("@loaders.gl/i3s");
352
- var colorizeTile = (tile, colorsByAttribute) => __async(void 0, null, function* () {
353
- const result = { isColored: false, id: tile.id };
354
- if (tile.content.customColors !== colorsByAttribute) {
355
- if (tile.content && colorsByAttribute) {
356
- if (!tile.content.originalColorsAttributes) {
357
- tile.content.originalColorsAttributes = __spreadProps(__spreadValues({}, tile.content.attributes.colors), {
358
- value: new Uint8Array(tile.content.attributes.colors.value)
359
- });
360
- } else if (colorsByAttribute.mode === "multiply") {
361
- tile.content.attributes.colors.value.set(tile.content.originalColorsAttributes.value);
362
- }
363
- tile.content.customColors = colorsByAttribute;
364
- const newColors = yield (0, import_i3s.customizeColors)(
365
- tile.content.attributes.colors,
366
- tile.content.featureIds,
367
- tile.header.attributeUrls,
368
- tile.tileset.tileset.fields,
369
- tile.tileset.tileset.attributeStorageInfo,
370
- colorsByAttribute,
371
- tile.tileset.loadOptions.i3s.token
372
- );
373
- if (tile.content.customColors === colorsByAttribute) {
374
- tile.content.attributes.colors = newColors;
375
- result.isColored = true;
376
- }
377
- } else if (tile.content && tile.content.originalColorsAttributes) {
378
- tile.content.attributes.colors.value = tile.content.originalColorsAttributes.value;
379
- tile.content.customColors = null;
380
- result.isColored = true;
381
- }
446
+ if (i === path.length - 1) {
447
+ i -= 1;
382
448
  }
383
- return result;
384
- });
449
+ const vDirection = path[i + 1].clone().subtract(path[i]).normalize();
450
+ const along = distanceAlong - previousDistance;
451
+ const vCenter = vDirection.clone().multiply(new import_core2.Vector2(along, along)).add(path[i]);
452
+ const vDirection2 = new import_core2.Vector2(projectFlat(path[i + 1])).subtract(projectFlat(path[i]));
453
+ const angle = vDirection2.verticalAngle() * 180 / Math.PI;
454
+ return { position: [vCenter.x, vCenter.y, 0], angle, color, object };
455
+ }
385
456
 
386
- // src/data-driven-tile-3d-layer/utils/filter-tile.ts
387
- var import_i3s2 = require("@loaders.gl/i3s");
388
- var import_core2 = require("@loaders.gl/core");
389
- var filterTile = (tile, filtersByAttribute) => __async(void 0, null, function* () {
390
- var _a, _b, _c, _d;
391
- const result = { isFiltered: false, id: tile.id };
392
- if (((_a = tile.content.userData) == null ? void 0 : _a.customFilters) !== filtersByAttribute) {
393
- if (tile.content && filtersByAttribute) {
394
- if (((_b = tile.content.userData) == null ? void 0 : _b.originalIndices) === void 0) {
395
- tile.content.userData = {};
396
- tile.content.userData.originalIndices = tile.content.indices;
397
- }
398
- tile.content.indices = (_c = tile.content.userData) == null ? void 0 : _c.originalIndices;
399
- tile.content.userData.customFilters = filtersByAttribute;
400
- const { indices } = yield filterTileIndices(
401
- tile,
402
- filtersByAttribute,
403
- tile.tileset.loadOptions.i3s.token
404
- );
405
- if (indices && tile.content.userData.customFilters === filtersByAttribute) {
406
- tile.content.indices = indices;
407
- result.isFiltered = true;
408
- }
409
- } else if (tile.content && ((_d = tile.content.userData) == null ? void 0 : _d.originalIndices) !== void 0) {
410
- tile.content.indices = tile.content.userData.originalIndices;
411
- tile.content.userData.customFilters = null;
412
- result.isFiltered = true;
457
+ // dist/path-marker-layer/polyline.js
458
+ var import_core3 = require("@math.gl/core");
459
+ function getClosestPointOnLine({ p, p1, p2, clampToLine = true }) {
460
+ const lineVector = new import_core3.Vector3(p2).subtract(p1);
461
+ const pointVector = new import_core3.Vector3(p).subtract(p1);
462
+ let dotProduct = lineVector.dot(pointVector);
463
+ if (clampToLine) {
464
+ dotProduct = (0, import_core3.clamp)(dotProduct, 0, 1);
465
+ }
466
+ return lineVector.lerp(p1, p2, dotProduct);
467
+ }
468
+ function getClosestPointOnPolyline({ p, points }) {
469
+ p = new import_core3.Vector3(p);
470
+ let pClosest = null;
471
+ let distanceSquared = Infinity;
472
+ let index = -1;
473
+ for (let i = 0; i < points.length - 1; ++i) {
474
+ const p1 = points[i];
475
+ const p2 = points[i + 1];
476
+ const pClosestOnLine = getClosestPointOnLine({ p, p1, p2 });
477
+ const distanceToLineSquared = p.distanceSquared(pClosestOnLine);
478
+ if (distanceToLineSquared < distanceSquared) {
479
+ distanceSquared = distanceToLineSquared;
480
+ pClosest = pClosestOnLine;
481
+ index = i;
413
482
  }
414
483
  }
415
- return result;
484
+ return {
485
+ point: pClosest,
486
+ index,
487
+ p1: points[index],
488
+ p2: points[index + 1],
489
+ distanceSquared,
490
+ distance: Math.sqrt(distanceSquared)
491
+ };
492
+ }
493
+
494
+ // dist/path-marker-layer/path-marker-layer.js
495
+ var DISTANCE_FOR_MULTI_ARROWS = 0.1;
496
+ var ARROW_HEAD_SIZE = 0.2;
497
+ var ARROW_TAIL_WIDTH = 0.05;
498
+ var DEFAULT_MARKER_LAYER = import_mesh_layers.SimpleMeshLayer;
499
+ var DEFAULT_MARKER_LAYER_PROPS = {
500
+ mesh: new Arrow2DGeometry({ headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH })
501
+ };
502
+ var defaultProps2 = Object.assign({}, PathOutlineLayer.defaultProps, {
503
+ MarkerLayer: DEFAULT_MARKER_LAYER,
504
+ markerLayerProps: DEFAULT_MARKER_LAYER_PROPS,
505
+ sizeScale: 100,
506
+ fp64: false,
507
+ highlightIndex: -1,
508
+ highlightPoint: null,
509
+ getPath: (x) => x.path,
510
+ getColor: (x) => x.color,
511
+ getMarkerColor: (x) => [0, 0, 0, 255],
512
+ getDirection: (x) => x.direction,
513
+ getMarkerPercentages: (object, { lineLength }) => lineLength > DISTANCE_FOR_MULTI_ARROWS ? [0.25, 0.5, 0.75] : [0.5]
416
514
  });
417
- function filterTileIndices(tile, filtersByAttribute, token) {
418
- return __async(this, null, function* () {
419
- var _a;
420
- if (!filtersByAttribute.attributeName.length) {
421
- return { success: false };
422
- }
423
- const filterAttributeField = tile.tileset.tileset.fields.find(
424
- ({ name }) => name === (filtersByAttribute == null ? void 0 : filtersByAttribute.attributeName)
425
- );
426
- if (!filterAttributeField || !["esriFieldTypeDouble", "esriFieldTypeInteger", "esriFieldTypeSmallInteger"].includes(
427
- filterAttributeField.type
428
- )) {
429
- return { success: false };
430
- }
431
- const tileFilterAttributeData = yield loadFeatureAttributeData(
432
- filterAttributeField.name,
433
- tile.header.attributeUrls,
434
- tile.tileset.tileset.attributeStorageInfo,
435
- token
436
- );
437
- if (!tileFilterAttributeData) {
438
- return { success: false };
439
- }
440
- const objectIdField = tile.tileset.tileset.fields.find(({ type }) => type === "esriFieldTypeOID");
441
- if (!objectIdField) {
442
- return { success: false };
443
- }
444
- const objectIdAttributeData = yield loadFeatureAttributeData(
445
- objectIdField.name,
446
- tile.header.attributeUrls,
447
- tile.tileset.tileset.attributeStorageInfo,
448
- token
449
- );
450
- if (!objectIdAttributeData) {
451
- return { success: false };
515
+ var PathMarkerLayer = class extends import_core4.CompositeLayer {
516
+ state = void 0;
517
+ initializeState() {
518
+ this.state = {
519
+ markers: [],
520
+ mesh: new Arrow2DGeometry({ headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH }),
521
+ closestPoint: null,
522
+ closestPoints: []
523
+ };
524
+ }
525
+ projectFlat(xyz, viewport, coordinateSystem, coordinateOrigin) {
526
+ if (coordinateSystem === import_core4.COORDINATE_SYSTEM.METER_OFFSETS) {
527
+ const [dx, dy] = viewport.metersToLngLatDelta(xyz);
528
+ const [x, y] = coordinateOrigin;
529
+ return viewport.projectFlat([x + dx, dy + y]);
530
+ } else if (coordinateSystem === import_core4.COORDINATE_SYSTEM.LNGLAT_OFFSETS) {
531
+ const [dx, dy] = xyz;
532
+ const [x, y] = coordinateOrigin;
533
+ return viewport.projectFlat([x + dx, dy + y]);
452
534
  }
453
- const attributeValuesMap = {};
454
- (_a = objectIdAttributeData[objectIdField.name]) == null ? void 0 : _a.forEach((elem, index) => {
455
- attributeValuesMap[elem] = //@ts-expect-error possible null
456
- tileFilterAttributeData[filterAttributeField.name][index];
457
- });
458
- if (!tile.content.indices) {
459
- const triangles = [];
460
- for (let i = 0; i < tile.content.featureIds.length; i += 3) {
461
- if (attributeValuesMap[tile.content.featureIds[i]] === filtersByAttribute.value) {
462
- triangles.push(i);
463
- }
464
- }
465
- const indices = new Uint32Array(3 * triangles.length);
466
- triangles.forEach((vertex, index) => {
467
- indices[index * 3] = vertex;
468
- indices[index * 3 + 1] = vertex + 1;
469
- indices[index * 3 + 2] = vertex + 2;
535
+ return viewport.projectFlat(xyz);
536
+ }
537
+ updateState({ props, oldProps, changeFlags }) {
538
+ if (changeFlags.dataChanged || changeFlags.updateTriggersChanged) {
539
+ const { data, getPath, getDirection, getMarkerColor, getMarkerPercentages, coordinateSystem, coordinateOrigin } = this.props;
540
+ const { viewport } = this.context;
541
+ const projectFlat = (o) => this.projectFlat(o, viewport, coordinateSystem, coordinateOrigin);
542
+ this.state.markers = createPathMarkers({
543
+ data,
544
+ getPath,
545
+ getDirection,
546
+ getColor: getMarkerColor,
547
+ getMarkerPercentages,
548
+ projectFlat
470
549
  });
471
- return { success: true, indices };
472
- } else {
473
- const triangles = [];
474
- for (let i = 0; i < tile.content.indices.length; i += 3) {
475
- if (attributeValuesMap[tile.content.featureIds[tile.content.indices[i]]] === filtersByAttribute.value) {
476
- triangles.push(i);
477
- }
550
+ this._recalculateClosestPoint();
551
+ }
552
+ if (changeFlags.propsChanged) {
553
+ if (props.point !== oldProps.point) {
554
+ this._recalculateClosestPoint();
478
555
  }
479
- const indices = new Uint32Array(3 * triangles.length);
480
- triangles.forEach((vertex, index) => {
481
- indices[index * 3] = tile.content.indices[vertex];
482
- indices[index * 3 + 1] = tile.content.indices[vertex + 1];
483
- indices[index * 3 + 2] = tile.content.indices[vertex + 2];
484
- });
485
- return { success: true, indices };
486
556
  }
487
- });
488
- }
489
- function loadFeatureAttributeData(attributeName, attributeUrls, attributesStorageInfo, token) {
490
- return __async(this, null, function* () {
491
- const attributeIndex = attributesStorageInfo.findIndex(({ name }) => attributeName === name);
492
- if (attributeIndex === -1) {
493
- return null;
557
+ }
558
+ _recalculateClosestPoint() {
559
+ const { highlightPoint, highlightIndex } = this.props;
560
+ if (highlightPoint && highlightIndex >= 0) {
561
+ const object = this.props.data[highlightIndex];
562
+ const points = this.props.getPath(object, null);
563
+ const { point } = getClosestPointOnPolyline({ points, p: highlightPoint });
564
+ this.state.closestPoints = [{ position: point }];
565
+ } else {
566
+ this.state.closestPoints = [];
494
567
  }
495
- const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], token);
496
- const attributeType = getAttributeValueType(attributesStorageInfo[attributeIndex]);
497
- const objectIdAttributeData = yield (0, import_core2.load)(objectIdAttributeUrl, import_i3s2.I3SAttributeLoader, {
498
- attributeName,
499
- attributeType
568
+ }
569
+ getPickingInfo({ info }) {
570
+ return Object.assign(info, {
571
+ // override object with picked feature
572
+ object: info.object && info.object.path || info.object
500
573
  });
501
- return objectIdAttributeData;
502
- });
503
- }
504
- function getUrlWithToken(url, token = null) {
505
- return token ? `${url}?token=${token}` : url;
506
- }
507
- function getAttributeValueType(attribute) {
508
- var _a;
509
- if (attribute.hasOwnProperty("objectIds")) {
510
- return "Oid32";
511
- } else if (attribute.hasOwnProperty("attributeValues")) {
512
- return (_a = attribute.attributeValues) == null ? void 0 : _a.valueType;
513
574
  }
514
- return "";
515
- }
575
+ renderLayers() {
576
+ return [
577
+ new PathOutlineLayer(this.props, this.getSubLayerProps({
578
+ id: "paths",
579
+ // Note: data has to be passed explicitly like this to avoid being empty
580
+ data: this.props.data
581
+ })),
582
+ new this.props.MarkerLayer(this.getSubLayerProps(Object.assign({}, this.props.markerLayerProps, {
583
+ id: "markers",
584
+ data: this.state.markers,
585
+ getOrientation: (x) => [0, -x.angle, 0],
586
+ getColor: (x) => x.color,
587
+ sizeScale: this.props.sizeScale,
588
+ fp64: this.props.fp64,
589
+ pickable: false,
590
+ parameters: {
591
+ blend: false,
592
+ depthTest: false
593
+ }
594
+ }))),
595
+ this.state.closestPoints && new import_layers3.ScatterplotLayer({
596
+ id: `${this.props.id}-highlight`,
597
+ data: this.state.closestPoints,
598
+ fp64: this.props.fp64
599
+ })
600
+ ];
601
+ }
602
+ };
603
+ __publicField(PathMarkerLayer, "layerName", "PathMarkerLayer");
604
+ __publicField(PathMarkerLayer, "defaultProps", defaultProps2);
605
+ //# sourceMappingURL=index.cjs.map