~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to api/lib/helioviewer/Tile.php

  • Committer: V. Keith Hughitt
  • Date: 2009-04-01 21:08:05 UTC
  • Revision ID: hughitt1@kore-20090401210805-372f7dgih07vxk42
nightly build 04-01-2009

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * @class Tile
 
4
 * @author Keith Hughitt
 
5
 */
 
6
if (Config::MOD_IMAGICK_ENABLED == true)
 
7
        require('JP2Image.php');
 
8
else
 
9
        require('JP2Image.Manual.php');
 
10
 
 
11
class Tile extends JP2Image {
 
12
        private $x;
 
13
        private $y;
 
14
 
 
15
        /**
 
16
         * constructor
 
17
         */
 
18
        public function __construct($id, $zoomLevel, $x, $y, $tileSize) {
 
19
                $xRange = array("start" => $x, "end" => $x);
 
20
                $yRange = array("start" => $y, "end" => $y);
 
21
 
 
22
                parent::__construct($id, $zoomLevel, $xRange, $yRange, $tileSize);
 
23
 
 
24
                $this->x = $x;
 
25
                $this->y = $y;
 
26
                $this->getTile();
 
27
        }
 
28
 
 
29
        /**
 
30
         * getTile
 
31
         */
 
32
        function getTile() {
 
33
                // Tile image format
 
34
                $format = $this->getImageFormat();
 
35
 
 
36
                // Filepaths (for intermediate pgm and final png/jpg image)
 
37
                $tile = $this->getFilePath($format);
 
38
                
 
39
                // If tile already exists in cache, use it
 
40
                if (Config::ENABLE_CACHE) {
 
41
                        if (file_exists($tile)) {
 
42
                                $this->display($tile);
 
43
                                exit();
 
44
                        }
 
45
                }
 
46
 
 
47
                // If nothing useful is in the cache, create the tile from scratch
 
48
                $im = $this->buildImage($tile);
 
49
 
 
50
                // Store image
 
51
                $this->image = $im;
 
52
                
 
53
                // Display image
 
54
                $this->display($tile);
 
55
        }
 
56
 
 
57
        /**
 
58
         * getFilePath
 
59
         * @return
 
60
         */
 
61
        function getFilePath($format) {
 
62
                // Starting point
 
63
                $filepath = $this->cacheDir . $this->tileSize . "/";
 
64
                if (!file_exists($filepath))
 
65
                        mkdir($filepath);
 
66
                        
 
67
                // Date information
 
68
                $year  = substr($this->timestamp,0,4);
 
69
                $month = substr($this->timestamp,5,2);
 
70
                $day   = substr($this->timestamp,8,2);
 
71
 
 
72
                // Create necessary directories
 
73
                $filepath .= $year . "/";
 
74
                if (!file_exists($filepath)) {
 
75
                        mkdir($filepath);
 
76
                        chmod($filepath, 0777);
 
77
                }
 
78
 
 
79
                $filepath .= $month . "/";
 
80
                if (!file_exists($filepath)) {
 
81
                        mkdir($filepath);
 
82
                        chmod($filepath, 0777);
 
83
                }
 
84
 
 
85
                $filepath .= $day . "/";
 
86
                if (!file_exists($filepath)) {
 
87
                        mkdir($filepath);
 
88
                        chmod($filepath, 0777);
 
89
                }
 
90
 
 
91
                // Convert coordinates to strings
 
92
                $xStr = "+" . str_pad($this->x, 2, '0', STR_PAD_LEFT);
 
93
                if (substr($this->x,0,1) == "-")
 
94
                        $xStr = "-" . str_pad(substr($this->x, 1), 2, '0', STR_PAD_LEFT);
 
95
 
 
96
                $yStr = "+" . str_pad($this->y, 2, '0', STR_PAD_LEFT);
 
97
                if (substr($this->y,0,1) == "-")
 
98
                        $yStr = "-" . str_pad(substr($this->y, 1), 2, '0', STR_PAD_LEFT);
 
99
 
 
100
                $filepath .= $this->imageId . "_" . $this->zoomLevel . "_" . $xStr . "_" . $yStr . ".$format";
 
101
 
 
102
                return $filepath;
 
103
        }
 
104
}
 
105
?>