Changeset 3206

Show
Ignore:
Timestamp:
07/25/2008 08:29:59 AM (4 months ago)
Author:
alexsancho
Message:

added initial support for custom icons

Location:
trunk/modules/gmaps
Files:
1 added
4 modified

Legend:

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

    r3199 r3206  
    2626                // Set the map center point 
    2727                $map->center(0, 0, 1)->controls('large')->types('G_PHYSICAL_MAP', 'add'); 
     28                 
     29                // Add a custom marker icon 
     30            $map->add_icon('tinyIcon', array 
     31            ( 
     32                        'image' => 'http://labs.google.com/ridefinder/images/mm_20_red.png', 
     33                        'shadow' => 'http://labs.google.com/ridefinder/images/mm_20_shadow.png', 
     34                        'iconSize' => array('12', '20'), 
     35                        'shadowSize' => array('22', '20'), 
     36                        'iconAnchor' => array('6', '20'), 
     37                        'infoWindowAnchor' => array('5', '1') 
     38            )); 
    2839 
    2940                // Add a new marker 
    30                 $map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>', array('draggable' => true, 'bouncy' => true)); 
     41                $map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>', array('icon' => 'tinyIcon', 'draggable' => true, 'bouncy' => true)); 
    3142 
    3243                View::factory('gmaps/api_demo')->set(array('api_url' => Gmap::api_url(), 'map' => $map->render()))->render(TRUE); 
     
    5667                        // Add a new marker 
    5768                        $map->add_marker($location->lat, $location->lon, 
    58                                 // Get the info window HTML 
    59                                 View::factory('gmaps/info_window')->bind('location', $location)->render()); 
     69                         
     70                        // Get the info window HTML 
     71                        View::factory('gmaps/info_window')->bind('location', $location)->render()); 
    6072                } 
    6173 
  • trunk/modules/gmaps/libraries/Gmap.php

    r3199 r3206  
    179179                'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP' 
    180180        ); 
     181         
     182        // Markers icons 
     183        protected $icons = array(); 
    181184 
    182185        // Map markers 
     
    269272 
    270273                return $this; 
     274        } 
     275         
     276        /** 
     277         * Create a custom marker icon 
     278         * 
     279         * @chainable 
     280         * @param string $name icon name 
     281         * @param array $options icon options 
     282         * @return object 
     283         */ 
     284        public function add_icon($name, array $options) 
     285        { 
     286            // Add a new cusotm icon 
     287            $this->icons[] = new Gmap_Icon($name, $options); 
     288             
     289            return $this; 
    271290        } 
    272291 
     
    330349                                'controls' => implode("\n", $controls), 
    331350                                'center' => $center, 
     351                                'icons' => $this->icons, 
    332352                                'markers' => $this->markers, 
    333353                        )) 
  • trunk/modules/gmaps/libraries/Gmap_Marker.php

    r3204 r3206  
    1717        protected $valid_options = array 
    1818        ( 
     19                'icon', 
    1920                'dragCrossMove', 
    2021                'title', 
     
    5354                                // Set marker options 
    5455                                if (in_array($option, $this->valid_options, true)) 
    55                                         $this->options[$option] = $value; 
     56                                        $this->options[] = "$option:$value"; 
    5657                        } 
    5758                } 
     
    6667                $marker = 'm'.++self::$id; 
    6768 
    68                 $output[] = 'var '.$marker.' = new google.maps.Marker(new google.maps.LatLng('.$this->latitude.', '.$this->longitude.'), '.json_encode($this->options).');'; 
     69                $output[] = 'var '.$marker.' = new google.maps.Marker(new google.maps.LatLng('.$this->latitude.', '.$this->longitude.'), {'.implode(",", $this->options).'});'; 
    6970                if ($html = $this->html) 
    7071                { 
  • trunk/modules/gmaps/views/gmaps/javascript.php

    r3163 r3206  
    77        <?php echo $center, "\n" ?> 
    88        <?php echo $options->render(1), "\n" ?> 
     9         
     10        // Build custom marker icons 
     11        <?php foreach($icons as $icon): ?> 
     12        <?php echo $icon->render(1), "\n" ?> 
     13        <?php endforeach ?> 
    914 
    1015        // Show map points 
    11         <?php foreach ($markers as $marker): ?> 
     16        <?php foreach($markers as $marker): ?> 
    1217        <?php echo $marker->render(1), "\n" ?> 
    1318        <?php endforeach ?>