Skip to content

Commit

Permalink
Added ability to define X and Y bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Goran Pavlovic committed Apr 10, 2017
1 parent 871f405 commit 05d03ec
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions leaflet.rrose-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,33 @@ L.Rrose = L.Popup.extend({
closeButton, wrapper;

// Set the pixel distances from the map edges at which popups are too close and need to be re-oriented.
var x_bound = 80, y_bound = 80;
var xBound, yBound;
if (this.options.xBound) {
xBound = this.options.xBound;
}
else {
xBound = 80;
}
if (this.options.yBound) {
yBound = this.options.yBound;
}
else {
yBound = 80;
}
// Determine the alternate direction to pop up; north mimics Leaflet's default behavior, so we initialize to that.
this.options.position = 'n';
// Then see if the point is too far north...
var y_diff = y_bound - this._map.latLngToContainerPoint(this._latlng).y;
var y_diff = yBound - this._map.latLngToContainerPoint(this._latlng).y;
if (y_diff > 0) {
this.options.position = 's'
}
// or too far east...
var x_diff = this._map.latLngToContainerPoint(this._latlng).x - (this._map.getSize().x - x_bound);
var x_diff = this._map.latLngToContainerPoint(this._latlng).x - (this._map.getSize().x - xBound);
if (x_diff > 0) {
this.options.position += 'w'
} else {
// or too far west.
x_diff = x_bound - this._map.latLngToContainerPoint(this._latlng).x;
x_diff = xBound - this._map.latLngToContainerPoint(this._latlng).x;
if (x_diff > 0) {
this.options.position += 'e'
}
Expand Down

0 comments on commit 05d03ec

Please sign in to comment.