leaflet-fullHash is broken, use leaflet-hash with workaround for now

pull/54/merge
Candid Dauth 2016-10-18 18:02:32 +03:00
rodzic c7b11d8dfa
commit a907718036
3 zmienionych plików z 46 dodań i 3 usunięć

Wyświetl plik

@ -32,7 +32,7 @@
"clipboard": "^1.5.12",
"togeojson": "https://github.com/mapbox/togeojson/raw/master/togeojson.js",
"osmtogeojson": "^2.2.12",
"leaflet-fullHash": "https://raw.githubusercontent.com/KoGor/leaflet-fullHash/master/leaflet-fullHash.js"
"leaflet-hash": "https://raw.githubusercontent.com/mlevans/leaflet-hash/master/leaflet-hash.js"
},
"resolutions": {
"leaflet": "^1.0.1"

Wyświetl plik

@ -106,7 +106,7 @@
iconLoading: "glyphicon glyphicon-screenshot"
}).addTo(map.map);
L.hash(map.map, map.layers);
fpUtils.leafletHash(map.map, map.layers);
map.map.on('almost:over', function(e) {
e.layer.fire('fp-almostover', e);

Wyświetl plik

@ -402,7 +402,50 @@
lon: Math.round(lon*100000)/100000,
zoom : zoom
};
}
};
fpUtils.leafletHash = function(map, layers) {
var hashControl = new L.Hash(map);
hashControl.parseHash = function(hash) {
var args = hash.split("/");
var ret = L.Hash.parseHash(args.slice(0, 3).join("/"));
if(ret) {
// This gets called just in L.Hash.update(), so we can already add/remove the layers here
var l = args[3] && args[3].split("-");
if(l && l.length > 0) {
for(var i in layers) {
if(l.indexOf(i) == -1) {
if(map.hasLayer(layers[i]))
map.removeLayer(layers[i]);
} else if(!map.hasLayer(layers[i]))
map.addLayer(layers[i]);
}
}
}
return ret;
};
hashControl.formatHash = function(map) {
var ret = L.Hash.formatHash(map);
var l = [ ];
for(var i in layers) {
if(map.hasLayer(layers[i]))
l.push(i);
}
ret += "/" + l.join("-");
return ret;
};
map.on("layeradd", hashControl.onMapMove, hashControl);
map.on("layerremove", hashControl.onMapMove, hashControl);
return hashControl;
};
return fpUtils;
});