npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mrubli/leaflet-freezy

v0.0.3

Published

Leaflet plugin preventing unwanted scroll capturing

Downloads

7

Readme

Leaflet.Freezy

Leaflet plugin to prevent unwanted scroll capturing.

Problem

Maps embedded in web pages have a habit of interfering with page scrolling. Some projects have worked around this behavior by making users hold down the Ctrl key in order to zoom maps. This can be annoying since it requires simultaneous use of the keyboard and the mouse.

Similarly, if a map is tall large enough to fill the screen on a mobile device, it can become impossible to perform page scrolling, an even more vexing usability problem.

While Chromium-based browsers have taken steps to mitigate the issue by suppressing mouse wheel and swiping input to maps while scrolling, other browsers (e.g. Firefox) still allow maps to aggressively capture scrolling control.

Solution

Leaflet.Freezy is a Leaflet plugin that provides a solution for these situations. Its main features are:

  • Lock interaction with ("freeze") maps on load until explicitly enabled.
  • Allow users to manually freeze maps with the help of a Freeze button.
  • Unlock interaction with ("thaw") maps by clicking or tapping the map.
  • Thaw maps by hovering over the map and re-freeze by moving the mouse pointer out of the map.

This plugin is a rewrite of the unmaintained and partially broken Leaflet.Sleep plugin.

Demo

Leaflet.Freezy Demo

Requirements

  • Leaflet: The plugin has mostly been tested with Leaflet 1.9 but strives to be compatible with earlier versions as well. If you spot a problem, please open an issue.
  • Browsers: There are no particular browser requirements. The plugin has been tested with Chromium-based browsers (Vivaldi, Brave, Ungoogled Chromium, Edge) as well as Firefox and Safari. Again, if you find a browser-specific issue, please open an issue.

Usage

Changing a standard map into a frozen map is a one-liner:

// Create a simple map using OpenStreetMap
var map = L.map('map-container')
    .setView([50.4024, 30.5313], 11)
    .addLayer(L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'));

// Add freeze logic and control to the map
L.control.freezeMapControl().addTo(map);

The above sample immediately freezes the map using the default freeze/thaw options.

You can also refer to the source code of the demo site for a working example.

Options

There are a number of options you can pass the freezeMapControl() constructor to adjust the behavior to your needs. The following example shows all available options and their respective default values:

L.control.freezeMapControl({
    // Whether to immediately freeze the map when the control is added.
    freezeOnAdd: true,
    // Opacity of the map container when it's frozen.
    frozenMapOpacity: 0.5,
    // Thaw the map when hovering the cursor over it for a certain duration.
    // Default: Browser-dependent (true for Chromium-based, false for others)
    hoverToThaw: true,
    // Amount of time after which hovering thaws the map. [ms]
    hoverToThawDuration: 1000,
    // Freeze the map again when leaving the map container with the cursor for a certain
    // duration.
    leaveToFreeze: true,
    // Amount of time after which to freeze the map when the cursor has left the map container.
    // [ms]
    leaveToFreezeDuration: 2000,
    // Whether to display the 'Freeze' button when the map is thawed.
    freezeButtonWhenThawed: true,
    // Inner HTML of the 'Freeze' button.
    freezeButtonInnerHtml: '🔒',
    // Title (hover text) of the 'Freeze' button.
    freezeButtonTitle: 'Deactivate map',
    // Overlay content to show while the map is frozen. This can be either of:
    //   undefined: Use the plugin's standard text overlay
    //   function: Function to evaluate in order to obtain a DOM element tree.
    //   null: Disable the overlay
    frozenOverlay: undefined,
}).addTo(map);

Callbacks

Callback functions can be registered to be notified when the map is frozen or thawed. This is useful if other UI elements should be made to depend on the map frozen/thawed state:

L.control.freezeMapControl()
    .on('freeze', () => console.log("🥶"))
    .on('thaw',   () => console.log("🥵"))
    .addTo(map);