calvinmetcalf / leaflet-hash

Add URL hashes to web pages with Leaflet maps

Home Page:http://calvinmetcalf.github.com/leaflet-hash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Leaflet-hash

Leaflet-hash lets you to add dynamic URL hashes to web pages with Leaflet maps. You can easily link users to specific map views.

Leaflet-hash

Demo

You can view a demo of leaflet-hash at calvinmetcalf.github.com/leaflet-hash.

Getting started

  1. Prepare a basic leaflet map. You can find instructions on Leaflet's quick-start guide.

  2. Include leaflet-hash.js.

  3. Once you have initialized the map (an instance of L.Map), add the following code:

        // Assuming your map instance is in a variable called map
        map.addHash();
  4. optionally you can pass a an object with a few options

    • lc: pass an instance of L.Control.Layer, the baselayers will be put in the hash
    • path: template for the url hash, defaults to '{z}/{lat}/{lng}' or '{base}/{z}/{lat}/{lng}' if lc is specified, parts need to be seperated by "/"
    • formatBase: an array of length 2 that will be used as the arguments of the overlay names before they go into the url hash, the default turns whitespace to underscores and all lowercase just pass "[//]" if you want it unchanged

Author

@mlevans

Contributors

@rsudekum

@yohanboniface

@calvinmetcalf

@tmcw

License

MIT License. See LICENSE for details.

About

Add URL hashes to web pages with Leaflet maps

http://calvinmetcalf.github.com/leaflet-hash

License:MIT License


Languages

Language:JavaScript 100.0%