Mapscript, SVG and Annotations

Yewondwossen Assefa assefa at DMSOLUTIONS.CA
Tue Jul 10 11:48:23 PDT 2007


Hi there,

  I did a quick test using php mapscript and an svg output. The poplace 
layer in the map file is a point layer and has a class with a label 
object (note that there is no labelitem set)

LAYER
  NAME popplace
  TYPE POINT
   STATUS ON
   ...
CLASS
       style
         SYMBOL 'circle'
        SIZE 6
        COLOR  0 0 255
      END
      LABEL
       COLOR  255 0 0
#      FONT fritqat-italic
       FONT Arial
       TYPE truetype
       SIZE 12
       ANGLE 10
       POSITION AUTO			
       PARTIALS FALSE
       OUTLINECOLOR 255 255 255			
     END
  ...

  script looks something like this

$oMap = ms_newmapobj("c:/msapps/gmap-ms40/htdocs/gmap75.map");

$oShp = ms_newShapeObj(MS_SHAPE_POINT);

$oLine = ms_newLineObj();

$oLine->addXY(-2299954.0642738,-612631);
$oShp->add( $oLine );

$oShp->set("text", "mytext");

$numlayers = $oMap->numlayers;
for ($i=0; $i<$numlayers; $i++)
{
   $oLayer = $oMap->getlayer($i);
   $oLayer->set("status", MS_OFF);
}
$oLayer = $oMap->getlayerbyname('popplace');
$oLayer->set("status", MS_ON);
$oLayer->addfeature($oShp);

$img = $oMap->draw();
$url = $img->saveWebImage();

header("Content-type: image/svg+xml");
$url = $img->saveImage("");


  It produces an svg point with the label my text :

  ...
<!-- START LAYER popplace -->
<ellipse cx="39" cy="586" rx="3" ry="3" fill="#0000ff"  />
<text x="38" y="581" font-family="Arial" font-size="12pt" fill="#ff0000" 
stroke="#ffffff" stroke-width="0.5" transform="rotate(-10.000000 38 
581)">mytext</text>
</svg>

  Not sure what the issue would be in your case, the only time I did not 
have the text produced was when I set the labelitem object. Could that 
be the case ?


Later

kk+w - digitale kartografie GmbH 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
> 


-- 
----------------------------------------------------------------
Assefa Yewondwossen
Software Analyst

Email: assefa at dmsolutions.ca
http://www.dmsolutions.ca/

Phone: (613) 565-5056 (ext 14)
Fax:   (613) 565-0925
----------------------------------------------------------------



More information about the MapServer-users mailing list