Changeset 3156 for trunk/modules

Show
Ignore:
Timestamp:
07/19/2008 06:42:22 PM (5 months ago)
Author:
alexsancho
Message:

initial support to MapTypeControl?

Files:
1 modified

Legend:

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

    r3151 r3156  
    1515         * Retrieves the latitude and longitude of an address. 
    1616         * 
    17          * @param   string address 
    18          * @return  array  longitude, latitude 
     17         * @param string $address address 
     18         * @return array longitude, latitude 
    1919         */ 
    2020        public static function address_to_ll($address) 
     
    3737         * ! Results of this method are cached for 1 day. 
    3838         * 
    39          * @param   string adress 
    40          * @return  object SimpleXML 
     39         * @param string $address adress 
     40         * @return object SimpleXML 
    4141         */ 
    4242        public static function address_to_xml($address) 
     
    5757                else 
    5858                { 
    59                         // Get the API key 
    60                         $api_key = Config::item('gmaps.api_key'); 
    61  
    62                         // Send the address URL encoded 
    63                         $addresss = rawurlencode($address); 
    64  
    6559                        // Disable error reporting while fetching the feed 
    6660                        $ER = error_reporting(~E_NOTICE); 
     
    7266                                '&output=xml'. 
    7367                                '&oe=utf-8'. 
    74                                 '&key='.$api_key. 
    75                                 '&q='.rawurlencode($address) 
     68                                '&key='.Config::item('gmaps.api_key'). // Get the API key 
     69                                '&q='.rawurlencode($address) // Send the address URL encoded 
    7670                        ); 
    7771 
     
    9791         * Returns an image map 
    9892         * 
    99          * @param   mixed $lat latitude or an array of marker points 
    100          * @param       float $lon longitude 
    101          * @param       integer $zoom zoom level (1-16) 
    102          * @param       string $type map type (roadmap or mobile) 
    103          * @param       integer $width map width 
    104          * @param       integer $height map height 
    105          * @return  string 
     93         * @param mixed $lat latitude or an array of marker points 
     94         * @param float $lon longitude 
     95         * @param integer $zoom zoom level (1-16) 
     96         * @param string $type map type (roadmap or mobile) 
     97         * @param integer $width map width 
     98         * @param integer $height map height 
     99         * @return string 
    106100         */ 
    107101        public static function static_map($lat = 0, $lon = 0, $zoom = 6, $type = 'roadmap', $width = 300, $height = 300) 
     
    142136        protected $center; 
    143137        protected $control; 
     138        protected $type_control = FALSE; 
     139         
     140        // Map types 
     141        protected $types = array(); 
    144142 
    145143        // Map markers 
     
    149147         * Set the GMap center point. 
    150148         * 
    151          * @param   string HTML map id attribute 
    152          * @param   array  array of GMap constructor options 
    153          * @return  void 
     149         * @param string $id HTML map id attribute 
     150         * @param array $options array of GMap constructor options 
     151         * @return void 
    154152         */ 
    155153        public function __construct($id = 'map', $options = NULL) 
     
    163161         * Return GMap javascript url 
    164162         *  
    165          * 
    166163         * @return string 
    167164         */ 
     
    175172         * 
    176173         * @chainable 
    177          * @param   float    latitude 
    178          * @param   float    longitude 
    179          * @param   integer zoom level (1-16) 
    180          * @return  object 
     174         * @param float $lat latitude 
     175         * @param float $lon longitude 
     176         * @param integer $zoom zoom level (1-16) 
     177         * @return object 
    181178         */ 
    182179        public function center($lat, $lon, $zoom = 6) 
     
    192189         * 
    193190         * @chainable 
    194          * @param   string  small or large 
    195          * @return  object 
     191         * @param string $size small or large 
     192         * @return object 
    196193         */ 
    197194        public function controls($size = NULL) 
     
    202199                return $this; 
    203200        } 
     201         
     202        /** 
     203         * Set the GMap type controls. 
     204         * by default renders G_NORMAL_MAP, G_SATELLITE_MAP, and G_HYBRID_MAP 
     205         * 
     206         * @chainable 
     207         * @param string $type map type 
     208         * @param string $action add or remove map type 
     209         * @return object 
     210         */ 
     211        public function types($type = NULL, $action = 'remove') 
     212        { 
     213                $this->type_control = TRUE; 
     214                 
     215                $types = array 
     216                ( 
     217                        'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP' 
     218                ); 
     219                 
     220                if ($type !== NULL and in_array($type, $types, true)) 
     221                { 
     222                        // Set the map type and action 
     223                        $this->types[$type] = (strtolower($action) === 'remove') ? 'remove' : 'add'; 
     224                } 
     225                 
     226                return $this; 
     227        } 
    204228 
    205229        /** 
     
    207231         * 
    208232         * @chainable 
    209          * @param   float  $lat latitude 
    210          * @param   float  $lon longitude 
    211          * @param   string $html HTML for info window 
    212          * @return  object 
     233         * @param float $lat latitude 
     234         * @param float $lon longitude 
     235         * @param string $html HTML for info window 
     236         * @return object 
    213237         */ 
    214238        public function add_marker($lat, $lon, $html = '') 
     
    224248         * 
    225249         * @param string $template template name 
    226          * @return  string 
     250         * @return string 
    227251         */ 
    228252        public function render($template = 'gmaps/javascript') 
     
    233257                // Map 
    234258                $map = 'var map = new google.maps.Map2(document.getElementById("'.$this->id.'"));'; 
    235  
     259                 
    236260                // Map controls 
    237261                $controls = empty($this->control) ? '' : 'map.addControl(new google.maps.'.$this->control.'MapControl());'; 
     262 
     263                // Map Types 
     264                if ($this->type_control === TRUE) 
     265                { 
     266                        if (count($this->types) > 0)  
     267                        { 
     268                                foreach($this->types as $type => $action) 
     269                                        $controls .= 'map.'.$action.'MapType('.$type.');'; 
     270                        } 
     271                         
     272                        $controls .= 'map.addControl(new google.maps.MapTypeControl());'; 
     273                } 
    238274 
    239275                // Map centering