Permalink
Browse files

Improve method chaining by returning this from most Map methods.

  • Loading branch information...
Tom MacWright
Tom MacWright committed Apr 15, 2011
1 parent 4e7c6b6 commit 061f056adaf33313d4a2421aee741b72aabfa474
Showing with 31 additions and 19 deletions.
  1. +15 −9 modestmaps.js
  2. +1 −1 modestmaps.min.js
  3. +15 −9 src/map.js
View
@@ -1088,17 +1088,18 @@ if (!com) {
this.coordinate = this.coordinate.zoomBy(zoomOffset);
this.draw();
this.dispatchCallback('zoomed', zoomOffset);
+ return this;
},
- zoomIn: function() { this.zoomBy(1); },
- zoomOut: function() { this.zoomBy(-1); },
- setZoom: function(z) { this.zoomBy(z - this.coordinate.zoom); },
+ zoomIn: function() { return this.zoomBy(1); },
+ zoomOut: function() { return this.zoomBy(-1); },
+ setZoom: function(z) { return this.zoomBy(z - this.coordinate.zoom); },
zoomByAbout: function(zoomOffset, point) {
var location = this.pointLocation(point);
this.zoomBy(zoomOffset);
var newPoint = this.locationPoint(location);
- this.panBy(point.x - newPoint.x, point.y - newPoint.y);
+ return this.panBy(point.x - newPoint.x, point.y - newPoint.y);
},
// panning
@@ -1108,23 +1109,25 @@ if (!com) {
this.coordinate.row -= dy / this.provider.tileHeight;
this.draw();
this.dispatchCallback('panned', [dx, dy]);
+ return this;
},
- panLeft: function() { this.panBy(100,0); },
- panRight: function() { this.panBy(-100,0); },
- panDown: function() { this.panBy(0,-100); },
- panUp: function() { this.panBy(0,100); },
+ panLeft: function() { return this.panBy(100,0); },
+ panRight: function() { return this.panBy(-100,0); },
+ panDown: function() { return this.panBy(0,-100); },
+ panUp: function() { return this.panBy(0,100); },
// positioning
setCenter: function(location) {
- this.setCenterZoom(location, this.coordinate.zoom);
+ return this.setCenterZoom(location, this.coordinate.zoom);
},
setCenterZoom: function(location, zoom) {
this.coordinate = this.provider.locationCoordinate(location).zoomTo(parseFloat(zoom) || 0);
this.draw();
this.dispatchCallback('centered', [location, zoom]);
+ return this;
},
setExtent: function(locations) {
@@ -1184,6 +1187,7 @@ if (!com) {
this.draw();
this.dispatchCallback('extentset', locations);
+ return this;
},
// map dimensions
@@ -1199,6 +1203,7 @@ if (!com) {
this.parent.style.height = Math.round(this.dimensions.y) + 'px';
this.draw();
this.dispatchCallback('resized', [ this.dimensions ]);
+ return this;
},
// projecting points on and off screen
@@ -1301,6 +1306,7 @@ if (!com) {
if (!firstProvider) {
this.draw();
}
+ return this;
},
// stats
Oops, something went wrong.

0 comments on commit 061f056

Please sign in to comment.