-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(docs): Add I3S Picking Tutorial #2896
Changes from 2 commits
844c84e
6baa48e
adc95aa
24c73d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,113 @@ | ||||||
# I3S Picking | ||||||
|
||||||
import Demo from 'examples/website/i3s-picking/src/app'; | ||||||
|
||||||
<div style={{height: '50vh'}}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we rename to *.mdx as it has React? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed |
||||||
<Demo /> | ||||||
</div> | ||||||
|
||||||
<p></p> | ||||||
At the example above you can click any interesting object to get it highlighted and show selected object attributes data. | ||||||
Objects picking can be implemented for `3DObject` layer type only, it's not applicable for `IntegratedMesh` layer type. | ||||||
Please find source code of the example <a href="https://github.com/visgl/loaders.gl/tree/master/examples/website/i3s-picking">here</a> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
|
||||||
## Selected object highlighting | ||||||
|
||||||
To get selected object highlighted it needs to set prop `pickable` of the `Tile3DLayer` to `true` and prop `highlightedObjectIndex` to value of index of the selected object. Please take a look at the short codesnippet below: | ||||||
|
||||||
```ts | ||||||
import DeckGL from '@deck.gl/react'; | ||||||
import {Tile3DLayer} from '@deck.gl/geo-layers'; | ||||||
import Map from 'react-map-gl'; | ||||||
import maplibregl from 'maplibre-gl'; | ||||||
|
||||||
const [highlightedObjectIndex, setHighlightedObjectIndex] = useState(-1); | ||||||
|
||||||
function renderLayers() { | ||||||
const loadOptions = {i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS}}; | ||||||
const layers = new Tile3DLayer({ | ||||||
data: tilesetURL, | ||||||
loader: I3SLoader, | ||||||
onTilesetLoad: onTilesetLoadHandler, | ||||||
loadOptions, | ||||||
pickable: true, | ||||||
highlightedObjectIndex | ||||||
}); | ||||||
return layers; | ||||||
} | ||||||
|
||||||
<DeckGL | ||||||
initialViewState={viewState} | ||||||
layers={renderLayers()} | ||||||
controller={true} | ||||||
onClick={(info) => setHighlightedObjectIndex(info.index)} | ||||||
> | ||||||
<Map reuseMaps mapLib={maplibregl} mapStyle={mapStyle} /> | ||||||
</DeckGL>; | ||||||
``` | ||||||
|
||||||
## Selected object attributes loading | ||||||
|
||||||
To get attributes data for the selected object it needs to invoke `loadFeatureAttributes` with the selected object and object's index as a params. | ||||||
|
||||||
```ts | ||||||
import DeckGL from '@deck.gl/react'; | ||||||
import {Tile3DLayer} from '@deck.gl/geo-layers'; | ||||||
import Map from 'react-map-gl'; | ||||||
import maplibregl from 'maplibre-gl'; | ||||||
import {loadFeatureAttributes} from '@loaders.gl/i3s'; | ||||||
|
||||||
const [highlightedObjectIndex, setHighlightedObjectIndex] = useState(-1); | ||||||
|
||||||
function onClickHandler(info) { | ||||||
setHighlightedObjectIndex(info.index); | ||||||
loadFeatureAttributes(info.object, info.index).then((result) => { | ||||||
setAttributesObject(result); | ||||||
}); | ||||||
} | ||||||
|
||||||
function renderLayers() { | ||||||
const loadOptions = {i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS}}; | ||||||
const layers = new Tile3DLayer({ | ||||||
data: tilesetURL, | ||||||
loader: I3SLoader, | ||||||
onTilesetLoad: onTilesetLoadHandler, | ||||||
loadOptions, | ||||||
pickable: true, | ||||||
highlightedObjectIndex | ||||||
}); | ||||||
return layers; | ||||||
} | ||||||
|
||||||
<DeckGL | ||||||
initialViewState={viewState} | ||||||
layers={renderLayers()} | ||||||
controller={true} | ||||||
onClick={onClickHandler} | ||||||
> | ||||||
<Map reuseMaps mapLib={maplibregl} mapStyle={mapStyle} /> | ||||||
</DeckGL>; | ||||||
``` | ||||||
|
||||||
Here is an example of the result returned by `loadFeatureAttributes`: | ||||||
|
||||||
```javascript | ||||||
{ | ||||||
"OBJECTID": "709688", | ||||||
"BIN": "1088469", | ||||||
"DOITT_ID": "1114961", | ||||||
"SOURCE_ID": "21510003972", | ||||||
"FID": "709688", | ||||||
"NAME": "Tower 1 World Trade Ctr", | ||||||
"BBL": "1000580001", | ||||||
"CNSTRCT_YR": "2009", | ||||||
"LSTMODDATE": "1/1/2015", | ||||||
"LSTSTATYPE": "Constructed", | ||||||
"HEIGHTROOF": "1408.377901", | ||||||
"FTRCODE": "5100", | ||||||
"SUBFTRCODE": "510000", | ||||||
"GROUNDELEV": "5", | ||||||
"NUM_FLOORS": "104", | ||||||
"BUILT_CODE": "" | ||||||
} | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we understand why the layout of this file suddenly changed? Modifications further down somehow triggered prettier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's changed by prettier after saving other changes.
Do you want to revert it back?