forked from nus-cs2103-AY1819S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
204 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Equipment Display</title> | ||
<meta name="viewport" content="initial-scale=1.0"> | ||
<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; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="map"></div> | ||
<script> | ||
/** | ||
This function parse the url parameters and return the points as an array of objects. | ||
Params: Url(String): The url to be parsed. | ||
Returns: The parameters object. | ||
*/ | ||
function parseUrlParams(url) { | ||
// get query string from url | ||
var queryString = url.split('?')[1]; | ||
var points = []; | ||
var tempObject = {}; | ||
var keyList = []; | ||
if (queryString) { | ||
// stuff after # is not part of query string, so get rid of it | ||
queryString = queryString.split('#')[0]; | ||
// split our query string into its component parts | ||
var arr = queryString.split('&'); | ||
for (var i = 0; i < arr.length; i++) { | ||
// separate the keys and the values | ||
var a = arr[i].split('='); | ||
// set parameter name and value (use 'null' if empty) | ||
var paramName = a[0]; | ||
var paramValue = typeof (a[1]) === 'undefined' ? null : a[1]; | ||
if (paramValue == null) { | ||
console.error("Bad parameters. Parameter value should not be empty. Parsing failed."); | ||
} | ||
console.log(paramValue); | ||
obj = JSON.parse(paramValue); | ||
tempObject[paramName] = obj; | ||
keyList.push(paramName); | ||
} | ||
if (!("coordinates" in tempObject)) { | ||
console.error("Bad parameters. Must have coordinates. Parsing failed."); | ||
return []; | ||
} else { | ||
console.log(tempObject); | ||
console.log(keyList); | ||
for (var i = 0; i < tempObject["coordinates"].length; i++) { | ||
var tempPoint = { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": tempObject["coordinates"][i] | ||
}, | ||
"properties": {} | ||
}; | ||
for (var j = 0; j < keyList.length; j++) { | ||
if (keyList[j] != "coordinates") { | ||
tempPoint["properties"][keyList[j]] = tempObject[keyList[j]][i];; | ||
} | ||
} | ||
points.push(tempPoint); | ||
} | ||
} | ||
} | ||
return points; | ||
} | ||
var map; | ||
function initMap() { | ||
var points = parseUrlParams(decodeURI(window.location.href)); | ||
map = new google.maps.Map(document.getElementById('map'), { | ||
center: { lat: 1.291610266, lng: 103.8497472 }, | ||
zoom: 12 | ||
}); | ||
var markers = [] | ||
for (var i = 0; i < points.length; i++) { | ||
var marker = { lat: points[i]["geometry"]["coordinates"][1], lng: points[i]["geometry"]["coordinates"][0] }; | ||
markers.push(new google.maps.Marker({ position: marker, map: map })); | ||
} | ||
} | ||
|
||
</script> | ||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDhN4_NQ94uS9Z0Ix6AfRgeXZN1rVahjBE&callback=initMap" async | ||
defer></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters