[mapserver-users] Re:acetate logo & inline features / text st ring

Hankley, Chip Chip.Hankley at GASAI.Com
Tue Aug 6 10:35:59 PDT 2002


...if you are using PHP-MapScript, something along the following lines will
work. I have used this function to embed numerous images... north arrows,
copyright information, etc. Basically, you need an image to embed, then play
around with the $img_x and $img_y to get it to the right spot.

Cheers!

Chip Hankley

-------------------------------------------------------
PHP-Mapscript example of using the embed_picture function

...

//Embed the scalebar into the main image before it's drawn
$sb_url=".." . draw_scalebar($map);
embed_picture($map, $Cur_Extent, $img, "$sb_url", ($map->width / 2), 10);

//Now embed the north arrow into the main map
embed_picture($map, $Cur_Extent, $img, "../MapSymbols/NorthW.gif", 20,
($map->height - 20));

...

function embed_picture($map, $Cur_Extent, $img, $img_name, $img_x, $img_y) {
//  
//  Function Parameters:
//    $map - the map object
//    $Cur_Extent (array) - extent of current image, xmin, ymin, xmax, ymax
//    $img - image object generated by $map->draw
//    $img_name - the name (and path) of the image to embed
//    $img_x - x pixel coordinates of location in $img to embed $img_name
//    $img_y - y pixel coordinates of location in $img to embed $img_name
//  

  //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($img_name);
  $class->set("symbol", $symb);

  //symbols/legend.gif

  //Place the point so that it is 221 pixels IN and 301
  // pixels UP from the lower left hand conrner of
  // the image. We are using an image that is 300 x 37
  // 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] + $img_x * $Pixel_X;
  $Spot_Y = $Cur_Extent[1] + $img_y * $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