[Mapserver-users] Limiting min and max scale when using MapScript
Eric Bridger
eric at gomoos.org
Thu Jul 31 03:47:45 PDT 2003
I always set min and max scales by trial and error. In a template you
can display [scale] to see the current scale. In mapscript I use a perl
function taken from the C code.
When using mapscript you can use MINXSCALE and MAXSCALE for LAYER's,
etc. but since you don't have a WEB object (the script must create the
WEB html by itself) setting $map->{web}->{maxscale} will have no affect.
Here's the perl code I use to prevent zooming out beyond the original
map extent:
#########################
# @imgext is the current map extent from the map form
# default is original extent
my $mapext = join(' ',
$map->{extent}->{minx},$map->{extent}->{miny},$map->{extent}->{maxx},$map->{extent}->{maxy});
if($zoom_direction < 0){
my $max_scale = calculateScale($map, $map->{extent}->{minx},
$map->{extent}->{maxx});
my $current_scale = calculateScale($map, $imgext[0], $imgext[2]);
if($current_scale >= $max_scale){
return $mapext;
}
}
#########################################
# 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.
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
On Thu, 2003-07-31 at 09:22, AMC Story wrote:
> Hi there everyone,
>
> Firstly, I was hoping someone could tell me how to arrive at sensible figures
> for minscale and maxscale as specified in the web object? The exact derivation
> of these values has been questioned several times in the archives but I haven't
> yet managed to find an answer, maybe this could be added on to the mapfile
> reference doc?
>
> Also, I think I remember seeing somewhere that if you are using MapScript as
> opposed to the CGI application, you can't specify a minscale and maxscale value
> in the mapfile. I've tried just setting these values in my script:
>
> $current_map->{web}->{maxscale}=some number?;
> $current_map->{web}->{minscale}=some number?;
>
> but whatever values I use this doesn't seem to make any difference.
>
> Can someone let me know how I can stop users from zooming in and out too far?
>
> Thanks very much,
> Ali
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
More information about the MapServer-users
mailing list