Raruto / leaflet-ui

Leaflet presets for common user interface customizations
GNU General Public License v3.0
29 stars 4 forks source link

Can I change the gestureHandlingOptions duration? #8

Closed qwertydude closed 3 years ago

qwertydude commented 3 years ago

Hi I wanted change the duration that the overlay advising Use ⌘ + scroll to zoom the map is displayed.

I discovered the gestureHandlingOptions.duration so figured all I needed to do was add this to my map options

gestureHandlingOptions: { duration: 850 }, But it didn't work.

Is this not a customisable option?

Raruto commented 3 years ago

Hi Chris, there may be a bug in the application logic, please try to check the following points to verify:

https://github.com/Raruto/leaflet-ui/blob/f634be9ec67e98d94990f21bc001cb4279d8d40d/src/leaflet-ui.js#L229-L234

https://github.com/Raruto/leaflet-ui/blob/f634be9ec67e98d94990f21bc001cb4279d8d40d/src/leaflet-ui.js#L278-L284

https://github.com/Raruto/leaflet-ui/blob/f634be9ec67e98d94990f21bc001cb4279d8d40d/src/leaflet-ui.js#L339-L342

Regards, Raruto

qwertydude commented 3 years ago

Thanks.

This is what I've found.

In Leafletjs:

Map.js line 1712 sets the gestureHandlingOptions to the hardcoded values (i.e. duration:1700)

return new Map(id, options);

Map.js line 127 sets the options from my custom options, thus also setting my values to gestureHandlingOptions

options = Util.setOptions(this, options);

Map.js line 156 resets the gestureHandlingOptions to the hardcoded values (i.e. duration:1700)

this.callInitHooks();

I know it's not your code, but do you think that is a bug? Or a quirk? Is there a way around it?

Thanks

Raruto commented 3 years ago

Hi chris, I don't think it's a core issue, but mostly a problem of leaflet-ui or leaflet-gesture-handling.

Try to take a closer look at the lines that I pointed out earlier to try to better understand how it actually works.

Also try playing with the following lines to make sure everything is okay:

 L.Map.mergeOptions({
  gestureHandling: true,
  gestureHandlingOptions: { duration: 850 }, // FIXED VALUE
 })
L.Map.addInitHook(function() {
  this.options.gestureHandling        = true;
  this.options.gestureHandlingOptions = { duration: 850 }; // FIXED VALUE
});

Reference: Extending Leaflet (class theory)

Happy testing, Raruto

qwertydude commented 3 years ago

Thanks, Raruto

Getting out of my depth a bit. Tho have learnt a bit this week! For this project, the time for me to resolve this the right way is no really justifiable. So will just re-build our own with the duration set to something smaller.

All that said... I've had to deactivate gesture handling anyway because the 2 finger move wasn't working on mobile, and again, I can't justify anymore time on this at the moment.

Do appreciate all your help though.

Thanks heaps.

Raruto commented 3 years ago

One should investigate further, but at least this works as expected:

var map = L.map('map', { gestureHandling: true });

// update from defaults: { text: {}, duration: 1700 }
L.extend(map.options.gestureHandlingOptions, { duration: 850 });

Raruto