Skip to content
Permalink
94f539c3e0
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
234 lines (226 sloc) 11 KB
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Location Tracker</title>
<script>
var arrayColumn = (arr, n) => arr.map(x => x[n])
var colorArray = ['#FF6633','#FF33FF', '#FFFF99', '#00B3E6',
'#E6B333', '#3366E6', '#999966', '#99FF99', '#B34D4D',
'#80B300', '#809900', '#E6B3B3', '#6680B3', '#66991A',
'#FF99E6', '#CCFF1A', '#FF1A66', '#E6331A', '#33FFCC',
'#66994D', '#B366CC', '#4D8000', '#B33300', '#CC80CC',
'#66664D', '#991AFF', '#E666FF', '#4DB3FF', '#1AB399',
'#E666B3', '#33991A', '#CC9999', '#B3B31A', '#00E680',
'#4D8066', '#809980', '#E6FF80', '#1AFF33', '#999933',
'#FF3380', '#CCCC00', '#66E64D', '#4D80CC', '#9900B3',
'#E64D66', '#4DB380', '#FF4D4D', '#99E6E6', '#6666FF'];
</script>
<style>
table {
width: 100%;
}
th, td {
padding: 8px;
}
tr:nth-child(even) {background-color: #f2f2f2;}
</style>
<link rel="stylesheet" href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fopenlayers%2Fopenlayers.github.io%40master%2Fen%2Fv6.1.1%2Fcss%2Fol.css&amp;data=02%7C01%7Crair19%40uni.coventry.ac.uk%7Cab61f4c4919e4ee5676408d7a64c90da%7C4b18ab9a37654abeac7c0e0d398afd4f%7C0%7C0%7C637160720081495136&amp;sdata=ayQGq6iUJRn4qiEq1qxedI%2FLY7kfKrA1ty4%2FcHp4scg%3D&amp;reserved=0" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fopenlayers%2Fopenlayers.github.io%40master%2Fen%2Fv6.1.1%2Fbuild%2Fol.js&amp;data=02%7C01%7Crair19%40uni.coventry.ac.uk%7Cab61f4c4919e4ee5676408d7a64c90da%7C4b18ab9a37654abeac7c0e0d398afd4f%7C0%7C0%7C637160720081495136&amp;sdata=yFIDZuJ6cQum8EzRv64SikPEGhVcrQxZSbvaZPXogY8%3D&amp;reserved=0"></script>
<script>
function initialize_map(longArray,latArray,dateArray,tidArray) {
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([-1.5197, 52.4068]),
zoom: 12
})
});
var tidColor = colorDictionary(tidArray);
add_lines(map,tidColor,longArray,latArray,dateArray,tidArray)
}
function add_map_point(map,tidColor,longArray,latArray,dateArray,tidArray) {
for (i=0; i<latArray.length; i++)
{
var add = false;
if (tidArray[i]==tidArray[i+1]){
if (dateArray[i]==dateArray[i+1])
{
if (latArray[i]!==latArray[i+1] && longArray[i]!==longArray[i+1])
{
add = true;
}
}
}
if (tidArray[i]==tidArray[i-1]){
if (dateArray[i] == dateArray[i-1])
{
if (latArray[i]!==latArray[i-1] && longArray[i]!==longArray[i-1])
{
add = true;
}
}
}
if (add == true)
{
var marker1 = new ol.layer.Vector({
title: tidArray[i],
source: new ol.source.Vector({
features: [
new ol.Feature({
geometry: new ol.geom.Point(ol.proj.fromLonLat([longArray[i],latArray[i]]))
})
]
}),
style: new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */({
color: tidColor[tidArray[i]],
crossOrigin: 'anonymous',
//anchor: [0.5, 0.5],
anchorXUnits: "fraction",
anchorYUnits: "fraction",
scale : 0.03,
//src: "https://image.flaticon.com/icons/svg/446/446075.svg",
src: "https://upload.wikimedia.org/wikipedia/commons/a/a0/Circle_-_black_simple.svg",
//src: "https://upload.wikimedia.org/wikipedia/commons/e/ec/RedDot.svg" //get an image for our red dot
//src: 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/Map_marker_font_awesome.svg/200px-Map_marker_font_awesome.svg.png',
//src:"https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimage.flaticon.com%2Ficons%2Fsvg%2F1397%2F1397898.svg&amp;data=02%7C01%7Crair19%40uni.coventry.ac.uk%7Cab61f4c4919e4ee5676408d7a64c90da%7C4b18ab9a37654abeac7c0e0d398afd4f%7C0%7C0%7C637160720081495136&amp;sdata=ILOTpuqrhe94M%2BMNexenwuxycoE73Ygy%2FkroSxzj7JM%3D&amp;reserved=0",
//src: "https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fe%2Fec%2FRedDot.svg&amp;data=02%7C01%7Crair19%40uni.coventry.ac.uk%7Cab61f4c4919e4ee5676408d7a64c90da%7C4b18ab9a37654abeac7c0e0d398afd4f%7C0%7C0%7C637160720081495136&amp;sdata=D0cQ9nzdQBcHctQZxzScWs%2FtlPHq3Byvcgmo%2BkUgEEA%3D&amp;reserved=0",
}))
})
});
map.addLayer(marker1);
} else
{
continue;
}
}
map.on("singleclick", function (evt) {
this.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
alert("tid: " + layer.get("title"));
evt.preventDefault();
});
});
}
function add_lines(map,tidColor,longArray,latArray,dateArray,tidArray){
var total = 0;
for (i=0; i<latArray.length-1; i++)
{
var loc1 = ol.proj.fromLonLat([longArray[i],latArray[i]]);
var loc2 = ol.proj.fromLonLat([longArray[i+1],latArray[i+1]]);
var lineStyle = [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: tidColor[tidArray[i]],
width: 2
})
})
];
if (tidArray[i]==tidArray[i+1] && dateArray[i]==dateArray[i+1])
{
total += distance(latArray[i], latArray[i+1], longArray[i], longArray[i+1]);
var myLine = new ol.layer.Vector({
tid: tidArray[i],
lat1: latArray[i],
lat2: latArray[i+1],
lon1: longArray[i],
lon2: longArray[i+1],
totalJourney: total,
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: new ol.geom.LineString([loc1, loc2]),
name: 'Line',
})]
})
});
} else {
total = 0;
continue;
}
map.on("singleclick", function (evt) {
this.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
alert("TID: " + layer.get("tid") + "\nDistance: " + distance(layer.get("lat1"),layer.get("lat2"),layer.get("lon1"),layer.get("lon2")) + " miles" + "\nDistance from start: " + layer.get("totalJourney") + " miles");
evt.preventDefault();
});
});
myLine.setStyle(lineStyle);
map.addLayer(myLine);
}
add_map_point(map,tidColor,longArray,latArray,dateArray,tidArray)
}
function colorDictionary(tidArray)
{
var tidColor = {};
var uniqueTid = [];
for (i=0; i<tidArray.length; i++)
{
if (tidArray[i] !== tidArray[i-1] && tidArray[i]==tidArray[i+1])
{
uniqueTid.push(tidArray[i]);
}
}
for (i=0; i<uniqueTid.length; i++)
{
tidColor[uniqueTid[i]] = colorArray[i];
}
return tidColor;
}
function distance(lat1,lat2,lon1,lon2)
{
var R = 6371; // Radius of the earth in km
var lat1r = (lat1)* Math.PI / 180;
var lat2r = (lat2)* Math.PI / 180;
var dLat = (lat2 - lat1) * Math.PI / 180;
var dLon = (lon2 - lon1) * Math.PI / 180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1r) * Math.cos(lat2r) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
return d/1.609; //Distance in miles
}
</script>
</head>
<body onload="initialize_map(arrayColumn({{locations}}, 0),arrayColumn({{locations}}, 1),arrayColumn({{locations}}, 2),arrayColumn({{locations}}, 4));">
<h2>My Map</h2>
<div id="map" class="map"></div>
<table width="100%" border="0">
<tbody>
<tr style="font-size:40px;">
<td style="font-family:Arial; text-align:center">Location Tracker</td>
</tr>
</tbody>
</table>
<table width="100%" border="0">
<tbody>
<tr style="font-size:16px; font-family:Arial; text-align:center">
<th>TID</th>
<th>Longitude</th>
<th>Latitude</th>
<th>Date</th>
<th>Time</th>
</tr>
{% for item in locations %}
<tr>
<td style="font-size:18px;font-family:Arial; text-align:center"; width="5%">{{ item[4] }}</td>
<td style="font-size:18px;font-family:Arial; text-align:center"; width="25%">{{ item[0] }}</td>
<td style="font-size:18px;font-family:Arial; text-align:center"; width="25%">{{ item[1] }}</td>
<td style="font-size:18px;font-family:Arial; text-align:center"; width="15%">{{ item[2] }}</td>
<td style="font-size:18px;font-family:Arial; text-align:center"; width="20%">{{ item[3] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>