Skip to content

Commit

Permalink
#59 workaround for non-synchronised flyTo
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Mar 16, 2020
1 parent 0dc2019 commit f6e3f3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/components/GenericMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export default class GenericMap extends BasicMap {
componentDidUpdate() {
if (this.mapComponentA && this.mapComponentA.leafletMapInstance && this.mapComponentB && this.mapComponentB.leafletMapInstance) {
this.mapComponentA.leafletMapInstance.sync(this.mapComponentB.leafletMapInstance);
this.mapComponentB.leafletMapInstance.sync(this.mapComponentA.leafletMapInstance);
// WARNING: flyTo will not work if we apply it to both maps!
this.mapComponentB.leafletMapInstance.sync(this.mapComponentA.leafletMapInstance,
{
noInitialSync: true
});
log.debug('Map Components synchronised');
}
}
Expand Down Expand Up @@ -65,6 +69,7 @@ export default class GenericMap extends BasicMap {
exclusiveGroups={this.state.exclusiveGroups}
mapId={'synchronisedMapA'}
ref={(mapComponent) => (this.mapComponentA = mapComponent)}
fly='true'
/>
<MapComponent
loading={this.state.loading}
Expand All @@ -75,6 +80,7 @@ export default class GenericMap extends BasicMap {
exclusiveGroups={this.state.exclusiveGroups}
mapId={'synchronisedMapB'}
ref={(mapComponent) => (this.mapComponentB = mapComponent)}
fly='false'
/>
</>);
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/components/commons/MapComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import turf from 'turf';
import 'leaflet-loading';
import LegendComponent from './LegendComponent.js';
import 'leaflet/dist/leaflet.css';
import log from 'loglevel';

// See https://github.com/mhasbie/react-leaflet-vectorgrid#usage-with-react-leaflet-v2
const ReactLeafletGroupedLayerControl = withLeaflet(ReactLeafletGroupedLayerControlForLeafletv1);
Expand All @@ -30,7 +31,7 @@ export default class MapComponent extends React.Component {

this.baseLayers = props.baseLayers;
this.tileLayerUrl = props.baseLayers[0].url;
this.fly = true;
this.fly = props.fly ? true : false;
// the leaflet instance, retrieved from the leaflet context
// see https://stackoverflow.com/questions/51308835/how-to-use-react-leaflet-context

Expand Down Expand Up @@ -106,6 +107,7 @@ export default class MapComponent extends React.Component {
this.leafletMapInstance.invalidateSize();

if (this.fly && this.props.studyAreaPolygon != null) {
log.info('centering on study area');
this.leafletMapInstance.flyToBounds(this.getBoundsFromArea(this.props.studyAreaPolygon), null);
this.fly = false;
}
Expand Down

0 comments on commit f6e3f3b

Please sign in to comment.