/** * Created by Pavel Boček on 01.06.2016. */ var baseZoom = 8; var baseLa = 48.7305967; var baseLo = 19.4570819; //48.7305967N, 19.4570819E SK stred //var baseLa = 49.743720; //var baseLo = 15.339102; var markers = []; var gmarkers = []; var markerClusterer; var gmap; var radius = 40; var city = getParameterByName('city'); //if (city) { // var cityObject = jQuery.getJSON("https://maps.googleapis.com/maps/api/geocode/json?address=" + encodeURIComponent(city), function () { // // document.cookie = "cityLat="+cityObject.responseJSON.results["0"].geometry.location.lat; // document.cookie = "cityLng="+cityObject.responseJSON.results["0"].geometry.location.lng; // document.cookie = "cityName="+city; // //// location.reload(); // // }); // //} function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i '; } var content = '
' + '
' + '
' + // '
'+ categoryName +'
' + '
'+ locations[i][0] +'
' + '
' + '
'+ locations[i][5] +'
' + ''+ locations[i][3] +'
' + ''+ locations[i][4] +'
' + '
' + 'tel.:'+ locations[i][7] +'
' + 'email: '+ locations[i][8] +'
' + '
' + '
' + '

Po: '+locations[i][10] + '
' + 'Út: '+locations[i][11] + '
' + 'St: '+locations[i][12] + '
' + 'Čt: '+locations[i][13] + '
' + 'Pá: '+locations[i][14] + '
' + 'So: '+locations[i][15] + '
' + 'Ne: '+locations[i][16] + '
' + '

