From a4fbd0ea605f17081a27ebf692d862704a0e1ee7 Mon Sep 17 00:00:00 2001 From: Rafael Martins Date: Thu, 16 Feb 2012 17:27:17 -0200 Subject: [PATCH] Add missing v3 migrated google_maps.js --- public/javascripts/google_maps.js | 65 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/public/javascripts/google_maps.js b/public/javascripts/google_maps.js index 797ea87..26e2187 100644 --- a/public/javascripts/google_maps.js +++ b/public/javascripts/google_maps.js @@ -1,13 +1,17 @@ var map; +var infoWindow; var mapPoints = {}; var mapBounds; -var mapDefaultIcon = new GIcon(G_DEFAULT_ICON); + +function mapOpenBalloon(marker, html) { + infoWindow.setPosition(marker.getPosition()); + infoWindow.setContent(html); + infoWindow.open(map, marker); +} -function mapPutMarker(lat, lng, title, _icon, url) { +function mapPutMarker(lat, lng, title, icon, url_or_function) { var point_str = lat + ":" + lng; - var icon = _icon == null ? mapDefaultIcon : _icon; - if (mapPoints[point_str]) { lng += (Math.random() - 0.5) * 0.02; lat += (Math.random() - 0.5) * 0.02; @@ -15,44 +19,43 @@ function mapPutMarker(lat, lng, title, _icon, url) { mapPoints[point_str] = true; } - var point = new GLatLng(lat, lng); - var options = { 'title' : title, 'icon' : icon }; - var marker = new GMarker(point, options); - map.addOverlay(marker); - - GEvent.addListener(marker, 'click', function() { - if (url) { - jQuery.ajax({url: url, - success: function(data) { - map.openInfoWindowHtml(point, jQuery(data).html()); - } - }); - } + var point = new google.maps.LatLng(lat, lng); + var options = { map: map, title: title, icon: icon, position: point }; + var marker = new google.maps.Marker(options); + + google.maps.event.addListener(marker, 'click', function() { + if (!url_or_function) + return; + if (typeof(url_or_function) == "function") + url_or_function(marker); + else + jQuery.ajax({url: url_or_function, success: function(data) { mapOpenBalloon(marker, jQuery(data).html()); } }); }); mapBounds.extend(point); return marker; } -window.unload = function() { - GUnload(); -}; - function mapLoad(initial_zoom) { - if (GBrowserIsCompatible()) { - map = new GMap2(document.getElementById("map")); + //center in Brazil + centerPoint = new google.maps.LatLng(-15.0, -50.1419); - new GKeyboardHandler(map); - map.addControl(new GLargeMapControl()); - map.addControl(new GMapTypeControl()); + map = new google.maps.Map(document.getElementById("map"), { + zoom: initial_zoom, + center: centerPoint, + mapTypeId: google.maps.MapTypeId.ROADMAP + }); - centerPoint = new GLatLng(-15.0, -50.1419); - map.setCenter(centerPoint, initial_zoom); - mapBounds = new GLatLngBounds(); - } + mapBounds = new google.maps.LatLngBounds(); + infoWindow = new google.maps.InfoWindow({map: map}); + + google.maps.event.addListener(map, 'click', function() { + infoWindow.close(); + }); } function mapCenter(latlng) { - map.setZoom(map.getBoundsZoomLevel(mapBounds)); + if (!latlng) + map.fitBounds(mapBounds); map.setCenter(latlng ? latlng : mapBounds.getCenter()); } -- libgit2 0.21.2