Monday, 6 June 2011

How to draw a line between two Markers ?

var polylineClip:PolylineClip = new PolylineClip(map);
map.addChild(polylineClip);

var locations:Array = [ new Location(10,10), new Location (20,20) ];

var polyline:Polyline = new Polyline('poly-id-1', locations);
polylineClip.addPolyline(polyline);


You can also use a PolygonMarker and PolygonClip, and set the polygon marker to not autoclose and not fill.



var polygonClip:PolygonClip = new PolygonClip(map);
map.addChild(polygonClip);

var locations:Array = [ new Location(10,10), new Location (20,20) ];

var polygon:PolygonMarker = new PolygonMarker(map, locations, false);
polygon.fill = false;
polygon.redraw();
polygonClip.attachMarker(polygon, polygon.location);


If you just have one or two lines you can make your own simple overlay like this:



var overlay:Sprite = new Sprite();
map.addChild(overlay);

var loc1:Location = new Location(...); // *** set lat,lon here! ***
var loc2:Location = new Location(...); // *** and here! ***

var onMapChange:Function = function(event:MapEvent):void {
var pt1:Point = map.locationPoint(loc1);
var pt2:Point = map.locationPoint(loc2);
overlay.graphics.clear();
overlay.graphics.lineStyle(2, 0xffffff);
overlay.graphics.moveTo(pt1.x, pt1.y);
overlay.graphics.lineTo(pt2.x, pt2.y);
};

map.addEventListener(MapEvent.PANNED, onMapChange);
map.addEventListener(MapEvent.ZOOMED_BY, onMapChange);
map.addEventListener(MapEvent.EXTENT_CHANGED, onMapChange);




No comments:

Post a Comment