forked from keplergl/kepler.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
21 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/deckgl-layers/src/geojson-layer/brush-geojson-layer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {Layer, LayerExtension } from '@deck.gl/core'; | ||
import {LayerContext} from '@deck.gl/core/lib/layer'; | ||
|
||
import shaderModule from './brush-shader-module'; | ||
|
||
const defaultProps = { | ||
}; | ||
|
||
export type BrushGeoJsonExtensionProps = { | ||
}; | ||
|
||
// Write an extension to brush geojson layer using the drawn polygon: | ||
// an instanced attribute 'instanceHighlighted' is added to the layer to indicate whether the feature is highlighted | ||
// the shader module is modified to discard the feature if instanceHighlighted is 0 | ||
// the accessor getHighlighted is used to get the value of instanceHighlighted based on the search result in GeoJsonlayer | ||
// From a test, deck: Updated attributes for 7314969 instances in azfyr45-polygons-fill in 162ms | ||
export default class BrushGeoJsonExtension extends LayerExtension { | ||
static defaultProps = defaultProps; | ||
static extensionName = 'BrushGeoJsonExtension'; | ||
|
||
getShaders(extension: any) { | ||
return { | ||
modules: [shaderModule], | ||
defines: {} | ||
}; | ||
} | ||
|
||
initializeState(this: Layer<BrushGeoJsonExtensionProps>, context: LayerContext, extension: this) { | ||
const attributeManager = this.getAttributeManager(); | ||
if (attributeManager) { | ||
attributeManager.addInstanced({ | ||
instanceHighlighted: { | ||
size: 1, | ||
accessor: 'getHighlighted' | ||
} | ||
}); | ||
} | ||
} | ||
updateState({ | ||
props, | ||
oldProps | ||
}) { | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/deckgl-layers/src/geojson-layer/brush-shader-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {project} from '@deck.gl/core'; | ||
|
||
import type {BrushGeoJsonExtensionProps} from './brush-geojson-layer'; | ||
|
||
const vs = ``; | ||
|
||
const fs = ``; | ||
|
||
const inject = { | ||
'vs:#decl': ` | ||
attribute float instanceHighlighted; | ||
varying float vHighlighted; | ||
`, | ||
'vs:#main-end': ` | ||
if (instanceHighlighted == 0.) { | ||
gl_Position = vec4(0.); | ||
} | ||
vHighlighted = instanceHighlighted; | ||
`, | ||
'fs:#decl': ` | ||
varying float vHighlighted; | ||
`, | ||
'fs:DECKGL_FILTER_COLOR': ` | ||
if (vHighlighted == 0.) { | ||
discard; | ||
} | ||
` | ||
}; | ||
|
||
export default { | ||
name: 'brush-geojson', | ||
dependencies: [project], | ||
vs, | ||
fs, | ||
inject, | ||
getUniforms: (opts?: BrushGeoJsonExtensionProps): Record<string, any> => { | ||
if (!opts) { | ||
return {}; | ||
} | ||
return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters