alt-click (for now) to bring ways in from vector background layers
[potlatch2.git] / net / systemeD / halcyon / MapPaint.as
1 package net.systemeD.halcyon {
2
3         import flash.display.Sprite;
4         import flash.display.DisplayObject;
5         import net.systemeD.halcyon.NodeUI;
6         import net.systemeD.halcyon.WayUI;
7         import net.systemeD.halcyon.connection.Node;
8         import net.systemeD.halcyon.connection.Way;
9         import net.systemeD.halcyon.styleparser.RuleSet;
10         import net.systemeD.halcyon.vectorlayers.VectorLayer;
11         import net.systemeD.halcyon.Globals;
12
13     public class MapPaint extends Sprite {
14
15                 public var map:Map;
16                 public var minlayer:int;
17                 public var maxlayer:int;
18                 public var ruleset:RuleSet;                                             // rules
19                 public var wayuis:Object=new Object();                  // sprites for ways and (POI/tagged) nodes
20                 public var nodeuis:Object=new Object();                 //  |
21                 public var isBackground:Boolean = true;                 // is it a background layer or the core paint object?
22
23                 // Set up layering
24                 // [layer][3]                   - names
25                 // [layer][2][sublayer] - stroke
26                 // [layer][1]                   - casing
27                 // [layer][0]                   - fill
28
29                 public function MapPaint(map:Map,minlayer:int,maxlayer:int) {
30                         this.map=map;
31                         this.minlayer=minlayer;
32                         this.maxlayer=maxlayer;
33
34                         for (var l:int=minlayer; l<=maxlayer; l++) {    // each layer (10 is +5, 0 is -5)
35                                 var s:Sprite = getHitSprite();                  //  |
36                                 s.addChild(getPaintSprite());                           //      | 0 fill
37                                 s.addChild(getPaintSprite());                           //      | 1 casing
38                                 var t:Sprite = getPaintSprite();                        //  | 2 stroke
39                                 for (var j:int=0; j<11; j++) {                          //      |  | ten sublayers
40                                         t.addChild(getPaintSprite());                   //  |  |  |
41                                 }                                                                                       //  |  |  |
42                                 s.addChild(t);                                                          //  |  |
43                                 s.addChild(getPaintSprite());                           //      | 3 names
44                                 s.addChild(getPaintSprite());                           //      | 4 nodes
45                                 s.addChild(getHitSprite());                                 //  | 5 entity hit tests
46                                 addChild(s);                                                            //  |
47                         }
48                         addChild(getPaintSprite());                                     // name sprite
49                 }
50                 
51                 public function get ready():Boolean {
52                         if (!ruleset) { return false; }
53                         if (!ruleset.loaded) { return false; }
54                         return true;
55                 }
56
57 /*              public function addToLayer(s:DisplayObject, layer:int, t:uint, sublayer:int=-1) {
58                         var l:DisplayObject=getChildAt(layer-minlayer);
59                         var o:DisplayObject=Sprite(l).getChildAt(t);
60                         if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
61                         Sprite(o).addChild(s);
62                         sprites.push(s);
63             if ( s is Sprite ) {
64                 Sprite(s).mouseEnabled = false;
65                 Sprite(s).mouseChildren = false;
66             }
67                 }
68 */
69
70                 public function createWayUI(way:Way):WayUI {
71                         wayuis[way.id]=new WayUI(way,this,false);
72                         return wayuis[way.id];
73                 }
74
75                 public function createNodeUI(node:Node):NodeUI {
76                         nodeuis[node.id]=new NodeUI(node,this,0,false);
77                         return nodeuis[node.id];
78                 }
79
80                 public function deleteWayUI(way:Way):void {
81                         wayuis[way.id].removeSprites();
82                         delete wayuis[way.id];
83                 }
84
85                 public function deleteNodeUI(node:Node):void {
86                         nodeuis[node.id].removeSprites();
87                         delete nodeuis[node.id];
88                 }
89                 
90                 public function renumberWayUI(way:Way,oldID:int):void {
91                         if (!wayuis[oldID]) { return; }
92                         wayuis[way.id]=wayuis[oldID];
93                         delete wayuis[oldID];
94                 }
95
96                 public function renumberNodeUI(node:Node,oldID:int):void {
97                         if (!nodeuis[oldID]) { return; }
98                         nodeuis[node.id]=nodeuis[oldID];
99                         delete nodeuis[oldID];
100                 }
101
102         private function getPaintSprite():Sprite {
103             var s:Sprite = new Sprite();
104             s.mouseEnabled = false;
105             s.mouseChildren = false;
106             return s;
107         }
108
109         private function getHitSprite():Sprite {
110             var s:Sprite = new Sprite();
111             return s;
112         }
113
114                 public function redraw():void {
115                         for each (var w:WayUI in wayuis) { w.recalculate(); w.redraw(); }
116                         for each (var p:NodeUI in nodeuis) { p.redraw(); }
117                 }
118
119                 public function redrawPOIs():void {
120                         for each (var p:NodeUI in nodeuis) { p.redraw(); }
121                 }
122                 
123                 public function findSource():VectorLayer {
124                         var v:VectorLayer;
125                         for each (v in map.vectorlayers) {
126                                 if (v.paint==this) { return v; }
127                         }
128                         return null;
129                 }
130         }
131 }