Skip to content

Instantly share code, notes, and snippets.

Created December 14, 2021 15:28
What would you like to do?
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
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]
// return/render logic eliminated for brevity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment