var data = {"count":21,"installations":[{"hp_type_name":"Vzduch-voda","longitude":"21.2482954","latitude":"48.7308917","company_name":"CUPRO s.r.o.","company_id":"36170178","locality":"Kosice","year":"2012","supplier":"HOTJET CZ s.r.o"},{"hp_type_name":"Voda-voda","longitude":"21.2581013","latitude":"48.7340875","company_name":"CUPRO s.r.o.","company_id":"36170178","locality":"Kosice","year":"2011","supplier":"ELTEX Krom\u011b\u0155\u00ed\u017e"},{"hp_type_name":"Vzduch-voda","longitude":"21.2618872","latitude":"48.7134489","company_name":"Jan UHRIN","company_id":"35066687","locality":"Kosice","year":"2012","supplier":"HOT JET s.r.o."},{"hp_type_name":"Voda-voda","longitude":"21.2581013","latitude":"48.7340875","company_name":"Jan UHRIN","company_id":"35066687","locality":"Kosice","year":"2011","supplier":"Eltex Kromeri\u017e"},{"hp_type_name":"Vzduch-vzduch reverzibiln\u00e9","longitude":"21.2620591","latitude":"48.7186457","company_name":"KLIMAK SERVICE, s.r.o.","company_id":"36519901","locality":"Kosice","year":"2011","supplier":"Air cond TOSHIBA"},{"hp_type_name":"Vzduch-vzduch reverzibiln\u00e9","longitude":"21.2620591","latitude":"48.7186457","company_name":"KLIMAK SERVICE, s.r.o.","company_id":"36519901","locality":"Kosice","year":"2011","supplier":"Air cond TOSHIBA"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2012","supplier":"Klima-Teplo Consulting"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2013","supplier":"KlimaTeplo Consulting"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2013","supplier":"KlimaTeplo Consulting"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2013","supplier":"KlimaTeplo Consulting"},{"hp_type_name":"Vzduch-vzduch reverzibiln\u00e9","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2009","supplier":"VZT MONT a.s."},{"hp_type_name":"Vzduch-vzduch reverzibiln\u00e9","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2010","supplier":"VZT MONT a.s."},{"hp_type_name":"Vzduch-vzduch reverzibiln\u00e9","longitude":"21.2635202","latitude":"48.6996513","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2010","supplier":"Klima-Teplo Consulting"},{"hp_type_name":"Vzduch-vzduch reverzibiln\u00e9","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2010","supplier":"VZT MONT a.s."},{"hp_type_name":"Vzduch-vzduch reverzibiln\u00e9","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2011","supplier":"VZT MONT"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2009","supplier":"BB KLIMA s.r.o."},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2012","supplier":"Klima-Teplo Consulting"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2012","supplier":"Klima-Teplo Consulting"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2012","supplier":"Klima-Teplo Consulting"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"KlimaVal s.r.o.","company_id":"31667881","locality":"Kosice","year":"2012","supplier":"Klima-Teplo Consulting"},{"hp_type_name":"Vzduch-voda","longitude":"21.2577999","latitude":"48.7210053","company_name":"Vokup k l i m s.r.o.","company_id":"36652121","locality":"Kosice","year":"2012","supplier":"Viessmann"}]}; var filteredLocalities = {}; var map = undefined; var locality = '' var lastLatitude = 48.69096039092549; var lastLongitude = 19.632568359375; var lastZoom = 7 function initialize() { var center = new google.maps.LatLng(lastLatitude, lastLongitude); map = new google.maps.Map(document.getElementById('map'), { zoom: lastZoom, center: center, mapTypeId: google.maps.MapTypeId.ROADMAP }); var latlngbounds = new google.maps.LatLngBounds(); var markers = []; for (var i = 0; i < data.installations.length; i++) { var dataInstallation = data.installations[i]; var latLng = new google.maps.LatLng(dataInstallation.latitude, dataInstallation.longitude); var marker = new google.maps.Marker({ position: latLng }); markers.push(marker); latlngbounds.extend(latLng); } var options = { imagePath: 'images/markerclusterer/m' }; var markerCluster = new MarkerClusterer(map, markers, options); map.setCenter(latlngbounds.getCenter()); map.fitBounds(latlngbounds); google.maps.event.addListener(map, 'idle', function() { updateCompaniesList(map); }); } function updateCompaniesList(map) { var lat1 = map.getBounds().getNorthEast().lat(); var lng1 = map.getBounds().getNorthEast().lng(); var lat0 = map.getBounds().getSouthWest().lat(); var lng0 = map.getBounds().getSouthWest().lng(); var hpTypeCounts = {}; var localityCounts = {}; var supplierCounts = {}; var companyCounts = {}; var rows = []; filteredLocalities = {}; for (var i = 0; i < data['count']; i++) { var installation = data['installations'][i]; var lng = installation['longitude']; var lat = installation['latitude']; if (lng >= lng0 && lng <= lng1 && lat >= lat0 && lat <= lat1) { if (installation.hp_type_name) { var key = ''.replace("REPLACE", installation.hp_type_name) + installation.hp_type_name + ''; if (hpTypeCounts[key]) { hpTypeCounts[key]++; } else { hpTypeCounts[key] = 1; } } if (installation.locality) { var key = ''.replace("REPLACE", installation.locality) + installation.locality + ''; if (localityCounts[key]) { localityCounts[key]++; } else { localityCounts[key] = 1; } } if (installation.company_name) { var key = ''.replace("REPLACE", installation.company_id) + installation.company_name + ''; if (companyCounts[key]) { companyCounts[key]++; } else { companyCounts[key] = 1; } } if (installation.supplier) { var key = ''.replace("REPLACE", installation.supplier) + installation.supplier + ''; if (supplierCounts[key]) { supplierCounts[key]++; } else { supplierCounts[key] = 1; } } } } jQuery('#hp_type_counts').html( countDictionaryToTable(hpTypeCounts) ); jQuery('#locality_counts').html( countDictionaryToTable(localityCounts) ); jQuery('#company_counts').html( countDictionaryToTable(companyCounts) ); jQuery('#supplier_counts').html( countDictionaryToTable(supplierCounts) ); } function countDictionaryToTable(counts) { return Object.keys(counts).sort(function(a,b) { return counts[b] - counts[a]; }).map(function (key) { return '