Commit bfdf8cd8e3875879a4dc953d96ea7809127960d0

Authored by Edmar Moretti
1 parent 881a50da

--no commit message

Showing 1 changed file with 943 additions and 943 deletions   Show diff stats
pacotes/tme/TME_Engine.php
... ... @@ -21,672 +21,672 @@
21 21  
22 22 class ThematicMap
23 23 {
24   - public $dataStore;
25   - public $coordDecimals = 2;
26   - public $engine = "";
27   - public $logoline = "files/balloonlogo.png";
28   - public $logo = 'files/logo.png';
29   -
30   - // Parameters
31   - public $mapType = 'choropleth'; // choropleth / prism / symbol
32   - public $symbolType; // image / polygon // collada
33   - public $symbolShape;
34   - public $mapTitle;
35   - public $mapDescription;
36   - public $mapSource;
37   - public $showTitle = true;
38   - public $showLegend = true;
39   - public $showValues = false;
40   - public $showNames = false;
41   - public $timeType = 'year'; // year / series / slider
42   - public $maxHeight = 2000000; // Prism / Bar
  24 + public $dataStore;
  25 + public $coordDecimals = 2;
  26 + public $engine = "";
  27 + public $logoline = "files/balloonlogo.png";
  28 + public $logo = 'files/logo.png';
  29 +
  30 + // Parameters
  31 + public $mapType = 'choropleth'; // choropleth / prism / symbol
  32 + public $symbolType; // image / polygon // collada
  33 + public $symbolShape;
  34 + public $mapTitle;
  35 + public $mapDescription;
  36 + public $mapSource;
  37 + public $showTitle = true;
  38 + public $showLegend = true;
  39 + public $showValues = false;
  40 + public $showNames = false;
  41 + public $timeType = 'year'; // year / series / slider
  42 + public $maxHeight = 2000000; // Prism / Bar
43 43 public $symbolMaxSize; // Symbol$imgBrand
44   - public $barSize = 50000;
45   - public $maxValue;
46   - public $minValue;
47   -
48   - public $indicatorID;
49   - public $indicator;
50   - public $year;
51   - private $yearArray;
52   -
53   - // Colour parameters
54   - public $colourType = 'scale'; // scale / single
55   - public $startColour = 'FFFF99';
56   - public $endColour = 'FF6600';
57   - public $noDataColour = 'CCCCCC';
58   - public $colour = 'FF6600';
59   - public $opacity = 90;
60   -
61   - public $classification = 'unclassed'; // unclassed / equal / quantile
62   - public $numClasses = 5;
63   -
64   - private $myColourScale; // Only choropleth/prism
65   - private $startColourRGB; // Array
66   - private $endColourRGB; // Array
67   - private $deltaColour; // Array
68   - private $kmlAlphaColour = 220;
69   - private $colourLegendHeight = 350;
70   - private $colourLegendWidth = 30;
71   -
72   - private $symbolVertices = 30; // Circle
73   - private $showLabel = false;
74   -
75   - private $classBreaks; // Array
76   - private $classColours; // Array
77   -
78   -
79   - private $precision = 0; // Number of decimals
80   -
81   - //
82   - // Constructor
83   - // @access protected
84   - //
85   - function __construct($dataStore, $paramArray)
86   - {
87   - $this->dataStore = $dataStore;
88   -
89   - // Mandatory parameters
  44 + public $barSize = 50000;
  45 + public $maxValue;
  46 + public $minValue;
  47 +
  48 + public $indicatorID;
  49 + public $indicator;
  50 + public $year;
  51 + private $yearArray;
  52 +
  53 + // Colour parameters
  54 + public $colourType = 'scale'; // scale / single
  55 + public $startColour = 'FFFF99';
  56 + public $endColour = 'FF6600';
  57 + public $noDataColour = 'CCCCCC';
  58 + public $colour = 'FF6600';
  59 + public $opacity = 90;
  60 +
  61 + public $classification = 'unclassed'; // unclassed / equal / quantile
  62 + public $numClasses = 5;
  63 +
  64 + private $myColourScale; // Only choropleth/prism
  65 + private $startColourRGB; // Array
  66 + private $endColourRGB; // Array
  67 + private $deltaColour; // Array
  68 + private $kmlAlphaColour = 220;
  69 + private $colourLegendHeight = 350;
  70 + private $colourLegendWidth = 30;
  71 +
  72 + private $symbolVertices = 30; // Circle
  73 + private $showLabel = false;
  74 +
  75 + private $classBreaks; // Array
  76 + private $classColours; // Array
  77 +
  78 +
  79 + private $precision = 0; // Number of decimals
  80 +
  81 + //
  82 + // Constructor
  83 + // @access protected
  84 + //
  85 + function __construct($dataStore, $paramArray)
  86 + {
  87 + $this->dataStore = $dataStore;
  88 +
  89 + // Mandatory parameters
90 90 $this->mapType = $paramArray['mapType']; // Mapping technique
91 91 $this->indicatorID = $paramArray['indicator']; // Main indicator
92 92 $this->year = $paramArray['year']; // Year
93 93 $this->dirtmp = $paramArray['dirtmp'];
94   - // Extract indicator metadata and values from dataStore
95   - $this->indicator = $this->dataStore['indicators'][$this->indicatorID];
96   - $this->minValue = $this->indicator['min'];
97   - $this->maxValue = $this->indicator['max'];
98   - $this->precision = $this->indicator['decimals'];
99   -
100   - // Optional parameters: mapTitle, mapDescription and source
101   - if (isset($paramArray['mapTitle'])) $this->mapTitle = $paramArray['mapTitle'];
102   - else $this->mapTitle = $this->indicator['name']; // Use default from indicator
103   -
104   - if (isset($paramArray['mapDescription'])) $this->mapDescription = $paramArray['mapDescription'];
105   - else $this->mapDescription = $this->indicator['description']; // Use default from indicator
106   -
107   - if (isset($paramArray['mapSource'])) $this->mapSource = $paramArray['mapSource'];
108   - else {
109   - //$this->mapSource = 'Statistics from ' . $this->indicator['source']; // Use default from indicator
110   - }
111   -
112   - // Other optional parameters
113   - if (isset($paramArray['timeType'])) $this->timeType = $paramArray['timeType'];
114   - if (isset($paramArray['showTitle'])) $this->showTitle = $paramArray['showTitle'];
115   - if (isset($paramArray['showLegend'])) $this->showLegend = $paramArray['showLegend'];
116   - if (isset($paramArray['colourType'])) $this->colourType = $paramArray['colourType'];
117   - if (isset($paramArray['colour'])) $this->colour = $paramArray['colour'];
118   - if (isset($paramArray['startColour'])) $this->startColour = $paramArray['startColour'];
119   - if (isset($paramArray['endColour'])) $this->endColour = $paramArray['endColour'];
120   - if (isset($paramArray['noDataColour'])) $this->noDataColour = $paramArray['noDataColour'];
121   - if (isset($paramArray['showValues'])) $this->showValues = $paramArray['showValues'];
122   - if (isset($paramArray['showNames'])) $this->showNames = $paramArray['showNames'];
123   - if (isset($paramArray['symbolType'])) $this->symbolType = $paramArray['symbolType'];
124   - if (isset($paramArray['symbolShape'])) $this->symbolShape = $paramArray['symbolShape'];
125   - if (isset($paramArray['symbolMaxSize'])) $this->symbolMaxSize = $paramArray['symbolMaxSize'];
126   - if (isset($paramArray['maxHeight'])) $this->maxHeight = $paramArray['maxHeight'];
127   - if (isset($paramArray['barSize'])) $this->barSize = $paramArray['barSize'];
128   - if (isset($paramArray['classification'])) $this->classification = $paramArray['classification'];
129   - if (isset($paramArray['numClasses'])) $this->numClasses = $paramArray['numClasses'];
130   -
131   - if ($this->showValues || $this->showNames) {
132   - $this->showLabel = true;
133   - }
134   -
135   - if (isset($paramArray['opacity'])) {
136   - $this->opacity = $paramArray['opacity'];
137   - $this->kmlAlphaColour = 255 * $this->opacity / 100;
138   - }
139   -
140   - // Make an array of available years
141   - if ($this->timeType != 'year') $this->yearArray = $this->indicator['years'];
142   - else $this->yearArray = array($this->year); // Only one year
143   -
144   -
145   - }
146   -
147   -
148   - //
149   - // Constructor
150   - // @access protected
151   - //
152   - function __deconstruct()
153   - {
154   - // What goes here?
155   - }
156   -
157   -
158   - //
159   - // Function
160   - // @access protected
161   - //
162   - public function getKML($url,$download = false)
163   - {
164   -
165   - // Create KMZ archieve
166   - $file = $this->dirtmp."/tme". time(). ".kmz";
167   -
168   - /*
169   - $zip = new ZipArchive();
170   - if ($zip->open($file, ZIPARCHIVE::CREATE)!==TRUE) {
171   - exit("cannot open <$file>\n");
172   - }
  94 + // Extract indicator metadata and values from dataStore
  95 + $this->indicator = $this->dataStore['indicators'][$this->indicatorID];
  96 + $this->minValue = $this->indicator['min'];
  97 + $this->maxValue = $this->indicator['max'];
  98 + $this->precision = $this->indicator['decimals'];
  99 +
  100 + // Optional parameters: mapTitle, mapDescription and source
  101 + if (isset($paramArray['mapTitle'])) $this->mapTitle = $paramArray['mapTitle'];
  102 + else $this->mapTitle = $this->indicator['name']; // Use default from indicator
  103 +
  104 + if (isset($paramArray['mapDescription'])) $this->mapDescription = $paramArray['mapDescription'];
  105 + else $this->mapDescription = $this->indicator['description']; // Use default from indicator
  106 +
  107 + if (isset($paramArray['mapSource'])) $this->mapSource = $paramArray['mapSource'];
  108 + else {
  109 + //$this->mapSource = 'Statistics from ' . $this->indicator['source']; // Use default from indicator
  110 + }
  111 +
  112 + // Other optional parameters
  113 + if (isset($paramArray['timeType'])) $this->timeType = $paramArray['timeType'];
  114 + if (isset($paramArray['showTitle'])) $this->showTitle = $paramArray['showTitle'];
  115 + if (isset($paramArray['showLegend'])) $this->showLegend = $paramArray['showLegend'];
  116 + if (isset($paramArray['colourType'])) $this->colourType = $paramArray['colourType'];
  117 + if (isset($paramArray['colour'])) $this->colour = $paramArray['colour'];
  118 + if (isset($paramArray['startColour'])) $this->startColour = $paramArray['startColour'];
  119 + if (isset($paramArray['endColour'])) $this->endColour = $paramArray['endColour'];
  120 + if (isset($paramArray['noDataColour'])) $this->noDataColour = $paramArray['noDataColour'];
  121 + if (isset($paramArray['showValues'])) $this->showValues = $paramArray['showValues'];
  122 + if (isset($paramArray['showNames'])) $this->showNames = $paramArray['showNames'];
  123 + if (isset($paramArray['symbolType'])) $this->symbolType = $paramArray['symbolType'];
  124 + if (isset($paramArray['symbolShape'])) $this->symbolShape = $paramArray['symbolShape'];
  125 + if (isset($paramArray['symbolMaxSize'])) $this->symbolMaxSize = $paramArray['symbolMaxSize'];
  126 + if (isset($paramArray['maxHeight'])) $this->maxHeight = $paramArray['maxHeight'];
  127 + if (isset($paramArray['barSize'])) $this->barSize = $paramArray['barSize'];
  128 + if (isset($paramArray['classification'])) $this->classification = $paramArray['classification'];
  129 + if (isset($paramArray['numClasses'])) $this->numClasses = $paramArray['numClasses'];
  130 +
  131 + if ($this->showValues || $this->showNames) {
  132 + $this->showLabel = true;
  133 + }
  134 +
  135 + if (isset($paramArray['opacity'])) {
  136 + $this->opacity = $paramArray['opacity'];
  137 + $this->kmlAlphaColour = 255 * $this->opacity / 100;
  138 + }
  139 +
  140 + // Make an array of available years
  141 + if ($this->timeType != 'year') $this->yearArray = $this->indicator['years'];
  142 + else $this->yearArray = array($this->year); // Only one year
  143 +
  144 +
  145 + }
  146 +
  147 +
  148 + //
  149 + // Constructor
  150 + // @access protected
  151 + //
  152 + function __deconstruct()
  153 + {
  154 + // What goes here?
  155 + }
  156 +
  157 +
  158 + //
  159 + // Function
  160 + // @access protected
  161 + //
  162 + public function getKML($url,$download = false)
  163 + {
  164 +
  165 + // Create KMZ archieve
  166 + $file = $this->dirtmp."/tme". time(). ".kmz";
  167 +
  168 + /*
  169 + $zip = new ZipArchive();
  170 + if ($zip->open($file, ZIPARCHIVE::CREATE)!==TRUE) {
  171 + exit("cannot open <$file>\n");
  172 + }
173 173 */
174   - include(__DIR__."/../kmlmapserver/classes/zip.class.php");
175   - $zip = new zipfile();
176   - // Add balloon logo to archieve (300 x 30 px)
177   - $zip->addFile($this->logoline, 'files/balloonlogo.png');
178   -
179   - // KML header
180   - $kml = "<?xml version='1.0' encoding='UTF-8'?>" . PHP_EOL
181   - . "<kml xmlns='http://www.opengis.net/kml/2.2' xmlns:atom='http://www.w3.org/2005/Atom'>" . PHP_EOL
182   - . " <Document>" . PHP_EOL
183   - . " <atom:author>" . PHP_EOL
184   - . " <atom:name>Thematic Mapping Engine</atom:name>" . PHP_EOL
185   - . " </atom:author>" . PHP_EOL
186   - . " <atom:link href='http://thematicmapping.org' rel='related' />" . PHP_EOL
187   - . " <name>$this->mapTitle</name>" . PHP_EOL
188   - . " <open>1</open>" . PHP_EOL
189   - . " <Snippet maxLines='1'>$this->mapSource</Snippet>" . PHP_EOL
190   - . " <description><![CDATA[ $this->mapDescription <p>$this->mapSource</p>$this->engine ]]></description>" . PHP_EOL;
191   - // Add style for indicator balloon
192   - $kmlStyles = " <Style id='balloonStyle'>" . PHP_EOL
193   - . " <BalloonStyle>" . PHP_EOL
194   - . " <text><![CDATA[" . PHP_EOL
195   - . " <a href='http://thematicmapping.org'><img src='http://thematicmapping.org/engine/files/balloonlogo.png'></a>" . PHP_EOL
196   - . " <p><b><font size='+2'>$[name]</font></b></p>" . PHP_EOL
197   - . " <p>$[description]</p>" . PHP_EOL
198   - . " ]]></text>" . PHP_EOL
199   - . " </BalloonStyle>" . PHP_EOL
200   - . " </Style>" . PHP_EOL
201   - . " <styleUrl>#balloonStyle</styleUrl>" . PHP_EOL;
202   -
203   -
204   - if ($this->colourType == 'scale') {
205   - // Need to run before getColourValue / getColourLegend / makeClasses
206   - self::makeColourScale();
207   -
208   - if ($this->classification != 'unclassed') {
209   - self::makeClasses($this->classification, $this->numClasses);
210   - }
211   -
212   - // Add colour legend to KMZ archieve
213   - if ($this->showLegend) {
214   - $imgLegenda = self::getColourLegend();
215   - $zip->addFile($imgLegenda,'files/legend.png');
216   - }
217   - $kmlSingleColour = ''; // Colours needs to be defined for each feature
218   - //$kmlColour = self::rgb2bgr($this->noDataColour); // Not in use, only so the variable has a value
219   - }
220   - else {
221   - $kmlSingleColour = '<color>' . self::rgb2bgr($this->colour) . '</color>';
222   - //$kmlColour = self::rgb2bgr($this->colour);
223   - }
224   -
225   -
226   - // Add style for value placemarks
227   - if ($this->showLabel) {
228   - $kmlStyles .= " <Style id='labelPlacemark'>" . PHP_EOL
229   - . " <IconStyle>" . PHP_EOL
230   - . " <scale>0.0</scale>" . PHP_EOL
231   - . " </IconStyle>" . PHP_EOL
232   - . " <LabelStyle>" . PHP_EOL
233   - . " <scale>1</scale>" . PHP_EOL
234   - . " </LabelStyle>" . PHP_EOL
235   - . " </Style>" . PHP_EOL;
236   - }
237   -
238   - // Define shared styles and legend
239   - $kmlStyles .= " <Style id='sharedStyle'>" . PHP_EOL;
240   - switch ($this->mapType) {
241   -
242   - case "choropleth":
243   - case "prism":
244   -
245   - $kmlStyles .= " <PolyStyle>" . PHP_EOL
246   - . " <fill>1</fill>" . PHP_EOL
247   - . " <outline>1</outline>" . PHP_EOL
248   - . " $kmlSingleColour" . PHP_EOL
249   - . " </PolyStyle>" . PHP_EOL
250   - . " <LineStyle>" . PHP_EOL
251   - . " <color>cc000000</color>" . PHP_EOL
252   - . " </LineStyle>" . PHP_EOL;
253   - break;
254   -
255   - case "bar":
256   -
257   - $kmlStyles .= " <PolyStyle>" . PHP_EOL
258   - . " <fill>1</fill>" . PHP_EOL
259   - . " <outline>0</outline>" . PHP_EOL
260   - . " $kmlSingleColour" . PHP_EOL
261   - . " </PolyStyle>" . PHP_EOL;
262   - break;
263   -
264   -
265   -
266   - // Proportional symbol
267   - case "symbol":
268   -
269   - switch($this->symbolType){
270   -
271   - case 'image':
272   - $zip->addFile("files/$this->symbolShape.png", 'files/symbol.png');
273   - $kmlStyles .= " <IconStyle>" . PHP_EOL
274   - . " $kmlSingleColour" . PHP_EOL
275   - . " <Icon>" . PHP_EOL
276   - . " <href>".$url."/symbol.png</href>" . PHP_EOL
277   - . " </Icon>" . PHP_EOL
278   - . " </IconStyle>" . PHP_EOL;
279   - break;
280   -
281   - case 'polygon':
282   - if ($this->symbolShape == 'square') {
283   - $this->symbolVertices = 4;
284   - }
285   - $kmlStyles .= " <PolyStyle>" . PHP_EOL
286   - . " $kmlSingleColour" . PHP_EOL
287   - . " <fill>1</fill>" . PHP_EOL
288   - . " <outline>1</outline>" . PHP_EOL
289   - . " </PolyStyle>" . PHP_EOL
290   - . " <LineStyle>" . PHP_EOL
291   - . " <color>cc000000</color>" . PHP_EOL
292   - . " </LineStyle>" . PHP_EOL;
293   - break;
294   -
295   - case 'collada':
296   - if ($this->colourType == 'scale') {
297   - // Limit number of collada objects (one for each colour)
298   - if ($this->classification == 'unclassed') {
299   - self::makeClasses('equal', 12);
300   - }
301   -
302   - foreach($this->classColours as $class => $classColour){
303   - $colladaColour = self::rgb2collada($classColour);
304   -
305   - // Read collada model
306   - $filename = "files/$this->symbolShape.dae";
307   - $handle = fopen($filename, "r");
308   - $collada = fread($handle, filesize($filename));
309   - fclose($handle);
310   -
311   - // Search and replace colour
312   - $pos = strpos($collada, '<effect id="material0-effect" name="material0-effect">');
313   - $pos = strpos($collada, "<diffuse>", $pos);
314   - $pos = strpos($collada, "<color>", $pos);
315   - $collada = substr_replace($collada, $colladaColour, $pos+7, 28);
316   -
317   - // Add collada object to kmz archieve
318   - $zip->addFromString("files/object$class.dae", $collada);
319   - }
320   - }
321   -
322   - // Single colour
323   - else {
324   - $colladaColour = self::rgb2collada($this->colour);
325   -
326   - // Read collada model
327   - $filename = "files/$this->symbolShape.dae";
328   - $handle = fopen($filename, "r");
329   - $collada = fread($handle, filesize($filename));
330   - fclose($handle);
331   -
332   - // Search and replace colour
333   - $pos = strpos($collada, '<effect id="material0-effect" name="material0-effect">');
334   - $pos = strpos($collada, "<diffuse>", $pos);
335   - $pos = strpos($collada, "<color>", $pos);
336   - $collada = substr_replace($collada, $colladaColour, $pos+7, 28);
337   -
338   - // Add collada object to kmz archieve
339   - $zip->addFromString("files/object.dae", $collada);
340   - }
341   -
342   - $kmlstyle = ''; // Not possible to define style for collada objects
343   -
344   - } // switch symbol
345   - } // switch type
346   -
347   - $kmlStyles .= " <BalloonStyle>" . PHP_EOL
348   - . " <text><![CDATA[" . PHP_EOL
349   - . " <a href='http://thematicmapping.org'><img src='http://thematicmapping.org/engine/files/balloonlogo.png'></a>" . PHP_EOL
350   - . " <p><b><font size='+2'>$[name]</font></b></p>" . PHP_EOL
351   - . " <p>$this->mapTitle: $[Snippet]</p>" . PHP_EOL
352   - . " <p>$this->mapDescription</p>" . PHP_EOL
353   - . " <p>$this->mapSource</p>" . PHP_EOL
354   - . " <p>$this->engine</p>" . PHP_EOL
355   - . " ]]></text>" . PHP_EOL
356   - . " </BalloonStyle>" . PHP_EOL
357   - . " </Style>" . PHP_EOL; // End of shared style
358   -
359   - $kmlFolder = " <Folder>" . PHP_EOL
360   - . " <name>Colunas</name>" . PHP_EOL
361   - . " <open>1</open>" . PHP_EOL;
362   -
363   - if ($this->timeType == 'series') {
364   - $kmlFolder .= " <Style>" . PHP_EOL
365   - . " <ListStyle>" . PHP_EOL
366   - . " <listItemType>radioFolder</listItemType>" . PHP_EOL
367   - . " </ListStyle>" . PHP_EOL
368   - . " </Style>" . PHP_EOL;
369   - }
370   -
371   - // Loop thorough all years
372   - foreach ($this->yearArray as $key => $year) {
373   -
374   - $kmlFeatures = '';
375   -
376   - if (($this->timeType == 'slider') OR ($year == $this->year)) $visibility = 1;
377   - else $visibility = 0;
378   -
379   - $kmlFolder .= " <Folder>" . PHP_EOL
380   - . " <name>$year</name>" . PHP_EOL
381   - . " <visibility>$visibility</visibility>" . PHP_EOL;
382   -
383   - if ($this->showLabel) {
384   - $kmlLabels = " <Folder>" . PHP_EOL
385   - . " <name>Show/hide labels</name>" . PHP_EOL
386   - . " <visibility>$visibility</visibility>" . PHP_EOL
387   - . " <Style>" . PHP_EOL
388   - . " <ListStyle>" . PHP_EOL
389   - . " <listItemType>checkHideChildren</listItemType>" . PHP_EOL
390   - . " </ListStyle>" . PHP_EOL
391   - . " </Style>" . PHP_EOL;
392   - }
393   -
394   - // Add timespan if time animation
395   - if ($this->timeType == 'slider') {
  174 + include(__DIR__."/../kmlmapserver/classes/zip.class.php");
  175 + $zip = new zipfile();
  176 + // Add balloon logo to archieve (300 x 30 px)
  177 + $zip->addFile($this->logoline, 'files/balloonlogo.png');
  178 +
  179 + // KML header
  180 + $kml = "<?xml version='1.0' encoding='UTF-8'?>" . PHP_EOL
  181 + . "<kml xmlns='http://www.opengis.net/kml/2.2' xmlns:atom='http://www.w3.org/2005/Atom'>" . PHP_EOL
  182 + . " <Document>" . PHP_EOL
  183 + . " <atom:author>" . PHP_EOL
  184 + . " <atom:name>Thematic Mapping Engine</atom:name>" . PHP_EOL
  185 + . " </atom:author>" . PHP_EOL
  186 + . " <atom:link href='http://thematicmapping.org' rel='related' />" . PHP_EOL
  187 + . " <name>$this->mapTitle</name>" . PHP_EOL
  188 + . " <open>1</open>" . PHP_EOL
  189 + . " <Snippet maxLines='1'>$this->mapSource</Snippet>" . PHP_EOL
  190 + . " <description><![CDATA[ $this->mapDescription <p>$this->mapSource</p>$this->engine ]]></description>" . PHP_EOL;
  191 + // Add style for indicator balloon
  192 + $kmlStyles = " <Style id='balloonStyle'>" . PHP_EOL
  193 + . " <BalloonStyle>" . PHP_EOL
  194 + . " <text><![CDATA[" . PHP_EOL
  195 + . " <a href='http://thematicmapping.org'><img src='http://thematicmapping.org/engine/files/balloonlogo.png'></a>" . PHP_EOL
  196 + . " <p><b><font size='+2'>$[name]</font></b></p>" . PHP_EOL
  197 + . " <p>$[description]</p>" . PHP_EOL
  198 + . " ]]></text>" . PHP_EOL
  199 + . " </BalloonStyle>" . PHP_EOL
  200 + . " </Style>" . PHP_EOL
  201 + . " <styleUrl>#balloonStyle</styleUrl>" . PHP_EOL;
  202 +
  203 +
  204 + if ($this->colourType == 'scale') {
  205 + // Need to run before getColourValue / getColourLegend / makeClasses
  206 + self::makeColourScale();
  207 +
  208 + if ($this->classification != 'unclassed') {
  209 + self::makeClasses($this->classification, $this->numClasses);
  210 + }
  211 +
  212 + // Add colour legend to KMZ archieve
  213 + if ($this->showLegend) {
  214 + $imgLegenda = self::getColourLegend();
  215 + $zip->addFile($imgLegenda,'files/legend.png');
  216 + }
  217 + $kmlSingleColour = ''; // Colours needs to be defined for each feature
  218 + //$kmlColour = self::rgb2bgr($this->noDataColour); // Not in use, only so the variable has a value
  219 + }
  220 + else {
  221 + $kmlSingleColour = '<color>' . self::rgb2bgr($this->colour) . '</color>';
  222 + //$kmlColour = self::rgb2bgr($this->colour);
  223 + }
  224 +
  225 +
  226 + // Add style for value placemarks
  227 + if ($this->showLabel) {
  228 + $kmlStyles .= " <Style id='labelPlacemark'>" . PHP_EOL
  229 + . " <IconStyle>" . PHP_EOL
  230 + . " <scale>0.0</scale>" . PHP_EOL
  231 + . " </IconStyle>" . PHP_EOL
  232 + . " <LabelStyle>" . PHP_EOL
  233 + . " <scale>1</scale>" . PHP_EOL
  234 + . " </LabelStyle>" . PHP_EOL
  235 + . " </Style>" . PHP_EOL;
  236 + }
  237 +
  238 + // Define shared styles and legend
  239 + $kmlStyles .= " <Style id='sharedStyle'>" . PHP_EOL;
  240 + switch ($this->mapType) {
  241 +
  242 + case "choropleth":
  243 + case "prism":
  244 +
  245 + $kmlStyles .= " <PolyStyle>" . PHP_EOL
  246 + . " <fill>1</fill>" . PHP_EOL
  247 + . " <outline>1</outline>" . PHP_EOL
  248 + . " $kmlSingleColour" . PHP_EOL
  249 + . " </PolyStyle>" . PHP_EOL
  250 + . " <LineStyle>" . PHP_EOL
  251 + . " <color>cc000000</color>" . PHP_EOL
  252 + . " </LineStyle>" . PHP_EOL;
  253 + break;
  254 +
  255 + case "bar":
  256 +
  257 + $kmlStyles .= " <PolyStyle>" . PHP_EOL
  258 + . " <fill>1</fill>" . PHP_EOL
  259 + . " <outline>0</outline>" . PHP_EOL
  260 + . " $kmlSingleColour" . PHP_EOL
  261 + . " </PolyStyle>" . PHP_EOL;
  262 + break;
  263 +
  264 +
  265 +
  266 + // Proportional symbol
  267 + case "symbol":
  268 +
  269 + switch($this->symbolType){
  270 +
  271 + case 'image':
  272 + $zip->addFile("files/$this->symbolShape.png", 'files/symbol.png');
  273 + $kmlStyles .= " <IconStyle>" . PHP_EOL
  274 + . " $kmlSingleColour" . PHP_EOL
  275 + . " <Icon>" . PHP_EOL
  276 + . " <href>".$url."/symbol.png</href>" . PHP_EOL
  277 + . " </Icon>" . PHP_EOL
  278 + . " </IconStyle>" . PHP_EOL;
  279 + break;
  280 +
  281 + case 'polygon':
  282 + if ($this->symbolShape == 'square') {
  283 + $this->symbolVertices = 4;
  284 + }
  285 + $kmlStyles .= " <PolyStyle>" . PHP_EOL
  286 + . " $kmlSingleColour" . PHP_EOL
  287 + . " <fill>1</fill>" . PHP_EOL
  288 + . " <outline>1</outline>" . PHP_EOL
  289 + . " </PolyStyle>" . PHP_EOL
  290 + . " <LineStyle>" . PHP_EOL
  291 + . " <color>cc000000</color>" . PHP_EOL
  292 + . " </LineStyle>" . PHP_EOL;
  293 + break;
  294 +
  295 + case 'collada':
  296 + if ($this->colourType == 'scale') {
  297 + // Limit number of collada objects (one for each colour)
  298 + if ($this->classification == 'unclassed') {
  299 + self::makeClasses('equal', 12);
  300 + }
  301 +
  302 + foreach($this->classColours as $class => $classColour){
  303 + $colladaColour = self::rgb2collada($classColour);
  304 +
  305 + // Read collada model
  306 + $filename = "files/$this->symbolShape.dae";
  307 + $handle = fopen($filename, "r");
  308 + $collada = fread($handle, filesize($filename));
  309 + fclose($handle);
  310 +
  311 + // Search and replace colour
  312 + $pos = strpos($collada, '<effect id="material0-effect" name="material0-effect">');
  313 + $pos = strpos($collada, "<diffuse>", $pos);
  314 + $pos = strpos($collada, "<color>", $pos);
  315 + $collada = substr_replace($collada, $colladaColour, $pos+7, 28);
  316 +
  317 + // Add collada object to kmz archieve
  318 + $zip->addFromString("files/object$class.dae", $collada);
  319 + }
  320 + }
  321 +
  322 + // Single colour
  323 + else {
  324 + $colladaColour = self::rgb2collada($this->colour);
  325 +
  326 + // Read collada model
  327 + $filename = "files/$this->symbolShape.dae";
  328 + $handle = fopen($filename, "r");
  329 + $collada = fread($handle, filesize($filename));
  330 + fclose($handle);
  331 +
  332 + // Search and replace colour
  333 + $pos = strpos($collada, '<effect id="material0-effect" name="material0-effect">');
  334 + $pos = strpos($collada, "<diffuse>", $pos);
  335 + $pos = strpos($collada, "<color>", $pos);
  336 + $collada = substr_replace($collada, $colladaColour, $pos+7, 28);
  337 +
  338 + // Add collada object to kmz archieve
  339 + $zip->addFromString("files/object.dae", $collada);
  340 + }
  341 +
  342 + $kmlstyle = ''; // Not possible to define style for collada objects
  343 +
  344 + } // switch symbol
  345 + } // switch type
  346 +
  347 + $kmlStyles .= " <BalloonStyle>" . PHP_EOL
  348 + . " <text><![CDATA[" . PHP_EOL
  349 + . " <a href='http://thematicmapping.org'><img src='http://thematicmapping.org/engine/files/balloonlogo.png'></a>" . PHP_EOL
  350 + . " <p><b><font size='+2'>$[name]</font></b></p>" . PHP_EOL
  351 + . " <p>$this->mapTitle: $[Snippet]</p>" . PHP_EOL
  352 + . " <p>$this->mapDescription</p>" . PHP_EOL
  353 + . " <p>$this->mapSource</p>" . PHP_EOL
  354 + . " <p>$this->engine</p>" . PHP_EOL
  355 + . " ]]></text>" . PHP_EOL
  356 + . " </BalloonStyle>" . PHP_EOL
  357 + . " </Style>" . PHP_EOL; // End of shared style
  358 +
  359 + $kmlFolder = " <Folder>" . PHP_EOL
  360 + . " <name>Colunas</name>" . PHP_EOL
  361 + . " <open>1</open>" . PHP_EOL;
  362 +
  363 + if ($this->timeType == 'series') {
  364 + $kmlFolder .= " <Style>" . PHP_EOL
  365 + . " <ListStyle>" . PHP_EOL
  366 + . " <listItemType>radioFolder</listItemType>" . PHP_EOL
  367 + . " </ListStyle>" . PHP_EOL
  368 + . " </Style>" . PHP_EOL;
  369 + }
  370 +
  371 + // Loop thorough all years
  372 + foreach ($this->yearArray as $key => $year) {
  373 +
  374 + $kmlFeatures = '';
  375 +
  376 + if (($this->timeType == 'slider') OR ($year == $this->year)) $visibility = 1;
  377 + else $visibility = 0;
  378 +
  379 + $kmlFolder .= " <Folder>" . PHP_EOL
  380 + . " <name>$year</name>" . PHP_EOL
  381 + . " <visibility>$visibility</visibility>" . PHP_EOL;
  382 +
  383 + if ($this->showLabel) {
  384 + $kmlLabels = " <Folder>" . PHP_EOL
  385 + . " <name>Show/hide labels</name>" . PHP_EOL
  386 + . " <visibility>$visibility</visibility>" . PHP_EOL
  387 + . " <Style>" . PHP_EOL
  388 + . " <ListStyle>" . PHP_EOL
  389 + . " <listItemType>checkHideChildren</listItemType>" . PHP_EOL
  390 + . " </ListStyle>" . PHP_EOL
  391 + . " </Style>" . PHP_EOL;
  392 + }
  393 +
  394 + // Add timespan if time animation
  395 + if ($this->timeType == 'slider') {
396 396  
397 397 $end = '';
398   - // Check if there is more years
399   - if (array_key_exists($key+1, $this->yearArray)) {
400   - $end = '<end>' . intval($this->yearArray[$key+1]-1) . '-12-31</end>';
401   - }
402   - $kmlFolder .= " <TimeSpan>" . PHP_EOL
403   - . " <begin>$year-01-01</begin>$end" . PHP_EOL
404   - . " </TimeSpan>" . PHP_EOL;
405   -
406   - }
407   -
408   - // Loop thorough all features (values without features will not be shown)
409   - foreach ($this->dataStore['features'] as $featureID => $feature)
410   - {
411   - $name = $feature['name'];
  398 + // Check if there is more years
  399 + if (array_key_exists($key+1, $this->yearArray)) {
  400 + $end = '<end>' . intval($this->yearArray[$key+1]-1) . '-12-31</end>';
  401 + }
  402 + $kmlFolder .= " <TimeSpan>" . PHP_EOL
  403 + . " <begin>$year-01-01</begin>$end" . PHP_EOL
  404 + . " </TimeSpan>" . PHP_EOL;
  405 +
  406 + }
  407 +
  408 + // Loop thorough all features (values without features will not be shown)
  409 + foreach ($this->dataStore['features'] as $featureID => $feature)
  410 + {
  411 + $name = $feature['name'];
412 412 //if (!mb_detect_encoding($name,"UTF-8",true))
413 413 //{$name = mb_convert_encoding($name,"UTF-8","ISO-8859-1");}
414 414 $name = "<![CDATA[ ".$name." ]]>";
415   - $value = ''; // use null?
416   - $valueText = 'no data';
417   - $valueLabel = '';
418   - $kmlFeature = '';
419   - $altitude = 0;
420   - $symbolSize = 0;
421   - $colladaCount = 0;
422   - //$kmlColour = self::rgb2bgr($this->noDataColour);
423   - $kmlColour = '';
424   -
425   - $longitude = $feature['lon'];
426   - $latitude = $feature['lat'];
427   -
428   - // Check if value exists for this feature
429   - if (isset($this->indicator['values'][$year][$featureID])) {
430   - // Extract value from dataStore
431   - $value = $this->indicator['values'][$year][$featureID];
432   - $valueText = $valueLabel = number_format($value, 2, ',', '.');
433   - // Colour scale
434   - if ($this->colourType == 'scale') {
435   - if ($this->classification != 'unclassed') {
436   - $class = self::getClass($value);
437   - $kmlColour = self::rgb2bgr($this->classColours[$class]);
438   - }
439   - else {
440   - $kmlColour = self::getColourValue($value, 'kml');
441   - }
442   - }
443   - // Single colour
444   - //else {
445   - // $kmlColour = self::rgb2bgr($this->colour);
446   - //}
447   - }
448   - else {
449   - $kmlColour = self::rgb2bgr($this->noDataColour);
450   - }
451   -
452   -
453   - switch ($this->mapType) {
454   -
455   - case "choropleth":
456   -
457   - $kmlFeature = " <Style>" . PHP_EOL
458   - . " <PolyStyle>" . PHP_EOL
459   - . " <color>$kmlColour</color>" . PHP_EOL
460   - . " </PolyStyle>" . PHP_EOL
461   - . " </Style>" . PHP_EOL;
462   -
463   - $kmlFeature .= self::wkt2kml($feature['wkt'], 0);
464   - break;
465   -
466   - case "prism":
467   - $altitude = intval($value * ($this->maxHeight / $this->maxValue));
468   -
469   - if ($this->colourType == 'scale') {
470   - $kmlFeature = " <Style>" . PHP_EOL
471   - . " <PolyStyle>" . PHP_EOL
472   - . " <color>$kmlColour</color>" . PHP_EOL
473   - . " </PolyStyle>" . PHP_EOL
474   - . " </Style>" . PHP_EOL;
475   - }
476   -
477   - $kmlFeature .= self::wkt2kml($feature['wkt'], $altitude) . PHP_EOL;
478   - break;
479   -
480   - case "bar":
481   - if ($value != null) {
482   - $altitude = intval($value * ($this->maxHeight / $this->maxValue));
483   -
484   - if ($this->colourType == 'scale') {
485   - $kmlFeature = " <Style>" . PHP_EOL
486   - . " <PolyStyle>" . PHP_EOL
487   - . " <color>$kmlColour</color>" . PHP_EOL
488   - . " </PolyStyle>" . PHP_EOL
489   - . " </Style>" . PHP_EOL;
490   - }
491   -
492   - $kmlFeature .= self::kmlSymbolCalculator($longitude, $latitude, $this->barSize, 15, $altitude);
493   - }
494   - break;
495   -
496   - case "symbol":
497   - if ($value != null) {
498   -
499   - switch($this->symbolType){
500   -
501   - case 'im$z = new ZipArchive();
  415 + $value = ''; // use null?
  416 + $valueText = 'no data';
  417 + $valueLabel = '';
  418 + $kmlFeature = '';
  419 + $altitude = 0;
  420 + $symbolSize = 0;
  421 + $colladaCount = 0;
  422 + //$kmlColour = self::rgb2bgr($this->noDataColour);
  423 + $kmlColour = '';
  424 +
  425 + $longitude = $feature['lon'];
  426 + $latitude = $feature['lat'];
  427 +
  428 + // Check if value exists for this feature
  429 + if (isset($this->indicator['values'][$year][$featureID])) {
  430 + // Extract value from dataStore
  431 + $value = $this->indicator['values'][$year][$featureID];
  432 + $valueText = $valueLabel = number_format($value, 2, ',', '.');
  433 + // Colour scale
  434 + if ($this->colourType == 'scale') {
  435 + if ($this->classification != 'unclassed') {
  436 + $class = self::getClass($value);
  437 + $kmlColour = self::rgb2bgr($this->classColours[$class]);
  438 + }
  439 + else {
  440 + $kmlColour = self::getColourValue($value, 'kml');
  441 + }
  442 + }
  443 + // Single colour
  444 + //else {
  445 + // $kmlColour = self::rgb2bgr($this->colour);
  446 + //}
  447 + }
  448 + else {
  449 + $kmlColour = self::rgb2bgr($this->noDataColour);
  450 + }
  451 +
  452 +
  453 + switch ($this->mapType) {
  454 +
  455 + case "choropleth":
  456 +
  457 + $kmlFeature = " <Style>" . PHP_EOL
  458 + . " <PolyStyle>" . PHP_EOL
  459 + . " <color>$kmlColour</color>" . PHP_EOL
  460 + . " </PolyStyle>" . PHP_EOL
  461 + . " </Style>" . PHP_EOL;
  462 +
  463 + $kmlFeature .= self::wkt2kml($feature['wkt'], 0);
  464 + break;
  465 +
  466 + case "prism":
  467 + $altitude = intval($value * ($this->maxHeight / $this->maxValue));
  468 +
  469 + if ($this->colourType == 'scale') {
  470 + $kmlFeature = " <Style>" . PHP_EOL
  471 + . " <PolyStyle>" . PHP_EOL
  472 + . " <color>$kmlColour</color>" . PHP_EOL
  473 + . " </PolyStyle>" . PHP_EOL
  474 + . " </Style>" . PHP_EOL;
  475 + }
  476 +
  477 + $kmlFeature .= self::wkt2kml($feature['wkt'], $altitude) . PHP_EOL;
  478 + break;
  479 +
  480 + case "bar":
  481 + if ($value != null) {
  482 + $altitude = intval($value * ($this->maxHeight / $this->maxValue));
  483 +
  484 + if ($this->colourType == 'scale') {
  485 + $kmlFeature = " <Style>" . PHP_EOL
  486 + . " <PolyStyle>" . PHP_EOL
  487 + . " <color>$kmlColour</color>" . PHP_EOL
  488 + . " </PolyStyle>" . PHP_EOL
  489 + . " </Style>" . PHP_EOL;
  490 + }
  491 +
  492 + $kmlFeature .= self::kmlSymbolCalculator($longitude, $latitude, $this->barSize, 15, $altitude);
  493 + }
  494 + break;
  495 +
  496 + case "symbol":
  497 + if ($value != null) {
  498 +
  499 + switch($this->symbolType){
  500 +
  501 + case 'im$z = new ZipArchive();
502 502 $z->open("test.zip", ZIPARCHIVE::CREATE);
503 503 folderToZip("storeThisFolder", $z);
504 504 $z->close();age':
505   - //$symbolSize = round(self::getSymbolSize($value, $this->symbolShape),2);
506   - $symbolSize = round($this->symbolMaxSize * sqrt($value/$this->maxValue), 2);
507   -
508   - $kmlFeature = " <Style>" . PHP_EOL
509   - . " <IconStyle>" . PHP_EOL
510   - . " <scale>$symbolSize</scale>" . PHP_EOL
511   - . " <color>$kmlColour</color>" . PHP_EOL
512   - . " </IconStyle>" . PHP_EOL
513   - . " </Style>" . PHP_EOL;
514   -
515   - $kmlFeature .= " <LookAt>" . PHP_EOL
516   - . " <longitude>$longitude</longitude>" . PHP_EOL
517   - . " <latitude>$latitude</latitude>" . PHP_EOL
518   - . " <altitude>0</altitude>" . PHP_EOL
519   - . " <range>3200000</range>" . PHP_EOL
520   - . " <altitudeMode>clampToGround</altitudeMode>" . PHP_EOL
521   - . " </LookAt>" . PHP_EOL
522   - . " <Point>" . PHP_EOL
523   - . " <coordinates>$longitude,$latitude,0</coordinates>" . PHP_EOL
524   - . " </Point>" . PHP_EOL;
525   - break;
526   -
527   - case 'polygon':
528   - //$symbolSize = intval(self::getSymbolSize($value, $this->symbolShape));
529   - $symbolSize = intval($this->symbolMaxSize * sqrt($value/$this->maxValue) * 70000);
530   - if ($this->colourType == 'scale') {
531   - $kmlFeature = " <Style>" . PHP_EOL
532   - . " <PolyStyle>" . PHP_EOL
533   - . " <color>$kmlColour</color>" . PHP_EOL
534   - . " </PolyStyle>" . PHP_EOL
535   - . " </Style>" . PHP_EOL;
536   - }
537   - $kmlFeature .= self::kmlSymbolCalculator($longitude, $latitude, $symbolSize, $this->symbolVertices, 0);
538   - break;
539   -
540   - case 'collada':
541   -
542   - //$symbolSize = intval(self::getSymbolSize($value, $this->symbolShape));
543   - $symbolSize = intval($this->symbolMaxSize * pow($value/$this->maxValue, 1/3) * 20000);
544   -
545   - $class = ''; // Single colour
546   - if ($this->colourType == 'scale') $class = self::getClass($value);
547   -
548   - $altitude = $symbolSize; // Used for label placement
549   - $kmlFeature = " <Model>" . PHP_EOL
550   - . " <altitudeMode>absolute</altitudeMode>" . PHP_EOL
551   - . " <Location>" . PHP_EOL
552   - . " <longitude>$longitude</longitude>" . PHP_EOL
553   - . " <latitude>$latitude</latitude>" . PHP_EOL
554   - . " <altitude>0</altitude>" . PHP_EOL
555   - . " </Location>" . PHP_EOL
556   - . " <Scale>" . PHP_EOL
557   - . " <x>$symbolSize</x>" . PHP_EOL
558   - . " <y>$symbolSize</y>" . PHP_EOL
559   - . " <z>$symbolSize</z>" . PHP_EOL
560   - . " </Scale>" . PHP_EOL
561   - . " <Link>" . PHP_EOL
562   - . " <href>files/object$class.dae</href>" . PHP_EOL
563   - . " </Link>" . PHP_EOL
564   - . " </Model>" . PHP_EOL;
565   - } // switch
566   - } // if
567   - } // switch
568   -
569   -
570   - $kmlFeatures .= " <Placemark>" . PHP_EOL
571   - . " <name>$name</name>" . PHP_EOL
572   - . " <visibility>$visibility</visibility>" . PHP_EOL
573   - . " <Snippet>$valueText ($year)</Snippet>" . PHP_EOL
574   - . " <styleUrl>#sharedStyle</styleUrl>" . PHP_EOL
575   - . $kmlFeature
576   - . " </Placemark>" . PHP_EOL;
577   -
578   - if ($this->showLabel) {
579   - $label = '';
580   - if ($this->showNames) $label = $name;
581   - if ($this->showValues) $label .= ' ' . $valueLabel;
582   - $kmlLabels .= " <Placemark>" . PHP_EOL
583   - . " <name>$label</name>" . PHP_EOL
584   - . " <visibility>$visibility</visibility>" . PHP_EOL
585   - . " <styleUrl>#labelPlacemark</styleUrl>" . PHP_EOL
586   - . " <Point>" . PHP_EOL
587   - . " <altitudeMode>absolute</altitudeMode>" . PHP_EOL
588   - . " <coordinates>$longitude, $latitude, $altitude</coordinates>" . PHP_EOL
589   - . " </Point>" . PHP_EOL
590   - . " </Placemark>" . PHP_EOL;
591   - }
592   -
593   - } // foreach features
594   -
595   - if ($this->showLabel) {
596   - $kmlLabels .= " </Folder>";
597   - $kmlFolder .= $kmlLabels;
598   - }
599   -
600   - $kmlFolder .= $kmlFeatures;
601   -
602   - $kmlFolder .= " </Folder>" . PHP_EOL;
603   - } // foreach years
604   -
605   -
606   -
607   - // Close Years folder
608   - $kmlFolder .= " </Folder>" . PHP_EOL;
609   -
610   - // Create logo with title and source and add to archieve
611   - if ($this->showTitle) {
612   - $imgBrand = self::mapTitleImage();
613   - $zip->addFile($imgBrand, 'files/brand.png');
614   - }
615   - else {
616   - $zip->addFile($this->logo, 'files/brand.png');
617   - }
618   - // Add title
619   - $kml .= " <ScreenOverlay>" . PHP_EOL
620   - . " <name>Título</name>" . PHP_EOL
621   - . " <Icon>" . PHP_EOL
622   - . " <href>http://localhost/ms_tmp/".basename($imgBrand)."</href>" . PHP_EOL
623   - . " </Icon>" . PHP_EOL
624   - . " <overlayXY x='0.01' y='0.99' xunits='fraction' yunits='fraction'/>" . PHP_EOL
625   - . " <screenXY x='0.01' y='0.99' xunits='fraction' yunits='fraction'/>" . PHP_EOL
626   - . " <size x='-1' y='-1' xunits='pixels' yunits='pixels'/>" . PHP_EOL
627   - . " </ScreenOverlay>" . PHP_EOL;
628   -
629   - // Add legend
630   - if ($this->showLegend && $this->colourType == 'scale') {
631   - $kml .= " <ScreenOverlay>" . PHP_EOL
632   - . " <name>Legenda</name>" . PHP_EOL
633   - . " <Icon>" . PHP_EOL
634   - . " <href>http://localhost/ms_tmp/".basename($imgLegenda)."</href>" . PHP_EOL
635   - . " </Icon>" . PHP_EOL
636   - . " <overlayXY x='0.01' y='0.14' xunits='fraction' yunits='fraction'/>" . PHP_EOL
637   - . " <screenXY x='0.01' y='0.14' xunits='fraction' yunits='fraction'/>" . PHP_EOL
638   - . " <size x='-1' y='-1' xunits='pixels' yunits='pixels'/>" . PHP_EOL
639   - . " </ScreenOverlay>" . PHP_EOL;
640   - }
641   -
642   - $kml .= $kmlStyles . $kmlFolder;
643   -
644   - // Add basemap
645   - //if (isset($paramArray['basemap'])) {
646   - // $kml .= "<NetworkLink>
647   - // <name>Basemap</name>
648   - // <Link><href>$basemap</href></Link>
649   - // </NetworkLink>" . PHP_EOL;
650   - //}
651   -
652   - $kml .= " </Document>" . PHP_EOL
653   - . "</kml>" . PHP_EOL;
  505 + //$symbolSize = round(self::getSymbolSize($value, $this->symbolShape),2);
  506 + $symbolSize = round($this->symbolMaxSize * sqrt($value/$this->maxValue), 2);
  507 +
  508 + $kmlFeature = " <Style>" . PHP_EOL
  509 + . " <IconStyle>" . PHP_EOL
  510 + . " <scale>$symbolSize</scale>" . PHP_EOL
  511 + . " <color>$kmlColour</color>" . PHP_EOL
  512 + . " </IconStyle>" . PHP_EOL
  513 + . " </Style>" . PHP_EOL;
  514 +
  515 + $kmlFeature .= " <LookAt>" . PHP_EOL
  516 + . " <longitude>$longitude</longitude>" . PHP_EOL
  517 + . " <latitude>$latitude</latitude>" . PHP_EOL
  518 + . " <altitude>0</altitude>" . PHP_EOL
  519 + . " <range>3200000</range>" . PHP_EOL
  520 + . " <altitudeMode>clampToGround</altitudeMode>" . PHP_EOL
  521 + . " </LookAt>" . PHP_EOL
  522 + . " <Point>" . PHP_EOL
  523 + . " <coordinates>$longitude,$latitude,0</coordinates>" . PHP_EOL
  524 + . " </Point>" . PHP_EOL;
  525 + break;
  526 +
  527 + case 'polygon':
  528 + //$symbolSize = intval(self::getSymbolSize($value, $this->symbolShape));
  529 + $symbolSize = intval($this->symbolMaxSize * sqrt($value/$this->maxValue) * 70000);
  530 + if ($this->colourType == 'scale') {
  531 + $kmlFeature = " <Style>" . PHP_EOL
  532 + . " <PolyStyle>" . PHP_EOL
  533 + . " <color>$kmlColour</color>" . PHP_EOL
  534 + . " </PolyStyle>" . PHP_EOL
  535 + . " </Style>" . PHP_EOL;
  536 + }
  537 + $kmlFeature .= self::kmlSymbolCalculator($longitude, $latitude, $symbolSize, $this->symbolVertices, 0);
  538 + break;
  539 +
  540 + case 'collada':
  541 +
  542 + //$symbolSize = intval(self::getSymbolSize($value, $this->symbolShape));
  543 + $symbolSize = intval($this->symbolMaxSize * pow($value/$this->maxValue, 1/3) * 20000);
  544 +
  545 + $class = ''; // Single colour
  546 + if ($this->colourType == 'scale') $class = self::getClass($value);
  547 +
  548 + $altitude = $symbolSize; // Used for label placement
  549 + $kmlFeature = " <Model>" . PHP_EOL
  550 + . " <altitudeMode>absolute</altitudeMode>" . PHP_EOL
  551 + . " <Location>" . PHP_EOL
  552 + . " <longitude>$longitude</longitude>" . PHP_EOL
  553 + . " <latitude>$latitude</latitude>" . PHP_EOL
  554 + . " <altitude>0</altitude>" . PHP_EOL
  555 + . " </Location>" . PHP_EOL
  556 + . " <Scale>" . PHP_EOL
  557 + . " <x>$symbolSize</x>" . PHP_EOL
  558 + . " <y>$symbolSize</y>" . PHP_EOL
  559 + . " <z>$symbolSize</z>" . PHP_EOL
  560 + . " </Scale>" . PHP_EOL
  561 + . " <Link>" . PHP_EOL
  562 + . " <href>files/object$class.dae</href>" . PHP_EOL
  563 + . " </Link>" . PHP_EOL
  564 + . " </Model>" . PHP_EOL;
  565 + } // switch
  566 + } // if
  567 + } // switch
  568 +
  569 +
  570 + $kmlFeatures .= " <Placemark>" . PHP_EOL
  571 + . " <name>$name</name>" . PHP_EOL
  572 + . " <visibility>$visibility</visibility>" . PHP_EOL
  573 + . " <Snippet>$valueText ($year)</Snippet>" . PHP_EOL
  574 + . " <styleUrl>#sharedStyle</styleUrl>" . PHP_EOL
  575 + . $kmlFeature
  576 + . " </Placemark>" . PHP_EOL;
  577 +
  578 + if ($this->showLabel) {
  579 + $label = '';
  580 + if ($this->showNames) $label = $name;
  581 + if ($this->showValues) $label .= ' ' . $valueLabel;
  582 + $kmlLabels .= " <Placemark>" . PHP_EOL
  583 + . " <name>$label</name>" . PHP_EOL
  584 + . " <visibility>$visibility</visibility>" . PHP_EOL
  585 + . " <styleUrl>#labelPlacemark</styleUrl>" . PHP_EOL
  586 + . " <Point>" . PHP_EOL
  587 + . " <altitudeMode>absolute</altitudeMode>" . PHP_EOL
  588 + . " <coordinates>$longitude, $latitude, $altitude</coordinates>" . PHP_EOL
  589 + . " </Point>" . PHP_EOL
  590 + . " </Placemark>" . PHP_EOL;
  591 + }
  592 +
  593 + } // foreach features
  594 +
  595 + if ($this->showLabel) {
  596 + $kmlLabels .= " </Folder>";
  597 + $kmlFolder .= $kmlLabels;
  598 + }
  599 +
  600 + $kmlFolder .= $kmlFeatures;
  601 +
  602 + $kmlFolder .= " </Folder>" . PHP_EOL;
  603 + } // foreach years
  604 +
  605 +
  606 +
  607 + // Close Years folder
  608 + $kmlFolder .= " </Folder>" . PHP_EOL;
  609 +
  610 + // Create logo with title and source and add to archieve
  611 + if ($this->showTitle) {
  612 + $imgBrand = self::mapTitleImage();
  613 + $zip->addFile($imgBrand, 'files/brand.png');
  614 + }
  615 + else {
  616 + $zip->addFile($this->logo, 'files/brand.png');
  617 + }
  618 + // Add title
  619 + $kml .= " <ScreenOverlay>" . PHP_EOL
  620 + . " <name>Titulo</name>" . PHP_EOL
  621 + . " <Icon>" . PHP_EOL
  622 + . " <href>".$url."/".basename($imgBrand)."</href>" . PHP_EOL
  623 + . " </Icon>" . PHP_EOL
  624 + . " <overlayXY x='0.01' y='0.99' xunits='fraction' yunits='fraction'/>" . PHP_EOL
  625 + . " <screenXY x='0.01' y='0.99' xunits='fraction' yunits='fraction'/>" . PHP_EOL
  626 + . " <size x='-1' y='-1' xunits='pixels' yunits='pixels'/>" . PHP_EOL
  627 + . " </ScreenOverlay>" . PHP_EOL;
  628 +
  629 + // Add legend
  630 + if ($this->showLegend && $this->colourType == 'scale') {
  631 + $kml .= " <ScreenOverlay>" . PHP_EOL
  632 + . " <name>Legenda</name>" . PHP_EOL
  633 + . " <Icon>" . PHP_EOL
  634 + . " <href>".$url."/".basename($imgLegenda)."</href>" . PHP_EOL
  635 + . " </Icon>" . PHP_EOL
  636 + . " <overlayXY x='0.01' y='0.14' xunits='fraction' yunits='fraction'/>" . PHP_EOL
  637 + . " <screenXY x='0.01' y='0.14' xunits='fraction' yunits='fraction'/>" . PHP_EOL
  638 + . " <size x='-1' y='-1' xunits='pixels' yunits='pixels'/>" . PHP_EOL
  639 + . " </ScreenOverlay>" . PHP_EOL;
  640 + }
  641 +
  642 + $kml .= $kmlStyles . $kmlFolder;
  643 +
  644 + // Add basemap
  645 + //if (isset($paramArray['basemap'])) {
  646 + // $kml .= "<NetworkLink>
  647 + // <name>Basemap</name>
  648 + // <Link><href>$basemap</href></Link>
  649 + // </NetworkLink>" . PHP_EOL;
  650 + //}
  651 +
  652 + $kml .= " </Document>" . PHP_EOL
  653 + . "</kml>" . PHP_EOL;
654 654  
655 655  
656 656 // Open archive if collada
657 657  
658 658  
659   - // Add kml to archieve
660   - //$zip->addFromString("doc.kml", $kml);
661   - $zip->addFile($kml, 'doc.kml');//edmar
  659 + // Add kml to archieve
  660 + //$zip->addFromString("doc.kml", $kml);
  661 + $zip->addFile($kml, 'doc.kml');//edmar
662 662  
663 663  
664   - //$zip->close();
665   - $zip->output($file);//edmar
666   - if($download){
667   - ob_end_clean();
668   - //header('Content-Type: application/vnd.google-earth.kml+xml');
669   - header('Content-Disposition: attachment; filename='.basename($file));
  664 + //$zip->close();
  665 + $zip->output($file);//edmar
  666 + if($download){
  667 + ob_end_clean();
  668 + //header('Content-Type: application/vnd.google-earth.kml+xml');
  669 + header('Content-Disposition: attachment; filename='.basename($file));
670 670 print $file;
671 671 exit;
672   - }
673   - else{
674   - return $url.basename($file);
675   - }
676   - }
  672 + }
  673 + else{
  674 + return $url.basename($file);
  675 + }
  676 + }
677 677  
678 678  
679 679  
680 680  
681   - //
682   - // Function
683   - // @access protected
684   - //
685   - // This function is based on code developed by "TJ":
686   - // http://bbs.keyhole.com/ubb/showflat.php?Cat=&Board=SupportKML&Number=166379&Searchpage=1&Main=166379&Words=calculate+TJ1&topic=&Search=true
687   - //
688   - function kmlSymbolCalculator( $longitude, $latitude, $distance, $points, $altitude )
689   - {
  681 + //
  682 + // Function
  683 + // @access protected
  684 + //
  685 + // This function is based on code developed by "TJ":
  686 + // http://bbs.keyhole.com/ubb/showflat.php?Cat=&Board=SupportKML&Number=166379&Searchpage=1&Main=166379&Words=calculate+TJ1&topic=&Search=true
  687 + //
  688 + function kmlSymbolCalculator( $longitude, $latitude, $distance, $points, $altitude )
  689 + {
690 690 $EARTH_RADIUS_EQUATOR = 6378140.0;
691 691 $RADIAN = 180 / pi();
692 692  
... ... @@ -698,14 +698,14 @@ $z-&gt;close();age&#39;:
698 698 $f = 1/298.257;
699 699 $e = 0.08181922;
700 700  
701   - $kml = ' <Polygon>' . PHP_EOL
702   - . ' <outerBoundaryIs>' . PHP_EOL
703   - . ' <LinearRing>' . PHP_EOL
704   - . ' <coordinates>';
  701 + $kml = ' <Polygon>' . PHP_EOL
  702 + . ' <outerBoundaryIs>' . PHP_EOL
  703 + . ' <LinearRing>' . PHP_EOL
  704 + . ' <coordinates>';
705 705  
706 706 //for ( $bearing = 0; $bearing <= 360; $bearing += 360/$points) {
707 707 // Changed start bearing beacuse of square orientation
708   - for ( $bearing = 45; $bearing <= 405; $bearing += 360/$points) {
  708 + for ( $bearing = 45; $bearing <= 405; $bearing += 360/$points) {
709 709  
710 710 $b = $bearing / $RADIAN;
711 711  
... ... @@ -720,313 +720,313 @@ $z-&gt;close();age&#39;:
720 720  
721 721 $kml .= " ".round($longA,$this->coordDecimals).",".round($latA,$this->coordDecimals);
722 722 if ($altitude) $kml .= ",".$altitude;
723   - }
  723 + }
724 724  
725   - $kml .= ' </coordinates>' . PHP_EOL
726   - . ' </LinearRing>' . PHP_EOL
727   - . ' </outerBoundaryIs>' . PHP_EOL;
  725 + $kml .= ' </coordinates>' . PHP_EOL
  726 + . ' </LinearRing>' . PHP_EOL
  727 + . ' </outerBoundaryIs>' . PHP_EOL;
728 728  
729   - if ($altitude)
730   - {
731   - $kml .= ' <extrude>1</extrude>' . PHP_EOL
732   - . ' <altitudeMode>absolute</altitudeMode>' . PHP_EOL;
733   - }
  729 + if ($altitude)
  730 + {
  731 + $kml .= ' <extrude>1</extrude>' . PHP_EOL
  732 + . ' <altitudeMode>absolute</altitudeMode>' . PHP_EOL;
  733 + }
734 734  
735   - $kml .= ' </Polygon>' . PHP_EOL;
  735 + $kml .= ' </Polygon>' . PHP_EOL;
736 736  
737 737 return $kml;
738   - }
739   -
740   -
741   - //
742   - // Function
743   - // @access protected
744   - //
745   - public function wkt2kml($wkt, $altitude)
746   - {
747   -
748   - // Change coordinate format
749   - $wkt = preg_replace("/([0-9\.\-]+) ([0-9\.\-]+),*/e", "round('$1',2).','.round('$2',2).',$altitude '", $wkt);
750   -
751   - $wkt = substr($wkt, 15); // Remove 'MULTIPOLYGON(((' at the beginning
752   - $wkt = substr($wkt, 0, -3); // Remove ')))' at the end
753   - $polygons = explode(')),((', $wkt); // Find all polygons
754   - $kml = ' <MultiGeometry>' . PHP_EOL;
755   -
756   - foreach ($polygons as $polygon) {
757   - $kml .= ' <Polygon>' . PHP_EOL;
758   - $boundary = explode('),(', $polygon); // Find all polygon boundaries
759   - $kml .= ' <outerBoundaryIs>' . PHP_EOL
760   - . ' <LinearRing>' . PHP_EOL
761   - . ' <coordinates>' . self::kmlReverseCoordinates($boundary[0]) . ' </coordinates>' . PHP_EOL
762   - . ' </LinearRing>' . PHP_EOL
763   - . ' </outerBoundaryIs>' . PHP_EOL;
764   -
765   - for ($i=1; $i < count($boundary); $i++) { // If inner boundaries
766   - $kml .= ' <innerBoundaryIs>' . PHP_EOL
767   - . ' <LinearRing>' . PHP_EOL
768   - . ' <coordinates>' . self::kmlReverseCoordinates($boundary[$i]) . ' </coordinates>' . PHP_EOL
769   - . ' </LinearRing>' . PHP_EOL
770   - . ' </innerBoundaryIs>' . PHP_EOL;
771   - }
772   - $kml .= ' </Polygon>' . PHP_EOL;
773   - }
774   - $kml .= ' </MultiGeometry>' . PHP_EOL;
775   -
776   - if ($altitude)
777   - {
778   - $kml = str_replace('<Polygon>', '<Polygon><extrude>1</extrude><tessellate>1</tessellate><altitudeMode>absolute</altitudeMode>', $kml);
779   - }
780   -
781   - return $kml;
782   - }
783   -
784   - //
785   - // Function
786   - // @access protected
787   - //
788   - function kmlReverseCoordinates($coordinates)
789   - {
790   - $coordinates = explode(" ", $coordinates);
791   - $coordinates = array_reverse($coordinates);
792   - $coordinates = implode(" ", $coordinates);
793   - return $coordinates;
794   - }
795   -
796   - // Generates KML colour
797   - function rgb2bgr($rgb)
798   - {
799   - $colour = dechex($this->kmlAlphaColour) . substr($rgb, -2) . substr($rgb, 2, 2) . substr($rgb, 0, 2);
800   - return $colour;
801   - }
802   -
803   - // Generates COLLADA colour
804   - function rgb2collada($rgb)
805   - {
806   - $red = number_format(hexdec(substr($rgb, 0, 2)) / 255, 6);
807   - $green = number_format(hexdec(substr($rgb, 2, 2)) / 255, 6);
808   - $blue = number_format(hexdec(substr($rgb, -2)) / 255, 6);
809   -
810   - $colour = "$red $green $blue 1"; // Transparency not supported in GE?
811   - return $colour;
812   - }
813   -
814   -
815   - // Generates a colour scale
816   - function makeColourScale(){
817   -
818   - // Extract red/green/blue decimal values from hexadecimal colours
819   - $this->startColourRGB = array(hexdec(substr($this->startColour, 0, 2)),
820   - hexdec(substr($this->startColour, 2, 2)),
821   - hexdec(substr($this->startColour, 4, 2)));
822   -
823   - $this->endColourRGB = array(hexdec(substr($this->endColour, 0, 2)),
824   - hexdec(substr($this->endColour, 2, 2)),
825   - hexdec(substr($this->endColour, 4, 2)));
826   -
827   - // Calculate the change value for red/green/blue
828   - $this->deltaColourRGB = array($this->endColourRGB[0] - $this->startColourRGB[0],
829   - $this->endColourRGB[1] - $this->startColourRGB[1],
830   - $this->endColourRGB[2] - $this->startColourRGB[2]);
831   - }
832   -
833   - function getColourValue($value, $format){
834   - $red = $this->startColourRGB[0] + ($this->deltaColourRGB[0] / ($this->maxValue - $this->minValue)) * ($value - $this->minValue);
835   - $green = $this->startColourRGB[1] + ($this->deltaColourRGB[1] / ($this->maxValue - $this->minValue)) * ($value - $this->minValue);
836   - $blue = $this->startColourRGB[2] + ($this->deltaColourRGB[2] / ($this->maxValue - $this->minValue)) * ($value - $this->minValue);
837   -
838   - if ($format == 'kml') {
839   - $colour = sprintf('%02X%02X%02X%02X', $this->kmlAlphaColour, $blue, $green, $red);
840   - }
841   - else { // Hex colour
842   - $colour = sprintf('%02X%02X%02X', $red, $green, $blue);
843   - }
844   -
845   - return $colour;
846   - }
847   -
848   - function getColourLegend(){
849   - $height = $this->colourLegendHeight;
850   - $width = $this->colourLegendWidth;
851   -
852   - // Create colour scale canvas
853   - $legend = imagecreatetruecolor(150, $height+6);
854   -
855   - // Allocate colours
856   - $bgColour = imagecolorallocatealpha($legend, 255, 255, 255, 127);
857   - $white = $fontColour = imagecolorallocate($legend, 255, 255, 255);
858   - imageSaveAlpha($legend, true);
859   -
860   - // Set background colour
861   - imagefill($legend, 0, 0, $bgColour);
862   -
863   - switch ($this->classification) {
864   -
865   - case 'unclassed':
866   - for ($i = 0; $i <= $height; $i++) {
867   - $red = intval($this->endColourRGB[0] - (($this->deltaColourRGB[0] / $height) * $i));
868   - $green = intval($this->endColourRGB[1] - (($this->deltaColourRGB[1] / $height) * $i));
869   - $blue = intval($this->endColourRGB[2] - (($this->deltaColourRGB[2] / $height) * $i));
870   - $myColourScale[] = imagecolorallocate($legend, $red, $green, $blue);
871   - }
872   - // Draw colour scale
873   - imagesetstyle($legend, $myColourScale);
874   -
875   - for ($i = 0; $i < $width; $i++) {
876   - imageline($legend, 21+$i, 2, 21+$i, $height+2, IMG_COLOR_STYLED);
877   - }
878   -
879   - // print min and max values
880   - //number_format(($s / $ocorrencias),2,",",".")
881   - //imagestring($legend, 3, $width+29, $height-6, number_format($this->minValue, $this->precision), $fontColour);
882   - //imagestring($legend, 3, $width+29, -3, number_format($this->maxValue, $this->precision), $fontColour);
883   - imagestring($legend, 3, $width+29, $height-6, number_format($this->minValue, 2,",","."), $fontColour);
884   - imagestring($legend, 3, $width+29, -3, number_format($this->maxValue, 2,",","."), $fontColour);
885   -
886   - break;
887   -
888   - // classed (equal intervals / quantiles)
889   - default:
890   - $ypos = 0;
891   - $interval = $height / $this->numClasses;
892   - $v = $this->classColours;
893   - foreach($v as $key => $colour){
894   - $red = hexdec(substr($colour, 0, 2));
895   - $green = hexdec(substr($colour, 2, 2));
896   - $blue = hexdec(substr($colour, 4, 2));
897   -
898   - $classColour = imagecolorallocate($legend, $red, $green, $blue);
899   - imagefilledrectangle($legend, 21, $height-$ypos+2, $width+20, $height-$ypos-$interval, $classColour);
900   -
901   - //imagestring($legend, 3, $width+29, $height-$ypos-5, number_format($this->classBreaks[$key], $this->precision), $fontColour);
902   - imagestring($legend, 3, $width+29, $height-$ypos-5, number_format($this->classBreaks[$key], 2,",","."), $fontColour);
903   -
904   - $ypos += $interval;
905   - }
906   - //imagestring($legend, 3, $width+29, -3, number_format($this->classBreaks[$key+1], $this->precision), $fontColour);
907   - imagestring($legend, 3, $width+29, -3, number_format($this->classBreaks[$key+1], 2,",","."), $fontColour);
908   -
909   - }
910   -
911   - // Border around colour scale
912   - imagerectangle($legend, 19, 0, $width+22, $height+4, $white);
913   - imagerectangle($legend, 20, 1, $width+21, $height+3, $white);
914   -
915   - // Legend title
916   - //imagestringup($legend, 3, 0, ($height/2)+(strlen($this->mapTitle)/2)*7, $this->mapTitle, $white);
917   -
918   - // Save legend
919   - $file = $this->dirtmp.'/legend'. time() .'.png';
920   - imagepng($legend, $file);
921   -
922   - return $file;
923   - }
924   -
925   -
926   - function getSymbolSize($value, $geometry)
927   - {
928   - switch ($geometry) {
929   - case 'circle': // Returns radius of the circle
930   - case 'square': // Returns length of a side
931   - return sqrt($value/$this->maxValue)*$this->symbolMaxSize;
932   - case 'column': // Returns height of the column
933   - return ($value/$this->maxValue)*$this->symbolMaxSize;
934   - case 'sphere': // Returns radius of the sphere
935   - case 'cube': // Returns length of a side
936   - return pow($value/$this->maxValue, 1/3)*$this->symbolMaxSize;
937 738 }
938   - }
939   -
940   - function makeClasses($classification, $numClasses){
941   - $this->classBreaks = array();
942   -
943   - switch ($classification) {
944   -
945   - case 'equal':
946   - $interval = ($this->maxValue - $this->minValue) / $numClasses;
947   - for ($i = 0; $i < $numClasses; $i++) {
948   - $position = $this->minValue + ($interval * $i);
949   - $this->classBreaks[] = round($position, $this->precision);
950   - }
951   - $this->classBreaks[] = $this->maxValue; // Last class break = biggest value
952   - break;
953   -
954   - case 'quantile':
955   - $values = array_values($this->indicator['values'][$this->year]);
956   - sort($values);
957   - $numValues = count($values);
958   - $classNum = $numValues / $numClasses; // Number in each class
959   - for ($i = 0; $i < $numClasses; $i++) {
960   - $position = (int)($classNum * $i);
961   - $this->classBreaks[] = $values[$position];
962   - }
963   - $this->classBreaks[] = $values[$numValues-1]; // Last class break = biggest value
  739 +
  740 +
  741 + //
  742 + // Function
  743 + // @access protected
  744 + //
  745 + public function wkt2kml($wkt, $altitude)
  746 + {
  747 +
  748 + // Change coordinate format
  749 + $wkt = preg_replace("/([0-9\.\-]+) ([0-9\.\-]+),*/e", "round('$1',2).','.round('$2',2).',$altitude '", $wkt);
  750 +
  751 + $wkt = substr($wkt, 15); // Remove 'MULTIPOLYGON(((' at the beginning
  752 + $wkt = substr($wkt, 0, -3); // Remove ')))' at the end
  753 + $polygons = explode(')),((', $wkt); // Find all polygons
  754 + $kml = ' <MultiGeometry>' . PHP_EOL;
  755 +
  756 + foreach ($polygons as $polygon) {
  757 + $kml .= ' <Polygon>' . PHP_EOL;
  758 + $boundary = explode('),(', $polygon); // Find all polygon boundaries
  759 + $kml .= ' <outerBoundaryIs>' . PHP_EOL
  760 + . ' <LinearRing>' . PHP_EOL
  761 + . ' <coordinates>' . self::kmlReverseCoordinates($boundary[0]) . ' </coordinates>' . PHP_EOL
  762 + . ' </LinearRing>' . PHP_EOL
  763 + . ' </outerBoundaryIs>' . PHP_EOL;
  764 +
  765 + for ($i=1; $i < count($boundary); $i++) { // If inner boundaries
  766 + $kml .= ' <innerBoundaryIs>' . PHP_EOL
  767 + . ' <LinearRing>' . PHP_EOL
  768 + . ' <coordinates>' . self::kmlReverseCoordinates($boundary[$i]) . ' </coordinates>' . PHP_EOL
  769 + . ' </LinearRing>' . PHP_EOL
  770 + . ' </innerBoundaryIs>' . PHP_EOL;
  771 + }
  772 + $kml .= ' </Polygon>' . PHP_EOL;
  773 + }
  774 + $kml .= ' </MultiGeometry>' . PHP_EOL;
  775 +
  776 + if ($altitude)
  777 + {
  778 + $kml = str_replace('<Polygon>', '<Polygon><extrude>1</extrude><tessellate>1</tessellate><altitudeMode>absolute</altitudeMode>', $kml);
  779 + }
  780 +
  781 + return $kml;
  782 + }
  783 +
  784 + //
  785 + // Function
  786 + // @access protected
  787 + //
  788 + function kmlReverseCoordinates($coordinates)
  789 + {
  790 + $coordinates = explode(" ", $coordinates);
  791 + $coordinates = array_reverse($coordinates);
  792 + $coordinates = implode(" ", $coordinates);
  793 + return $coordinates;
  794 + }
  795 +
  796 + // Generates KML colour
  797 + function rgb2bgr($rgb)
  798 + {
  799 + $colour = dechex($this->kmlAlphaColour) . substr($rgb, -2) . substr($rgb, 2, 2) . substr($rgb, 0, 2);
  800 + return $colour;
  801 + }
  802 +
  803 + // Generates COLLADA colour
  804 + function rgb2collada($rgb)
  805 + {
  806 + $red = number_format(hexdec(substr($rgb, 0, 2)) / 255, 6);
  807 + $green = number_format(hexdec(substr($rgb, 2, 2)) / 255, 6);
  808 + $blue = number_format(hexdec(substr($rgb, -2)) / 255, 6);
  809 +
  810 + $colour = "$red $green $blue 1"; // Transparency not supported in GE?
  811 + return $colour;
  812 + }
  813 +
  814 +
  815 + // Generates a colour scale
  816 + function makeColourScale(){
  817 +
  818 + // Extract red/green/blue decimal values from hexadecimal colours
  819 + $this->startColourRGB = array(hexdec(substr($this->startColour, 0, 2)),
  820 + hexdec(substr($this->startColour, 2, 2)),
  821 + hexdec(substr($this->startColour, 4, 2)));
  822 +
  823 + $this->endColourRGB = array(hexdec(substr($this->endColour, 0, 2)),
  824 + hexdec(substr($this->endColour, 2, 2)),
  825 + hexdec(substr($this->endColour, 4, 2)));
  826 +
  827 + // Calculate the change value for red/green/blue
  828 + $this->deltaColourRGB = array($this->endColourRGB[0] - $this->startColourRGB[0],
  829 + $this->endColourRGB[1] - $this->startColourRGB[1],
  830 + $this->endColourRGB[2] - $this->startColourRGB[2]);
  831 + }
  832 +
  833 + function getColourValue($value, $format){
  834 + $red = $this->startColourRGB[0] + ($this->deltaColourRGB[0] / ($this->maxValue - $this->minValue)) * ($value - $this->minValue);
  835 + $green = $this->startColourRGB[1] + ($this->deltaColourRGB[1] / ($this->maxValue - $this->minValue)) * ($value - $this->minValue);
  836 + $blue = $this->startColourRGB[2] + ($this->deltaColourRGB[2] / ($this->maxValue - $this->minValue)) * ($value - $this->minValue);
  837 +
  838 + if ($format == 'kml') {
  839 + $colour = sprintf('%02X%02X%02X%02X', $this->kmlAlphaColour, $blue, $green, $red);
  840 + }
  841 + else { // Hex colour
  842 + $colour = sprintf('%02X%02X%02X', $red, $green, $blue);
  843 + }
  844 +
  845 + return $colour;
  846 + }
  847 +
  848 + function getColourLegend(){
  849 + $height = $this->colourLegendHeight;
  850 + $width = $this->colourLegendWidth;
  851 +
  852 + // Create colour scale canvas
  853 + $legend = imagecreatetruecolor(150, $height+6);
  854 +
  855 + // Allocate colours
  856 + $bgColour = imagecolorallocatealpha($legend, 255, 255, 255, 127);
  857 + $white = $fontColour = imagecolorallocate($legend, 255, 255, 255);
  858 + imageSaveAlpha($legend, true);
  859 +
  860 + // Set background colour
  861 + imagefill($legend, 0, 0, $bgColour);
  862 +
  863 + switch ($this->classification) {
  864 +
  865 + case 'unclassed':
  866 + for ($i = 0; $i <= $height; $i++) {
  867 + $red = intval($this->endColourRGB[0] - (($this->deltaColourRGB[0] / $height) * $i));
  868 + $green = intval($this->endColourRGB[1] - (($this->deltaColourRGB[1] / $height) * $i));
  869 + $blue = intval($this->endColourRGB[2] - (($this->deltaColourRGB[2] / $height) * $i));
  870 + $myColourScale[] = imagecolorallocate($legend, $red, $green, $blue);
  871 + }
  872 + // Draw colour scale
  873 + imagesetstyle($legend, $myColourScale);
  874 +
  875 + for ($i = 0; $i < $width; $i++) {
  876 + imageline($legend, 21+$i, 2, 21+$i, $height+2, IMG_COLOR_STYLED);
  877 + }
  878 +
  879 + // print min and max values
  880 + //number_format(($s / $ocorrencias),2,",",".")
  881 + //imagestring($legend, 3, $width+29, $height-6, number_format($this->minValue, $this->precision), $fontColour);
  882 + //imagestring($legend, 3, $width+29, -3, number_format($this->maxValue, $this->precision), $fontColour);
  883 + imagestring($legend, 3, $width+29, $height-6, number_format($this->minValue, 2,",","."), $fontColour);
  884 + imagestring($legend, 3, $width+29, -3, number_format($this->maxValue, 2,",","."), $fontColour);
  885 +
  886 + break;
  887 +
  888 + // classed (equal intervals / quantiles)
  889 + default:
  890 + $ypos = 0;
  891 + $interval = $height / $this->numClasses;
  892 + $v = $this->classColours;
  893 + foreach($v as $key => $colour){
  894 + $red = hexdec(substr($colour, 0, 2));
  895 + $green = hexdec(substr($colour, 2, 2));
  896 + $blue = hexdec(substr($colour, 4, 2));
  897 +
  898 + $classColour = imagecolorallocate($legend, $red, $green, $blue);
  899 + imagefilledrectangle($legend, 21, $height-$ypos+2, $width+20, $height-$ypos-$interval, $classColour);
  900 +
  901 + //imagestring($legend, 3, $width+29, $height-$ypos-5, number_format($this->classBreaks[$key], $this->precision), $fontColour);
  902 + imagestring($legend, 3, $width+29, $height-$ypos-5, number_format($this->classBreaks[$key], 2,",","."), $fontColour);
  903 +
  904 + $ypos += $interval;
  905 + }
  906 + //imagestring($legend, 3, $width+29, -3, number_format($this->classBreaks[$key+1], $this->precision), $fontColour);
  907 + imagestring($legend, 3, $width+29, -3, number_format($this->classBreaks[$key+1], 2,",","."), $fontColour);
  908 +
  909 + }
  910 +
  911 + // Border around colour scale
  912 + imagerectangle($legend, 19, 0, $width+22, $height+4, $white);
  913 + imagerectangle($legend, 20, 1, $width+21, $height+3, $white);
  914 +
  915 + // Legend title
  916 + //imagestringup($legend, 3, 0, ($height/2)+(strlen($this->mapTitle)/2)*7, $this->mapTitle, $white);
  917 +
  918 + // Save legend
  919 + $file = $this->dirtmp.'/legend'. time() .'.png';
  920 + imagepng($legend, $file);
  921 +
  922 + return $file;
  923 + }
  924 +
  925 +
  926 + function getSymbolSize($value, $geometry)
  927 + {
  928 + switch ($geometry) {
  929 + case 'circle': // Returns radius of the circle
  930 + case 'square': // Returns length of a side
  931 + return sqrt($value/$this->maxValue)*$this->symbolMaxSize;
  932 + case 'column': // Returns height of the column
  933 + return ($value/$this->maxValue)*$this->symbolMaxSize;
  934 + case 'sphere': // Returns radius of the sphere
  935 + case 'cube': // Returns length of a side
  936 + return pow($value/$this->maxValue, 1/3)*$this->symbolMaxSize;
  937 + }
  938 + }
  939 +
  940 + function makeClasses($classification, $numClasses){
  941 + $this->classBreaks = array();
  942 +
  943 + switch ($classification) {
  944 +
  945 + case 'equal':
  946 + $interval = ($this->maxValue - $this->minValue) / $numClasses;
  947 + for ($i = 0; $i < $numClasses; $i++) {
  948 + $position = $this->minValue + ($interval * $i);
  949 + $this->classBreaks[] = round($position, $this->precision);
  950 + }
  951 + $this->classBreaks[] = $this->maxValue; // Last class break = biggest value
  952 + break;
  953 +
  954 + case 'quantile':
  955 + $values = array_values($this->indicator['values'][$this->year]);
  956 + sort($values);
  957 + $numValues = count($values);
  958 + $classNum = $numValues / $numClasses; // Number in each class
  959 + for ($i = 0; $i < $numClasses; $i++) {
  960 + $position = (int)($classNum * $i);
  961 + $this->classBreaks[] = $values[$position];
  962 + }
  963 + $this->classBreaks[] = $values[$numValues-1]; // Last class break = biggest value
  964 + }
  965 +
  966 + // Make class colours (could be separate function)
  967 + for ($i = 0; $i < $numClasses; $i++) {
  968 + $red = (int)($this->startColourRGB[0] + ($this->deltaColourRGB[0] / ($numClasses - 1)) * $i);
  969 + $green = (int)($this->startColourRGB[1] + ($this->deltaColourRGB[1] / ($numClasses - 1)) * $i);
  970 + $blue = (int)($this->startColourRGB[2] + ($this->deltaColourRGB[2] / ($numClasses - 1)) * $i);
  971 +
  972 + $this->classColours[$i] = sprintf('%02X%02X%02X', $red, $green, $blue);
  973 + }
964 974 }
965 975  
966   - // Make class colours (could be separate function)
967   - for ($i = 0; $i < $numClasses; $i++) {
968   - $red = (int)($this->startColourRGB[0] + ($this->deltaColourRGB[0] / ($numClasses - 1)) * $i);
969   - $green = (int)($this->startColourRGB[1] + ($this->deltaColourRGB[1] / ($numClasses - 1)) * $i);
970   - $blue = (int)($this->startColourRGB[2] + ($this->deltaColourRGB[2] / ($numClasses - 1)) * $i);
971   -
972   - $this->classColours[$i] = sprintf('%02X%02X%02X', $red, $green, $blue);
973   - }
974   - }
975   -
976   -
977   - function getClass($value){
978   - $class = 0;
979   - //var_dump($this->classBreaks);exit;
980   - for ($i = 1; $i < count($this->classBreaks); $i++) {
981   - if ($value > $this->classBreaks[$i] && $value <= $this->classBreaks[$i+1]) {
982   - $class = $i;
983   - }
984   - }
985   - return $class;
986   - }
987   -
988   - function mapTitleImage(){
989   - $title = explode('|', wordwrap($this->mapTitle, 25, "|", true));
990   - $source = explode('|', wordwrap($this->mapSource, 25, "|", true));
991   -
992   - // Calculate text height (15px for each text line)
993   - $textSize = (count($title) + count($source)) * 15;
994   -
995   - // Create new legend canvas
996   - $legend = imagecreatetruecolor(200, 56 + $textSize);
997   -
998   - // Allocate colours
999   - $bgColour = imagecolorallocatealpha($legend, 255, 255, 255, 10);
1000   - $black = $fontColour = imagecolorallocate($legend, 0, 0, 0);
1001   - imageSaveAlpha($legend, true);
1002   -
1003   - // Set background colour
1004   - imagefill($legend, 0, 0, $bgColour);
1005   -
1006   - // Add logo
1007   - $legendTop = imagecreatefrompng($this->logo);
1008   - imagecopy($legend, $legendTop, 0, 0, 0, 0, 200, 30);
1009   -
1010   - // Print title
1011   - $ypos = 37;
1012   - foreach($title as $line){
1013   -
1014   - imagestring($legend, 3, 100-(strlen($line)*7)/2, $ypos, $line, $fontColour);
1015   - $ypos += 15;
1016   - }
1017   -
1018   - // Print source
1019   - foreach($source as $line){
1020   - $ypos += 15;
1021   - imagestring($legend, 2, 192-(strlen($line)*6), $ypos, $line, $fontColour);
1022   - }
1023   -
1024   - // Save legend
1025   - $file = $this->dirtmp.'/logo'. time() .'.png';
1026   - imagepng($legend, $file);
1027   -
1028   - return $file;
1029   - }
  976 +
  977 + function getClass($value){
  978 + $class = 0;
  979 + //var_dump($this->classBreaks);exit;
  980 + for ($i = 1; $i < count($this->classBreaks); $i++) {
  981 + if ($value > $this->classBreaks[$i] && $value <= $this->classBreaks[$i+1]) {
  982 + $class = $i;
  983 + }
  984 + }
  985 + return $class;
  986 + }
  987 +
  988 + function mapTitleImage(){
  989 + $title = explode('|', wordwrap($this->mapTitle, 25, "|", true));
  990 + $source = explode('|', wordwrap($this->mapSource, 25, "|", true));
  991 +
  992 + // Calculate text height (15px for each text line)
  993 + $textSize = (count($title) + count($source)) * 15;
  994 +
  995 + // Create new legend canvas
  996 + $legend = imagecreatetruecolor(200, 56 + $textSize);
  997 +
  998 + // Allocate colours
  999 + $bgColour = imagecolorallocatealpha($legend, 255, 255, 255, 10);
  1000 + $black = $fontColour = imagecolorallocate($legend, 0, 0, 0);
  1001 + imageSaveAlpha($legend, true);
  1002 +
  1003 + // Set background colour
  1004 + imagefill($legend, 0, 0, $bgColour);
  1005 +
  1006 + // Add logo
  1007 + $legendTop = imagecreatefrompng($this->logo);
  1008 + imagecopy($legend, $legendTop, 0, 0, 0, 0, 200, 30);
  1009 +
  1010 + // Print title
  1011 + $ypos = 37;
  1012 + foreach($title as $line){
  1013 +
  1014 + imagestring($legend, 3, 100-(strlen($line)*7)/2, $ypos, $line, $fontColour);
  1015 + $ypos += 15;
  1016 + }
  1017 +
  1018 + // Print source
  1019 + foreach($source as $line){
  1020 + $ypos += 15;
  1021 + imagestring($legend, 2, 192-(strlen($line)*6), $ypos, $line, $fontColour);
  1022 + }
  1023 +
  1024 + // Save legend
  1025 + $file = $this->dirtmp.'/logo'. time() .'.png';
  1026 + imagepng($legend, $file);
  1027 +
  1028 + return $file;
  1029 + }
1030 1030 } // class ThematicMap
1031 1031  
1032 1032  
... ...