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:
(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
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
1
person likes this idea
I like this idea!
Tell me when this idea gets some attention.
The more people who like this idea, the more it gets noticed.
The more people who like this idea, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Hi Chris,
Thanks for sharing your solution - it looks good to me!
I've not worked much with the Flash 10 APIs myself, so it's interesting to see how people are using them.
As for coding strategies for this sort of thing... Personally I would have made a copy of PolylineClip and modified it for my own needs. I'm not a fan of subclasses unless I have many classes with lots of shared functionality. But your approach is sound, I wouldn't worry about my opinion :) -
Hi RandomEtc,
thanks for the reply. actually I'm not a fan of subclasses either, but I did not want to touch or modify the modestmaps api, so that I can use a new release of modestmaps right away without reimplementing my changes. By the way, is anybody still working on it or is it not getting developed any further?
do you think it is possible to get this "feature" into the modestmaps api, maybe if we rewrite my implementation so that it targets flash player 9?
regards
chris -
If you'd like to fix up the polyline clip so it works with moveTo lineTo as your Flash 10 one does, but in Flash 9, then I'd be happy to apply a patch. If you'd like to make other similar changes/improvements to the API then get in touch (tom at stamen.com) and we can see about subversion access.
We're still working on Modest Maps - I'm a little bit behind on the changes I put in the roadmap but I'm still planning on getting to them soon. -
Inappropriate?Hey RandomEtc,
just wanted to say that i did not forget about this, but these days i did not have a minute of free time. I will post the code for flash 9 as soon as i manage to implement it.
Regards
Chris -
Hello,
sorry that it has taken me so long, but I really have had no time. I was going to go for a bigger fix but right now I would just like to post the minimal solution to solve this issue:
// Clip each point and draw if visible
if (clipLineToRect(tPoint1,tPoint2,boundaryWindow)) {
if (i == 1 || !tPoint1.equals(localPointsArray[i-1])) {
this.graphics.moveTo(tPoint1.x,tPoint1.y);
}
this.graphics.lineTo(tPoint2.x,tPoint2.y);
}
all that should be needed is adding this extra if clause. i would be really happy if this was tested and implemented into the modestmaps lib inside the PolylineClip class in the method updatePolyline
i have some ideas for future enhancements, but i unfortunately dont have time :(
Loading Profile...



EMPLOYEE