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
1 parent
bd12236
commit 3f47a95
Showing
3 changed files
with
86 additions
and
73 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {createElement} from 'react'; | ||
import {View, log} from '@deck.gl/core'; | ||
import {inheritsFrom} from './inherits-from'; | ||
import evaluateChildren from './evaluate-children'; | ||
|
||
// Iterate over views and reposition children associated with views | ||
// TODO - Can we supply a similar function for the non-React case? | ||
export default function positionChildrenUnderViews({children, viewports, deck}) { | ||
const {viewManager} = deck || {}; | ||
|
||
if (!viewManager || !viewManager.views.length) { | ||
return []; | ||
} | ||
|
||
const defaultViewId = viewManager.views[0].id; | ||
|
||
return children.map((child, i) => { | ||
if (child.props.viewportId) { | ||
log.removed('viewportId', '<View>')(); | ||
} | ||
if (child.props.viewId) { | ||
log.removed('viewId', '<View>')(); | ||
} | ||
|
||
// Unless child is a View, position / render as part of the default view | ||
let viewId = defaultViewId; | ||
let viewChildren = child; | ||
if (inheritsFrom(child.type, View)) { | ||
viewId = child.props.id || defaultViewId; | ||
viewChildren = child.props.children; | ||
} | ||
|
||
const viewport = viewManager.getViewport(viewId); | ||
const viewState = viewManager.getViewState(viewId); | ||
|
||
// Drop (auto-hide) elements with viewId that are not matched by any current view | ||
if (!viewport) { | ||
return null; | ||
} | ||
|
||
// Resolve potentially relative dimensions using the deck.gl container size | ||
const {x, y, width, height} = viewport; | ||
|
||
viewChildren = evaluateChildren(viewChildren, { | ||
x, | ||
y, | ||
width, | ||
height, | ||
viewport, | ||
viewState | ||
}); | ||
|
||
const style = {position: 'absolute', left: x, top: y, width, height}; | ||
const key = `view-child-${viewId}-${i}`; | ||
return createElement('div', {key, id: key, style}, viewChildren); | ||
}); | ||
} |