This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.GMAP.async-overlays.js
91 lines (73 loc) · 2.63 KB
/
jquery.GMAP.async-overlays.js
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
/* Simple async overlay
* ======================
*
* needs google maps api is loaded before:
* <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
*
* gets data from url /api/map/ and expect that data to be json in following format:
* [{"title": "some title",
* "id": 1,
* "longitude": 8.5500001907348597,
* "latitude": 47.36669921875,
* "content": "<p>Content</p>",
* "icon": "/media/img/taube.png"},
* < ... >
* ]
*/
$(function(){
if ($('#map').length) {
var latlng = new google.maps.LatLng(46.83, 8.1);
var myOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var infowindow = new google.maps.InfoWindow({
content: '',
maxWidth : 230,
size: new google.maps.Size(60, 30)
});
function bindWindow(marker, content){
google.maps.event.addListener(marker, 'click', function(){
infowindow.close();
infowindow.setContent(content);
infowindow.open(map, marker);
});
}
function drawMarker(item, show) {
return (function() {
var position = new google.maps.LatLng(item.latitude, item.longitude);
var marker = new google.maps.Marker({
position: position,
map: map,
title: item.title,
icon: item.icon
});
bindWindow(marker, item.content);
if (show) {
infowindow.setContent(item.content);
infowindow.open(map, marker);
}
});
}
$.getJSON('/api/map/', function(data){
all = data.length
for (i in data) {
var wait = 0;
if ((all - i) < 50) {
wait = 500 * (all - i);
}
var local = i;
var item = data[local];
if (parseInt(i)+1==all) {
show = true
} else {
show = false
}
drawMarkerRef = drawMarker(item, show);
var timeout = setTimeout(drawMarkerRef, wait)
}
})
}
});