Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Open
wants to merge 2 commits into from

2 participants

Yohan Boniface Calvin Metcalf
Yohan Boniface

Just to stay closer from Leaflet own usages.
Thanks!

Yohan

Calvin Metcalf

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

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

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

var map = L.map('map');
map.addHash();
Calvin Metcalf

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

Yohan Boniface

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

Calvin Metcalf

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

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

instead of

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

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
View
@@ -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;
+ }
+ });
})(window);
Something went wrong with that request. Please try again.