[Mapserver-users] draw a shape--use the MAXSCALE and label stuff defined in mapfile

Eric Bridger eric at gomoos.org
Tue Jan 20 10:18:12 EST 2004


On Sat, 2004-01-17 at 20:30, Ed Martin wrote:
> i'm drawing the individual shapes instead of just the layer to control 
> the shapes that get drawn but it isn't adding the label and it isn't 
> obeying the maxscale defined in the map file, how do i make it add the 
> label and have the maxscale, i'm using php/mapscript and here is a part 
> of what i have
> 
> $cities_layer = $map->getLayerByName('Cities');
> //open the layer
> $cities_layer->open();
> $city_shape = $cities_layer->getShape(-1, $city_id);
> $cities_layer->close();
> $city_shape->draw($map,$cities_layer,$image);
> $city_shape->free();
 
I'm pretty sure that when using mapscript you must handle all this
yourself if you are not using $cities_layer->draw().  
You can try setting:
$cities_layer->{text} = $my_label. You can grab the label from the dbf
file using something like XBase.pm.

You'll also need to calculate the scale yourself.
Here is a perl example:
#########################################
# 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) = @_;
    
    my $minx = $map->{extent}->{minx};
    my $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);
}







More information about the mapserver-users mailing list