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

@@ -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.