This repository was archived by the owner on Apr 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathindex.html
More file actions
85 lines (76 loc) · 3.16 KB
/
index.html
File metadata and controls
85 lines (76 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!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.js"></script>
<script type="module" src="../google-map.js"></script>
<script type="module" src="../google-map-marker.js"></script>
<script type="module" src="../google-map-poly.js"></script>
<script type="module" src="../google-map-directions.js"></script>
<style>
body {
margin: 0;
height: 100vh;
}
#controlsToggle {
position: absolute;
left: 10%;
bottom: 10%;
}
</style>
</head>
<body class="fullbleed">
<dom-bind>
<template is="dom-bind">
<google-map latitude="37.779" longitude="-122.3892" min-zoom="9" max-zoom="11"
language="en" api-key="[[apiKey]]">
<google-map-marker slot="markers" latitude="37.779" longitude="-122.3892" label="GG"
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" api-key="[[apiKey]]"></google-map-directions>
</template>
</dom-bind>
<button id="controlsToggle" onclick="toggleControls()">Toggle controls</button>
<script type="module">
import '../google-map.js';
import '../google-map-marker.js';
import '../google-map-poly.js';
import '../google-map-directions.js';
var t = document.querySelector('template');
if (location.origin === 'https://user-content-dot-custom-elements.appspot.com') {
t.apiKey = 'AIzaSyD3E1D9b-Z7ekrT3tbhl_dy8DCXuIuDDRc'; // TODO: update to your own API Key!
}
function toggleControls() {
var gmap = document.querySelector('google-map');
gmap.disableDefaultUi = !gmap.disableDefaultUi;
}
document.addEventListener('dom-change', function(e) {
var gmap = document.querySelector('google-map');
var directions = document.querySelector('google-map-directions');
gmap.addEventListener('api-load', function(e) {
document.querySelector('google-map-directions').map = this.map;
});
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>