Google Maps API sample WebGL Overlay with a fox

Experiments of Google Maps WebGL Overlay feature based on the below WebGL Overlay sample using Khronos Group's sample fox model. sources: - https://github.com/shuuji3/google-maps-webgl-playground

by Shuuji TAKAHASHI

HTML

<!DOCTYPE html>
<html>

  <head>
    <title>Simple WebGL Overlay</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <script src="https://unpkg.com/three@0.128.0/build/three.min.js"></script>
    <script src="https://unpkg.com/three@0.106.2/examples/js/loaders/GLTFLoader.js"></script>
    <script src="https://unpkg.com/zlibjs@0.3.1/bin/inflate.min.js"></script>

    <!-- jsFiddle will insert css and js -->
  </head>

  <body>
    <div id="header">
      <a href="https://jsfiddle.net/shuuji3/3oqz2pub/146/?animal=fox" target="_blank" rel="noopener">
        <button id="fox" disabled>🦊 Fox</button>        
      </a>
      <a href="https://jsfiddle.net/shuuji3/3oqz2pub/146/?animal=fish" target="_blank" rel="noopener">
        <button id="fish" disabled>🐟 Fish</button>
      </a>
      <a href="https://jsfiddle.net/shuuji3/3oqz2pub/146/?animal=duck" target="_blank" rel="noopener">
        <button id="duck" disabled>🐄 Duck</button>
      </a>
      <span>← not working yet...</span>
    </div>
    <div id="map" class="map"></div>

    <!-- Async script executes immediately and must be after any DOM elements used in callback. -->
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&libraries=&v=beta" async></script>
  </body>

</html>

CSS

/* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
#map {
  height: 95%;
}

#head {
  height: 5%;
}

button {
  padding: 0.5em 30px;
  margin: 10px 5px;
  background: #fff59d;
  border: yellow 3px solid;
  border: 0;
}

a {
  text-decoration: none;
}

/* Optional: Makes the sample page fill the window. */
html,
body {
  font-family: system-ui;
  height: 100%;
  margin: 0;
  padding: 0;
}

JavaScript

let map;
let source;

const mapOptions = {
  tilt: 0,
  heading: 0,
  zoom: 18,
  //center: { lat: 35.6594945, lng: 139.6999859 }, // shibuya station
  center: { lat: 35.6585, lng: 139.7448 }, // tokyo tower
  mapId: "15431d2b469f209e",
};

function initMap() {
  const mapDiv = document.getElementById("map");
  map = new google.maps.Map(mapDiv, mapOptions);
  const animal = new URLSearchParams(location.search).get('animal') || 'fox'
  
  const fox = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Fox/glTF-Embedded/Fox.gltf'
  const fish = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/30203d9c61288d0c6e4554eea3d5ebd2a31805ed/2.0/BarramundiFish/glTF/BarramundiFish.gltf'
  const duck = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/30203d9c61288d0c6e4554eea3d5ebd2a31805ed/2.0/Duck/glTF-Embedded/Duck.gltf'
  
  
  if (animal === 'fox') {
    source = fox;
  } else if (animal === 'fish') {
    source = fish;
  } else {
    source = duck;
  } 
  
  initWebglOverlayView(map)
}

function initWebglOverlayView(map) {
  let scene, renderer, camera, loader;
  const webglOverlayView = new google.maps.WebglOverlayView();

  webglOverlayView.onAdd = () => {
    // Set up the scene.
    scene = new THREE.Scene();
    camera = new THREE.PerspectiveCamera();
    const ambientLight = new THREE.AmbientLight(0xffffff, 0.75); // Soft white light.
    scene.add(ambientLight);
    const directionalLight = new THREE.DirectionalLight(0xffffff, 0.25);
    directionalLight.position.set(0.5, -1, 0.5);
    scene.add(directionalLight);
    // Load the model.
    loader = new THREE.GLTFLoader();
    const pin = "https://raw.githubusercontent.com/googlemaps/js-samples/master/assets/pin.gltf";
      //const source = 'https://storage.googleapis.com/shuuji3-gltf-models/apple/scene.gltf' // ~80MB!
    loader.load(pin, (gltf) => {
      gltf.scene.scale.set(20, 20, 20);
      gltf.scene.rotation.x = Math.PI / 2; // Rotations are...