Location: PHPKode > scripts > GPX Mapper & CMS > gpx-mapper-cms/cls.svgDrawer.php
<?

/*		
	GPX Drawer
	Version: 1.0 
	Author: David Boardman
	URL: http://www.netzfunk.org/?usr=d
	Licenced under Creative Commons Attribution-NonCommercial-ShareAlike 2.5

	If redistributed in any form, please include credits and a link to http://www.netzfunk.org/?usr=d
*/

include("cls.gpxDrawer.php");

class svgDrawer extends gpxDrawer{

	var $xml;
	var $mapwidth;
	var $mapheight;
	var $path;
	var $mapname;
	var $scale;
	var $svg;
	var $pixelfact;
	var $config;
	
	function svgDrawer($config,$mapwidth,$mapheight,$mapname,$path,$xmlfile,$scale){
		$this->mapscale=$scale;
		$this->pixelfact=2817.947378;
		$this->xml=$xmlfile;
		$this->path=$path;
		$this->mapname=$mapname;
		$this->mapwidth=$mapwidth;
		$this->mapheight=$mapheight;
		$this->svg="";
		$this->config=$config;
	}

	function headerSVG(){
		$this->svg.="<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \n \"http://www.w3.org/TR/SVG/DTD/svg10.dtd\">\n";
		$this->svg.="<svg width=\"".$this->mapwidth."px\" height=\"".$this->mapheight."px\" viewBox=\"0 0 ".$this->mapwidth." ".$this->mapheight."\"\n preserveAspectRatio=\"xMinYMin\" xmlns=\"http://www.w3.org/2000/svg\">\n";
		$this->svg.="<title>GPX SVG MAPPER</title>\n<desc>GPX SVG MAPPER</desc>\n";
		$this->svg.="<rect x=\"0px\" y=\"0\" width=\"".($this->mapwidth+100)."\" height=\"".($this->mapheight+100)."\" style=\"fill:none; stroke:black;stroke-width:2\"/>";
	}

	function svgPath($img,$pos){
		for($i=0;$i<count($pos);$i++){
			if(($pos[$i]['x'] < $this->mapwidth) && ($pos[$i]['y'] < $this->mapheight)){
				$offset_x=$pos[$i]['x'];
				$offset_y=$pos[$i]['y'];
			if((($offset_x2!="")&&($offset_y2!=""))||(($offset_x2!=0)&&($offset_y2!=0))){
				 $this->svg.="<path id=\"$i\" d=\"M $offset_x $offset_y  L $offset_x2 $offset_y2 Z\" style=\"fill:red;fill-opacity:0.4;stroke-opacity:0.7\" stroke=\"black\" stroke-width=\"2\" />\n"; 
			}
			else {
				$this->svg.="<rect x=\"".($offset_x-5)."px\" y=\"".($offset_y-5)."\" width=\"14\" height=\"14\" style=\"fill:blue;\"/>\n<text x=\"".($offset_x)."\" y=\"".($offset_y+20)."\" align=\"center\" style=\"font-family:arial;font-size:12px;font-weight:bold;color:black;letter-spacing:0px;\" text-anchor=\"middle\">START</text>\n";
				}
			$offset_x2=$offset_x;
			$offset_y2=$offset_y;
			if($i==count($pos)-1){
				$this->svg.="<rect x=\"".($offset_x-5)."px\" y=\"".($offset_y-5)."\" width=\"14\" height=\"14\" style=\"fill:green;\"/>\n<text x=\"".($offset_x)."\" y=\"".($offset_y+20)."\" align=\"center\" style=\"font-family:arial;font-size:12px;font-weight:bold;color:black;letter-spacing:0px;\" text-anchor=\"middle\">END</text>\n";
				}									
			}
		}
	}

	function svgPOI($img,$pos,$link,$title,$r){  // (img mappa,x/y,link poi,titolo poi,raggio) DISEGNO WAYPOINTS (WPT)
		for($i=0;$i<count($pos);$i++){
			$x[]=$pos[$i]['x'];
			$y[]=$pos[$i]['y'];
			$this->svg.="<circle cx=\"".$pos[$i]['x']."\" cy=\"".$pos[$i]['y']."\" r=\"".$r[$i]."\" style=\"fill:none; stroke:red;stroke-width:5\"/>\n";
			$this->svg.="<a xlink:href=\"".$link[$i]."\"><text x=\"".$pos[$i]['x']."\" y=\"".($pos[$i]['y']-5)."\" align=\"center\" style=\"font-family:'cronos display';font-size:11px;color:black;letter-spacing:1px;\" text-anchor=\"middle\">".$title[$i]."</text></a>\n";
		}
	}

	function svgMap(){
		$this->headerSVG();
		$center=$this->getMapCenter();
		$mapscalepixfact=$this->mapscale / $this->pixelfact;
		
		for($i=0;$i<count($this->trkpt);$i++){ // TRACKPOINTS
			$p[$i]=$this->calcxy($this->trkpt[$i]['lat'],$this->trkpt[$i]['lon'],$mapscalepixfact,$center['lat'],$center['lon']);
			}
		for($i=0;$i<count($this->wpt);$i++){ // WAYPOINTS
			$w[$i]=$this->calcxy($this->wpt[$i]['lat'],$this->wpt[$i]['lon'],$mapscalepixfact,$center['lat'],$center['lon']);
			$l[$i]=$this->wpt[$i]['link'];
			$t[$i]=$this->wpt[$i]['cmt'];
			$ray=explode("|",$this->wpt[$i]['desc']);
			$r[$i]=$this->calcRay($ray[0],$ray[1],$ray[2]); // calcola raggio WPTS
		}
		$this->svgPOI($map,$w,$l,$t,$r);  //(mappa,x/y,link,titolo,raggio)
		$this->svgPath($map,$p);
	}

	function saveSVG(){
		if(!is_writable($this->path)){
			exit("Check permissions on \"".$this->path."\" directory.");
		}
		$this->svg.="</svg>";
		$filename=$this->path."/".$this->mapname.".php";
		$this->nome_arq = $filename; 
			
		$this->myfile = @fopen($this->nome_arq, "w+"); // apro il file specificato
		if (!$this->myfile){
		  echo "Operazione non valida.";
		}
		else{
			fputs($this->myfile,$this->svg); //inserisco i dati estratti
			fclose($this->myfile); // chiudo il file
		}
	}
	
	function gotoSVG(){
		header("location:".$this->config['svgfolder']."/_svgViewer.php?svg=".$this->mapname."");
	}

}
?>
Return current item: GPX Mapper & CMS