' + '' + '
'; // if(city){ // jQuery.getJSON("https://maps.googleapis.com/maps/api/geocode/json?address="+encodeURIComponent(city), function(val) { // if(val.results.length) { // var location = val.results[0].geometry.location; //// $("#lat").val(location.lat) //// $("#lon").val(location.lng) // // } // }); // // console.debug(jQuery.getJSON("https://maps.googleapis.com/maps/api/geocode/json?address="+encodeURIComponent(city))); // //// console.debug('city: '+location.lat+' / '+location.lng); //// console.debug('marker: '+locations[i][1]+' / '+locations[i][2]); // } if(city){ var searchCity = removeUTF8charsAndLower(locations[i][5]); // console.debug(city); // console.debug(searchCity); // console.debug(locations[i][9]); // if(city!='' && locations[i][9]==='true'){ if(city!='' || searchCity.indexOf(city) > -1){ var distance = google.maps.geometry.spherical.computeDistanceBetween(cityLatLng, latLng)/1000; if(distance <= radius){ var marker = new google.maps.Marker({ 'position': latLng, 'category': category, 'map': gmap, 'icon': "/wp-content/themes/colorlak/img/map-point.png" }); markers.push(marker); gmarkers.push(marker); // Marker click listener google.maps.event.addListener(marker, 'click', (function (marker, content) { return function () { infowindow.setContent(content); infowindow.open(gmap, marker); gmap.panTo(this.getPosition()); // gmap.setZoom(15); } })(marker, content)); } // console.debug('here1'); } // else if(searchCity.indexOf(city) > -1){ // var marker = new google.maps.Marker({ // 'position': latLng, // 'category': category, // 'map': gmap, // 'icon': "/wp-content/themes/colorlak/img/map-point.png" // }); // markers.push(marker); // gmarkers.push(marker); // // Marker click listener // google.maps.event.addListener(marker, 'click', (function (marker, content) { // return function () { // infowindow.setContent(content); // infowindow.open(gmap, marker); // gmap.panTo(this.getPosition()); // // gmap.setZoom(15); // } // })(marker, content)); // console.debug('here2'); // // }; gmap.setCenter(cityLatLng); gmap.setZoom(11); } else{ var marker = new google.maps.Marker({ 'position': latLng, 'category': category, 'map': gmap, 'icon': "/wp-content/themes/colorlak/img/map-point.png" }); markers.push(marker); gmarkers.push(marker); // Marker click listener google.maps.event.addListener(marker, 'click', (function (marker, content) { return function () { infowindow.setContent(content); infowindow.open(gmap, marker); gmap.panTo(this.getPosition()); // gmap.setZoom(15); } })(marker, content)); // console.debug('here3'); } // if(zip){ // if(psc === zip ){ // var marker = new google.maps.Marker({ // 'position': latLng, // 'category': category, // 'map': gmap, // 'icon': "/wp-content/themes/colorlak/img/map-point.png" // }); // markers.push(marker); // gmarkers.push(marker); // // // Marker click listener // google.maps.event.addListener(marker, 'click', (function (marker, content) { // return function () { // infowindow.setContent(content); // infowindow.open(gmap, marker); // gmap.panTo(this.getPosition()); // // gmap.setZoom(15); // } // })(marker, content)); // } // }else{ // var marker = new google.maps.Marker({ // 'position': latLng, // 'category': category, // 'map': gmap, // 'icon': "/wp-content/themes/colorlak/img/map-point.png" // }); // markers.push(marker); // gmarkers.push(marker); // // // Marker click listener // google.maps.event.addListener(marker, 'click', (function (marker, content) { // return function () { // infowindow.setContent(content); // infowindow.open(gmap, marker); // gmap.panTo(this.getPosition()); // // gmap.setZoom(15); // } // })(marker, content)); // } } // console.log('markers',markers); if(tonCentra || svetBarev || ostatni){ // console.log(1); for (i = 0; i < markers.length; i++) { marker = gmarkers[i]; if(tonCentra && svetBarev && ostatni){ marker.setVisible(true); }else if(tonCentra && (marker.category === 1 || marker.category === 3)){ marker.setVisible(true); }else if(svetBarev && (marker.category === 2 || marker.category === 3)){ marker.setVisible(true); }else if(ostatni && marker.category === 0){ marker.setVisible(true); }else if(tonCentra && svetBarev && marker.category === 0){ marker.setVisible(false); }else{ marker.setVisible(false); } } }else if(!tonCentra && !svetBarev && city != null){ // console.log(2); for (i = 0; i < markers.length; i++) { marker = gmarkers[i]; if(marker.category === 0){ marker.setVisible(true); }else{ marker.setVisible(false); } } }else if(city){ // console.log(3); for (i = 0; i < markers.length; i++) { marker = gmarkers[i]; if(marker.category === 0){ marker.setVisible(true); }else{ marker.setVisible(false); } } }else{ // console.log(4); marker.setVisible(true); } // gmap.setCenter(latLng); // markerClusterer = new MarkerClusterer(gmap, markers); } function addMarker(){ var marker = new google.maps.Marker({ 'position': latLng, 'category': category, 'map': gmap, 'icon': "/wp-content/themes/colorlak/img/map-point.png" }); markers.push(marker); gmarkers.push(marker); // Marker click listener google.maps.event.addListener(marker, 'click', (function (marker, content) { return function () { infowindow.setContent(content); infowindow.open(gmap, marker); gmap.panTo(this.getPosition()); // gmap.setZoom(15); } })(marker, content)); } filterMarkers = function (category) { var activeFilters = []; jQuery('input[type=checkbox]').each(function () { if (this.checked) { activeFilters.push(this.value); jQuery('.store-type-'+this.value).each(function(){ jQuery(this).show(); }); }else{ jQuery('.store-type-'+this.value).each(function(){ jQuery(this).hide(); }); } }); if (activeFilters.length > 0) { for (i = 0; i < markers.length; i++) { marker = gmarkers[i]; if (activeFilters.indexOf(String(marker.category)) != -1) { marker.setVisible(true); } else { marker.setVisible(false); } } } else { for (i = 0; i < markers.length; i++) { marker = gmarkers[i]; marker.setVisible(false); } } } function removeUTF8charsAndLower(string){ var sdiak = "áäčďéěíĺľňóô öŕšťúů üýřžÁÄČĎÉĚÍĹĽŇÓÔ ÖŔŠŤÚŮ ÜÝŘŽ"; var bdiak = "aacdeeillnoo orstuu uyrzAACDEEILLNOO ORSTUU UYRZ"; tx = ""; txt = string; for(p = 0; p < txt.length; p++) { if (sdiak.indexOf(txt.charAt(p)) != -1) { tx += bdiak.charAt(sdiak.indexOf(txt.charAt(p))); } else tx += txt.charAt(p); } return tx.toLowerCase(); } function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); } function myPosition() { // Try HTML5 geolocation. if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { var pos = { lat: position.coords.latitude, lng: position.coords.longitude }; gmap.setZoom(13); gmap.setCenter(pos); }, function () { handleLocationError(true, gmap.getCenter()); }); } else { // Browser doesn't support Geolocation handleLocationError(false, gmap.getCenter()); } // // Try HTML5 geolocation. // if (navigator.geolocation) { // navigator.geolocation.getCurrentPosition(function(position) { // var pos = { // lat: position.coords.latitude, // lng: position.coords.longitude // }; // // infoWindow.setPosition(pos); // infoWindow.setContent('Location found.'); // gmap.setCenter(pos); // }, function() { // handleLocationError(true, infoWindow, gmap.getCenter()); // }); // } else { // // Browser doesn't support Geolocation // handleLocationError(false, infoWindow, gmap.getCenter()); // } } function handleLocationError(browserHasGeolocation, pos) { // infoWindow.setPosition(pos); // infoWindow.setContent(browserHasGeolocation ? // 'Error: The Geolocation service failed.' : // 'Error: Your browser doesn\'t support geolocation.'); } jQuery(document).ready(function () { gMapInitialize(); });