Create export_map_project.py
Browse files- export_map_project.py +79 -0
export_map_project.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import zipfile
|
5 |
+
|
6 |
+
# Load dataset
|
7 |
+
dataset = load_dataset("maringetxway/local")["train"]
|
8 |
+
|
9 |
+
# Create output folder
|
10 |
+
os.makedirs("map_project", exist_ok=True)
|
11 |
+
|
12 |
+
# Save data.json
|
13 |
+
with open("map_project/data.json", "w") as f:
|
14 |
+
json.dump(dataset[:], f)
|
15 |
+
|
16 |
+
# index.html
|
17 |
+
index_html = """<!DOCTYPE html>
|
18 |
+
<html lang="en">
|
19 |
+
<head>
|
20 |
+
<meta charset="UTF-8">
|
21 |
+
<title>World Map from Hugging Face Dataset</title>
|
22 |
+
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
|
23 |
+
<style>
|
24 |
+
html, body {
|
25 |
+
margin: 0;
|
26 |
+
padding: 0;
|
27 |
+
}
|
28 |
+
#map {
|
29 |
+
height: 100vh;
|
30 |
+
width: 100%;
|
31 |
+
}
|
32 |
+
</style>
|
33 |
+
</head>
|
34 |
+
<body>
|
35 |
+
<div id="map"></div>
|
36 |
+
|
37 |
+
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
38 |
+
<script src="script.js"></script>
|
39 |
+
</body>
|
40 |
+
</html>
|
41 |
+
"""
|
42 |
+
with open("map_project/index.html", "w") as f:
|
43 |
+
f.write(index_html)
|
44 |
+
|
45 |
+
# script.js
|
46 |
+
script_js = """const map = L.map('map').setView([20, 0], 2);
|
47 |
+
|
48 |
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
49 |
+
attribution: '© OpenStreetMap contributors'
|
50 |
+
}).addTo(map);
|
51 |
+
|
52 |
+
fetch('data.json')
|
53 |
+
.then(response => response.json())
|
54 |
+
.then(data => {
|
55 |
+
data.forEach(entry => {
|
56 |
+
const lat = parseFloat(entry.latitude || entry.Latitude);
|
57 |
+
const lng = parseFloat(entry.longitude || entry.Longitude);
|
58 |
+
const name = entry.name || entry.Name || 'Unknown';
|
59 |
+
const desc = entry.description || entry.Description || '';
|
60 |
+
|
61 |
+
if (!isNaN(lat) && !isNaN(lng)) {
|
62 |
+
L.marker([lat, lng])
|
63 |
+
.addTo(map)
|
64 |
+
.bindPopup(`<strong>${name}</strong><br>${desc}`);
|
65 |
+
}
|
66 |
+
});
|
67 |
+
});
|
68 |
+
"""
|
69 |
+
with open("map_project/script.js", "w") as f:
|
70 |
+
f.write(script_js)
|
71 |
+
|
72 |
+
# Zip it
|
73 |
+
with zipfile.ZipFile("world_map_project.zip", "w") as zipf:
|
74 |
+
for foldername, subfolders, filenames in os.walk("map_project"):
|
75 |
+
for filename in filenames:
|
76 |
+
filepath = os.path.join(foldername, filename)
|
77 |
+
zipf.write(filepath, os.path.relpath(filepath, "map_project"))
|
78 |
+
|
79 |
+
print("✅ Done! File saved as world_map_project.zip")
|