Skip to content

Commit

Permalink
ensure map bounds provided even when map is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Oct 28, 2016
1 parent ea369c2 commit e1c8030
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion public/vislib/_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,21 @@ define(function (require) {
};

TileMapMap.prototype.mapBounds = function () {
return this.map.getBounds();
let bounds = this.map.getBounds();

//When map is not visible, there is no width or height.
//Need to manually create bounds based on container width/height
if(bounds.getNorthWest().equals(bounds.getSouthEast())) {
let parent = this._container.parentNode;
while(parent.clientWidth === 0 && parent.clientHeight === 0) {
parent = parent.parentNode;
}

const southWest = this.map.layerPointToLatLng(L.point(parent.clientWidth/2 * -1, parent.clientHeight/2 * -1));
const northEast = this.map.layerPointToLatLng(L.point(parent.clientWidth/2, parent.clientHeight/2));
bounds = L.latLngBounds(southWest, northEast);
}
return bounds;
};

/**
Expand Down

0 comments on commit e1c8030

Please sign in to comment.