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