[mapserver-users] svg output label anomalies
sbauman at abt.net
sbauman at abt.net
Tue Feb 16 14:59:21 PST 2010
I'm writing a street mapping application that has two output formats:
a png file to the web browser and an svg file for further editing and
printing via inkscape. I'm using a single map file with two output
formats like this:
OUTPUTFORMAT
NAME png
DRIVER "GD/PNG"
MIMETYPE "image/png"
IMAGEMODE PC256
EXTENSION "png"
END
OUTPUTFORMAT
NAME svg
MIMETYPE "image/svg+xml"
DRIVER svg
FORMATOPTION "COMPRESSED_OUTPUT=FALSE"
FORMATOPTION "FULL_RESOLUTION=TRUE"
END
The perl script on the web server chooses the output in response to
what's sent from the browser. If an svg output is desired the perl
script does the following to generate an svg file:
# draw map and save image
#
my $image = $map->draw();
$map->drawLabelCache($image);
$image->save($image_path.$image_name);
if ($parms->param('print')) {
my $print_map = $map->clone();
$print_map->selectOutputFormat("svg");
$print_map->{resolution} = 90;
my $print_image = $print_map->draw();
$print_map->drawLabelCache($print_image);
my $filename=$image_path.$print_name;
$print_image->save($filename);
open(DLFILE, "<$filename");
my @fileholder = <DLFILE>;
close(DLFILE);
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=nys1.svg\n\n";
print @fileholder;
exit;
}
where $map and $image are generated for the png output. I'm cloning
this map object and changing some of the attributes that are svg
specific. The hope is that the svg output would duplicate what
appears on the screen because what appears on the screen is good for
my purposes.
There are two anomalies. First, all the labels are printed in
duplicate. I've verified this by looking at the svg file with a text
editor. I can live with this one.
The label directive on the map file is:
LABEL
TYPE truetype
FONT "arial"
SIZE 8
ANGLE auto
COLOR 0 0 255
OUTLINECOLOR 255 255 255
MINDISTANCE 100
MINFEATURESIZE auto
POSITION auto
END
This brings up the second and more serious anomaly. I'm using
mapserver to align and position the labels close to the line
features. It does a good job on the png file. However, it does not
rotate labels in the clockwise direction but keeps them horizontal.
It's fine for labels that are rotated counter-clockwise. I've
verified this by reading the svg file. Here are two examples:
<text x="130" y="-1" font-family="arial" font-size="8pt"
fill="#000000" stroke="#ffffff"
stroke-width="0.1" text-anchor="middle">
Main St
</text>
<text x="259" y="419" font-family="arial" font-size="8pt"
fill="#000000" stroke="#ffffff"
stroke-width="0.1" transform="rotate(-84.995650 259 419)"
text-anchor="middle">Main St
</text>
The rotate transform gives the rotation angle and the pivot point.
That's a counter-clockwise rotation because svg makes the downward
directon on the y-axis to be positive.
Here's the version string for my installation:
MapServer version 5.4.2 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP
OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE
SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER
SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT
SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=THREADS
SUPPORTS=GEOS SUPPORTS=RGBA_PNG INPUT=TIFF INPUT=POSTGIS INPUT=OGR
INPUT=GDAL INPUT=MYGIS INPUT=SHAPEFILE
Any help would be appreciated. Thanks.
Stephen Bauman
13810 Franklin Ave 2N
Flushing NY 11355-3302
Tel: 718-359-7972 (USA)
More information about the MapServer-users
mailing list