Changeset 3145
- Timestamp:
- 07/17/2008 12:31:03 PM (5 months ago)
- Location:
- trunk/modules/gmaps
- Files:
-
- 7 added
- 9 modified
-
config/gmaps.php (modified) (1 diff)
-
controllers/gmaps_demo.php (modified) (4 diffs)
-
i18n (added)
-
i18n/en_US (added)
-
i18n/en_US/gmaps.php (added)
-
i18n/es_ES (added)
-
i18n/es_ES/gmaps.php (added)
-
libraries/Gmap.php (modified) (7 diffs)
-
libraries/Gmap_Marker.php (modified) (1 diff)
-
models/location.php (modified) (1 diff)
-
views/gmaps/api_demo.php (modified) (1 diff)
-
views/gmaps/info_window.php (modified) (1 diff)
-
views/gmaps/javascript.php (modified) (1 diff)
-
views/gmaps/jquery.php (modified) (1 diff)
-
views/gmaps/jquery_javascript.php (added)
-
views/gmaps/xml.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/gmaps/config/gmaps.php
r2207 r3145 5 5 * This API key is usable for http://localhost/* 6 6 */ 7 7 8 $config['api_key'] = 'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA'; -
trunk/modules/gmaps/controllers/gmaps_demo.php
r2317 r3145 18 18 public function index() 19 19 { 20 $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap');21 22 20 // Create a new Gmap 23 $map = new Gmap('map'); 21 $map = new Gmap('map', array 22 ( 23 'ScrollWheelZoom' => TRUE, 24 )); 24 25 25 26 // Set the map center point … … 29 30 $map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>'); 30 31 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); 32 33 } 33 34 34 35 public function azmap() 35 36 { 36 $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap');37 38 37 // Create a new Gmap 39 38 $map = new Gmap('map', array … … 119 118 public function jquery() 120 119 { 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); 122 125 } 123 126 124 127 public function xml() 125 128 { 126 $this->db = Database::instance('mysql://root:r00tdb@localhost/azmap');127 128 129 // Get all locations 129 130 $locations = ORM::factory('location')->find_all(); … … 137 138 $node = $xml->addChild('marker'); 138 139 139 // Set the latitu tde and longitude140 $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)); 142 143 143 144 $node->html = View::factory('gmaps/xml')->bind('location', $location)->render(); -
trunk/modules/gmaps/libraries/Gmap.php
r3126 r3145 101 101 102 102 // Map markers 103 protected $markers ;103 protected $markers = array(); 104 104 105 105 /** … … 116 116 $this->options = new Gmap_Options((array) $options); 117 117 } 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 } 118 129 119 130 /** … … 144 155 { 145 156 // Set the control type 146 $this->control s= (strtolower($size) === 'small') ? 'Small' : 'Large';157 $this->control = (strtolower($size) === 'small') ? 'Small' : 'Large'; 147 158 148 159 return $this; … … 153 164 * 154 165 * @chainable 155 * @param float latitude156 * @param float longitude157 * @param string HTML for info window166 * @param float $lat latitude 167 * @param float $lon longitude 168 * @param string $html HTML for info window 158 169 * @return object 159 170 */ … … 169 180 * Render the map into GMap Javascript. 170 181 * 182 * @param string $template template name 171 183 * @return string 172 184 */ 173 public function render( )185 public function render($template = 'gmaps/javascript') 174 186 { 175 187 // Latitude, longitude, and zoom … … 177 189 178 190 // Map 179 $map = 'var map = new GMap2(document.getElementById("'.$this->id.'"));';191 $map = 'var map = new google.maps.Map2(document.getElementById("'.$this->id.'"));'; 180 192 181 193 // Map controls 182 $controls = empty($this->control s) ? '' : 'map.addControl(new G'.$this->controls.'MapControl());';194 $controls = empty($this->control) ? '' : 'map.addControl(new google.maps.'.$this->control.'MapControl());'; 183 195 184 196 // 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.');'; 189 198 190 199 // Render the Javascript 191 return View::factory( 'gmaps/javascript', array200 return View::factory($template, array 192 201 ( 193 202 'map' => $map, … … 195 204 'controls' => $controls, 196 205 'center' => $center, 197 'zoom' => $zoom,198 206 'markers' => $this->markers, 199 207 )) -
trunk/modules/gmaps/libraries/Gmap_Marker.php
r2207 r3145 37 37 38 38 $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.'));'; 40 40 if ($html = $this->html) 41 41 { 42 $output[] = ' GEvent.addListener(m, "click", function()';42 $output[] = 'google.maps.Event.addListener(m, "click", function()'; 43 43 $output[] = '{'; 44 44 $output[] = "\t".'m.openInfoWindowHtml('; -
trunk/modules/gmaps/models/location.php
r2207 r3145 9 9 `description` varchar(127) NOT NULL, 10 10 `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, 13 13 PRIMARY KEY (`id`), 14 14 UNIQUE KEY `uniq_ll` (`lon`,`lat`) -
trunk/modules/gmaps/views/gmaps/api_demo.php
r2326 r3145 4 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 5 5 <title>Google Maps JavaScript API Example</title> 6 <script src="http://maps.google.com/maps?file=api&v=2&key=<?php echo Config::item('gmaps.api_key') ?>&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> 7 10 </head> 8 11 <body> 9 12 <p>You can use your scroll wheel to zoom in and out of the map.</p> 10 13 <div id="map" style="width: 600px; height: 400px"></div> 11 <script type="text/javascript">12 <?php echo $map ?>13 </script>14 14 </body> 15 15 </html> -
trunk/modules/gmaps/views/gmaps/info_window.php
r2326 r3145 1 1 <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> 3 3 <h6 class="title"><?php echo $location->title ?></h6> 4 4 <?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" ?>1 google.load("maps", "2.x", {"language" : "<?php echo substr(Config::item('locale.language'), 0, 2);?>"}); 2 function 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" ?> 9 9 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 } 14 15 } 16 google.setOnLoadCallback(initialize); -
trunk/modules/gmaps/views/gmaps/jquery.php
r2989 r3145 4 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 5 5 <title>Gmaps jQuery + XML Example</title> 6 <script src="http://maps.google.com/maps?file=api&v=2&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> 9 8 <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?> 63 10 </script> 64 11 </head>
