-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmap.js
More file actions
109 lines (98 loc) · 2.95 KB
/
Copy pathgmap.js
File metadata and controls
109 lines (98 loc) · 2.95 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//declare variables needed for this page
var gMap;
var gGeoCoder = new google.maps.Geocoder();
var gMarkersArray = [];
var gInfoWindowsArray = [];
function initialize() {
//set default
var gMapOptions = {
zoom: 6,
center: new google.maps.LatLng(42.7, -76),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
gMap = new google.maps.Map(document.getElementById('map_canvas'),
gMapOptions);
}
//google.maps.event.addDomListener(window, 'load', initialize);
function processAddress( address, map ) {
//marker
var marker = new google.maps.Marker({//create
map: map,
position: new google.maps.LatLng ( address.lat, address.lng )
});
gMarkersArray.push(marker);//store
//window
var infoWindow = new google.maps.InfoWindow({//create
content: constructInfoContent( address )
});
gInfoWindowsArray.push(infoWindow);//store
// bind marker click event
google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map,marker);
});
}
function constructInfoContent( address ) {
//construct content to be put into the tooltip
var contentString = '';
contentString += '<div class="gMap-tooltip">' +
'<h4>'+address.name+'</h4>' +
'<div>'+address.street1+'</div>' ;
if ( address.street2 ) {
contentString += '<div>'+address.street2+'</div>';
}
contentString += '<div>'+address.city+', ' + address.state + ' ' + address.zip +
'</div>';
return contentString;
}
function processAddressList( array ) {
for ( i=0;i<array.length;i++ ) {
processAddress( array[i], gMap);
$('#screenlist').append( "<li><a href='#' class='gmapAddress' data-index='"+i+"'>"+array[i].name+"</a></li>" )
}
}
//geocode function
/*
function googleGeoCodeAddress( inputAddress ) {
if (gMap == null) {
initialize();
}
gGeoCoder.geocode( { 'address': inputAddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
gMap.setCenter(results[0].geometry.location);
gMap.setZoom(12);
gMapMarker = new google.maps.Marker({
map: gMap,
position: results[0].geometry.location
});
console.log(results[0].geometry.location);
gMarkersArray.push(gMapMarker);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
*/
// extend clear functions
google.maps.Map.prototype.clearMarkerOverlays = function() {
if (gMarkersArray) {
for (var i = 0; i < gMarkersArray.length; i++ ) {
gMarkersArray[i].setMap(null);
}
}
};
google.maps.Map.prototype.clearWindowOverlays = function() {
if (gInfoWindowsArray) {
for (var i = 0; i < gMarkersArray.length; i++ ) {
gInfoWindowsArray[i].setMap(null);
}
}
};
function infoWindowHook( obj ) {
var index = obj.attr("data-index");
var marker = gMarkersArray[index];
var infoWindow = gInfoWindowsArray[index];
gMap.clearWindowOverlays();
gMap.setCenter( marker.getPosition() );
gMap.setZoom(12);
infoWindow.open(gMap, marker )
}