I'm having difficulty figuring out how to modify my code so that when you hover over a point on the map, a box appears displaying the location's name, in addition to displaying weather data from the weather API either in the same hover box or in the right-hand corner of the map.
// Store Temperature
let temperature;
// Store Weather
let weather = "";
let points;
let json;
let longitude;
let latitude;
let myMap;
let canvas;
const mappa = new Mappa("Leaflet");
let zoom = false;
let options = {
lat: 32.8407, //canvas center
lng: -82.6324,
zoom: 7.4,
style:
" https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png",
};
function preload() {
let api = "https://api.openweathermap.org/data/2.5/weather?";
let apiKey = "&appid=f7e1bf3a627a1b8861aa5c001a1a4f1a";
let units = "&units=imperial";
let gaUrl =
"https://api.openweathermap.org/data/2.5/weather?q=New%20York&units=imperial&APPID=e812164ca05ed9e0344b89ebe273c141";
// let gaUrl = "https://api.openweathermap.org/data/2.5/box/city?bbox=-85.605165,30.357851,-80.839729,35.000659,10&appid=f7e1bf3a627a1b8861aa5c001a1a4f1a&units=imperial";
json = loadJSON(gaUrl);
data = loadJSON("/data/gaStations.json");
}
function setup() {
canvas = createCanvas(800, 600);
myMap = mappa.tileMap(options);
myMap.overlay(canvas);
fill(200, 100, 100);
points = myMap.geoJSON(data, "Point");
// Get Temperature (error when switching API url)
temperature = json.main.temp_max;
// Switch the API from weather data from New York to Georgia causes an error in the console displaying "TypeError: Cannot read properties of undefined (reading 'temp')"
// Reference: View parameters under @ https://openweathermap.org/current
weather = json.weather[0].description;
}