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