Get your own customer support community
 

Polyline Overlays without circles in them

Hello,

i was playing around with the Polyline Overlay drawing a route on a map. Unfortunately the polyline had some circles in it, because every line segment in it was drawn with a moveTo and lineTo command, so that it could be clipped. See the circles in the following picture:



The circles always appear, when not using alpha = 1.

So i thought, why not only call a new moveTo command when the previous line segment did not have to be drawn. So I extended the PolylineClip class and overrode the updatePolyline function as following:

override public function updatePolyline(polyline:Polyline):void
{
var w:Number = map.getWidth() * 2;
var h:Number = map.getHeight() * 2;

var boundaryWindow:Rectangle=new Rectangle(-w/2,-h/2,w,h);

var commands:Vector.<int> = new Vector.</int><int>();
var data:Vector.</int><number> = new Vector.</number><number>();
var nextCommand:int = GraphicsPathCommand.MOVE_TO;

// Calculate local coordinates for each point
for (var i:uint = 1; i < polyline.locationsArray.length;i++)
{
var p1:Point = map.locationPoint(polyline.locationsArray[i - 1] as Location, this);
var p2:Point = map.locationPoint(polyline.locationsArray[i] as Location, this);
if (clipLineToRect(p1, p2, boundaryWindow)) {
commands.push(nextCommand);
nextCommand = GraphicsPathCommand.LINE_TO;
data.push(p1.x, p1.y);
} else {
nextCommand = GraphicsPathCommand.MOVE_TO;
}
}
this.graphics.lineStyle(polyline.lineThickness,polyline.lineColor,polyline.lineAlpha,polyline.pixelHinting,polyline.scaleMode,polyline.caps,polyline.joints,polyline.miterLimit);
this.graphics.drawPath(commands, data);
}
</number>


(SORRY: The forum messed up the code a little, it's supposed to be var commands:Vector.<int> = new Vector.<int>(); and in the data one the theres the same problem)

As you can see, I am targeting flash player 10 with this solution already using the vector type and the drawPath command. Now the result looks like this:



So now I would like to know, what you think about this solution. Would there have been another possibility to achieve this without subclassing PolylineClip? Or would there be a better way to do this with subclassing PolylineClip?

Or is there a chance of getting this into the modestmaps api, so that i can throw my subclass away and it always acts like this?

Regards
Chris
 
happy I’m confident
Inappropriate?
1 person likes this idea

User_default_medium