mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-27 09:55:23 +01:00
Merge pull request #634 from orangemug/fix/issue-630
Scroll selected <LayerListItem/> into view
This commit is contained in:
commit
a1dedd1aa6
2 changed files with 28 additions and 6 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue