import flash.text.GridFitType;
import flash.text.TextField;
import flash.text.TextFormat;
+ import flash.geom.Matrix;
+ import flash.geom.Point;
import net.systemeD.halcyon.connection.Node;
import net.systemeD.halcyon.connection.Connection;
import net.systemeD.halcyon.styleparser.*;
public var icon:Sprite; // instance in display list
public var name:Sprite; // |
private var iconname:String=''; // name of icon
+ private var heading:Number=0; // heading within way
+ private var rotation:Number=0; // rotation applied to this POI
public var loaded:Boolean=false;
public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
// [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
// public static var DejaVu:Class;
- public function POI(node:Node, map:Map, sl:StyleList=null) {
+ public function POI(node:Node, map:Map, sl:StyleList=null, rotation:Number=0) {
this.map = map;
this.node = node;
+ this.rotation = rotation;
redraw(sl);
node.addEventListener(Connection.NODE_MOVED, nodeMoved);
}
public function redraw(sl:StyleList=null):Boolean {
var tags:Object = node.getTagsCopy();
+ tags['_heading']=heading;
// ** apply :hover etc.
if (!sl) { sl=map.ruleset.getStyles(this.node,tags); }
if (!sl.hasStyles() && iconname=='') { return false; }
if (sl.pointStyles[sublayer]) {
var s:PointStyle=sl.pointStyles[sublayer];
r=true;
+ if (s.rotation) { rotation=s.rotation; }
if (s.icon_image!=iconname) {
// 'load' icon (actually just from library)
if (map.ruleset.images[s.icon_image]) {
private function updatePosition():void {
if (!loaded) { return; }
- icon.x=map.lon2coord(node.lon)-icon.width/2;
- icon.y=map.latp2coord(node.latp)-icon.height/2;
+ icon.x=0; icon.y=0; icon.rotation=0;
+
+ var m:Matrix=new Matrix();
+// m.identity();
+ m.translate(-icon.width/2,-icon.height/2);
+ m.rotate(rotation);
+ m.translate(map.lon2coord(node.lon),map.latp2coord(node.latp));
+ icon.transform.matrix=m;
}
}
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
+ public var heading:Array=new Array(); // angle at each node
private var stateClasses:Object = new Object();
private var hitzone:Sprite;
private var listenSprite:Sprite;
public function recalculate():void {
var lx:Number, ly:Number, sc:Number;
+ var node:Node, latp:Number, lon:Number;
var cx:Number=0, cy:Number=0;
pathlength=0;
patharea=0;
lx = way.getNode(way.length-1).lon;
ly = way.getNode(way.length-1).latp;
for ( var i:uint = 0; i < way.length; i++ ) {
- var node:Node = way.getNode(i);
- var latp:Number = node.latp;
- var lon:Number = node.lon;
+ node = way.getNode(i);
+ latp = node.latp;
+ lon = node.lon;
+
+ // length and area
if ( i>0 ) { pathlength += Math.sqrt( Math.pow(lon-lx,2)+Math.pow(latp-ly,2) ); }
sc = (lx*latp-lon*ly)*map.scalefactor;
cx += (lx+lon)*sc;
cy += (ly+latp)*sc;
patharea += sc;
+
+ // heading
+ if (i>0) { heading[i-1]=Math.atan2((lon-lx),(latp-ly)); }
+
lx=lon; ly=latp;
}
+ heading[way.length-1]=heading[way.length-2];
pathlength*=map.scalefactor;
patharea/=2;
}
// ** draw icons
+ var r:Number;
for (var i:uint = 0; i < way.length; i++) {
var node:Node = way.getNode(i);
if (map.pois[node.id]) {
} else if (node.hasTags()) {
sl=map.ruleset.getStyles(node,node.getTagsHash());
if (sl.hasStyles()) {
- map.pois[node.id]=new POI(node,map,sl);
+ if (i==0) { r= heading[i]; }
+ else { r=(heading[i]+heading[i-1])/2; }
+ map.pois[node.id]=new POI(node,map,sl,r);
// ** this should be done via the registerPOI/event listener mechanism,
// but that needs a bit of reworking so we can pass in a styleList
// (otherwise we end up computing the styles twice which is expensive)
public var icon_image:String;
public var icon_width:uint;
public var icon_height:uint;
+ public var rotation:Number;
override public function get properties():Array {
return [
- 'icon_image','icon_width','icon_height'
+ 'icon_image','icon_width','icon_height','rotation'
];
}
}