-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclusterSlide.js
79 lines (53 loc) · 2.13 KB
/
clusterSlide.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
var ClusterSlide = {
initSlide: function(map, cluster, infowindow){
var cs = this;
current_zoom = map.getZoom();
map_max_zoom = map.maxZoom;
cluster_size = cluster.getSize();
template_id = '#infobox-template';
// Determining if the max zoom has been reached with still markers inside
if (current_zoom == map_max_zoom && cluster_size > 1) {
marker_counter = 0;
var popup ='<div class="pop-up"><strong></strong></div>' ;
infowindow.setContent( popup );
infowindow.setPosition(cluster.getCenter());
infowindow.open(map);
//Get markers
var markers = cluster.getMarkers();
this.displayWindow(markers[marker_counter].id, template_id);
marker_counter = this.getMarkerCounter(marker_counter, "next", cluster_size);
$("body").on('click', '.prev-pop', function () {
cs.displayWindow(markers[marker_counter].id, template_id);
marker_counter = cs.getMarkerCounter(marker_counter, "prev", cluster_size);
});
$("body").on('click', '.next-pop', function () {
cs.displayWindow(markers[marker_counter].id, template_id);
marker_counter = cs.getMarkerCounter(marker_counter, "next", cluster_size);
});
}
},
displayWindow : function (info, template_id){
$('.pop-up').empty();
// Retrieve the template data from the HTML (jQuery is used here).
var template = $(template_id).html();
// Compile the template data into a function
var templateScript = Handlebars.compile(template);
var context = { "id" : info };
// html = 'My name is Ritesh Kumar. I am a developer.'
var html = templateScript(context);
// Insert the HTML code into the page
$('.pop-up').append(html);
},
getMarkerCounter : function (marker_counter, action, cluster_size) {
if (marker_counter == 0 && action == "prev") {
marker_counter = cluster_size - 1;
}
if (marker_counter == cluster_size - 1 && action == "next") {
marker_counter = 0;
}
else {
marker_counter++;
}
return marker_counter;
},
}