<?php

/**
 * Geolocalization
 *
 * @author Arkadiusz Rychlik <a.rychlik at eppe.com.pl>
 */
class Eppe_View_Helper_Geolocalization extends Zend_View_Helper_Abstract {

	/**
	 * Wyświetla mape google
	 * @param array $data cz: center zoom, cd+ce: center point, md+me: marker point
	 * @param int $width
	 * @param int $height
	 * @return string HTML + Js 
	 */
	public function geolocalization($data,$width=188,$height=290) {
		$uid = uniqid();
		
		$html = <<<EOF

			<script>
			
				var createGeolocalization$uid = function(){
					var gmaps$uid = {
						map: null,

						mapOptions: {
							zoom: {$data['cz']},
							center: new google.maps.LatLng({$data['cd']}, {$data['ce']}),
							mapTypeId: google.maps.MapTypeId.TERRAIN
						},

						init: function(){
							gmaps$uid.map = new google.maps.Map(document.getElementById('map-canvas$uid'),gmaps$uid.mapOptions);
							new google.maps.Marker({
								map: gmaps$uid.map,
								position: new google.maps.LatLng({$data['md']}, {$data['me']})
							});
						}
					};
					gmaps$uid.init();
				};
									
			$(function(){
			
				if(typeof google != "undefined" && typeof google.maps != "undefined"){
					createGeolocalization$uid();
				}
				else{
					$.getScript("https://maps.googleapis.com/maps/api/js?sensor=false&callback=createGeolocalization$uid", function() {
					});
				}
							
			});
			
			</script>
				
			<div id="map-canvas$uid" style="width:{$width}px;height:{$height}px;"></div>
EOF;
		return $html;
	}
	
}
