8000 Fixing CloseButton position when Rrose popup opens down. by GPavlovic · Pull Request #10 · erictheise/rrose · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixing CloseButton position when Rrose popup opens down. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Rrose is a plugin for the Leaflet JavaScript Mapping Library. It's useful when y

### How to use it

In your project, drop `leaflet.rrose-src.js` alongside `leaflet-src.js`, `leaflet.rrose.css` alongside `leaflet.css`. You can also install Rrose via [bower](http://bower.io/). Then, instead of instantiating a new `L.Popup` object, instantiate a new `L.Rrose` object:
In your project, drop `leaflet.rrose-src.js` alongside `leaflet-src.js`, `leaflet.rrose.css` alongside `leaflet.css`. You can also install Rrose (v0.2.0) via [bower](http://bower.io/), or serve the library up from [jsDelivr](https://www.jsdelivr.com/?query=rrose). Then, instead of instantiating a new `L.Popup` object, instantiate a new `L.Rrose` object:


```javascript
Expand Down
29 changes: 0 additions & 29 deletions bower.json

This file was deleted.

55 changes: 40 additions & 15 deletions dist/leaflet.rrose-src.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,56 @@

L.Rrose = L.Popup.extend({

_initLayout:function () {
_initLayout: function () {
var prefix = 'leaflet-rrose',
container = this._container = L.DomUtil.create('div', prefix + ' ' + this.options.className + ' leaflet-zoom-animated'),
closeButton, wrapper;

if (this.options.closeButton) {
closeButton = this._closeButton = L.DomUtil.create('a', prefix + '-close-button', container);
closeButton.href = '#close';
closeButton.innerHTML = '×';

L.DomEvent.on(closeButton, 'click', this._onCloseButtonClick, this);
}

// 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.latLngToContainer 8000 Point(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'
}
}

if (this.options.closeButton) {
let closeButtonClass = prefix + '-close-button';
if (this.options.position === 's') {
closeButtonClass += ' ' + prefix + '-close-button-s';
}
closeButton = this._closeButton = L.DomUtil.create('a', closeButtonClass, container);
closeButton.href = '#close';
closeButton.innerHTML = '×';

L.DomEvent.on(closeButton, 'click', this._onCloseButtonClick, this);
}

// Create the necessary DOM elements in the correct order. Pure 'n' and 's' conditions need only one class for styling, others need two.
if (/s/.test(this.options.position)) {
if (this.options.position === 's') {
Expand Down Expand Up @@ -83,7 +99,7 @@ L.Rrose = L.Popup.extend({

},

_updatePosition:function () {
_updatePosition: function () {
var pos = this._map.latLngToLayerPoint(this._latlng),
is3d = L.Browser.any3d,
offset = this.options.offset;
Expand All @@ -93,7 +109,12 @@ L.Rrose = L.Popup.extend({
}

if (/s/.test(this.options.position)) {
this._containerBottom = -this._container.offsetHeight + offset.y - (is3d ? 0 : pos.y);
if (this._map.getBounds()._southWest.lat < 0) {
this._containerBottom = -this._container.offsetHeight - offset.y + (is3d ? 0 : pos.y);
}
else {
this._containerBottom = -this._container.offsetHeight + offset.y - (is3d ? 0 : pos.y);
}
} else {
this._containerBottom = -offset.y - (is3d ? 0 : pos.y);
}
Expand All @@ -113,3 +134,7 @@ L.Rrose = L.Popup.extend({
}

});

L.rrose = function (options, source) {
return new L.Rrose(options, source);
};
6 changes: 5 additions & 1 deletion dist/leaflet.rrose.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ a.leaflet-rrose-close-button {
font-weight: bold;
}

a.leaflet-rrose-close-button-s {
top: 20px;
}

a.leaflet-rrose-close-button:hover {
color: #999;
}
Expand Down Expand Up @@ -136,4 +140,4 @@ a.leaflet-rrose-close-button:hover {

.leaflet-rrose-content {
font: 12px/1.4 "Helvetica Neue", Arial, Helvetica, sans-serif;
}
}
115 changes: 0 additions & 115 deletions leaflet.rrose-src.js

This file was deleted.

Loading
0