2 var markers_visible_max = 150;
3 var markersrc_color = { fill: 'red', stroke: 'darkred' };
4 var markerdst_color = { fill: '#F8E23B', stroke: '#383F47' };
7 var regionhits_countonly = {};
9 var markercaptions = {};
10 var markers_total = 0;
12 function marker_animation(x, y, css) {
13 $("#world-map").append(
14 $('<div class="marker_animation ' + css + '"></div>')
15 .css('left', x + 'px')
17 .css({ opacity: 1, scale: 0 })
18 .transition({ opacity: 0, scale: 1 }, 1000, 'linear', function(){ $(this).remove(); })
22 function marker_animation_ll(lat, lng, css) {
23 var xy = mapobj.latLngToPoint(lat, lng);
24 marker_animation(xy.x, xy.y, css);
27 function get_regioncode(x, y) {
29 var efp = $(document.elementFromPoint(x + $("#world-map").offset().left, y + $("#world-map").offset().top));
31 return efp.attr('data-code');
32 } else if(efp.is('circle') || (efp.is('div') && efp.hasClass('marker_animation'))) {
33 // This is as ugly as it gets. If we hit an existing marker, make it invisible,
34 // look again and then make it visible again.
36 var rc = get_regioncode(x, y);
44 function get_regioncode_ll(lat, lng) {
45 var xy = mapobj.latLngToPoint(lat, lng);
46 return get_regioncode(xy.x, xy.y);
49 function get_regionname_ll(lat, lng) {
50 var code = get_regioncode_ll(lat,lng);
51 return code ? mapobj.getRegionName(code) : null;
54 function add_log(msg) {
55 // remove old log entries from time to time
56 entries = $("#log div.log_entry");
57 if(entries.length > markers_visible_max) {
58 // dont remove them all, only a few, so we dont see them disappear
59 entries.slice(0, markers_visible_max/2).remove();
60 // remove abandoned line breaks
61 $('#log br').nextUntil('div.log_entry', 'br').remove();
63 // only automatically scroll down if the user did not manually scroll up before :-)
64 var scroll = $('#log').scrollTop() + $('#log').innerHeight() == $('#log')[0].scrollHeight;
65 $('#log').append('<div class="log_entry">' + msg + '</div><br/>');
67 $("#log").scrollTop($("#log")[0].scrollHeight);
71 function remove_oldest_marker() {
72 // only remove src markers
73 toremove = $($("#world-map svg g circle.jvectormap-marker[fill=" + markersrc_color.fill + "]")[0]);
74 par = toremove.parent();
75 mapobj.removeMarkers( [ toremove.attr('data-index') ]);
76 par.remove(); // Remove parent node too (jVectorMap does not do this by itself)
79 function add_marker_ll(lat, lng, type, eventname, region) {
80 if(eventname == null) { eventname = "other"; }
81 if(type == null) { type = 'src'; }
83 // only count src markers which are within a valid region
84 if(region == null) { region = get_regioncode_ll(lat, lng); }
86 if(regionhits[region] == null) { regionhits[region] = {}; regionhits_countonly[region] = 0; }
87 if(regionhits[region][eventname] == null) { regionhits[region][eventname] = 0; }
88 regionhits[region][eventname]++;
89 regionhits_countonly[region]++;
92 var markerkey = lat + "," + lng;
93 if(markerhits[markerkey] == null) { markerhits[markerkey] = {}; }
94 if(markerhits[markerkey][eventname] == null) { markerhits[markerkey][eventname] = 0; }
95 markerhits[markerkey][eventname]++;
96 marker_animation_ll(lat, lng, type == 'dst' ? 'markerdst' : 'markersrc');
97 // only add markers which do not exist yet
98 if(mapobj.markers[markerkey] == null) {
99 if(markers_total >= markers_visible_max) {
100 remove_oldest_marker();
103 mapobj.addMarker(markerkey, {
104 latLng: [ lat, lng ], name: "(" + lat + ", " + lng + ")",
105 style: markerdst_color
108 mapobj.addMarker(markerkey, {
109 latLng: [ lat, lng ], name: "(" + lat + ", " + lng + ")"
116 function update_regioncolors() {
117 // Force recomputation of min and max for correct color scaling
118 mapobj.series.regions[0].params.min = null;
119 mapobj.series.regions[0].params.max = null;
121 mapobj.series.regions[0].setValues(regionhits_countonly);