ignore invalid #hash values for cx:cy:zl
authorTero Marttila <terom@fixme.fi>
Sat, 09 Jan 2010 15:30:19 +0200
changeset 50 ba9d03e46925
parent 49 9dedd0e30b6b
child 51 866eb1aad566
ignore invalid #hash values for cx:cy:zl
bin/dev-server
static/tiles2.js
--- a/bin/dev-server	Sat Jan 09 15:13:42 2010 +0200
+++ b/bin/dev-server	Sat Jan 09 15:30:19 2010 +0200
@@ -13,7 +13,7 @@
     }),
 })
 
-def main (host='127.0.0.1', port=8000) :
+def main (host='0.0.0.0', port=8000) :
     httpd = wsgiref.simple_server.make_server(host, port, app)
 
     print "Listening on %s:%d" % (host, port)
--- a/static/tiles2.js	Sat Jan 09 15:13:42 2010 +0200
+++ b/static/tiles2.js	Sat Jan 09 15:30:19 2010 +0200
@@ -109,7 +109,9 @@
             Event.observe(this.btn_zoom_out, "click", this.zoom_out.bindAsEventListener(this));
            
         // initial view location (centered)
-        var cx = 0, cy = 0, zl = 0;
+        var cx = this.source.img_width / 2;
+        var cy = this.source.img_height / 2;
+        var zl = 0; // XXX: would need to scale x/y for this: (this.source.zoom_min + this.source.zoom_max) / 2;
         
         // from link?
         if (document.location.hash) {
@@ -117,15 +119,9 @@
             var pt = document.location.hash.substr(1).split(":");
             
             // unpack    
-            if (pt.length) cx = parseInt(pt.shift());
-            if (pt.length) cy = parseInt(pt.shift());
-            if (pt.length) zl = parseInt(pt.shift());
-
-        } else {
-            // start in the center
-            cx = this.source.img_width / 2;
-            cy = this.source.img_height / 2;
-            zl = 0; // XXX: need to scale x/y for this: (this.source.zoom_min + this.source.zoom_max) / 2;
+            if (pt.length) cx = parseInt(pt.shift()) || cx;
+            if (pt.length) cy = parseInt(pt.shift()) || cy;
+            if (pt.length) zl = parseInt(pt.shift()) || zl;
         }
 
         // initialize zoom state to given zl