Changeset 2158 for trunk/modules/gmaps/libraries/Gmap_Marker.php
- Timestamp:
- 02/23/2008 01:41:41 PM (9 months ago)
- Files:
-
- 1 modified
-
trunk/modules/gmaps/libraries/Gmap_Marker.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/gmaps/libraries/Gmap_Marker.php
r2084 r2158 6 6 public $html; 7 7 8 // Address9 public $address;10 11 8 // Latitude and longitude 12 9 public $latitude; 13 10 public $longitude; 14 11 15 public function __construct($lon, $lat) 12 /** 13 * Create a new GMap marker. 14 * 15 * @param float latitude 16 * @param float longitude 17 * @param string HTML of info window 18 * @return void 19 */ 20 public function __construct($lat, $lon, $html) 16 21 { 17 22 if ( ! is_numeric($lat) OR ! is_numeric($lon)) 18 23 throw new Kohana_Exception('gmaps.invalid_marker', $lat, $lon); 19 24 20 //http://maps.google.com/?q=South+Africa&ie=UTF8&ll=-32.175612,21.42334&spn=5.503756,11.260986&t=h&z=7 25 // Set the latitude and longitude 26 $this->latitude = $lat; 27 $this->longitude = $lon; 21 28 22 $this->longitude = ($lon < 0) ? min(0, max($lon, -90)) : min(90, max($lon, 0));23 $this-> latitude = ($lat < 0) ? min(0, max($lat, -180)) : min(180, max($lat, 0));29 // Set the info window HTML 30 $this->html = $html; 24 31 } 25 32 26 public function __get($key)33 public function render($tabs = 0) 27 34 { 28 if ($key === 'lat' OR $key === 'latitude') 35 // Create the tabs 36 $tabs = empty($tabs) ? '' : str_repeat("\t", $tabs); 37 38 $output = array(); 39 $output[] = 'var m = new GMarker(new GLatLng('.$this->latitude.', '.$this->longitude.'));'; 40 if ($html = $this->html) 29 41 { 30 return $this->latitude; 42 $output[] = 'GEvent.addListener(m, "click", function()'; 43 $output[] = '{'; 44 $output[] = "\t".'m.openInfoWindowHtml('; 45 $output[] = "\t\t'".implode("'+\n\t\t$tabs'", explode("\n", $html))."'"; 46 $output[] = "\t);"; 47 $output[] = '});'; 31 48 } 32 elseif ($key === 'lon' OR $key === 'longitude') 33 { 34 return $this->longitude; 35 } 49 $output[] = 'map.addOverlay(m);'; 36 50 37 return NULL; 38 } 39 40 public function __set($key, $value) 41 { 42 51 return implode("\n".$tabs, $output); 43 52 } 44 53
