Skip to content

Commit

Permalink
Change function and variable name
Browse files Browse the repository at this point in the history
Switch some variable name to camel case to be coherent with Leaflet.
Change _move to _bounceMotion and _animate to _motionStep so they be
less generic.
  • Loading branch information
maximeh committed Aug 29, 2013
1 parent 73e0ee7 commit 427ea66
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions bouncemarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
return this._map.containerPointToLatLng(point);
},

_animate: function (opts) {
_motionStep: function (opts) {
var self = this;

var start = new Date();
self.id = setInterval(function () {
self.intervalId = setInterval(function () {
var timePassed = new Date() - start;
var progress = timePassed / opts.duration;
if (progress > 1) {
Expand All @@ -64,31 +64,31 @@
opts.step(delta);
if (progress === 1) {
opts.end();
clearInterval(self.id);
clearInterval(self.intervalId);
}
}, opts.delay || 10);
},

_move: function (delta, duration, callback) {
var original = L.latLng(this._orig_latlng),
start_y = this._drop_point.y,
start_x = this._drop_point.x,
_bounceMotion: function (delta, duration, callback) {
var original = L.latLng(this._origLatlng),
start_y = this._dropPoint.y,
start_x = this._dropPoint.x,
distance = this._point.y - start_y;
var self = this;

this._animate({
this._motionStep({
delay: 10,
duration: duration || 1000, // 1 sec by default
delta: delta,
step: function (delta) {
self._drop_point.y =
self._dropPoint.y =
start_y
+ (distance * delta)
- (self._map.project(self._map.getCenter()).y - self._orig_map_center.y);
self._drop_point.x =
- (self._map.project(self._map.getCenter()).y - self._origMapCenter.y);
self._dropPoint.x =
start_x
- (self._map.project(self._map.getCenter()).x - self._orig_map_center.x);
self.setLatLng(self._toLatLng(self._drop_point));
- (self._map.project(self._map.getCenter()).x - self._origMapCenter.x);
self.setLatLng(self._toLatLng(self._dropPoint));
},
end: function () {
self.setLatLng(original);
Expand All @@ -112,14 +112,14 @@

// Bounce : if options.height in pixels is not specified, drop from top.
// If options.duration is not specified animation is 1s long.
bounce: function(options, end_callback) {
this._orig_latlng = this.getLatLng();
this._bounce(options, end_callback);
bounce: function(options, endCallback) {
this._origLatlng = this.getLatLng();
this._bounce(options, endCallback);
},

_bounce: function (options, end_callback) {
_bounce: function (options, endCallback) {
if (typeof options === "function") {
end_callback = options;
endCallback = options;
options = null;
}
options = options || {duration: 1000, height: -1};
Expand All @@ -131,16 +131,16 @@
}

// Keep original map center
this._orig_map_center = this._map.project(this._map.getCenter());
this._drop_point = this._getDropPoint(options.height);
this._move(this._easeOutBounce, options.duration, end_callback);
this._origMapCenter = this._map.project(this._map.getCenter());
this._dropPoint = this._getDropPoint(options.height);
this._bounceMotion(this._easeOutBounce, options.duration, endCallback);
},

// This will get you a drop point given a height.
// If no height is given, the top y will be used.
_getDropPoint: function (height) {
// Get current coordidates in pixel
this._point = this._toPoint(this._orig_latlng);
this._point = this._toPoint(this._origLatlng);
var top_y;
if (height === undefined || height < 0) {
top_y = this._toPoint(this._map.getBounds()._northEast).y;
Expand All @@ -153,7 +153,7 @@
onAdd: function (map) {
this._map = map;
// Keep original latitude and longitude
this._orig_latlng = this._latlng;
this._origLatlng = this._latlng;

// We need to have our drop point BEFORE adding the marker to the map
// otherwise, it would create a flicker. (The marker would appear at final
Expand All @@ -169,8 +169,8 @@
this.options.bounceOnAddOptions.height = this.options.bounceOnAddHeight;
}

this._drop_point = this._getDropPoint(this.options.bounceOnAddOptions.height);
this.setLatLng(this._toLatLng(this._drop_point));
this._dropPoint = this._getDropPoint(this.options.bounceOnAddOptions.height);
this.setLatLng(this._toLatLng(this._dropPoint));
}

// Call leaflet original method to add the Marker to the map.
Expand All @@ -182,7 +182,7 @@
},

onRemove: function (map) {
clearInterval(this.id);
clearInterval(this.intervalId);
originalOnRemove.call(this, map);
}
});
Expand Down

0 comments on commit 427ea66

Please sign in to comment.