// This program is free software; you can redistribute it and/or
// modify it under the terms of version 3 of the GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// http://www.gnu.org/licenses/
//
//
class ThematicMap
{
public $dataStore;
public $coordDecimals = 2;
public $engine = "";
public $logoline = "files/balloonlogo.png";
public $logo = 'files/logo.png';
// Parameters
public $mapType = 'choropleth'; // choropleth / prism / symbol
public $symbolType; // image / polygon // collada
public $symbolShape;
public $mapTitle;
public $mapDescription;
public $mapSource;
public $showTitle = true;
public $showLegend = true;
public $showValues = false;
public $showNames = false;
public $timeType = 'year'; // year / series / slider
public $maxHeight = 2000000; // Prism / Bar
public $symbolMaxSize; // Symbol$imgBrand
public $barSize = 50000;
public $maxValue;
public $minValue;
public $indicatorID;
public $indicator;
public $year;
private $yearArray;
// Colour parameters
public $colourType = 'scale'; // scale / single
public $startColour = 'FFFF99';
public $endColour = 'FF6600';
public $noDataColour = 'CCCCCC';
public $colour = 'FF6600';
public $opacity = 90;
public $classification = 'unclassed'; // unclassed / equal / quantile
public $numClasses = 5;
public $nomeArquivo = "";
public $nomeTemp = ""; //prefixo para as imagens
public $outlinecolor = "";
public $numvertices = "";
private $myColourScale; // Only choropleth/prism
private $startColourRGB; // Array
private $endColourRGB; // Array
private $deltaColour; // Array
private $kmlAlphaColour = 220;
private $colourLegendHeight = 350;
private $colourLegendWidth = 30;
private $symbolVertices = 30; // Circle
private $showLabel = false;
private $classBreaks; // Array
private $classColours; // Array
private $precision = 0; // Number of decimals
//
// Constructor
// @access protected
//
function __construct($dataStore, $paramArray, $nomeTemp = "")
{
$this->dataStore = $dataStore;
if($nomeTemp == ""){
$this->nomeTemp = time();
}else{
$this->nomeTemp = $nomeTemp;
}
// Mandatory parameters
$this->mapType = $paramArray['mapType']; // Mapping technique
$this->indicatorID = $paramArray['indicator']; // Main indicator
$this->year = $paramArray['year']; // Year
if(!isset($paramArray['outlinecolor']) || $paramArray['outlinecolor'] == "" || $paramArray['outlinecolor'] == "-1,-1,-1"){
$this->outlinecolor = "";
}
else{
$this->outlinecolor = $this->RGB2hex(explode(",",$paramArray['outlinecolor']));
}
$this->numvertices = $paramArray['numvertices'];
$this->dirtmp = $paramArray['dirtmp'];
// Extract indicator metadata and values from dataStore
if($dataStore != ""){
$this->indicator = $this->dataStore['indicators'][$this->indicatorID];
}
$this->minValue = $this->indicator['min'];
$this->maxValue = $this->indicator['max'];
$this->precision = $this->indicator['decimals'];
// Optional parameters: mapTitle, mapDescription and source
if (isset($paramArray['mapTitle'])) $this->mapTitle = $paramArray['mapTitle'];
else $this->mapTitle = $this->indicator['name']; // Use default from indicator
if (isset($paramArray['mapDescription'])) $this->mapDescription = $paramArray['mapDescription'];
else $this->mapDescription = $this->indicator['description']; // Use default from indicator
if (isset($paramArray['mapSource'])) $this->mapSource = $paramArray['mapSource'];
else {
//$this->mapSource = 'Statistics from ' . $this->indicator['source']; // Use default from indicator
}
// Other optional parameters
if (isset($paramArray['timeType'])) $this->timeType = $paramArray['timeType'];
if (isset($paramArray['showTitle'])) $this->showTitle = $paramArray['showTitle'];
if (isset($paramArray['showLegend'])) $this->showLegend = $paramArray['showLegend'];
if (isset($paramArray['colourType'])) $this->colourType = $paramArray['colourType'];
if (isset($paramArray['colour'])) $this->colour = $paramArray['colour'];
if (isset($paramArray['startColour'])) $this->startColour = $paramArray['startColour'];
if (isset($paramArray['endColour'])) $this->endColour = $paramArray['endColour'];
if (isset($paramArray['noDataColour'])) $this->noDataColour = $paramArray['noDataColour'];
if (isset($paramArray['showValues'])) $this->showValues = $paramArray['showValues'];
if (isset($paramArray['showNames'])) $this->showNames = $paramArray['showNames'];
if (isset($paramArray['symbolType'])) $this->symbolType = $paramArray['symbolType'];
if (isset($paramArray['symbolShape'])) $this->symbolShape = $paramArray['symbolShape'];
if (isset($paramArray['symbolMaxSize'])) $this->symbolMaxSize = $paramArray['symbolMaxSize'];
if (isset($paramArray['maxHeight'])) $this->maxHeight = $paramArray['maxHeight'];
if (isset($paramArray['barSize'])) $this->barSize = $paramArray['barSize'];
if (isset($paramArray['classification'])) $this->classification = $paramArray['classification'];
if (isset($paramArray['numClasses'])) $this->numClasses = $paramArray['numClasses'];
if ($this->showValues || $this->showNames) {
$this->showLabel = true;
}
if (isset($paramArray['opacity'])) {
$this->opacity = $paramArray['opacity'];
$this->kmlAlphaColour = 255 * $this->opacity / 100;
}
// Make an array of available years
if ($this->timeType != 'year') $this->yearArray = $this->indicator['years'];
else $this->yearArray = array($this->year); // Only one year
}
//
// Constructor
// @access protected
//
function __deconstruct()
{
// What goes here?
}
//
// Function
// @access protected
//
public function getKML($url,$download = false, $file = "")
{
// Create KMZ archieve
if($file == ""){
$file = $this->dirtmp."/tme". $this->nomeTemp. ".kmz";
}
$this->nomeArquivo = $file;
if(!file_exists($file)){
include(dirname(__FILE__)."/../kmlmapserver/classes/zip.class.php");
$zip = new zipfile();
// Add balloon logo to archieve (300 x 30 px)
$zip->addFile($this->logoline, 'files/balloonlogo.png');
// KML header
$kml = "" . PHP_EOL
. "" . PHP_EOL
. " " . PHP_EOL
. " " . PHP_EOL
. " Thematic Mapping Engine" . PHP_EOL
. " " . PHP_EOL
. " " . PHP_EOL
. " $this->mapTitle" . PHP_EOL
. " 1" . PHP_EOL
. " $this->mapSource" . PHP_EOL
. " mapDescription