1

I'm trying to apply custom styling to a Google Map with the Store Locator Plus plugin for WordPress. I found a support thread where someone was able to apply custom styles to the map using this bit of code:

<script>
$(window).load(function (){
  var mapStyles = [{ "stylers": [{ "hue": '#ff0000'}, { "lightness": -1} ]}];
  loaded_map = window.cslmap.gmap;
  loaded_map.setOptions({ styles:mapStyles});
});
</script>

For some reason gmap keeps returning as null for me, so the script doesn't work. I've tried rooting around in the plugin's JavaScript, and I see the gmap stuff, but I can't figure out why this isn't working.

My testing page: http://lombard.myweblinx.net/?page_id=2
Link to the plugin's JavaScript: http://lombard.myweblinx.net/wp-content/plugins/store-locator-le/js/slp.js?ver=4.1.01

JacobTheDev
  • 17,318
  • 25
  • 95
  • 158
  • The code on the page you link to is `loaded_map = cslmap.infowindow;` not that above. window.cslmap.gmap looks like a non-null object to me. – geocodezip Feb 07 '14 at 20:03
  • Woops, I was doing testing and forgot to change it back. Should be correct now. – JacobTheDev Feb 07 '14 at 20:08
  • Looks like the map isn't initialized when the 'load' event fires, it probably doesn't start initializing until then. You will need to wait until after the library finishes initializing the map before it will be available. Don't know if there is an event when that happens or not. – geocodezip Feb 07 '14 at 21:04

1 Answers1

1

Invoke the function at the end of __buildMap() (that's the point where you can be sure that cslmap has been initialized)

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • Can you give me a code example? I was able to get it working using a `setTimeout()`, but your method sounds more reliable. I tried using http://stackoverflow.com/a/5000466/654480, but I kept getting an error that that function didn't exit. – JacobTheDev Feb 10 '14 at 17:00
  • cut and paste the code that will be executed from it's current position to the end of `__buildMap()` – Dr.Molle Feb 10 '14 at 21:09