Merge pull request #273 from twpayne/controls-api

reconsider the way we specify controls on the map
This commit is contained in:
Tom Payne
2013-03-06 05:59:31 -08:00
16 changed files with 274 additions and 221 deletions

View File

@@ -4,6 +4,7 @@ goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.control.ScaleLineUnits');
goog.require('ol.control.defaults');
goog.require('ol.layer.TileLayer');
goog.require('ol.projection');
goog.require('ol.source.TiledWMS');
@@ -24,11 +25,16 @@ var layers = new ol.Collection([
]);
var map = new ol.Map({
controls: ol.control.defaults({
scaleLine: true,
// FIXME The typecast here is only needed if the example is compiled
scaleLineOptions: /** @type {ol.control.ScaleLineOptions} */ ({
units: ol.control.ScaleLineUnits.DEGREES
})
}),
layers: layers,
// The OSgeo server does not set cross origin headers, so we cannot use WebGL
renderers: [ol.RendererHint.CANVAS, ol.RendererHint.DOM],
scaleLineControl: true,
scaleLineUnits: ol.control.ScaleLineUnits.DEGREES,
target: 'map',
view: new ol.View2D({
projection: ol.projection.getFromCode('EPSG:4326'),

View File

@@ -5,6 +5,7 @@ goog.require('ol.Geolocation');
goog.require('ol.Map');
goog.require('ol.RendererHints');
goog.require('ol.View2D');
goog.require('ol.control.defaults');
goog.require('ol.layer.TileLayer');
goog.require('ol.source.MapQuestOpenAerial');
@@ -13,9 +14,11 @@ var layer = new ol.layer.TileLayer({
source: new ol.source.MapQuestOpenAerial()
});
var map = new ol.Map({
controls: ol.control.defaults({
scaleLine: true
}),
layers: new ol.Collection([layer]),
renderers: ol.RendererHints.createFromQueryData(),
scaleLineControl: true,
target: 'map',
view: new ol.View2D({
center: new ol.Coordinate(0, 0),

View File

@@ -5,6 +5,7 @@ goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.animation');
goog.require('ol.control.MousePosition');
goog.require('ol.control.defaults');
goog.require('ol.easing');
goog.require('ol.interaction.Keyboard');
goog.require('ol.layer.TileLayer');
@@ -26,22 +27,28 @@ var view = new ol.View2D({
zoom: 1
});
var domMap = new ol.Map({
layers: new ol.Collection([layer]),
renderer: ol.RendererHint.DOM,
target: 'domMap',
view: view
});
var domMousePosition = new ol.control.MousePosition({
coordinateFormat: ol.Coordinate.toStringHDMS,
projection: ol.projection.getFromCode('EPSG:4326'),
target: document.getElementById('domMousePosition'),
undefinedHTML: ' '
});
domMousePosition.setMap(domMap);
var domMap = new ol.Map({
controls: ol.control.defaults({}, [domMousePosition]),
layers: new ol.Collection([layer]),
renderer: ol.RendererHint.DOM,
target: 'domMap',
view: view
});
var webglMousePosition = new ol.control.MousePosition({
coordinateFormat: ol.Coordinate.toStringHDMS,
projection: ol.projection.getFromCode('EPSG:4326'),
target: document.getElementById('webglMousePosition'),
undefinedHTML: ' '
});
var webglMap = new ol.Map({
controls: ol.control.defaults({}, [webglMousePosition]),
renderer: ol.RendererHint.WEBGL,
target: 'webglMap'
});
@@ -50,22 +57,6 @@ if (webglMap !== null) {
webglMap.bindTo('view', domMap);
}
var webglMousePosition = new ol.control.MousePosition({
coordinateFormat: ol.Coordinate.toStringHDMS,
projection: ol.projection.getFromCode('EPSG:4326'),
target: document.getElementById('webglMousePosition'),
undefinedHTML: ' '
});
webglMousePosition.setMap(webglMap);
var canvasMap = new ol.Map({
renderer: ol.RendererHint.CANVAS,
target: 'canvasMap'
});
if (canvasMap !== null) {
canvasMap.bindTo('layers', domMap);
canvasMap.bindTo('view', domMap);
}
var canvasMousePosition = new ol.control.MousePosition({
coordinateFormat: ol.Coordinate.toStringHDMS,
@@ -73,7 +64,15 @@ var canvasMousePosition = new ol.control.MousePosition({
target: document.getElementById('canvasMousePosition'),
undefinedHtml: ' '
});
canvasMousePosition.setMap(canvasMap);
var canvasMap = new ol.Map({
controls: ol.control.defaults({}, [canvasMousePosition]),
renderer: ol.RendererHint.CANVAS,
target: 'canvasMap'
});
if (canvasMap !== null) {
canvasMap.bindTo('layers', domMap);
canvasMap.bindTo('view', domMap);
}
var keyboardInteraction = new ol.interaction.Keyboard();
keyboardInteraction.addCallback('0', function() {

View File

@@ -22,7 +22,6 @@ var layers = new ol.Collection([
var map = new ol.Map({
layers: layers,
renderers: ol.RendererHints.createFromQueryData(),
scaleLineControl: true,
target: 'map',
view: new ol.View2D({
center: new ol.Coordinate(0, 0),

View File

@@ -1,24 +1,11 @@
@exportObjectLiteral ol.MapOptions
@exportObjectLiteralProperty ol.MapOptions.attributionControl boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.doubleClickZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.dragPan boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.controls Array.<ol.control.Control>|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.scaleLineControl boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.scaleLineUnits ol.control.ScaleLineUnits|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
@exportObjectLiteralProperty ol.MapOptions.zoomControl boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.zoomDelta number|undefined
@exportObjectLiteral ol.View2DOptions
@exportObjectLiteralProperty ol.View2DOptions.center ol.Coordinate|undefined
@@ -59,6 +46,14 @@
@exportObjectLiteralProperty ol.control.AttributionOptions.map ol.Map|undefined
@exportObjectLiteralProperty ol.control.AttributionOptions.target Element|undefined
@exportObjectLiteral ol.control.DefaultsOptions
@exportObjectLiteralProperty ol.control.DefaultsOptions.attribution boolean|undefined
@exportObjectLiteralProperty ol.control.DefaultsOptions.attributionOptions ol.control.AttributionOptions|undefined
@exportObjectLiteralProperty ol.control.DefaultsOptions.scaleLine boolean|undefined
@exportObjectLiteralProperty ol.control.DefaultsOptions.scaleLineOptions ol.control.ScaleLineOptions|undefined
@exportObjectLiteralProperty ol.control.DefaultsOptions.zoom boolean|undefined
@exportObjectLiteralProperty ol.control.DefaultsOptions.zoomOptions ol.control.ZoomOptions|undefined
@exportObjectLiteral ol.control.ScaleLineOptions
@exportObjectLiteralProperty ol.control.ScaleLineOptions.map ol.Map|undefined
@exportObjectLiteralProperty ol.control.ScaleLineOptions.minWidth number|undefined
@@ -77,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

View File

@@ -99,6 +99,17 @@ ol.Collection.prototype.clear = function() {
};
/**
* @param {Array} arr Array.
*/
ol.Collection.prototype.extend = function(arr) {
var i;
for (i = 0; i < arr.length; ++i) {
this.push(arr[i]);
}
};
/**
* @param {Function} f Function.
* @param {Object=} opt_obj Object.

View File

@@ -21,10 +21,11 @@ goog.require('ol.source.Source');
/**
* @constructor
* @extends {ol.control.Control}
* @param {ol.control.AttributionOptions} attributionOptions Attribution
* options.
* @param {ol.control.AttributionOptions=} opt_options Options.
*/
ol.control.Attribution = function(attributionOptions) {
ol.control.Attribution = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
this.ulElement_ = goog.dom.createElement(goog.dom.TagName.UL);
@@ -34,8 +35,8 @@ ol.control.Attribution = function(attributionOptions) {
goog.base(this, {
element: element,
map: attributionOptions.map,
target: attributionOptions.target
map: options.map,
target: options.target
});
/**

View File

@@ -0,0 +1 @@
@exportSymbol ol.control.defaults ol.control.defaults

View File

@@ -0,0 +1,51 @@
goog.provide('ol.control.defaults');
goog.require('goog.array');
goog.require('ol.control.Attribution');
goog.require('ol.control.ScaleLine');
goog.require('ol.control.Zoom');
/**
* @param {ol.control.DefaultsOptions=} opt_options Options.
* @param {Array.<ol.control.Control>=} opt_controls Additional controls.
* @return {Array.<ol.control.Control>} Controls.
*/
ol.control.defaults = function(opt_options, opt_controls) {
var options = goog.isDef(opt_options) ? opt_options : {};
/** @type {Array.<ol.control.Control>} */
var controls = [];
var attributionControl = goog.isDef(options.attribution) ?
options.attribution : true;
if (attributionControl) {
var attributionControlOptions = goog.isDef(options.attributionOptions) ?
options.attributionOptions : undefined;
controls.push(new ol.control.Attribution(attributionControlOptions));
}
var scaleLineControl = goog.isDef(options.scaleLine) ?
options.scaleLine : false;
if (scaleLineControl) {
var scaleLineOptions = goog.isDef(options.scaleLineOptions) ?
options.scaleLineOptions : undefined;
controls.push(new ol.control.ScaleLine(scaleLineOptions));
}
var zoomControl = goog.isDef(options.zoom) ?
options.zoom : true;
if (zoomControl) {
var zoomControlOptions = goog.isDef(options.zoomControlOptions) ?
options.zoomControlOptions : undefined;
controls.push(new ol.control.Zoom(zoomControlOptions));
}
if (goog.isDef(opt_controls)) {
goog.array.extend(controls, opt_controls);
}
return controls;
};

View File

@@ -23,10 +23,11 @@ goog.require('ol.projection');
/**
* @constructor
* @extends {ol.control.Control}
* @param {ol.control.MousePositionOptions} mousePositionOptions Mouse position
* options.
* @param {ol.control.MousePositionOptions=} opt_options Options.
*/
ol.control.MousePosition = function(mousePositionOptions) {
ol.control.MousePosition = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': 'ol-mouse-position'
@@ -34,28 +35,28 @@ ol.control.MousePosition = function(mousePositionOptions) {
goog.base(this, {
element: element,
map: mousePositionOptions.map,
target: mousePositionOptions.target
map: options.map,
target: options.target
});
/**
* @private
* @type {ol.Projection|undefined}
*/
this.projection_ = mousePositionOptions.projection;
this.projection_ = options.projection;
/**
* @private
* @type {ol.CoordinateFormatType|undefined}
*/
this.coordinateFormat_ = mousePositionOptions.coordinateFormat;
this.coordinateFormat_ = options.coordinateFormat;
/**
* @private
* @type {string}
*/
this.undefinedHTML_ = goog.isDef(mousePositionOptions.undefinedHTML) ?
mousePositionOptions.undefinedHTML : '';
this.undefinedHTML_ = goog.isDef(options.undefinedHTML) ?
options.undefinedHTML : '';
/**
* @private

View File

@@ -19,9 +19,11 @@ ol.control.ZOOM_DURATION = 250;
/**
* @constructor
* @extends {ol.control.Control}
* @param {ol.control.ZoomOptions} zoomOptions Zoom options.
* @param {ol.control.ZoomOptions=} opt_options Options.
*/
ol.control.Zoom = function(zoomOptions) {
ol.control.Zoom = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
var inElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#zoomIn',
@@ -46,15 +48,15 @@ ol.control.Zoom = function(zoomOptions) {
goog.base(this, {
element: element,
map: zoomOptions.map,
target: zoomOptions.target
map: options.map,
target: options.target
});
/**
* @type {number}
* @private
*/
this.delta_ = goog.isDef(zoomOptions.delta) ? zoomOptions.delta : 1;
this.delta_ = goog.isDef(options.delta) ? options.delta : 1;
};
goog.inherits(ol.control.Zoom, ol.control.Control);

View File

@@ -0,0 +1 @@
@exportSymbol ol.interaction.defaults ol.interaction.defaults

View File

@@ -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 {Array.<ol.interaction.Interaction>=} opt_interactions Additional
* interactions.
* @return {ol.Collection} Interactions.
*/
ol.interaction.defaults = function(opt_options, opt_interactions) {
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));
}
if (goog.isDef(opt_interactions)) {
interactions.extend(opt_interactions);
}
return interactions;
};

View File

@@ -28,7 +28,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,22 +43,8 @@ goog.require('ol.Tile');
goog.require('ol.TileQueue');
goog.require('ol.View');
goog.require('ol.View2D');
goog.require('ol.control.Attribution');
goog.require('ol.control.Control');
goog.require('ol.control.ScaleLine');
goog.require('ol.control.Zoom');
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.control.defaults');
goog.require('ol.interaction.defaults');
goog.require('ol.layer.Layer');
goog.require('ol.projection');
goog.require('ol.projection.addCommonProjections');
@@ -293,15 +278,15 @@ ol.Map = function(mapOptions) {
// this gives the map an initial size
this.handleBrowserWindowResize();
/** @type {Array.<ol.control.Control>} */
var controls = mapOptionsInternal.controls;
goog.array.forEach(controls,
/**
* @param {ol.control.Control} control Control.
*/
function(control) {
control.setMap(this);
}, this);
if (goog.isDef(mapOptionsInternal.controls)) {
goog.array.forEach(mapOptionsInternal.controls,
/**
* @param {ol.control.Control} control Control.
*/
function(control) {
control.setMap(this);
}, this);
}
};
goog.inherits(ol.Map, ol.Object);
@@ -882,20 +867,11 @@ ol.Map.createOptionsInternal = function(mapOptions) {
}
}
/**
* @type {Array.<ol.control.Control>}
*/
var controls = ol.Map.createControls_(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}
@@ -913,123 +889,6 @@ ol.Map.createOptionsInternal = function(mapOptions) {
};
/**
* @private
* @param {ol.MapOptions} mapOptions Map options.
* @return {Array.<ol.control.Control>} Controls.
*/
ol.Map.createControls_ = function(mapOptions) {
/** @type {Array.<ol.control.Control>} */
var controls = [];
var attributionControl = goog.isDef(mapOptions.attributionControl) ?
mapOptions.attributionControl : true;
if (attributionControl) {
controls.push(new ol.control.Attribution({}));
}
var scaleLineControl = goog.isDef(mapOptions.scaleLineControl) ?
mapOptions.scaleLineControl : false;
if (scaleLineControl) {
var scaleLineUnits = goog.isDef(mapOptions.scaleLineUnits) ?
mapOptions.scaleLineUnits : undefined;
controls.push(new ol.control.ScaleLine({
units: scaleLineUnits
}));
}
var zoomControl = goog.isDef(mapOptions.zoomControl) ?
mapOptions.zoomControl : true;
if (zoomControl) {
var zoomDelta = goog.isDef(mapOptions.zoomDelta) ?
mapOptions.zoomDelta : 1;
controls.push(new ol.control.Zoom({
delta: zoomDelta
}));
}
return controls;
};
/**
* @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 File

@@ -235,6 +235,17 @@ describe('ol.collection', function() {
});
});
});
describe('extending a collection', function() {
it('adds elements to end of the collection', function() {
collection.extend([1, 2]);
expect(collection.getLength()).toEqual(2);
expect(goog.array.equals(collection.getArray(), [1, 2])).toBeTruthy();
expect(collection.getAt(0)).toEqual(1);
expect(collection.getAt(1)).toEqual(2);
});
});
});
goog.require('goog.array');

View File

@@ -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');