How do I talk to Smart Map in JavaScript? Well, I know for a fact I am doing this incorrectly &amp; it's going to be painfully obvious. I can see why (I think) but to be honest I just don’t “get it”.
I’m trying to style a Google map using Smart Map &amp; JavaScript, but keep getting the JS error:
Uncaught ReferenceError: smartMap is not defined(…)

This is what my template looks like:
{# Google Map of location. #}
{% set options = {
    height: 500,
    width: '100%',
    zoom: 15,
    markerOptions: {
    },
    infoWindowOptions: {
        maxWidth: 200
    }
} %}

    &lt;div id=&quot;mapCanvas&quot;&gt;
        {{ craft.smartMap.map(product.address, options) }}
    &lt;/div&gt;


    &lt;script src=&quot;/assets/js/app.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;

Within app.min.js I am doing this:
if ($('#mapCanvas').length) {
    var styles = [{
        &quot;featureType&quot;: &quot;all&quot;,
        &quot;elementType&quot;: &quot;geometry&quot;,
        &quot;stylers&quot;: [{&quot;visibility&quot;: &quot;simplified&quot;}, {&quot;hue&quot;: &quot;#ff7700&quot;}]
    },

    ...

    smartMap.map['smartmap-mapcanvas-1'].setOptions({styles: styles});
}

I've been reading this post which literally has the answer to my problem I believe. I just don't understand how to tell the system where/what smartMap is.
Thank you for any suggestions!
EDIT
Here is what the rendered page looks like:
&lt;script src=&quot;/assets/js/app.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://maps.googleapis.com/maps/api/js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://mysite.dev/cpresources/smartmap/js/smartmap.js?d=1449217510&quot;&gt;&lt;/script&gt;

EDIT 2
Just for future reference in case someone else comes across this thread. It ended up being the way I was initializing my js file.
// This executes before we're ready
(function () {
    'use strict';
    ...

})();


// This works
$(function () {
   ...
});
I'd recommend loading your JS file after the smartmap.js file has been loaded. The smartMap JS object needs to exist before your code gets run.

Try loading your JS using the includeJsFile tag... I believe that should place it in the correct position.

{% includeJsFile "/assets/js/app.min.js" %}


If that doesn't work, then you may need to wrap your code in something that would prevent it from running until the page is fully loaded...

$(function () {
    // Your code goes here
});


^ That example uses jQuery. The same can be achieved without jQuery, if you're not using it.