Map isn't showing – getting a grey picture instead
-
I’ve noticed that a Google Map on one of my websites isn’t working properly anymore. Instead, it’s showing a grey blank picture on Chrome, Firefox or IE…except it still works on Safari for some odd reason.
I created a custom Google Map and embedded it with Snazzy Maps to change the colours. What I’ve been doing is loading the map to a default state on a page, and then the map reloads into a new direction as soon as you click on a button.
I’ve got the API key encrypted in the functions file, and created two JS files to load the map on screen with different latitude and longitude directions, with a custom Snazzy Map of course.
Keep in mind: I created this whole procedure manually back in February, a few months before SM released the plugin on WordPress.
Code on web page
<div id="oats" onclick="showmap1();"><img class="aligncenter size-full wp-image-423" src="../../wp-content/uploads/2015/02/img01.png" alt="" width="158" height="17" /></div> <div id="apricot" onclick="showmap2();"><img class="aligncenter size-full wp-image-423" src="../../wp-content/uploads/2015/01/img02.jpg" alt="" width="158" height="130" /></div> <div id="map_canvas"></div> <div id="provenance_text"></div>
JS and Google Map API embedded in functions.php
wp_enqueue_script('google-maps', 'https://maps.googleapis.com/maps/api/js?v=3&sensor=false', array(), null, true); wp_enqueue_script( 'script', get_stylesheet_directory_uri(). "/js/default_map.js", array('google-maps'), null, true); wp_enqueue_script( 'maps', get_stylesheet_directory_uri(). "/js/maps.js", array('jquery'), $version, true); wp_localize_script( 'script', 'wpGlobals', array( 'mapOptions' => file_get_contents( dirname(__FILE__) . '/map_style.json' ) ) );
default_map.js
function makeMap() { var snazzyMap = JSON.parse(wpGlobals.mapOptions); var map = new google.maps.Map(document.getElementById('map_canvas'), { center : new google.maps.LatLng(-27.161789136782797, 138.94277218749994), zoom : 4, mapTypeId : google.maps.MapTypeId.ROADMAP, disableDefaultUI: true, styles : snazzyMap } ); } google.maps.event.addDomListener(window, 'load', makeMap);
maps.js
function showmap1() { var snazzyMap1 = JSON.parse(wpGlobals.mapOptions); var citymap1 = {}; citymap1['cambooya'] = { center: new google.maps.LatLng(-27.709669, 151.882014), population: 120000 }; citymap1['canning creek'] = { center: new google.maps.LatLng(-28.198142, 151.219560), population: 120000 }; citymap1['boggabilla'] = { center: new google.maps.LatLng(-28.661886, 150.011064), population: 120000 }; document.getElementById("oats").style.opacity = "1"; document.getElementById("apricot").style.opacity = "0.5"; var cityIcon; function initialize() { var map1 = this; var width = Math.max( jQuery(window).width(), window.innerWidth); if (width > 767) { zoomLevel = 4; } if (width <= 767) { zoomLevel = 3; } var mapOptions1 = { zoom: zoomLevel, center: new google.maps.LatLng(-27.161789136782797, 138.94277218749994), styles: snazzyMap1 }; var map1 = new google.maps.Map(document.getElementById('map_canvas, mapOptions1); for (var city1 in citymap1) { var populationOptions1 = { strokeColor: '#966057', strokeOpacity: 0.8, strokeWeight: 1, fillColor: '#966057', fillOpacity: 3, map: map1, center: citymap1[city1].center, radius: Math.sqrt(citymap1[city1].population) * 100 }; cityIcon = new google.maps.Circle(populationOptions1); } document.getElementById("provenance_text").innerHTML = "<h3>Oats</h3><p>Oats are produced in the grain cropping regions of south-west Australia</p>"; } initialize(); google.maps.event.addDomListener(window, 'resize', initialize); } window.onload = showmap1(); function showmap2() { var snazzyMap2 = JSON.parse(wpGlobals.mapOptions); var citymap2 = {}; citymap2['burnett'] = { center: new google.maps.LatLng(-24.76468, 152.41271), population: 220000 }; citymap2['perth'] = { center: new google.maps.LatLng(-31.95222, 115.85899), population: 220000 }; citymap2['adelaide hills'] = { center: new google.maps.LatLng(-34.9290, 138.6010), population: 220000 }; document.getElementById("oats").style.opacity = "0.5"; document.getElementById("apricot").style.opacity = "1"; var cityCircle; function initialize() { var width2 = Math.max( jQuery(window).width(), window.innerWidth); if (width2 > 767) { zoomLevel = 4; } if (width2 <= 767) { zoomLevel = 3; } var mapOptions2 = { zoom: zoomLevel, /*scrollwheel: false, draggable: false, disableDoubleClickZoom: true,*/ center: new google.maps.LatLng(-27.161789136782797, 138.94277218749994), styles: snazzyMap2 }; var map2 = new google.maps.Map(document.getElementById('map_canvas, mapOptions2); for (var city in citymap2) { var populationOptions2 = { strokeColor: '#FD8C4D', strokeOpacity: 0.8, strokeWeight: 1, fillColor: '#FD8C4D', fillOpacity: 3, map: map2, center: citymap2[city].center, radius: Math.sqrt(citymap2[city].population) * 100 }; cityCircle = new google.maps.Circle(populationOptions2); } document.getElementById("provenance_text").innerHTML = "<h3>Apricots</h3><p>Summer stonefruit is produced in approximately 26 regions in all states across the country.</small></p>"; } initialize(); google.maps.event.addDomListener(window, 'resize', initialize); }
Any ideas what’s going on?
- The topic ‘Map isn't showing – getting a grey picture instead’ is closed to new replies.