@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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.js", "tile-source-layer/tile-source-layer.js", "path-outline-layer/path-outline-layer.js", "path-outline-layer/outline.js", "path-marker-layer/path-marker-layer.js", "path-marker-layer/arrow-2d-geometry.js", "path-marker-layer/create-path-markers.js", "path-marker-layer/polyline.js"],
4
+ "sourcesContent": ["// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nexport { TileSourceLayer } from './tile-source-layer/tile-source-layer';\nexport { PathOutlineLayer } from './path-outline-layer/path-outline-layer';\nexport { PathMarkerLayer } from './path-marker-layer/path-marker-layer';\n", "// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { CompositeLayer } from '@deck.gl/core';\nimport { TileLayer } from '@deck.gl/geo-layers';\nimport { BitmapLayer, GeoJsonLayer, PathLayer } from '@deck.gl/layers';\n/* global window */\nconst devicePixelRatio = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;\n/**\n * A Deck.gl layer that renders a tile source\n * Autodiscovers type of content (vector tile, bitmap, ...)\n * Can render debug borders around tiles\n * TODO - Change debug border color based on zoom level\n */\nexport class TileSourceLayer extends CompositeLayer {\n static layerName = 'TileSourceLayer';\n static defaultProps = {\n ...TileLayer.defaultProps,\n showTileBorders: true\n };\n state = undefined;\n initializeState() {\n this.setState({\n tileSource: null\n });\n }\n updateState({ props, changeFlags }) {\n this.setState({\n tileSource: props.tileSource\n });\n }\n renderLayers() {\n const { tileSource, showTileBorders, metadata, onTilesLoad } = this.props;\n const minZoom = metadata?.minZoom || 0;\n const maxZoom = metadata?.maxZoom || 30;\n return [\n new TileLayer({\n // HACK: Trigger new layer via id prop to force clear tile cache\n id: String(tileSource.url),\n getTileData: tileSource.getTileData,\n // Assume the pmtiles file support HTTP/2, so we aren't limited by the browser to a certain number per domain.\n maxRequests: 20,\n pickable: true,\n onViewportLoad: onTilesLoad,\n autoHighlight: showTileBorders,\n highlightColor: [60, 60, 60, 40],\n minZoom,\n maxZoom,\n tileSize: 256,\n // TOOD - why is this needed?\n zoomOffset: devicePixelRatio === 1 ? -1 : 0,\n renderSubLayers: renderSubLayers,\n // Custom prop\n tileSource,\n showTileBorders\n })\n ];\n }\n}\nfunction renderSubLayers(props) {\n const { tileSource, showTileBorders, minZoom, maxZoom, tile: { index: { z: zoom }, bbox: { west, south, east, north } } } = props;\n const layers = [];\n const borderColor = zoom <= minZoom || zoom >= maxZoom ? [255, 0, 0, 255] : [0, 0, 255, 255];\n switch (tileSource.mimeType) {\n case 'application/vnd.mapbox-vector-tile':\n layers.push(new GeoJsonLayer({\n id: `${props.id}-geojson`,\n data: props.data,\n pickable: true,\n getFillColor: [0, 190, 80, 255],\n lineWidthScale: 500,\n lineWidthMinPixels: 0.5\n }));\n break;\n case 'image/png':\n case 'image/jpeg':\n case 'image/webp':\n case 'image/avif':\n layers.push(new BitmapLayer(props, {\n data: null,\n image: props.data,\n bounds: [west, south, east, north],\n pickable: true\n }));\n break;\n default:\n // eslint-disable-next-line no-console\n console.error('Unknown tile mimeType', tileSource?.mimeType);\n }\n // Debug tile borders\n if (showTileBorders) {\n layers.push(new PathLayer({\n id: `${props.id}-border`,\n data: [\n [\n [west, north],\n [west, south],\n [east, south],\n [east, north],\n [west, north]\n ]\n ],\n getPath: (d) => d,\n getColor: borderColor,\n widthMinPixels: 4\n }));\n }\n return layers;\n}\n", "// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { PathLayer } from '@deck.gl/layers';\nimport { GL } from '@luma.gl/constants';\nimport { outline } from './outline';\n/**\n * Unit literal to shader unit number conversion.\n */\nexport const UNIT = {\n common: 0,\n meters: 1,\n pixels: 2\n};\n// TODO - this should be built into assembleShaders\nfunction injectShaderCode({ source, code = '' }) {\n const INJECT_CODE = /}[^{}]*$/;\n return source.replace(INJECT_CODE, code.concat('\\n}\\n'));\n}\nconst VS_CODE = `\\\n outline_setUV(gl_Position);\n outline_setZLevel(instanceZLevel);\n`;\nconst FS_CODE = `\\\n fragColor = outline_filterColor(fragColor);\n`;\nconst defaultProps = {\n getZLevel: () => 0\n};\nexport class PathOutlineLayer extends PathLayer {\n static layerName = 'PathOutlineLayer';\n static defaultProps = defaultProps;\n state = undefined;\n // Override getShaders to inject the outline module\n getShaders() {\n const shaders = super.getShaders();\n return Object.assign({}, shaders, {\n modules: shaders.modules.concat([outline]),\n vs: injectShaderCode({ source: shaders.vs, code: VS_CODE }),\n fs: injectShaderCode({ source: shaders.fs, code: FS_CODE })\n });\n }\n // @ts-expect-error PathLayer is missing LayerContext arg\n initializeState(context) {\n super.initializeState();\n // Create an outline \"shadow\" map\n // TODO - we should create a single outlineMap for all layers\n this.setState({\n outlineFramebuffer: context.device.createFramebuffer({}),\n dummyTexture: context.device.createTexture({})\n });\n // Create an attribute manager\n // @ts-expect-error check whether this.getAttributeManager works here\n this.state.attributeManager.addInstanced({\n instanceZLevel: {\n size: 1,\n type: GL.UNSIGNED_BYTE,\n accessor: 'getZLevel'\n }\n });\n }\n // Override draw to add render module\n draw({ moduleParameters = {}, parameters, uniforms, context }) {\n // Need to calculate same uniforms as base layer\n const { jointRounded, capRounded, billboard, miterLimit, widthUnits, widthScale, widthMinPixels, widthMaxPixels } = this.props;\n uniforms = Object.assign({}, uniforms, {\n jointType: Number(jointRounded),\n capType: Number(capRounded),\n billboard,\n widthUnits: UNIT[widthUnits],\n widthScale,\n miterLimit,\n widthMinPixels,\n widthMaxPixels\n });\n // Render the outline shadowmap (based on segment z orders)\n const { outlineFramebuffer, dummyTexture } = this.state;\n // TODO(v9): resize, see 'sf' example.\n // outlineFramebuffer.resize();\n // TODO(v9) clear FBO\n // outlineFramebuffer.clear({ color: true, depth: true, stencil: true });\n this.state.model.updateModuleSettings({\n outlineEnabled: true,\n outlineRenderShadowmap: true,\n outlineShadowmap: dummyTexture\n });\n this.state.model.draw({\n uniforms: Object.assign({}, uniforms, {\n jointType: 0,\n widthScale: this.props.widthScale * 1.3\n }),\n parameters: {\n depthTest: false,\n // Biggest value needs to go into buffer\n blendEquation: GL.MAX\n },\n framebuffer: outlineFramebuffer\n });\n // Now use the outline shadowmap to render the lines (with outlines)\n this.state.model.updateModuleSettings({\n outlineEnabled: true,\n outlineRenderShadowmap: false,\n outlineShadowmap: outlineFramebuffer\n });\n this.state.model.draw({\n uniforms: Object.assign({}, uniforms, {\n jointType: Number(jointRounded),\n capType: Number(capRounded),\n widthScale: this.props.widthScale\n }),\n parameters: {\n depthTest: false\n }\n });\n }\n}\n", "// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n/* eslint-disable camelcase */\nconst INITIAL_STATE = {\n outlineEnabled: false,\n outlineRenderShadowmap: false,\n outlineShadowmap: null\n};\nfunction getUniforms({ outlineEnabled, outlineRenderShadowmap, outlineShadowmap } = INITIAL_STATE) {\n const uniforms = {};\n if (outlineEnabled !== undefined) {\n // ? 1.0 : 0.0;\n uniforms.outline_uEnabled = outlineEnabled;\n }\n if (outlineRenderShadowmap !== undefined) {\n // ? 1.0 : 0.0;\n uniforms.outline_uRenderOutlines = outlineRenderShadowmap;\n }\n if (outlineShadowmap !== undefined) {\n uniforms.outline_uShadowmap = outlineShadowmap;\n }\n return uniforms;\n}\nconst vs = `\\\n#version 300 es\nin float instanceZLevel;\nout float outline_vzLevel;\nout vec4 outline_vPosition;\n\n// Set the z level for the outline shadowmap rendering\nvoid outline_setZLevel(float zLevel) {\n outline_vzLevel = zLevel;\n}\n\n// Store an adjusted position for texture2DProj\nvoid outline_setUV(vec4 position) {\n // mat4(\n // 0.5, 0.0, 0.0, 0.0,\n // 0.0, 0.5, 0.0, 0.0,\n // 0.0, 0.0, 0.5, 0.0,\n // 0.5, 0.5, 0.5, 1.0\n // ) * position;\n outline_vPosition = vec4(position.xyz * 0.5 + position.w * 0.5, position.w);\n}\n`;\nconst fs = `\\\nuniform bool outline_uEnabled;\nuniform bool outline_uRenderOutlines;\nuniform sampler2D outline_uShadowmap;\n\nin float outline_vzLevel;\n// in vec2 outline_vUV;\nin vec4 outline_vPosition;\n\nout vec4 fragColor;\n\nconst float OUTLINE_Z_LEVEL_ERROR = 0.01;\n\n// Return a darker color in shadowmap\nvec4 outline_filterShadowColor(vec4 color) {\n return vec4(outline_vzLevel / 255., outline_vzLevel / 255., outline_vzLevel / 255., 1.);\n}\n\n// Return a darker color if in shadowmap\nvec4 outline_filterDarkenColor(vec4 color) {\n if (outline_uEnabled) {\n float maxZLevel;\n if (outline_vPosition.q > 0.0) {\n maxZLevel = texture2DProj(outline_uShadowmap, outline_vPosition).r * 255.;\n } else {\n discard;\n }\n if (maxZLevel < outline_vzLevel + OUTLINE_Z_LEVEL_ERROR) {\n vec4(color.rgb * 0.5, color.a);\n } else {\n discard;\n }\n }\n return color;\n}\n\n// if enabled and rendering outlines - Render depth to shadowmap\n// if enabled and rendering colors - Return a darker color if in shadowmap\n// if disabled, just return color\nvec4 outline_filterColor(vec4 color) {\n if (outline_uEnabled) {\n return outline_uRenderOutlines ?\n outline_filterShadowColor(color) :\n outline_filterDarkenColor(color);\n }\n return color;\n}\n`;\nexport const outline = {\n name: 'outline',\n vs,\n fs,\n getUniforms\n};\n", "// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { CompositeLayer, COORDINATE_SYSTEM } from '@deck.gl/core';\nimport { ScatterplotLayer } from '@deck.gl/layers';\nimport { SimpleMeshLayer } from '@deck.gl/mesh-layers';\nimport { PathOutlineLayer } from '../path-outline-layer/path-outline-layer';\nimport { Arrow2DGeometry } from './arrow-2d-geometry';\nimport { createPathMarkers } from './create-path-markers';\nimport { getClosestPointOnPolyline } from './polyline';\nconst DISTANCE_FOR_MULTI_ARROWS = 0.1;\nconst ARROW_HEAD_SIZE = 0.2;\nconst ARROW_TAIL_WIDTH = 0.05;\n// const ARROW_CENTER_ADJUST = -0.8;\nconst DEFAULT_MARKER_LAYER = SimpleMeshLayer;\nconst DEFAULT_MARKER_LAYER_PROPS = {\n mesh: new Arrow2DGeometry({ headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH })\n};\nconst defaultProps = Object.assign({}, PathOutlineLayer.defaultProps, {\n MarkerLayer: DEFAULT_MARKER_LAYER,\n markerLayerProps: DEFAULT_MARKER_LAYER_PROPS,\n sizeScale: 100,\n fp64: false,\n highlightIndex: -1,\n highlightPoint: null,\n getPath: (x) => x.path,\n getColor: (x) => x.color,\n getMarkerColor: (x) => [0, 0, 0, 255],\n getDirection: (x) => x.direction,\n getMarkerPercentages: (object, { lineLength }) => lineLength > DISTANCE_FOR_MULTI_ARROWS ? [0.25, 0.5, 0.75] : [0.5]\n});\nexport class PathMarkerLayer extends CompositeLayer {\n static layerName = 'PathMarkerLayer';\n static defaultProps = defaultProps;\n state = undefined;\n initializeState() {\n this.state = {\n markers: [],\n mesh: new Arrow2DGeometry({ headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH }),\n closestPoint: null,\n closestPoints: []\n };\n }\n projectFlat(xyz, viewport, coordinateSystem, coordinateOrigin) {\n if (coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS) {\n const [dx, dy] = viewport.metersToLngLatDelta(xyz);\n const [x, y] = coordinateOrigin;\n return viewport.projectFlat([x + dx, dy + y]);\n }\n else if (coordinateSystem === COORDINATE_SYSTEM.LNGLAT_OFFSETS) {\n const [dx, dy] = xyz;\n const [x, y] = coordinateOrigin;\n return viewport.projectFlat([x + dx, dy + y]);\n }\n return viewport.projectFlat(xyz);\n }\n updateState({ props, oldProps, changeFlags }) {\n if (changeFlags.dataChanged || changeFlags.updateTriggersChanged) {\n const { data, getPath, getDirection, getMarkerColor, getMarkerPercentages, coordinateSystem, coordinateOrigin } = this.props;\n const { viewport } = this.context;\n const projectFlat = (o) => this.projectFlat(o, viewport, coordinateSystem, coordinateOrigin);\n this.state.markers = createPathMarkers({\n data,\n getPath,\n getDirection,\n getColor: getMarkerColor,\n getMarkerPercentages,\n projectFlat\n });\n this._recalculateClosestPoint();\n }\n if (changeFlags.propsChanged) {\n if (props.point !== oldProps.point) {\n this._recalculateClosestPoint();\n }\n }\n }\n _recalculateClosestPoint() {\n const { highlightPoint, highlightIndex } = this.props;\n if (highlightPoint && highlightIndex >= 0) {\n const object = this.props.data[highlightIndex];\n const points = this.props.getPath(object, null);\n const { point } = getClosestPointOnPolyline({ points, p: highlightPoint });\n this.state.closestPoints = [{ position: point }];\n }\n else {\n this.state.closestPoints = [];\n }\n }\n getPickingInfo({ info }) {\n return Object.assign(info, {\n // override object with picked feature\n object: (info.object && info.object.path) || info.object\n });\n }\n renderLayers() {\n return [\n new PathOutlineLayer(this.props, this.getSubLayerProps({\n id: 'paths',\n // Note: data has to be passed explicitly like this to avoid being empty\n data: this.props.data\n })),\n new this.props.MarkerLayer(this.getSubLayerProps(Object.assign({}, this.props.markerLayerProps, {\n id: 'markers',\n data: this.state.markers,\n getOrientation: (x) => [0, -x.angle, 0],\n getColor: (x) => x.color,\n sizeScale: this.props.sizeScale,\n fp64: this.props.fp64,\n pickable: false,\n parameters: {\n blend: false,\n depthTest: false\n }\n }))),\n this.state.closestPoints &&\n new ScatterplotLayer({\n id: `${this.props.id}-highlight`,\n data: this.state.closestPoints,\n fp64: this.props.fp64\n })\n ];\n }\n}\n", "// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { Geometry } from '@luma.gl/engine';\nexport class Arrow2DGeometry extends Geometry {\n constructor(opts = {}) {\n super(Object.assign({}, opts, {\n attributes: getArrowAttributes(opts),\n topology: 'triangle-list'\n }));\n }\n}\nfunction getArrowAttributes({ length = 1, headSize = 0.2, tailWidth = 0.05, tailStart = 0.05 }) {\n const texCoords = [\n // HEAD\n 0.5,\n 1.0,\n 0,\n 0.5 - headSize / 2,\n 1.0 - headSize,\n 0,\n 0.5 + headSize / 2,\n 1.0 - headSize,\n 0,\n 0.5 - tailWidth / 2,\n tailStart,\n 0,\n 0.5 + tailWidth / 2,\n 1.0 - headSize,\n 0,\n 0.5 + tailWidth / 2,\n tailStart,\n 0,\n 0.5 - tailWidth / 2,\n tailStart,\n 0,\n 0.5 - tailWidth / 2,\n 1.0 - headSize,\n 0,\n 0.5 + tailWidth / 2,\n 1.0 - headSize,\n 0\n ];\n 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];\n // Center and scale\n const positions = new Array(texCoords.length);\n for (let i = 0; i < texCoords.length / 3; i++) {\n const i3 = i * 3;\n positions[i3 + 0] = (texCoords[i3 + 0] - 0.5) * length;\n positions[i3 + 1] = (texCoords[i3 + 1] - 0.5) * length;\n positions[i3 + 2] = 0;\n }\n return {\n positions: { size: 3, value: new Float32Array(positions) },\n normals: { size: 3, value: new Float32Array(normals) },\n texCoords: { size: 2, value: new Float32Array(texCoords) }\n };\n}\n", "// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { Vector2 } from '@math.gl/core';\nfunction getLineLength(vPoints) {\n // calculate total length\n let lineLength = 0;\n for (let i = 0; i < vPoints.length - 1; i++) {\n lineLength += vPoints[i].distance(vPoints[i + 1]);\n }\n return lineLength;\n}\nconst DEFAULT_COLOR = [0, 0, 0, 255];\nconst DEFAULT_DIRECTION = { forward: true, backward: false };\nexport function createPathMarkers({ data, getPath = (x, context) => x.path, getDirection = (x) => x.direction, getColor = (x) => DEFAULT_COLOR, getMarkerPercentages = (x, info) => [0.5], projectFlat }) {\n const markers = [];\n for (const object of data) {\n const path = getPath(object, null);\n const direction = getDirection(object) || DEFAULT_DIRECTION;\n const color = getColor(object);\n const vPoints = path.map((p) => new Vector2(p));\n const vPointsReverse = vPoints.slice(0).reverse();\n // calculate total length\n const lineLength = getLineLength(vPoints);\n // Ask for where to put markers\n const percentages = getMarkerPercentages(object, { lineLength });\n // Create the markers\n for (const percentage of percentages) {\n if (direction.forward) {\n const marker = createMarkerAlongPath({\n path: vPoints,\n percentage,\n lineLength,\n color,\n object,\n projectFlat\n });\n markers.push(marker);\n }\n if (direction.backward) {\n const marker = createMarkerAlongPath({\n path: vPointsReverse,\n percentage,\n lineLength,\n color,\n object,\n projectFlat\n });\n markers.push(marker);\n }\n }\n }\n return markers;\n}\nfunction createMarkerAlongPath({ path, percentage, lineLength, color, object, projectFlat }) {\n const distanceAlong = lineLength * percentage;\n let currentDistance = 0;\n let previousDistance = 0;\n let i = 0;\n for (i = 0; i < path.length - 1; i++) {\n currentDistance += path[i].distance(path[i + 1]);\n if (currentDistance > distanceAlong) {\n break;\n }\n previousDistance = currentDistance;\n }\n // If reached the end of the loop without exiting early,\n // undo the final increment to avoid a null-pointer exception\n if (i === path.length - 1) {\n i -= 1;\n }\n const vDirection = path[i + 1].clone().subtract(path[i]).normalize();\n const along = distanceAlong - previousDistance;\n const vCenter = vDirection.clone().multiply(new Vector2(along, along)).add(path[i]);\n const vDirection2 = new Vector2(projectFlat(path[i + 1])).subtract(projectFlat(path[i]));\n const angle = (vDirection2.verticalAngle() * 180) / Math.PI;\n return { position: [vCenter.x, vCenter.y, 0], angle, color, object };\n}\n", "// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { Vector3, clamp } from '@math.gl/core';\n// Return the closest point on a line segment\nexport function getClosestPointOnLine({ p, p1, p2, clampToLine = true }) {\n const lineVector = new Vector3(p2).subtract(p1);\n const pointVector = new Vector3(p).subtract(p1);\n let dotProduct = lineVector.dot(pointVector);\n if (clampToLine) {\n dotProduct = clamp(dotProduct, 0, 1);\n }\n return lineVector.lerp(p1, p2, dotProduct);\n}\n// Return the closest point on a line segment\nexport function getClosestPointOnPolyline({ p, points }) {\n p = new Vector3(p);\n let pClosest = null;\n let distanceSquared = Infinity;\n let index = -1;\n for (let i = 0; i < points.length - 1; ++i) {\n const p1 = points[i];\n const p2 = points[i + 1];\n const pClosestOnLine = getClosestPointOnLine({ p, p1, p2 });\n const distanceToLineSquared = p.distanceSquared(pClosestOnLine);\n if (distanceToLineSquared < distanceSquared) {\n distanceSquared = distanceToLineSquared;\n pClosest = pClosestOnLine;\n index = i;\n }\n }\n return {\n point: pClosest,\n index,\n p1: points[index],\n p2: points[index + 1],\n distanceSquared,\n distance: Math.sqrt(distanceSquared)\n };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,kBAA+B;AAC/B,wBAA0B;AAC1B,oBAAqD;AAErD,IAAM,mBAAoB,OAAO,WAAW,eAAe,OAAO,oBAAqB;AAOhF,IAAM,kBAAN,cAA8B,2BAAe;AAAA,EAMhD,QAAQ;AAAA,EACR,kBAAkB;AACd,SAAK,SAAS;AAAA,MACV,YAAY;AAAA,IAChB,CAAC;AAAA,EACL;AAAA,EACA,YAAY,EAAE,OAAO,YAAY,GAAG;AAChC,SAAK,SAAS;AAAA,MACV,YAAY,MAAM;AAAA,IACtB,CAAC;AAAA,EACL;AAAA,EACA,eAAe;AACX,UAAM,EAAE,YAAY,iBAAiB,UAAU,YAAY,IAAI,KAAK;AACpE,UAAM,WAAU,qCAAU,YAAW;AACrC,UAAM,WAAU,qCAAU,YAAW;AACrC,WAAO;AAAA,MACH,IAAI,4BAAU;AAAA;AAAA,QAEV,IAAI,OAAO,WAAW,GAAG;AAAA,QACzB,aAAa,WAAW;AAAA;AAAA,Q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,CAAC;AAAA,QACtC,UAAU,CAAC,MAAM,EAAE;AAAA,QACnB,WAAW,KAAK,MAAM;AAAA,QACtB,MAAM,KAAK,MAAM;AAAA,QACjB,UAAU;AAAA,QACV,YAAY;AAAA,UACR,OAAO;AAAA,UACP,WAAW;AAAA,QACf;AAAA,MACJ,CAAC,CAAC,CAAC;AAAA,MACH,KAAK,MAAM,iBACP,IAAI,gCAAiB;AAAA,QACjB,IAAI,GAAG,KAAK,MAAM;AAAA,QAClB,MAAM,KAAK,MAAM;AAAA,QACjB,MAAM,KAAK,MAAM;AAAA,MACrB,CAAC;AAAA,IACT;AAAA,EACJ;AACJ;AA3FI,cADS,iBACF,aAAY;AACnB,cAFS,iBAEF,gBAAeA;",
6
+ "names": ["import_layers", "import_core", "import_layers", "import_core", "import_core", "defaultProps"]
7
+ }
@@ -0,0 +1,6 @@
1
+ export type { TileSourceLayerProps } from './tile-source-layer/tile-source-layer';
2
+ export { TileSourceLayer } from './tile-source-layer/tile-source-layer';
3
+ export type { PathOutlineLayerProps } from './path-outline-layer/path-outline-layer';
4
+ export { PathOutlineLayer } from './path-outline-layer/path-outline-layer';
5
+ export type { PathMarkerLayerProps } from './path-marker-layer/path-marker-layer';
6
+ export { PathMarkerLayer } from './path-marker-layer/path-marker-layer';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export { TileSourceLayer } from "./tile-source-layer.js";
2
- export { DataDrivenTile3DLayer } from "./data-driven-tile-3d-layer/data-driven-tile-3d-layer.js";
3
- export { colorizeTile } from "./data-driven-tile-3d-layer/utils/colorize-tile.js";
4
- export { filterTile } from "./data-driven-tile-3d-layer/utils/filter-tile.js";
5
- //# sourceMappingURL=index.js.map
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { TileSourceLayer } from './tile-source-layer/tile-source-layer';
5
+ export { PathOutlineLayer } from './path-outline-layer/path-outline-layer';
6
+ export { PathMarkerLayer } from './path-marker-layer/path-marker-layer';
@@ -0,0 +1,4 @@
1
+ import { Geometry } from '@luma.gl/engine';
2
+ export declare class Arrow2DGeometry extends Geometry {
3
+ constructor(opts?: {});
4
+ }
@@ -0,0 +1,58 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { Geometry } from '@luma.gl/engine';
5
+ export class Arrow2DGeometry extends Geometry {
6
+ constructor(opts = {}) {
7
+ super(Object.assign({}, opts, {
8
+ attributes: getArrowAttributes(opts),
9
+ topology: 'triangle-list'
10
+ }));
11
+ }
12
+ }
13
+ function getArrowAttributes({ length = 1, headSize = 0.2, tailWidth = 0.05, tailStart = 0.05 }) {
14
+ const texCoords = [
15
+ // HEAD
16
+ 0.5,
17
+ 1.0,
18
+ 0,
19
+ 0.5 - headSize / 2,
20
+ 1.0 - headSize,
21
+ 0,
22
+ 0.5 + headSize / 2,
23
+ 1.0 - headSize,
24
+ 0,
25
+ 0.5 - tailWidth / 2,
26
+ tailStart,
27
+ 0,
28
+ 0.5 + tailWidth / 2,
29
+ 1.0 - headSize,
30
+ 0,
31
+ 0.5 + tailWidth / 2,
32
+ tailStart,
33
+ 0,
34
+ 0.5 - tailWidth / 2,
35
+ tailStart,
36
+ 0,
37
+ 0.5 - tailWidth / 2,
38
+ 1.0 - headSize,
39
+ 0,
40
+ 0.5 + tailWidth / 2,
41
+ 1.0 - headSize,
42
+ 0
43
+ ];
44
+ 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];
45
+ // Center and scale
46
+ const positions = new Array(texCoords.length);
47
+ for (let i = 0; i < texCoords.length / 3; i++) {
48
+ const i3 = i * 3;
49
+ positions[i3 + 0] = (texCoords[i3 + 0] - 0.5) * length;
50
+ positions[i3 + 1] = (texCoords[i3 + 1] - 0.5) * length;
51
+ positions[i3 + 2] = 0;
52
+ }
53
+ return {
54
+ positions: { size: 3, value: new Float32Array(positions) },
55
+ normals: { size: 3, value: new Float32Array(normals) },
56
+ texCoords: { size: 2, value: new Float32Array(texCoords) }
57
+ };
58
+ }
@@ -0,0 +1,18 @@
1
+ /** GeoJSON style position coordinate vector */
2
+ export type Position = [number, number] | [number, number, number];
3
+ /** [red, green, blue, alpha] in premultiplied alpha format */
4
+ export type Color = [number, number, number, number];
5
+ export interface PathMarker {
6
+ position: Position;
7
+ angle: number;
8
+ color: Color;
9
+ object: unknown;
10
+ }
11
+ export declare function createPathMarkers({ data, getPath, getDirection, getColor, getMarkerPercentages, projectFlat }: {
12
+ data: any;
13
+ getPath?: (x: any, context: any) => any;
14
+ getDirection?: (x: any) => any;
15
+ getColor?: (x: any) => number[];
16
+ getMarkerPercentages?: (x: any, info: any) => number[];
17
+ projectFlat: any;
18
+ }): PathMarker[];
@@ -0,0 +1,78 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { Vector2 } from '@math.gl/core';
5
+ function getLineLength(vPoints) {
6
+ // calculate total length
7
+ let lineLength = 0;
8
+ for (let i = 0; i < vPoints.length - 1; i++) {
9
+ lineLength += vPoints[i].distance(vPoints[i + 1]);
10
+ }
11
+ return lineLength;
12
+ }
13
+ const DEFAULT_COLOR = [0, 0, 0, 255];
14
+ const DEFAULT_DIRECTION = { forward: true, backward: false };
15
+ export function createPathMarkers({ data, getPath = (x, context) => x.path, getDirection = (x) => x.direction, getColor = (x) => DEFAULT_COLOR, getMarkerPercentages = (x, info) => [0.5], projectFlat }) {
16
+ const markers = [];
17
+ for (const object of data) {
18
+ const path = getPath(object, null);
19
+ const direction = getDirection(object) || DEFAULT_DIRECTION;
20
+ const color = getColor(object);
21
+ const vPoints = path.map((p) => new Vector2(p));
22
+ const vPointsReverse = vPoints.slice(0).reverse();
23
+ // calculate total length
24
+ const lineLength = getLineLength(vPoints);
25
+ // Ask for where to put markers
26
+ const percentages = getMarkerPercentages(object, { lineLength });
27
+ // Create the markers
28
+ for (const percentage of percentages) {
29
+ if (direction.forward) {
30
+ const marker = createMarkerAlongPath({
31
+ path: vPoints,
32
+ percentage,
33
+ lineLength,
34
+ color,
35
+ object,
36
+ projectFlat
37
+ });
38
+ markers.push(marker);
39
+ }
40
+ if (direction.backward) {
41
+ const marker = createMarkerAlongPath({
42
+ path: vPointsReverse,
43
+ percentage,
44
+ lineLength,
45
+ color,
46
+ object,
47
+ projectFlat
48
+ });
49
+ markers.push(marker);
50
+ }
51
+ }
52
+ }
53
+ return markers;
54
+ }
55
+ function createMarkerAlongPath({ path, percentage, lineLength, color, object, projectFlat }) {
56
+ const distanceAlong = lineLength * percentage;
57
+ let currentDistance = 0;
58
+ let previousDistance = 0;
59
+ let i = 0;
60
+ for (i = 0; i < path.length - 1; i++) {
61
+ currentDistance += path[i].distance(path[i + 1]);
62
+ if (currentDistance > distanceAlong) {
63
+ break;
64
+ }
65
+ previousDistance = currentDistance;
66
+ }
67
+ // If reached the end of the loop without exiting early,
68
+ // undo the final increment to avoid a null-pointer exception
69
+ if (i === path.length - 1) {
70
+ i -= 1;
71
+ }
72
+ const vDirection = path[i + 1].clone().subtract(path[i]).normalize();
73
+ const along = distanceAlong - previousDistance;
74
+ const vCenter = vDirection.clone().multiply(new Vector2(along, along)).add(path[i]);
75
+ const vDirection2 = new Vector2(projectFlat(path[i + 1])).subtract(projectFlat(path[i]));
76
+ const angle = (vDirection2.verticalAngle() * 180) / Math.PI;
77
+ return { position: [vCenter.x, vCenter.y, 0], angle, color, object };
78
+ }
@@ -0,0 +1,40 @@
1
+ import { CompositeLayer, DefaultProps } from '@deck.gl/core';
2
+ import { PathOutlineLayerProps } from '../path-outline-layer/path-outline-layer';
3
+ import { Arrow2DGeometry } from './arrow-2d-geometry';
4
+ import { Vector3 } from '@math.gl/core';
5
+ export type PathMarkerLayerProps<DataT> = PathOutlineLayerProps<DataT> & {
6
+ getDirection?: (x: any) => any;
7
+ getMarkerColor?: (x: any) => number[];
8
+ getMarkerPercentages?: (x: any, info: any) => number[];
9
+ highlightPoint?: any;
10
+ highlightIndex?: number;
11
+ MarkerLayer?: any;
12
+ markerLayerProps?: any;
13
+ sizeScale?: number;
14
+ fp64?: boolean;
15
+ nebulaLayer?: any;
16
+ };
17
+ export declare class PathMarkerLayer<DataT = any, ExtraPropsT = Record<string, unknown>> extends CompositeLayer<ExtraPropsT & Required<PathMarkerLayerProps<DataT>>> {
18
+ static layerName: string;
19
+ static defaultProps: DefaultProps<PathMarkerLayerProps<any>>;
20
+ state: {
21
+ closestPoint: Vector3 | null;
22
+ closestPoints?: {
23
+ position: Vector3;
24
+ }[];
25
+ markers: any[];
26
+ mesh: Arrow2DGeometry;
27
+ };
28
+ initializeState(): void;
29
+ projectFlat(xyz: any, viewport: any, coordinateSystem: any, coordinateOrigin: any): any;
30
+ updateState({ props, oldProps, changeFlags }: {
31
+ props: any;
32
+ oldProps: any;
33
+ changeFlags: any;
34
+ }): void;
35
+ _recalculateClosestPoint(): void;
36
+ getPickingInfo({ info }: {
37
+ info: any;
38
+ }): any;
39
+ renderLayers(): any[];
40
+ }
@@ -0,0 +1,124 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { CompositeLayer, COORDINATE_SYSTEM } from '@deck.gl/core';
5
+ import { ScatterplotLayer } from '@deck.gl/layers';
6
+ import { SimpleMeshLayer } from '@deck.gl/mesh-layers';
7
+ import { PathOutlineLayer } from '../path-outline-layer/path-outline-layer';
8
+ import { Arrow2DGeometry } from './arrow-2d-geometry';
9
+ import { createPathMarkers } from './create-path-markers';
10
+ import { getClosestPointOnPolyline } from './polyline';
11
+ const DISTANCE_FOR_MULTI_ARROWS = 0.1;
12
+ const ARROW_HEAD_SIZE = 0.2;
13
+ const ARROW_TAIL_WIDTH = 0.05;
14
+ // const ARROW_CENTER_ADJUST = -0.8;
15
+ const DEFAULT_MARKER_LAYER = SimpleMeshLayer;
16
+ const DEFAULT_MARKER_LAYER_PROPS = {
17
+ mesh: new Arrow2DGeometry({ headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH })
18
+ };
19
+ const defaultProps = Object.assign({}, PathOutlineLayer.defaultProps, {
20
+ MarkerLayer: DEFAULT_MARKER_LAYER,
21
+ markerLayerProps: DEFAULT_MARKER_LAYER_PROPS,
22
+ sizeScale: 100,
23
+ fp64: false,
24
+ highlightIndex: -1,
25
+ highlightPoint: null,
26
+ getPath: (x) => x.path,
27
+ getColor: (x) => x.color,
28
+ getMarkerColor: (x) => [0, 0, 0, 255],
29
+ getDirection: (x) => x.direction,
30
+ getMarkerPercentages: (object, { lineLength }) => lineLength > DISTANCE_FOR_MULTI_ARROWS ? [0.25, 0.5, 0.75] : [0.5]
31
+ });
32
+ export class PathMarkerLayer extends CompositeLayer {
33
+ static layerName = 'PathMarkerLayer';
34
+ static defaultProps = defaultProps;
35
+ state = undefined;
36
+ initializeState() {
37
+ this.state = {
38
+ markers: [],
39
+ mesh: new Arrow2DGeometry({ headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH }),
40
+ closestPoint: null,
41
+ closestPoints: []
42
+ };
43
+ }
44
+ projectFlat(xyz, viewport, coordinateSystem, coordinateOrigin) {
45
+ if (coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS) {
46
+ const [dx, dy] = viewport.metersToLngLatDelta(xyz);
47
+ const [x, y] = coordinateOrigin;
48
+ return viewport.projectFlat([x + dx, dy + y]);
49
+ }
50
+ else if (coordinateSystem === COORDINATE_SYSTEM.LNGLAT_OFFSETS) {
51
+ const [dx, dy] = xyz;
52
+ const [x, y] = coordinateOrigin;
53
+ return viewport.projectFlat([x + dx, dy + y]);
54
+ }
55
+ return viewport.projectFlat(xyz);
56
+ }
57
+ updateState({ props, oldProps, changeFlags }) {
58
+ if (changeFlags.dataChanged || changeFlags.updateTriggersChanged) {
59
+ const { data, getPath, getDirection, getMarkerColor, getMarkerPercentages, coordinateSystem, coordinateOrigin } = this.props;
60
+ const { viewport } = this.context;
61
+ const projectFlat = (o) => this.projectFlat(o, viewport, coordinateSystem, coordinateOrigin);
62
+ this.state.markers = createPathMarkers({
63
+ data,
64
+ getPath,
65
+ getDirection,
66
+ getColor: getMarkerColor,
67
+ getMarkerPercentages,
68
+ projectFlat
69
+ });
70
+ this._recalculateClosestPoint();
71
+ }
72
+ if (changeFlags.propsChanged) {
73
+ if (props.point !== oldProps.point) {
74
+ this._recalculateClosestPoint();
75
+ }
76
+ }
77
+ }
78
+ _recalculateClosestPoint() {
79
+ const { highlightPoint, highlightIndex } = this.props;
80
+ if (highlightPoint && highlightIndex >= 0) {
81
+ const object = this.props.data[highlightIndex];
82
+ const points = this.props.getPath(object, null);
83
+ const { point } = getClosestPointOnPolyline({ points, p: highlightPoint });
84
+ this.state.closestPoints = [{ position: point }];
85
+ }
86
+ else {
87
+ this.state.closestPoints = [];
88
+ }
89
+ }
90
+ getPickingInfo({ info }) {
91
+ return Object.assign(info, {
92
+ // override object with picked feature
93
+ object: (info.object && info.object.path) || info.object
94
+ });
95
+ }
96
+ renderLayers() {
97
+ return [
98
+ new PathOutlineLayer(this.props, this.getSubLayerProps({
99
+ id: 'paths',
100
+ // Note: data has to be passed explicitly like this to avoid being empty
101
+ data: this.props.data
102
+ })),
103
+ new this.props.MarkerLayer(this.getSubLayerProps(Object.assign({}, this.props.markerLayerProps, {
104
+ id: 'markers',
105
+ data: this.state.markers,
106
+ getOrientation: (x) => [0, -x.angle, 0],
107
+ getColor: (x) => x.color,
108
+ sizeScale: this.props.sizeScale,
109
+ fp64: this.props.fp64,
110
+ pickable: false,
111
+ parameters: {
112
+ blend: false,
113
+ depthTest: false
114
+ }
115
+ }))),
116
+ this.state.closestPoints &&
117
+ new ScatterplotLayer({
118
+ id: `${this.props.id}-highlight`,
119
+ data: this.state.closestPoints,
120
+ fp64: this.props.fp64
121
+ })
122
+ ];
123
+ }
124
+ }
@@ -0,0 +1,18 @@
1
+ import { Vector3 } from '@math.gl/core';
2
+ export declare function getClosestPointOnLine({ p, p1, p2, clampToLine }: {
3
+ p: any;
4
+ p1: any;
5
+ p2: any;
6
+ clampToLine?: boolean;
7
+ }): Vector3;
8
+ export declare function getClosestPointOnPolyline({ p, points }: {
9
+ p: any;
10
+ points: any;
11
+ }): {
12
+ point: Vector3;
13
+ index: number;
14
+ p1: any;
15
+ p2: any;
16
+ distanceSquared: number;
17
+ distance: number;
18
+ };
@@ -0,0 +1,40 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { Vector3, clamp } from '@math.gl/core';
5
+ // Return the closest point on a line segment
6
+ export function getClosestPointOnLine({ p, p1, p2, clampToLine = true }) {
7
+ const lineVector = new Vector3(p2).subtract(p1);
8
+ const pointVector = new Vector3(p).subtract(p1);
9
+ let dotProduct = lineVector.dot(pointVector);
10
+ if (clampToLine) {
11
+ dotProduct = clamp(dotProduct, 0, 1);
12
+ }
13
+ return lineVector.lerp(p1, p2, dotProduct);
14
+ }
15
+ // Return the closest point on a line segment
16
+ export function getClosestPointOnPolyline({ p, points }) {
17
+ p = new Vector3(p);
18
+ let pClosest = null;
19
+ let distanceSquared = Infinity;
20
+ let index = -1;
21
+ for (let i = 0; i < points.length - 1; ++i) {
22
+ const p1 = points[i];
23
+ const p2 = points[i + 1];
24
+ const pClosestOnLine = getClosestPointOnLine({ p, p1, p2 });
25
+ const distanceToLineSquared = p.distanceSquared(pClosestOnLine);
26
+ if (distanceToLineSquared < distanceSquared) {
27
+ distanceSquared = distanceToLineSquared;
28
+ pClosest = pClosestOnLine;
29
+ index = i;
30
+ }
31
+ }
32
+ return {
33
+ point: pClosest,
34
+ index,
35
+ p1: points[index],
36
+ p2: points[index + 1],
37
+ distanceSquared,
38
+ distance: Math.sqrt(distanceSquared)
39
+ };
40
+ }
@@ -0,0 +1,8 @@
1
+ declare function getUniforms({ outlineEnabled, outlineRenderShadowmap, outlineShadowmap }?: Record<string, any>): Record<string, any>;
2
+ export declare const outline: {
3
+ readonly name: "outline";
4
+ readonly vs: "#version 300 es\nin float instanceZLevel;\nout float outline_vzLevel;\nout vec4 outline_vPosition;\n\n// Set the z level for the outline shadowmap rendering\nvoid outline_setZLevel(float zLevel) {\n outline_vzLevel = zLevel;\n}\n\n// Store an adjusted position for texture2DProj\nvoid outline_setUV(vec4 position) {\n // mat4(\n // 0.5, 0.0, 0.0, 0.0,\n // 0.0, 0.5, 0.0, 0.0,\n // 0.0, 0.0, 0.5, 0.0,\n // 0.5, 0.5, 0.5, 1.0\n // ) * position;\n outline_vPosition = vec4(position.xyz * 0.5 + position.w * 0.5, position.w);\n}\n";
5
+ readonly fs: "uniform bool outline_uEnabled;\nuniform bool outline_uRenderOutlines;\nuniform sampler2D outline_uShadowmap;\n\nin float outline_vzLevel;\n// in vec2 outline_vUV;\nin vec4 outline_vPosition;\n\nout vec4 fragColor;\n\nconst float OUTLINE_Z_LEVEL_ERROR = 0.01;\n\n// Return a darker color in shadowmap\nvec4 outline_filterShadowColor(vec4 color) {\n return vec4(outline_vzLevel / 255., outline_vzLevel / 255., outline_vzLevel / 255., 1.);\n}\n\n// Return a darker color if in shadowmap\nvec4 outline_filterDarkenColor(vec4 color) {\n if (outline_uEnabled) {\n float maxZLevel;\n if (outline_vPosition.q > 0.0) {\n maxZLevel = texture2DProj(outline_uShadowmap, outline_vPosition).r * 255.;\n } else {\n discard;\n }\n if (maxZLevel < outline_vzLevel + OUTLINE_Z_LEVEL_ERROR) {\n vec4(color.rgb * 0.5, color.a);\n } else {\n discard;\n }\n }\n return color;\n}\n\n// if enabled and rendering outlines - Render depth to shadowmap\n// if enabled and rendering colors - Return a darker color if in shadowmap\n// if disabled, just return color\nvec4 outline_filterColor(vec4 color) {\n if (outline_uEnabled) {\n return outline_uRenderOutlines ?\n outline_filterShadowColor(color) :\n outline_filterDarkenColor(color);\n }\n return color;\n}\n";
6
+ readonly getUniforms: typeof getUniforms;
7
+ };
8
+ export {};
@@ -0,0 +1,100 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /* eslint-disable camelcase */
5
+ const INITIAL_STATE = {
6
+ outlineEnabled: false,
7
+ outlineRenderShadowmap: false,
8
+ outlineShadowmap: null
9
+ };
10
+ function getUniforms({ outlineEnabled, outlineRenderShadowmap, outlineShadowmap } = INITIAL_STATE) {
11
+ const uniforms = {};
12
+ if (outlineEnabled !== undefined) {
13
+ // ? 1.0 : 0.0;
14
+ uniforms.outline_uEnabled = outlineEnabled;
15
+ }
16
+ if (outlineRenderShadowmap !== undefined) {
17
+ // ? 1.0 : 0.0;
18
+ uniforms.outline_uRenderOutlines = outlineRenderShadowmap;
19
+ }
20
+ if (outlineShadowmap !== undefined) {
21
+ uniforms.outline_uShadowmap = outlineShadowmap;
22
+ }
23
+ return uniforms;
24
+ }
25
+ const vs = `\
26
+ #version 300 es
27
+ in float instanceZLevel;
28
+ out float outline_vzLevel;
29
+ out vec4 outline_vPosition;
30
+
31
+ // Set the z level for the outline shadowmap rendering
32
+ void outline_setZLevel(float zLevel) {
33
+ outline_vzLevel = zLevel;
34
+ }
35
+
36
+ // Store an adjusted position for texture2DProj
37
+ void outline_setUV(vec4 position) {
38
+ // mat4(
39
+ // 0.5, 0.0, 0.0, 0.0,
40
+ // 0.0, 0.5, 0.0, 0.0,
41
+ // 0.0, 0.0, 0.5, 0.0,
42
+ // 0.5, 0.5, 0.5, 1.0
43
+ // ) * position;
44
+ outline_vPosition = vec4(position.xyz * 0.5 + position.w * 0.5, position.w);
45
+ }
46
+ `;
47
+ const fs = `\
48
+ uniform bool outline_uEnabled;
49
+ uniform bool outline_uRenderOutlines;
50
+ uniform sampler2D outline_uShadowmap;
51
+
52
+ in float outline_vzLevel;
53
+ // in vec2 outline_vUV;
54
+ in vec4 outline_vPosition;
55
+
56
+ out vec4 fragColor;
57
+
58
+ const float OUTLINE_Z_LEVEL_ERROR = 0.01;
59
+
60
+ // Return a darker color in shadowmap
61
+ vec4 outline_filterShadowColor(vec4 color) {
62
+ return vec4(outline_vzLevel / 255., outline_vzLevel / 255., outline_vzLevel / 255., 1.);
63
+ }
64
+
65
+ // Return a darker color if in shadowmap
66
+ vec4 outline_filterDarkenColor(vec4 color) {
67
+ if (outline_uEnabled) {
68
+ float maxZLevel;
69
+ if (outline_vPosition.q > 0.0) {
70
+ maxZLevel = texture2DProj(outline_uShadowmap, outline_vPosition).r * 255.;
71
+ } else {
72
+ discard;
73
+ }
74
+ if (maxZLevel < outline_vzLevel + OUTLINE_Z_LEVEL_ERROR) {
75
+ vec4(color.rgb * 0.5, color.a);
76
+ } else {
77
+ discard;
78
+ }
79
+ }
80
+ return color;
81
+ }
82
+
83
+ // if enabled and rendering outlines - Render depth to shadowmap
84
+ // if enabled and rendering colors - Return a darker color if in shadowmap
85
+ // if disabled, just return color
86
+ vec4 outline_filterColor(vec4 color) {
87
+ if (outline_uEnabled) {
88
+ return outline_uRenderOutlines ?
89
+ outline_filterShadowColor(color) :
90
+ outline_filterDarkenColor(color);
91
+ }
92
+ return color;
93
+ }
94
+ `;
95
+ export const outline = {
96
+ name: 'outline',
97
+ vs,
98
+ fs,
99
+ getUniforms
100
+ };
@@ -0,0 +1,34 @@
1
+ import { PathLayer, PathLayerProps } from '@deck.gl/layers';
2
+ import type { DefaultProps, LayerContext } from '@deck.gl/core';
3
+ import { Framebuffer, Texture } from '@luma.gl/core';
4
+ /**
5
+ * Unit literal to shader unit number conversion.
6
+ */
7
+ export declare const UNIT: {
8
+ common: number;
9
+ meters: number;
10
+ pixels: number;
11
+ };
12
+ export type PathOutlineLayerProps<DataT> = PathLayerProps<DataT> & {
13
+ dashJustified?: boolean;
14
+ getDashArray?: [number, number] | ((d: DataT) => [number, number] | null);
15
+ getZLevel?: (d: DataT, index: number) => number;
16
+ };
17
+ export declare class PathOutlineLayer<DataT = any, ExtraPropsT = Record<string, unknown>> extends PathLayer<DataT, ExtraPropsT & Required<PathOutlineLayerProps<DataT>>> {
18
+ static layerName: string;
19
+ static defaultProps: DefaultProps<PathOutlineLayerProps<any>>;
20
+ state: {
21
+ model?: any;
22
+ pathTesselator: any;
23
+ outlineFramebuffer: Framebuffer;
24
+ dummyTexture: Texture;
25
+ };
26
+ getShaders(): any;
27
+ initializeState(context: LayerContext): void;
28
+ draw({ moduleParameters, parameters, uniforms, context }: {
29
+ moduleParameters?: {};
30
+ parameters: any;
31
+ uniforms: any;
32
+ context: any;
33
+ }): void;
34
+ }