Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit 23eb05d

Browse files
author
Calvin Metcalf
committed
and I grabed an old version of hash now fixed and tested
1 parent 6bbb5e9 commit 23eb05d

File tree

3 files changed

+56
-58
lines changed

3 files changed

+56
-58
lines changed

dist/leaflet-full.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8705,11 +8705,13 @@ L.Control.Layers.Provided = L.Control.Layers.extend({
87058705
len = base.length,
87068706
i=0;
87078707
while(i<len){
8708-
if (i === 0) {
8708+
if(typeof base[i] === "string"){
8709+
if (i === 0) {
87098710
first = L.tileLayer.provider(base[0]);
87108711
out[base[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = first;
8711-
} else {
8712+
} else {
87128713
out[base[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = L.tileLayer.provider(base[i]);
8714+
}
87138715
}
87148716
i++;
87158717
}
@@ -8723,7 +8725,9 @@ L.Control.Layers.Provided = L.Control.Layers.extend({
87238725
len = overlay.length,
87248726
i=0;
87258727
while(i<len){
8726-
out[overlay[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = L.tileLayer.provider(overlay[i]);
8728+
if(typeof base[i] === "string"){
8729+
out[overlay[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = L.tileLayer.provider(overlay[i]);
8730+
}
87278731
i++;
87288732
}
87298733
overlay = out;
@@ -8754,64 +8758,62 @@ L.control.layers.provided = function (baseLayers, overlays, options) {
87548758
}
87558759
if (this.options.lc && !this.options.formatBase) {
87568760
this.options.formatBase = [
8757-
/[\s\:A-Z]/g, function(match) {
8761+
/[\sA-Z]/g, function(match) {
87588762
if (match.match(/\s/)) {
87598763
return "_";
87608764
} else if (match.match(/\:/)) {
8761-
return "";
8765+
return "";
87628766
}
87638767
if (match.match(/[A-Z]/)) {
87648768
return match.toLowerCase();
87658769
}
87668770
}
87678771
];
87688772
}
8769-
if (this.map._loaded || location.hash) {
8773+
if (this.map._loaded) {
87708774
return this.startListning();
87718775
} else {
8772-
return this.map.on("load", this.startListning,this);
8776+
return this.map.on("load", this.startListning);
87738777
}
87748778
},
87758779
startListning: function() {
8776-
var onHashChange,phash;
8780+
var onHashChange,
8781+
_this = this;
87778782
if (location.hash) {
8778-
phash = this.parseHash(location.hash);
8779-
if(phash){
8780-
this.updateFromState(phash);
8781-
}
8783+
this.updateFromState(this.parseHash(location.hash));
87828784
}
87838785
if (history.pushState) {
87848786
if (!location.hash) {
87858787
history.replaceState.apply(history, this.formatState());
87868788
}
87878789
window.onpopstate = function(event) {
87888790
if (event.state) {
8789-
return this.updateFromState(event.state);
8791+
return _this.updateFromState(event.state);
87908792
}
87918793
};
87928794
this.map.on("moveend", function() {
87938795
var pstate;
8794-
pstate = this.formatState();
8795-
if (location.hash !== pstate[2] && !this.moving) {
8796+
pstate = _this.formatState();
8797+
if (location.hash !== pstate[2] && !_this.moving) {
87968798
return history.pushState.apply(history, pstate);
87978799
}
8798-
},this);
8800+
});
87998801
} else {
88008802
if (!location.hash) {
88018803
location.hash = this.formatState()[2];
88028804
}
88038805
onHashChange = function() {
88048806
var pstate;
8805-
pstate = this.formatState();
8806-
if (location.hash !== pstate[2] && !this.moving) {
8807+
pstate = _this.formatState();
8808+
if (location.hash !== pstate[2] && !_this.moving) {
88078809
return location.hash = pstate[2];
88088810
}
88098811
};
8810-
this.map.on("moveend", onHashChange, this);
8812+
this.map.on("moveend", onHashChange);
88118813
if (('onhashchange' in window) && (window.documentMode === void 0 || window.documentMode > 7)) {
88128814
window.onhashchange = function() {
88138815
if (location.hash) {
8814-
return this.updateFromState(this.parseHash(location.hash));
8816+
return _this.updateFromState(_this.parseHash(location.hash));
88158817
}
88168818
};
88178819
} else {
@@ -8820,28 +8822,25 @@ L.control.layers.provided = function (baseLayers, overlays, options) {
88208822
}
88218823
return this.map.on("baselayerchange", function(e) {
88228824
var pstate, _ref;
8823-
this.base = (_ref = this.options.lc._layers[e.layer._leaflet_id].name).replace.apply(_ref, _this.options.formatBase);
8824-
pstate = this.formatState();
8825+
_this.base = (_ref = _this.options.lc._layers[e.layer._leaflet_id].name).replace.apply(_ref, _this.options.formatBase);
8826+
pstate = _this.formatState();
88258827
if (history.pushState) {
8826-
if (location.hash !== pstate[2] && !this.moving) {
8828+
if (location.hash !== pstate[2] && !_this.moving) {
88278829
return history.pushState.apply(history, pstate);
88288830
}
88298831
} else {
8830-
if (location.hash !== pstate[2] && !this.moving) {
8832+
if (location.hash !== pstate[2] && !_this.moving) {
88318833
return location.hash = pstate[2];
88328834
}
88338835
}
8834-
}, this);
8836+
});
88358837
},
88368838
parseHash: function(hash) {
88378839
var args, lat, latIndex, lngIndex, lon, out, path, zIndex, zoom;
88388840
path = this.options.path.split("/");
88398841
zIndex = path.indexOf("{z}");
88408842
latIndex = path.indexOf("{lat}");
88418843
lngIndex = path.indexOf("{lng}");
8842-
if(zIndex === -1 || latIndex === -1 || lngIndex === -1){
8843-
return;
8844-
}
88458844
if (hash.indexOf("#") === 0) {
88468845
hash = hash.substr(1);
88478846
}
@@ -8962,4 +8961,4 @@ L.control.layers.provided = function (baseLayers, overlays, options) {
89628961
}
89638962
});
89648963

8965-
}).call(this);
8964+
}).call(this);

src/leaflet-hash.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,62 @@
1313
}
1414
if (this.options.lc && !this.options.formatBase) {
1515
this.options.formatBase = [
16-
/[\s\:A-Z]/g, function(match) {
16+
/[\sA-Z]/g, function(match) {
1717
if (match.match(/\s/)) {
1818
return "_";
1919
} else if (match.match(/\:/)) {
20-
return "";
20+
return "";
2121
}
2222
if (match.match(/[A-Z]/)) {
2323
return match.toLowerCase();
2424
}
2525
}
2626
];
2727
}
28-
if (this.map._loaded || location.hash) {
28+
if (this.map._loaded) {
2929
return this.startListning();
3030
} else {
31-
return this.map.on("load", this.startListning,this);
31+
return this.map.on("load", this.startListning);
3232
}
3333
},
3434
startListning: function() {
35-
var onHashChange,phash;
35+
var onHashChange,
36+
_this = this;
3637
if (location.hash) {
37-
phash = this.parseHash(location.hash);
38-
if(phash){
39-
this.updateFromState(phash);
40-
}
38+
this.updateFromState(this.parseHash(location.hash));
4139
}
4240
if (history.pushState) {
4341
if (!location.hash) {
4442
history.replaceState.apply(history, this.formatState());
4543
}
4644
window.onpopstate = function(event) {
4745
if (event.state) {
48-
return this.updateFromState(event.state);
46+
return _this.updateFromState(event.state);
4947
}
5048
};
5149
this.map.on("moveend", function() {
5250
var pstate;
53-
pstate = this.formatState();
54-
if (location.hash !== pstate[2] && !this.moving) {
51+
pstate = _this.formatState();
52+
if (location.hash !== pstate[2] && !_this.moving) {
5553
return history.pushState.apply(history, pstate);
5654
}
57-
},this);
55+
});
5856
} else {
5957
if (!location.hash) {
6058
location.hash = this.formatState()[2];
6159
}
6260
onHashChange = function() {
6361
var pstate;
64-
pstate = this.formatState();
65-
if (location.hash !== pstate[2] && !this.moving) {
62+
pstate = _this.formatState();
63+
if (location.hash !== pstate[2] && !_this.moving) {
6664
return location.hash = pstate[2];
6765
}
6866
};
69-
this.map.on("moveend", onHashChange, this);
67+
this.map.on("moveend", onHashChange);
7068
if (('onhashchange' in window) && (window.documentMode === void 0 || window.documentMode > 7)) {
7169
window.onhashchange = function() {
7270
if (location.hash) {
73-
return this.updateFromState(this.parseHash(location.hash));
71+
return _this.updateFromState(_this.parseHash(location.hash));
7472
}
7573
};
7674
} else {
@@ -79,28 +77,25 @@
7977
}
8078
return this.map.on("baselayerchange", function(e) {
8179
var pstate, _ref;
82-
this.base = (_ref = this.options.lc._layers[e.layer._leaflet_id].name).replace.apply(_ref, _this.options.formatBase);
83-
pstate = this.formatState();
80+
_this.base = (_ref = _this.options.lc._layers[e.layer._leaflet_id].name).replace.apply(_ref, _this.options.formatBase);
81+
pstate = _this.formatState();
8482
if (history.pushState) {
85-
if (location.hash !== pstate[2] && !this.moving) {
83+
if (location.hash !== pstate[2] && !_this.moving) {
8684
return history.pushState.apply(history, pstate);
8785
}
8886
} else {
89-
if (location.hash !== pstate[2] && !this.moving) {
87+
if (location.hash !== pstate[2] && !_this.moving) {
9088
return location.hash = pstate[2];
9189
}
9290
}
93-
}, this);
91+
});
9492
},
9593
parseHash: function(hash) {
9694
var args, lat, latIndex, lngIndex, lon, out, path, zIndex, zoom;
9795
path = this.options.path.split("/");
9896
zIndex = path.indexOf("{z}");
9997
latIndex = path.indexOf("{lat}");
10098
lngIndex = path.indexOf("{lng}");
101-
if(zIndex === -1 || latIndex === -1 || lngIndex === -1){
102-
return;
103-
}
10499
if (hash.indexOf("#") === 0) {
105100
hash = hash.substr(1);
106101
}
@@ -221,4 +216,4 @@
221216
}
222217
});
223218

224-
}).call(this);
219+
}).call(this);

src/leaflet-providers.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,13 @@ L.Control.Layers.Provided = L.Control.Layers.extend({
314314
len = base.length,
315315
i=0;
316316
while(i<len){
317-
if (i === 0) {
317+
if(typeof base[i] === "string"){
318+
if (i === 0) {
318319
first = L.tileLayer.provider(base[0]);
319320
out[base[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = first;
320-
} else {
321+
} else {
321322
out[base[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = L.tileLayer.provider(base[i]);
323+
}
322324
}
323325
i++;
324326
}
@@ -332,7 +334,9 @@ L.Control.Layers.Provided = L.Control.Layers.extend({
332334
len = overlay.length,
333335
i=0;
334336
while(i<len){
335-
out[overlay[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = L.tileLayer.provider(overlay[i]);
337+
if(typeof base[i] === "string"){
338+
out[overlay[i].replace(/\./g,": ").replace(/([a-z])([A-Z])/g,"$1 $2")] = L.tileLayer.provider(overlay[i]);
339+
}
336340
i++;
337341
}
338342
overlay = out;

0 commit comments

Comments
 (0)