Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created August 19, 2015 20:43
Show Gist options
  • Save tmcw/bd48b2c11504dc537835 to your computer and use it in GitHub Desktop.
Save tmcw/bd48b2c11504dc537835 to your computer and use it in GitHub Desktop.

Use this with two Mapbox GL JS map instances as arguments to the syncMaps function and it'll keep them pointed at the same thing.

function copyPosition(a, b) {
b.jumpTo({
center: a.getCenter(),
zoom: a.getZoom(),
bearing: a.getBearing(),
pitch: a.getPitch()
});
}
function syncMaps(a, b) {
a.on('moveend', function() {
copyPosition(a, b);
});
b.on('moveend', function() {
copyPosition(b, a);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment