ok - got zoom to work - another question

Eric Bridger eric at GOMOOS.ORG
Mon Nov 22 12:52:43 EST 2004


At 08:39 AM 11/22/2004 -0800, Joseph Norris wrote:
>Everyone,
>
>I have my zoom working but now I would like to tackle something else.  I am
>putting an ellipse in the zip polygons if there is a 1-more teachers there.
>For each zip there maybe a max of 10 teachers.  I would like an ellipse or
>symbol for each one so that when the user zooms into the polygon they can
>see a symbol for each teacher. Can I do this within the class?  If so how or
>would be the best way to handle this?


You can do this in the map file by creating two layers and using MAXSCALE, MINSCALE.
Layer 1 has one ellipse per zip wherever there are 1-10 teachers.
MINSCALE is set so that it won't appear when you are zoomed in.
Layer 2 has one ellipse for each teacher and has MAXSCALE set so that it turns on when Layer 1 is turned off.

Of course if you are using Perl Mapscript you will need to calculate the scale yourself and turn on and off the layers yourself.
Here's and example:

my $current_scale = calculateScale($map, $imgext[0], $imgext[2]);
# From mapserver3.6.4: mapscale.c msCalculateScale().  This is not a precision thing. We don't worry about
# msAdjustExtent() since in all our maps, image SIZE has same aspect ratio as the map EXTENT.
# $minx and $maxx are optional in which case the current extent of the map is used.

# Be careful about the current map's extent. zoomMap() changes the extents.

sub calculateScale{
    my ($map, $minx, $maxx) = @_;
    if(!$minx){
        $minx = $map->{extent}->{minx};
        $maxx = $map->{extent}->{maxx};
    }
    my @inchesPerUnit = (1, 12, 63360.0, 39.3701, 39370.1, 4374754);
    my $width = $map->{width};
    my $units = $map->{units}; # index into unitsPerUnit array
    my $resolution = $map->{resolution};
    my $md = $width / ($resolution * $inchesPerUnit[$units]);
    my $gd = $maxx - $minx;
    return($gd/$md);
}

Eric



More information about the mapserver-users mailing list