Commit a4fbd0ea605f17081a27ebf692d862704a0e1ee7

Authored by Rafael Martins
1 parent 6de8cf43

Add missing v3 migrated google_maps.js

Showing 1 changed file with 34 additions and 31 deletions   Show diff stats
public/javascripts/google_maps.js
1 1 var map;
  2 +var infoWindow;
2 3 var mapPoints = {};
3 4 var mapBounds;
4   -var mapDefaultIcon = new GIcon(G_DEFAULT_ICON);
  5 +
  6 +function mapOpenBalloon(marker, html) {
  7 + infoWindow.setPosition(marker.getPosition());
  8 + infoWindow.setContent(html);
  9 + infoWindow.open(map, marker);
  10 +}
5 11  
6   -function mapPutMarker(lat, lng, title, _icon, url) {
  12 +function mapPutMarker(lat, lng, title, icon, url_or_function) {
7 13 var point_str = lat + ":" + lng;
8 14  
9   - var icon = _icon == null ? mapDefaultIcon : _icon;
10   -
11 15 if (mapPoints[point_str]) {
12 16 lng += (Math.random() - 0.5) * 0.02;
13 17 lat += (Math.random() - 0.5) * 0.02;
... ... @@ -15,44 +19,43 @@ function mapPutMarker(lat, lng, title, _icon, url) {
15 19 mapPoints[point_str] = true;
16 20 }
17 21  
18   - var point = new GLatLng(lat, lng);
19   - var options = { 'title' : title, 'icon' : icon };
20   - var marker = new GMarker(point, options);
21   - map.addOverlay(marker);
22   -
23   - GEvent.addListener(marker, 'click', function() {
24   - if (url) {
25   - jQuery.ajax({url: url,
26   - success: function(data) {
27   - map.openInfoWindowHtml(point, jQuery(data).html());
28   - }
29   - });
30   - }
  22 + var point = new google.maps.LatLng(lat, lng);
  23 + var options = { map: map, title: title, icon: icon, position: point };
  24 + var marker = new google.maps.Marker(options);
  25 +
  26 + google.maps.event.addListener(marker, 'click', function() {
  27 + if (!url_or_function)
  28 + return;
  29 + if (typeof(url_or_function) == "function")
  30 + url_or_function(marker);
  31 + else
  32 + jQuery.ajax({url: url_or_function, success: function(data) { mapOpenBalloon(marker, jQuery(data).html()); } });
31 33 });
32 34 mapBounds.extend(point);
33 35  
34 36 return marker;
35 37 }
36 38  
37   -window.unload = function() {
38   - GUnload();
39   -};
40   -
41 39 function mapLoad(initial_zoom) {
42   - if (GBrowserIsCompatible()) {
43   - map = new GMap2(document.getElementById("map"));
  40 + //center in Brazil
  41 + centerPoint = new google.maps.LatLng(-15.0, -50.1419);
44 42  
45   - new GKeyboardHandler(map);
46   - map.addControl(new GLargeMapControl());
47   - map.addControl(new GMapTypeControl());
  43 + map = new google.maps.Map(document.getElementById("map"), {
  44 + zoom: initial_zoom,
  45 + center: centerPoint,
  46 + mapTypeId: google.maps.MapTypeId.ROADMAP
  47 + });
48 48  
49   - centerPoint = new GLatLng(-15.0, -50.1419);
50   - map.setCenter(centerPoint, initial_zoom);
51   - mapBounds = new GLatLngBounds();
52   - }
  49 + mapBounds = new google.maps.LatLngBounds();
  50 + infoWindow = new google.maps.InfoWindow({map: map});
  51 +
  52 + google.maps.event.addListener(map, 'click', function() {
  53 + infoWindow.close();
  54 + });
53 55 }
54 56  
55 57 function mapCenter(latlng) {
56   - map.setZoom(map.getBoundsZoomLevel(mapBounds));
  58 + if (!latlng)
  59 + map.fitBounds(mapBounds);
57 60 map.setCenter(latlng ? latlng : mapBounds.getCenter());
58 61 }
... ...