-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.php
176 lines (167 loc) · 5.72 KB
/
map.php
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
<?php
session_start();
ini_set('display_errors',1);
error_reporting(E_ALL);
if (!isset($_SESSION['success'])){
header("Location: index.php");
}
//Connect to our mySQL Database and retrieve the coords
$connection = mysqli_connect('database-1.chyh1wnf7bbo.ap-southeast-2.rds.amazonaws.com', 'admin', 'cloudpass');
if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
$database = mysqli_select_db($connection, 'gtfs');
$coords = array();
$result = mysqli_query($connection, "SELECT * FROM coords");
while($query_data = mysqli_fetch_array($result)) {
$coords[] = array((float)$query_data['lat'], (float)$query_data['lon']);
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Leaflet css -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin=""></script>
<!-- Leaflet-Image -->
<script src='https://unpkg.com/leaflet-image@latest/leaflet-image.js'></script>
<!-- AWS SDK -->
<script src="aws-sdk-2.548.0.min.js"></script>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.php">Cloud Computing</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
</ul>
</div>
</div>
</nav>
</head>
<body>
<!-- added -->
<div id="images"></div>
<div class="container">
<div class="col-md-4">
<div class="card">
<!-- Leaflet Map -->
<div id="map" style="width:800px; height: 500px;"></div>
</div>
</div>
<div class="col-md-4">
<div class="card">
Filename: <?php echo $_SESSION['filename'];?> <br>
Number of coordinate pairs: <?php echo count($coords);?> <br>
<input id="btn" type="button" value="Send map to email" onclick="emailFunction(); alert('Email sent');"/>
</div>
</div>
</div>
<script type="text/javascript">
function emailFunction() {
'use strict';
//AWS Region
var aws_region = "ap-southeast-2";
//From Address - Requires Pinpoint Verification
var senderAddress = "herasy@gmail.com";
//To Address
var toAddresses = [ "vineet.bugtani@icloud.com" ];
//Subject Line
var subject = "Cloud Computing - Map";
//Email Body
var body_text = `Amazon Pinpoint Email
----------------------------------------------------
This email was sent with Amazon Pinpoint using the AWS SDK for JavaScript.`;
//Image
var myDiv = document.getElementById("images").innerHTML;
// Message Tags
var tag0 = { 'Name':'key0', 'Value':'value0' };
var tag1 = { 'Name':'key1', 'Value':'value1' };
//Character Encoding
var charset = "UTF-8";
//AWS Creds
AWS.config.credentials = new AWS.Credentials('YOUR IAM KEY HERE', 'YOUR IAM SECRET HERE');
//Update region
AWS.config.update({region:aws_region});
//Create a new PinpointEmail object.
var pinpointEmail = new AWS.PinpointEmail();
// Specify the parameters to pass to the API.
var params = {
FromEmailAddress: senderAddress,
Destination: {
ToAddresses: toAddresses
},
Content: {
Simple: {
Body: {
Html: {
Data: myDiv,
Charset: charset
},
Text: {
Data: body_text,
Charset: charset
}
},
Subject: {
Data: subject,
Charset: charset
}
}
},
EmailTags: [
tag0,
tag1
]
};
//Try to send the email.
pinpointEmail.sendEmail(params, function(err, data) {
// If something goes wrong, print an error message.
if(err) {
console.log(err.message);
} else {
console.log("Email sent! Message ID: ", data.MessageId);
}
});
}
</script>
<script>
//Create leaflet map object
var map = L.map('map', {
center: [-37.8183431013018, 144.952513264004],
zoom: 13,
preferCanvas: true
});
//Parse the coords array
var latlngs = JSON.parse('<?php echo json_encode($coords); ?>');
//Mapbox Tilelayer
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'YOUR MAPBOX KEY HERE'
}).addTo(map);
//Coordinates Polyline
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
map.fitBounds(polyline.getBounds());
//Create Canvas Image
leafletImage(map, function(err, canvas) {
var img = document.createElement('img');
var dimensions = map.getSize();
img.width = dimensions.x;
img.height = dimensions.y;
img.src = canvas.toDataURL();
document.getElementById('images').innerHTML = '';
document.getElementById('images').appendChild(img);
document.getElementById("images").style.display = "none";
});
</script>
</body>
</html>