-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraffic2.html
170 lines (134 loc) · 4.71 KB
/
traffic2.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps Multiple Markers</title>
<script src="https://maps.google.com/maps/api/js?key=AIzaSyAYBKGusllIEoLJwgC2e8mfJl83J2CHZR0&libraries=places"
type="text/javascript"></script>
</head>
<body>
<input
id="pac-input"
class="controls"
type="text"
placeholder="Search Box"
/>
<div id="map" style="width: 1200px; height: 900px;"></div>
<script type="text/javascript">
async function initMap() {
//function initAutocomplete() {
//var url ="https://tweednswgovau.sharepoint.com/sites/Traffic/Traffic%20Monitoring/FME/DocSetUrls.csv";
var url ="data/DocSetUrls.csv";
var request = new XMLHttpRequest();
request.open("GET", url, false);
request.send(null);
var csvData = new Array();
var jsonObject = request.responseText.split(/\r?\n|\r/);
for (var i = 0; i < jsonObject.length; i++) {
if(jsonObject[i].length > 0) { //skip last empty row
csvData.push(jsonObject[i].split(','));
}
}
// Retrived data from csv file content
// console.log(csvData);
/*
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
*/
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
var map = new Map(document.getElementById('map'), {
zoom: 13,
center: new google.maps.LatLng(-28.247382, 153.479403),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Create the search box and link it to the UI element.
const input = document.getElementById("pac-input");
const searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener("bounds_changed", () => {
searchBox.setBounds(map.getBounds());
});
let markers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener("places_changed", () => {
const places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
// Clear out the old markers.
/*
markers.forEach((marker) => {
marker.setMap(null);
});
markers = [];
*/
// For each place, get the icon, name and location.
const bounds = new google.maps.LatLngBounds();
places.forEach((place) => {
if (!place.geometry || !place.geometry.location) {
console.log("Returned place contains no geometry");
return;
}
const icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25),
};
// Create a marker for each place.
markers.push(
new google.maps.Marker({
map,
icon,
title: place.name,
position: place.geometry.location,
}),
);
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < csvData.length; i++) {
console.log(csvData[i]);
// try{
// marker = new AdvancedMarkerElement({
//see this page: https://developers.google.com/maps/documentation/javascript/advanced-markers/add-marker
marker = new google.maps.Marker({
// position: new google.maps.LatLng(locations[i][1], locations[i][2]),
// map,
position: new google.maps.LatLng(parseFloat(csvData[i][2].replace(/['"]+/g,'')), parseFloat(csvData[i][3].replace(/['"]+/g,''))),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent("<a href='"+ csvData[i][4]+"' target='_blank'>"+csvData[i][0]+"-"+csvData[i][1]+"</a>");
infowindow.open(map, marker);
}
})(marker, i));
// console.log(parseFloat(csvData[i][2].replace(/['"]+/g,'')), '-',csvData[i][2]);
//}catch(ex){}
}
}
initMap();
/*}
window.initAutocomplete = initAutocomplete;
*/
</script>
</body>
</html>