$max_width ) $width = $max_width ; $height = 200; $max_height = 600; if (isset($_GET['height'])) $height = $_GET['height']; if ($height > $max_height) $height = $max_height; class WmsMapObject //mapobject class simulation { var $x1, $y1, $x2, $y2; var $png; function RequestMap($kijs, $x,$y, $w,$h, $zoom) { if ( $zoom<1 || $zoom>15 ) $zoom = 3; //default $mpx[15] = 6007.47872745750; //layer scales $mpx[14] = 3003.73936372870; $mpx[13] = 1501.86954957240; $mpx[12] = 750.934774786220; $mpx[11] = 375.467519685040; $mpx[10] = 187.733627550590; $mpx[ 9] = 93.8669460672250; $mpx[ 8] = 46.9334730336130; $mpx[ 7] = 23.4667365168060; $mpx[ 6] = 11.7332359664720; $mpx[ 5] = 5.86661798323600; $mpx[ 4] = 2.93344128354920; $mpx[ 3] = 1.46658834984340; $mpx[ 2] = 0.73342646685293; $mpx[ 1] = 0.36671323342647; $this->x1 = ( $x-($w/2*$mpx[$zoom]) ); //bounding box $this->y1 = ( $y+($h/2*$mpx[$zoom]) ); $this->x2 = ( $x+($w/2*$mpx[$zoom]) ); $this->y2 = ( $y-($h/2*$mpx[$zoom]) ); $bbox = ($this->x1).','.($this->y2-6000000).','.($this->x2).','.($this->y1-6000000); $url = 'http://wms.kartes.lv/'.$kijs.'/lks/15/?BBOX='.$bbox.'&WIDTH='.$w.'&HEIGHT='.$h.'&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap'; //wms string //echo $url; //exit(); //$url = 'http://maps.kartes.lv/kijs/wms/get_wms.php?kijs='.$kijs.'&name=lks&v=15&BBOX='.$bbox.'&WIDTH='.$w.'&HEIGHT='.$h.'&KIJS='.$kijs.'&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap'; //wms string $contents = $this->curl_get_contents($url); $this->png = imagecreatefromstring($contents); return ($this->png !== false); } function Png2Gif($png) { ob_start(); imagegif($png); //convert png -> gif $str_gif = ob_get_contents(); ob_end_clean(); return $str_gif; } function curl_get_contents($url) { $handle = curl_init(); curl_setopt($handle, CURLOPT_URL, $url); curl_setopt($handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1'); curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($handle); curl_close($handle); return $data; } } if ( !isset($_GET['objx'], $_GET['objy']) ) Error($width, $height, "Nav padotas objekta x un y koordinātes."); else { $objx = $_GET['objx']; $objy = $_GET['objy']; if ( isset($_GET['centx' ]) ) $centx = $_GET['centx' ]; else $centx = $_GET['objx']; if ( isset($_GET['centy' ]) ) $centy = $_GET['centy' ]; else $centy = $_GET['objy']; if ( isset($_GET['zoom' ]) ) $zoom = $_GET['zoom' ]; else $zoom = -1; if ( isset($_GET['logo' ]) ) $logo_file = $_GET['logo' ]; else $logo_file = 'logo.gif'; if ( isset($_GET['format']) ) $format = $_GET['format']; else $format = 'gif'; $map_obj = new WmsMapObject(); $res = $map_obj->RequestMap($kijs, $centx, $centy, $width, $height, $zoom); if ( $res == false ) Error($width, $height, "Kļūda pieprasot kartes apgabalu."); else { // uzliekam pa virsu logo $im = $map_obj->png; $im_logo = imagecreatefromstring( file_get_contents($logo_file) ); //gif,png,jpg if ( $im_logo === false ) Error($width, $height, "Neizdevās izveidot logo '$logo_file'."); else { $logo_width = imagesx ($im_logo); // dabūnam logo dimensijas $logo_height = imagesy ($im_logo); include_once("funkcijas.php"); if ( $obj_koord_mas = FromMetersToPixels($map_obj->x1, $map_obj->x2, $map_obj->y1, $map_obj->y2, $width, $height, $objx, $objy) ) // aprēķinam bildes atrašānās vietu { $lx = $obj_koord_mas[0]-$logo_width /2; $ly = $obj_koord_mas[1]-$logo_height/2; if ( !imagecopy($im, $im_logo, $lx, $ly, 0, 0, $logo_width, $logo_height) ) Error($width, $height, "Neizdevās uzlikt logo."); else { if ( $format != 'png' ) imagegif($im); else { header("Content-Type: image/png"); imagepng($im); } } } else { Error($width, $height, "Neizdevās pārvērst metrus punktos."); } imagedestroy($im_logo); } imagedestroy($im); } } ?>