diff --git a/have-been-to/README.md b/have-been-to/README.md new file mode 100644 index 0000000..b7e0ce7 --- /dev/null +++ b/have-been-to/README.md @@ -0,0 +1,6 @@ +https://eoimages.gsfc.nasa.gov/images/imagerecords/144000/144898/BlackMarble_2016_01deg.jpg + +https://eoimages.gsfc.nasa.gov/images/imagerecords/147000/147190/eo_base_2020_clean_3600x1800.png + + +https://visibleearth.nasa.gov/collection/1484/blue-marble diff --git a/have-been-to/__pycache__/database.cpython-312.pyc b/have-been-to/__pycache__/database.cpython-312.pyc index 13b5eb0..766532c 100644 Binary files a/have-been-to/__pycache__/database.cpython-312.pyc and b/have-been-to/__pycache__/database.cpython-312.pyc differ diff --git a/have-been-to/app.py b/have-been-to/app.py index 6b204d1..1cfe390 100644 --- a/have-been-to/app.py +++ b/have-been-to/app.py @@ -1,6 +1,6 @@ from flask import Flask, render_template, request, jsonify from flask_cors import CORS -from database import init_db, add_country, remove_country, get_all_countries, save_highlight_color, get_highlight_color +from database import init_db, add_country, remove_country, get_all_countries, save_highlight_color, get_highlight_color, save_map_type, get_map_type import requests app = Flask(__name__) @@ -56,5 +56,16 @@ def get_highlight_color_route(): color = get_highlight_color() return jsonify({"color": color}) +@app.route('/save_map_type', methods=['POST']) +def save_map_type_route(): + map_type = request.json['mapType'] + save_map_type(map_type) + return jsonify({"success": True}) + +@app.route('/get_map_type', methods=['GET']) +def get_map_type_route(): + map_type = get_map_type() + return jsonify({"mapType": map_type}) + if __name__ == '__main__': app.run(debug=True, port=5001) diff --git a/have-been-to/countries.db b/have-been-to/countries.db index 39a6550..7fee22d 100644 Binary files a/have-been-to/countries.db and b/have-been-to/countries.db differ diff --git a/have-been-to/database.py b/have-been-to/database.py index 80fda62..dd13182 100644 --- a/have-been-to/database.py +++ b/have-been-to/database.py @@ -46,3 +46,18 @@ def get_highlight_color(): result = c.fetchone() conn.close() return result[0] if result else None + +def save_map_type(map_type): + conn = sqlite3.connect('countries.db') + c = conn.cursor() + c.execute("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)", ('map_type', map_type)) + conn.commit() + conn.close() + +def get_map_type(): + conn = sqlite3.connect('countries.db') + c = conn.cursor() + c.execute("SELECT value FROM settings WHERE key = 'map_type'") + result = c.fetchone() + conn.close() + return result[0] if result else 'standard' diff --git a/have-been-to/static/images/BlackMarble_2016_01deg.jpg b/have-been-to/static/images/BlackMarble_2016_01deg.jpg new file mode 100644 index 0000000..bfe6cef Binary files /dev/null and b/have-been-to/static/images/BlackMarble_2016_01deg.jpg differ diff --git a/have-been-to/static/images/eo_base_2020_clean_3600x1800.png b/have-been-to/static/images/eo_base_2020_clean_3600x1800.png new file mode 100644 index 0000000..b39d5e1 Binary files /dev/null and b/have-been-to/static/images/eo_base_2020_clean_3600x1800.png differ diff --git a/have-been-to/static/images/world.oceanmask.5400x2700.png b/have-been-to/static/images/world.oceanmask.5400x2700.png new file mode 100644 index 0000000..fe02dd4 Binary files /dev/null and b/have-been-to/static/images/world.oceanmask.5400x2700.png differ diff --git a/have-been-to/static/js/globe.js b/have-been-to/static/js/globe.js index b08a5e5..325241f 100644 --- a/have-been-to/static/js/globe.js +++ b/have-been-to/static/js/globe.js @@ -8,6 +8,13 @@ let allCountries = []; // 存储所有国家名称 let worldData; // 存储世界地理数据 let worldDataLoaded = false; // 标记世界数据是否已加载 let highlightColor = 0xFFFF00; // 默认高亮颜色 +let currentMapType = 'standard'; +const mapTextures = { + standard: '/static/images/eo_base_2020_clean_3600x1800.png', + night: '/static/images/BlackMarble_2016_01deg.jpg', + gray: '/static/images/world.oceanmask.5400x2700.png', + satellite: '/static/images/world.topo.bathy.200412.3x5400x2700.jpg' +}; export { init, addCountry, removeCountry, exportMap }; @@ -29,13 +36,34 @@ function init() { renderer.setSize(window.innerWidth, window.innerHeight); document.getElementById('map').appendChild(renderer.domElement); - const mapTexture = new THREE.TextureLoader().load('/static/images/world.topo.bathy.200412.3x5400x2700.jpg'); + const mapTexture = new THREE.TextureLoader().load(mapTextures[currentMapType]); const material = new THREE.MeshBasicMaterial({ map: mapTexture }); map = new THREE.Mesh(new THREE.PlaneGeometry(360, 180), material); scene.add(map); camera.position.z = 100; + setupControls(); + setupColorPicker(); + loadHighlightColor(); + loadSavedMapType(); + + loadWorldData(); + animate(); + loadCountries(); + loadAllCountries(); + setupAutocomplete(); + + window.addEventListener('resize', onWindowResize, false); + + // Move the event listeners setup to a separate function + setupEventListeners(); + + // Update renderer size + updateRendererSize(); +} + +function setupControls() { controls = new OrbitControls(camera, renderer.domElement); controls.enableRotate = false; controls.enablePan = true; @@ -53,34 +81,30 @@ function init() { controls.minZoom = 1; controls.maxZoom = 5; controls.update(); +} - setupColorPicker(); - loadHighlightColor(); +function setupEventListeners() { + const zoomInButton = document.getElementById('zoom-in'); + const zoomOutButton = document.getElementById('zoom-out'); + const sidebarToggle = document.querySelector('button[x-on\\:click]'); - loadWorldData(); - animate(); - loadCountries(); - loadAllCountries(); - setupAutocomplete(); + if (zoomInButton) { + zoomInButton.addEventListener('click', () => { + controls.zoomIn(); + }); + } - window.addEventListener('resize', onWindowResize, false); + if (zoomOutButton) { + zoomOutButton.addEventListener('click', () => { + controls.zoomOut(); + }); + } - // Add event listeners for zoom buttons - document.getElementById('zoom-in').addEventListener('click', () => { - controls.zoomIn(); - }); - document.getElementById('zoom-out').addEventListener('click', () => { - controls.zoomOut(); - }); + if (sidebarToggle) { + sidebarToggle.addEventListener('click', updateRendererSize); + } - // Update renderer size - updateRendererSize(); - - // Add event listener for sidebar toggle - document.querySelector('button[x-on\\:click]').addEventListener('click', updateRendererSize); - - // Add event listener for window resize - window.addEventListener('resize', updateRendererSize); + setupMapSelection(); } function onWindowResize() { @@ -380,7 +404,11 @@ function exportMap() { exportCamera.position.z = 100; // Add the map and highlighted countries to the export scene - exportScene.add(map.clone()); + const exportMap = new THREE.Mesh( + new THREE.PlaneGeometry(360, 180), + new THREE.MeshBasicMaterial({ map: map.material.map }) + ); + exportScene.add(exportMap); highlightedCountries.forEach(country => { exportScene.add(country.clone()); }); @@ -416,3 +444,50 @@ function updateRendererSize() { renderer.setSize(width, height); } + +function setupMapSelection() { + const mapSelect = document.getElementById('map-select'); + if (mapSelect) { + mapSelect.addEventListener('change', (event) => { + changeMapType(event.target.value); + }); + } else { + console.error('Map select element not found'); + } +} + +function changeMapType(mapType) { + if (mapType !== currentMapType) { + currentMapType = mapType; + const newTexture = new THREE.TextureLoader().load(mapTextures[mapType]); + map.material.map = newTexture; + map.material.needsUpdate = true; + saveMapType(mapType); + } +} + +function loadSavedMapType() { + fetch('/get_map_type') + .then(response => response.json()) + .then(data => { + if (data.mapType) { + changeMapType(data.mapType); + document.getElementById('map-select').value = data.mapType; + } + }); +} + +function saveMapType(mapType) { + fetch('/save_map_type', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ mapType: mapType }), + }); +} + +// Move this to the end of the file +document.addEventListener('DOMContentLoaded', () => { + init(); +}); diff --git a/have-been-to/templates/index.html b/have-been-to/templates/index.html index 1a3b42a..c5561a8 100644 --- a/have-been-to/templates/index.html +++ b/have-been-to/templates/index.html @@ -39,6 +39,15 @@