Changeset 3191 for trunk/modules

Show
Ignore:
Timestamp:
07/22/2008 01:31:21 PM (4 months ago)
Author:
alexsancho
Message:

added default map type to center method

Files:
1 modified

Legend:

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

    r3181 r3191  
    7575 
    7676                // Load Cache 
    77                 ($cache === NULL) and $cache = Cache::instance(); 
    78  
     77                if ($cache === NULL)  
     78                { 
     79                        $cache = Cache::instance(); 
     80                } 
     81                 
    7982                // Address cache key 
    8083                $key = 'gmap-address-'.sha1($address); 
     
    119122         * @param mixed $lat latitude or an array of marker points 
    120123         * @param float $lon longitude 
    121          * @param integer $zoom zoom level (1-16) 
     124         * @param integer $zoom zoom level (1-19) 
    122125         * @param string $type map type (roadmap or mobile) 
    123126         * @param integer $width map width 
     
    172175        // Map types 
    173176        protected $types = array(); 
     177        protected $default_types = array 
     178        ( 
     179                'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP' 
     180        ); 
    174181 
    175182        // Map markers 
     
    196203         * @param float $lat latitude 
    197204         * @param float $lon longitude 
    198          * @param integer $zoom zoom level (1-16) 
    199          * @return object 
    200          */ 
    201         public function center($lat, $lon, $zoom = 6) 
    202         { 
    203                 // Set center location and zoom 
    204                 $this->center = array($lat, $lon, $zoom); 
     205         * @param integer $zoom zoom level (1-19) 
     206         * @param string $type default map type 
     207         * @return object 
     208         */ 
     209        public function center($lat, $lon, $zoom = 6, $type = 'G_NORMAL_MAP') 
     210        { 
     211                $zoom = min(0, max(19, abs($zoom))); 
     212                $type = ($type != 'G_NORMAL_MAP' AND in_array($type, $this->default_types, true)) ? $type : 'G_NORMAL_MAP'; 
     213 
     214                // Set center location, zoom and default map type 
     215                $this->center = array($lat, $lon, $zoom, $type); 
    205216 
    206217                return $this; 
     
    251262                $this->type_control = TRUE; 
    252263 
    253                 $types = array 
    254                 ( 
    255                         'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP' 
    256                 ); 
    257  
    258                 if ($type !== NULL and in_array($type, $types, true)) 
     264                if ($type !== NULL AND in_array($type, $this->default_types, true)) 
    259265                { 
    260266                        // Set the map type and action 
    261                         $this->types[$type] = (strtolower($action) === 'remove') ? 'remove' : 'add'; 
     267                        $this->types[$type] = (strtolower($action) == 'remove') ? 'remove' : 'add'; 
    262268                } 
    263269 
     
    290296        public function render($template = 'gmaps/javascript') 
    291297        { 
    292                 // Latitude, longitude, and zoom 
    293                 list ($lat, $lon, $zoom) = $this->center; 
     298                // Latitude, longitude, zoom and default map type 
     299                list ($lat, $lon, $zoom, $default_type) = $this->center; 
    294300 
    295301                // Map 
     
    315321 
    316322                // Map centering 
    317                 $center = 'map.setCenter(new google.maps.LatLng('.$lat.', '.$lon.'), '.$zoom.');'; 
     323                $center = 'map.setCenter(new google.maps.LatLng('.$lat.', '.$lon.'), '.$zoom.', '.$default_type.');'; 
    318324 
    319325                // Render the Javascript