static/tiles2.js
changeset 43 fcd818eb5a71
parent 40 5454d2e2f633
child 45 0ce4064c428e
equal deleted inserted replaced
40:5454d2e2f633 43:fcd818eb5a71
     1 // A source of tile images of a specific width/height, zoom level range, and some other attributes
     1 // A source of tile images of a specific width/height, zoom level range, and some other attributes
     2 var Source = Class.create({
     2 var Source = Class.create({
     3     initialize: function (path, tile_width, tile_height, zoom_min, zoom_max) {
     3     initialize: function (path, tile_width, tile_height, zoom_min, zoom_max, img_width, img_height) {
     4         this.path = path;
     4         this.path = path;
     5         this.tile_width = tile_width;
     5         this.tile_width = tile_width;
     6         this.tile_height = tile_height;
     6         this.tile_height = tile_height;
     7         this.zoom_min = zoom_min;
     7         this.zoom_min = zoom_min;
     8         this.zoom_max = zoom_max;
     8         this.zoom_max = zoom_max;
       
     9         this.img_width = img_width;
       
    10         this.img_height = img_height;
     9 
    11 
    10         this.refresh = false;
    12         this.refresh = false;
    11         this.opt_key = this.opt_value = null;
    13         this.opt_key = this.opt_value = null;
    12     },
    14     },
    13     
    15     
    89         // set viewport size
    91         // set viewport size
    90         this.update_size();
    92         this.update_size();
    91         
    93         
    92         // this comes after update_size, since it must be updated once we have the size and zoom layer...
    94         // this comes after update_size, since it must be updated once we have the size and zoom layer...
    93         this.image_link = $("lnk-image");
    95         this.image_link = $("lnk-image");
       
    96             
       
    97         // initial location
       
    98         var cx = 0, cy = 0, z = 0;
    94         
    99         
    95         // initial location?    
   100         // initial location?    
    96         if (document.location.hash) {
   101         if (document.location.hash) {
    97             // x:y:z tuple
   102             // x:y:z tuple
    98             var pt = document.location.hash.substr(1).split(":");
   103             var pt = document.location.hash.substr(1).split(":");
    99             
   104             
   100             // unpack
   105             // unpack    
   101             var cx = 0, cy = 0, z = 0;
       
   102             
       
   103             if (pt.length) cx = parseInt(pt.shift());
   106             if (pt.length) cx = parseInt(pt.shift());
   104             if (pt.length) cy = parseInt(pt.shift());
   107             if (pt.length) cy = parseInt(pt.shift());
   105             if (pt.length) z = parseInt(pt.shift());
   108             if (pt.length) z = parseInt(pt.shift());
   106 
   109 
   107             // initial view
       
   108             this.zoom_scaled(
       
   109                 cx - this.center_offset_x, 
       
   110                 cy - this.center_offset_y, 
       
   111                 z
       
   112             );
       
   113 
       
   114         } else {
   110         } else {
   115             // this sets the scroll offsets, zoom level, and loads the tiles
   111             // start in the center
   116             this.zoom_to(0, 0, 0);
   112             cx = this.source.img_width / 2;
       
   113             cy = this.source.img_height / 2;
       
   114             z = 0; // XXX: xy unscaled: (this.source.zoom_min + this.source.zoom_max) / 2;
   117         }
   115         }
       
   116 
       
   117         // initial view
       
   118         this.zoom_scaled(
       
   119             cx - this.center_offset_x, 
       
   120             cy - this.center_offset_y, 
       
   121             z
       
   122         );
   118     },
   123     },
   119     
   124     
   120     /* event handlers */
   125     /* event handlers */
   121 
   126 
   122     // window resized
   127     // window resized