Remove MousePosition's deprecated undefinedHTML option

Simplify the placeholder option to only accept strings or undefined.
This commit is contained in:
Maximilian Krög
2022-07-31 01:28:08 +02:00
parent f276f3f47f
commit c90c4c84c5
3 changed files with 15 additions and 106 deletions

View File

@@ -18,6 +18,10 @@ The default intervals now align with integer minutes and seconds better suited t
Inserting with `setAt` or `insertAt` beyond the current length used to create a sparse Collection with `undefined` inserted for any missing indexes. This will now throw an error instead.
#### ol/control/MousePosition
The control will now by default keep displaying the last mouse position when the mouse leaves the viewport. With `placeholder: ' '` you can keep the old behaviour. The `placeholder` option no longer accepts `false` as a valid value, instead simply omit the option. The `undefinedHTML` option has been removed. You should use `placeholder` instead.
### 6.15.0
#### Deprecated `tilePixelRatio` option for data tile sources.

View File

@@ -41,13 +41,11 @@ const COORDINATE_FORMAT = 'coordinateFormat';
* callback.
* @property {HTMLElement|string} [target] Specify a target if you want the
* control to be rendered outside of the map's viewport.
* @property {string|boolean} [placeholder] Markup to show when the mouse position is not
* available (e.g. when the pointer leaves the map viewport). By default, a non-breaking space
* is rendered when the mouse leaves the viewport. To render something else, provide a string
* to be used as the text content (e.g. 'no position' or '' for an empty string). Set the placeholder
* to `false` to retain the last position when the mouse leaves the viewport. In a future release, this
* will be the default behavior.
* @property {string} [undefinedHTML=' '] This option is deprecated. Use the `placeholder` option instead.
* @property {string} [placeholder] Markup to show when the mouse position is not
* available (e.g. when the pointer leaves the map viewport). By default, a non-breaking space is rendered
* initially and the last position is retained when the mouse leaves the viewport.
* When a string is provided (e.g. `'no position'` or `''` for an empty string) it is used as a
* placeholder.
*/
/**
@@ -104,41 +102,16 @@ class MousePosition extends Control {
}
/**
* Change this to `false` when removing the deprecated `undefinedHTML` option.
* @private
* @type {boolean}
*/
let renderOnMouseOut = true;
/**
* @type {string}
*/
let placeholder = ' ';
if ('undefinedHTML' in options) {
// deprecated behavior
if (options.undefinedHTML !== undefined) {
placeholder = options.undefinedHTML;
}
renderOnMouseOut = !!placeholder;
} else if ('placeholder' in options) {
if (options.placeholder === false) {
renderOnMouseOut = false;
} else {
placeholder = String(options.placeholder);
}
}
this.renderOnMouseOut_ = options.placeholder !== undefined;
/**
* @private
* @type {string}
*/
this.placeholder_ = placeholder;
/**
* @private
* @type {boolean}
*/
this.renderOnMouseOut_ = renderOnMouseOut;
this.placeholder_ = this.renderOnMouseOut_ ? options.placeholder : ' ';
/**
* @private

View File

@@ -84,8 +84,8 @@ describe('ol/control/MousePosition', function () {
expect(element.innerHTML).to.be('some text');
});
it('renders the last posisition if placeholder is false and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({placeholder: false});
it('renders the last posisition if placeholder is not set and mouse moves outside the viewport', function () {
const ctrl = new MousePosition();
ctrl.setMap(map);
map.renderSync();
@@ -105,7 +105,7 @@ describe('ol/control/MousePosition', function () {
expect(element.innerHTML).to.be('20,-30');
});
it('renders an empty space if placehodler is set to the same and mouse moves outside the viewport', function () {
it('renders an empty space if placeholder is set to the same and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({
placeholder: '',
});
@@ -128,73 +128,5 @@ describe('ol/control/MousePosition', function () {
expect(element.innerHTML).to.be('');
});
});
describe('undefinedHTML (deprecated)', function () {
it('renders undefinedHTML when mouse moves out', function () {
const ctrl = new MousePosition({
undefinedHTML: 'some text',
});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('some text');
simulateEvent(EventType.POINTERMOVE, 20, 30);
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('some text');
});
it('clears the mouse position by default when the mouse moves outside the viewport', function () {
const ctrl = new MousePosition();
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be(' ');
target.dispatchEvent(new PointerEvent('pointermove'));
simulateEvent(EventType.POINTERMOVE, 20, 30);
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be(' ');
});
it('retains the mouse position when undefinedHTML is falsey and mouse moves outside the viewport', function () {
const ctrl = new MousePosition({
undefinedHTML: '',
});
ctrl.setMap(map);
map.renderSync();
const element = document.querySelector(
'.ol-mouse-position',
map.getTarget()
);
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('');
target.dispatchEvent(new PointerEvent('pointermove'));
simulateEvent(EventType.POINTERMOVE, 20, 30);
expect(element.innerHTML).to.be('20,-30');
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
expect(element.innerHTML).to.be('20,-30');
});
});
});
});