Improve type checking in ol.interaction.Interaction

This commit is contained in:
Tom Payne
2013-12-13 16:05:08 +01:00
parent b39ae367e7
commit 35768f8b48

View File

@@ -2,8 +2,10 @@
goog.provide('ol.interaction.Interaction');
goog.require('goog.asserts');
goog.require('goog.events.EventTarget');
goog.require('ol.MapBrowserEvent');
goog.require('ol.View2D');
goog.require('ol.animation');
goog.require('ol.easing');
@@ -64,6 +66,7 @@ ol.interaction.Interaction.prototype.setMap = function(map) {
*/
ol.interaction.Interaction.pan = function(
map, view, delta, opt_duration) {
goog.asserts.assertInstanceof(view, ol.View2D);
var currentCenter = view.getCenter();
if (goog.isDef(currentCenter)) {
if (goog.isDef(opt_duration) && opt_duration > 0) {
@@ -89,6 +92,7 @@ ol.interaction.Interaction.pan = function(
*/
ol.interaction.Interaction.rotate =
function(map, view, rotation, opt_anchor, opt_duration) {
goog.asserts.assertInstanceof(view, ol.View2D);
rotation = view.constrainRotation(rotation, 0);
ol.interaction.Interaction.rotateWithoutConstraints(
map, view, rotation, opt_anchor, opt_duration);
@@ -104,6 +108,7 @@ ol.interaction.Interaction.rotate =
*/
ol.interaction.Interaction.rotateWithoutConstraints =
function(map, view, rotation, opt_anchor, opt_duration) {
goog.asserts.assertInstanceof(view, ol.View2D);
if (goog.isDefAndNotNull(rotation)) {
var currentRotation = view.getRotation();
var currentCenter = view.getCenter();
@@ -125,6 +130,7 @@ ol.interaction.Interaction.rotateWithoutConstraints =
if (goog.isDefAndNotNull(opt_anchor)) {
var center = view.calculateCenterRotate(rotation, opt_anchor);
map.withFrozenRendering(function() {
goog.asserts.assertInstanceof(view, ol.View2D);
view.setCenter(center);
view.setRotation(rotation);
});
@@ -152,6 +158,7 @@ ol.interaction.Interaction.rotateWithoutConstraints =
*/
ol.interaction.Interaction.zoom =
function(map, view, resolution, opt_anchor, opt_duration, opt_direction) {
goog.asserts.assertInstanceof(view, ol.View2D);
resolution = view.constrainResolution(resolution, 0, opt_direction);
ol.interaction.Interaction.zoomWithoutConstraints(
map, view, resolution, opt_anchor, opt_duration);
@@ -167,6 +174,7 @@ ol.interaction.Interaction.zoom =
*/
ol.interaction.Interaction.zoomByDelta =
function(map, view, delta, opt_anchor, opt_duration) {
goog.asserts.assertInstanceof(view, ol.View2D);
var currentResolution = view.getResolution();
var resolution = view.constrainResolution(currentResolution, delta, 0);
ol.interaction.Interaction.zoomWithoutConstraints(
@@ -183,6 +191,7 @@ ol.interaction.Interaction.zoomByDelta =
*/
ol.interaction.Interaction.zoomWithoutConstraints =
function(map, view, resolution, opt_anchor, opt_duration) {
goog.asserts.assertInstanceof(view, ol.View2D);
if (goog.isDefAndNotNull(resolution)) {
var currentResolution = view.getResolution();
var currentCenter = view.getCenter();
@@ -204,6 +213,7 @@ ol.interaction.Interaction.zoomWithoutConstraints =
if (goog.isDefAndNotNull(opt_anchor)) {
var center = view.calculateCenterZoom(resolution, opt_anchor);
map.withFrozenRendering(function() {
goog.asserts.assertInstanceof(view, ol.View2D);
view.setCenter(center);
view.setResolution(resolution);
});