[Mapserver-users] highlight paths
Joe Bussell
joe at otsys.com
Mon Jul 14 15:15:29 PDT 2003
Greetings,
We cheat really. In fact we aren't highlighting the path at the
street level at all. Just zoom in to a clover leaf somewhere and you
will see what I mean. What we are actually doing is creating new line
objects based on the start and end points. These are rendered just
before the street layers, so it appears to be highlighting. The extra
work to get the actual shape elements from our street shapefiles hasn't
seemed worth the effort. At some point I will give this a shot, but for
the time our current solution is 'good enough'.
We are using mapscript to do this. I suppose you could use
Perl::DBI to access the shapefiles, extract the relevant segments,
create a new shapefile (or database table) and rip the image from that.
I would like to hear any other thoughts on this, especially if you
can improve on our technique. In the interest of speeding you up, and
getting the best solution there is, I offer the following snippet of
PERL that does the majic for us:
for my $i (0 .. ($map->{numlayers}-1))
{
my $layer = $map->getLayer($i);
my $route = 0;
if ( $layer->{name} eq "RouteLine" )
{
$route = 1;
}
if ( !$route )
{
$layer->draw( $map, $img );
}
else
{
my $rlayer = $map->getLayerByName( "RouteLine" ) or
carp "Unable to getLayerByName( RouteLine )
$mapscript::ms_error->{message}\n";
my $firstX = 0;
my $firstY = 0;
my $lastX = 0;
my $lastY = 0;
foreach my $tuple ( @$routeHashRef )
{
my $y = $tuple->[ 0 ];
my $x = $tuple->[ 1 ];
my $speed = $tuple->[2];
if ( $lastX == 0 )
{
$firstX = $x;
$firstY = $y;
}
else
{
my $feature = new mapscript::shapeObj(
$mapscript::MS_SHAPE_POLYGON );
$line = new mapscript::lineObj();
$point = new mapscript::pointObj();
$point->{x} = $lastX;
$point->{y} = $lastY;
$line->add( $point );
$point = new mapscript::pointObj();
$point->{x} = $x;
$point->{y} = $y;
$line->add( $point );
$feature->{classindex} = 0;
if ( $speed > 0 )
{
$feature->{text} = int( $speed );
}
$feature->add( $line );
$feature->draw( $map, $rlayer, $img );
}
$lastX = $x;
$lastY = $y;
# carp " ($lastX, $lastY) ";
}
$rlayer->draw( $map, $img );
}
}
The mapfile still controls the render order, so the routeLine must occur
before the street layer.
I hope this is more helpful than distracting. I welcome comment and
encourage debate.
Cordially,
Joe Bussell
www.trafficdodger.com
PS: Do you want to license our complete solution?
Immanuel Manurung wrote:
> Maybe my questions have been asked several times, so first of all, I'm
> sorry :)
>
> I want to make a city pathfinding site like
> http://www.trafficdodger.com/, but I have problems to highlight the
> paths after user submit the query the begin/end locations. Is it
> possible not to use MapScript? Do I need to create a special shape
> layer to display the query? How the http://www.trafficdodger.com/ site
> highlight it with a wide 'path'? (not just put different colors on the
> street objects)
>
> Thanks for your attention.
More information about the MapServer-users
mailing list