- var precision = zoomPrecision(args.zoom);
- return '#' + args.zoom +
- '/' + args.lat.toFixed(precision) +
- '/' + args.lon.toFixed(precision);
+ var center, zoom, layers;
+
+ if (args instanceof L.Map) {
+ center = args.getCenter();
+ zoom = args.getZoom();
+ layers = args.getLayersCode();
+ } else {
+ center = L.latLng(args.lat, args.lon);
+ zoom = args.zoom;
+ layers = args.layers || '';
+ }
+
+ center = center.wrap();
+ layers = layers.replace('M', '');
+
+ var precision = zoomPrecision(zoom),
+ hash = '#map=' + zoom +
+ '/' + center.lat.toFixed(precision) +
+ '/' + center.lng.toFixed(precision);
+
+ if (layers) {
+ hash += '&layers=' + layers;
+ }
+
+ return hash;