-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (63 loc) · 2.51 KB
/
app.js
File metadata and controls
73 lines (63 loc) · 2.51 KB
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
// Bilingual toggle
const langToggle = document.getElementById('lang-toggle');
let currentLang = 'en';
langToggle.addEventListener('click', () => {
currentLang = currentLang === 'en' ? 'rw' : 'en';
document.querySelectorAll('[data-en]').forEach(el => {
el.textContent = el.getAttribute(`data-${currentLang}`);
});
langToggle.textContent = currentLang === 'en' ? 'Kinyarwanda' : 'English';
});
// Leaflet map with stunting visualization
const map = L.map('map').setView([-1.95, 30.06], 8);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
}).addTo(map);
fetch('data/sample-districts.geojson')
.then(res => res.json())
.then(data => {
L.geoJSON(data, {
pointToLayer: (feature, latlng) => {
const severity = feature.properties.stunting;
const color = severity > 30 ? 'red' : severity > 20 ? 'orange' : 'green';
return L.circleMarker(latlng, {
radius: 10,
fillColor: color,
color: '#333',
weight: 1,
opacity: 1,
fillOpacity: 0.8
}).bindPopup(`<strong>${feature.properties.name}</strong><br>Stunting: ${severity}%`);
}
}).addTo(map);
});
// Weather forecast + voice accessibility
fetch('https://api.open-meteo.com/v1/forecast?latitude=-1.95&longitude=30.06¤t_weather=true')
.then(res => res.json())
.then(data => {
const weatherText = `Temperature: ${data.current_weather.temperature}°C, Windspeed: ${data.current_weather.windspeed} km/h`;
document.getElementById('weather-info').textContent = weatherText;
document.getElementById('speak-weather').addEventListener('click', () => {
const utterance = new SpeechSynthesisUtterance(weatherText);
speechSynthesis.speak(utterance);
});
});
// Marketplace listing with localStorage
const form = document.getElementById('listing-form');
const listingsDiv = document.getElementById('listings');
const savedListings = JSON.parse(localStorage.getItem('listings')) || [];
savedListings.forEach(text => {
const listing = document.createElement('div');
listing.textContent = text;
listingsDiv.appendChild(listing);
});
form.addEventListener('submit', (e) => {
e.preventDefault();
const entry = `${form.product.value} - ${form.quantity.value} units - Call: ${form.phone.value}`;
const listing = document.createElement('div');
listing.textContent = entry;
listingsDiv.appendChild(listing);
savedListings.push(entry);
localStorage.setItem('listings', JSON.stringify(savedListings));
form.reset();
});