1/*! 2 * Google Maps customization v1.0 3 * Created by Ciprian Lazar. 4 * Working on Cleanlab theme 5 * Pure JavaScript! NO jQuery required! 6 */ 7 8//** JavaScript for Google Maps **// 9 10var Zn_google_map = function ( 11 mapCanvasId, 12 ourLocation, 13 routingColor, 14 locations, 15 mapTypeId, 16 zoom, 17 scrollwheel, 18 customStyle, 19 customStyleActive, 20 show_overview, 21 show_streetview, 22 show_maptype, 23 map_clustering 24) { 25 //** Set this properties before initializing the map 26 this.mapCanvasId = mapCanvasId || ""; 27 this.ourLocation = ourLocation 28 ? new google.maps.LatLng(ourLocation[0], ourLocation[1]) 29 : new google.maps.LatLng(41.44739, -72.843868); //** [lat,long] 30 this.routingColor = routingColor || "#FF0000"; 31 this.locations = locations || [[41.44739, -72.843868, "<p>CleanLab</p>"]]; //** [lat, long, tooltip, icon, size, animation, anchor] 32 this.zoom = zoom || 17; 33 this.mapTypeId = mapTypeId 34 ? mapTypeId.toUpperCase() === "SATELLITE" 35 ? google.maps.MapTypeId.SATELLITE 36 : mapTypeId.toUpperCase() === "HYBRID" 37 ? google.maps.MapTypeId.HYBRID 38 : mapTypeId.toUpperCase() === "TERRAIN" 39 ? google.maps.MapTypeId.TERRAIN 40 : google.maps.MapTypeId.ROADMAP 41 : google.maps.MapTypeId.ROADMAP; 42 this.scrollwheel = scrollwheel || false; 43 this.show_overview = show_overview || false; 44 this.show_streetview = show_streetview || false; 45 this.show_maptype = show_maptype || false; 46 47 //** This properties are standard for all maps 48 //this.mapStyleLight = [{ stylers: [{ lightness: 30 }] }, { elementType: 'labels', stylers: [{ lightness: 30 }] }]; 49 //this.mapStyleNormal = [{ stylers: [{ lightness: 0 }] }, { elementType: 'labels', stylers: [{ lightness: 0 }] }]; 50 51 // Map Color Scheme - more styles here http://snazzymaps.com/ 52 this.normalMapStyle = customStyle || false; 53 this.activeMapStyle = customStyleActive || false; 54 55 this.directionCoord = 56 typeof this.locations != "undefined" && 57 typeof this.locations[0][0] != "undefined" && 58 typeof this.locations[0][1] != "undefined" 59 ? new google.maps.LatLng(this.locations[0][0], this.locations[0][1]) 60 : this.ourLocation; 61 this.directionsDisplay; 62 this.directionsService = new google.maps.DirectionsService(); 63 this.map; 64 this.map; 65 66 this.map_clustering = map_clustering; 67}; 68 69Zn_google_map.prototype.init_map = function () { 70 var that = this; 71 //** Set the options for the map 72 var myOptions = { 73 zoom: this.zoom, 74 center: this.ourLocation, 75 mapTypeId: this.mapTypeId, 76 scrollwheel: this.scrollwheel, 77 noClear: true, 78 mapTypeControl: this.show_maptype, 79 streetViewControl: this.show_streetview, 80 panControlOptions: { position: google.maps.ControlPosition.RIGHT_CENTER }, 81 scaleControl: false, 82 overviewMapControl: this.show_overview, 83 zoomControl: true, 84 zoomControlOptions: { 85 style: google.maps.ZoomControlStyle.LARGE, 86 position: google.maps.ControlPosition.LEFT_CENTER, 87 }, 88 //** Make the map lighter 89 styles: this.normalMapStyle, 90 }; 91 //** Define the map 92 this.map = new google.maps.Map( 93 document.getElementById(this.mapCanvasId), 94 myOptions 95 ); 96 this.directionsDisplay = new google.maps.DirectionsRenderer({ 97 polylineOptions: { strokeColor: this.routingColor }, 98 }); //({ suppressMarkers: true }); 99 100 //** Add the markers to the map [[lat, long, tooltip, icon, size, animation, anchor],...] 101 var infowindow = new google.maps.InfoWindow(); 102 google.maps.event.addListener(infowindow, "closeclick", function () { 103 that.map.setOptions({ styles: that.normalMapStyle }); 104 }); 105 var marker, i; 106 var allMarkers = []; 107 for (i = 0; i < this.locations.length; i++) { 108 marker = new google.maps.Marker({ 109 map: this.map, 110 position: new google.maps.LatLng( 111 this.locations[i][0], 112 this.locations[i][1] 113 ), 114 icon: this.locations[i][3] || null, 115 size: this.locations[i][4] || null, 116 anchor: this.locations[i][6] || null, 117 animation: this.locations[i][5] 118 ? this.locations[i][5].toUpperCase() === "BOUNCE" 119 ? google.maps.Animation.BOUNCE 120 : this.locations[i][5].toUpperCase() === "DROP" 121 ? google.maps.Animation.DROP 122 : null 123 : null, 124 });
125 126 allMarkers.push(marker); 127 128 google.maps.event.addListener( 129 marker, 130 "click", 131 (function (marker, i) { 132 return function () { 133 if ( 134 typeof that.locations[i][2] != "undefined" && 135 that.locations[i][2].length > 0 136 ) { 137 infowindow.setContent(that.locations[i][2]); 138 infowindow.open(that.map, marker); 139 that.map.setOptions({ styles: that.activeMapStyle }); 140 that.directionCoord = new google.maps.LatLng( 141 that.locations[i][0], 142 that.locations[i][1] 143 ); 144 } 145 }; 146 })(marker, i) 147 ); 148 } 149 150 // Add a marker clusterer to manage the markers if is enable. 151 152 if (this.map_clustering === "yes") { 153 new MarkerClusterer(that.map, allMarkers, { 154 imagePath: ZnGoogleMapConfig.assets_url, 155 }); 156 } 157 158 var currCenter = this.map.getCenter(); 159 window.onresize = function (event) { 160 google.maps.event.trigger(that.map, "resize"); 161 that.map.setCenter(currCenter); 162 }; 163 164 //** If having the startLocation container, add event to <ENTER> 165 if (this.findChildByClass("zn_startLocation")) { 166 var that = this; 167 this.findChildByClass("zn_startLocation").onkeydown = function (event) { 168 if (event.keyCode == 13) that.calcRoute(); 169 }; 170 } 171 172 //** If having removeRoute element, add event on click 173 if (this.findChildByClass("zn_removeRoute")) { 174 var that = this; 175 this.findChildByClass("zn_removeRoute").onclick = function () { 176 that.removeRoute(); 177 }; 178 } 179}; 180//** Load the map 181//google.maps.event.addDomListener(window, 'load', init_map); 182 183//** Calculate route based on the address 184Zn_google_map.prototype.calcRoute = function () { 185 var that = this; 186 var start = this.findChildByClass("zn_startLocation").value; 187 var end = this.directionCoord; 188 var request = { 189 origin: start, 190 destination: end, 191 travelMode: google.maps.TravelMode.DRIVING, 192 }; 193 this.directionsService.route(request, function (response, status) { 194 if (status === google.maps.DirectionsStatus.OK) { 195 //** Apply some styling classes 196 that 197 .findChildByClass("zn_startLocation") 198 .classList.remove("startLocationInvalid"); 199 that 200 .findChildByClass("zn_visitUsContainer") 201 .classList.add("startLocationNotEmpty"); 202 //** Show directions on the map and zoom to their bounding box 203 that.directionsDisplay.polylineOptions.strokeColor = that.routingColor; 204 that.directionsDisplay.setMap(that.map); 205 that.directionsDisplay.setDirections(response); 206 //** Supress the destination marker 207 //directionsDisplay.b.markers[1].setMap(null); 208 } else {
209 //** Style the input box 210 that 211 .findChildByClass("zn_visitUsContainer") 212 .classList.add("startLocationNotEmpty"); 213 that 214 .findChildByClass("zn_startLocation") 215 .classList.add("startLocationInvalid"); 216 } 217 }); 218}; 219 220Zn_google_map.prototype.removeRoute = function () { 221 //** Remove the directions from the map and zoom back to our office 222 this.directionsDisplay.setMap(null); 223 this.map.setCenter(this.ourLocation); 224 this.map.setZoom(this.zoom); 225 this.findChildByClass("zn_startLocation").value = ""; 226 this.findChildByClass("zn_startLocation").classList.remove( 227 "startLocationInvalid" 228 ); 229 this.findChildByClass("zn_visitUsContainer").classList.remove( 230 "startLocationNotEmpty" 231 ); 232}; 233 234Zn_google_map.prototype.findChildByClass = function (myClassName, parent) { 235 //** Search for visit us from element and icon_close element 236 var children = document 237 .getElementById(parent || this.mapCanvasId) 238 .getElementsByTagName("*"); 239 for (child in children) 240 if ( 241 (" " + children[child].className + " ").indexOf(" " + myClassName + " ") > 242 -1 243 ) { 244 return children[child]; 245 } 246 247 return null; 248}; 249 250Zn_google_map.prototype.refreshUI = function (event) { 251 var center = this.map.getCenter(); 252 window.dispatchEvent(new Event("resize")); 253 google.maps.event.trigger(this.map, "resize"); 254 this.map.setCenter(center); 255}; 256 257window.zn_tabs_refresh = function () {};
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.