-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCountry.js
More file actions
60 lines (48 loc) · 1.84 KB
/
Copy pathCountry.js
File metadata and controls
60 lines (48 loc) · 1.84 KB
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
let Country = function(geoCoords, properties, lineColor, shapeColor) {
this.geoCoords = geoCoords;
this.properties = properties;
this.lineColor = (!lineColor) ? 0xff0000 : lineColor;
this.shapeColor = (!shapeColor) ? 0x000000 : shapeColor;
}
Country.prototype = {
createLine : function() {
const geometry = new THREE.Geometry();
for (let P of this.geoCoords.coordinates) {
if(this.geoCoords.type === "MultiPolygon"){
P = P[0];
}
let p0 = new THREE.Vector3(P[0][0], P[0][1], 0);
for (let i = 1; i < P.length; ++ i) {
let p1 = new THREE.Vector3(P[i][0], P[i][1], 0);
geometry.vertices.push(p0, p1);
p0 = p1;
}
}
let mat = new THREE.LineBasicMaterial({color: this.lineColor});
let lineSegments = new THREE.LineSegments(geometry, mat);
lineSegments.userData = this;
return lineSegments;
},
createShape : function() {
let vecs2 = [];
let shapearray = [];
for (let P of this.geoCoords.coordinates) {
if(this.geoCoords.type === "MultiPolygon") {
P = P[0];
}
let p0 = new THREE.Vector2(P[0][0], P[0][1]);
for (let i = 1; i < P.length; ++ i) {
let p1 = new THREE.Vector2(P[i][0], P[i][1]);
vecs2.push(p0, p1);
p0 = p1;
}
shapearray.push(new THREE.Shape(vecs2));
vecs2 = [];
}
let mat = new THREE.MeshBasicMaterial({color: this.shapeColor});
let shapeGeo = new THREE.ShapeBufferGeometry(shapearray);
let mesh = new THREE.Mesh( shapeGeo, mat ) ;
mesh.userData = this;
return mesh;
}
};