DRYing things up a bit with Rectangle.js
This commit is contained in:
parent
53627cab80
commit
a9c1629875
@ -4,23 +4,20 @@
|
||||
|
||||
L.Rectangle = L.Polygon.extend({
|
||||
initialize: function (latLngBounds, options) {
|
||||
var latlngs = [
|
||||
latLngBounds.getSouthWest(),
|
||||
latLngBounds.getNorthWest(),
|
||||
latLngBounds.getNorthEast(),
|
||||
latLngBounds.getSouthEast(),
|
||||
latLngBounds.getSouthWest()
|
||||
];
|
||||
L.Polygon.prototype.initialize.call(this, latlngs, options);
|
||||
L.Polygon.prototype.initialize.call(this, this._boundsToLatLngs(latLngBounds), options);
|
||||
},
|
||||
|
||||
setBounds: function (latLngBounds) {
|
||||
this.setLatLngs([
|
||||
latLngBounds.getSouthWest(),
|
||||
latLngBounds.getNorthWest(),
|
||||
latLngBounds.getNorthEast(),
|
||||
latLngBounds.getSouthEast(),
|
||||
latLngBounds.getSouthWest()
|
||||
]);
|
||||
this.setLatLngs(this._boundsToLatLngs(latLngBounds));
|
||||
},
|
||||
|
||||
_boundsToLatLngs: function (latLngBounds) {
|
||||
return [
|
||||
latLngBounds.getSouthWest(),
|
||||
latLngBounds.getNorthWest(),
|
||||
latLngBounds.getNorthEast(),
|
||||
latLngBounds.getSouthEast(),
|
||||
latLngBounds.getSouthWest()
|
||||
];
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user