-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkers.jsx
70 lines (53 loc) · 1.98 KB
/
markers.jsx
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
// app/components/globe/markers.jsx
import * as THREE from 'three';
import { toSphereCoordinates } from './utils/utils';
import { config, groups, elements } from '~/components/globe/utils/config';
import Marker from './marker';
class Markers extends THREE.Group {
constructor(props) {
super(props);
const { countries = [], markerRadius = 2 } = props;
this.countries = countries;
this.radius = config.sizes.globe + config.sizes.globe * config.scale.markers;
this.markerGeometry = new THREE.SphereGeometry(markerRadius, 8, 8);
this.markerMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0.8,
});
this.markers = new THREE.Group();
this.markers.name = 'GlobeMarkers';
groups.markers = this.markers;
this.create();
}
create() {
if (!Array.isArray(this.countries)) {
console.error("Countries is not an array:", this.countries);
return;
}
const allCoords = [];
for (let country of this.countries) {
if (country.latitude && country.longitude) {
const lat = +country.latitude;
const lng = +country.longitude;
const cords = toSphereCoordinates(lat, lng, this.radius);
allCoords.push(cords);
const marker = new Marker({
textColor: 'white',
pointColor: this.markerMaterial.color.getHex(),
glowColor: this.markerMaterial.color.getHex(),
cords: cords,
label: country.name,
geometry: this.markerGeometry,
material: this.markerMaterial
});
this.markers.add(marker.getGroup());
elements.markers.push(marker);
}
}
groups.globe.add(this.markers);
}
render() {
return null;
}
}
export default Markers;