author | Tero Marttila <terom@fixme.fi> |
Mon, 25 Jan 2010 02:58:00 +0200 | |
changeset 73 | 5dfb245b814d |
parent 51 | 866eb1aad566 |
child 127 | df89d13f2354 |
permissions | -rw-r--r-- |
30 | 1 |
// A source of tile images of a specific width/height, zoom level range, and some other attributes |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
2 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
3 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
4 |
* A source of image tiles. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
5 |
* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
6 |
* The image source is expected to serve fixed-size tiles (tile_width × tile_height) of image data based on the |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
7 |
* x, y, zl URL query parameters. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
8 |
* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
9 |
* x, y - the pixel coordinates of the top-left corner |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
10 |
* XXX: these are scaled from the image coordinates by the zoom level |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
11 |
* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
12 |
* zl - the zoom level used, out < zl < in. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
13 |
* The image pixels are scaled by powers-of-two, so a 256x256 tile at zl=-1 shows a 512x512 area of the |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
14 |
* 1:1 image. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
15 |
*/ |
30 | 16 |
var Source = Class.create({ |
43 | 17 |
initialize: function (path, tile_width, tile_height, zoom_min, zoom_max, img_width, img_height) { |
30 | 18 |
this.path = path; |
19 |
this.tile_width = tile_width; |
|
20 |
this.tile_height = tile_height; |
|
21 |
this.zoom_min = zoom_min; |
|
22 |
this.zoom_max = zoom_max; |
|
43 | 23 |
this.img_width = img_width; |
24 |
this.img_height = img_height; |
|
30 | 25 |
|
26 |
this.refresh = false; |
|
27 |
this.opt_key = this.opt_value = null; |
|
28 |
}, |
|
29 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
30 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
31 |
* Return an URL representing the tile at the given viewport (row, col) at the given zl. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
32 |
* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
33 |
* XXX: sw/sh = screen-width/height, used to choose an appropriate output size for dynamic image sources... |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
34 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
35 |
build_url: function (col, row, zl /*, sw, sh */) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
36 |
// XXX: distribute tile requests across tile*.foo.bar |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
37 |
if (0) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
38 |
// two-bit hash (0-4) based on the (col, row) |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
39 |
var hash = ( (col % 2) << 1 | (row % 2) ) + 1; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
40 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
41 |
// the subdomain to use |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
42 |
var subdomain = ""; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
43 |
|
30 | 44 |
subdomain = "tile" + hash + "."; |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
45 |
} |
30 | 46 |
|
47 |
// the (x, y) co-ordinates |
|
48 |
var x = col * this.tile_width; |
|
49 |
var y = row * this.tile_height; |
|
50 |
||
40 | 51 |
var url = this.path + "?x=" + x + "&y=" + y + "&zl=" + zl; // + "&sw=" + sw + "&sh=" + sh; |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
52 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
53 |
// refresh the tile each time it is loaded? |
30 | 54 |
if (this.refresh) |
55 |
url += "&ts=" + new Date().getTime(); |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
56 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
57 |
// XXX: additional parameters, not used |
30 | 58 |
if (this.opt_key && this.opt_value) |
59 |
url += "&" + this.opt_key + "=" + this.opt_value; |
|
60 |
||
61 |
return url; |
|
62 |
}, |
|
40 | 63 |
|
64 |
// build an URL for a full image |
|
65 |
build_image_url: function (cx, cy, w, h, zl) { |
|
66 |
return (this.path + "?cx=" + cx + "&cy=" + cy + "&w=" + w + "&h=" + h + "&zl=" + zl); |
|
67 |
} |
|
30 | 68 |
}); |
69 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
70 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
71 |
* Viewport implements the tiles-UI. It consists of a draggable substrate, which in turn consists of several |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
72 |
* ZoomLayers, which then contain the actual tile images. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
73 |
* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
74 |
* Vars: |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
75 |
* scroll_x/y - the visible pixel offset of the top-left corner |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
76 |
*/ |
30 | 77 |
var Viewport = Class.create({ |
78 |
initialize: function (source, viewport_id) { |
|
79 |
this.source = source; |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
80 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
81 |
// get a handle on the UI elements |
30 | 82 |
this.id = viewport_id; |
83 |
this.div = $(viewport_id); |
|
84 |
this.substrate = this.div.down("div.substrate"); |
|
85 |
||
86 |
// make the substrate draggable |
|
87 |
this.draggable = new Draggable(this.substrate, { |
|
88 |
onStart: this.on_scroll_start.bind(this), |
|
89 |
onDrag: this.on_scroll_move.bind(this), |
|
49
9dedd0e30b6b
don't use zindex for draggable
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
90 |
onEnd: this.on_scroll_end.bind(this), |
9dedd0e30b6b
don't use zindex for draggable
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
91 |
|
9dedd0e30b6b
don't use zindex for draggable
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
92 |
zindex: false |
30 | 93 |
}); |
94 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
95 |
// register event handlers for other UI functions |
30 | 96 |
Event.observe(this.substrate, "dblclick", this.on_dblclick.bindAsEventListener(this)); |
97 |
Event.observe(this.substrate, "mousewheel", this.on_mousewheel.bindAsEventListener(this)); |
|
98 |
Event.observe(this.substrate, "DOMMouseScroll", this.on_mousewheel.bindAsEventListener(this)); // mozilla |
|
99 |
Event.observe(document, "resize", this.on_resize.bindAsEventListener(this)); |
|
39 | 100 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
101 |
// init zoom UI buttons |
39 | 102 |
this.btn_zoom_in = $("btn-zoom-in"); |
103 |
this.btn_zoom_out = $("btn-zoom-out"); |
|
104 |
||
105 |
if (this.btn_zoom_in) |
|
106 |
Event.observe(this.btn_zoom_in, "click", this.zoom_in.bindAsEventListener(this)); |
|
107 |
||
108 |
if (this.btn_zoom_out) |
|
109 |
Event.observe(this.btn_zoom_out, "click", this.zoom_out.bindAsEventListener(this)); |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
110 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
111 |
// initial view location (centered) |
50
ba9d03e46925
ignore invalid #hash values for cx:cy:zl
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
112 |
var cx = this.source.img_width / 2; |
ba9d03e46925
ignore invalid #hash values for cx:cy:zl
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
113 |
var cy = this.source.img_height / 2; |
ba9d03e46925
ignore invalid #hash values for cx:cy:zl
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
114 |
var zl = 0; // XXX: would need to scale x/y for this: (this.source.zoom_min + this.source.zoom_max) / 2; |
32 | 115 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
116 |
// from link? |
32 | 117 |
if (document.location.hash) { |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
118 |
// parse x:y:z tuple |
32 | 119 |
var pt = document.location.hash.substr(1).split(":"); |
120 |
||
43 | 121 |
// unpack |
50
ba9d03e46925
ignore invalid #hash values for cx:cy:zl
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
122 |
if (pt.length) cx = parseInt(pt.shift()) || cx; |
ba9d03e46925
ignore invalid #hash values for cx:cy:zl
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
123 |
if (pt.length) cy = parseInt(pt.shift()) || cy; |
ba9d03e46925
ignore invalid #hash values for cx:cy:zl
Tero Marttila <terom@fixme.fi>
parents:
49
diff
changeset
|
124 |
if (pt.length) zl = parseInt(pt.shift()) || zl; |
43 | 125 |
} |
32 | 126 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
127 |
// initialize zoom state to given zl |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
128 |
this._init_zoom(zl); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
129 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
130 |
// initialize viewport size |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
131 |
this.update_size(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
132 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
133 |
// initialize scroll offset |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
134 |
this._init_scroll(cx, cy); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
135 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
136 |
// this comes after update_size, so that the initial update_size doesn't try and update the image_link, |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
137 |
// since this only works once we have the zoom layers set up... |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
138 |
this.image_link = $("lnk-image"); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
139 |
this.update_image_link(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
140 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
141 |
// display tiles! |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
142 |
this.update_tiles(); |
30 | 143 |
}, |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
144 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
145 |
/* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
146 |
* Initializers - only run once |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
147 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
148 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
149 |
/** Initialize the zoom state to show the given zoom level */ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
150 |
_init_zoom: function (zl) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
151 |
// the stack of zoom levels |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
152 |
this.zoom_layers = []; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
153 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
154 |
// populate the zoom-layers stack based on the number of zoom levels defined for the source |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
155 |
for (var zoom_level = this.source.zoom_min; zoom_level <= this.source.zoom_max; zoom_level++) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
156 |
var zoom_layer = new ZoomLayer(this.source, zoom_level); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
157 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
158 |
this.substrate.appendChild(zoom_layer.div); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
159 |
this.zoom_layers[zoom_level] = zoom_layer; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
160 |
} |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
161 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
162 |
// is the new zoom level valid? |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
163 |
if (!this.zoom_layers[zl]) |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
164 |
// XXX: nasty, revert to something else? |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
165 |
return false; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
166 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
167 |
// set the zoom layyer |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
168 |
this.zoom_layer = this.zoom_layers[zl]; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
169 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
170 |
// enable it with initial z-index |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
171 |
this.zoom_layer.enable(11); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
172 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
173 |
// init the UI accordingly |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
174 |
this.update_zoom_ui(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
175 |
}, |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
176 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
177 |
/** Initialize the scroll state to show the given (scaled) centered coordinates */ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
178 |
_init_scroll: function (cx, cy) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
179 |
// scroll center |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
180 |
this.scroll_center_to(cx, cy); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
181 |
}, |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
182 |
|
30 | 183 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
184 |
/* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
185 |
* Handle input events |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
186 |
*/ |
30 | 187 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
188 |
/** Viewport resized */ |
30 | 189 |
on_resize: function (ev) { |
190 |
this.update_size(); |
|
191 |
this.update_tiles(); |
|
192 |
}, |
|
193 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
194 |
/** Double-click to zoom and center */ |
30 | 195 |
on_dblclick: function (ev) { |
196 |
var offset = this.event_offset(ev); |
|
197 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
198 |
// center view and zoom in |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
199 |
this.center_and_zoom_in( |
30 | 200 |
this.scroll_x + offset.x, |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
201 |
this.scroll_y + offset.y |
30 | 202 |
); |
203 |
}, |
|
204 |
||
205 |
// mousewheel handler |
|
206 |
on_mousewheel: function (ev) { |
|
207 |
// this works in very weird ways, so it's based on code from http://adomas.org/javascript-mouse-wheel/ |
|
208 |
// (it didn't include any license, so this is written out manually) |
|
209 |
var delta; |
|
210 |
||
211 |
// this is browser-dependant... |
|
212 |
if (ev.wheelDelta) { |
|
213 |
// IE + Opera |
|
214 |
delta = ev.wheelDelta; |
|
215 |
||
216 |
if (window.opera) { |
|
217 |
// Opera, but apparently not newer versions? |
|
218 |
//delta = -delta; |
|
219 |
} |
|
220 |
||
221 |
} else if (ev.detail) { |
|
222 |
// Mozilla |
|
223 |
delta = -ev.detail; |
|
224 |
||
225 |
} else { |
|
226 |
// mousewheel not supported... |
|
227 |
return; |
|
228 |
||
229 |
} |
|
230 |
||
231 |
// don't scroll the page |
|
232 |
if (ev.preventDefault) |
|
233 |
ev.preventDefault(); |
|
234 |
||
235 |
// delta > 0 : scroll up, zoom in |
|
236 |
// delta < 0 : scroll down, zoom out |
|
237 |
delta = delta < 0 ? -1 : 1; |
|
238 |
||
239 |
// Firefox's DOMMouseEvent's pageX/Y attributes are broken. layerN is for mozilla, offsetN for IE, seems to work |
|
240 |
||
241 |
// absolute location of the cursor |
|
242 |
var x = parseInt(ev.target.style.left) + (ev.layerX ? ev.layerX : ev.offsetX); |
|
243 |
var y = parseInt(ev.target.style.top) + (ev.layerY ? ev.layerY : ev.offsetY); |
|
244 |
||
245 |
// zoom \o/ |
|
246 |
this.zoom_center_to(x, y, delta); |
|
247 |
}, |
|
248 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
249 |
/** Substrate scroll was started */ |
30 | 250 |
on_scroll_start: function (ev) { |
251 |
||
252 |
}, |
|
253 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
254 |
/** Substrate was scrolled, update scroll_{x,y}, and then update tiles after 100ms */ |
30 | 255 |
on_scroll_move: function (ev) { |
256 |
this.update_scroll(); |
|
51
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
257 |
|
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
258 |
// fast-update at 100ms intervals |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
259 |
this.update_after_timeout(true); |
30 | 260 |
}, |
261 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
262 |
/** Substrate scroll was ended, update tiles now */ |
30 | 263 |
on_scroll_end: function (ev) { |
264 |
this.update_now(); |
|
265 |
}, |
|
266 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
267 |
/** Calculate the absolute (x, y) coords of the given event inside the viewport */ |
30 | 268 |
event_offset: function (ev) { |
269 |
var offset = this.div.cumulativeOffset(); |
|
270 |
||
271 |
return { |
|
272 |
x: ev.pointerX() - offset.left, |
|
273 |
y: ev.pointerY() - offset.top |
|
274 |
}; |
|
275 |
}, |
|
276 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
277 |
/* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
278 |
* Change view - scroll/zoom |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
279 |
*/ |
30 | 280 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
281 |
/** Scroll the view to place the given absolute (x, y) co-ordinate at the top left */ |
30 | 282 |
scroll_to: function (x, y) { |
283 |
// update it via the style |
|
284 |
this.substrate.style.top = "-" + y + "px"; |
|
285 |
this.substrate.style.left = "-" + x + "px"; |
|
286 |
||
287 |
// update these as well |
|
288 |
this.scroll_x = x; |
|
289 |
this.scroll_y = y; |
|
290 |
}, |
|
291 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
292 |
/** Scroll the view to place the given absolute (x, y) co-ordinate at the center */ |
30 | 293 |
scroll_center_to: function (x, y) { |
294 |
return this.scroll_to( |
|
295 |
x - this.center_offset_x, |
|
296 |
y - this.center_offset_y |
|
297 |
); |
|
298 |
}, |
|
299 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
300 |
/** Zoom à la delta such that the given (zoomed) absolute (x, y) co-ordinates will be at the top left */ |
30 | 301 |
zoom_scaled: function (x, y, delta) { |
302 |
if (!this.update_zoom(delta)) |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
303 |
// couldn't zoom, scaled coords are wrong |
30 | 304 |
return false; |
305 |
||
306 |
// scroll to the new position |
|
307 |
this.scroll_to(x, y); |
|
308 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
309 |
// update view after 100ms - in case we zoom again? |
30 | 310 |
this.update_after_timeout(); |
311 |
||
312 |
return true; |
|
313 |
}, |
|
314 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
315 |
/** Zoom à la delta such that the given (current) absolute (x, y) co-ordinates will be at the top left */ |
30 | 316 |
zoom_to: function (x, y, delta) { |
317 |
return this.zoom_scaled( |
|
318 |
scaleByZoomDelta(x, delta), |
|
319 |
scaleByZoomDelta(y, delta), |
|
320 |
delta |
|
321 |
); |
|
322 |
}, |
|
323 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
324 |
/** Zoom à la delta such that the given (current) absolute (x, y) co-ordinates will be at the center */ |
30 | 325 |
zoom_center_to: function (x, y, delta) { |
326 |
return this.zoom_scaled( |
|
327 |
scaleByZoomDelta(x, delta) - this.center_offset_x, |
|
328 |
scaleByZoomDelta(y, delta) - this.center_offset_y, |
|
329 |
delta |
|
330 |
); |
|
331 |
}, |
|
332 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
333 |
/** Zoom à la delta, keeping the view centered */ |
39 | 334 |
zoom_centered: function (delta) { |
335 |
return this.zoom_center_to( |
|
336 |
this.scroll_x + this.center_offset_x, |
|
337 |
this.scroll_y + this.center_offset_y, |
|
338 |
delta |
|
339 |
); |
|
340 |
}, |
|
341 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
342 |
/** Zoom in one level, keeping the view centered */ |
39 | 343 |
zoom_in: function () { |
344 |
return this.zoom_centered(+1); |
|
345 |
}, |
|
346 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
347 |
/** Zoom out one level, keeping the view centered */ |
39 | 348 |
zoom_out: function () { |
349 |
return this.zoom_centered(-1); |
|
350 |
}, |
|
30 | 351 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
352 |
/** Center the view on the given coords, and zoom in, if possible */ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
353 |
center_and_zoom_in: function (cx, cy) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
354 |
// try and zoom in |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
355 |
if (this.update_zoom(1)) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
356 |
// scaled coords |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
357 |
cx = scaleByZoomDelta(cx, 1); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
358 |
cy = scaleByZoomDelta(cy, 1); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
359 |
} |
30 | 360 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
361 |
// re-center |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
362 |
this.scroll_center_to(cx, cy); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
363 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
364 |
// update view after 100ms - in case we zoom again? |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
365 |
this.update_after_timeout(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
366 |
}, |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
367 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
368 |
/* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
369 |
* Update view state |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
370 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
371 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
372 |
/** Update the view_* / center_offset_* vars, and any dependent items */ |
30 | 373 |
update_size: function () { |
374 |
this.view_width = this.div.getWidth(); |
|
375 |
this.view_height = this.div.getHeight(); |
|
376 |
||
377 |
this.center_offset_x = Math.floor(this.view_width / 2); |
|
378 |
this.center_offset_y = Math.floor(this.view_height / 2); |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
379 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
380 |
// the link-to-image uses the current view size |
40 | 381 |
this.update_image_link(); |
30 | 382 |
}, |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
383 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
384 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
385 |
* Update the scroll_x/y state |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
386 |
*/ |
30 | 387 |
update_scroll: function() { |
388 |
this.scroll_x = -parseInt(this.substrate.style.left); |
|
389 |
this.scroll_y = -parseInt(this.substrate.style.top); |
|
390 |
}, |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
391 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
392 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
393 |
* Switch zoom layers |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
394 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
395 |
update_zoom: function (delta) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
396 |
// is the new zoom level valid? |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
397 |
if (!this.zoom_layers[this.zoom_layer.level + delta]) |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
398 |
return false; |
30 | 399 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
400 |
var zoom_old = this.zoom_layer; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
401 |
var zoom_new = this.zoom_layers[this.zoom_layer.level + delta]; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
402 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
403 |
// XXX: clear hide-zoom-after-timeout |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
404 |
if (this.zoom_timer) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
405 |
clearTimeout(this.zoom_timer); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
406 |
this.zoom_timer = null; |
30 | 407 |
} |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
408 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
409 |
// get other zoom layers out of the way |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
410 |
// XXX: u |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
411 |
this.zoom_layers.each(function (zl) { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
412 |
zl.disable(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
413 |
}); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
414 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
415 |
// update the current zoom layer |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
416 |
this.zoom_layer = zoom_new; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
417 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
418 |
// layer them such that the old on remains visible underneath the new one |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
419 |
zoom_new.enable(11); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
420 |
zoom_old.enable(10); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
421 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
422 |
// resize the tiles in the two zoom layers |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
423 |
zoom_new.update_tiles(zoom_new.level); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
424 |
zoom_old.update_tiles(zoom_new.level); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
425 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
426 |
// disable the old zoom layer after 1000ms - after the new zoom layer has loaded - not an optimal solution |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
427 |
this.zoom_timer = setTimeout(function () { zoom_old.disable()}, 1000); |
30 | 428 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
429 |
// update UI state |
39 | 430 |
this.update_zoom_ui(); |
431 |
||
30 | 432 |
return true; |
433 |
}, |
|
39 | 434 |
|
51
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
435 |
/** Run update_tiles() at 500ms intervals */ |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
436 |
update_after_timeout: function (fast) { |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
437 |
// have not called update_tiles() yet |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
438 |
this._update_idle = false; |
39 | 439 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
440 |
// cancel old timeout |
51
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
441 |
if (!fast && this._update_timeout) { |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
442 |
clearTimeout(this._update_timeout); |
51
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
443 |
this._update_timeout = null; |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
444 |
} |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
445 |
|
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
446 |
if (!this._update_timeout) |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
447 |
// trigger after delay |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
448 |
this._update_timeout = setTimeout(this._update_timeout_trigger.bind(this), fast ? 500 : 100); |
39 | 449 |
}, |
30 | 450 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
451 |
_update_timeout_trigger: function () { |
51
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
452 |
this._update_timeout = null; |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
453 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
454 |
// have called update_tiles() |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
455 |
this._update_idle = true; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
456 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
457 |
this.update_tiles(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
458 |
}, |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
459 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
460 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
461 |
* Unschedule the call to update_tiles() and call it now, unless it's already been triggered by the previous call to |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
462 |
* update_after_timeout |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
463 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
464 |
update_now: function () { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
465 |
// abort trigger if active |
51
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
466 |
if (this._update_timeout) { |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
467 |
clearTimeout(this._update_timeout); |
51
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
468 |
this._update_timeout = null; |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
469 |
} |
866eb1aad566
update_tiles() every 500ms during scrolling
Tero Marttila <terom@fixme.fi>
parents:
50
diff
changeset
|
470 |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
471 |
// update now unless already done |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
472 |
if (!this._update_idle) |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
473 |
this.update_tiles(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
474 |
}, |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
475 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
476 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
477 |
* Determine the set of visible tiles, and ensure they are loaded |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
478 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
479 |
update_tiles: function () { |
30 | 480 |
// short names for some vars... |
481 |
var x = this.scroll_x; |
|
482 |
var y = this.scroll_y; |
|
483 |
var sw = this.view_width; |
|
484 |
var sh = this.view_height; |
|
485 |
var tw = this.source.tile_width; |
|
486 |
var th = this.source.tile_height; |
|
487 |
var zl = this.zoom_layer.level; |
|
488 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
489 |
// figure out which set of cols/rows are visible |
30 | 490 |
var start_col = Math.max(0, Math.floor(x / tw)); |
491 |
var start_row = Math.max(0, Math.floor(y / th)); |
|
492 |
var end_col = Math.floor((x + sw) / tw); |
|
493 |
var end_row = Math.floor((y + sh) / th); |
|
494 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
495 |
// loop through all visible tiles |
30 | 496 |
for (var col = start_col; col <= end_col; col++) { |
497 |
for (var row = start_row; row <= end_row; row++) { |
|
498 |
// the tile's id |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
499 |
var id = "tile_" + zl + "_" + col + "_" + row; |
30 | 500 |
|
501 |
// does the element exist already? |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
502 |
// XXX: use basic document.getElementById for perf? |
30 | 503 |
var t = $(id); |
504 |
||
505 |
if (!t) { |
|
506 |
// build a new tile |
|
507 |
t = Builder.node("img", { |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
508 |
src: this.source.build_url(col, row, zl /* , sw, sh */), |
46 | 509 |
id: id //, |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
510 |
// title: "(" + col + ", " + row + ")", |
30 | 511 |
// style set later |
512 |
} |
|
513 |
); |
|
514 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
515 |
// position |
30 | 516 |
t.style.top = th * row; |
517 |
t.style.left = tw * col; |
|
518 |
t.style.display = "none"; |
|
519 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
520 |
// display once loaded |
30 | 521 |
Event.observe(t, "load", _tile_loaded.bindAsEventListener(t)); |
522 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
523 |
// remember the col/row |
30 | 524 |
t.__col = col; |
525 |
t.__row = row; |
|
526 |
||
527 |
// add it to the zoom layer |
|
528 |
this.zoom_layer.add_tile(t); |
|
529 |
||
530 |
} else if (this.source.reload) { |
|
531 |
// force the tile to reload |
|
532 |
touch_tile(t, col, row); |
|
533 |
||
534 |
} |
|
535 |
} |
|
536 |
} |
|
40 | 537 |
|
538 |
this.update_scroll_ui(); |
|
539 |
}, |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
540 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
541 |
/* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
542 |
* UI state |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
543 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
544 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
545 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
546 |
* Update any zl-dependant UI elements |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
547 |
*/ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
548 |
update_zoom_ui: function () { |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
549 |
// deactivate zoom-in button if zoomed in |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
550 |
if (this.btn_zoom_in) |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
551 |
(this.zoom_layer.level >= this.source.zoom_max) ? this.btn_zoom_in.disable() : this.btn_zoom_in.enable(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
552 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
553 |
// deactivate zoom-out button if zoomed out |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
554 |
if (this.btn_zoom_out) |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
555 |
(this.zoom_layer.level <= this.source.zoom_min) ? this.btn_zoom_out.disable() : this.btn_zoom_out.enable(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
556 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
557 |
// link-to-image |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
558 |
this.update_image_link(); |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
559 |
}, |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
560 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
561 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
562 |
* Update any position-dependant UI elements |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
563 |
*/ |
40 | 564 |
update_scroll_ui: function () { |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
565 |
// update the link-to-this-page thing |
48
7577a3b68ccc
don't include # in document.location.hash value
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
566 |
document.location.hash = (this.scroll_x + this.center_offset_x) + ":" + (this.scroll_y + this.center_offset_y) + ":" + this.zoom_layer.level; |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
567 |
|
40 | 568 |
// update link-to-image |
569 |
this.update_image_link(); |
|
570 |
}, |
|
571 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
572 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
573 |
* Update the link-to-image-of-this-view link with dimensions, zoom, position |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
574 |
*/ |
40 | 575 |
update_image_link: function () { |
576 |
if (!this.image_link) |
|
577 |
return; |
|
578 |
||
579 |
this.image_link.href = this.source.build_image_url( |
|
580 |
this.scroll_x + this.center_offset_x, |
|
581 |
this.scroll_y + this.center_offset_y, |
|
582 |
this.view_width, this.view_height, |
|
583 |
this.zoom_layer.level |
|
584 |
); |
|
585 |
||
586 |
this.image_link.innerHTML = this.view_width + "x" + this.view_height + "@" + this.zoom_layer.level; |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
587 |
} |
30 | 588 |
}); |
589 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
590 |
/** Used by Viewport.update_tiles to make a tile visible after it has loaded */ |
30 | 591 |
function _tile_loaded (ev) { |
592 |
this.style.display = "block"; |
|
593 |
} |
|
594 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
595 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
596 |
* A zoom layer contains a (col, row) grid of tiles at a specific zoom level. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
597 |
*/ |
30 | 598 |
var ZoomLayer = Class.create({ |
599 |
initialize: function (source, zoom_level) { |
|
600 |
this.source = source; |
|
601 |
this.level = zoom_level; |
|
602 |
this.div = Builder.node("div", { id: "zl_" + this.level, style: "position: relative; display: none;"}); |
|
603 |
||
604 |
// our tiles |
|
605 |
this.tiles = []; |
|
606 |
}, |
|
607 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
608 |
/** Add a tile to this zoom layer's grid */ |
30 | 609 |
add_tile: function (tile) { |
610 |
this.div.appendChild(tile); |
|
611 |
this.tiles.push(tile); |
|
612 |
}, |
|
613 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
614 |
/** Make this zoom layer visible with the given z-index */ |
30 | 615 |
enable: function (z_index) { |
616 |
this.div.style.zIndex = z_index; |
|
46 | 617 |
|
618 |
// XXX: IE8 needs this for some reason |
|
619 |
$(this.div).show(); |
|
30 | 620 |
}, |
621 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
622 |
/** Hide this zoom layer */ |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
623 |
disable: function () { |
46 | 624 |
// XXX: IE8 |
625 |
$(this.div).hide(); |
|
30 | 626 |
}, |
627 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
628 |
/** |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
629 |
* Update the tile grid in this zoom layer such the tiles are in the correct position and of the correct size |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
630 |
* when viewed with the given zoom level. |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
631 |
* |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
632 |
* For zoom levels different than this layer's level, this will resize the tiles! |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
633 |
*/ |
30 | 634 |
update_tiles: function (zoom_level) { |
635 |
var zd = zoom_level - this.level; |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
636 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
637 |
// desired tile size |
30 | 638 |
var tw = scaleByZoomDelta(this.source.tile_width, zd); |
639 |
var th = scaleByZoomDelta(this.source.tile_height, zd); |
|
640 |
||
641 |
var tiles = this.tiles; |
|
642 |
var tiles_len = tiles.length; |
|
643 |
var t, ts; |
|
644 |
||
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
645 |
// XXX: *all* tiles? :/ |
30 | 646 |
for (var i = 0; i < tiles_len; i++) { |
647 |
t = tiles[i]; |
|
648 |
ts = t.style; |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
649 |
|
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
650 |
// reposition |
30 | 651 |
ts.width = tw; |
652 |
ts.height = th; |
|
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
653 |
ts.top = th * t.__row; |
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
654 |
ts.left = tw * t.__col; |
30 | 655 |
} |
45
0ce4064c428e
cleanup tiles2.js, fix scaling of old layer when zooming, and have double-click always center
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
656 |
} |
30 | 657 |
}); |
658 |
||
659 |
// scale the given co-ordinate by a zoom delta. If we zoom in (dz > 0), n will become larger, and if we zoom |
|
660 |
// out (dz < 0), n will become smaller. |
|
661 |
function scaleByZoomDelta (n, dz) { |
|
662 |
if (dz > 0) |
|
663 |
return n << dz; |
|
664 |
else |
|
665 |
return n >> -dz; |
|
666 |
} |
|
667 |