import flash.text.GridFitType;
import flash.text.TextField;
import flash.text.TextFormat;
+ import flash.events.*;
import net.systemeD.halcyon.styleparser.*;
import net.systemeD.halcyon.connection.*;
public var layer:int=0; // map layer
public var map:Map; // reference to parent map
public var sprites:Array=new Array(); // instances in display list
+ private var hitzone:Sprite;
public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
embedFonts: true,
antiAliasType: AntiAliasType.ADVANCED,
gridFitType: GridFitType.NONE
};
- [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
- public static var DejaVu:Class;
+// [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
+// public static var DejaVu:Class;
public var nameformat:TextFormat;
this.way = way;
this.map = map;
init();
+ way.addEventListener(Connection.TAG_CHANGE, wayTagChanged);
}
+ private function wayTagChanged(event:TagEvent):void {
+ redraw();
+ }
+
private function init():void {
recalculate();
redraw();
// remove all currently existing sprites
while (sprites.length>0) {
- var d:Sprite=sprites.pop(); d.parent.removeChild(d);
+ var d:DisplayObject=sprites.pop(); d.parent.removeChild(d);
}
// which layer?
for each (var s:* in styles) {
if (s is ShapeStyle) {
- var stroke:Sprite, fill:Sprite, roadname:Sprite, f:Graphics, g:Graphics;
+ var stroke:Shape, fill:Shape, roadname:Sprite, f:Graphics, g:Graphics;
var doStroke:Boolean=false, doDashed:Boolean=false;
var doFill:Boolean=false, fill_colour:uint, fill_opacity:Number;
var doCasing:Boolean=false, doDashedCasing:Boolean=false;
// Set stroke style
if (s.isStroked) {
- stroke=new Sprite(); addToLayer(stroke,1,s.sublayer); g=stroke.graphics;
+ stroke=new Shape(); addToLayer(stroke,1,s.sublayer); g=stroke.graphics;
g.moveTo(map.lon2coord(way.getNode(0).lon), map.latp2coord(way.getNode(0).latp));
g.lineStyle(s.stroke_width, s.stroke_colour, s.stroke_opacity/100,
false, "normal", s.stroke_linecap, s.stroke_linejoin);
// Set fill and casing style
if (s.isFilled || s.isCased) {
- fill=new Sprite(); addToLayer(fill,0); f=fill.graphics;
+ fill=new Shape(); addToLayer(fill,0); f=fill.graphics;
f.moveTo(map.lon2coord(way.getNode(0).lon), map.latp2coord(way.getNode(0).latp));
if (s.isCased) { f.lineStyle(s.casing_width, s.casing_colour, s.casing_opacity/100,
false, "normal", s.stroke_linecap, s.stroke_linejoin); }
// ** to do
}
}
+
+ if ( styles.length == 0 ) {
+ // there's no styles... so add a thin trace
+ var def:Sprite = new Sprite();
+ def.graphics.lineStyle(0.5, 0x808080, 1, false, "normal");
+ solidLine(def.graphics);
+ addToLayer(def, 1);
+ }
+
+ // create a generic "way" hitzone sprite
+ hitzone = new Sprite();
+ hitzone.graphics.lineStyle(4, 0x000000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
+ solidLine(hitzone.graphics);
+ addToLayer(hitzone, 2);
+ hitzone.visible = false;
+
+ var listenSprite:Sprite = new Sprite();
+ listenSprite.hitArea = hitzone;
+ addToLayer(listenSprite, 2);
+ listenSprite.buttonMode = true;
+ listenSprite.mouseEnabled = true;
+ listenSprite.addEventListener(MouseEvent.CLICK, mouseEvent);
+ listenSprite.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent);
+ listenSprite.addEventListener(MouseEvent.MOUSE_OVER, mouseEvent);
+ listenSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseEvent);
+
}
// ------------------------------------------------------------------------------------------
private function rotatedLetter(char:String, t:Number, w:Number, h:Number, a:Number, o:Number):TextField {
var tf:TextField = new TextField();
tf.embedFonts = true;
+ tf.mouseEnabled = false;
+ tf.mouseWheelEnabled = false;
tf.defaultTextFormat = nameformat;
tf.text = char;
tf.width = tf.textWidth+4;
// Add object (stroke/fill/roadname) to layer sprite
- private function addToLayer(s:Sprite,t:uint,sublayer:int=-1):void {
+ private function addToLayer(s:DisplayObject,t:uint,sublayer:int=-1):void {
var l:DisplayObject=Map(map).getChildAt(layer);
var o:DisplayObject=Sprite(l).getChildAt(t);
if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
Sprite(o).addChild(s);
sprites.push(s);
+ if ( s is Sprite ) Sprite(s).mouseEnabled = false;
}
+
+ private function mouseEvent(event:MouseEvent):void {
+ map.wayMouseEvent(event, way);
+ }
+
+ public function setHighlight(highlight:Boolean):void {
+ hitzone.visible = highlight;
+ }
}
}