[Mapserver-users] Annotation setExpression() problem

Rene Teniere TENIERER at gov.ns.ca
Mon Feb 16 09:25:36 PST 2004


Hi all,
Wondering if someone can help me here. I am creating an annotation
layer with a dynamic expression to label only what I want each time.
Problem is that I cannot set the expression through mapscript. It works
fine hard-coded in the mapfile, but it has to be done through php. The
expression would look like: /1234|2345|3456/ or /1234/  That is
represented in the $sExp variable in the code below. At first I set up
the mapfile annotation layer without an expression then used
$class->setExpression($sExp); to set the expression. That did not work,
even though the variable contents worked in the mapfile with the desired
results.

Next, I got rid of the annotation layer in the map file and decided to
create it through php/mapscript. The end results showed up with no
annotation at all. The code for the layer creation is below, and I have
no idea why it will not work. Anyone have any ideas?

Rene

   <?php
      $map_path = "C:/chameleon11a/websites/wap/";
      $map = ms_newMapObj($map_path."sketch.map");
      $map->setExtent($minX-10, $minY-10, $maxX+10, $maxY+10);
      $image = $map->draw();
      $wap = $map->getLayerByName("WAP");
      $shapes = ms_newLayerObj($map, $wap);
      $shapes->set("name","Shapes");
      $shapes->set("data","");

      //Create the annotation layer
      $anno = ms_newLayerObj($map);
      $anno->set("name","annolayer");
      $anno->set("maxscale",500000);
      $anno->set("status",MS_ON);
      $anno->set("data","D:\gis_data\wap_2002\all");
      $anno->set("type",MS_LAYER_ANNOTATION);
      $anno->set("labelitem","ID");
      $anno->set("classitem","ID");


      $class = ms_newClassObj($anno);
      $class->set("name","annoclass");
      $class->set("status",MS_ON);

      $class->label->type->MS_BITMAP;
      $class->label->size->MS_MEDIUM;
      $class->label->position->MS_CC;
      $class->label->color->setRGB(255,0,0);

      //Create Annotation Expression
      $sExp = "/".$nID[0];
      for($k=0; $k<=$nCOUNT; $k=$k+1)
      {
        if($k>0)
        {
          $sExp = $sExp."|".$nID[$k];
        }
      }
      $sExp = $sExp."/";

      //$expression = $class->getExpression();
      //error_log("Before:".$expression);

      $class->setExpression($sExp);

      //$expression = $class->getExpression();
      //error_log("After:".$expression);

      $shapes_class = ms_newClassObj($shapes);

      $wap->open();
      for($j=0; $j<=$nCOUNT; $j=$j+1)
      {
        $nShape[$j] = $wap->getShape(-1, $nIndex[$j]);
        $nShape[$j]->draw($map, $shapes, $image);
      }
      $wap->close();

      $scalebar = $map->drawScaleBar();
      $image_url = $image->saveWebImage();
      $scalebar_url = $scalebar->saveWebImage();
    ?>




More information about the MapServer-users mailing list