Fix dragzoom with rotated view

When the view is rotated the extent of the drag box is not the same as the
drag box.
This commit is contained in:
Maximilian Krög
2021-05-08 02:10:05 +02:00
parent b89809c1a1
commit c19ebc72cb
2 changed files with 47 additions and 49 deletions

View File

@@ -2,14 +2,7 @@
* @module ol/interaction/DragZoom
*/
import DragBox from './DragBox.js';
import {
createOrUpdateFromCoordinates,
getBottomLeft,
getTopRight,
scaleFromCenter,
} from '../extent.js';
import {easeOut} from '../easing.js';
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
import {shiftKeyOnly} from '../events/condition.js';
/**
@@ -71,22 +64,17 @@ class DragZoom extends DragBox {
onBoxEnd(event) {
const map = this.getMap();
const view = /** @type {!import("../View.js").default} */ (map.getView());
let extent = this.getGeometry().getExtent();
let geometry = this.getGeometry();
if (this.out_) {
const size = /** @type {!import("../size.js").Size} */ (map.getSize());
const mapExtent = view.calculateExtentInternal(size);
const boxPixelExtent = createOrUpdateFromCoordinates([
map.getPixelFromCoordinateInternal(getBottomLeft(extent)),
map.getPixelFromCoordinateInternal(getTopRight(extent)),
]);
const factor = view.getResolutionForExtentInternal(boxPixelExtent, size);
scaleFromCenter(mapExtent, 1 / factor);
extent = mapExtent;
const rotatedExtent = view.rotatedExtentForGeometry(geometry);
const resolution = view.getResolutionForExtentInternal(rotatedExtent);
const factor = view.getResolution() / resolution;
geometry = geometry.clone();
geometry.scale(factor * factor);
}
view.fitInternal(polygonFromExtent(extent), {
view.fitInternal(geometry, {
duration: this.duration_,
easing: easeOut,
});