-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
201 lines (181 loc) · 5.04 KB
/
index.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Draw Map Path</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px}
#bar{
text-align:center;
width:100%;
position:absolute;
top:0px;
z-index:10;}
#csv-file{
font-size: 16px;
background: white;
padding: 10px;}
#pano{
position: absolute;
top: 50%;
left: 0;
width:100%;
height:50%;
display: none;}
.minimap{
height:50% !important;}
.bigmap{
height:100% !important;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
<script src="papaparse.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var map; // this is global
// declar styles
var styles = [
{
"featureType": "administrative.country",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "landscape",
"elementType": "geometry.fill",
"stylers": [
{ "color": "#ecf6f7" },
{ "visibility": "on" }
]
},{
"featureType": "poi",
"elementType": "geometry",
"stylers": [
{ "visibility": "on" },
{ "color": "#ecf5f7" }
]
},{
"featureType": "road",
"stylers": [
{ "color": "#e0e7e9" }
]
},{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{ "color": "#9ab6df" }
]
},{
"elementType": "labels.text.fill",
"stylers": [
{ "visibility": "on" },
{ "color": "#444444" }
]
},{
"elementType": "labels.icon",
"stylers": [
{ "visibility": "off" }
]
}
];
// initialize
function initialize() {
var mapOptions = {
zoom: 4,
styles: styles,
center: new google.maps.LatLng(52.027240, -93.451172)
};
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
var panoramaOptions = {
enableCloseButton : true,
visible: false
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
map.setOptions({
streetView: panorama
});
// on upload
$("#csv-file").change(handleFileSelect);
// control streetview
google.maps.event.addListener(panorama, "visible_changed", function() {
if (panorama.getVisible() && $("#pano").is(':visible')){
//moving the pegman around the map
}else if(panorama.getVisible() && $("#pano").is(':hidden')){
$("#pano").show();
$("#map-canvas").removeClass('bigmap');
$("#map-canvas").addClass('minimap');
}
google.maps.event.addListener(panorama, "closeclick", function() {
$("#pano").hide();
$("#map-canvas").removeClass('minimap');
$("#map-canvas").addClass('bigmap');
});
});
}
// on upload function
function handleFileSelect(evt) {
var file = evt.target.files[0];
path = new Array(); // local variable to handleFileSelect
Papa.parse(file, {
header: true,
complete: function(results) {
console.log(results);
for (i = 0; i < results.data.length; i++){
var lat = results.data[i].Lat;
var lng = results.data[i].Lng;
var time = results.data[i].Time;
var latlng = new google.maps.LatLng(lat,lng);
// add coordinates to array
path.push(latlng);
// marker
var note = results.data[i].Note;
var search ='"'+'https://www.google.ca/maps/search/' + lat + ',' + lng + '"';
var image = 'img/marker.png';
var marker = new google.maps.Marker({
position: latlng,
icon: image,
html: note + "<br>" + time + "<br>Latitude:" + lat + "<br>Longitude:" + lng + '<br><a target="_blank" href=' + search + ">Search</a>"
});
// infowindow
var infowindow = new google.maps.InfoWindow({
maxWidth: 200
});
// click
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(this.html);
infowindow.open(map, this);
}
})(marker, i));
// add markers
marker.setMap(map);
}
// set path for array
var drawPath = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 4
});
// draw array, zoom in, center map
drawPath.setMap(map);
map.setCenter(new google.maps.LatLng(results.data[1].Lat,results.data[1].Lng) );
map.setZoom(12)
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="bar">
<input type="file" id="csv-file" name="files"/>
</div>
<div id="map-canvas"></div>
<div id="pano"></div>
</body>
</html>