From baf8cc49a165c27c28d6caa458665daedbd621d2 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:17:11 +0200 Subject: [PATCH 01/19] Avoid generating long lines in exports --- bin/generate-exports.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/generate-exports.py b/bin/generate-exports.py index 64b4a67de1..e2f0eca521 100755 --- a/bin/generate-exports.py +++ b/bin/generate-exports.py @@ -111,7 +111,9 @@ class Class(Exportable): lines.append(' }\n') lines.append(' goog.base(this, arg);\n') lines.append('};\n') - lines.append('goog.inherits(%sExport, %s);\n' % (self.name, self.name)) + lines.append('goog.inherits(\n') + lines.append(' %sExport,\n' % (self.name,)); + lines.append(' %s);\n' % (self.name,)); lines.append('goog.exportSymbol(\n') lines.append(' \'%s\',\n' % (self.name,)) lines.append(' %s);\n' % (self.export_name(),)) From a4d8e1c4d86ac16919dc01b9085a793a62c07d1e Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:18:33 +0200 Subject: [PATCH 02/19] Correct property in ol.interaction.DefaultsOptions --- src/objectliterals.jsdoc | 2 ++ src/ol/interaction/interactiondefaults.js | 6 +++--- test/spec/ol/map.test.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 03b42ccef8..d71f39e2df 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -167,6 +167,8 @@ /** * Interactions for the map. Default is true for all options. * @typedef {Object} ol.interaction.DefaultsOptions + * @property {boolean|undefined} altShiftDragRotate Whether Alt-Shift-drag + * rotate is desired. * @property {boolean|undefined} doubleClickZoom Whether double click zoom is * desired. * @property {boolean|undefined} dragPan Whether drag-pan is desired. diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index 024399f4e0..0ad6ee5e78 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -28,9 +28,9 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var interactions = new ol.Collection(); - var rotate = goog.isDef(options.rotate) ? - options.rotate : true; - if (rotate) { + var altShiftDragRotate = goog.isDef(options.altShiftDragRotate) ? + options.altShiftDragRotate : true; + if (altShiftDragRotate) { interactions.push(new ol.interaction.DragRotate( ol.interaction.condition.altShiftKeysOnly)); } diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js index 8fea115322..c4d702b284 100644 --- a/test/spec/ol/map.test.js +++ b/test/spec/ol/map.test.js @@ -72,7 +72,7 @@ describe('ol.Map', function() { beforeEach(function() { options = { - rotate: false, + altShiftDragRotate: false, doubleClickZoom: false, dragPan: false, keyboard: false, From f2836ea111a19bc8be86b4788a9fc0b39c776a56 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:20:45 +0200 Subject: [PATCH 03/19] Configure ol.interaction.DblClickZoom with options --- src/objectliterals.jsdoc | 7 +++++++ src/ol/interaction/dblclickzoominteraction.js | 10 +++++++--- src/ol/interaction/interactiondefaults.js | 6 +++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index d71f39e2df..a802fa16cf 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -164,6 +164,12 @@ * @property {number|undefined} minResolution Minimum resolution. */ +/** + * @typedef {Object} ol.interaction.DblClickZoomOptions + * @property {number|undefined} delta The zoom delta applied on each double + * click. + */ + /** * Interactions for the map. Default is true for all options. * @typedef {Object} ol.interaction.DefaultsOptions @@ -182,6 +188,7 @@ * desired. * @property {boolean|undefined} touchRotate Whether touch rotate is desired. * @property {boolean|undefined} touchZoom Whether touch zoom is desired. + * @property {number|undefined} zoomDelta Zoom delta. */ /** diff --git a/src/ol/interaction/dblclickzoominteraction.js b/src/ol/interaction/dblclickzoominteraction.js index 24d28b84da..3e8e1d2932 100644 --- a/src/ol/interaction/dblclickzoominteraction.js +++ b/src/ol/interaction/dblclickzoominteraction.js @@ -18,16 +18,20 @@ ol.interaction.DBLCLICKZOOM_ANIMATION_DURATION = 250; /** * @constructor * @extends {ol.interaction.Interaction} - * @param {number} delta The zoom delta applied on each double click. + * @param {ol.interaction.DblClickZoomOptions=} opt_options Options. */ -ol.interaction.DblClickZoom = function(delta) { +ol.interaction.DblClickZoom = function(opt_options) { + + var options = goog.isDef(opt_options) ? opt_options : {}; + /** * @private * @type {number} */ - this.delta_ = delta; + this.delta_ = goog.isDef(options.delta) ? options.delta : 1; goog.base(this); + }; goog.inherits(ol.interaction.DblClickZoom, ol.interaction.Interaction); diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index 0ad6ee5e78..e3023b492e 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -38,9 +38,9 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var doubleClickZoom = goog.isDef(options.doubleClickZoom) ? options.doubleClickZoom : true; if (doubleClickZoom) { - var zoomDelta = goog.isDef(options.zoomDelta) ? - options.zoomDelta : 1; - interactions.push(new ol.interaction.DblClickZoom(zoomDelta)); + interactions.push(new ol.interaction.DblClickZoom({ + delta: options.zoomDelta + })); } var touchPan = goog.isDef(options.touchPan) ? From eb9f6c027bfa231ffb7d9e14e02398e8bf1ac040 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:28:14 +0200 Subject: [PATCH 04/19] Avoid duplicate property lookup --- src/ol/interaction/dblclickzoominteraction.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ol/interaction/dblclickzoominteraction.js b/src/ol/interaction/dblclickzoominteraction.js index 3e8e1d2932..49efbd3ae7 100644 --- a/src/ol/interaction/dblclickzoominteraction.js +++ b/src/ol/interaction/dblclickzoominteraction.js @@ -46,8 +46,7 @@ ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent = mapBrowserEvent.isMouseActionButton()) { var map = mapBrowserEvent.map; var anchor = mapBrowserEvent.getCoordinate(); - var delta = mapBrowserEvent.browserEvent.shiftKey ? - -this.delta_ : this.delta_; + var delta = browserEvent.shiftKey ? -this.delta_ : this.delta_; // FIXME works for View2D only var view = map.getView().getView2D(); ol.interaction.Interaction.zoomByDelta(map, view, delta, anchor, From ef17d4f3b80ba09ecebe3b2e1264788f5664ba76 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:33:48 +0200 Subject: [PATCH 05/19] Rename DblClickZoom to DoubleClickZoom --- src/objectliterals.jsdoc | 2 +- ...nteraction.js => doubleclickzoominteraction.js} | 14 +++++++------- src/ol/interaction/interactiondefaults.js | 4 ++-- test/spec/ol/map.test.js | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) rename src/ol/interaction/{dblclickzoominteraction.js => doubleclickzoominteraction.js} (71%) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index a802fa16cf..9668d01d99 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -165,7 +165,7 @@ */ /** - * @typedef {Object} ol.interaction.DblClickZoomOptions + * @typedef {Object} ol.interaction.DoubleClickZoomOptions * @property {number|undefined} delta The zoom delta applied on each double * click. */ diff --git a/src/ol/interaction/dblclickzoominteraction.js b/src/ol/interaction/doubleclickzoominteraction.js similarity index 71% rename from src/ol/interaction/dblclickzoominteraction.js rename to src/ol/interaction/doubleclickzoominteraction.js index 49efbd3ae7..1d9a087e7d 100644 --- a/src/ol/interaction/dblclickzoominteraction.js +++ b/src/ol/interaction/doubleclickzoominteraction.js @@ -1,6 +1,6 @@ // FIXME works for View2D only -goog.provide('ol.interaction.DblClickZoom'); +goog.provide('ol.interaction.DoubleClickZoom'); goog.require('goog.asserts'); goog.require('ol.MapBrowserEvent'); @@ -11,16 +11,16 @@ goog.require('ol.interaction.Interaction'); /** * @define {number} Animation duration. */ -ol.interaction.DBLCLICKZOOM_ANIMATION_DURATION = 250; +ol.interaction.DOUBLECLICKZOOM_ANIMATION_DURATION = 250; /** * @constructor * @extends {ol.interaction.Interaction} - * @param {ol.interaction.DblClickZoomOptions=} opt_options Options. + * @param {ol.interaction.DoubleClickZoomOptions=} opt_options Options. */ -ol.interaction.DblClickZoom = function(opt_options) { +ol.interaction.DoubleClickZoom = function(opt_options) { var options = goog.isDef(opt_options) ? opt_options : {}; @@ -33,13 +33,13 @@ ol.interaction.DblClickZoom = function(opt_options) { goog.base(this); }; -goog.inherits(ol.interaction.DblClickZoom, ol.interaction.Interaction); +goog.inherits(ol.interaction.DoubleClickZoom, ol.interaction.Interaction); /** * @inheritDoc */ -ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent = +ol.interaction.DoubleClickZoom.prototype.handleMapBrowserEvent = function(mapBrowserEvent) { var browserEvent = mapBrowserEvent.browserEvent; if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK && @@ -50,7 +50,7 @@ ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent = // FIXME works for View2D only var view = map.getView().getView2D(); ol.interaction.Interaction.zoomByDelta(map, view, delta, anchor, - ol.interaction.DBLCLICKZOOM_ANIMATION_DURATION); + ol.interaction.DOUBLECLICKZOOM_ANIMATION_DURATION); mapBrowserEvent.preventDefault(); browserEvent.preventDefault(); } diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index e3023b492e..f1f26a1069 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -2,7 +2,7 @@ goog.provide('ol.interaction.defaults'); goog.require('ol.Collection'); goog.require('ol.Kinetic'); -goog.require('ol.interaction.DblClickZoom'); +goog.require('ol.interaction.DoubleClickZoom'); goog.require('ol.interaction.DragPan'); goog.require('ol.interaction.DragRotate'); goog.require('ol.interaction.DragZoom'); @@ -38,7 +38,7 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var doubleClickZoom = goog.isDef(options.doubleClickZoom) ? options.doubleClickZoom : true; if (doubleClickZoom) { - interactions.push(new ol.interaction.DblClickZoom({ + interactions.push(new ol.interaction.DoubleClickZoom({ delta: options.zoomDelta })); } diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js index c4d702b284..e99d3ee857 100644 --- a/test/spec/ol/map.test.js +++ b/test/spec/ol/map.test.js @@ -103,7 +103,7 @@ describe('ol.Map', function() { it('create double click interaction with default delta', function() { var interactions = ol.interaction.defaults(options); expect(interactions.getLength()).to.eql(1); - expect(interactions.getAt(0)).to.be.a(ol.interaction.DblClickZoom); + expect(interactions.getAt(0)).to.be.a(ol.interaction.DoubleClickZoom); expect(interactions.getAt(0).delta_).to.eql(1); }); }); @@ -113,7 +113,7 @@ describe('ol.Map', function() { options.zoomDelta = 7; var interactions = ol.interaction.defaults(options); expect(interactions.getLength()).to.eql(1); - expect(interactions.getAt(0)).to.be.a(ol.interaction.DblClickZoom); + expect(interactions.getAt(0)).to.be.a(ol.interaction.DoubleClickZoom); expect(interactions.getAt(0).delta_).to.eql(7); }); }); @@ -127,6 +127,6 @@ goog.require('goog.dom'); goog.require('ol.Map'); goog.require('ol.RendererHint'); goog.require('ol.RendererHints'); -goog.require('ol.interaction.DblClickZoom'); +goog.require('ol.interaction.DoubleClickZoom'); goog.require('ol.interaction.MouseWheelZoom'); goog.require('ol.interaction.defaults'); From 003ac5536e130582170ee8e32183729ea6a0f87a Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:44:53 +0200 Subject: [PATCH 06/19] Configure ol.interaction.DragRotate with options --- src/objectliterals.jsdoc | 5 +++++ src/ol/interaction/dragrotateinteraction.js | 10 +++++++--- src/ol/interaction/interactiondefaults.js | 3 +-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 9668d01d99..2c955719c8 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -170,6 +170,11 @@ * click. */ +/** + * @typedef {Object} ol.interaction.DragRotateOptions + * @property {ol.interaction.ConditionType|undefined} condition Condition. + */ + /** * Interactions for the map. Default is true for all options. * @typedef {Object} ol.interaction.DefaultsOptions diff --git a/src/ol/interaction/dragrotateinteraction.js b/src/ol/interaction/dragrotateinteraction.js index e922a31454..681c86c654 100644 --- a/src/ol/interaction/dragrotateinteraction.js +++ b/src/ol/interaction/dragrotateinteraction.js @@ -6,6 +6,7 @@ goog.require('ol.ViewHint'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Drag'); goog.require('ol.interaction.Interaction'); +goog.require('ol.interaction.condition'); /** @@ -18,9 +19,11 @@ ol.interaction.DRAGROTATE_ANIMATION_DURATION = 250; /** * @constructor * @extends {ol.interaction.Drag} - * @param {ol.interaction.ConditionType} condition Condition. + * @param {ol.interaction.DragRotateOptions=} opt_options Options. */ -ol.interaction.DragRotate = function(condition) { +ol.interaction.DragRotate = function(opt_options) { + + var options = goog.isDef(opt_options) ? opt_options : {}; goog.base(this); @@ -28,7 +31,8 @@ ol.interaction.DragRotate = function(condition) { * @private * @type {ol.interaction.ConditionType} */ - this.condition_ = condition; + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.altShiftKeysOnly; /** * @private diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index f1f26a1069..077bbd1fab 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -31,8 +31,7 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var altShiftDragRotate = goog.isDef(options.altShiftDragRotate) ? options.altShiftDragRotate : true; if (altShiftDragRotate) { - interactions.push(new ol.interaction.DragRotate( - ol.interaction.condition.altShiftKeysOnly)); + interactions.push(new ol.interaction.DragRotate()); } var doubleClickZoom = goog.isDef(options.doubleClickZoom) ? From d90f292c7170e437d8961ee28051e45a809fe1ed Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:45:11 +0200 Subject: [PATCH 07/19] Initialize all properties in constructor --- src/ol/interaction/dragrotateinteraction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/interaction/dragrotateinteraction.js b/src/ol/interaction/dragrotateinteraction.js index 681c86c654..60dfa35258 100644 --- a/src/ol/interaction/dragrotateinteraction.js +++ b/src/ol/interaction/dragrotateinteraction.js @@ -38,7 +38,7 @@ ol.interaction.DragRotate = function(opt_options) { * @private * @type {number|undefined} */ - this.lastAngle_; + this.lastAngle_ = undefined; }; goog.inherits(ol.interaction.DragRotate, ol.interaction.Drag); From 8d29bf3c2021a9f4d5572d3243d0d6981208c5fa Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:46:09 +0200 Subject: [PATCH 08/19] Add ol.interaction.condition.always --- src/ol/interaction/condition.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ol/interaction/condition.js b/src/ol/interaction/condition.js index 3644843ddc..c0831f38ec 100644 --- a/src/ol/interaction/condition.js +++ b/src/ol/interaction/condition.js @@ -1,6 +1,8 @@ goog.provide('ol.interaction.ConditionType'); goog.provide('ol.interaction.condition'); +goog.require('goog.functions'); + /** * @typedef {function(goog.events.BrowserEvent): boolean} @@ -32,6 +34,13 @@ ol.interaction.condition.altShiftKeysOnly = function(browserEvent) { }; +/** + * @param {goog.events.BrowserEvent} browserEvent Browser event. + * @return {boolean} True. + */ +ol.interaction.condition.always = goog.functions.TRUE; + + /** * @param {goog.events.BrowserEvent} browserEvent Browser event. * @return {boolean} True if only the no modifier keys are pressed. From 75ac8a484704a076e7a14692725b2cfa38c0d138 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 14:46:24 +0200 Subject: [PATCH 09/19] Export ol.interaction.condition.* --- src/ol/interaction/condition.exports | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/ol/interaction/condition.exports diff --git a/src/ol/interaction/condition.exports b/src/ol/interaction/condition.exports new file mode 100644 index 0000000000..d9a0595be0 --- /dev/null +++ b/src/ol/interaction/condition.exports @@ -0,0 +1,6 @@ +@exportSymbol ol.interaction.condition.altKeyOnly +@exportSymbol ol.interaction.condition.altShiftKeysOnly +@exportSymbol ol.interaction.condition.always +@exportSymbol ol.interaction.condition.noModifierKeys +@exportSymbol ol.interaction.condition.platformModifierKeyOnly +@exportSymbol ol.interaction.condition.shiftKeyOnly From 76a9f805452406b832a87963c8ff57e3c1379b6d Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 15:16:59 +0200 Subject: [PATCH 10/19] Update ol.interaction.DragRotateAndZoom --- src/objectliterals.jsdoc | 5 ++ .../dragrotateandzoominteraction.js | 49 ++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 2c955719c8..8450016ed5 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -175,6 +175,11 @@ * @property {ol.interaction.ConditionType|undefined} condition Condition. */ +/** + * @typedef {Object} ol.interaction.DragRotateAndZoomOptions + * @property {ol.interaction.ConditionType|undefined} condition Condition. + */ + /** * Interactions for the map. Default is true for all options. * @typedef {Object} ol.interaction.DefaultsOptions diff --git a/src/ol/interaction/dragrotateandzoominteraction.js b/src/ol/interaction/dragrotateandzoominteraction.js index 4e67f01c27..f19ca10e7d 100644 --- a/src/ol/interaction/dragrotateandzoominteraction.js +++ b/src/ol/interaction/dragrotateandzoominteraction.js @@ -7,15 +7,24 @@ goog.require('goog.math.Vec2'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Drag'); goog.require('ol.interaction.Interaction'); +goog.require('ol.interaction.condition'); + + +/** + * @define {number} Animation duration. + */ +ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION = 400; /** * @constructor * @extends {ol.interaction.Drag} - * @param {ol.interaction.ConditionType} condition Condition. + * @param {ol.interaction.DragRotateAndZoomOptions=} opt_options Options. */ -ol.interaction.DragRotateAndZoom = function(condition) { +ol.interaction.DragRotateAndZoom = function(opt_options) { + + var options = goog.isDef(opt_options) ? opt_options : {}; goog.base(this); @@ -23,7 +32,8 @@ ol.interaction.DragRotateAndZoom = function(condition) { * @private * @type {ol.interaction.ConditionType} */ - this.condition_ = condition; + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.shiftKeyOnly; /** * @private @@ -37,6 +47,12 @@ ol.interaction.DragRotateAndZoom = function(condition) { */ this.lastMagnitude_ = undefined; + /** + * @private + * @type {number} + */ + this.lastScaleDelta_ = 0; + }; goog.inherits(ol.interaction.DragRotateAndZoom, ol.interaction.Drag); @@ -57,22 +73,41 @@ ol.interaction.DragRotateAndZoom.prototype.handleDrag = // FIXME works for View2D only var view = map.getView().getView2D(); map.requestRenderFrame(); - // FIXME the calls to map.rotate and map.zoomToResolution should use - // map.withFrozenRendering but an assertion fails :-( if (goog.isDef(this.lastAngle_)) { var angleDelta = theta - this.lastAngle_; - ol.interaction.Interaction.rotate( + ol.interaction.Interaction.rotateWithoutConstraints( map, view, view.getRotation() - angleDelta); } this.lastAngle_ = theta; if (goog.isDef(this.lastMagnitude_)) { var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); - ol.interaction.Interaction.zoom(map, view, resolution); + ol.interaction.Interaction.zoomWithoutConstraints(map, view, resolution); + } + if (goog.isDef(this.lastMagnitude_)) { + this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; } this.lastMagnitude_ = magnitude; }; +/** + * @inheritDoc + */ +ol.interaction.DragRotateAndZoom.prototype.handleDragEnd = + function(mapBrowserEvent) { + var map = mapBrowserEvent.map; + var view = map.getView().getView2D(); + var direction = this.lastScaleDelta_ - 1; + map.withFrozenRendering(function() { + ol.interaction.Interaction.rotate(map, view, view.getRotation()); + ol.interaction.Interaction.zoom(map, view, view.getResolution(), undefined, + ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION, direction); + }); + this.lastScaleDelta_ = 0; + return true; +}; + + /** * @inheritDoc */ From 808de79d16902625f18ed097a587564bf845384f Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 15:17:17 +0200 Subject: [PATCH 11/19] Export ol.interaction.DragRotateAndZoom --- src/ol/interaction/dragrotateandzoom.exports | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/ol/interaction/dragrotateandzoom.exports diff --git a/src/ol/interaction/dragrotateandzoom.exports b/src/ol/interaction/dragrotateandzoom.exports new file mode 100644 index 0000000000..c217fc5a82 --- /dev/null +++ b/src/ol/interaction/dragrotateandzoom.exports @@ -0,0 +1 @@ +@exportClass ol.interaction.DragRotateAndZoom ol.interaction.DragRotateAndZoomOptions From d1b2e4e483934a6d9d8f5e951ffb6f4484643c44 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 15:18:44 +0200 Subject: [PATCH 12/19] Add drag rotate and zoom example --- examples/drag-rotate-and-zoom.html | 55 ++++++++++++++++++++++++++++++ examples/drag-rotate-and-zoom.js | 25 ++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 examples/drag-rotate-and-zoom.html create mode 100644 examples/drag-rotate-and-zoom.js diff --git a/examples/drag-rotate-and-zoom.html b/examples/drag-rotate-and-zoom.html new file mode 100644 index 0000000000..c965216399 --- /dev/null +++ b/examples/drag-rotate-and-zoom.html @@ -0,0 +1,55 @@ + + + + + + + + + + Drag rotate and zoom example + + + + + +
+ +
+
+
+
+
+ +
+ +
+

Drag rotate and zoom example

+

Shift + Drag to rotate and zoom the map around its center.

+
+

See the drag-rotate-and-zoom.js source to see how this is done.

+
+
drag, rotate, zoom, interaction
+
+ +
+ +
+ + + + + + diff --git a/examples/drag-rotate-and-zoom.js b/examples/drag-rotate-and-zoom.js new file mode 100644 index 0000000000..65a7b94768 --- /dev/null +++ b/examples/drag-rotate-and-zoom.js @@ -0,0 +1,25 @@ +goog.require('ol.Map'); +goog.require('ol.RendererHints'); +goog.require('ol.View2D'); +goog.require('ol.interaction.DragRotateAndZoom'); +goog.require('ol.interaction.defaults'); +goog.require('ol.layer.TileLayer'); +goog.require('ol.source.MapQuestOpenAerial'); + + +var map = new ol.Map({ + interactions: ol.interaction.defaults({}, [ + new ol.interaction.DragRotateAndZoom() + ]), + layers: [ + new ol.layer.TileLayer({ + source: new ol.source.MapQuestOpenAerial() + }) + ], + renderers: ol.RendererHints.createFromQueryData(), + target: 'map', + view: new ol.View2D({ + center: [0, 0], + zoom: 2 + }) +}); From cc33727fad9784062561da65df720f995c4d5a15 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 15:33:25 +0200 Subject: [PATCH 13/19] Configure ol.interaction.KeyboardPan with options --- src/objectliterals.jsdoc | 1 + src/ol/interaction/interactiondefaults.js | 3 +-- src/ol/interaction/keyboardpaninteraction.js | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 8450016ed5..6d8a2ee656 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -203,6 +203,7 @@ /** * @typedef {Object} ol.interaction.KeyboardPanOptions + * @property {ol.interaction.ConditionType|undefined} condition Condition. * @property {number|undefined} pixelDelta Pixel delta */ diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index 077bbd1fab..52a2acbf38 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -72,8 +72,7 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var keyboard = goog.isDef(options.keyboard) ? options.keyboard : true; if (keyboard) { - interactions.push(new ol.interaction.KeyboardPan( - ol.interaction.condition.noModifierKeys)); + interactions.push(new ol.interaction.KeyboardPan()); interactions.push(new ol.interaction.KeyboardZoom( ol.interaction.condition.noModifierKeys)); } diff --git a/src/ol/interaction/keyboardpaninteraction.js b/src/ol/interaction/keyboardpaninteraction.js index cdea2a6ac8..d5f6fc9a93 100644 --- a/src/ol/interaction/keyboardpaninteraction.js +++ b/src/ol/interaction/keyboardpaninteraction.js @@ -9,6 +9,7 @@ goog.require('ol.View2D'); goog.require('ol.coordinate'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Interaction'); +goog.require('ol.interaction.condition'); /** @@ -21,10 +22,9 @@ ol.interaction.KEYBOARD_PAN_DURATION = 100; /** * @constructor * @extends {ol.interaction.Interaction} - * @param {ol.interaction.ConditionType} condition Condition. * @param {ol.interaction.KeyboardPanOptions=} opt_options Options. */ -ol.interaction.KeyboardPan = function(condition, opt_options) { +ol.interaction.KeyboardPan = function(opt_options) { goog.base(this); @@ -34,7 +34,8 @@ ol.interaction.KeyboardPan = function(condition, opt_options) { * @private * @type {ol.interaction.ConditionType} */ - this.condition_ = condition; + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.noModifierKeys; /** * @private From 48d455431770be01466574741c7cd9c70f23ba00 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 15:41:00 +0200 Subject: [PATCH 14/19] Configure ol.interaction.KeyboardZoom with options --- src/objectliterals.jsdoc | 1 + src/ol/interaction/interactiondefaults.js | 5 +++-- src/ol/interaction/keyboardzoominteraction.js | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 6d8a2ee656..31d3ac326c 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -209,6 +209,7 @@ /** * @typedef {Object} ol.interaction.KeyboardZoomOptions + * @property {ol.interaction.ConditionType|undefined} condition Condition. * @property {number|undefined} delta Delta. */ diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index 52a2acbf38..1e34390262 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -73,8 +73,9 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { options.keyboard : true; if (keyboard) { interactions.push(new ol.interaction.KeyboardPan()); - interactions.push(new ol.interaction.KeyboardZoom( - ol.interaction.condition.noModifierKeys)); + interactions.push(new ol.interaction.KeyboardZoom({ + delta: options.zoomDelta + })); } var mouseWheelZoom = goog.isDef(options.mouseWheelZoom) ? diff --git a/src/ol/interaction/keyboardzoominteraction.js b/src/ol/interaction/keyboardzoominteraction.js index c98e6ed516..8bd6cc8748 100644 --- a/src/ol/interaction/keyboardzoominteraction.js +++ b/src/ol/interaction/keyboardzoominteraction.js @@ -6,6 +6,7 @@ goog.require('goog.asserts'); goog.require('goog.events.KeyHandler.EventType'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Interaction'); +goog.require('ol.interaction.condition'); /** @@ -17,11 +18,10 @@ ol.interaction.KEYBOARD_ZOOM_DURATION = 100; /** * @constructor - * @param {ol.interaction.ConditionType} condition Condition. * @param {ol.interaction.KeyboardZoomOptions=} opt_options Options. * @extends {ol.interaction.Interaction} */ -ol.interaction.KeyboardZoom = function(condition, opt_options) { +ol.interaction.KeyboardZoom = function(opt_options) { goog.base(this); @@ -31,7 +31,8 @@ ol.interaction.KeyboardZoom = function(condition, opt_options) { * @private * @type {ol.interaction.ConditionType} */ - this.condition_ = condition; + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.noModifierKeys; /** * @private From 3b9699fbc8813d6231faf637eadbd0b7d69fb3ee Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 15:47:58 +0200 Subject: [PATCH 15/19] Configure ol.interaction.DragZoom with options --- src/objectliterals.jsdoc | 5 +++++ src/ol/interaction/dragzoominteraction.js | 10 +++++++--- src/ol/interaction/interactiondefaults.js | 3 +-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 31d3ac326c..c4620ddd0d 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -180,6 +180,11 @@ * @property {ol.interaction.ConditionType|undefined} condition Condition. */ +/** + * @typedef {Object} ol.interaction.DragZoomOptions + * @property {ol.interaction.ConditionType|undefined} condition Condition. + */ + /** * Interactions for the map. Default is true for all options. * @typedef {Object} ol.interaction.DefaultsOptions diff --git a/src/ol/interaction/dragzoominteraction.js b/src/ol/interaction/dragzoominteraction.js index 87a293b168..6155de3ecb 100644 --- a/src/ol/interaction/dragzoominteraction.js +++ b/src/ol/interaction/dragzoominteraction.js @@ -10,6 +10,7 @@ goog.require('ol.control.DragBox'); goog.require('ol.extent'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Drag'); +goog.require('ol.interaction.condition'); /** @@ -30,17 +31,20 @@ ol.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS_SQUARED = /** * @constructor * @extends {ol.interaction.Drag} - * @param {ol.interaction.ConditionType} condition Condition. + * @param {ol.interaction.DragZoomOptions=} opt_options Options. */ -ol.interaction.DragZoom = function(condition) { +ol.interaction.DragZoom = function(opt_options) { goog.base(this); + var options = goog.isDef(opt_options) ? opt_options : {}; + /** * @private * @type {ol.interaction.ConditionType} */ - this.condition_ = condition; + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.shiftKeyOnly; /** * @type {ol.control.DragBox} diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index 1e34390262..097f621ae7 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -87,8 +87,7 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var shiftDragZoom = goog.isDef(options.shiftDragZoom) ? options.shiftDragZoom : true; if (shiftDragZoom) { - interactions.push( - new ol.interaction.DragZoom(ol.interaction.condition.shiftKeyOnly)); + interactions.push(new ol.interaction.DragZoom()); } if (goog.isDef(opt_interactions)) { From a36b4a04660c8ca704f0e739fddec228ad7b7d48 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 16:05:24 +0200 Subject: [PATCH 16/19] Configure ol.interaction.DragPan with options --- src/objectliterals.jsdoc | 6 ++++++ src/ol/interaction/dragpaninteraction.js | 13 ++++++++----- src/ol/interaction/interactiondefaults.js | 7 +++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index c4620ddd0d..5deb9d3ef9 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -170,6 +170,12 @@ * click. */ +/** + * @typedef {Object} ol.interaction.DragPanOptions + * @property {ol.Kinetic|undefined} kinetic Kinetic. + * @property {ol.interaction.ConditionType|undefined} condition Conditon. + */ + /** * @typedef {Object} ol.interaction.DragRotateOptions * @property {ol.interaction.ConditionType|undefined} condition Condition. diff --git a/src/ol/interaction/dragpaninteraction.js b/src/ol/interaction/dragpaninteraction.js index 86ebc1240c..5588159fc4 100644 --- a/src/ol/interaction/dragpaninteraction.js +++ b/src/ol/interaction/dragpaninteraction.js @@ -11,30 +11,33 @@ goog.require('ol.ViewHint'); goog.require('ol.coordinate'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Drag'); +goog.require('ol.interaction.condition'); /** * @constructor * @extends {ol.interaction.Drag} - * @param {ol.interaction.ConditionType} condition Condition. - * @param {ol.Kinetic=} opt_kinetic Kinetic object. + * @param {ol.interaction.DragPanOptions=} opt_options Options. */ -ol.interaction.DragPan = function(condition, opt_kinetic) { +ol.interaction.DragPan = function(opt_options) { goog.base(this); + var options = goog.isDef(opt_options) ? opt_options : {}; + /** * @private * @type {ol.interaction.ConditionType} */ - this.condition_ = condition; + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.noModifierKeys; /** * @private * @type {ol.Kinetic|undefined} */ - this.kinetic_ = opt_kinetic; + this.kinetic_ = options.kinetic; /** * @private diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index 097f621ae7..b086eee1f9 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -13,7 +13,6 @@ goog.require('ol.interaction.MouseWheelZoom'); goog.require('ol.interaction.TouchPan'); goog.require('ol.interaction.TouchRotate'); goog.require('ol.interaction.TouchZoom'); -goog.require('ol.interaction.condition'); /** @@ -64,9 +63,9 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var dragPan = goog.isDef(options.dragPan) ? options.dragPan : true; if (dragPan) { - interactions.push( - new ol.interaction.DragPan(ol.interaction.condition.noModifierKeys, - new ol.Kinetic(-0.005, 0.05, 100))); + interactions.push(new ol.interaction.DragPan({ + kinetic: new ol.Kinetic(-0.005, 0.05, 100) + })); } var keyboard = goog.isDef(options.keyboard) ? From 2dff59a4d487a2638150327310f1478f69069fbc Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 16:11:22 +0200 Subject: [PATCH 17/19] Configure ol.interaction.TouchPan with options --- src/objectliterals.jsdoc | 5 +++++ src/ol/interaction/interactiondefaults.js | 5 +++-- src/ol/interaction/touchpaninteraction.js | 8 +++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 5deb9d3ef9..a66bc2a5a8 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -224,6 +224,11 @@ * @property {number|undefined} delta Delta. */ +/** + * @typedef {Object} ol.interaction.TouchPanOptions + * @property {ol.Kinetic|undefined} kinetic Kinetic. + */ + /** * @typedef {Object} ol.layer.LayerOptions * @property {number|undefined} brightness Brightness. diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index b086eee1f9..bc77efbaf4 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -44,8 +44,9 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var touchPan = goog.isDef(options.touchPan) ? options.touchPan : true; if (touchPan) { - interactions.push(new ol.interaction.TouchPan( - new ol.Kinetic(-0.005, 0.05, 100))); + interactions.push(new ol.interaction.TouchPan({ + kinetic: new ol.Kinetic(-0.005, 0.05, 100) + })); } var touchRotate = goog.isDef(options.touchRotate) ? diff --git a/src/ol/interaction/touchpaninteraction.js b/src/ol/interaction/touchpaninteraction.js index 8bd3ef35d3..08b8740ec4 100644 --- a/src/ol/interaction/touchpaninteraction.js +++ b/src/ol/interaction/touchpaninteraction.js @@ -15,17 +15,19 @@ goog.require('ol.interaction.Touch'); /** * @constructor * @extends {ol.interaction.Touch} - * @param {ol.Kinetic=} opt_kinetic Kinetic object. + * @param {ol.interaction.TouchPanOptions=} opt_options Options. */ -ol.interaction.TouchPan = function(opt_kinetic) { +ol.interaction.TouchPan = function(opt_options) { goog.base(this); + var options = goog.isDef(opt_options) ? opt_options : {}; + /** * @private * @type {ol.Kinetic|undefined} */ - this.kinetic_ = opt_kinetic; + this.kinetic_ = options.kinetic; /** * @private From 9e8d20aee49b9506973401b1ec0e4d45769e4e42 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 16:12:09 +0200 Subject: [PATCH 18/19] Re-use ol.Kinetic object --- src/ol/interaction/interactiondefaults.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ol/interaction/interactiondefaults.js b/src/ol/interaction/interactiondefaults.js index bc77efbaf4..b2ba3bd2e4 100644 --- a/src/ol/interaction/interactiondefaults.js +++ b/src/ol/interaction/interactiondefaults.js @@ -27,6 +27,8 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { var interactions = new ol.Collection(); + var kinetic = new ol.Kinetic(-0.005, 0.05, 100); + var altShiftDragRotate = goog.isDef(options.altShiftDragRotate) ? options.altShiftDragRotate : true; if (altShiftDragRotate) { @@ -45,7 +47,7 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { options.touchPan : true; if (touchPan) { interactions.push(new ol.interaction.TouchPan({ - kinetic: new ol.Kinetic(-0.005, 0.05, 100) + kinetic: kinetic })); } @@ -65,7 +67,7 @@ ol.interaction.defaults = function(opt_options, opt_interactions) { options.dragPan : true; if (dragPan) { interactions.push(new ol.interaction.DragPan({ - kinetic: new ol.Kinetic(-0.005, 0.05, 100) + kinetic: kinetic })); } From 4da61e8ae9f7fc78df7971cbb3b10219d59717ad Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 16:30:55 +0200 Subject: [PATCH 19/19] Configure ol.interaction.TouchRotate with options --- src/objectliterals.jsdoc | 5 +++++ src/ol/interaction/touchrotateinteraction.js | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index a66bc2a5a8..b3e43feb4e 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -229,6 +229,11 @@ * @property {ol.Kinetic|undefined} kinetic Kinetic. */ +/** + * @typedef {Object} ol.interaction.TouchRotateOptions + * @property {number|undefined} threshold Minimal angle to start a rotation. + */ + /** * @typedef {Object} ol.layer.LayerOptions * @property {number|undefined} brightness Brightness. diff --git a/src/ol/interaction/touchrotateinteraction.js b/src/ol/interaction/touchrotateinteraction.js index d7ffb146f5..e0e4c9e937 100644 --- a/src/ol/interaction/touchrotateinteraction.js +++ b/src/ol/interaction/touchrotateinteraction.js @@ -21,13 +21,14 @@ ol.interaction.TOUCHROTATE_ANIMATION_DURATION = 250; /** * @constructor * @extends {ol.interaction.Touch} - * @param {number=} opt_threshold Minimal angle to start a rotation. - * Default to 0.3 (radian). + * @param {ol.interaction.TouchRotateOptions=} opt_options Options. */ -ol.interaction.TouchRotate = function(opt_threshold) { +ol.interaction.TouchRotate = function(opt_options) { goog.base(this); + var options = goog.isDef(opt_options) ? opt_options : {}; + /** * @private * @type {ol.Coordinate} @@ -56,7 +57,7 @@ ol.interaction.TouchRotate = function(opt_threshold) { * @private * @type {number} */ - this.threshold_ = goog.isDef(opt_threshold) ? opt_threshold : 0.3; + this.threshold_ = goog.isDef(options.threshold) ? options.threshold : 0.3; }; goog.inherits(ol.interaction.TouchRotate, ol.interaction.Touch);