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