From 5659397b39fd5aa4e23dbee9fb41507e384c2bd5 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 27 Nov 2020 11:52:52 +0100 Subject: [PATCH 1/3] No need to adjust hitTolerance for pixel ratio --- src/ol/PluggableMap.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 4d8128a0ff..1f51b3fa5f 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -75,7 +75,7 @@ import {removeNode} from './dom.js'; * {@link module:ol/layer/Layer layer-candidate} and it should return a boolean value. * Only layers which are visible and for which this function returns `true` * will be tested for features. By default, all visible layers will be tested. - * @property {number} [hitTolerance=0] Hit-detection tolerance in pixels. Pixels + * @property {number} [hitTolerance=0] Hit-detection tolerance in css pixels. Pixels * inside the radius around the given position will be checked for features. * @property {boolean} [checkWrapped=true] Check-Wrapped Will check for for wrapped geometries inside the range of * +/- 1 world width. Works only if a projection is used that can be wrapped. @@ -559,9 +559,7 @@ class PluggableMap extends BaseObject { const coordinate = this.getCoordinateFromPixelInternal(pixel); opt_options = opt_options !== undefined ? opt_options : {}; const hitTolerance = - opt_options.hitTolerance !== undefined - ? opt_options.hitTolerance * this.frameState_.pixelRatio - : 0; + opt_options.hitTolerance !== undefined ? opt_options.hitTolerance : 0; const layerFilter = opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE; const checkWrapped = opt_options.checkWrapped !== false; @@ -624,9 +622,7 @@ class PluggableMap extends BaseObject { } const options = opt_options || {}; const hitTolerance = - options.hitTolerance !== undefined - ? options.hitTolerance * this.frameState_.pixelRatio - : 0; + options.hitTolerance !== undefined ? options.hitTolerance : 0; const layerFilter = options.layerFilter || TRUE; return this.renderer_.forEachLayerAtPixel( pixel, @@ -654,9 +650,7 @@ class PluggableMap extends BaseObject { const layerFilter = opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE; const hitTolerance = - opt_options.hitTolerance !== undefined - ? opt_options.hitTolerance * this.frameState_.pixelRatio - : 0; + opt_options.hitTolerance !== undefined ? opt_options.hitTolerance : 0; const checkWrapped = opt_options.checkWrapped !== false; return this.renderer_.hasFeatureAtCoordinate( coordinate, From db89da6e15f47cdca67299bc33e1bf677502a6b9 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 27 Nov 2020 12:44:34 +0100 Subject: [PATCH 2/3] Update changelog --- changelog/upgrade-notes.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index 1766664c5f..5836bae2e0 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -1,5 +1,20 @@ ## Upgrade notes +### Next version + +#### Units of the `hitTolerance` option fixed + +Previously, the `hitTolerance` option of the map's `getFeaturesAtPixel()`, `forEachFeatureAtPixel()` and `hasFeatureAtPixel()` methods behaved differntly depending on the `devicePixelRatio` (or the `pixelRatio` of the map). Now this is fixed, the `hitTolerance`'s units are css pixels. + +If your application adjusts for that with code like +```js +{ hitTolerance: 10 / devicePixelRatio, } +``` +you'll have to change that code to +```js +{ hitTolerance: 10, } +``` + ### v6.4.0 #### Pointer events polyfill removed From fe36ff4ee3379baa5cd4c6831cf5bef6556a4bb0 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sun, 29 Nov 2020 00:02:39 +0100 Subject: [PATCH 3/3] Clarify change in changelog --- changelog/upgrade-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index 5836bae2e0..f9db712bfe 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -4,7 +4,7 @@ #### Units of the `hitTolerance` option fixed -Previously, the `hitTolerance` option of the map's `getFeaturesAtPixel()`, `forEachFeatureAtPixel()` and `hasFeatureAtPixel()` methods behaved differntly depending on the `devicePixelRatio` (or the `pixelRatio` of the map). Now this is fixed, the `hitTolerance`'s units are css pixels. +Previously, the `hitTolerance` option of the map's `getFeaturesAtPixel()`, `forEachFeatureAtPixel()` and `hasFeatureAtPixel()` methods behaved differntly depending on the `devicePixelRatio` (or the `pixelRatio` of the map), because the original value was internally multiplied by the device pixel ratio twice instead of just once. Now this is fixed. **Note**: The `hitTolerance`'s units are css pixels. The documentation was updated to reflect this. If your application adjusts for that with code like ```js