Merge remote-tracking branch 'openlayers/master' into vector-api

This commit is contained in:
Tom Payne
2013-12-13 20:22:06 +01:00
39 changed files with 555 additions and 420 deletions

View File

@@ -84,11 +84,13 @@ ol.interaction.DragPan.prototype.handleDragEnd = function(mapBrowserEvent) {
// FIXME works for View2D only
var map = mapBrowserEvent.map;
var view = map.getView().getView2D();
var view = map.getView();
view.setHint(ol.ViewHint.INTERACTING, -1);
if (this.kinetic_ && this.kinetic_.end()) {
var view2DState = view.getView2DState();
var view2D = view.getView2D();
goog.asserts.assertInstanceof(view2D, ol.View2D);
var view2DState = view2D.getView2DState();
var distance = this.kinetic_.getDistance();
var angle = this.kinetic_.getAngle();
this.kineticPreRenderFn_ = this.kinetic_.pan(view2DState.center);
@@ -99,8 +101,8 @@ ol.interaction.DragPan.prototype.handleDragEnd = function(mapBrowserEvent) {
centerpx[0] - distance * Math.cos(angle),
centerpx[1] - distance * Math.sin(angle)
]);
dest = view.constrainCenter(dest);
view.setCenter(dest);
dest = view2D.constrainCenter(dest);
view2D.setCenter(dest);
}
map.requestRenderFrame();
};

View File

@@ -105,13 +105,14 @@ ol.interaction.DragRotateAndZoom.prototype.handleDragEnd =
function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
// FIXME works for View2D only
var view = map.getView().getView2D();
var view = map.getView();
view.setHint(ol.ViewHint.INTERACTING, -1);
var view2DState = view.getView2DState();
var view2D = view.getView2D();
var view2DState = view2D.getView2DState();
var direction = this.lastScaleDelta_ - 1;
map.withFrozenRendering(function() {
ol.interaction.Interaction.rotate(map, view, view2DState.rotation);
ol.interaction.Interaction.zoom(map, view, view2DState.resolution,
ol.interaction.Interaction.rotate(map, view2D, view2DState.rotation);
ol.interaction.Interaction.zoom(map, view2D, view2DState.resolution,
undefined, ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION,
direction);
});

View File

@@ -74,11 +74,12 @@ ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) {
ol.interaction.DragRotate.prototype.handleDragEnd = function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
// FIXME works for View2D only
var view = map.getView().getView2D();
var view = map.getView();
view.setHint(ol.ViewHint.INTERACTING, -1);
var view2DState = view.getView2DState();
ol.interaction.Interaction.rotate(map, view, view2DState.rotation, undefined,
ol.interaction.DRAGROTATE_ANIMATION_DURATION);
var view2D = view.getView2D();
var view2DState = view2D.getView2DState();
ol.interaction.Interaction.rotate(map, view2D, view2DState.rotation,
undefined, ol.interaction.DRAGROTATE_ANIMATION_DURATION);
};

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');
@@ -58,12 +60,13 @@ ol.interaction.Interaction.prototype.setMap = function(map) {
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {ol.IView2D} view View.
* @param {ol.Coordinate} delta Delta.
* @param {number=} opt_duration Duration.
*/
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) {
@@ -82,13 +85,14 @@ ol.interaction.Interaction.pan = function(
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {ol.IView2D} view View.
* @param {number|undefined} rotation Rotation.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
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);
@@ -97,13 +101,14 @@ ol.interaction.Interaction.rotate =
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {ol.IView2D} view View.
* @param {number|undefined} rotation Rotation.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
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);
});
@@ -137,7 +143,7 @@ ol.interaction.Interaction.rotateWithoutConstraints =
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {ol.IView2D} view View.
* @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
@@ -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);
@@ -160,13 +167,14 @@ ol.interaction.Interaction.zoom =
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {ol.IView2D} view View.
* @param {number} delta Delta from previous zoom level.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
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(
@@ -176,13 +184,14 @@ ol.interaction.Interaction.zoomByDelta =
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {ol.IView2D} view View.
* @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
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);
});

View File

@@ -5,6 +5,7 @@ goog.require('goog.asserts');
goog.require('ol.Kinetic');
goog.require('ol.Pixel');
goog.require('ol.PreRenderFunction');
goog.require('ol.View2D');
goog.require('ol.coordinate');
goog.require('ol.interaction.Touch');
@@ -64,15 +65,16 @@ ol.interaction.TouchPan.prototype.handleTouchMove = function(mapBrowserEvent) {
var deltaX = this.lastCentroid[0] - centroid[0];
var deltaY = centroid[1] - this.lastCentroid[1];
var map = mapBrowserEvent.map;
var view = map.getView().getView2D();
var view2DState = view.getView2DState();
var view2D = map.getView().getView2D();
goog.asserts.assertInstanceof(view2D, ol.View2D);
var view2DState = view2D.getView2DState();
var center = [deltaX, deltaY];
ol.coordinate.scale(center, view2DState.resolution);
ol.coordinate.rotate(center, view2DState.rotation);
ol.coordinate.add(center, view2DState.center);
center = view.constrainCenter(center);
center = view2D.constrainCenter(center);
map.requestRenderFrame();
view.setCenter(center);
view2D.setCenter(center);
}
this.lastCentroid = centroid;
};
@@ -84,12 +86,14 @@ ol.interaction.TouchPan.prototype.handleTouchMove = function(mapBrowserEvent) {
ol.interaction.TouchPan.prototype.handleTouchEnd =
function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
var view = map.getView();
var view2D = map.getView().getView2D();
goog.asserts.assertInstanceof(view2D, ol.View2D);
if (this.targetTouches.length === 0) {
if (!this.noKinetic_ && this.kinetic_ && this.kinetic_.end()) {
var distance = this.kinetic_.getDistance();
var angle = this.kinetic_.getAngle();
var center = view.getCenter();
var center = view2D.getCenter();
goog.asserts.assert(goog.isDef(center));
this.kineticPreRenderFn_ = this.kinetic_.pan(center);
map.beforeRender(this.kineticPreRenderFn_);
var centerpx = map.getPixelFromCoordinate(center);
@@ -97,8 +101,8 @@ ol.interaction.TouchPan.prototype.handleTouchEnd =
centerpx[0] - distance * Math.cos(angle),
centerpx[1] - distance * Math.sin(angle)
]);
dest = view.constrainCenter(dest);
view.setCenter(dest);
dest = view2D.constrainCenter(dest);
view2D.setCenter(dest);
}
map.requestRenderFrame();
return false;
@@ -116,12 +120,13 @@ ol.interaction.TouchPan.prototype.handleTouchStart =
function(mapBrowserEvent) {
if (this.targetTouches.length > 0) {
var map = mapBrowserEvent.map;
var view = map.getView();
var view2D = map.getView().getView2D();
goog.asserts.assertInstanceof(view2D, ol.View2D);
this.lastCentroid = null;
map.requestRenderFrame();
if (!goog.isNull(this.kineticPreRenderFn_) &&
map.removePreRenderFunction(this.kineticPreRenderFn_)) {
view.setCenter(mapBrowserEvent.frameState.view2DState.center);
view2D.setCenter(mapBrowserEvent.frameState.view2DState.center);
this.kineticPreRenderFn_ = null;
}
if (this.kinetic_) {