DRYing things up a bit with Rectangle.js

This commit is contained in:
Jason Sanford 2012-02-21 07:47:34 -07:00
parent 53627cab80
commit a9c1629875

View File

@ -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()
];
}
});