Permalink
Browse files

Add ol.interaction.defaults

  • Loading branch information...
1 parent a94eadf commit 671ee79c7452cb135124d4ed3867b6d8be9407c2 @twpayne committed Mar 6, 2013
Showing with 120 additions and 112 deletions.
  1. +11 −9 src/objectliterals.exports
  2. +1 −0 src/ol/interaction/defaults.exports
  3. +101 −0 src/ol/interaction/defaults.js
  4. +3 −100 src/ol/map.js
  5. +4 −3 test/spec/ol/map.test.js
View
@@ -1,19 +1,10 @@
@exportObjectLiteral ol.MapOptions
@exportObjectLiteralProperty ol.MapOptions.controls Array.<ol.control.Control>|undefined
-@exportObjectLiteralProperty ol.MapOptions.doubleClickZoom boolean|undefined
-@exportObjectLiteralProperty ol.MapOptions.dragPan boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.interactions ol.Collection|undefined
-@exportObjectLiteralProperty ol.MapOptions.keyboard boolean|undefined
-@exportObjectLiteralProperty ol.MapOptions.keyboardPanOffset number|undefined
@exportObjectLiteralProperty ol.MapOptions.layers ol.Collection|undefined
-@exportObjectLiteralProperty ol.MapOptions.mouseWheelZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.renderer ol.RendererHint|undefined
@exportObjectLiteralProperty ol.MapOptions.renderers Array.<ol.RendererHint>|undefined
-@exportObjectLiteralProperty ol.MapOptions.shiftDragZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.target Element|string
-@exportObjectLiteralProperty ol.MapOptions.touchPan boolean|undefined
-@exportObjectLiteralProperty ol.MapOptions.touchRotate boolean|undefined
-@exportObjectLiteralProperty ol.MapOptions.touchZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.view ol.IView|undefined
@exportObjectLiteral ol.View2DOptions
@@ -81,6 +72,17 @@
@exportObjectLiteralProperty ol.control.ZoomOptions.map ol.Map|undefined
@exportObjectLiteralProperty ol.control.ZoomOptions.target Element|undefined
+@exportObjectLiteral ol.interaction.DefaultOptions
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.doubleClickZoom boolean|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.dragPan boolean|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.keyboard boolean|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.keyboardPanOffset number|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.mouseWheelZoom boolean|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.shiftDragZoom boolean|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.touchPan boolean|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.touchRotate boolean|undefined
+@exportObjectLiteralProperty ol.interaction.DefaultOptions.touchZoom boolean|undefined
+
@exportObjectLiteral ol.layer.LayerOptions
@exportObjectLiteralProperty ol.layer.LayerOptions.brightness number|undefined
@exportObjectLiteralProperty ol.layer.LayerOptions.contrast number|undefined
@@ -0,0 +1 @@
+@exportSymbol ol.interaction.defaults ol.interaction.defaults
@@ -0,0 +1,101 @@
+goog.provide('ol.interaction.defaults');
+
+goog.require('ol.Collection');
+goog.require('ol.Kinetic');
+goog.require('ol.interaction.DblClickZoom');
+goog.require('ol.interaction.DragPan');
+goog.require('ol.interaction.DragRotate');
+goog.require('ol.interaction.DragZoom');
+goog.require('ol.interaction.Interaction');
+goog.require('ol.interaction.KeyboardPan');
+goog.require('ol.interaction.KeyboardZoom');
+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');
+
+
+/**
+ * @param {ol.interaction.DefaultOptions=} opt_options Options.
+ * @param {...ol.interaction.Interaction} var_args Further interactions.
+ * @return {ol.Collection} Interactions.
+ */
+ol.interaction.defaults = function(opt_options, var_args) {
+
+ var options = goog.isDef(opt_options) ? opt_options : {};
+
+ var interactions = new ol.Collection();
+
+ var rotate = goog.isDef(options.rotate) ?
+ options.rotate : true;
+ if (rotate) {
+ interactions.push(new ol.interaction.DragRotate(
+ ol.interaction.condition.altShiftKeysOnly));
+ }
+
+ 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));
+ }
+
+ 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)));
+ }
+
+ var touchRotate = goog.isDef(options.touchRotate) ?
+ options.touchRotate : true;
+ if (touchRotate) {
+ interactions.push(new ol.interaction.TouchRotate());
+ }
+
+ var touchZoom = goog.isDef(options.touchZoom) ?
+ options.touchZoom : true;
+ if (touchZoom) {
+ interactions.push(new ol.interaction.TouchZoom());
+ }
+
+ 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)));
+ }
+
+ var keyboard = goog.isDef(options.keyboard) ?
+ options.keyboard : true;
+ var keyboardPanOffset = goog.isDef(options.keyboardPanOffset) ?
+ options.keyboardPanOffset : 80;
+ if (keyboard) {
+ interactions.push(new ol.interaction.KeyboardPan(keyboardPanOffset));
+ interactions.push(new ol.interaction.KeyboardZoom());
+ }
+
+ var mouseWheelZoom = goog.isDef(options.mouseWheelZoom) ?
+ options.mouseWheelZoom : true;
+ if (mouseWheelZoom) {
+ interactions.push(new ol.interaction.MouseWheelZoom());
+ }
+
+ var shiftDragZoom = goog.isDef(options.shiftDragZoom) ?
+ options.shiftDragZoom : true;
+ if (shiftDragZoom) {
+ interactions.push(
+ new ol.interaction.DragZoom(ol.interaction.condition.shiftKeyOnly));
+ }
+
+ var i;
+ for (i = 1; i < arguments.length; ++i) {
+ interactions.push(arguments[i]);
+ }
+
+ return interactions;
+
+};
View
@@ -27,7 +27,6 @@ goog.require('ol.Coordinate');
goog.require('ol.Extent');
goog.require('ol.FrameState');
goog.require('ol.IView');
-goog.require('ol.Kinetic');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEvent.EventType');
goog.require('ol.MapBrowserEventHandler');
@@ -44,18 +43,7 @@ goog.require('ol.TileQueue');
goog.require('ol.View');
goog.require('ol.View2D');
goog.require('ol.control.defaults');
-goog.require('ol.interaction.DblClickZoom');
-goog.require('ol.interaction.DragPan');
-goog.require('ol.interaction.DragRotate');
-goog.require('ol.interaction.DragZoom');
-goog.require('ol.interaction.Interaction');
-goog.require('ol.interaction.KeyboardPan');
-goog.require('ol.interaction.KeyboardZoom');
-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');
+goog.require('ol.interaction.defaults');
goog.require('ol.layer.Layer');
goog.require('ol.projection');
goog.require('ol.projection.addCommonProjections');
@@ -881,15 +869,8 @@ ol.Map.createOptionsInternal = function(mapOptions) {
var controls = goog.isDef(mapOptions.controls) ?
mapOptions.controls : ol.control.defaults();
- /**
- * @type {ol.Collection}
- */
- var interactions;
- if (goog.isDef(mapOptions.interactions)) {
- interactions = mapOptions.interactions;
- } else {
- interactions = ol.Map.createInteractions_(mapOptions);
- }
+ var interactions = goog.isDef(mapOptions.interactions) ?
+ mapOptions.interactions : ol.interaction.defaults();
/**
* @type {Element}
@@ -908,84 +889,6 @@ ol.Map.createOptionsInternal = function(mapOptions) {
/**
- * @private
- * @param {ol.MapOptions} mapOptions Map options.
- * @return {ol.Collection} Interactions.
- */
-ol.Map.createInteractions_ = function(mapOptions) {
-
- var interactions = new ol.Collection();
-
- var rotate = goog.isDef(mapOptions.rotate) ?
- mapOptions.rotate : true;
- if (rotate) {
- interactions.push(new ol.interaction.DragRotate(
- ol.interaction.condition.altShiftKeysOnly));
- }
-
- var doubleClickZoom = goog.isDef(mapOptions.doubleClickZoom) ?
- mapOptions.doubleClickZoom : true;
- if (doubleClickZoom) {
- var zoomDelta = goog.isDef(mapOptions.zoomDelta) ?
- mapOptions.zoomDelta : 1;
- interactions.push(new ol.interaction.DblClickZoom(zoomDelta));
- }
-
- var touchPan = goog.isDef(mapOptions.touchPan) ?
- mapOptions.touchPan : true;
- if (touchPan) {
- interactions.push(new ol.interaction.TouchPan(
- new ol.Kinetic(-0.005, 0.05, 100)));
- }
-
- var touchRotate = goog.isDef(mapOptions.touchRotate) ?
- mapOptions.touchRotate : true;
- if (touchRotate) {
- interactions.push(new ol.interaction.TouchRotate());
- }
-
- var touchZoom = goog.isDef(mapOptions.touchZoom) ?
- mapOptions.touchZoom : true;
- if (touchZoom) {
- interactions.push(new ol.interaction.TouchZoom());
- }
-
- var dragPan = goog.isDef(mapOptions.dragPan) ?
- mapOptions.dragPan : true;
- if (dragPan) {
- interactions.push(
- new ol.interaction.DragPan(ol.interaction.condition.noModifierKeys,
- new ol.Kinetic(-0.005, 0.05, 100)));
- }
-
- var keyboard = goog.isDef(mapOptions.keyboard) ?
- mapOptions.keyboard : true;
- var keyboardPanOffset = goog.isDef(mapOptions.keyboardPanOffset) ?
- mapOptions.keyboardPanOffset : 80;
- if (keyboard) {
- interactions.push(new ol.interaction.KeyboardPan(keyboardPanOffset));
- interactions.push(new ol.interaction.KeyboardZoom());
- }
-
- var mouseWheelZoom = goog.isDef(mapOptions.mouseWheelZoom) ?
- mapOptions.mouseWheelZoom : true;
- if (mouseWheelZoom) {
- interactions.push(new ol.interaction.MouseWheelZoom());
- }
-
- var shiftDragZoom = goog.isDef(mapOptions.shiftDragZoom) ?
- mapOptions.shiftDragZoom : true;
- if (shiftDragZoom) {
- interactions.push(
- new ol.interaction.DragZoom(ol.interaction.condition.shiftKeyOnly));
- }
-
- return interactions;
-
-};
-
-
-/**
* @param {goog.Uri.QueryData=} opt_queryData Query data.
* @return {Array.<ol.RendererHint>} Renderer hints.
*/
View
@@ -87,7 +87,7 @@ describe('ol.Map', function() {
describe('create mousewheel interaction', function() {
it('creates mousewheel interaction', function() {
options.mouseWheelZoom = true;
- var interactions = ol.Map.createInteractions_(options);
+ var interactions = ol.interaction.defaults(options);
expect(interactions.getLength()).toEqual(1);
expect(interactions.getAt(0)).toBeA(ol.interaction.MouseWheelZoom);
});
@@ -101,7 +101,7 @@ describe('ol.Map', function() {
describe('default zoomDelta', function() {
it('create double click interaction with default delta', function() {
- var interactions = ol.Map.createInteractions_(options);
+ var interactions = ol.interaction.defaults(options);
expect(interactions.getLength()).toEqual(1);
expect(interactions.getAt(0)).toBeA(ol.interaction.DblClickZoom);
expect(interactions.getAt(0).delta_).toEqual(1);
@@ -111,7 +111,7 @@ describe('ol.Map', function() {
describe('set zoomDelta', function() {
it('create double click interaction with set delta', function() {
options.zoomDelta = 7;
- var interactions = ol.Map.createInteractions_(options);
+ var interactions = ol.interaction.defaults(options);
expect(interactions.getLength()).toEqual(1);
expect(interactions.getAt(0)).toBeA(ol.interaction.DblClickZoom);
expect(interactions.getAt(0).delta_).toEqual(7);
@@ -233,5 +233,6 @@ goog.require('ol.RendererHints');
goog.require('ol.View2D');
goog.require('ol.interaction.DblClickZoom');
goog.require('ol.interaction.MouseWheelZoom');
+goog.require('ol.interaction.defaults');
goog.require('ol.layer.TileLayer');
goog.require('ol.source.XYZ');

0 comments on commit 671ee79

Please sign in to comment.