Double Maps API inclusion

by Philip Kahn

HTML

<script src="https://polygit.org/polymer+:master/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="https://polygit.org/polymer+:master/components/polymer/polymer.html"></script>
<script src="https://polygit.org/polymer+:master/components/google-map/google-map.html"></script>
<head>
  <base href="https://polygit.org/polymer+:master/components/">

  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  
  <link href="polymer/polymer.html" rel="import"/>
  <link rel="import" href="google-map/google-map.html"/>

</head>
<body>
  
  <google-map id="global-data-map" map-type="terrain" api-key="AIzaSyBbn0cCiNJOu041xNW23NzX6PTzKu1TXoM" zoom="3" min-zoom="3"></google-map>
  
  <div id="log-body">
  
  </div>
  
</body>

CSS

google-map {
  height: 60vh;
  width: 80vw;
}

CoffeeScript

# 'Fiddles and Bins' API key
gMapsApiKey = "AIzaSyBbn0cCiNJOu041xNW23NzX6PTzKu1TXoM"

jQuery.fn.exists = -> jQuery(this).length > 0

loadJS = (src, callback = new Object(), doCallbackOnError = true) ->
  ###
  # Load a new javascript file
  #
  # If it's already been loaded, jump straight to the callback
  #
  # @param string src The source URL of the file
  # @param function callback Function to execute after the script has
  #                          been loaded
  # @param bool doCallbackOnError Should the callback be executed if
  #                               loading the script produces an error?
  ###
  if $("script[src='#{src}']").exists()
    if typeof callback is "function"
      try
        callback()
      catch e
        console.error "Script is already loaded, but there was an error executing the callback function - #{e.message}"
    # Whether or not there was a callback, end the script
    return true
  # Create a new DOM selement
  s = document.createElement("script")
  # Set all the attributes. We can be a bit redundant about this
  s.setAttribute("src",src)
  s.setAttribute("async","async")
  s.setAttribute("type","text/javascript")
  s.src = src
  s.async = true
  # Onload function
  onLoadFunction = ->
    state = s.readyState
    try
      if not callback.done and (not state or /loaded|complete/.test(state))
        callback.done = true
        if typeof callback is "function"
          try
            callback()
          catch e
            console.error "Postload callback error for #{src} - #{e.message}"
            console.warn e.stack
    catch e
      console.error "Onload error - #{e.message}"
  # Error function
  errorFunction = ->
    console.warn "There may have been a problem loading #{src}"
    try
      unless callback.done
        callback.done = true
        if typeof callback is "function" and doCallbackOnError
          try
            callback()
          catch e
            console.error "Post error callback error -...