Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Use "include" Leaflet API for addind methods to L.Map #14

wants to merge 2 commits into from

2 participants


Just to stay closer from Leaflet own usages.



when you do it that way then you can't do

var map ='map').addHash();

because it's not in the prototype chain yet, you can only do

var map ='map');

ignore the previous comment, for both ways you have to set view before you can add the hash


We just need to add return this; to make it work.
I'll add it ;)


no this turns out to be a different issue, you get an error if you do

var map ='map').addHash();

instead of

var map ='map').setView([42.2, -71], 8).addHash();//or wherever

yeah my issue was actually part of #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 7 deletions.
  1. +14 −7 leaflet-hash.js
21 leaflet-hash.js
@@ -143,13 +143,20 @@
this.isListening = false;
L.hash = function(map){
- return new L.Hash(map);
+ return new L.Hash(map);
- L.Map.prototype.addHash = function(){
- this._hash = L.hash(this);
- };
- L.Map.prototype.removeHash = function(){
- this._hash.remove();
- }
+ L.Map.include({
+ addHash: function(){
+ this._hash = L.hash(this);
+ return this;
+ },
+ removeHash: function(){
+ this._hash.remove();
+ return this;
+ }
+ });
Something went wrong with that request. Please try again.