1 | |
---|
2 | // Originally 0=x, 1=y, 2=id, 4=tags; |
---|
3 | // now .x, .y, .id, .attr |
---|
4 | |
---|
5 | function Node(id,x,y,attr) { |
---|
6 | this.id=id; |
---|
7 | this.x=x; |
---|
8 | this.y=y; |
---|
9 | this.attr=attr; |
---|
10 | this.tagged=hasTags(attr); |
---|
11 | }; |
---|
12 | |
---|
13 | // Node.ways? |
---|
14 | // Node.removeFromWay? |
---|
15 | // Node.addToWay? |
---|
16 | |
---|
17 | Node.prototype.removeFromAllWays=function() { |
---|
18 | var qway,qs,x,y,attr; |
---|
19 | var waylist=new Array(); var poslist=new Array(); |
---|
20 | for (qway in _root.map.ways) { |
---|
21 | var qdirty=false; |
---|
22 | for (qs=0; qs<_root.map.ways[qway].path.length; qs+=1) { |
---|
23 | if (_root.map.ways[qway].path[qs]==this.id) { |
---|
24 | waylist.push(qway); poslist.push(qs); |
---|
25 | _root.map.ways[qway].path.splice(qs,1); |
---|
26 | qdirty=true; |
---|
27 | } |
---|
28 | } |
---|
29 | if (qdirty) { _root.map.ways[qway].removeDuplicates(); } |
---|
30 | if (qdirty && _root.map.ways[qway].path.length<2) { |
---|
31 | _root.map.ways[qway].remove(); |
---|
32 | } else if (qdirty) { |
---|
33 | _root.map.ways[qway].redraw(); |
---|
34 | _root.map.ways[qway].clean=false; |
---|
35 | } |
---|
36 | } |
---|
37 | if (_root.wayselected) { _root.ws.select(); } |
---|
38 | _root.undo.append(UndoStack.prototype.undo_deletepoint, |
---|
39 | new Array(deepCopy(this),waylist,poslist), |
---|
40 | "deleting a point"); |
---|
41 | }; |
---|
42 | |
---|
43 | Node.prototype.moveTo=function(newx,newy,ignoreway) { |
---|
44 | // ** if this.ways is created, this should loop through it |
---|
45 | this.x=newx; this.y=newy; |
---|
46 | var qchanged; |
---|
47 | for (var qway in _root.map.ways) { |
---|
48 | var qdirty=0; |
---|
49 | for (var qs=0; qs<_root.map.ways[qway].path.length; qs+=1) { |
---|
50 | if (_root.map.ways[qway].path[qs]==this.id) { qdirty=1; } |
---|
51 | } |
---|
52 | if (qdirty && qway!=ignoreway) { _root.map.ways[qway].redraw(); qchanged=qway; } |
---|
53 | } |
---|
54 | return qchanged; // return ID of last changed way |
---|
55 | }; |
---|
56 | |
---|
57 | Node.prototype.renumberTo=function(id) { |
---|
58 | var old=this.id; |
---|
59 | nodes[id]=new Node(id,this.x,this.y,this.attr); |
---|
60 | delete this; |
---|
61 | for (var qway in _root.map.ways) { |
---|
62 | for (qs=0; qs<_root.map.ways[qway].path.length; qs+=1) { |
---|
63 | if (_root.map.ways[qway].path[qs]==old) { |
---|
64 | _root.map.ways[qway].path[qs]=id; |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | }; |
---|
69 | |
---|
70 | |
---|
71 | // ------------------------------------------------------------------------ |
---|
72 | // Support functions |
---|
73 | |
---|
74 | // hasTags - does a tag hash contain any significant tags? |
---|
75 | |
---|
76 | function hasTags(a) { |
---|
77 | var c=false; |
---|
78 | for (var j in a) { |
---|
79 | if (j!='created_by' && a[j]!='' && j!='source' && j.indexOf('tiger:')!=0) { c=true; } |
---|
80 | } |
---|
81 | return c; |
---|
82 | } |
---|