-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
215 lines (189 loc) · 7.29 KB
/
test.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html>
<html>
<head>
<title>3D Globe Visualization</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
}
#globe-container {
width: 100%;
height: 100vh;
position: relative;
}
.location-card {
display: none;
position: absolute;
background: rgba(255, 255, 255, 0.9);
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 300px;
z-index: 1000;
}
.location-card h3 {
margin-top: 0;
color: #02814D;
}
.location-card p {
color: #333;
line-height: 1.5;
}
</style>
</head>
<body>
<div id="globe-container"></div>
<div id="location-card" class="location-card">
<h3 id="location-title"></h3>
<p id="location-description"></p>
</div>
<script>
// Initialize Three.js scene
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('globe-container').appendChild(renderer.domElement);
// Create globe
const radius = 5;
const segments = 64;
const geometry = new THREE.SphereGeometry(radius, segments, segments);
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load('https://threejs.org/examples/textures/land_ocean_ice_cloud_2048.jpg');
const material = new THREE.MeshPhongMaterial({ map: texture });
const globe = new THREE.Mesh(geometry, material);
scene.add(globe);
// Add lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xffffff, 1);
pointLight.position.set(10, 10, 10);
scene.add(pointLight);
// Set camera position
camera.position.z = 10;
// Location data with more points
const locations = [
{
name: "Tokyo, Japan",
lat: 35.6762,
lng: 139.6503,
description: "The bustling capital of Japan, known for its unique blend of traditional culture and modern technology."
},
{
name: "New York, USA",
lat: 40.7128,
lng: -74.0060,
description: "The city that never sleeps, featuring iconic landmarks and diverse cultural experiences."
},
{
name: "London, UK",
lat: 51.5074,
lng: -0.1278,
description: "Historic capital of England, blending centuries-old architecture with modern culture."
},
{
name: "Sydney, Australia",
lat: -33.8688,
lng: 151.2093,
description: "Australia's largest city, famous for its iconic Opera House and beautiful harbor."
},
{
name: "Rio de Janeiro, Brazil",
lat: -22.9068,
lng: -43.1729,
description: "Vibrant Brazilian city known for its Carnival celebration and Christ the Redeemer statue."
}
];
// Add location markers
const markerGeometry = new THREE.SphereGeometry(0.1, 16, 16);
const markerMaterial = new THREE.MeshBasicMaterial({ color: 0xFF0088 });
const markers = locations.map(location => {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
const position = latLngToVector3(location.lat, location.lng, radius);
marker.position.copy(position);
marker.userData = location;
globe.add(marker); // Add marker as child of globe instead of scene
return marker;
});
// Convert latitude and longitude to 3D coordinates
function latLngToVector3(lat, lng, radius) {
const phi = (90 - lat) * (Math.PI / 180);
const theta = (lng + 180) * (Math.PI / 180);
const x = -(radius * Math.sin(phi) * Math.cos(theta));
const y = radius * Math.cos(phi);
const z = radius * Math.sin(phi) * Math.sin(theta);
return new THREE.Vector3(x, y, z);
}
// Handle click events
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
window.addEventListener('click', (event) => {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(markers);
if (intersects.length > 0) {
const location = intersects[0].object.userData;
showLocationCard(location, event.clientX, event.clientY);
} else {
hideLocationCard();
}
});
// Add drag rotation
let isDragging = false;
let previousMousePosition = {
x: 0,
y: 0
};
document.addEventListener('mousedown', (e) => {
isDragging = true;
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
const deltaMove = {
x: e.clientX - previousMousePosition.x,
y: e.clientY - previousMousePosition.y
};
globe.rotation.y += deltaMove.x * 0.005;
globe.rotation.x += deltaMove.y * 0.005;
}
previousMousePosition = {
x: e.clientX,
y: e.clientY
};
});
document.addEventListener('mouseup', (e) => {
isDragging = false;
});
// Show/hide location card
function showLocationCard(location, x, y) {
const card = document.getElementById('location-card');
document.getElementById('location-title').textContent = location.name;
document.getElementById('location-description').textContent = location.description;
card.style.display = 'block';
card.style.left = `${x + 10}px`;
card.style.top = `${y + 10}px`;
}
function hideLocationCard() {
document.getElementById('location-card').style.display = 'none';
}
// Animation loop
function animate() {
requestAnimationFrame(animate);
if (!isDragging) {
globe.rotation.y += 0.0005;
}
renderer.render(scene, camera);
}
animate();
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>