-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathways.js
70 lines (67 loc) · 2.49 KB
/
ways.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
67
68
69
70
function Ways(){
this.items = {};
this.modules = {}; //I have to go deeper.
this.from_xml = function(xml){
var nds, child, way, results = evaluateXPath(xml, "/osm/way[not(tag/@k='building')]");
while(way = results.iterateNext()){
//if(parseInt(way.getAttribute("version"))>3) continue;
id = parseInt(way.getAttribute("id"));
if(processed.ways.indexOf(id) > -1) continue;
ver = parseInt(way.getAttribute("version"));
var tmpway = {};
nds = [];
tmpway.ver = ver;
for(var i=0; i<way.children.length; i++){
child = way.children[i];
if(child.tagName==='nd') nds.push(parseInt(child.getAttribute("ref")));
}
var waypoints = [];
for(i=0; i<nds.length; i++){
ref = nds[i];
waypoints.push(nodes[ref]);
}
tmpway.nodes = new Uint32Array(nds);
tmpway.points = waypoints;
for(mid in this.modules){
this.modules[mid].parse_itm(tmpway, way);
}
/*for(var i=0; i<way.children.length; i++){
child = way.children[i];
if(child.tagName==='tag'){
var k = child.getAttribute("k");
if(k==='name') tmpway.name = child.getAttribute("v");
else if(k==='landuse') tmpway.landuse = child.getAttribute("v");
else if(k==='barrier') tmpway.barrier = child.getAttribute("v");
else if(k==='leisure') tmpway.leisure = child.getAttribute("v");
}
}*/
if(processed.ways.indexOf(id)===-1) {
this.items[id] = tmpway;
processed.ways.push(id);
}
delete way;
}
delete results;
}
this.get_mesh = function(meshgroup){
var wayshapes = [];
for(mid in this.modules){
this.modules[mid].get_mesh(meshgroup);
}
for(way in this.items){
try {
//Path
wayshapes.push(CPath(this.items[way].points, 0.8));
} catch (e){
console.warn(e);
}
}
meshgroup.add( CMesh(wayshapes, Math.round(Math.random()*0xffffff)) );
}
this.to_render = function(camera){
for(mid in this.modules){
this.modules[mid].to_render(camera);
}
}
}
modules.ways = new Ways();