Mapscript, SVG and Annotations

Martin Weinelt mweinelt at PLANIGLOBE.COM
Tue Jul 10 09:52:10 PDT 2007


I tried $map->drawLabelCache($SVGImg ), but that returns MS_FAILURE. Actually, there seems a problem with labeling on a SVG-'image'.
I work around with:

open SVGMAP, '>>', '/path/to/saved/svgimg.svg';  
for (my $labnum=0; $labnum < $map->{labelcache}->{numlabels};$labnum++ ) {
      my $next_lab = $map->nextLabel() ;
      my $lab_txt  = $next_lab->{text};
      my $lab_x    = $next_lab->{point}->{x}; my $lab_y = $next_lab->{point}->{y};
      print SVGMAP  '<text x="'.$lab_x.'" y="'.$lab_y.'" font-family="verdana" font-size="10pt" fill="#000000" stroke="#ffffe6" stroke-width="0.5">'.$lab_txt.'</text>' . "\n";
 }
print SVGMAP  '</svg>';
close SVGMAP;  

Of course, I would much more like to make use of MapServers anti-overposting mechanics for labels.

Really nobody else came across that problem?

Martin 

On Montag 09 Juli 2007, Martin Weinelt wrote:
> Hi,
>
> I am using addFeature to dynamically add site locations with a
> label to a map. It's Perl mapscript.
>
> @sites is an array of hash references, $sitesLyr is from the map
> file:
>
> ###############
>  foreach my $site (@sites) {
>    my $site_pt = $$site{'site_loc'};
>       $site_pt =~s/.*\((.*)\)*./$1/;  # extract the points x and y
>    my $line     = new mapscript::lineObj();
>    my $siteShp  = new
> mapscript::shapeObj($mapscript::MS_SHAPE_POINT);
>
>    my $point = new mapscript::pointObj();
>    my($x,$y) = split(/ /, $site_pt);
>       $point->setXY($x,$y);
>       $line->add($point);
>       $siteShp->add($line);
>       $siteShp->{text} = $$site{'site_name'};
>       $siteShp->setBounds();
>       $sitesLyr->addFeature($siteShp);
>   }
>
>  my $img = $map->draw();
>
> #############
>
> This works perfectly for the usual PNG output map. Using the same
> routine for a SVG 'image' results in the symbols/markers getting
> plotted, but the labels are missing. If I switch to a static
> shapefile for this layer, the labels do appear in the SVG.
>
> Is there anything special with SVG output and the 'addFeature'
> method for layers that I am missing?
>
> Thanks,
>
> Martin



-- 
 --- Martin Weinelt 
 --- kk+w - digital cartography 
 --- Kiel, Germany
 --- Tel: +49.431.5791165
 --- http://www.planiglobe.com 



More information about the MapServer-users mailing list