Use view.getRotation and view.getResolution instead of view.getState

view.getState calls 4 functions and creates an object and an array.
It's more efficient to use view.getRotation and view.getResolution.
This commit is contained in:
Frederic Junod
2015-08-26 12:46:36 +02:00
parent 15ef7eec85
commit c1575e810b
2 changed files with 6 additions and 9 deletions

View File

@@ -88,16 +88,15 @@ ol.interaction.DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) {
var theta = Math.atan2(delta.y, delta.x);
var magnitude = delta.magnitude();
var view = map.getView();
var viewState = view.getState();
map.render();
if (goog.isDef(this.lastAngle_)) {
var angleDelta = theta - this.lastAngle_;
ol.interaction.Interaction.rotateWithoutConstraints(
map, view, viewState.rotation - angleDelta);
map, view, view.getRotation() - angleDelta);
}
this.lastAngle_ = theta;
if (goog.isDef(this.lastMagnitude_)) {
var resolution = this.lastMagnitude_ * (viewState.resolution / magnitude);
var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
ol.interaction.Interaction.zoomWithoutConstraints(map, view, resolution);
}
if (goog.isDef(this.lastMagnitude_)) {
@@ -121,10 +120,9 @@ ol.interaction.DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
var view = map.getView();
view.setHint(ol.ViewHint.INTERACTING, -1);
var viewState = view.getState();
var direction = this.lastScaleDelta_ - 1;
ol.interaction.Interaction.rotate(map, view, viewState.rotation);
ol.interaction.Interaction.zoom(map, view, viewState.resolution,
ol.interaction.Interaction.rotate(map, view, view.getRotation());
ol.interaction.Interaction.zoom(map, view, view.getResolution(),
undefined, this.duration_, direction);
this.lastScaleDelta_ = 0;
return false;

View File

@@ -83,8 +83,7 @@ ol.interaction.KeyboardPan.handleEvent = function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
var view = map.getView();
goog.asserts.assert(!goog.isNull(view), 'view should not be null');
var viewState = view.getState();
var mapUnitsDelta = viewState.resolution * this.pixelDelta_;
var mapUnitsDelta = view.getResolution() * this.pixelDelta_;
var deltaX = 0, deltaY = 0;
if (keyCode == goog.events.KeyCodes.DOWN) {
deltaY = -mapUnitsDelta;
@@ -96,7 +95,7 @@ ol.interaction.KeyboardPan.handleEvent = function(mapBrowserEvent) {
deltaY = mapUnitsDelta;
}
var delta = [deltaX, deltaY];
ol.coordinate.rotate(delta, viewState.rotation);
ol.coordinate.rotate(delta, view.getRotation());
ol.interaction.Interaction.pan(map, view, delta, this.duration_);
mapBrowserEvent.preventDefault();
stopEvent = true;