static/tiles.js
author Tero Marttila <terom@fixme.fi>
Tue, 05 May 2009 19:37:32 +0300
changeset 13 a0cb32f3de3d
permissions -rw-r--r--
add silly crap (FastCGI, tiles.*)
13
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
// A source of tile images of a specific width/height, zoom level range, and some other attributes
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
var Source = Class.create({
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
    initialize: function (path, tile_width, tile_height, zoom_min, zoom_max) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
        // relative path?
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
        if (path.substring(0, 1) != "/") {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
            // current document path
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
            _path = document.location.pathname;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
            // as relative
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
            _path = _path.substring(0, _path.lastIndexOf("/"));
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
            // conact to make absolute path
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
            path = _path + "/" + path
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
        }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
        // store
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
        this.path = path;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
        this.tile_width = tile_width;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
        this.tile_height = tile_height;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
        this.zoom_min = zoom_min;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
        this.zoom_max = zoom_max;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
        this.refresh = false;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
        this.opt_key = this.opt_value = null;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
    // build a URL for the given tile image
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
    build_url: function (col, row, zl, sw, sh) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
        // two-bit hash (0-4) based on the (col, row)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
        var hash = ( (col % 2) << 1 | (row % 2) ) + 1;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
        // the subdomain to use
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
        var subdomain = "";
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
        if (0)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
            subdomain = "tile" + hash + ".";
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
        // the (x, y) co-ordinates
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
        var x = col * this.tile_width;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
        var y = row * this.tile_height;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
        var url = "http://" + subdomain + document.location.host + this.path + "?x=" + x + "&y=" + y + "&z=" + zl + "&sw=" + sw + "&sh=" + sh;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
        if (this.refresh)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
            url += "&ts=" + new Date().getTime();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
        if (this.opt_key && this.opt_value)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
            url += "&" + this.opt_key + "=" + this.opt_value;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
        return url;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
});
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
// a viewport that contains a substrate which contains several zoom layers which contain many tiles
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
var Viewport = Class.create({
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
    initialize: function (source, viewport_id) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
        this.source = source;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
        this.id = viewport_id;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
        this.div = $(viewport_id);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
        this.substrate = this.div.down("div.substrate");
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
        // the stack of zoom levels
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
        this.zoom_layers = [];
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
        // pre-populate the stack
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
        for (var zoom_level = source.zoom_min; zoom_level <= source.zoom_max; zoom_level++) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
            var zoom_layer = new ZoomLayer(source, zoom_level);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    71
            this.substrate.appendChild(zoom_layer.div);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
            this.zoom_layers[zoom_level] = zoom_layer;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    73
        }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
        // make the substrate draggable
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
        this.draggable = new Draggable(this.substrate, {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
            onStart: this.on_scroll_start.bind(this),
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
            onDrag: this.on_scroll_move.bind(this),
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
            onEnd: this.on_scroll_end.bind(this),
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
        });
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    81
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
        // event handlers
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    83
        Event.observe(this.substrate, "dblclick", this.on_dblclick.bindAsEventListener(this));
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    84
        Event.observe(this.substrate, "mousewheel", this.on_mousewheel.bindAsEventListener(this));
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    85
        Event.observe(this.substrate, "DOMMouseScroll", this.on_mousewheel.bindAsEventListener(this));     // mozilla
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    86
        Event.observe(document, "resize", this.on_resize.bindAsEventListener(this));
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    87
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    88
        // load initial view
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    89
        this.update_size();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    90
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
        // this sets the scroll offsets, zoom level, and loads the tiles
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
        this.zoom_to(0, 0, 0);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
    /* event handlers */
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    97
    // window resized
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
    on_resize: function (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
        this.update_size();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
        this.update_tiles();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   101
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   102
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   103
    // double-click handler
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   104
    on_dblclick: function (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   105
        var offset = this.event_offset(ev);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   106
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   107
        this.zoom_center_to(
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   108
            this.scroll_x + offset.x,
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   109
            this.scroll_y + offset.y,
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
            1   // zoom in
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
        );
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   113
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
    // mousewheel handler
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
    on_mousewheel: function (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
        // this works in very weird ways, so it's based on code from http://adomas.org/javascript-mouse-wheel/
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
        // (it didn't include any license, so this is written out manually)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   118
        var delta;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   119
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   120
        // this is browser-dependant...
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
        if (ev.wheelDelta) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
            // IE + Opera
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   123
            delta = ev.wheelDelta;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   124
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
            if (window.opera) {  
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   126
                // Opera, but apparently not newer versions?
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
                //delta = -delta;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
            }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   129
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
        } else if (ev.detail) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   131
            // Mozilla
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   132
            delta = -ev.detail;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   133
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   134
        } else {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   135
            // mousewheel not supported...
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
            return;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   137
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
        }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   139
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   140
        // don't scroll the page
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   141
        if (ev.preventDefault)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   142
            ev.preventDefault();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   143
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   144
        // delta > 0 : scroll up, zoom in
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   145
        // delta < 0 : scroll down, zoom out
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   146
        delta = delta < 0 ? -1 : 1;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   147
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   148
        // Firefox's DOMMouseEvent's pageX/Y attributes are broken. layerN is for mozilla, offsetN for IE, seems to work
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   149
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   150
        // absolute location of the cursor
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   151
        var x = parseInt(ev.target.style.left) + (ev.layerX ? ev.layerX : ev.offsetX);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   152
        var y = parseInt(ev.target.style.top) + (ev.layerY ? ev.layerY : ev.offsetY);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   153
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   154
        // zoom \o/
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   155
        this.zoom_center_to(x, y, delta);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   156
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   157
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   158
    // substrate scroll was started
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
    on_scroll_start: function (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   160
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   161
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   162
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   163
    // substrate was scrolled, update scroll_{x,y}, and then update tiles after 100ms
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   164
    on_scroll_move: function (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   165
        this.update_scroll();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   166
        this.update_after_timeout();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   167
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   169
    // substrate scroll was ended, update tiles now
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
    on_scroll_end: function (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
        this.update_now();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   172
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   173
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   174
    /* get state */
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   175
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
    // return the absolute (x, y) coords of the given event inside the viewport
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   177
    event_offset: function (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   178
        var offset = this.div.cumulativeOffset();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   179
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   180
        return {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   181
            x: ev.pointerX() - offset.left, 
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   182
            y: ev.pointerY() - offset.top
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   183
        };
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   184
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   185
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   186
    /* modify state */
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   188
    // scroll the view to place the given absolute (x, y) co-ordinate at the top left
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   189
    scroll_to: function (x, y) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   190
        // update it via the style
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   191
        this.substrate.style.top = "-" + y + "px";
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   192
        this.substrate.style.left = "-" + x + "px";
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   193
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   194
        // update these as well
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   195
        this.scroll_x = x;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   196
        this.scroll_y = y;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   197
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   198
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   199
    // scroll the view to place the given absolute (x, y) co-ordinate at the center
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   200
    scroll_center_to: function (x, y) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   201
        return this.scroll_to(
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   202
            x - this.center_offset_x,
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   203
            y - this.center_offset_y
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   204
        );
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   205
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   206
 
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   207
    // zoom à la delta such that the given (zoomed) absolute (x, y) co-ordinates will be at the top left
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   208
    zoom_scaled: function (x, y, delta) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   209
        if (!this.update_zoom(delta))
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   210
            return false;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   211
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   212
        // scroll to the new position
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   213
        this.scroll_to(x, y);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   214
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   215
        // update view
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   216
        // XXX: ...
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   217
        this.update_after_timeout();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   218
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   219
        return true;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   220
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   221
   
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   222
    // zoom à la delta such that the given (current) absolute (x, y) co-ordinates will be at the top left
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   223
    zoom_to: function (x, y, delta) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   224
        return this.zoom_scaled(
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   225
            scaleByZoomDelta(x, delta),
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   226
            scaleByZoomDelta(y, delta),
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   227
            delta
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   228
        );
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   229
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   230
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   231
    // zoom à la delta such that the given (current) absolute (x, y) co-ordinates will be at the center
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   232
    zoom_center_to: function (x, y, delta) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   233
        return this.zoom_scaled(
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   234
            scaleByZoomDelta(x, delta) - this.center_offset_x,
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   235
            scaleByZoomDelta(y, delta) - this.center_offset_y,
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   236
            delta
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   237
        );
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   238
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   239
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   240
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   241
    /* update view/state to reflect reality */
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   242
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   243
    // figure out the viewport dimensions
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   244
    update_size: function () {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   245
        this.view_width = this.div.getWidth();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   246
        this.view_height = this.div.getHeight();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   247
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   248
        this.center_offset_x = Math.floor(this.view_width / 2);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   249
        this.center_offset_y = Math.floor(this.view_height / 2);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   250
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   251
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   252
    // figure out the scroll offset as absolute pixel co-ordinates at the top left
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   253
    update_scroll: function() {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   254
        this.scroll_x = -parseInt(this.substrate.style.left);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   255
        this.scroll_y = -parseInt(this.substrate.style.top);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   256
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   257
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   258
    // wiggle the ZoomLevels around to match the current zoom level
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   259
    update_zoom: function(delta) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   260
        if (!this.zoom_layer) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   261
            // first zoom operation
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   262
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   263
            // is the new zoom level valid?
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   264
            if (!this.zoom_layers[delta])
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   265
                return false;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   266
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   267
            // set the zoom layyer
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   268
            this.zoom_layer = this.zoom_layers[delta];
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   269
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   270
            // enable it
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   271
            this.zoom_layer.enable(11);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   272
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   273
            // no need to .update_tiles or anything like that
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   274
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   275
        } else {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   276
            // is the new zoom level valid?
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   277
            if (!this.zoom_layers[this.zoom_layer.level + delta])
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   278
                return false;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   279
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   280
            var zoom_old = this.zoom_layer;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   281
            var zoom_new = this.zoom_layers[this.zoom_layer.level + delta];
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   282
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   283
            // XXX: ugly hack
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   284
            if (this.zoom_timer) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   285
                clearTimeout(this.zoom_timer);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   286
                this.zoom_timer = null;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   287
            }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   288
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   289
            // get other zoom layers out of the way
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   290
            this.zoom_layers.each(function (zl) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   291
                zl.disable();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   292
            });
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   293
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   294
            // update the zoom layer
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   295
            this.zoom_layer = zoom_new;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   296
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   297
            // apply new z-indexes, preferr the current one over the new one
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   298
            zoom_new.enable(11);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   299
            zoom_old.enable(10);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   300
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   301
            // resize the tiles in the two zoom layers
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   302
            zoom_new.update_tiles(zoom_new.level);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   303
            zoom_old.update_tiles(zoom_old.level);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   304
            
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   305
            // XXX: ugly hack
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   306
            this.zoom_timer = setTimeout(function () { zoom_old.disable()}, 1000);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   307
        }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   308
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   309
        return true;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   310
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   311
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   312
    // ensure that all tiles that are currently visible are loaded
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   313
    update_tiles: function() {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   314
        // short names for some vars...
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   315
        var x = this.scroll_x;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   316
        var y = this.scroll_y;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   317
        var sw = this.view_width;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   318
        var sh = this.view_height;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   319
        var tw = this.source.tile_width;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   320
        var th = this.source.tile_height;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   321
        var zl = this.zoom_layer.level;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   322
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   323
        // figure out what set of columns are visible
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   324
        var start_col = Math.max(0, Math.floor(x / tw));
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   325
        var start_row = Math.max(0, Math.floor(y / th));
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   326
        var end_col = Math.floor((x + sw) / tw);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   327
        var end_row = Math.floor((y + sh) / th);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   328
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   329
        // loop through all those tiles
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   330
        for (var col = start_col; col <= end_col; col++) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   331
            for (var row = start_row; row <= end_row; row++) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   332
                // the tile's id
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   333
                var id = "tile_" + this.zoom_layer.level + "_" + col + "_" + row;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   334
                
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   335
                // does the element exist already?
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   336
                var t = $(id);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   337
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   338
                if (!t) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   339
                    // build a new tile
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   340
                    t = Builder.node("img", {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   341
                            src:    this.source.build_url(col, row, zl, sw, sh),
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   342
                            id:     id,
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   343
                            title:  "(" + col + ", " + row + ")",
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   344
                            // style set later
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   345
                        }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   346
                    );
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   347
                    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   348
                    // set the CSS style stuff
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   349
                    t.style.top = th * row;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   350
                    t.style.left = tw * col;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   351
                    t.style.display = "none";
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   352
                    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   353
                    // wait for it to load
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   354
                    Event.observe(t, "load", _tile_loaded.bindAsEventListener(t));
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   355
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   356
                    // store the col/row
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   357
                    t.__col = col;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   358
                    t.__row = row;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   359
                    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   360
                    // add it to the zoom layer
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   361
                    this.zoom_layer.add_tile(t);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   362
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   363
                } else if (this.source.reload) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   364
                    // force the tile to reload
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   365
                    touch_tile(t, col, row);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   366
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   367
                }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   368
            }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   369
        }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   370
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   371
/* XXX: fixme
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   372
        // update the link-to-this-page thing
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   373
        document.location.hash = "#goto_" + (x + g_w_half) + ":" + g_w + "_" + (y + g_h_half) + ":" + g_h + "_" + g_z;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   374
*/
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   375
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   376
    }, 
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   377
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   378
    // do update_tiles after 100ms, unless we are called again
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   379
    update_after_timeout: function () {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   380
        this._update_idle = false;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   381
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   382
        if (this._update_timeout)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   383
            clearTimeout(this._update_timeout);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   384
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   385
        this._update_timeout = setTimeout(this._update_timeout_trigger.bind(this), 100);  
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   386
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   387
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   388
    _update_timeout_trigger: function () {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   389
        this._update_idle = true;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   390
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   391
        this.update_tiles();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   392
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   393
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   394
    // call update_tiles if it hasn't been called due to update_after_timeout
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   395
    update_now: function () {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   396
        if (this._update_timeout)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   397
            clearTimeout(this._update_timeout);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   398
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   399
        if (!this._update_idle)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   400
            this.update_tiles();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   401
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   402
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   403
});
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   404
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   405
// used by Viewport.update_tiles to make a tile visible after it has loaded
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   406
function _tile_loaded (ev) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   407
    this.style.display = "block";
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   408
}
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   409
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   410
// a zoom layer containing the tiles for one zoom level
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   411
var ZoomLayer = Class.create({
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   412
    initialize: function (source, zoom_level) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   413
        this.source = source;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   414
        this.level = zoom_level;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   415
        this.div = Builder.node("div", { id: "zl_" + this.level, style: "position: relative; display: none;"});
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   416
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   417
        // our tiles
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   418
        this.tiles = [];
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   419
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   420
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   421
    // add a tile to this zoom layer
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   422
    add_tile: function (tile) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   423
        this.div.appendChild(tile);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   424
        this.tiles.push(tile);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   425
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   426
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   427
    // make this zoom layer visible with the given z-index
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   428
    enable: function (z_index) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   429
        this.div.style.zIndex = z_index;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   430
        this.div.show();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   431
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   432
   
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   433
    // hide this zoom layer
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   434
    disable: function (z_index) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   435
        this.div.hide();
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   436
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   437
    
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   438
    // update the tiles in this zoom layer so that they are in the correct position and of the correct size when
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   439
    // viewed with the given zoom level
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   440
    update_tiles: function (zoom_level) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   441
        var zd = zoom_level - this.level;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   442
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   443
        var tw = scaleByZoomDelta(this.source.tile_width, zd);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   444
        var th = scaleByZoomDelta(this.source.tile_height, zd);
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   445
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   446
        var tiles = this.tiles;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   447
        var tiles_len = tiles.length;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   448
        var t, ts;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   449
        
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   450
        for (var i = 0; i < tiles_len; i++) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   451
            t = tiles[i];
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   452
            ts = t.style;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   453
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   454
            ts.width = tw;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   455
            ts.height = th;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   456
            ts.top = th*t.__row;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   457
            ts.left = tw*t.__col;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   458
        }
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   459
    },
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   460
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   461
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   462
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   463
});
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   464
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   465
// scale the given co-ordinate by a zoom delta. If we zoom in (dz > 0), n will become larger, and if we zoom 
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   466
// out (dz < 0), n will become smaller.
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   467
function scaleByZoomDelta (n, dz) {
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   468
    if (dz > 0)
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   469
        return n << dz;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   470
    else
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   471
        return n >> -dz;
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   472
}
a0cb32f3de3d add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   473