-
Notifications
You must be signed in to change notification settings - Fork 11
/
createCities.js
66 lines (52 loc) · 2.41 KB
/
createCities.js
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
/**
* Created by ZhaokangYuan on 2016/1/14.
*/
var CreateCities = function (url) {
this.url = url;
this.create = function (scene, radius) {
/*$.getJSON(url, function (cities) {
var material = new THREE.ParticleBasicMaterial({size: 2, vertexColors: true, color: 0xffffff});
var geom = new THREE.Geometry();
for (var i = 0; i < cities.length; i++) {
var lngLat = {lng: cities[i].long, lat: cities[i].lat};
var l = radius * Math.cos(lngLat.lat / 180 * Math.PI);
var x = l * Math.sin(lngLat.lng / 180 * Math.PI);
var y = radius * Math.sin(lngLat.lat / 180 * Math.PI);
var z = l * Math.cos(lngLat.lng / 180 * Math.PI);
var particle = new THREE.Vector3(x, y, z);
geom.vertices.push(particle);
geom.colors.push(new THREE.Color(0x2EFFFF));
}
var system = new THREE.ParticleSystem(geom, material);
scene.add(system);
});*/
d3.csv(url, function (error,data) {
if(error)
console.log(error);
else{
var material = new THREE.ParticleBasicMaterial({size: 0.5, vertexColors: true, color: 0xffffff});
var geom = new THREE.Geometry();
for (var i = 0; i < data.length; i++) {
var id=data[i]['id'];
var short_name=data[i]['short_name'];
var long_name=data[i]['long_name'];
var state=data[i]['state'];
var city=data[i]['city'];
var ip_count=data[i]['ip_count'];
var lat=data[i]['lat'];
var lng=data[i]['lng'];
var lngLat = {lng: lng, lat: lat};
var l = radius * Math.cos(lngLat.lat / 180 * Math.PI);
var x = l * Math.sin(lngLat.lng / 180 * Math.PI);
var y = radius * Math.sin(lngLat.lat / 180 * Math.PI);
var z = l * Math.cos(lngLat.lng / 180 * Math.PI);
var particle = new THREE.Vector3(x, y, z);
geom.vertices.push(particle);
geom.colors.push(new THREE.Color(0x2EFFFF));
}
var system = new THREE.ParticleSystem(geom, material);
scene.add(system);
}
})
}
}