Changeset 3145 for trunk/modules

Show
Ignore:
Timestamp:
07/17/2008 12:31:03 PM (5 months ago)
Author:
alexsancho
Message:

Some cleaning and minor changes

Location:
trunk/modules/gmaps
Files:
7 added
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/gmaps/config/gmaps.php

    r2207 r3145  
    55 * This API key is usable for http://localhost/* 
    66 */ 
     7 
    78$config['api_key'] = 'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA'; 
  • trunk/modules/gmaps/controllers/gmaps_demo.php

    r2317 r3145  
    1818        public function index() 
    1919        { 
    20                 $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap'); 
    21  
    2220                // Create a new Gmap 
    23                 $map = new Gmap('map'); 
     21                $map = new Gmap('map', array 
     22                ( 
     23                        'ScrollWheelZoom' => TRUE, 
     24                )); 
    2425 
    2526                // Set the map center point 
     
    2930                $map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>'); 
    3031 
    31                 View::factory('gmaps/api_demo')->set('map', $map->render())->render(TRUE); 
     32                View::factory('gmaps/api_demo')->set(array('api_url' => $map->api_uri(), 'map' => $map->render()))->render(TRUE); 
    3233        } 
    3334 
    3435        public function azmap() 
    3536        { 
    36                 $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap'); 
    37  
    3837                // Create a new Gmap 
    3938                $map = new Gmap('map', array 
     
    119118        public function jquery() 
    120119        { 
    121                 View::factory('gmaps/jquery')->render(TRUE); 
     120                $map = new Gmap('map'); 
     121                 
     122                $map->center(0, 35, 16)->controls('large'); 
     123 
     124                View::factory('gmaps/jquery')->set(array('api_url' => $map->api_uri(), 'map' => $map->render('gmaps/jquery_javascript')))->render(TRUE); 
    122125        } 
    123126 
    124127        public function xml() 
    125128        { 
    126                 $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap'); 
    127  
    128129                // Get all locations 
    129130                $locations = ORM::factory('location')->find_all(); 
     
    137138                        $node = $xml->addChild('marker'); 
    138139 
    139                         // Set the latitutde and longitude 
    140                         $node->addAttribute('lon', $location->lon); 
    141                         $node->addAttribute('lat', $location->lat); 
     140                        // Set the latitude and longitude 
     141                        $node->addAttribute('lon', sprintf('%F', $location->lon)); 
     142                        $node->addAttribute('lat', sprintf('%F', $location->lat)); 
    142143 
    143144                        $node->html = View::factory('gmaps/xml')->bind('location', $location)->render(); 
  • trunk/modules/gmaps/libraries/Gmap.php

    r3126 r3145  
    101101 
    102102        // Map markers 
    103         protected $markers; 
     103        protected $markers = array(); 
    104104 
    105105        /** 
     
    116116                $this->options = new Gmap_Options((array) $options); 
    117117        } 
     118         
     119        /** 
     120         * Return GMap javascript url 
     121         *  
     122         * 
     123         * @return string 
     124         */ 
     125         public function api_uri() 
     126         { 
     127            return 'http://www.google.com/jsapi?key='.Config::item('gmaps.api_key'); 
     128         } 
    118129 
    119130        /** 
     
    144155        { 
    145156                // Set the control type 
    146                 $this->controls = (strtolower($size) === 'small') ? 'Small' : 'Large'; 
     157                $this->control = (strtolower($size) === 'small') ? 'Small' : 'Large'; 
    147158 
    148159                return $this; 
     
    153164         * 
    154165         * @chainable 
    155          * @param   float   latitude 
    156          * @param   float   longitude 
    157          * @param   string  HTML for info window 
     166         * @param   float   $lat latitude 
     167         * @param   float   $lon longitude 
     168         * @param   string  $html HTML for info window 
    158169         * @return  object 
    159170         */ 
     
    169180         * Render the map into GMap Javascript. 
    170181         * 
     182         * @param string $template template name 
    171183         * @return  string 
    172184         */ 
    173         public function render() 
     185        public function render($template = 'gmaps/javascript') 
    174186        { 
    175187                // Latitude, longitude, and zoom 
     
    177189 
    178190                // Map 
    179                 $map = 'var map = new GMap2(document.getElementById("'.$this->id.'"));'; 
     191                $map = 'var map = new google.maps.Map2(document.getElementById("'.$this->id.'"));'; 
    180192 
    181193                // Map controls 
    182                 $controls = empty($this->controls) ? '' : 'map.addControl(new G'.$this->controls.'MapControl());'; 
     194                $controls = empty($this->control) ? '' : 'map.addControl(new google.maps.'.$this->control.'MapControl());'; 
    183195 
    184196                // Map centering 
    185                 $center = 'map.setCenter(new GLatLng('.$lat.', '.$lon.'));'; 
    186  
    187                 // Map zoom 
    188                 $zoom = 'map.setZoom('.$zoom.');'; 
     197                $center = 'map.setCenter(new google.maps.LatLng('.$lat.', '.$lon.'), '.$zoom.');'; 
    189198 
    190199                // Render the Javascript 
    191                 return View::factory('gmaps/javascript', array 
     200                return View::factory($template, array 
    192201                        ( 
    193202                                'map' => $map, 
     
    195204                                'controls' => $controls, 
    196205                                'center' => $center, 
    197                                 'zoom' => $zoom, 
    198206                                'markers' => $this->markers, 
    199207                        )) 
  • trunk/modules/gmaps/libraries/Gmap_Marker.php

    r2207 r3145  
    3737 
    3838                $output = array(); 
    39                 $output[] = 'var m = new GMarker(new GLatLng('.$this->latitude.', '.$this->longitude.'));'; 
     39                $output[] = 'var m = new google.maps.Marker(new google.maps.LatLng('.$this->latitude.', '.$this->longitude.'));'; 
    4040                if ($html = $this->html) 
    4141                { 
    42                         $output[] = 'GEvent.addListener(m, "click", function()'; 
     42                        $output[] = 'google.maps.Event.addListener(m, "click", function()'; 
    4343                        $output[] = '{'; 
    4444                        $output[] = "\t".'m.openInfoWindowHtml('; 
  • trunk/modules/gmaps/models/location.php

    r2207 r3145  
    99  `description` varchar(127) NOT NULL, 
    1010  `link` varchar(127) NOT NULL, 
    11   `lon` float NOT NULL, 
    12   `lat` float NOT NULL, 
     11  `lon` float(10,6) NOT NULL, 
     12  `lat` float(10,6) NOT NULL, 
    1313  PRIMARY KEY  (`id`), 
    1414  UNIQUE KEY `uniq_ll` (`lon`,`lat`) 
  • trunk/modules/gmaps/views/gmaps/api_demo.php

    r2326 r3145  
    44<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    55<title>Google Maps JavaScript API Example</title> 
    6 <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo Config::item('gmaps.api_key') ?>&amp;hl=<?php echo substr(Config::item('locale.language'), 0, 2) ?>" type="text/javascript"></script> 
     6<script src="<?php echo $api_url ?>" type="text/javascript"></script> 
     7<script type="text/javascript"> 
     8<?php echo $map ?> 
     9</script> 
    710</head> 
    811<body> 
    912<p>You can use your scroll wheel to zoom in and out of the map.</p> 
    1013<div id="map" style="width: 600px; height: 400px"></div> 
    11 <script type="text/javascript"> 
    12 <?php echo $map ?> 
    13 </script> 
    1414</body> 
    1515</html> 
  • trunk/modules/gmaps/views/gmaps/info_window.php

    r2326 r3145  
    11<div class="gmap-html"> 
    2 <span class="image"><?php echo html::image(array('src' => $location->image, 'alt' => $location->title, 'width' => 100, 'height' => 100)) ?></span> 
     2<span class="image"><?php echo html::image(array('src' => $location->link, 'alt' => $location->title, 'width' => 100, 'height' => 100)) ?></span> 
    33<h6 class="title"><?php echo $location->title ?></h6> 
    44<?php 
  • trunk/modules/gmaps/views/gmaps/javascript.php

    r2326 r3145  
    1 if (GBrowserIsCompatible()) 
    2 { 
    3         // Initialize the GMap 
    4         <?php echo $map, "\n" ?> 
    5         <?php echo $controls, "\n" ?> 
    6         <?php echo $center, "\n" ?> 
    7         <?php echo $zoom, "\n" ?> 
    8         <?php echo $options->render(1), "\n" ?> 
     1google.load("maps", "2.x", {"language" : "<?php echo substr(Config::item('locale.language'), 0, 2);?>"}); 
     2function initialize() { 
     3    if (GBrowserIsCompatible()) { 
     4                // Initialize the GMap 
     5                <?php echo $map, "\n" ?> 
     6        <?php echo $controls, "\n" ?> 
     7        <?php echo $center, "\n" ?> 
     8        <?php echo $options->render(1), "\n" ?> 
    99 
    10         // Show map points 
    11 <?php foreach ($markers as $marker): ?> 
    12         <?php echo $marker->render(1), "\n" ?> 
    13 <?php endforeach ?> 
     10        // Show map points 
     11        <?php foreach ($markers as $marker): ?> 
     12        <?php echo $marker->render(1), "\n" ?> 
     13        <?php endforeach ?> 
     14    } 
    1415} 
     16google.setOnLoadCallback(initialize); 
  • trunk/modules/gmaps/views/gmaps/jquery.php

    r2989 r3145  
    44<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    55<title>Gmaps jQuery + XML Example</title> 
    6 <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo Config::item('gmaps.api_key') ?>" type="text/javascript"></script> 
    7 <?php echo html::script('jquery.min') ?> 
    8  
     6<script src="<?php echo $api_url ?>" type="text/javascript"></script> 
     7<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> 
    98<script type="text/javascript"> 
    10 $(document).ready(function() 
    11 { 
    12         if (GBrowserIsCompatible()) 
    13         { 
    14                 // Initialize the map 
    15                 var map = new GMap(document.getElementById('map')); 
    16                 map.addControl(new GLargeMapControl()); 
    17                 map.centerAndZoom(new GPoint(0,35), 16); 
    18                 map.enableScrollWheelZoom(); 
    19  
    20                 // Disable the scrollwheel from scrolling the map 
    21                 GEvent.addDomListener(map.getContainer(), 'DOMMouseScroll', function(e) 
    22                 { 
    23                         e.preventDefault(); 
    24                         e.returnValue = false; 
    25                 }); 
    26  
    27                 // Load map markers 
    28                 $.ajax 
    29                 ({ 
    30                         type: 'GET', 
    31                         url: '<?php echo url::site('google_map/xml') ?>', 
    32                         dataType: 'xml', 
    33                         success: function(data, status) 
    34                         { 
    35                                 $('marker', data).each(function() 
    36                                 { 
    37                                         // Current marker 
    38                                         var node = $(this); 
    39  
    40                                         // Extract HTML 
    41                                         var html = node.find('html').text(); 
    42  
    43                                         // Create a new map marker 
    44                                         var marker = new GMarker(new GLatLng(node.attr("lat"), node.attr("lon"))); 
    45                                         GEvent.addListener(marker, "click", function() 
    46                                         { 
    47                                                 marker.openInfoWindowHtml(html); 
    48                                         }); 
    49  
    50                                         // Add the marker to the map 
    51                                         map.addOverlay(marker); 
    52                                 }); 
    53                         }, 
    54                         error: function(request, status, error) 
    55                         { 
    56                                 alert('There was an error retrieving the marker information, please refresh the page to try again.'); 
    57                         } 
    58                 }); 
    59         } 
    60 }); 
    61 // Unload the map when the window is closed 
    62 $(document.body).unload(function(){ GBrowserIsCompatible() && GUnload(); }); 
     9<?php echo $map?> 
    6310</script> 
    6411</head>