forked from tomscholz/geojson-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoly.html
174 lines (168 loc) · 5.13 KB
/
poly.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<title>FlyBuy Zone Creator</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.footerleft {
position: absolute;
top: 0;
left: 0;
}
.footerright {
position: absolute;
top: 0;
right: 0;
}
.footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
background-color: #336499;
color: white;
text-align: center;
text-decoration: none;
font-family: 'Roboto',sans-serif;
font-weight: 300;
}
.button {
display: inline-block;
padding: 1.0em 2.4em;
border: 0.2em solid #336499;
text-decoration: none;
font-family: 'Roboto',sans-serif;
font-size: 0.9em;
font-weight: 500;
color: #336499;
background-color: white;
text-align:center;
transition: all 0.2s;
}
</style>
</head>
<body>
<div id="map"></div>
<div class="footer">
<div>
<button type="button" class="button footerleft" onclick="markPoint()" >Point</button>
</div>
<div>
<p id="polygon"> </p>
</div>
<div>
<button type="button" class="button footerright" onclick="location.reload();" >Reload</button>
</div>
</div>
<script>
var map, infoWindow;
var pos = {lat: -34.397, lng: 150.644};
var zone;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: pos,
zoom: 20
});
infoWindow = new google.maps.InfoWindow;
accuracyCircle = new google.maps.Circle({
strokeOpacity: 0,
strokeWeight: 0,
fillColor: "#FF0000",
fillOpacity: 0.15,
map: map
});
newZone();
// Try HTML5 geolocation.
if (navigator.geolocation) {
options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
navigator.geolocation.watchPosition(function(position) {
pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent(`Accuracy: ${Math.trunc(position.coords.accuracy)}m`);
infoWindow.open(map);
accuracyCircle.setCenter(pos);
accuracyCircle.setRadius(position.coords.accuracy);
var path = zone.getPath();
path.pop();
path.push(new google.maps.LatLng(pos));
//accuracyCircle.open(map);
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
}, options);
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
function newZone() {
//setMapOnAll(null);
zone = new google.maps.Polygon({
geodesic: true,
strokeColor: '#0000FF',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#0000FF",
fillOpacity: 0.55,
});
zone.setMap(map)
}
function markPoint() {
var path = zone.getPath();
//path.push(new google.maps.LatLng(pos));
var marker = new google.maps.Marker({
position: pos,
title: '#' + path.getLength(),
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 4
},
map: map
});
polyText = formatPolygon(zone.getPath()["i"])
//document.getElementById("polygon").innerText = polyText
navigator.clipboard.writeText(polyText)
path.push(new google.maps.LatLng(pos));
};
function formatPolygon(path) {
var txt = '[';
for(let i = 0; i < path.length; i++){
if (txt != '[') {
txt = txt + ','
};
txt = txt + `(${path[i].lng()},${path[i].lat()})`
}
return txt + ']'
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCZkgmnjJVufr03S22zvvHTSuZuExQ9HmU&callback=initMap">
</script>
</body>
</html>