[mapserver-users] PHP, Create Layer on Fly - HELP

Hankley, Chip Chip.Hankley at GASAI.Com
Tue Oct 16 17:03:36 EDT 2001


Tim,

A couple weeks ago, I had sent a note to the list regarding placing a legend
inside the mapframe dynamically. You asked me to forward you the solution
when I figured it out.

The guys as DMSolutions put up a new dll yesterday - that, along with a
little syntax fix, solved the problem. Function below.

Chip Hankley

________________________________________________________


embed_legend($map, $Cur_Extent, $img);

function embed_legend($map, $Cur_Extent, $img) {
  //$map is the current MapObject
  //$Cur_Extent is an array where:
    //$Cur_Extent[0] = Xmin
    //$Cur_Extent[1] = Ymin
    //$Cur_Extent[2] = Xmax
    //$Cur_Extent[3] = Ymax
  //$img is the current ImageObject

  //Create a new Point Layer
  $layer = ms_newLayerObj($map);
  $layer->set("name", "legend");
  $layer->set("type", MS_LAYER_POINT);
  $layer->set("status", 1);

  //Create a new Class for the Layer
  $class = ms_newClassObj($layer);
  $class->set("name", "legendclass");
  $symb = $map->getSymbolByName('symbols/legend.png');
  $class->set("symbol", $symb);

  //Place the point so that it is 52 pixels IN and 41
  // pixels UP from the lower left hand conrner of
  // the image. We are using an image that is 100 x 80
  // pixels... this should put the image just inside
  // the rendered image.
  $ImgWidth = $map->width;
  $ImgHeight = $map->height;
  $Pixel_X = ($Cur_Extent[2] - $Cur_Extent[0]) / $ImgWidth;
  $Pixel_Y = ($Cur_Extent[3] - $Cur_Extent[1]) / $ImgHeight;
  $Spot_X = $Cur_Extent[0] + 52 * $Pixel_X;
  $Spot_Y = $Cur_Extent[1] + 41 * $Pixel_Y;
  
  $point = ms_newpointObj();
  $point->setXY($Spot_X, $Spot_Y);
  $point->draw($map,$layer,$img,'legendclass',undef);

  $layer->draw($img);
}



More information about the mapserver-users mailing list