OSDN Git Service

commit the part that makes the map work
[automap/automap.git] / Automap / MapSRC / src / ViewFrameUtils.js
1 ViewFrame.initInfobox = function (ibox, iboxSlots) {
2         // TODO: make faster
3         ViewFrame.chunks
4                 .chunkMetadataNames.forEach((item, i) => {
5                         const slot = document.createElement('tr');
6                         const head = document.createElement('th');
7                         head.innerText = item;
8                         const row = document.createElement('td');
9                         row.innerText = '0';
10                         iboxSlots[i] = row;
11                         slot.append(head, row);
12                         ibox.append(slot);
13                 });
14 };
15
16 ViewFrame.prototype.updateEdges = function () {
17         if (this.width != window.innerWidth || this.height != window.innerHeight) {
18                 this.width = window.innerWidth;
19                 this.map.canvas.width = this.width;
20                 this.height = window.innerHeight;
21                 this.map.canvas.height = this.height;
22                 this.map.imageSmoothingEnabled = false;
23         }
24         const chunksWide = Math.ceil(this.width / this.zoom);
25         const chunksHigh = Math.ceil(this.height / this.zoom);
26
27         this.east = this.x + chunksWide / 2; // this is fractional and is used to keep track of the edges of the window
28         this.eastChunk = Math.ceil(this.east); // this is not and is used to track the chunks that need to load
29         this.west = this.x - chunksWide / 2;
30         this.westChunk = Math.floor(this.west);
31         this.north = this.y + chunksHigh / 2;
32         this.northChunk = Math.ceil(this.north);
33         this.south = this.y - chunksHigh / 2;
34         this.southChunk = Math.floor(this.south);
35 };
36
37 /**
38 * dx and dy are the distances in chunks
39 */
40 ViewFrame.prototype.moveCenter = function (dx, dy) {
41         // to pan when we click on the map!
42         this.x += (dx - this.width / 2) / this.zoom;
43         this.y += (dy - this.height / 2) / this.zoom;
44 };
45
46 /**
47 * x and y are positions in chunks
48 */
49 ViewFrame.prototype.setCenter = function (x, y) {
50         this.x = x;
51         this.y = y;
52 };
53
54 /**
55 * x and y are positions in BLOCKS!!!!
56 */
57 ViewFrame.prototype.setBlockwiseCenter = function (x, y) {
58         this.x = x / this.zoom;
59         this.y = y / this.zoom;
60 };
61
62 ViewFrame.prototype.clear = function () {
63         this.loadedChunksByName.clear();
64         this.loadedChunksByCoords.clear();
65         if (this.chunkScript) this.chunkScript.remove();
66         delete this.chunkScript;
67         delete ViewFrame.chunks;
68         this.map.clearRect(0, 0, window.innerWidth, window.innerHeight);
69 };
70
71 function decode(img, cb) {
72         img.decode()
73                 .then(() => {
74                         cb(img);
75                 })
76                 .catch(() => {}); // so images arent added on error
77 }