Skip to content

Commit

Permalink
Add support for use as an npm module
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jul 11, 2018
1 parent 8a24660 commit 8d500ce
Show file tree
Hide file tree
Showing 10 changed files with 1,284 additions and 1,246 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tabWidth: 4
90 changes: 67 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,93 @@ Version 1.1.2

Brings the basic functionality of [Google Maps Gesture Handling](https://developers.google.com/maps/documentation/javascript/examples/interaction-cooperative) into Leaflet.

Prevents users from getting trapped on the map when scrolling a long page.
Prevents users from getting trapped on the map when scrolling a long page.

**On Desktop**

![alt text](https://elmarquis.github.io/Leaflet.GestureHandling/examples/images/desktop.png "Desktop")

- The map ignores the mouse scroll wheel.
- The user is prompted to use ctrl+scroll to zoom the map.
- The map ignores the mouse scroll wheel.
- The user is prompted to use ctrl+scroll to zoom the map.

**On Mobile / Touch devices**

![alt text](https://elmarquis.github.io/Leaflet.GestureHandling/examples/images/mobile.png "Mobile")

- The map ignores single fingered dragging.
- The user is prompted to use two fingers to pan the map.

- The map ignores single fingered dragging.
- The user is prompted to use two fingers to pan the map.

## Demo

[View demo](https://elmarquis.github.io/Leaflet.GestureHandling/examples/)

## Install
The latest leaflet-gesture-handling can be downloaded from the dist folder.

The latest leaflet-gesture-handling can be downloaded from the dist folder.

## Usage
Include the css and js file after leaflet.js.
```
<link rel="stylesheet" href="css/leaflet-gesture-handling.css" type="text/css">
<script src="js/leaflet-gesture-handling.js"></script>

Include the css and js file after leaflet.js.

```html
<link rel="stylesheet" href="css/leaflet-gesture-handling.min.css" type="text/css">
<script src="js/leaflet-gesture-handling.min.js"></script>
```

Set **gestureHandling: true** in your map initialization script.
Once this is published to NPM, you can load this directly from [UNPKG](https://unpkg.com):

```html
<link rel="stylesheet" href="//unpkg.com/leaflet-gesture-handling/dist/leaflet-gesture-handling.min.css" type="text/css">
<script src="//unpkg.com/leaflet-gesture-handling"></script>
```
var map = L.map("map", {

Set **gestureHandling: true** in your map initialization script.

```js
var map = L.map("map", {
center: [-25.2702, 134.2798],
zoom: 3,
gestureHandling: true
});
```

### Use as a module

If you are using a bundler such as Webpack or Parcel, you can load the library as a module. First install the module with NPM (n.b. change this to `npm install leaflet-gesture-handling` when the package is published on NPM).

```sh
npm install ascorbic/leaflet-gesture-handling
```

Then include the module and CSS in your source:

```js
import * as L from "leaflet";
import { GestureHandling } from "leaflet-gesture-handling";

import "leaflet/dist/leaflet.css";
import "leaflet-gesture-handling/dist/leaflet-gesture-handling.css";
```

Then attach it as a handler to the map:

```js
L.Map.addInitHook("addHandler", "gestureHandling", GestureHandling);

const map = L.map("map", {
center: [50.36, -4.747],
zoom: 3,
gestureHandling: true
});
```

## Multi Language and Custom Text
The plugin will auto detect a users language from the browser setting and show the appropriate translation.

The plugin will auto detect a users language from the browser setting and show the appropriate translation.
However if you wish to override this, you can set your own text using the **gestureHandlingText** option. You must specify text for touch, scroll and scrollMac.

```
var map = L.map("map", {
```js
var map = L.map("map", {
center: [-25.2702, 134.2798],
zoom: 3,
gestureHandling: true,
Expand All @@ -62,18 +103,21 @@ However if you wish to override this, you can set your own text using the **gest
```

## Useful info
GestureHandling disables the following map attributes.
- dragging
- tap
- scrollWheelZoom

They are temporarily enabled for the duration the user scrolls with ctrl+mousewheel or uses two fingers to pan the map on mobile.
GestureHandling disables the following map attributes.

- dragging
- tap
- scrollWheelZoom

They are temporarily enabled for the duration the user scrolls with ctrl+mousewheel or uses two fingers to pan the map on mobile.

## Compatibility with other plugins

I have added compatibility with [Leaflet-MiniMap](https://github.com/Norkart/Leaflet-MiniMap). It allows the user to still pan around the minimap with a single finger.

If there's any other plugins you'd like this to work with, let me know or submit a pull request.
If there's any other plugins you'd like this to work with, let me know or submit a pull request.

## License
MIT

MIT
Loading

0 comments on commit 8d500ce

Please sign in to comment.