iwa-panda2

Manage Weather Data by International Weather Agency (Version 2)
Log | Files | Refs | README

commit 8df0af86eb1b437db5f57fa4634df91a16f1fa55
parent 4372246368ca8ac5ebafe7d959f94ee12c1f59cf
Author: Friedel Schön <[email protected]>
Date:   Wed, 28 Jun 2023 21:50:43 +0200

adding working, dynamic map

Diffstat:
Mindex.php | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mjs/map.js | 24+++++++++++++++++++-----
2 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/index.php b/index.php @@ -17,6 +17,66 @@ $router->addRoute(["POST"], "/login", $login); //logout $router->addRoute(["POST", "GET"], "/logout", $logout); +$router->addRoute(["GET"], "/api/:data", function ($key) { + if($key['data'] == ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk') { + $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2"); + $weather_data = []; + $query = "SELECT distinct temperature, wind_speed, nl.name as city, co.country as country + FROM weather_data wd + JOIN station s ON wd.station_name = s.name + JOIN contract_station cs ON cs.station_name = s.name + JOIN nearestlocation nl ON nl.station_name = s.name + JOIN country co ON co.country_code = nl.country_code + JOIN geolocation geo ON geo.country_code = co.country_code + JOIN contract c ON cs.contract_id = c.contract_id + WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk' + GROUP BY nl.name"; + + $stmt = mysqli_prepare($db, $query); + $stmt->execute(); + $data = $stmt->get_result(); + + while ($row = $data->fetch_assoc()) { + $wind_chill = Model\Formula::windchill($row["temperature"], $row["wind_speed"]); + $weather_data[] = [ + 'windchill' => $wind_chill, + 'location' => $row['city'], + 'country' => $row['country'] + ]; + } + header('Content-Type: application/json'); + echo json_encode($weather_data); + } elseif($key['data'] == ':ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684') { + $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2"); + $weather_data = []; + $query = "SELECT distinct temperature, dew_point, nl.name as city, date_time + FROM weather_data wd + JOIN station s ON wd.station_name = s.name + JOIN contract_station cs ON cs.station_name = s.name + JOIN nearestlocation nl ON nl.station_name = s.name + JOIN country co ON co.country_code = nl.country_code + JOIN geolocation geo ON geo.country_code = co.country_code + JOIN contract c ON cs.contract_id = c.contract_id + WHERE c.token = 'ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684' + "; + $stmt = mysqli_prepare($db, $query); + $stmt->execute(); + $data = $stmt->get_result(); + + while ($row = $data->fetch_assoc()) { + $humidity = Model\Formula::humid($row["temperature"], $row["dew_point"]); + $weather_data[] = [ + 'humidity' => $humidity, + 'location' => $row['city'], + 'datetime' => $row['date_time'] + ]; + } + + header('Content-Type: application/json'); + echo json_encode($weather_data); + } +}); + if(isset($_SESSION['user_permissions']) && in_array(1, $_SESSION['user_permissions'])) { //user //add diff --git a/js/map.js b/js/map.js @@ -59,12 +59,26 @@ $(document).ready(function(){ });*/ -var map = L.map('map').setView([51.505, -0.09], 13); +var map = L.map('map').setView([51.505, -0.09], 1); L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); -L.marker([51.5, -0.09]).addTo(map) - .bindPopup('A pretty CSS popup.<br> Easily customizable.') - .openPopup(); -\ No newline at end of file +const zooToken = ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'; + +/* +windchill -1.48 +location "Dutch Harbor" +country "United States" +*/ + +fetch(`http://localhost:8080/api/${zooToken}`) + .then(response => response.json()) + .then(data => { + for (let { windchill: temperature, location: city, country } of data) { + fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${city},${country}`) + .then(res => res.json()) + .then(res => L.marker([ res[0].lat, res[0].lon ]).addTo(map).bindPopup(`${city}, ${country}: ${temperature} &deg;C`)) + } + }); +\ No newline at end of file