static/tiles2.js
author Tero Marttila <terom@fixme.fi>
Wed, 06 Jan 2010 17:07:24 +0200
changeset 39 eeedb6c2f7c0
parent 38 0abb7289d4b8
child 40 5454d2e2f633
permissions -rw-r--r--
zoom button UI
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
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
    29
        var url = this.path + "?x=" + x + "&y=" + y + "&zoom=" + 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
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
});
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
// 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
    42
var Viewport = Class.create({
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
    initialize: function (source, viewport_id) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
        this.source = source;
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
        this.id = viewport_id;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
        this.div = $(viewport_id);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
        this.substrate = this.div.down("div.substrate");
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
        // the stack of zoom levels
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
        this.zoom_layers = [];
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
        // pre-populate the stack
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
        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
    55
            var zoom_layer = new ZoomLayer(source, zoom_level);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
            this.substrate.appendChild(zoom_layer.div);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
            this.zoom_layers[zoom_level] = zoom_layer;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
        }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
        // make the substrate draggable
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
        this.draggable = new Draggable(this.substrate, {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
            onStart: this.on_scroll_start.bind(this),
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
            onDrag: this.on_scroll_move.bind(this),
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
            onEnd: this.on_scroll_end.bind(this),
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
        });
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
        // event handlers
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
        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
    70
        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
    71
        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
    72
        Event.observe(document, "resize", this.on_resize.bindAsEventListener(this));
39
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    73
        
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    74
        // zoom buttons
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    75
        this.btn_zoom_in = $("btn-zoom-in");
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    76
        this.btn_zoom_out = $("btn-zoom-out");
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    77
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    78
        if (this.btn_zoom_in)
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    79
            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
    80
        
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    81
        if (this.btn_zoom_out)
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    82
            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
    83
    
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    84
        // set viewport size
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    85
        this.update_size();
32
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    86
        
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    87
        // initial location?    
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    88
        if (document.location.hash) {
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    89
            // x:y:z tuple
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    90
            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
    91
            
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    92
            // unpack
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    93
            var cx = 0, cy = 0, z = 0;
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    94
            
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    95
            if (pt.length) cx = parseInt(pt.shift());
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    96
            if (pt.length) cy = parseInt(pt.shift());
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    97
            if (pt.length) z = parseInt(pt.shift());
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
32
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    99
            // initial view
38
0abb7289d4b8 fix intial zoom to be unscaled
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   100
            this.zoom_scaled(
0abb7289d4b8 fix intial zoom to be unscaled
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   101
                cx - this.center_offset_x, 
0abb7289d4b8 fix intial zoom to be unscaled
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   102
                cy - this.center_offset_y, 
0abb7289d4b8 fix intial zoom to be unscaled
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   103
                z
0abb7289d4b8 fix intial zoom to be unscaled
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   104
            );
32
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   105
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   106
        } else {
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   107
            // 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
   108
            this.zoom_to(0, 0, 0);
aa168c7da551 implement x:y:z tuple in URL
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   109
        }
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
    /* event handlers */
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   113
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
    // window resized
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
    on_resize: function (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
        this.update_size();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
        this.update_tiles();
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
    // double-click handler
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
    on_dblclick: function (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
        var offset = this.event_offset(ev);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   123
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   124
        this.zoom_center_to(
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
            this.scroll_x + offset.x,
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   126
            this.scroll_y + offset.y,
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
            1   // zoom in
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
        );
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   129
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   131
    // mousewheel handler
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   132
    on_mousewheel: function (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   133
        // 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
   134
        // (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
   135
        var delta;
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
        // this is browser-dependant...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
        if (ev.wheelDelta) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   139
            // IE + Opera
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   140
            delta = ev.wheelDelta;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   141
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   142
            if (window.opera) {  
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   143
                // Opera, but apparently not newer versions?
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   144
                //delta = -delta;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   145
            }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   146
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   147
        } else if (ev.detail) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   148
            // Mozilla
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   149
            delta = -ev.detail;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   150
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   151
        } else {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   152
            // mousewheel not supported...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   153
            return;
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
        }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   156
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   157
        // don't scroll the page
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   158
        if (ev.preventDefault)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
            ev.preventDefault();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   160
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   161
        // delta > 0 : scroll up, zoom in
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   162
        // delta < 0 : scroll down, zoom out
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   163
        delta = delta < 0 ? -1 : 1;
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
        // 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
   166
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   167
        // absolute location of the cursor
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
        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
   169
        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
   170
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
        // zoom \o/
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   172
        this.zoom_center_to(x, y, delta);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   173
    },
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
    // substrate scroll was started
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
    on_scroll_start: function (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   177
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
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   180
    // 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
   181
    on_scroll_move: function (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   182
        this.update_scroll();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   183
        this.update_after_timeout();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   184
    },
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
    // substrate scroll was ended, update tiles now
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
    on_scroll_end: function (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   188
        this.update_now();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   189
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   190
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   191
    /* get state */
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
    // 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
   194
    event_offset: function (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   195
        var offset = this.div.cumulativeOffset();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   196
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   197
        return {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   198
            x: ev.pointerX() - offset.left, 
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   199
            y: ev.pointerY() - offset.top
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
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   202
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   203
    /* modify state */
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
    // 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
   206
    scroll_to: function (x, y) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   207
        // update it via the style
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   208
        this.substrate.style.top = "-" + y + "px";
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   209
        this.substrate.style.left = "-" + x + "px";
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
        // update these as well
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   212
        this.scroll_x = x;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   213
        this.scroll_y = y;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   214
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   215
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   216
    // 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
   217
    scroll_center_to: function (x, y) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   218
        return this.scroll_to(
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   219
            x - this.center_offset_x,
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   220
            y - this.center_offset_y
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   221
        );
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
    // 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
   225
    zoom_scaled: function (x, y, delta) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   226
        if (!this.update_zoom(delta))
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   227
            return false;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   228
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   229
        // scroll to the new position
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   230
        this.scroll_to(x, y);
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
        // update view
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   233
        // XXX: ...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   234
        this.update_after_timeout();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   235
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   236
        return true;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   237
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   238
   
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   239
    // 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
   240
    zoom_to: function (x, y, delta) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   241
        return this.zoom_scaled(
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   242
            scaleByZoomDelta(x, delta),
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   243
            scaleByZoomDelta(y, delta),
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   244
            delta
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
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   248
    // 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
   249
    zoom_center_to: function (x, y, delta) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   250
        return this.zoom_scaled(
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   251
            scaleByZoomDelta(x, delta) - this.center_offset_x,
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   252
            scaleByZoomDelta(y, delta) - this.center_offset_y,
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   253
            delta
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
39
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   257
    // zoom à la delta, keeping the view centered
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   258
    zoom_centered: function (delta) {
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   259
        return this.zoom_center_to(
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   260
            this.scroll_x + this.center_offset_x,
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   261
            this.scroll_y + this.center_offset_y,
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   262
            delta
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   263
        );
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   264
    },
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   265
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   266
    // zoom in one level, keeping the view centered
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   267
    zoom_in: function () {
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   268
        return this.zoom_centered(+1);
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   269
    },
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   270
    
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   271
    // zoom out one leve, keeping the view centered
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   272
    zoom_out: function () {
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   273
        return this.zoom_centered(-1);
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   274
    },
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   275
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   276
    /* update view/state to reflect reality */
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   277
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   278
    // figure out the viewport dimensions
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   279
    update_size: function () {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   280
        this.view_width = this.div.getWidth();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   281
        this.view_height = this.div.getHeight();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   282
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   283
        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
   284
        this.center_offset_y = Math.floor(this.view_height / 2);
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
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   287
    // 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
   288
    update_scroll: function() {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   289
        this.scroll_x = -parseInt(this.substrate.style.left);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   290
        this.scroll_y = -parseInt(this.substrate.style.top);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   291
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   292
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   293
    // 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
   294
    update_zoom: function(delta) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   295
        if (!this.zoom_layer) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   296
            // first zoom operation
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   297
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   298
            // is the new zoom level valid?
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   299
            if (!this.zoom_layers[delta])
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   300
                return false;
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
            // set the zoom layyer
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   303
            this.zoom_layer = this.zoom_layers[delta];
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   304
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   305
            // enable it
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   306
            this.zoom_layer.enable(11);
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
            // no need to .update_tiles or anything like that
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   309
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   310
        } else {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   311
            // is the new zoom level valid?
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   312
            if (!this.zoom_layers[this.zoom_layer.level + delta])
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   313
                return false;
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
            var zoom_old = this.zoom_layer;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   316
            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
   317
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   318
            // XXX: ugly hack
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   319
            if (this.zoom_timer) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   320
                clearTimeout(this.zoom_timer);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   321
                this.zoom_timer = null;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   322
            }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   323
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   324
            // get other zoom layers out of the way
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   325
            this.zoom_layers.each(function (zl) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   326
                zl.disable();
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
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   329
            // update the zoom layer
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   330
            this.zoom_layer = zoom_new;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   331
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   332
            // 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
   333
            zoom_new.enable(11);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   334
            zoom_old.enable(10);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   335
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   336
            // resize the tiles in the two zoom layers
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   337
            zoom_new.update_tiles(zoom_new.level);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   338
            zoom_old.update_tiles(zoom_old.level);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   339
            
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   340
            // XXX: ugly hack
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   341
            this.zoom_timer = setTimeout(function () { zoom_old.disable()}, 1000);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   342
        }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   343
39
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   344
        // update UI
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   345
        this.update_zoom_ui();
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   346
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   347
        return true;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   348
    },
39
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   349
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   350
    // keep the zoom buttons, if any, updated
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   351
    update_zoom_ui: function () {
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   352
        if (this.btn_zoom_in)
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   353
            (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
   354
        
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   355
        if (this.btn_zoom_out)
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   356
            (this.zoom_layer.level <= this.source.zoom_min) ? this.btn_zoom_out.disable() : this.btn_zoom_out.enable();
eeedb6c2f7c0 zoom button UI
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   357
    },
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   358
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   359
    // 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
   360
    update_tiles: function() {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   361
        // short names for some vars...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   362
        var x = this.scroll_x;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   363
        var y = this.scroll_y;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   364
        var sw = this.view_width;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   365
        var sh = this.view_height;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   366
        var tw = this.source.tile_width;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   367
        var th = this.source.tile_height;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   368
        var zl = this.zoom_layer.level;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   369
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   370
        // figure out what set of columns are visible
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   371
        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
   372
        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
   373
        var end_col = Math.floor((x + sw) / tw);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   374
        var end_row = Math.floor((y + sh) / th);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   375
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   376
        // loop through all those tiles
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   377
        for (var col = start_col; col <= end_col; col++) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   378
            for (var row = start_row; row <= end_row; row++) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   379
                // the tile's id
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   380
                var id = "tile_" + this.zoom_layer.level + "_" + col + "_" + row;
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
                // does the element exist already?
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   383
                var t = $(id);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   384
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   385
                if (!t) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   386
                    // build a new tile
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   387
                    t = Builder.node("img", {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   388
                            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
   389
                            id:     id,
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   390
                            title:  "(" + col + ", " + row + ")",
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   391
                            // style set later
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   392
                        }
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
                    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   395
                    // set the CSS style stuff
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   396
                    t.style.top = th * row;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   397
                    t.style.left = tw * col;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   398
                    t.style.display = "none";
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   399
                    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   400
                    // wait for it to load
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   401
                    Event.observe(t, "load", _tile_loaded.bindAsEventListener(t));
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   402
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   403
                    // store the col/row
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   404
                    t.__col = col;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   405
                    t.__row = row;
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
                    // add it to the zoom layer
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   408
                    this.zoom_layer.add_tile(t);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   409
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   410
                } else if (this.source.reload) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   411
                    // force the tile to reload
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   412
                    touch_tile(t, col, row);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   413
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
            }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   416
        }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   417
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   418
        // 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
   419
        document.location.hash = "#" + (this.scroll_x + this.center_offset_x) + ":" + (this.scroll_y + this.center_offset_y) + ":" + this.zoom_layer.level;
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   420
    }, 
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
    // 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
   423
    update_after_timeout: function () {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   424
        this._update_idle = false;
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
        if (this._update_timeout)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   427
            clearTimeout(this._update_timeout);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   428
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   429
        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
   430
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   431
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   432
    _update_timeout_trigger: function () {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   433
        this._update_idle = true;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   434
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   435
        this.update_tiles();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   436
    },
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
    // 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
   439
    update_now: function () {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   440
        if (this._update_timeout)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   441
            clearTimeout(this._update_timeout);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   442
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   443
        if (!this._update_idle)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   444
            this.update_tiles();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   445
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   446
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   447
});
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   448
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   449
// 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
   450
function _tile_loaded (ev) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   451
    this.style.display = "block";
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   452
}
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   453
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   454
// 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
   455
var ZoomLayer = Class.create({
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   456
    initialize: function (source, zoom_level) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   457
        this.source = source;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   458
        this.level = zoom_level;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   459
        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
   460
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   461
        // our tiles
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   462
        this.tiles = [];
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
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   465
    // add a tile to this zoom layer
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   466
    add_tile: function (tile) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   467
        this.div.appendChild(tile);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   468
        this.tiles.push(tile);
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
    
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   471
    // 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
   472
    enable: function (z_index) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   473
        this.div.style.zIndex = z_index;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   474
        this.div.show();
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   475
    },
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   476
   
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   477
    // hide this zoom layer
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   478
    disable: function (z_index) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   479
        this.div.hide();
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
    // 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
   483
    // viewed with the given zoom level
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   484
    update_tiles: function (zoom_level) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   485
        var zd = zoom_level - this.level;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   486
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   487
        var tw = scaleByZoomDelta(this.source.tile_width, zd);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   488
        var th = scaleByZoomDelta(this.source.tile_height, zd);
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   489
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   490
        var tiles = this.tiles;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   491
        var tiles_len = tiles.length;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   492
        var t, ts;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   493
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   494
        for (var i = 0; i < tiles_len; i++) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   495
            t = tiles[i];
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   496
            ts = t.style;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   497
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   498
            ts.width = tw;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   499
            ts.height = th;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   500
            ts.top = th*t.__row;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   501
            ts.left = tw*t.__col;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   502
        }
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   503
    },
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
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   507
});
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   508
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   509
// 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
   510
// out (dz < 0), n will become smaller.
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   511
function scaleByZoomDelta (n, dz) {
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   512
    if (dz > 0)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   513
        return n << dz;
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   514
    else
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   515
        return n >> -dz;
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