1var map, infowindow, bt4_geocoder = null; 2 3function mia_posizione(position) { 4 var lat = position.coords.latitude; 5 var lon = position.coords.longitude; 6 7 jQuery('#advanced_search_lat').val(lat); 8 jQuery('#advanced_search_lng').val(lon); 9 if (typeof(auto_update_map) !== 'undefined') { 10 map.setCenter({lat: lat, lng: lon}); 11 map.setZoom(16); 12 } 13} 14 15function google_geolocation() { 16 var request_params = JSON.stringify({ 17 "considerIp": "true" 18 }); 19 jQuery.ajax('https://www.googleapis.com/geolocation/v1/geolocate?key=' + keygoogle, { 20 data: request_params, 21 contentType: 'application/json', 22 type: 'POST', 23 success: function (result) { 24 if (typeof(result.location.lat) !== 'undefined') { 25 var position = { 26 coords: { 27 latitude: result.location.lat, 28 longitude: result.location.lng 29 } 30 }; 31 mia_posizione(position); 32 } 33 } 34 }); 35} 36 37function initMap() { 38 if(typeof (is_home) !== 'undefined' && is_home === true) { 39 google_geolocation(); 40 } 41 map = new google.maps.Map(document.getElementById('map'), { 42 zoom: 3, 43 mapTypeId: google.maps.MapTypeId.ROADMAP, 44 mapTypeControl: false, 45 streetViewControl: false, 46 fullscreenControl: false, 47 scrollwheel: false, 48 /* 49 * Sul telefono un dito solo scorre la pagina, la mappa si sposta con 50 * due dita: altrimenti il tocco che parte sulla mappa lo prende la 51 * mappa e la pagina non scorre piu. Sul desktop la rotellina resta 52 * ferma come prima, e per ingrandire serve ctrl. 53 */ 54 gestureHandling: 'cooperative', 55 styles: map_config_style 56 }); 57 58 map.addListener('click', map_move_update_search); 59 map.addListener('dragend', map_move_update_search); 60 map.addListener('resize', map_move_update_search); 61 setTimeout(function() { 62 map.addListener('zoom_changed', map_move_update_search); 63 }, 3000); 64 65 function map_move_update_search() { 66 if (typeof(auto_update_map) !== 'undefined') { 67 var center = map.getCenter(); 68 jQuery('#advanced_search_lat').val(center.lat()); 69 jQuery('#advanced_search_lng').val(center.lng()); 70 } 71 } 72 73 if (locations.length > 0) { 74 var prev_infowindow = false; 75 var bounds = new google.maps.LatLngBounds(); 76 var oms = new OverlappingMarkerSpiderfier(map, { 77 markersWontMove: true, 78 markersWontHide: true, 79 basicFormatEvents: true 80 }); 81 82 var markers = locations.map(function (location, i) { 83 location.icon = location.icon.replace('encfont', bt4_font_data); 84 location.icon = location.icon.replace('fillcolor', brand_green); 85 var event_icon = new google.maps.MarkerImage( 86 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(location.icon), 87 null, null, null, new google.maps.Size(40, 50)); 88 var marker = ''; 89 marker = new google.maps.Marker({ 90 position: {lat: parseFloat(location.lat), lng: parseFloat(location.lng)}, 91 icon: event_icon 92 }); 93 // The popup is built when it is clicked, so there is no element to 94 // measure beforehand: the picture is requested at the popup's own 95 // size, scaled for the device, just before the window opens. 96 // Square, because the markers are served from the 'event-main' size, 97 // which is registered as 387x387 cropped. The popup CSS is 98 // "#map .content .image { width: 100% }" inside a 260px info window, 99 // so the picture renders 260x260 and anything else would change the 100 // shape the popup has always had. 101 var POPUP_IMAGE_WIDTH = 260; 102 var POPUP_IMAGE_HEIGHT = 260; 103 var buildHtml = function (imageUrl) { 104 var out = '<div class=\"content\">' + 105 '<a href=\"' + location.link + '\">'; 106 if (imageUrl) { 107 out += '<img class=\"image\" src=\"' + imageUrl + '\">'; 108 } 109 out += '<div class=\"info\">' + 110 '<div class=\"category\">' + location.category + '</div>' + 111 '<div class=\"title\">' + location.title + '</div>' + 112 '<div class=\"address\">' + location.address + '</div>' + 113 '</div>' + 114 '</a></div>'; 115 return out; 116 }; 117 var fallbackImage = (typeof (location.image) !== 'undefined' && location.image !== null) 118 ? location.image 119 : ''; 120 bounds.extend(marker.position); 121 marker.addListener('spider_click', function () { 122 var openWindow = function (imageUrl) { 123 var infowindow = new google.maps.InfoWindow({ 124 content: buildHtml(imageUrl) 125 //maxWidth: 260, 126 //maxHeight: 500 127 }); 128 129 if (prev_infowindow) { 130 prev_infowindow.close(); 131 } 132 133 prev_infowindow = infowindow; 134 infowindow.open(map, marker); 135 }; 136 137 // devicePixelRatio is only knowable here, so a retina screen gets 138 // a sharp popup without every other visitor paying for one. 139 if (location.image_token && window.bt4Imgproxy && bt4Imgproxy.signToken) { 140 bt4Imgproxy.signToken(location.image_token, POPUP_IMAGE_WIDTH, POPUP_IMAGE_HEIGHT, 'fill') 141 .then(openWindow) 142 .catch(function () { openWindow(fallbackImage); }); 143 } else { 144 openWindow(fallbackImage); 145 } 146 }); 147 oms.addMarker(marker); 148 return marker; 149 }); 150 151 if(locations.length > 1) { 152 map.fitBounds(bounds); 153 } else { 154 map.setCenter({ 155 lat: parseFloat(locations[0].lat), 156 lng: parseFloat(locations[0].lng) 157 }); 158 map.setZoom(14); 159 } 160 161 google.maps.event.addListener(map, 'click', function (event) { 162 if (prev_infowindow) prev_infowindow.close(); 163 }); 164 new MarkerClusterer(map, markers, { 165 imagePath: '/wp-content/plugins/bt4-engine-frontend/static_assets/global/js/images/m', 166 maxZoom: 15 167 }); 168 169 } else if ( 170 jQuery("#advanced_search_lat").length > 0 && 171 jQuery("#advanced_search_lng").length > 0 && 172 jQuery("#advanced_search_lat").val() !== '' && 173 jQuery("#advanced_search_lng").val() !== '' 174 ) { 175 var center = { 176 lat: parseFloat(jQuery("#advanced_search_lat").val()), 177 lng: parseFloat(jQuery("#advanced_search_lng").val()) 178 }; 179 map.setCenter(center); 180 map.setZoom(13); 181 } else { 182 google_geolocation(); 183 } 184 185 function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) { 186 var R = 6371; // Radius of the earth in km 187 var dLat = deg2rad(lat2 - lat1); // deg2rad below 188 var dLon = deg2rad(lon2 - lon1); 189 var a = 190 Math.sin(dLat / 2) * Math.sin(dLat / 2) + 191 Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * 192 Math.sin(dLon / 2) * Math.sin(dLon / 2) 193 ; 194 var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 195 return R * c; // Distance in km 196 } 197 198 function getBoundingBox(LatLng, radius) { 199 var circle = new google.maps.Circle({ 200 center: LatLng, 201 radius: parseFloat(radius) * 100 202 });
203 return circle.getBounds(); 204 } 205 206 function deg2rad(deg) { 207 return deg * (Math.PI / 180); 208 } 209 210}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.