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
function MapWrapper(props) { | |
// state, ref, and initialization logic eliminated for brevity | |
// update map if features prop changes - logic formerly put into componentDidUpdate | |
useEffect( () => { | |
if (props.features.length) { // may be empty on first render | |
// set features to map | |
featuresLayer.setSource( | |
new VectorSource({ | |
features: props.features // make sure features is an array | |
}) | |
) | |
// fit map to feature extent (with 100px of padding) | |
map.getView().fit(featuresLayer.getSource().getExtent(), { | |
padding: [100,100,100,100] | |
}) | |
} | |
},[props.features]) | |
// return/render logic eliminated for brevity | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment