diff --git a/imports/ui/pages/Subscriptions/SubscriptionsMap.js b/imports/ui/pages/Subscriptions/SubscriptionsMap.js index d7c2c40..b1a98e4 100644 --- a/imports/ui/pages/Subscriptions/SubscriptionsMap.js +++ b/imports/ui/pages/Subscriptions/SubscriptionsMap.js @@ -43,6 +43,15 @@ class SubscriptionsMap extends React.Component { this.handleMapReady = this.handleMapReady.bind(this); } + // The `subs-public-union` doc (~2.2MB) usually arrives via DDP *after* the map + // is ready, so the one-shot MapReady draw runs with `userSubs` still null. + // Redraw the union (and fit bounds on first real data) whenever it changes. + componentDidUpdate(prevProps) { + if (this.map && this.props.userSubs && this.props.userSubs !== prevProps.userSubs) { + this.handleLeafletLoad(this.map); + } + } + getMap() { return this.map; } @@ -66,7 +75,7 @@ class SubscriptionsMap extends React.Component { handleLeafletLoad(map) { // console.log('Map loading'); - if (map && this.props.userSubs !== 'null') { + if (map && this.props.userSubs && this.props.userSubs !== 'null') { // console.log(`Union of ${this.props.userSubs}`); this.state.union = subsUnion(this.state.union, { map, @@ -74,8 +83,12 @@ class SubscriptionsMap extends React.Component { bounds: this.props.userSubsBounds, fromServer: true, show: true, - fit: this.state.init + // Only auto-fit to the union the first time we draw it with real data + // (and never once the user has recentred), so later reactive updates + // don't steal the current view. `fitDone` is a plain instance flag. + fit: this.state.init && !this.fitDone }); + this.fitDone = true; } }