Skip to content
Permalink
Browse files

Added onMapCenterChanged() and onMapZoomChanged() events

  • Loading branch information...
MiniCodeMonkey committed Mar 6, 2019
1 parent 512442b commit 46ea4f3f47368a75f0c525e2ee7190f2c3a7f5a3
Showing with 14 additions and 0 deletions.
  1. +8 −0 docs/events.html
  2. +6 −0 src/Map.js
@@ -38,6 +38,14 @@
console.log('You hovered ' + feature.properties.NAME);
};
map.onMapCenterChanged = function (center) {
console.log('New center is ' + center.join(', '));
};
map.onMapZoomChanged = function (zoom) {
console.log('New zoom is ' + zoom);
};
fetch('https://gistcdn.githack.com/mpmckenna8/af23032b41f0ea1212563b523e859228/raw/0cbceeedf57d9bf2e723f57d19e923591b9249a0/schoolsca.topojson')
.then(response => response.json())
.then(json => {
@@ -28,6 +28,8 @@ export default class Map {
this.onMarkerHover = null;
this.onPolygonClicked = null;
this.onPolygonHover = null;
this.onMapCenterChanged = null;
this.onMapZoomChanged = null;

this.draw = this.draw.bind(this);
window.requestAnimationFrame(this.draw);
@@ -315,6 +317,8 @@ export default class Map {

this.setTargetMoveOffset(0, 0, false);
this.options.center = latLon;

this.onMapCenterChanged && this.onMapCenterChanged(this.options.center);
}

updateZoom() {
@@ -346,6 +350,8 @@ export default class Map {
this.state.tileLayers[0].tilesZoomLevel = null;

// this.state.tileLayers[this.state.tileLayers.length - 1].shouldBeDeleted = true;

this.onMapZoomChanged && this.onMapZoomChanged(this.options.zoom);
}
} else {
this.state.scale = 1;

0 comments on commit 46ea4f3

Please sign in to comment.
You can’t perform that action at this time.