Separate internal and API methods for the view
This commit is contained in:
13
examples/geographic.html
Normal file
13
examples/geographic.html
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
layout: example.html
|
||||
title: Geographic Coordinates
|
||||
shortdesc: Using geographic coordinates for the map view.
|
||||
docs: >
|
||||
Calling the <code>useGeographic</code> function in the <code>'ol/proj'</code> module
|
||||
makes it so the map view uses geographic coordinates (even if the view projection is
|
||||
not geographic).
|
||||
tags: "geographic"
|
||||
---
|
||||
<div id="map" class="map"></div>
|
||||
<div id="info"></div>
|
||||
|
||||
27
examples/geographic.js
Normal file
27
examples/geographic.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import {useGeographic} from '../src/ol/proj.js';
|
||||
import Map from '../src/ol/Map.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import OSM from '../src/ol/source/OSM.js';
|
||||
|
||||
useGeographic();
|
||||
|
||||
const map = new Map({
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new OSM()
|
||||
})
|
||||
],
|
||||
target: 'map',
|
||||
view: new View({
|
||||
center: [-110, 45],
|
||||
zoom: 8
|
||||
})
|
||||
});
|
||||
|
||||
const info = document.getElementById('info');
|
||||
map.on('moveend', function() {
|
||||
const view = map.getView();
|
||||
const center = view.getCenter();
|
||||
info.innerText = `lon: ${center[0].toFixed(2)}, lat: ${center[1].toFixed(2)}`;
|
||||
});
|
||||
@@ -418,14 +418,14 @@ class Overlay extends BaseObject {
|
||||
}
|
||||
|
||||
if (delta[0] !== 0 || delta[1] !== 0) {
|
||||
const center = /** @type {import("./coordinate.js").Coordinate} */ (map.getView().getCenter());
|
||||
const center = /** @type {import("./coordinate.js").Coordinate} */ (map.getView().getCenterInternal());
|
||||
const centerPx = map.getPixelFromCoordinate(center);
|
||||
const newCenterPx = [
|
||||
centerPx[0] + delta[0],
|
||||
centerPx[1] + delta[1]
|
||||
];
|
||||
|
||||
map.getView().animate({
|
||||
map.getView().animateInternal({
|
||||
center: map.getCoordinateFromPixel(newCenterPx),
|
||||
duration: this.autoPanAnimation.duration,
|
||||
easing: this.autoPanAnimation.easing
|
||||
|
||||
171
src/ol/View.js
171
src/ol/View.js
@@ -19,7 +19,7 @@ import GeometryType from './geom/GeometryType.js';
|
||||
import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
|
||||
import {clamp, modulo} from './math.js';
|
||||
import {assign} from './obj.js';
|
||||
import {createProjection, METERS_PER_UNIT} from './proj.js';
|
||||
import {createProjection, METERS_PER_UNIT, toUserCoordinate, toUserExtent, fromUserCoordinate, fromUserExtent, getUserProjection} from './proj.js';
|
||||
import Units from './proj/Units.js';
|
||||
import {equals} from './coordinate.js';
|
||||
import {easeOut} from './easing.js';
|
||||
@@ -82,9 +82,9 @@ import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
/**
|
||||
* @typedef {Object} ViewOptions
|
||||
* @property {import("./coordinate.js").Coordinate} [center] The initial center for
|
||||
* the view. The coordinate system for the center is specified with the
|
||||
* `projection` option. Layer sources will not be fetched if this is not set,
|
||||
* but the center can be set later with {@link #setCenter}.
|
||||
* the view. If a user projection is not set, the coordinate system for the center is
|
||||
* specified with the `projection` option. Layer sources will not be fetched if this
|
||||
* is not set, but the center can be set later with {@link #setCenter}.
|
||||
* @property {boolean|number} [constrainRotation=true] Rotation constraint.
|
||||
* `false` means no constraint. `true` means no constraint, but snap to zero
|
||||
* near zero. A number constrains the rotation to that number of values. For
|
||||
@@ -309,6 +309,13 @@ class View extends BaseObject {
|
||||
*/
|
||||
this.targetRotation_;
|
||||
|
||||
if (options.center) {
|
||||
options.center = fromUserCoordinate(options.center, this.projection_);
|
||||
}
|
||||
if (options.extent) {
|
||||
options.extent = fromUserExtent(options.extent, this.projection_);
|
||||
}
|
||||
|
||||
this.applyOptions_(options);
|
||||
}
|
||||
|
||||
@@ -370,7 +377,7 @@ class View extends BaseObject {
|
||||
};
|
||||
|
||||
this.setRotation(options.rotation !== undefined ? options.rotation : 0);
|
||||
this.setCenter(options.center !== undefined ? options.center : null);
|
||||
this.setCenterInternal(options.center !== undefined ? options.center : null);
|
||||
if (options.resolution !== undefined) {
|
||||
this.setResolution(options.resolution);
|
||||
} else if (options.zoom !== undefined) {
|
||||
@@ -408,7 +415,7 @@ class View extends BaseObject {
|
||||
}
|
||||
|
||||
// preserve center
|
||||
options.center = this.getCenter();
|
||||
options.center = this.getCenterInternal();
|
||||
|
||||
// preserve rotation
|
||||
options.rotation = this.getRotation();
|
||||
@@ -453,14 +460,26 @@ class View extends BaseObject {
|
||||
if (this.isDef() && !this.getAnimating()) {
|
||||
this.resolveConstraints(0);
|
||||
}
|
||||
this.animate_.apply(this, arguments);
|
||||
const args = new Array(arguments.length);
|
||||
for (let i = 0; i < args.length; ++i) {
|
||||
let options = arguments[i];
|
||||
if (options.center) {
|
||||
options = assign({}, options);
|
||||
options.center = fromUserCoordinate(options.center, this.getProjection());
|
||||
}
|
||||
if (options.anchor) {
|
||||
options = assign({}, options);
|
||||
options.anchor = fromUserCoordinate(options.anchor, this.getProjection());
|
||||
}
|
||||
args[i] = options;
|
||||
}
|
||||
this.animateInternal.apply(this, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {...(AnimationOptions|function(boolean): void)} var_args Animation options.
|
||||
*/
|
||||
animate_(var_args) {
|
||||
animateInternal(var_args) {
|
||||
let animationCount = arguments.length;
|
||||
let callback;
|
||||
if (animationCount > 1 && typeof arguments[animationCount - 1] === 'function') {
|
||||
@@ -471,7 +490,7 @@ class View extends BaseObject {
|
||||
// if view properties are not yet set, shortcut to the final state
|
||||
const state = arguments[animationCount - 1];
|
||||
if (state.center) {
|
||||
this.setCenter(state.center);
|
||||
this.setCenterInternal(state.center);
|
||||
}
|
||||
if (state.zoom !== undefined) {
|
||||
this.setZoom(state.zoom);
|
||||
@@ -661,7 +680,7 @@ class View extends BaseObject {
|
||||
*/
|
||||
calculateCenterRotate(rotation, anchor) {
|
||||
let center;
|
||||
const currentCenter = this.getCenter();
|
||||
const currentCenter = this.getCenterInternal();
|
||||
if (currentCenter !== undefined) {
|
||||
center = [currentCenter[0] - anchor[0], currentCenter[1] - anchor[1]];
|
||||
rotateCoordinate(center, rotation - this.getRotation());
|
||||
@@ -677,7 +696,7 @@ class View extends BaseObject {
|
||||
*/
|
||||
calculateCenterZoom(resolution, anchor) {
|
||||
let center;
|
||||
const currentCenter = this.getCenter();
|
||||
const currentCenter = this.getCenterInternal();
|
||||
const currentResolution = this.getResolution();
|
||||
if (currentCenter !== undefined && currentResolution !== undefined) {
|
||||
const x = anchor[0] - resolution * (anchor[0] - currentCenter[0]) / currentResolution;
|
||||
@@ -717,9 +736,19 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getCenter() {
|
||||
return (
|
||||
/** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(ViewProperty.CENTER))
|
||||
);
|
||||
const center = this.getCenterInternal();
|
||||
if (!center) {
|
||||
return center;
|
||||
}
|
||||
return toUserCoordinate(center, this.getProjection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view center without transforming to user projection.
|
||||
* @return {import("./coordinate.js").Coordinate|undefined} The center of the view.
|
||||
*/
|
||||
getCenterInternal() {
|
||||
return /** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(ViewProperty.CENTER));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -754,8 +783,18 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
calculateExtent(opt_size) {
|
||||
const extent = this.calculateExtentInternal(opt_size);
|
||||
return toUserExtent(extent, this.getProjection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./size.js").Size=} opt_size Box pixel size. If not provided, the size of the
|
||||
* first map that uses this view will be used.
|
||||
* @return {import("./extent.js").Extent} Extent.
|
||||
*/
|
||||
calculateExtentInternal(opt_size) {
|
||||
const size = opt_size || this.getSizeFromViewport_();
|
||||
const center = /** @type {!import("./coordinate.js").Coordinate} */ (this.getCenter());
|
||||
const center = /** @type {!import("./coordinate.js").Coordinate} */ (this.getCenterInternal());
|
||||
assert(center, 1); // The view center is not defined
|
||||
const resolution = /** @type {!number} */ (this.getResolution());
|
||||
assert(resolution !== undefined, 2); // The view resolution is not defined
|
||||
@@ -866,6 +905,17 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getResolutionForExtent(extent, opt_size) {
|
||||
return this.getResolutionForExtentInternal(fromUserExtent(extent, this.getProjection()), opt_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resolution for a provided extent (in map units) and size (in pixels).
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {import("./size.js").Size=} opt_size Box pixel size.
|
||||
* @return {number} The resolution at which the provided extent will render at
|
||||
* the given size.
|
||||
*/
|
||||
getResolutionForExtentInternal(extent, opt_size) {
|
||||
const size = opt_size || this.getSizeFromViewport_();
|
||||
const xResolution = getWidth(extent) / size[0];
|
||||
const yResolution = getHeight(extent) / size[1];
|
||||
@@ -930,7 +980,7 @@ class View extends BaseObject {
|
||||
* @return {State} View state.
|
||||
*/
|
||||
getState() {
|
||||
const center = /** @type {import("./coordinate.js").Coordinate} */ (this.getCenter());
|
||||
const center = /** @type {import("./coordinate.js").Coordinate} */ (this.getCenterInternal());
|
||||
const projection = this.getProjection();
|
||||
const resolution = /** @type {number} */ (this.getResolution());
|
||||
const rotation = this.getRotation();
|
||||
@@ -1014,11 +1064,8 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
fit(geometryOrExtent, opt_options) {
|
||||
const options = opt_options || {};
|
||||
let size = options.size;
|
||||
if (!size) {
|
||||
size = this.getSizeFromViewport_();
|
||||
}
|
||||
const options = assign({size: this.getSizeFromViewport_()}, opt_options || {});
|
||||
|
||||
/** @type {import("./geom/SimpleGeometry.js").default} */
|
||||
let geometry;
|
||||
assert(Array.isArray(geometryOrExtent) || typeof /** @type {?} */ (geometryOrExtent).getSimplifiedGeometry === 'function',
|
||||
@@ -1026,15 +1073,34 @@ class View extends BaseObject {
|
||||
if (Array.isArray(geometryOrExtent)) {
|
||||
assert(!isEmpty(geometryOrExtent),
|
||||
25); // Cannot fit empty extent provided as `geometry`
|
||||
geometry = polygonFromExtent(geometryOrExtent);
|
||||
const extent = fromUserExtent(geometryOrExtent, this.getProjection());
|
||||
geometry = polygonFromExtent(extent);
|
||||
} else if (geometryOrExtent.getType() === GeometryType.CIRCLE) {
|
||||
geometryOrExtent = geometryOrExtent.getExtent();
|
||||
geometry = polygonFromExtent(geometryOrExtent);
|
||||
geometry.rotate(this.getRotation(), getCenter(geometryOrExtent));
|
||||
const extent = fromUserExtent(geometryOrExtent.getExtent(), this.getProjection());
|
||||
geometry = polygonFromExtent(extent);
|
||||
geometry.rotate(this.getRotation(), getCenter(extent));
|
||||
} else {
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection) {
|
||||
geometry = /** @type {import("./geom/SimpleGeometry.js").default} */ (geometry.clone().transform(userProjection, this.getProjection()));
|
||||
} else {
|
||||
geometry = geometryOrExtent;
|
||||
}
|
||||
}
|
||||
|
||||
this.fitInternal(geometry, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./geom/SimpleGeometry.js").default} geometry The geometry.
|
||||
* @param {FitOptions=} opt_options Options.
|
||||
*/
|
||||
fitInternal(geometry, opt_options) {
|
||||
const options = opt_options || {};
|
||||
let size = options.size;
|
||||
if (!size) {
|
||||
size = this.getSizeFromViewport_();
|
||||
}
|
||||
const padding = options.padding !== undefined ? options.padding : [0, 0, 0, 0];
|
||||
const nearest = options.nearest !== undefined ? options.nearest : false;
|
||||
let minResolution;
|
||||
@@ -1066,7 +1132,7 @@ class View extends BaseObject {
|
||||
}
|
||||
|
||||
// calculate resolution
|
||||
let resolution = this.getResolutionForExtent(
|
||||
let resolution = this.getResolutionForExtentInternal(
|
||||
[minRotX, minRotY, maxRotX, maxRotY],
|
||||
[size[0] - padding[1] - padding[3], size[1] - padding[0] - padding[2]]);
|
||||
resolution = isNaN(resolution) ? minResolution :
|
||||
@@ -1085,7 +1151,7 @@ class View extends BaseObject {
|
||||
const callback = options.callback ? options.callback : VOID;
|
||||
|
||||
if (options.duration !== undefined) {
|
||||
this.animate_({
|
||||
this.animateInternal({
|
||||
resolution: resolution,
|
||||
center: this.getConstrainedCenter(center, resolution),
|
||||
duration: options.duration,
|
||||
@@ -1107,6 +1173,15 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
centerOn(coordinate, size, position) {
|
||||
this.centerOnInternal(fromUserCoordinate(coordinate, this.getProjection()), size, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
|
||||
* @param {import("./size.js").Size} size Box pixel size.
|
||||
* @param {import("./pixel.js").Pixel} position Position on the view to center on.
|
||||
*/
|
||||
centerOnInternal(coordinate, size, position) {
|
||||
// calculate rotated position
|
||||
const rotation = this.getRotation();
|
||||
const cosAngle = Math.cos(-rotation);
|
||||
@@ -1122,14 +1197,14 @@ class View extends BaseObject {
|
||||
const centerX = rotX * cosAngle - rotY * sinAngle;
|
||||
const centerY = rotY * cosAngle + rotX * sinAngle;
|
||||
|
||||
this.setCenter([centerX, centerY]);
|
||||
this.setCenterInternal([centerX, centerY]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean} Is defined.
|
||||
*/
|
||||
isDef() {
|
||||
return !!this.getCenter() && this.getResolution() !== undefined;
|
||||
return !!this.getCenterInternal() && this.getResolution() !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1138,10 +1213,19 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
adjustCenter(deltaCoordinates) {
|
||||
const center = this.targetCenter_;
|
||||
const center = toUserCoordinate(this.targetCenter_, this.getProjection());
|
||||
this.setCenter([center[0] + deltaCoordinates[0], center[1] + deltaCoordinates[1]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds relative coordinates to the center of the view. Any extent constraint will apply.
|
||||
* @param {import("./coordinate.js").Coordinate} deltaCoordinates Relative value to add.
|
||||
*/
|
||||
adjustCenterInternal(deltaCoordinates) {
|
||||
const center = this.targetCenter_;
|
||||
this.setCenterInternal([center[0] + deltaCoordinates[0], center[1] + deltaCoordinates[1]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
|
||||
* constraint will apply.
|
||||
@@ -1181,6 +1265,17 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
adjustRotation(delta, opt_anchor) {
|
||||
if (opt_anchor) {
|
||||
opt_anchor = fromUserCoordinate(opt_anchor, this.getProjection());
|
||||
}
|
||||
this.adjustRotationInternal(delta, opt_anchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} delta Relative value to add to the zoom rotation, in radians.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The rotation center.
|
||||
*/
|
||||
adjustRotationInternal(delta, opt_anchor) {
|
||||
const isMoving = this.getAnimating() || this.getInteracting();
|
||||
const newRotation = this.constraints_.rotation(this.targetRotation_ + delta, isMoving);
|
||||
if (opt_anchor !== undefined) {
|
||||
@@ -1197,6 +1292,14 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
setCenter(center) {
|
||||
this.setCenterInternal(fromUserCoordinate(center, this.getProjection()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the center using the view projection (not the user projection).
|
||||
* @param {import("./coordinate.js").Coordinate|undefined} center The center of the view.
|
||||
*/
|
||||
setCenterInternal(center) {
|
||||
this.targetCenter_ = center;
|
||||
this.applyTargetState_();
|
||||
}
|
||||
@@ -1303,14 +1406,14 @@ class View extends BaseObject {
|
||||
|
||||
if (this.getResolution() !== newResolution ||
|
||||
this.getRotation() !== newRotation ||
|
||||
!this.getCenter() ||
|
||||
!equals(this.getCenter(), newCenter)) {
|
||||
!this.getCenterInternal() ||
|
||||
!equals(this.getCenterInternal(), newCenter)) {
|
||||
|
||||
if (this.getAnimating()) {
|
||||
this.cancelAnimations();
|
||||
}
|
||||
|
||||
this.animate_({
|
||||
this.animateInternal({
|
||||
rotation: newRotation,
|
||||
center: newCenter,
|
||||
resolution: newResolution,
|
||||
|
||||
@@ -11,6 +11,7 @@ import Overlay from '../Overlay.js';
|
||||
import OverlayPositioning from '../OverlayPositioning.js';
|
||||
import ViewProperty from '../ViewProperty.js';
|
||||
import Control from './Control.js';
|
||||
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE, CLASS_COLLAPSED} from '../css.js';
|
||||
import {replaceNode} from '../dom.js';
|
||||
import {listen, listenOnce} from '../events.js';
|
||||
@@ -230,7 +231,7 @@ class OverviewMap extends Control {
|
||||
const endMoving = function(event) {
|
||||
const coordinates = ovmap.getEventCoordinate(event);
|
||||
|
||||
scope.getMap().getView().setCenter(coordinates);
|
||||
scope.getMap().getView().setCenterInternal(coordinates);
|
||||
|
||||
window.removeEventListener('mousemove', move);
|
||||
window.removeEventListener('mouseup', endMoving);
|
||||
@@ -346,7 +347,7 @@ class OverviewMap extends Control {
|
||||
const mapSize = /** @type {import("../size.js").Size} */ (map.getSize());
|
||||
|
||||
const view = map.getView();
|
||||
const extent = view.calculateExtent(mapSize);
|
||||
const extent = view.calculateExtentInternal(mapSize);
|
||||
|
||||
if (this.viewExtent_ && equalsExtent(extent, this.viewExtent_)) {
|
||||
// repeats of the same extent may indicate constraint conflicts leading to an endless cycle
|
||||
@@ -357,7 +358,7 @@ class OverviewMap extends Control {
|
||||
const ovmapSize = /** @type {import("../size.js").Size} */ (ovmap.getSize());
|
||||
|
||||
const ovview = ovmap.getView();
|
||||
const ovextent = ovview.calculateExtent(ovmapSize);
|
||||
const ovextent = ovview.calculateExtentInternal(ovmapSize);
|
||||
|
||||
const topLeftPixel =
|
||||
ovmap.getPixelFromCoordinate(getTopLeft(extent));
|
||||
@@ -396,7 +397,7 @@ class OverviewMap extends Control {
|
||||
const mapSize = /** @type {import("../size.js").Size} */ (map.getSize());
|
||||
|
||||
const view = map.getView();
|
||||
const extent = view.calculateExtent(mapSize);
|
||||
const extent = view.calculateExtentInternal(mapSize);
|
||||
|
||||
const ovview = ovmap.getView();
|
||||
|
||||
@@ -407,7 +408,7 @@ class OverviewMap extends Control {
|
||||
MAX_RATIO / MIN_RATIO) / Math.LN2;
|
||||
const ratio = 1 / (Math.pow(2, steps / 2) * MIN_RATIO);
|
||||
scaleFromCenter(extent, ratio);
|
||||
ovview.fit(extent);
|
||||
ovview.fitInternal(polygonFromExtent(extent));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -423,7 +424,7 @@ class OverviewMap extends Control {
|
||||
|
||||
const ovview = ovmap.getView();
|
||||
|
||||
ovview.setCenter(view.getCenter());
|
||||
ovview.setCenterInternal(view.getCenterInternal());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -448,7 +449,7 @@ class OverviewMap extends Control {
|
||||
|
||||
const overlay = this.boxOverlay_;
|
||||
const box = this.boxOverlay_.getElement();
|
||||
const center = view.getCenter();
|
||||
const center = view.getCenterInternal();
|
||||
const resolution = view.getResolution();
|
||||
const ovresolution = ovview.getResolution();
|
||||
const width = mapSize[0] * resolution / ovresolution;
|
||||
|
||||
@@ -204,7 +204,7 @@ class ZoomSlider extends Control {
|
||||
const resolution = this.getResolutionForPosition_(relativePosition);
|
||||
const zoom = view.getConstrainedZoom(view.getZoomForResolution(resolution));
|
||||
|
||||
view.animate({
|
||||
view.animateInternal({
|
||||
zoom: zoom,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* @module ol/control/ZoomToExtent
|
||||
*/
|
||||
import EventType from '../events/EventType.js';
|
||||
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
import Control from './Control.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
|
||||
@@ -80,7 +81,7 @@ class ZoomToExtent extends Control {
|
||||
const map = this.getMap();
|
||||
const view = map.getView();
|
||||
const extent = !this.extent ? view.getProjection().getExtent() : this.extent;
|
||||
view.fit(extent);
|
||||
view.fitInternal(polygonFromExtent(extent));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ class DragPan extends PointerInteraction {
|
||||
const view = map.getView();
|
||||
scaleCoordinate(delta, view.getResolution());
|
||||
rotateCoordinate(delta, view.getRotation());
|
||||
view.adjustCenter(delta);
|
||||
view.adjustCenterInternal(delta);
|
||||
}
|
||||
} else if (this.kinetic_) {
|
||||
// reset so we don't overestimate the kinetic energy after
|
||||
@@ -113,13 +113,13 @@ class DragPan extends PointerInteraction {
|
||||
if (!this.noKinetic_ && this.kinetic_ && this.kinetic_.end()) {
|
||||
const distance = this.kinetic_.getDistance();
|
||||
const angle = this.kinetic_.getAngle();
|
||||
const center = /** @type {!import("../coordinate.js").Coordinate} */ (view.getCenter());
|
||||
const center = view.getCenterInternal();
|
||||
const centerpx = map.getPixelFromCoordinate(center);
|
||||
const dest = map.getCoordinateFromPixel([
|
||||
centerpx[0] - distance * Math.cos(angle),
|
||||
centerpx[1] - distance * Math.sin(angle)
|
||||
]);
|
||||
view.animate({
|
||||
view.animateInternal({
|
||||
center: view.getConstrainedCenter(dest),
|
||||
duration: 500,
|
||||
easing: easeOut
|
||||
|
||||
@@ -78,7 +78,7 @@ class DragRotate extends PointerInteraction {
|
||||
Math.atan2(size[1] / 2 - offset[1], offset[0] - size[0] / 2);
|
||||
if (this.lastAngle_ !== undefined) {
|
||||
const delta = theta - this.lastAngle_;
|
||||
view.adjustRotation(-delta);
|
||||
view.adjustRotationInternal(-delta);
|
||||
}
|
||||
this.lastAngle_ = theta;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class DragRotateAndZoom extends PointerInteraction {
|
||||
const view = map.getView();
|
||||
if (this.lastAngle_ !== undefined) {
|
||||
const angleDelta = this.lastAngle_ - theta;
|
||||
view.adjustRotation(angleDelta);
|
||||
view.adjustRotationInternal(angleDelta);
|
||||
}
|
||||
this.lastAngle_ = theta;
|
||||
if (this.lastMagnitude_ !== undefined) {
|
||||
|
||||
@@ -73,20 +73,20 @@ function onBoxEnd() {
|
||||
let extent = this.getGeometry().getExtent();
|
||||
|
||||
if (this.out_) {
|
||||
const mapExtent = view.calculateExtent(size);
|
||||
const mapExtent = view.calculateExtentInternal(size);
|
||||
const boxPixelExtent = createOrUpdateFromCoordinates([
|
||||
map.getPixelFromCoordinate(getBottomLeft(extent)),
|
||||
map.getPixelFromCoordinate(getTopRight(extent))]);
|
||||
const factor = view.getResolutionForExtent(boxPixelExtent, size);
|
||||
const factor = view.getResolutionForExtentInternal(boxPixelExtent, size);
|
||||
|
||||
scaleFromCenter(mapExtent, 1 / factor);
|
||||
extent = mapExtent;
|
||||
}
|
||||
|
||||
const resolution = view.getConstrainedResolution(view.getResolutionForExtent(extent, size));
|
||||
const resolution = view.getConstrainedResolution(view.getResolutionForExtentInternal(extent, size));
|
||||
const center = view.getConstrainedCenter(getCenter(extent), resolution);
|
||||
|
||||
view.animate({
|
||||
view.animateInternal({
|
||||
resolution: resolution,
|
||||
center: center,
|
||||
duration: this.duration_,
|
||||
|
||||
@@ -108,10 +108,10 @@ class Interaction extends BaseObject {
|
||||
* @param {number=} opt_duration Duration.
|
||||
*/
|
||||
export function pan(view, delta, opt_duration) {
|
||||
const currentCenter = view.getCenter();
|
||||
const currentCenter = view.getCenterInternal();
|
||||
if (currentCenter) {
|
||||
const center = [currentCenter[0] + delta[0], currentCenter[1] + delta[1]];
|
||||
view.animate_({
|
||||
view.animateInternal({
|
||||
duration: opt_duration !== undefined ? opt_duration : 250,
|
||||
easing: linear,
|
||||
center: view.getConstrainedCenter(center)
|
||||
@@ -138,7 +138,7 @@ export function zoomByDelta(view, delta, opt_anchor, opt_duration) {
|
||||
if (view.getAnimating()) {
|
||||
view.cancelAnimations();
|
||||
}
|
||||
view.animate({
|
||||
view.animateInternal({
|
||||
resolution: newResolution,
|
||||
anchor: opt_anchor,
|
||||
duration: opt_duration !== undefined ? opt_duration : 250,
|
||||
|
||||
@@ -117,7 +117,7 @@ class PinchRotate extends PointerInteraction {
|
||||
// rotate
|
||||
if (this.rotating_) {
|
||||
map.render();
|
||||
view.adjustRotation(rotationDelta, this.anchor_);
|
||||
view.adjustRotationInternal(rotationDelta, this.anchor_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ describe('ol.interaction.DragZoom', function() {
|
||||
interaction.onBoxEnd_();
|
||||
setTimeout(function() {
|
||||
const view = map.getView();
|
||||
const center = view.getCenter();
|
||||
const center = view.getCenterInternal();
|
||||
expect(center).to.eql(getCenter(extent));
|
||||
done();
|
||||
}, 50);
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('ol.interaction.KeyboardPan', function() {
|
||||
describe('handleEvent()', function() {
|
||||
it('pans on arrow keys', function() {
|
||||
const view = map.getView();
|
||||
const spy = sinon.spy(view, 'animate_');
|
||||
const spy = sinon.spy(view, 'animateInternal');
|
||||
const event = new MapBrowserEvent('keydown', map, {
|
||||
type: 'keydown',
|
||||
target: map.getTargetElement(),
|
||||
@@ -51,7 +51,7 @@ describe('ol.interaction.KeyboardPan', function() {
|
||||
expect(spy.getCall(3).args[0].center).to.eql([128, 0]);
|
||||
view.setCenter([0, 0]);
|
||||
|
||||
view.animate_.restore();
|
||||
view.animateInternal.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('ol.interaction.KeyboardZoom', function() {
|
||||
describe('handleEvent()', function() {
|
||||
it('zooms on + and - keys', function() {
|
||||
const view = map.getView();
|
||||
const spy = sinon.spy(view, 'animate');
|
||||
const spy = sinon.spy(view, 'animateInternal');
|
||||
const event = new MapBrowserEvent('keydown', map, {
|
||||
type: 'keydown',
|
||||
target: map.getTargetElement(),
|
||||
@@ -41,7 +41,7 @@ describe('ol.interaction.KeyboardZoom', function() {
|
||||
expect(spy.getCall(1).args[0].resolution).to.eql(4);
|
||||
view.setResolution(2);
|
||||
|
||||
view.animate.restore();
|
||||
view.animateInternal.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -99,20 +99,20 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
});
|
||||
}
|
||||
|
||||
describe('spying on view.animate()', function() {
|
||||
describe('spying on view.animateInternal()', function() {
|
||||
let view;
|
||||
beforeEach(function() {
|
||||
view = map.getView();
|
||||
sinon.spy(view, 'animate');
|
||||
sinon.spy(view, 'animateInternal');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
view.animate.restore();
|
||||
view.animateInternal.restore();
|
||||
});
|
||||
|
||||
it('works in DOM_DELTA_LINE mode (wheel)', function(done) {
|
||||
map.once('postrender', function() {
|
||||
const call = view.animate.getCall(0);
|
||||
const call = view.animateInternal.getCall(0);
|
||||
expect(call.args[0].resolution).to.be(2);
|
||||
expect(call.args[0].anchor).to.eql([0, 0]);
|
||||
done();
|
||||
@@ -132,7 +132,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
|
||||
it('works on all browsers (wheel)', function(done) {
|
||||
map.once('postrender', function() {
|
||||
const call = view.animate.getCall(0);
|
||||
const call = view.animateInternal.getCall(0);
|
||||
expect(call.args[0].resolution).to.be(2);
|
||||
expect(call.args[0].anchor).to.eql([0, 0]);
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user