Remove MousePosition's deprecated undefinedHTML option
Simplify the placeholder option to only accept strings or undefined.
This commit is contained in:
@@ -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.
|
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
|
### 6.15.0
|
||||||
|
|
||||||
#### Deprecated `tilePixelRatio` option for data tile sources.
|
#### Deprecated `tilePixelRatio` option for data tile sources.
|
||||||
|
|||||||
@@ -41,13 +41,11 @@ const COORDINATE_FORMAT = 'coordinateFormat';
|
|||||||
* callback.
|
* callback.
|
||||||
* @property {HTMLElement|string} [target] Specify a target if you want the
|
* @property {HTMLElement|string} [target] Specify a target if you want the
|
||||||
* control to be rendered outside of the map's viewport.
|
* control to be rendered outside of the map's viewport.
|
||||||
* @property {string|boolean} [placeholder] Markup to show when the mouse position is not
|
* @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
|
* available (e.g. when the pointer leaves the map viewport). By default, a non-breaking space is rendered
|
||||||
* is rendered when the mouse leaves the viewport. To render something else, provide a string
|
* initially and the last position is retained when the mouse leaves the viewport.
|
||||||
* to be used as the text content (e.g. 'no position' or '' for an empty string). Set the placeholder
|
* When a string is provided (e.g. `'no position'` or `''` for an empty string) it is used as a
|
||||||
* to `false` to retain the last position when the mouse leaves the viewport. In a future release, this
|
* placeholder.
|
||||||
* will be the default behavior.
|
|
||||||
* @property {string} [undefinedHTML=' '] This option is deprecated. Use the `placeholder` option instead.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,41 +102,16 @@ class MousePosition extends Control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change this to `false` when removing the deprecated `undefinedHTML` option.
|
* @private
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
let renderOnMouseOut = true;
|
this.renderOnMouseOut_ = options.placeholder !== undefined;
|
||||||
|
|
||||||
/**
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.placeholder_ = placeholder;
|
this.placeholder_ = this.renderOnMouseOut_ ? options.placeholder : ' ';
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {boolean}
|
|
||||||
*/
|
|
||||||
this.renderOnMouseOut_ = renderOnMouseOut;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ describe('ol/control/MousePosition', function () {
|
|||||||
expect(element.innerHTML).to.be('some text');
|
expect(element.innerHTML).to.be('some text');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the last posisition if placeholder is false and mouse moves outside the viewport', function () {
|
it('renders the last posisition if placeholder is not set and mouse moves outside the viewport', function () {
|
||||||
const ctrl = new MousePosition({placeholder: false});
|
const ctrl = new MousePosition();
|
||||||
ctrl.setMap(map);
|
ctrl.setMap(map);
|
||||||
map.renderSync();
|
map.renderSync();
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ describe('ol/control/MousePosition', function () {
|
|||||||
expect(element.innerHTML).to.be('20,-30');
|
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({
|
const ctrl = new MousePosition({
|
||||||
placeholder: '',
|
placeholder: '',
|
||||||
});
|
});
|
||||||
@@ -128,73 +128,5 @@ describe('ol/control/MousePosition', function () {
|
|||||||
expect(element.innerHTML).to.be('');
|
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');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user