From 1d8cc53408b0c4dce54bf061f11a7164b0dc457f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Palm=C3=A9r?= Date: Fri, 17 Nov 2017 14:36:23 +0100 Subject: [PATCH] #5921 Remove touch based click tolerance (#5922) --- spec/suites/layer/vector/PathSpec.js | 12 ++++++++++++ src/layer/vector/Path.js | 3 +-- src/layer/vector/Renderer.js | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spec/suites/layer/vector/PathSpec.js b/spec/suites/layer/vector/PathSpec.js index 527b78fa..58b6c08e 100644 --- a/spec/suites/layer/vector/PathSpec.js +++ b/spec/suites/layer/vector/PathSpec.js @@ -80,5 +80,17 @@ describe('Path', function () { }, 300); }); + it('it should return tolerance with stroke', function () { + var path = new L.Polyline([[1, 2], [3, 4], [5, 6]]); + var layer = path.addTo(map); + expect(path._clickTolerance()).to.equal(path.options.weight / 2); + }); + + it('it should return zero tolerance without stroke', function () { + var path = new L.Polyline([[1, 2], [3, 4], [5, 6]]); + var layer = path.addTo(map); + path.options.stroke = false; + expect(path._clickTolerance()).to.equal(0); + }); }); }); diff --git a/src/layer/vector/Path.js b/src/layer/vector/Path.js index 77324387..03234373 100644 --- a/src/layer/vector/Path.js +++ b/src/layer/vector/Path.js @@ -1,6 +1,5 @@ import {Layer} from '../Layer'; import * as Util from '../../core/Util'; -import {touch} from '../../core/Browser'; /* * @class Path @@ -140,6 +139,6 @@ export var Path = Layer.extend({ _clickTolerance: function () { // used when doing hit detection for Canvas layers - return (this.options.stroke ? this.options.weight / 2 : 0) + (touch ? 10 : 0); + return (this.options.stroke ? this.options.weight / 2 : 0) + this._renderer.options.tolerance; } }); diff --git a/src/layer/vector/Renderer.js b/src/layer/vector/Renderer.js index d2e5e77d..424a179b 100644 --- a/src/layer/vector/Renderer.js +++ b/src/layer/vector/Renderer.js @@ -34,7 +34,11 @@ export var Renderer = Layer.extend({ // @option padding: Number = 0.1 // How much to extend the clip area around the map view (relative to its size) // e.g. 0.1 would be 10% of map view in each direction - padding: 0.1 + padding: 0.1, + + // @option tolerance: Number = 0 + // How much to extend click tolerance round a path/object on the map + tolerance : 0 }, initialize: function (options) {