Fix private scope type issues in controls

This commit is contained in:
Andreas Hocevar
2020-04-13 12:07:16 +02:00
parent b0f20d6bd6
commit f4d64700ef
8 changed files with 97 additions and 102 deletions

View File

@@ -49,7 +49,7 @@ class Attribution extends Control {
super({
element: document.createElement('div'),
render: options.render || render,
render: options.render,
target: options.target,
});
@@ -328,15 +328,15 @@ class Attribution extends Control {
getCollapsed() {
return this.collapsed_;
}
}
/**
* Update the attribution element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @this {Attribution}
*/
export function render(mapEvent) {
this.updateElement_(mapEvent.frameState);
/**
* Update the attribution element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @override
*/
render(mapEvent) {
this.updateElement_(mapEvent.frameState);
}
}
export default Attribution;

View File

@@ -74,11 +74,9 @@ class Control extends BaseObject {
*/
this.listenerKeys = [];
/**
* @private
* @type {function(import("../MapEvent.js").default): void}
*/
this.render_ = options.render ? options.render : VOID;
if (options.render) {
this.render = options.render;
}
if (options.target) {
this.setTarget(options.target);
@@ -133,14 +131,11 @@ class Control extends BaseObject {
}
/**
* Update the projection. Rendering of the coordinates is done in
* `handleMouseMove` and `handleMouseUp`.
* Renders the control.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @api
*/
render(mapEvent) {
this.render_.call(this, mapEvent);
}
render(mapEvent) {}
/**
* This function is used to set a target element for the control. It has no

View File

@@ -66,7 +66,7 @@ class MousePosition extends Control {
super({
element: element,
render: options.render || render,
render: options.render,
target: options.target,
});
@@ -251,22 +251,22 @@ class MousePosition extends Control {
this.renderedHTML_ = html;
}
}
}
/**
* Update the projection. Rendering of the coordinates is done in
* `handleMouseMove` and `handleMouseUp`.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @this {MousePosition}
*/
export function render(mapEvent) {
const frameState = mapEvent.frameState;
if (!frameState) {
this.mapProjection_ = null;
} else {
if (this.mapProjection_ != frameState.viewState.projection) {
this.mapProjection_ = frameState.viewState.projection;
this.transform_ = null;
/**
* Update the projection. Rendering of the coordinates is done in
* `handleMouseMove` and `handleMouseUp`.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @override
*/
render(mapEvent) {
const frameState = mapEvent.frameState;
if (!frameState) {
this.mapProjection_ = null;
} else {
if (this.mapProjection_ != frameState.viewState.projection) {
this.mapProjection_ = frameState.viewState.projection;
this.transform_ = null;
}
}
}
}

View File

@@ -81,7 +81,7 @@ class OverviewMap extends Control {
super({
element: document.createElement('div'),
render: options.render || render,
render: options.render,
target: options.target,
});
@@ -644,16 +644,16 @@ class OverviewMap extends Control {
getOverviewMap() {
return this.ovmap_;
}
}
/**
* Update the overview map element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @this {OverviewMap}
*/
export function render(mapEvent) {
this.validateExtent_();
this.updateBox_();
/**
* Update the overview map element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @override
*/
render(mapEvent) {
this.validateExtent_();
this.updateBox_();
}
}
export default OverviewMap;

View File

@@ -39,7 +39,7 @@ class Rotate extends Control {
super({
element: document.createElement('div'),
render: options.render || render,
render: options.render,
target: options.target,
});
@@ -145,32 +145,32 @@ class Rotate extends Control {
}
}
}
}
/**
* Update the rotate control element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @this {Rotate}
*/
export function render(mapEvent) {
const frameState = mapEvent.frameState;
if (!frameState) {
return;
}
const rotation = frameState.viewState.rotation;
if (rotation != this.rotation_) {
const transform = 'rotate(' + rotation + 'rad)';
if (this.autoHide_) {
const contains = this.element.classList.contains(CLASS_HIDDEN);
if (!contains && rotation === 0) {
this.element.classList.add(CLASS_HIDDEN);
} else if (contains && rotation !== 0) {
this.element.classList.remove(CLASS_HIDDEN);
}
/**
* Update the rotate control element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @override
*/
render(mapEvent) {
const frameState = mapEvent.frameState;
if (!frameState) {
return;
}
this.label_.style.transform = transform;
const rotation = frameState.viewState.rotation;
if (rotation != this.rotation_) {
const transform = 'rotate(' + rotation + 'rad)';
if (this.autoHide_) {
const contains = this.element.classList.contains(CLASS_HIDDEN);
if (!contains && rotation === 0) {
this.element.classList.add(CLASS_HIDDEN);
} else if (contains && rotation !== 0) {
this.element.classList.remove(CLASS_HIDDEN);
}
}
this.label_.style.transform = transform;
}
this.rotation_ = rotation;
}
this.rotation_ = rotation;
}
export default Rotate;

View File

@@ -87,7 +87,7 @@ class ScaleLine extends Control {
super({
element: document.createElement('div'),
render: options.render || render,
render: options.render,
target: options.target,
});
@@ -471,21 +471,21 @@ class ScaleLine extends Control {
const inchesPerMeter = 39.37;
return parseFloat(resolution.toString()) * mpu * inchesPerMeter * dpi;
}
}
/**
* Update the scale line element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @this {ScaleLine}
*/
export function render(mapEvent) {
const frameState = mapEvent.frameState;
if (!frameState) {
this.viewState_ = null;
} else {
this.viewState_ = frameState.viewState;
/**
* Update the scale line element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @override
*/
render(mapEvent) {
const frameState = mapEvent.frameState;
if (!frameState) {
this.viewState_ = null;
} else {
this.viewState_ = frameState.viewState;
}
this.updateElement_();
}
this.updateElement_();
}
export default ScaleLine;

View File

@@ -49,7 +49,7 @@ class ZoomSlider extends Control {
super({
element: document.createElement('div'),
render: options.render || render,
render: options.render,
});
/**
@@ -356,23 +356,23 @@ class ZoomSlider extends Control {
const fn = this.getMap().getView().getValueForResolutionFunction();
return clamp(1 - fn(res), 0, 1);
}
}
/**
* Update the zoomslider element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @this {ZoomSlider}
*/
export function render(mapEvent) {
if (!mapEvent.frameState) {
return;
/**
* Update the zoomslider element.
* @param {import("../MapEvent.js").default} mapEvent Map event.
* @override
*/
render(mapEvent) {
if (!mapEvent.frameState) {
return;
}
if (!this.sliderInitialized_) {
this.initSlider_();
}
const res = mapEvent.frameState.viewState.resolution;
this.currentResolution_ = res;
this.setThumbPosition_(res);
}
if (!this.sliderInitialized_) {
this.initSlider_();
}
const res = mapEvent.frameState.viewState.resolution;
this.currentResolution_ = res;
this.setThumbPosition_(res);
}
export default ZoomSlider;