Show
Ignore:
Timestamp:
02/23/2008 01:41:41 PM (9 months ago)
Author:
Shadowhand
Message:

Hooray! Gmaps module in a working (but early) form!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/gmaps/libraries/Gmap_Marker.php

    r2084 r2158  
    66        public $html; 
    77 
    8         // Address 
    9         public $address; 
    10  
    118        // Latitude and longitude 
    129        public $latitude; 
    1310        public $longitude; 
    1411 
    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) 
    1621        { 
    1722                if ( ! is_numeric($lat) OR ! is_numeric($lon)) 
    1823                        throw new Kohana_Exception('gmaps.invalid_marker', $lat, $lon); 
    1924 
    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; 
    2128 
    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; 
    2431        } 
    2532 
    26         public function __get($key) 
     33        public function render($tabs = 0) 
    2734        { 
    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) 
    2941                { 
    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[] = '});'; 
    3148                } 
    32                 elseif ($key === 'lon' OR $key === 'longitude') 
    33                 { 
    34                         return $this->longitude; 
    35                 } 
     49                $output[] = 'map.addOverlay(m);'; 
    3650 
    37                 return NULL; 
    38         } 
    39  
    40         public function __set($key, $value) 
    41         { 
    42                  
     51                return implode("\n".$tabs, $output); 
    4352        } 
    4453