Permalink
Browse files

Merge branch 'master' of github.com:openlayers/ol3 into vector

  • Loading branch information...
2 parents 65b3bb7 + a64e4ae commit 1ecbc36a39695df29e1c3c8246b716801cffb6a0 @ahocevar ahocevar committed Jan 30, 2013
View
@@ -85,6 +85,9 @@ def report_sizes(t):
virtual('build', 'build/ol.css', 'build/ol.js')
+virtual('todo', 'fixme')
+
+
@target('build/ol.css', 'build/ol.js')
def build_ol_css(t):
t.touch()
@@ -247,6 +250,27 @@ def hostexamples(t):
def test(t):
t.run('%(PHANTOMJS)s', 'test/phantom-jasmine/run_jasmine_test.coffee', 'test/ol.html')
+@target('fixme', phony=True)
+def find_fixme(t):
+ regex = re.compile(".(FIXME|TODO).")
+ matches = dict()
+ totalcount = 0
+ for filename in SRC:
+ f = open(filename, 'r')
+ for lineno, line in enumerate(f):
+ if regex.search(line):
+ if (filename not in matches):
+ matches[filename] = list()
+ matches[filename].append("#" + str(lineno + 1).ljust(10) + line.strip())
+ totalcount += 1
+ f.close()
+
+ for filename in matches:
+ print " ", filename, "has", len(matches[filename]), "matches:"
+ for match in matches[filename]:
+ print " ", match
+ print
+ print "A total number of", totalcount, "TODO/FIXME was found"
if __name__ == '__main__':
main()
View
@@ -19,9 +19,6 @@
display: inline;
list-style: none;
}
-.ol-attribution li {
- display: inline;
-}
.ol-attribution li:not(:last-child):after {
content: "\2003";
}
View
@@ -33,7 +33,7 @@ You can turn off compilation by appending `?mode=RAW` to the URL, for example
Run the plovr web server (see above), and either open the `test/ol.html` file
in the browser (e.g. <http://localhost:8000/test/ol.html>), or run `./build.py test`
-on the console (headless testing with PhantomJS).
+on the console (headless testing with PhantomJS, make sure to install it first from http://phantomjs.org/download.html).
See also the test-specific [readme](https://github.com/openlayers/ol3/tree/master/test).
@@ -45,6 +45,10 @@ Then:
$ ./build.py lint
+## Run the precommit hook before pushing a commit:
+
+ $ ./build.py precommit
+
## Add examples
The examples are located in the `examples` directory. Adding a new example
View
@@ -15,5 +15,6 @@ ol.BrowserFeature = {
* @type {boolean} True if browser supports touch events
*/
HAS_TOUCH: ol.ASSUME_TOUCH ||
- (document && 'ontouchstart' in document.documentElement)
+ (document && 'ontouchstart' in document.documentElement) ||
+ !!(window.navigator.msPointerEnabled)
};
@@ -24,7 +24,7 @@ ol.control.Attribution = function(attributionOptions) {
this.ulElement_ = goog.dom.createElement(goog.dom.TagName.UL);
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
- 'class': 'ol-attribution'
+ 'class': 'ol-attribution ol-unselectable'
}, this.ulElement_);
goog.base(this, {
@@ -81,6 +81,13 @@ ol.interaction.Drag.prototype.handleDragStart = goog.functions.FALSE;
/**
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
+ * @protected
+ */
+ol.interaction.Drag.prototype.handleDown = goog.nullFunction;
+
+
+/**
* @inheritDoc
*/
ol.interaction.Drag.prototype.handleMapBrowserEvent =
@@ -91,6 +98,10 @@ ol.interaction.Drag.prototype.handleMapBrowserEvent =
}
var view = map.getView();
var browserEvent = mapBrowserEvent.browserEvent;
+ if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DOWN) {
+ goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
+ this.handleDown(mapBrowserEvent);
+ }
if (this.dragging_) {
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DRAG) {
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
@@ -16,8 +16,9 @@ goog.require('ol.interaction.Drag');
* @constructor
* @extends {ol.interaction.Drag}
* @param {ol.interaction.ConditionType} condition Condition.
+ * @param {ol.Kinetic=} opt_kinetic Kinetic object.
*/
-ol.interaction.DragPan = function(condition) {
+ol.interaction.DragPan = function(condition, opt_kinetic) {
goog.base(this);
@@ -27,6 +28,18 @@ ol.interaction.DragPan = function(condition) {
*/
this.condition_ = condition;
+ /**
+ * @private
+ * @type {ol.Kinetic|undefined}
+ */
+ this.kinetic_ = opt_kinetic;
+
+ /**
+ * @private
+ * @type {?ol.PreRenderFunction}
+ */
+ this.kineticPreRenderFn_ = null;
+
};
goog.inherits(ol.interaction.DragPan, ol.interaction.Drag);
@@ -35,6 +48,9 @@ goog.inherits(ol.interaction.DragPan, ol.interaction.Drag);
* @inheritDoc
*/
ol.interaction.DragPan.prototype.handleDrag = function(mapBrowserEvent) {
+ if (this.kinetic_) {
+ this.kinetic_.update(mapBrowserEvent.browserEvent);
+ }
var map = mapBrowserEvent.map;
// FIXME works for View2D only
var view = map.getView();
@@ -55,9 +71,27 @@ ol.interaction.DragPan.prototype.handleDrag = function(mapBrowserEvent) {
* @inheritDoc
*/
ol.interaction.DragPan.prototype.handleDragEnd = function(mapBrowserEvent) {
+
+ // FIXME works for View2D only
+
var map = mapBrowserEvent.map;
- map.requestRenderFrame();
- map.getView().setHint(ol.ViewHint.PANNING, -1);
+ var view = map.getView();
+ view.setHint(ol.ViewHint.PANNING, -1);
+
+ if (this.kinetic_ && this.kinetic_.end()) {
+ var distance = this.kinetic_.getDistance();
+ var angle = this.kinetic_.getAngle();
+ var center = view.getCenter();
+ this.kineticPreRenderFn_ = this.kinetic_.createPanFrom(center);
+ map.addPreRenderFunction(this.kineticPreRenderFn_);
+
+ var centerpx = map.getPixelFromCoordinate(center);
+ var destpx = new ol.Pixel(
+ centerpx.x - distance * Math.cos(angle),
+ centerpx.y - distance * Math.sin(angle));
+ var dest = map.getCoordinateFromPixel(destpx);
+ view.setCenter(dest);
+ }
};
@@ -67,6 +101,9 @@ ol.interaction.DragPan.prototype.handleDragEnd = function(mapBrowserEvent) {
ol.interaction.DragPan.prototype.handleDragStart = function(mapBrowserEvent) {
var browserEvent = mapBrowserEvent.browserEvent;
if (this.condition_(browserEvent)) {
+ if (this.kinetic_) {
+ this.kinetic_.begin(browserEvent);
+ }
var map = mapBrowserEvent.map;
map.requestRenderFrame();
map.getView().setHint(ol.ViewHint.PANNING, 1);
@@ -75,3 +112,21 @@ ol.interaction.DragPan.prototype.handleDragStart = function(mapBrowserEvent) {
return false;
}
};
+
+
+/**
+ * @inheritDoc
+ */
+ol.interaction.DragPan.prototype.handleDown = function(mapBrowserEvent) {
+ var map = mapBrowserEvent.map;
+ // FIXME works for View2D only
+ var view = map.getView();
+ goog.asserts.assert(view instanceof ol.View2D);
+ goog.asserts.assert(!goog.isNull(mapBrowserEvent.frameState));
+ if (!goog.isNull(this.kineticPreRenderFn_) &&
+ map.removePreRenderFunction(this.kineticPreRenderFn_)) {
+ map.requestRenderFrame();
+ view.setCenter(mapBrowserEvent.frameState.view2DState.center);
+ this.kineticPreRenderFn_ = null;
+ }
+};
View
@@ -0,0 +1,154 @@
+
+goog.provide('ol.Kinetic');
+
+goog.require('goog.array');
+goog.require('ol.Pixel');
+goog.require('ol.animation');
+
+
+/**
+ * @typedef {{x: number,
+ * y: number,
+ * t: number}}
+ */
+ol.KineticPoint;
+
+
+
+/**
+ * @constructor
+ * @param {number} decay Rate of decay (must be negative).
+ * @param {number} minVelocity Minimum velocity (pixels/millisecond).
+ * @param {number} delay Delay to consider to calculate the kinetic
+ * initial values (milliseconds).
+ */
+ol.Kinetic = function(decay, minVelocity, delay) {
+
+ /**
+ * @private
+ * @type {number}
+ */
+ this.decay_ = decay;
+
+ /**
+ * @private
+ * @type {number}
+ */
+ this.minVelocity_ = minVelocity;
+
+ /**
+ * @private
+ * @type {number}
+ */
+ this.delay_ = delay;
+
+ /**
+ * @private
+ * @type {Array.<ol.KineticPoint>}
+ */
+ this.points_ = [];
+
+ /**
+ * @private
+ * @type {number}
+ */
+ this.angle_ = 0;
+
+ /**
+ * @private
+ * @type {number}
+ */
+ this.initialVelocity_ = 0;
+};
+
+
+/**
+ * @param {goog.events.BrowserEvent} browserEvent Browser event.
+ */
+ol.Kinetic.prototype.begin = function(browserEvent) {
+ this.points_.length = 0;
+ this.angle_ = 0;
+ this.initialVelocity_ = 0;
+ this.update(browserEvent);
+};
+
+
+/**
+ * @param {goog.events.BrowserEvent} browserEvent Browser event.
+ */
+ol.Kinetic.prototype.update = function(browserEvent) {
+ this.points_.push({
+ x: browserEvent.clientX,
+ y: browserEvent.clientY,
+ t: goog.now()
+ });
+};
+
+
+/**
+ * @return {boolean} Whether we should do kinetic animation.
+ */
+ol.Kinetic.prototype.end = function() {
+ var now = goog.now();
+ var lastIndex = this.points_.length - 1;
+ var firstIndex = lastIndex - 1;
+ while (firstIndex >= 0 && this.points_[firstIndex].t > now - this.delay_) {
+ firstIndex--;
+ }
+ if (firstIndex >= 0) {
+ var first = this.points_[firstIndex];
+ var last = this.points_[lastIndex];
+ var dx = last.x - first.x;
+ var dy = last.y - first.y;
+ this.angle_ = Math.atan2(dy, dx);
+ this.initialVelocity_ = Math.sqrt(dx * dx + dy * dy) / (last.t - first.t);
+ return this.initialVelocity_ > this.minVelocity_;
+ }
+ return false;
+};
+
+
+/**
+ * @param {ol.Coordinate} source Source coordinate for the animation.
+ * @return {ol.PreRenderFunction} Pre-render function for kinetic animation.
+ */
+ol.Kinetic.prototype.createPanFrom = function(source) {
+ var decay = this.decay_;
+ var initialVelocity = this.initialVelocity_;
+ var minVelocity = this.minVelocity_;
+ var duration = this.getDuration_();
+ var easingFunction = function(t) {
+ return initialVelocity * (Math.exp((decay * t) * duration) - 1) /
+ (minVelocity - initialVelocity);
+ };
+ return ol.animation.createPanFrom({
+ source: source,
+ duration: duration,
+ easing: easingFunction
+ });
+};
+
+
+/**
+ * @private
+ * @return {number} Duration of animation (milliseconds).
+ */
+ol.Kinetic.prototype.getDuration_ = function() {
+ return Math.log(this.minVelocity_ / this.initialVelocity_) / this.decay_;
+};
+
+
+/**
+ * @return {number} Total distance travelled (pixels).
+ */
+ol.Kinetic.prototype.getDistance = function() {
+ return (this.minVelocity_ - this.initialVelocity_) / this.decay_;
+};
+
+
+/**
+ * @return {number} Angle of the kinetic panning animation (radians).
+ */
+ol.Kinetic.prototype.getAngle = function() {
+ return this.angle_;
+};
Oops, something went wrong.

0 comments on commit 1ecbc36

Please sign in to comment.