wildfires
This commit is contained in:
parent
db94e7c618
commit
0dc274f7fa
41
api/wildfires.php
Normal file
41
api/wildfires.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
// Fetches wildfire data from WFIGS and returns as JSON
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
// The ArcGIS REST API endpoint for current wildfire perimeters
|
||||||
|
$url = 'https://services3.arcgis.com/T4QMspbfLg3qTGWY/arcgis/rest/services/WFIGS_Interagency_Perimeters_Current/FeatureServer/0/query?where=1=1&outFields=poly_IncidentName,poly_Acres_AutoCalc,attr_InitialResponseDateTime,attr_PercentContained&f=geojson';
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'worldsphere.ai bot'); // Some APIs require a user agent
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($response === false) {
|
||||||
|
echo json_encode(['error' => 'Could not fetch wildfire data.']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
echo json_encode(['error' => 'Could not parse wildfire data.']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$features = $data['features'] ?? [];
|
||||||
|
|
||||||
|
$wildfires = [];
|
||||||
|
foreach ($features as $feature) {
|
||||||
|
$properties = $feature['properties'];
|
||||||
|
$wildfires[] = [
|
||||||
|
'name' => $properties['poly_IncidentName'],
|
||||||
|
'acres' => $properties['poly_Acres_AutoCalc'],
|
||||||
|
'started' => $properties['attr_InitialResponseDateTime'],
|
||||||
|
'percent_contained' => $properties['attr_PercentContained'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($wildfires);
|
||||||
|
?>
|
||||||
@ -93,3 +93,11 @@ h2 {
|
|||||||
#cyclone-data .card {
|
#cyclone-data .card {
|
||||||
background-color: #F8F9FA;
|
background-color: #F8F9FA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#wildfire-widget {
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wildfire-data .card {
|
||||||
|
background-color: #F8F9FA;
|
||||||
|
}
|
||||||
|
|||||||
@ -69,4 +69,36 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
console.error('Error fetching cyclone data:', error);
|
console.error('Error fetching cyclone data:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch and display wildfire data
|
||||||
|
const wildfireDataContainer = document.getElementById('wildfire-data');
|
||||||
|
if (wildfireDataContainer) {
|
||||||
|
fetch('api/wildfires.php')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data && data.length > 0) {
|
||||||
|
let html = '';
|
||||||
|
data.forEach(fire => {
|
||||||
|
html += `
|
||||||
|
<div class="col-md-4 mb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">${fire.name}</h5>
|
||||||
|
<p class="card-text">${fire.acres ? Math.round(fire.acres) + ' acres' : 'Size not available'}</p>
|
||||||
|
<p class="card-text">${fire.percent_contained !== null ? fire.percent_contained + '% contained' : 'Containment not available'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
wildfireDataContainer.innerHTML = html;
|
||||||
|
} else {
|
||||||
|
wildfireDataContainer.innerHTML = '<div class="col-12"><p>No active wildfires reported at the moment.</p></div>';
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
wildfireDataContainer.innerHTML = '<p>Could not load wildfire data. Please try again later.</p>';
|
||||||
|
console.error('Error fetching wildfire data:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -63,6 +63,13 @@ $hero_image_alt = $image_data ? $image_data['alt'] : 'Satellite view of a hurric
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="wildfire-widget" class="container text-center">
|
||||||
|
<h2>Active Wildfires</h2>
|
||||||
|
<div id="wildfire-data" class="row">
|
||||||
|
<p>Loading real-time wildfire data...</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section id="solutions" class="container text-center">
|
<section id="solutions" class="container text-center">
|
||||||
<h2>Technology & Innovation</h2>
|
<h2>Technology & Innovation</h2>
|
||||||
<p class="lead mb-5">Our innovative platform combines state-of-the-art AI models, big data analytics, and immersive visualization techniques to provide unparalleled insights into weather risks and climate patterns.</p>
|
<p class="lead mb-5">Our innovative platform combines state-of-the-art AI models, big data analytics, and immersive visualization techniques to provide unparalleled insights into weather risks and climate patterns.</p>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user