Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
Prevent auto-redraw on selecting Alaska.
Browse files Browse the repository at this point in the history
Alaska is so large that selecting it would normally trigger a refresh of
the state overlays. This patch prevents state redraws triggered
internal zooming and panning.
  • Loading branch information
jmcarp committed Sep 17, 2015
1 parent 85f9c26 commit ae76928
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions static/js/modules/election-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ ElectionLookupMap.prototype.init = function() {
this.overlay = null;
this.districts = null;
this.map = L.map(this.elm);
this.map.on('zoomend', this.handleZoom.bind(this));
this.map.on('viewreset', this.handleReset.bind(this));
L.tileLayer.provider('Stamen.TonerLite').addTo(this.map);
if (this.opts.drawStates) {
this.map.setView([37.8, -96], 3);
Expand Down Expand Up @@ -408,6 +408,7 @@ ElectionLookupMap.prototype.updateBounds = function(districts) {
var rule = districts && _.find(boundsOverrides, function(rule, district) {
return districts.indexOf(parseInt(district)) !== -1;
});
this._viewReset = !!(rule || districts);
if (rule) {
this.map.setView(rule.coords, rule.zoom);
}
Expand Down Expand Up @@ -471,7 +472,11 @@ ElectionLookupMap.prototype.handleDistrictClick = function(e) {
}
};

ElectionLookupMap.prototype.handleZoom = function(e) {
ElectionLookupMap.prototype.handleReset = function(e) {
if (this._viewReset) {
this._viewReset = false;
return;
}
var zoom = e.target.getZoom();
if (zoom <= STATE_ZOOM_THRESHOLD) {
this.drawStates();
Expand Down

0 comments on commit ae76928

Please sign in to comment.