Merge pull request #818 from twpayne/view2d-properties

View2D properties
This commit is contained in:
Tom Payne
2013-06-25 04:50:30 -07:00
3 changed files with 17 additions and 17 deletions

View File

@@ -61,10 +61,12 @@ ol.interaction.DragPan.prototype.handleDrag = function(mapBrowserEvent) {
// FIXME works for View2D only
var view = map.getView();
goog.asserts.assertInstanceof(view, ol.View2D);
var resolution = view.getResolution();
var rotation = view.getRotation();
var newCenter = [-resolution * this.deltaX, resolution * this.deltaY];
ol.coordinate.rotate(newCenter, rotation);
var view2DState = view.getView2DState();
var newCenter = [
-view2DState.resolution * this.deltaX,
view2DState.resolution * this.deltaY
];
ol.coordinate.rotate(newCenter, view2DState.rotation);
ol.coordinate.add(newCenter, this.startCenter);
map.requestRenderFrame();
view.setCenter(newCenter);

View File

@@ -64,9 +64,8 @@ ol.interaction.KeyboardPan.prototype.handleMapBrowserEvent =
// FIXME works for View2D only
var view = map.getView();
goog.asserts.assertInstanceof(view, ol.View2D);
var resolution = view.getResolution();
var rotation = view.getRotation();
var mapUnitsDelta = resolution * this.delta_;
var view2DState = view.getView2DState();
var mapUnitsDelta = view2DState.resolution * this.delta_;
var deltaX = 0, deltaY = 0;
if (keyCode == goog.events.KeyCodes.DOWN) {
deltaY = -mapUnitsDelta;
@@ -78,7 +77,7 @@ ol.interaction.KeyboardPan.prototype.handleMapBrowserEvent =
deltaY = mapUnitsDelta;
}
var delta = [deltaX, deltaY];
ol.coordinate.rotate(delta, rotation);
ol.coordinate.rotate(delta, view2DState.rotation);
ol.interaction.Interaction.pan(
map, view, delta, ol.interaction.KEYBOARD_PAN_DURATION);
mapBrowserEvent.preventDefault();

View File

@@ -89,7 +89,8 @@ ol.View2D = function(opt_options) {
values[ol.View2DProperty.RESOLUTION] = resolutionConstraint(
this.maxResolution_, options.zoom);
}
values[ol.View2DProperty.ROTATION] = options.rotation;
values[ol.View2DProperty.ROTATION] =
goog.isDef(options.rotation) ? options.rotation : 0;
this.setValues(values);
};
goog.inherits(ol.View2D, ol.View);
@@ -254,12 +255,10 @@ ol.View2D.prototype.getResolutionForValueFunction = function(opt_power) {
/**
* Get the current rotation of this view.
* @return {number} Map rotation.
* @inheritDoc
*/
ol.View2D.prototype.getRotation = function() {
return /** @type {number|undefined} */ (
this.get(ol.View2DProperty.ROTATION)) || 0;
return /** @type {number|undefined} */ (this.get(ol.View2DProperty.ROTATION));
};
goog.exportProperty(
ol.View2D.prototype,
@@ -306,14 +305,14 @@ ol.View2D.prototype.getView2D = function() {
ol.View2D.prototype.getView2DState = function() {
goog.asserts.assert(this.isDef());
var center = /** @type {ol.Coordinate} */ (this.getCenter());
var projection = /** @type {ol.Projection} */ (this.getProjection());
var projection = this.getProjection();
var resolution = /** @type {number} */ (this.getResolution());
var rotation = /** @type {number} */ (this.getRotation());
var rotation = this.getRotation();
return {
center: center.slice(),
projection: projection,
projection: goog.isDef(projection) ? projection : null,
resolution: resolution,
rotation: rotation
rotation: goog.isDef(rotation) ? rotation : 0
};
};