Perl Mapscript Problem

Stephen Woodbridge woodbri at SWOODBRIDGE.COM
Fri Sep 16 00:12:12 EDT 2005


Stephen Woodbridge wrote:
> Hi All,
> 
> I had dynamic symbol manipulation working on MS 4.01 but can not get it 
> to work on 4.4.1 or 4.6.1. In the following code snippets every think 
> works with the default symbol that is defined in symbolset file, but the 
> code does not let me change the imagepath on the fly.
> 
> Also, I can not get the label on the umarker layer to show unless I 
> specify     LABELCACHE FALSE    and umarker layer is the last in the 
> mapfile.
> 
> Any ideas or help would be appreciated.
> 
> -Steve W.
> 
> 
>  From the mapscript:
> 
>     my $lay = $mapObj->getLayerByName('umarker');
>     if ($lay) {
>         $lay->{status} = 1;
>         my $class = $lay->getClass(0);
>         my $pnt = new mapscript::pointObj();
>         my @marks = split(/;/, $mark);
>         foreach my $x (@marks) {
>             my ($y, $x, $txt, $sym) = split(/[\s,]/, $x);
>             if ($sym && -r "$symbol_path/$sym") {
>                 my $style = $class->getStyle(0);
>                 $style->{symbolname} = "$symbol_path/$sym";
>             }
>             $pnt->{x} = $x;
>             $pnt->{y} = $y;
>             $pnt->draw($mapObj, $lay, $imgObj, 0, $txt);
>         }
>     }
> 
> Or alternately from mapscript:
> 
>     my $lay = $mapObj->getLayerByName('umarker');
>     if ($lay) {
>         $lay->{status} = 1;
>         my $pnt = new mapscript::pointObj();
>         my @marks = split(/;/, $mark);
>         my $symbolset = $mapObj->{symbolset};
>         my $symbol = $symbolset->getSymbolByName('marker');
>         foreach my $x (@marks) {
>             my ($y, $x, $txt, $sym) = split(/[\s,]/, $x);
>             if ($sym && -r "$symbol_path/$sym") {
>                 $symbol->{imagepath} = "$symbol_path/$sym";
>             }
>             $pnt->{x} = $x;
>             $pnt->{y} = $y;
>             $pnt->draw($mapObj, $lay, $imgObj, 0, $txt);
>         }
>     }
> 
> 
> 
>  From the mapfile:
> 
>   LAYER
>     NAME "umarker"
>     STATUS ON
>     TYPE POINT
>     LABELCACHE FALSE
>     TEMPLATE "ttt.html"
>     CLASS
>       NAME "User Marker"
>       #TEXT "HERE"
>       SYMBOL "marker"
>       COLOR 0 0 0
>       LABEL
>         TYPE TRUETYPE
>         FONT "arial-bold"
>         SIZE 8
>         POSITION AUTO
>         OFFSET 0 0
>         BUFFER 4
>         COLOR 0 0 0
>         OUTLINECOLOR 230 230 230
>         FORCE TRUE
>       END
>     END
>   END
> 
>  From the symbol.sym symbolset file:
> 
>   Symbol
>     Name 'marker'
>     Type PIXMAP
>     Image 'markers/purppin.png'
>     Transparent 1
>   END
> 

Here is yet another variation that does not work:

# draw markers on the image

     my $lay = $mapObj->getLayerByName('umarker');
     if ($lay) {
         $lay->{status} = 1;
         my $class = $lay->getClass(0);
         my $pnt = new mapscript::pointObj();
         my @marks = split(/;/, param('mark') || $mark);
         my $symbolset = $mapObj->{symbolset};
         my $symbol = $symbolset->getSymbolByName('marker');
         foreach my $x (@marks) {
             my ($y, $x, $txt, $sym) = split(/[\s,]/, $x);
             if ($sym && -r "$symbol_path/$sym") {
                 my $tmp_sym = new mapscript::symbolObj('tmp_sym', 
"$symbol_path/$sym");
                 my $tmp_img = $tmp_sym->getImage($mapscript::MS_PNG);
                 $symbol->setImage($tmp_img);
             }
             $pnt->{x} = $x;
             $pnt->{y} = $y;
             $pnt->draw($mapObj, $lay, $imgObj, 0, $txt);
         }
     }
}

I also explicitly added a STYLE block to the mapfile like:

   LAYER
     NAME "umarker"
     STATUS ON
     TYPE POINT
     LABELCACHE FALSE
     TEMPLATE "ttt.html"
     CLASS
       NAME "User Marker"
       STYLE
         SYMBOL "marker"
         COLOR 0 0 0
       END
       #TEXT "HERE"
       LABEL
         TYPE TRUETYPE
         FONT "arial-bold"
         SIZE 8
         POSITION AUTO
         OFFSET 0 0
         BUFFER 4
         COLOR 0 0 0
         OUTLINECOLOR 230 230 230
         FORCE TRUE
       END
     END
   END



More information about the mapserver-users mailing list