index.html 2.41 KB
<!doctype html>
<!-- Copyright (c) 2015 Google Inc. All rights reserved. -->
<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <title>Google Map demo</title>
  <script src="../../webcomponentsjs/webcomponents-lite.min.js"></script>
  <link rel="import" href="../google-map.html">
  <link rel="import" href="../google-map-marker.html">
  <link rel="import" href="../google-map-poly.html">
  <link rel="import" href="../google-map-directions.html">
  <style>
    body {
      margin: 0;
      height: 100vh;
    }
    #controlsToggle {
      position: absolute;
      left: 10%;
      bottom: 10%;
    }
  </style>
</head>
<body class="fullbleed">

<google-map latitude="37.779" longitude="-122.3892" min-zoom="9" max-zoom="11"
            language="en">
  <google-map-marker latitude="37.779" longitude="-122.3892"
                     title="Go Giants!" draggable="true" drag-events>
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/San_Francisco_Giants_Cap_Insignia.svg/200px-San_Francisco_Giants_Cap_Insignia.svg.png" />
  </google-map-marker>
  <google-map-poly closed fill-color="red" fill-opacity=".25" stroke-weight="1">
    <google-map-point latitude="37.779" longitude="-122.3892"></google-map-point>
    <google-map-point latitude="37.804" longitude="-122.2711"></google-map-point>
    <google-map-point latitude="37.386" longitude="-122.0837"></google-map-point>
  </google-map-poly>
</google-map>

<google-map-directions start-address="Oakland" end-address="Mountain View"
            language="en"></google-map-directions>

<button id="controlsToggle" onclick="toggleControls()">Toggle controls</button>

<script>
  var gmap = document.querySelector('google-map');
  gmap.addEventListener('api-load', function(e) {
    document.querySelector('google-map-directions').map = this.map;
  });

  function toggleControls() {
    gmap.disableDefaultUi = !gmap.disableDefaultUi;
  }

  var marker = document.querySelector('google-map-marker');
  var poly = document.querySelector('google-map-poly');
  var point = document.querySelector('google-map-point');

  marker.addEventListener('google-map-marker-dragend', function(e) {
    var latLng = e.detail.latLng;
    console.log('pin dropped', latLng.lat(), latLng.lng());
    point.latitude = latLng.lat();
    point.longitude = latLng.lng();
    poly._buildPathFromPoints();
  });
</script>
</body>
</html>