Merge pull request #634 from orangemug/fix/issue-630

Scroll selected <LayerListItem/> into view
This commit is contained in:
Orange Mug 2020-04-06 13:11:53 +01:00 committed by GitHub
commit a1dedd1aa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View file

@ -42,11 +42,15 @@ class LayerListContainer extends React.Component {
onLayerSelect: () => {}, onLayerSelect: () => {},
} }
state = { constructor(props) {
collapsedGroups: {}, super(props);
areAllGroupsExpanded: false, this.selectedItemRef = React.createRef();
isOpen: { this.state = {
add: false, collapsedGroups: {},
areAllGroupsExpanded: false,
isOpen: {
add: false,
}
} }
} }
@ -161,6 +165,13 @@ class LayerListContainer extends React.Component {
return propsChanged; return propsChanged;
} }
componentDidUpdate () {
const selectedItemNode = this.selectedItemRef.current;
if (selectedItemNode && selectedItemNode.node) {
selectedItemNode.node.scrollIntoView();
}
}
render() { render() {
const listItems = [] const listItems = []
@ -192,6 +203,11 @@ class LayerListContainer extends React.Component {
); );
}); });
const additionalProps = {};
if (idx === this.props.selectedLayerIndex) {
additionalProps.ref = this.selectedItemRef;
}
layerIdCount.set(layer.id, layerIdCount.set(layer.id,
layerIdCount.has(layer.id) ? layerIdCount.get(layer.id) + 1 : 0 layerIdCount.has(layer.id) ? layerIdCount.get(layer.id) + 1 : 0
); );
@ -213,6 +229,7 @@ class LayerListContainer extends React.Component {
onLayerDestroy={this.props.onLayerDestroy.bind(this)} onLayerDestroy={this.props.onLayerDestroy.bind(this)}
onLayerCopy={this.props.onLayerCopy.bind(this)} onLayerCopy={this.props.onLayerCopy.bind(this)}
onLayerVisibilityToggle={this.props.onLayerVisibilityToggle.bind(this)} onLayerVisibilityToggle={this.props.onLayerVisibilityToggle.bind(this)}
{...additionalProps}
/> />
listItems.push(listItem) listItems.push(listItem)
idx += 1 idx += 1

View file

@ -170,7 +170,7 @@ export default class MapboxGlMap extends React.Component {
if(this.props.inspectModeEnabled) { if(this.props.inspectModeEnabled) {
return renderPopup(<FeaturePropertyPopup features={features} />, tmpNode); return renderPopup(<FeaturePropertyPopup features={features} />, tmpNode);
} else { } else {
return renderPopup(<FeatureLayerPopup features={features} onLayerSelect={this.props.onLayerSelect} zoom={this.state.zoom} />, tmpNode); return renderPopup(<FeatureLayerPopup features={features} onLayerSelect={this.onLayerSelectById} zoom={this.state.zoom} />, tmpNode);
} }
} }
}) })
@ -208,6 +208,11 @@ export default class MapboxGlMap extends React.Component {
map.on("zoomend", mapViewChange); map.on("zoomend", mapViewChange);
} }
onLayerSelectById = (id) => {
const index = this.props.mapStyle.layers.findIndex(layer => layer.id === id);
this.props.onLayerSelect(index);
}
render() { render() {
if(IS_SUPPORTED) { if(IS_SUPPORTED) {
return <div return <div