imagemaps with mapscript, part 2

Robert Chavez rchavez at perseus.tufts.edu
Wed Mar 15 13:05:57 EST 2000


Thanks Steve.

I've put together a quick and dirty little Perl routine that does the
job
too, for what it's worth.  Seems to work well so far.

I'm getting the coordinates for the shapes I want to render from a
Postgres
database -- these coordinates are retrieved in another routine and
stored
in @polygon in the form (point1x, point1y, point2x, point2y, point3x,
point3y ...),

Rob

sub create_imagemap {

    #Read image width and height from map file
    $imgwidth = $map->{width};
    $imgheight = $map->{height};

    #@polygon is a simple list that stores the real world coordinates of

the object pulled from the database
    @vertices = @polygon;

    #loop through the list grabbing each x and y coordinate and
converting
the geo-coordinate to image coordinates
    while (@vertices) {

         #grab first coordinate, remove any parentheses
        $xvert = shift(@vertices);
        $xvert =~ s/[\(\)]//g;

         #convert x map coordinate to image coordinates
        $cellsizex = (($map->{extent}->{maxx} -
$map->{extent}->{minx})/($imgwidth - 1));
        $ximg = (($xvert - $map->{extent}->{minx})/$cellsizex);

        #add image coord. to the new list
        push (@imgshape,$ximg);

        #grab second coordinate, remove any parentheses
        $yvert = shift(@vertices);
       $yvert =~ s/[\(\)]//g;

        #convert y map coordinate to image coordinates
        $cellsizey = (($map->{extent}->{maxy} -
$map->{extent}->{miny})/($imgheight - 1));
        $yimg = (($map->{extent}->{maxy} - $yvert)/$cellsizey);

        #add image coord. to the new list
        push (@imgshape,$yimg);

       }

    #form the <area> tag for html output
    $coords = join(",", at imgshape);
    $area = "\<area shape=\"polygon\" coords=\"$coords\"
href=\"URL-HERE\"\>\n";
    print STDERR "$area";
    push (@areas, $area);
}



Stephen Lime wrote:

> The easiest way would be to add a method to a shapeObj to apply a
> map to it. That is to clip, thin and transform the coordinates. It's a

> pretty easy addition. However, I've frozen development until I get the

> webCVS running with the folks at the UMN. It'll be a couple of weeks
> before I can make the changes.
>
> Steve
>
> Stephen Lime




More information about the mapserver-users mailing list