implement x:y:z tuple in URL
authorTero Marttila <terom@fixme.fi>
Wed, 06 Jan 2010 14:45:55 +0200
changeset 32 aa168c7da551
parent 31 7eec7486a0af
child 33 0ed40e11b0e8
implement x:y:z tuple in URL
static/tiles2.js
--- a/static/tiles2.js	Wed Jan 06 14:29:55 2010 +0200
+++ b/static/tiles2.js	Wed Jan 06 14:45:55 2010 +0200
@@ -70,12 +70,29 @@
         Event.observe(this.substrate, "mousewheel", this.on_mousewheel.bindAsEventListener(this));
         Event.observe(this.substrate, "DOMMouseScroll", this.on_mousewheel.bindAsEventListener(this));     // mozilla
         Event.observe(document, "resize", this.on_resize.bindAsEventListener(this));
-
-        // load initial view
+    
+        // set viewport size
         this.update_size();
+        
+        // initial location?    
+        if (document.location.hash) {
+            // x:y:z tuple
+            var pt = document.location.hash.substr(1).split(":");
+            
+            // unpack
+            var cx = 0, cy = 0, z = 0;
+            
+            if (pt.length) cx = parseInt(pt.shift());
+            if (pt.length) cy = parseInt(pt.shift());
+            if (pt.length) z = parseInt(pt.shift());
 
-        // this sets the scroll offsets, zoom level, and loads the tiles
-        this.zoom_to(0, 0, 0);
+            // initial view
+            this.zoom_center_to(cx, cy, z);
+
+        } else {
+            // this sets the scroll offsets, zoom level, and loads the tiles
+            this.zoom_to(0, 0, 0);
+        }
     },
     
     /* event handlers */
@@ -354,11 +371,8 @@
             }
         }
 
-/* XXX: fixme
         // update the link-to-this-page thing
-        document.location.hash = "#goto_" + (x + g_w_half) + ":" + g_w + "_" + (y + g_h_half) + ":" + g_h + "_" + g_z;
-*/
-
+        document.location.hash = "#" + (this.scroll_x + this.center_offset_x) + ":" + (this.scroll_y + this.center_offset_y) + ":" + this.zoom_layer.level;
     }, 
 
     // do update_tiles after 100ms, unless we are called again