Remove opt_ prefix

This commit is contained in:
Tim Schaub
2022-08-11 17:46:31 -06:00
committed by Tim Schaub
parent dd1edc37ca
commit 99612e7f9a
183 changed files with 1918 additions and 2079 deletions

View File

@@ -288,7 +288,7 @@ const DEFAULT_MIN_ZOOM = 0;
* A consequence of this is that, when applying a delta on the view state, one
* should use `adjustCenter`, `adjustRotation`, `adjustZoom` and `adjustResolution`
* rather than the corresponding setters. This will let view do its internal
* computations. Besides, the `adjust*` methods also take an `opt_anchor`
* computations. Besides, the `adjust*` methods also take an `anchor`
* argument which allows specifying an origin for the transformation.
*
* ### Interacting with the view
@@ -303,9 +303,9 @@ const DEFAULT_MIN_ZOOM = 0;
*/
class View extends BaseObject {
/**
* @param {ViewOptions} [opt_options] View options.
* @param {ViewOptions} [options] View options.
*/
constructor(opt_options) {
constructor(options) {
super();
/***
@@ -323,7 +323,7 @@ class View extends BaseObject {
*/
this.un;
const options = Object.assign({}, opt_options);
options = Object.assign({}, options);
/**
* @private
@@ -896,19 +896,17 @@ class View extends BaseObject {
/**
* Returns the current viewport size.
* @private
* @param {number} [opt_rotation] Take into account the rotation of the viewport when giving the size
* @param {number} [rotation] Take into account the rotation of the viewport when giving the size
* @return {import("./size.js").Size} Viewport size or `[100, 100]` when no viewport is found.
*/
getViewportSize_(opt_rotation) {
getViewportSize_(rotation) {
const size = this.viewportSize_;
if (opt_rotation) {
if (rotation) {
const w = size[0];
const h = size[1];
return [
Math.abs(w * Math.cos(opt_rotation)) +
Math.abs(h * Math.sin(opt_rotation)),
Math.abs(w * Math.sin(opt_rotation)) +
Math.abs(h * Math.cos(opt_rotation)),
Math.abs(w * Math.cos(rotation)) + Math.abs(h * Math.sin(rotation)),
Math.abs(w * Math.sin(rotation)) + Math.abs(h * Math.cos(rotation)),
];
} else {
return size;
@@ -920,12 +918,10 @@ class View extends BaseObject {
* to avoid performance hit and layout reflow.
* This should be done on map size change.
* Note: the constraints are not resolved during an animation to avoid stopping it
* @param {import("./size.js").Size} [opt_size] Viewport size; if undefined, [100, 100] is assumed
* @param {import("./size.js").Size} [size] Viewport size; if undefined, [100, 100] is assumed
*/
setViewportSize(opt_size) {
this.viewportSize_ = Array.isArray(opt_size)
? opt_size.slice()
: [100, 100];
setViewportSize(size) {
this.viewportSize_ = Array.isArray(size) ? size.slice() : [100, 100];
if (!this.getAnimating()) {
this.resolveConstraints(0);
}
@@ -970,14 +966,14 @@ class View extends BaseObject {
}
/**
* @param {Array<number>} [opt_hints] Destination array.
* @param {Array<number>} [hints] Destination array.
* @return {Array<number>} Hint.
*/
getHints(opt_hints) {
if (opt_hints !== undefined) {
opt_hints[0] = this.hints_[0];
opt_hints[1] = this.hints_[1];
return opt_hints;
getHints(hints) {
if (hints !== undefined) {
hints[0] = this.hints_[0];
hints[1] = this.hints_[1];
return hints;
} else {
return this.hints_.slice();
}
@@ -988,23 +984,23 @@ class View extends BaseObject {
* The size is the pixel dimensions of the box into which the calculated extent
* should fit. In most cases you want to get the extent of the entire map,
* that is `map.getSize()`.
* @param {import("./size.js").Size} [opt_size] Box pixel size. If not provided, the size
* @param {import("./size.js").Size} [size] Box pixel size. If not provided, the size
* of the map that uses this view will be used.
* @return {import("./extent.js").Extent} Extent.
* @api
*/
calculateExtent(opt_size) {
const extent = this.calculateExtentInternal(opt_size);
calculateExtent(size) {
const extent = this.calculateExtentInternal(size);
return toUserExtent(extent, this.getProjection());
}
/**
* @param {import("./size.js").Size} [opt_size] Box pixel size. If not provided,
* @param {import("./size.js").Size} [size] Box pixel size. If not provided,
* the map's last known viewport size will be used.
* @return {import("./extent.js").Extent} Extent.
*/
calculateExtentInternal(opt_size) {
const size = opt_size || this.getViewportSizeMinusPadding_();
calculateExtentInternal(size) {
size = size || this.getViewportSizeMinusPadding_();
const center = /** @type {!import("./coordinate.js").Coordinate} */ (
this.getCenterInternal()
);
@@ -1116,27 +1112,27 @@ class View extends BaseObject {
/**
* 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.
* @param {import("./size.js").Size} [size] Box pixel size.
* @return {number} The resolution at which the provided extent will render at
* the given size.
* @api
*/
getResolutionForExtent(extent, opt_size) {
getResolutionForExtent(extent, size) {
return this.getResolutionForExtentInternal(
fromUserExtent(extent, this.getProjection()),
opt_size
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.
* @param {import("./size.js").Size} [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.getViewportSizeMinusPadding_();
getResolutionForExtentInternal(extent, size) {
size = size || this.getViewportSizeMinusPadding_();
const xResolution = getWidth(extent) / size[0];
const yResolution = getHeight(extent) / size[1];
return Math.max(xResolution, yResolution);
@@ -1145,11 +1141,11 @@ class View extends BaseObject {
/**
* Return a function that returns a value between 0 and 1 for a
* resolution. Exponential scaling is assumed.
* @param {number} [opt_power] Power.
* @param {number} [power] Power.
* @return {function(number): number} Resolution for value function.
*/
getResolutionForValueFunction(opt_power) {
const power = opt_power || 2;
getResolutionForValueFunction(power) {
power = power || 2;
const maxResolution = this.getConstrainedResolution(this.maxResolution_);
const minResolution = this.minResolution_;
const max = Math.log(maxResolution / minResolution) / Math.log(power);
@@ -1178,11 +1174,11 @@ class View extends BaseObject {
/**
* Return a function that returns a resolution for a value between
* 0 and 1. Exponential scaling is assumed.
* @param {number} [opt_power] Power.
* @param {number} [power] Power.
* @return {function(number): number} Value for resolution function.
*/
getValueForResolutionFunction(opt_power) {
const logPower = Math.log(opt_power || 2);
getValueForResolutionFunction(power) {
const logPower = Math.log(power || 2);
const maxResolution = this.getConstrainedResolution(this.maxResolution_);
const minResolution = this.minResolution_;
const max = Math.log(maxResolution / minResolution) / logPower;
@@ -1201,11 +1197,11 @@ class View extends BaseObject {
/**
* Returns the size of the viewport minus padding.
* @private
* @param {number} [opt_rotation] Take into account the rotation of the viewport when giving the size
* @param {number} [rotation] Take into account the rotation of the viewport when giving the size
* @return {import("./size.js").Size} Viewport size reduced by the padding.
*/
getViewportSizeMinusPadding_(opt_rotation) {
let size = this.getViewportSize_(opt_rotation);
getViewportSizeMinusPadding_(rotation) {
let size = this.getViewportSize_(rotation);
const padding = this.padding_;
if (padding) {
size = [
@@ -1326,10 +1322,10 @@ class View extends BaseObject {
* Takes care of the map angle.
* @param {import("./geom/SimpleGeometry.js").default|import("./extent.js").Extent} geometryOrExtent The geometry or
* extent to fit the view to.
* @param {FitOptions} [opt_options] Options.
* @param {FitOptions} [options] Options.
* @api
*/
fit(geometryOrExtent, opt_options) {
fit(geometryOrExtent, options) {
/** @type {import("./geom/SimpleGeometry.js").default} */
let geometry;
assert(
@@ -1362,7 +1358,7 @@ class View extends BaseObject {
}
}
this.fitInternal(geometry, opt_options);
this.fitInternal(geometry, options);
}
/**
@@ -1393,10 +1389,10 @@ class View extends BaseObject {
/**
* @param {import("./geom/SimpleGeometry.js").default} geometry The geometry.
* @param {FitOptions} [opt_options] Options.
* @param {FitOptions} [options] Options.
*/
fitInternal(geometry, opt_options) {
const options = opt_options || {};
fitInternal(geometry, options) {
options = options || {};
let size = options.size;
if (!size) {
size = this.getViewportSizeMinusPadding_();
@@ -1551,12 +1547,11 @@ class View extends BaseObject {
* Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
* constraint will apply.
* @param {number} ratio The ratio to apply on the view resolution.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
* @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
* @api
*/
adjustResolution(ratio, opt_anchor) {
const anchor =
opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection());
adjustResolution(ratio, anchor) {
anchor = anchor && fromUserCoordinate(anchor, this.getProjection());
this.adjustResolutionInternal(ratio, anchor);
}
@@ -1564,9 +1559,9 @@ class View extends BaseObject {
* Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
* constraint will apply.
* @param {number} ratio The ratio to apply on the view resolution.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
* @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
*/
adjustResolutionInternal(ratio, opt_anchor) {
adjustResolutionInternal(ratio, anchor) {
const isMoving = this.getAnimating() || this.getInteracting();
const size = this.getViewportSize_(this.getRotation());
const newResolution = this.constraints_.resolution(
@@ -1576,8 +1571,8 @@ class View extends BaseObject {
isMoving
);
if (opt_anchor) {
this.targetCenter_ = this.calculateCenterZoom(newResolution, opt_anchor);
if (anchor) {
this.targetCenter_ = this.calculateCenterZoom(newResolution, anchor);
}
this.targetResolution_ *= ratio;
@@ -1588,39 +1583,39 @@ class View extends BaseObject {
* Adds a value to the view zoom level, optionally using an anchor. Any resolution
* constraint will apply.
* @param {number} delta Relative value to add to the zoom level.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
* @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
* @api
*/
adjustZoom(delta, opt_anchor) {
this.adjustResolution(Math.pow(this.zoomFactor_, -delta), opt_anchor);
adjustZoom(delta, anchor) {
this.adjustResolution(Math.pow(this.zoomFactor_, -delta), anchor);
}
/**
* Adds a value to the view rotation, optionally using an anchor. Any rotation
* constraint will apply.
* @param {number} delta Relative value to add to the zoom rotation, in radians.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The rotation center.
* @param {import("./coordinate.js").Coordinate} [anchor] The rotation center.
* @api
*/
adjustRotation(delta, opt_anchor) {
if (opt_anchor) {
opt_anchor = fromUserCoordinate(opt_anchor, this.getProjection());
adjustRotation(delta, anchor) {
if (anchor) {
anchor = fromUserCoordinate(anchor, this.getProjection());
}
this.adjustRotationInternal(delta, opt_anchor);
this.adjustRotationInternal(delta, anchor);
}
/**
* @param {number} delta Relative value to add to the zoom rotation, in radians.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The rotation center.
* @param {import("./coordinate.js").Coordinate} [anchor] The rotation center.
*/
adjustRotationInternal(delta, opt_anchor) {
adjustRotationInternal(delta, anchor) {
const isMoving = this.getAnimating() || this.getInteracting();
const newRotation = this.constraints_.rotation(
this.targetRotation_ + delta,
isMoving
);
if (opt_anchor) {
this.targetCenter_ = this.calculateCenterRotate(newRotation, opt_anchor);
if (anchor) {
this.targetCenter_ = this.calculateCenterRotate(newRotation, anchor);
}
this.targetRotation_ += delta;
this.applyTargetState_();
@@ -1693,13 +1688,13 @@ class View extends BaseObject {
* Recompute rotation/resolution/center based on target values.
* Note: we have to compute rotation first, then resolution and center considering that
* parameters can influence one another in case a view extent constraint is present.
* @param {boolean} [opt_doNotCancelAnims] Do not cancel animations.
* @param {boolean} [opt_forceMoving] Apply constraints as if the view is moving.
* @param {boolean} [doNotCancelAnims] Do not cancel animations.
* @param {boolean} [forceMoving] Apply constraints as if the view is moving.
* @private
*/
applyTargetState_(opt_doNotCancelAnims, opt_forceMoving) {
applyTargetState_(doNotCancelAnims, forceMoving) {
const isMoving =
this.getAnimating() || this.getInteracting() || opt_forceMoving;
this.getAnimating() || this.getInteracting() || forceMoving;
// compute rotation
const newRotation = this.constraints_.rotation(
@@ -1741,7 +1736,7 @@ class View extends BaseObject {
this.set(ViewProperty.CENTER, newCenter);
}
if (this.getAnimating() && !opt_doNotCancelAnims) {
if (this.getAnimating() && !doNotCancelAnims) {
this.cancelAnimations();
}
this.cancelAnchor_ = undefined;
@@ -1752,13 +1747,13 @@ class View extends BaseObject {
* This is typically done on interaction end.
* Note: calling this with a duration of 0 will apply the constrained values straight away,
* without animation.
* @param {number} [opt_duration] The animation duration in ms.
* @param {number} [opt_resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
* @param {number} [duration] The animation duration in ms.
* @param {number} [resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
*/
resolveConstraints(opt_duration, opt_resolutionDirection, opt_anchor) {
const duration = opt_duration !== undefined ? opt_duration : 200;
const direction = opt_resolutionDirection || 0;
resolveConstraints(duration, resolutionDirection, anchor) {
duration = duration !== undefined ? duration : 200;
const direction = resolutionDirection || 0;
const newRotation = this.constraints_.rotation(this.targetRotation_);
const size = this.getViewportSize_(newRotation);
@@ -1788,8 +1783,7 @@ class View extends BaseObject {
return;
}
const anchor =
opt_anchor || (duration === 0 ? this.cancelAnchor_ : undefined);
anchor = anchor || (duration === 0 ? this.cancelAnchor_ : undefined);
this.cancelAnchor_ = undefined;
if (
@@ -1828,42 +1822,41 @@ class View extends BaseObject {
/**
* Notify the View that an interaction has ended. The view state will be resolved
* to a stable one if needed (depending on its constraints).
* @param {number} [opt_duration] Animation duration in ms.
* @param {number} [opt_resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
* @param {number} [duration] Animation duration in ms.
* @param {number} [resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
* @api
*/
endInteraction(opt_duration, opt_resolutionDirection, opt_anchor) {
const anchor =
opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection());
this.endInteractionInternal(opt_duration, opt_resolutionDirection, anchor);
endInteraction(duration, resolutionDirection, anchor) {
anchor = anchor && fromUserCoordinate(anchor, this.getProjection());
this.endInteractionInternal(duration, resolutionDirection, anchor);
}
/**
* Notify the View that an interaction has ended. The view state will be resolved
* to a stable one if needed (depending on its constraints).
* @param {number} [opt_duration] Animation duration in ms.
* @param {number} [opt_resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
* @param {number} [duration] Animation duration in ms.
* @param {number} [resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
*/
endInteractionInternal(opt_duration, opt_resolutionDirection, opt_anchor) {
endInteractionInternal(duration, resolutionDirection, anchor) {
this.setHint(ViewHint.INTERACTING, -1);
this.resolveConstraints(opt_duration, opt_resolutionDirection, opt_anchor);
this.resolveConstraints(duration, resolutionDirection, anchor);
}
/**
* Get a valid position for the view center according to the current constraints.
* @param {import("./coordinate.js").Coordinate|undefined} targetCenter Target center position.
* @param {number} [opt_targetResolution] Target resolution. If not supplied, the current one will be used.
* @param {number} [targetResolution] Target resolution. If not supplied, the current one will be used.
* This is useful to guess a valid center position at a different zoom level.
* @return {import("./coordinate.js").Coordinate|undefined} Valid center position.
*/
getConstrainedCenter(targetCenter, opt_targetResolution) {
getConstrainedCenter(targetCenter, targetResolution) {
const size = this.getViewportSize_(this.getRotation());
return this.constraints_.center(
targetCenter,
opt_targetResolution || this.getResolution(),
targetResolution || this.getResolution(),
size
);
}
@@ -1871,30 +1864,30 @@ class View extends BaseObject {
/**
* Get a valid zoom level according to the current view constraints.
* @param {number|undefined} targetZoom Target zoom.
* @param {number} [opt_direction=0] Indicate which resolution should be used
* @param {number} [direction=0] Indicate which resolution should be used
* by a renderer if the view resolution does not match any resolution of the tile source.
* If 0, the nearest resolution will be used. If 1, the nearest lower resolution
* will be used. If -1, the nearest higher resolution will be used.
* @return {number|undefined} Valid zoom level.
*/
getConstrainedZoom(targetZoom, opt_direction) {
getConstrainedZoom(targetZoom, direction) {
const targetRes = this.getResolutionForZoom(targetZoom);
return this.getZoomForResolution(
this.getConstrainedResolution(targetRes, opt_direction)
this.getConstrainedResolution(targetRes, direction)
);
}
/**
* Get a valid resolution according to the current view constraints.
* @param {number|undefined} targetResolution Target resolution.
* @param {number} [opt_direction=0] Indicate which resolution should be used
* @param {number} [direction=0] Indicate which resolution should be used
* by a renderer if the view resolution does not match any resolution of the tile source.
* If 0, the nearest resolution will be used. If 1, the nearest lower resolution
* will be used. If -1, the nearest higher resolution will be used.
* @return {number|undefined} Valid resolution.
*/
getConstrainedResolution(targetResolution, opt_direction) {
const direction = opt_direction || 0;
getConstrainedResolution(targetResolution, direction) {
direction = direction || 0;
const size = this.getViewportSize_(this.getRotation());
return this.constraints_.resolution(targetResolution, direction, size);