1/** 2 * (c) Greg Priday, freely distributable under the terms of the GPL 2.0 license. 3 */ 4(function ($) { 5 "use strict"; 6 7 $(window).load(function () { 8 thim_sc_googlemap.load(); 9 }); 10 11 12 var thim_sc_googlemap = window.thim_sc_googlemap = { 13 14 load : function () { 15 if ($('.thim-sc-googlemap').length > 0) { 16 if ($('.thim-sc-googlemap').data('cover')) { 17 thim_sc_googlemap.cover(); 18 } else { 19 thim_sc_googlemap.load_api(); 20 } 21 } 22 }, 23 load_api: function () { 24 var apiKey = $('.ob-google-map-canvas').data('api_key'); 25 var apiUrl = 'https://maps.googleapis.com/maps/api/js?v=3.exp&callback=thim_sc_googlemap_init'; 26 27 if (apiKey) { 28 apiUrl += '&key=' + apiKey; 29 } else { 30 var api = 'AIzaSyDNnrBbNMIqC2x_wTYJNEzHYSrMqQF-YVo'; 31 apiUrl += '&key=' + api; 32 } 33 var script = $('<script type="text/javascript" src="' + apiUrl + '"></script>'); 34 $('body').append(script); 35 }, 36 37 cover: function () { 38 $('.thim-sc-googlemap .map-cover').on('hover', function () { 39 $(this).remove(); 40 thim_sc_googlemap.load_api(); 41 }); 42 } 43 44 }; 45 46 47})(jQuery); 48 49 50/** 51 * function thim_shortcode_googlemap_init 52 * create google map 53 */ 54function thim_sc_googlemap_init() { 55 thim_sc_googlemap_create_map(window.jQuery); 56} 57 58 59/** 60 * create map 61 * @param $ : jquery 62 */ 63function thim_sc_googlemap_create_map($) { 64 $('.ob-google-map-canvas').each(function () { 65 var $$ = $(this); 66 // We use the ob_geocoder 67 var ob_geocoder = new google.maps.Geocoder(); 68 ob_geocoder.geocode({'address': $$.data('address')}, function (results, status) { 69 if (status == google.maps.GeocoderStatus.OK) { 70 var zoom = Number($$.data('zoom')); 71 if (!zoom) zoom = 14; 72 var userMapTypeId = 'user_map_style'; 73 var mapOptions = { 74 zoom : zoom, 75 scrollwheel : Boolean($$.data('scroll-zoom')), 76 // draggable: Boolean( $$.data('draggable') ), 77 center : results[0].geometry.location, 78 mapTypeControlOptions: { 79 mapTypeIds: [google.maps.MapTypeId.ROADMAP, userMapTypeId] 80 } 81 }; 82 83 var map = new google.maps.Map($$.get(0), mapOptions); 84 85 86 var userMapStyles = $$.data('style'); 87 88 var userMapOptions = { 89 name: userMapStyles 90 }; 91 92 var style_light = [{ 93 "featureType": "water", 94 "elementType": "geometry", 95 "stylers" : [{"color": "#e9e9e9"}, {"lightness": 17}] 96 }, { 97 "featureType": "landscape", 98 "elementType": "geometry", 99 "stylers" : [{"color": "#f5f5f5"}, {"lightness": 20}] 100 }, { 101 "featureType": "road.highway", 102 "elementType": "geometry.fill", 103 "stylers" : [{"color": "#ffffff"}, {"lightness": 17}] 104 }, { 105 "featureType": "road.highway", 106 "elementType": "geometry.stroke", 107 "stylers" : [{"color": "#ffffff"}, {"lightness": 29}, {"weight": 0.2}] 108 }, { 109 "featureType": "road.arterial", 110 "elementType": "geometry", 111 "stylers" : [{"color": "#ffffff"}, {"lightness": 18}] 112 }, { 113 "featureType": "road.local", 114 "elementType": "geometry", 115 "stylers" : [{"color": "#ffffff"}, {"lightness": 16}] 116 }, { 117 "featureType": "poi", 118 "elementType": "geometry", 119 "stylers" : [{"color": "#f5f5f5"}, {"lightness": 21}] 120 }, { 121 "featureType": "poi.park", 122 "elementType": "geometry", 123 "stylers" : [{"color": "#dedede"}, {"lightness": 21}] 124 }, { 125 "elementType": "labels.text.stroke", 126 "stylers" : [{"visibility": "on"}, {"color": "#ffffff"}, {"lightness": 16}] 127 }, { 128 "elementType": "labels.text.fill", 129 "stylers" : [{"saturation": 36}, {"color": "#333333"}, {"lightness": 40}] 130 }, {"elementType": "labels.icon", "stylers": [{"visibility": "off"}]}, { 131 "featureType": "transit", 132 "elementType": "geometry", 133 "stylers" : [{"color": "#f2f2f2"}, {"lightness": 19}] 134 }, { 135 "featureType": "administrative", 136 "elementType": "geometry.fill", 137 "stylers" : [{"color": "#fefefe"}, {"lightness": 20}] 138 }, { 139 "featureType": "administrative", 140 "elementType": "geometry.stroke", 141 "stylers" : [{"color": "#fefefe"}, {"lightness": 17}, {"weight": 1.2}] 142 }]; 143 144 if (userMapStyles && userMapStyles != 'default') { 145 switch (userMapStyles) { 146 case 'light': 147 userMapStyles = style_light; 148 break; 149 default: 150 break; 151 } 152 var userMapType = new google.maps.StyledMapType(userMapStyles, userMapOptions); 153 154 map.mapTypes.set(userMapTypeId, userMapType); 155 map.setMapTypeId(userMapTypeId); 156 } 157 158 if (Boolean($$.data('marker-at-center'))) { 159 160 new google.maps.Marker({ 161 position: results[0].geometry.location, 162 map : map, 163 // draggable: Boolean( $$.data('markers-draggable') ), 164 icon : $$.data('marker-icon'), 165 title : '' 166 }); 167 } 168 var markerPositions = $$.data('marker-positions'); 169 if (markerPositions && markerPositions.length) { 170 markerPositions.forEach( 171 function (mrkr) { 172 ob_geocoder.geocode({'address': mrkr.place}, function (res, status) { 173 if (status == google.maps.GeocoderStatus.OK) { 174 new google.maps.Marker({ 175 position: res[0].geometry.location, 176 map : map, 177 // draggable: Boolean( $$.data('markers-draggable') ), 178 icon : $$.data('marker-icon'), 179 title : '' 180 }); 181 } 182 }); 183 } 184 ); 185 } 186 var directions = $$.data('directions'); 187 if (directions) { 188 189 if (directions.waypoints && directions.waypoints.length) { 190 directions.waypoints.map( 191 function (wypt) { 192 wypt.stopover = Boolean(wypt.stopover); 193 } 194 ); 195 } 196 197 var directionsRenderer = new google.maps.DirectionsRenderer();
198 directionsRenderer.setMap(map); 199 200 var directionsService = new google.maps.DirectionsService(); 201 directionsService.route({ 202 origin : directions.origin, 203 destination : directions.destination, 204 travelMode : directions.travelMode.toUpperCase(), 205 avoidHighways : Boolean(directions.avoidHighways), 206 avoidTolls : Boolean(directions.avoidTolls), 207 waypoints : directions.waypoints, 208 optimizeWaypoints: Boolean(directions.optimizeWaypoints) 209 210 }, 211 function (result, status) { 212 if (status == google.maps.DirectionsStatus.OK) { 213 directionsRenderer.setDirections(result); 214 } 215 }); 216 } 217 } 218 else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) { 219 $$.append('<div><p><strong>There were no results for the place you entered. Please try another.</strong></p></div>'); 220 } 221 }); 222 }); 223}
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.