google_maps.js
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var map;
var infoWindow;
var mapPoints = {};
var mapBounds;
function mapOpenBalloon(marker, html) {
infoWindow.setPosition(marker.getPosition());
infoWindow.setContent(html);
infoWindow.open(map, marker);
}
function mapPutMarker(lat, lng, title, icon, url_or_function) {
var point_str = lat + ":" + lng;
if (mapPoints[point_str]) {
lng += (Math.random() - 0.5) * 0.02;
lat += (Math.random() - 0.5) * 0.02;
} else {
mapPoints[point_str] = true;
}
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;
}
function mapLoad(initial_zoom) {
//center in Brazil
centerPoint = new google.maps.LatLng(-15.0, -50.1419);
map = new google.maps.Map(document.getElementById("map"), {
zoom: initial_zoom,
center: centerPoint,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
mapBounds = new google.maps.LatLngBounds();
infoWindow = new google.maps.InfoWindow({map: map});
google.maps.event.addListener(map, 'click', function() {
infoWindow.close();
});
}
function mapCenter(latlng) {
if (!latlng)
map.fitBounds(mapBounds);
map.setCenter(latlng ? latlng : mapBounds.getCenter());
}