xxxxxxxxxx
60
let data; // To store the CSV data
let minLat, maxLat, minLon, maxLon;
function preload() {
// Load the CSV file
data = loadStrings('mcdeurope.csv');
}
function setup() {
createCanvas(800, 600);
background(220);
// Initialize min and max values with extreme values
minLat = 90;
maxLat = -90;
minLon = 180;
maxLon = -180;
// Loop through each line in the CSV data
for (let i = 0; i < data.length; i++) {
// Split each line into latitude and longitude using a comma as the delimiter
let parts = split(data[i], ',');
// Check if the line contains at least two values (latitude and longitude)
if (parts.length >= 2) {
// Get latitude and longitude values
let latitude = float(parts[0]);
let longitude = float(parts[1]);
// Update min and max values for latitude and longitude
minLat = min(minLat, latitude);
maxLat = max(maxLat, latitude);
minLon = min(minLon, longitude);
maxLon = max(maxLon, longitude);
}
}
// Loop through the data again to map and draw the points
for (let i = 0; i < data.length; i++) {
// Split each line into latitude and longitude using a comma as the delimiter
let parts = split(data[i], ',');
// Check if the line contains at least two values (latitude and longitude)
if (parts.length >= 2) {
// Get latitude and longitude values
let latitude = float(parts[0]);
let longitude = float(parts[1]);
// Map the coordinates to the canvas using the updated min and max values
let x = map(longitude, minLon, maxLon, 0, width);
let y = map(latitude, minLat, maxLat, height, 0); // Flip y-axis for correct mapping
// Draw a point at the mapped coordinates
stroke(0);
strokeWeight(2);
point(x, y);
}
}
}