Changeset 3199 for trunk/modules

Show
Ignore:
Timestamp:
07/23/2008 11:44:44 AM (4 months ago)
Author:
alexsancho
Message:

added marker options support to Gmap_Marker

Location:
trunk/modules/gmaps
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/gmaps/controllers/gmaps_demo.php

    r3193 r3199  
    2828 
    2929                // Add a new marker 
    30                 $map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>'); 
     30                $map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>', array('draggable' => true, 'bouncy' => true)); 
    3131 
    3232                View::factory('gmaps/api_demo')->set(array('api_url' => Gmap::api_url(), 'map' => $map->render()))->render(TRUE); 
  • trunk/modules/gmaps/libraries/Gmap.php

    r3195 r3199  
    280280         * @return object 
    281281         */ 
    282         public function add_marker($lat, $lon, $html = '') 
     282        public function add_marker($lat, $lon, $html = '', $options = array()) 
    283283        { 
    284284                // Add a new marker 
    285                 $this->markers[] = new Gmap_Marker($lat, $lon, $html); 
     285                $this->markers[] = new Gmap_Marker($lat, $lon, $html, $options); 
    286286 
    287287                return $this; 
  • trunk/modules/gmaps/libraries/Gmap_Marker.php

    r3145 r3199  
    99        public $latitude; 
    1010        public $longitude; 
     11         
     12        // Marker Options 
     13        protected $options = array(); 
     14        protected $valid_options = array 
     15        ( 
     16                'dragCrossMove', 
     17                'title', 
     18                'clickable', 
     19                'draggable', 
     20                'bouncy', 
     21                'bounceGravity', 
     22                'autoPan' 
     23        ); 
    1124 
    1225        /** 
     
    1831         * @return  void 
    1932         */ 
    20         public function __construct($lat, $lon, $html) 
     33        public function __construct($lat, $lon, $html, $options = array()) 
    2134        { 
    2235                if ( ! is_numeric($lat) OR ! is_numeric($lon)) 
     
    2942                // Set the info window HTML 
    3043                $this->html = $html; 
     44                 
     45                if (count($options) > 0) 
     46                { 
     47                        foreach ($options as $option => $value)  
     48                        { 
     49                                if (in_array($option, $this->valid_options, true)) 
     50                                        $this->options[$option] = $value; 
     51                        } 
     52                } 
    3153        } 
    3254 
     
    3759 
    3860                $output = array(); 
    39                 $output[] = 'var m = new google.maps.Marker(new google.maps.LatLng('.$this->latitude.', '.$this->longitude.'));'; 
     61                $output[] = 'var m = new google.maps.Marker(new google.maps.LatLng('.$this->latitude.', '.$this->longitude.'), '.json_encode($this->options).');'; 
    4062                if ($html = $this->html) 
    4163                {