[Mapserver-users] Mapscript and Labels comes back...

Jaroslaw Kowalczyk karas1974 at wp.pl
Sat Jun 21 03:09:35 PDT 2003


Hello,

I am trying to write application in php and mapscript showing location of
several points on a map. All works well, however my problem is with putting
labels on a map. I have already received help form Eric Bridger (Thank you
again!), but there is still something  wrong with my code.

Are there any code samples available showing how to put labels on a map. I
store labels and coordinates in mySQL database, and then create shapefile,
and load shapefile into new layer. I would be grateful for any example.

I also atachee part of my code bellow, and error it causes.



// This is part of the main program ------------------START


 BuildSelectionShapefile($kategoria_oferty);                // first create
shapefile based on data in mySQL database
 $image=$map->draw();
 $map->drawLabelCache($image);
 $image_url=$image->saveWebImage(MS_PNG,1,1,0);

//--------------------------------------------------THE END



// This function is used to create shapefile with points and their labels
(based on mySQL database)

function BuildSelectionShapefile($kat_of)
 {

  GLOBAL $map;
  GLOBAL $image;

   //creating shapefile on disk in tmp directory

          $shapetempname="tmp".time();

$shapefile_temp=ms_newShapefileObj("c:/usr/krasnal/www/edeveloper/gmap/htdoc
s/data/".$shapetempname,MS_SHP_POINT);

$dbname="c:/usr/krasnal/www/edeveloper/gmap/htdocs/data/$shapetempname".".db
f";
          $def=array(array("id_oferty","C",4,0));
          $dbid=dbase_create($dbname,$def);
          dbase_pack($dbid);
          dbase_close($dbid);
          $dbidrw=dbase_open($dbname,2);

          $sql = mysql_connect (localhost);
          mysql_select_db("edeveloper");
          $zapytanie = 'SELECT `oferty`.`opis`, `oferty`.`x_oferty`,
`oferty`.`y_oferty`, `oferty`.`id_oferty` FROM przeznaczenie LEFT JOIN
`oferty` ON `przeznaczenie`.`id_oferty` =
`oferty`.`id_oferty` WHERE `przeznaczenie`.`id_przeznaczenia` LIKE \''
.$kat_of. '\'';
          $wykonaj = mysql_query($zapytanie);
          $liczba_ofert=mysql_num_rows($wykonaj);
          while ($wiersz = mysql_fetch_array($wykonaj))
                  {
                        $pointObj=ms_newPointObj();

$pointObj->setXY($wiersz["x_oferty"],$wiersz["y_oferty"],1);
                       $result=$shapefile_temp->addPoint($pointObj);
                       $pointObj->free();
                       $valuedbf=array($wiersz["id_oferty"]);
                       $test=dbase_add_record($dbidrw, $valuedbf);
                   }
            dbase_pack($dbidrw);
            dbase_close($dbidrw);
            $shapefile_temp->free();

    //creating new layer

            $newLayer=ms_newLayerObj($map);
            $newLayer->set('status',MS_ON);
            $newLayer->set('name',"Oferty");
            $newLayer->set('type',MS_LAYER_POINT);
            $newLayer->set('labelitem',"id_oferty");

    // creating new class

        $newClass=ms_newClassObj($newLayer);
        $newClass->set('name','wybrane_oferty');
        $newClass->set('symbol',4);
        $newClass->set('size',15);
        $newClass->set('color',$map->addColor(255, 0, 0));
        $newClass->set('outlinecolor',$map->addColor(0, 0, 0));
        $newClass->{label}->set('font','fritqat');
        $newClass->{label}->set('type',MS_TRUETYPE);
        $newClass->{label}->set('size',8);
        $newClass->{label}->set('position',MS_AUTO);
        $newClass->{label}->set('color',$map->addColor(0, 2, 2));
        $newClass->{label}->set('antialias',true);

    //reading shapefile and and filling new layer and class.


$shapefile_temp=ms_newShapefileObj("c:/usr/krasnal/www/edeveloper/gmap/htdoc
s/data/".$shapetempname,-1);
        $l_ofert=$shapefile_temp->{numshapes};
        for ($i=0;($i<$l_ofert);$i++)
              {
                   $newShapeObj=ms_newShapeObj(MS_SHAPE_POINT);
                   $newShapeObj=$shapefile_temp->getShape($i);
                   $ok=$newShapeObj->set('text',"[".$i."]");
                   $newLayer->addFeature($newShapeObj);
                   $newShapeObj->free();
              }
      $shapefile_temp->free();
 }



This code cause server error:

PHP caused error: wrong page in module PHP_MAPSCRIPT_36.DLL przy
016f:0144a95f.
Rejestry:
EAX=00000000 CS=016f EIP=0144a95f EFLGS=00210246
EBX=007625f0 SS=0177 ESP=0063b188 EBP=0063b194
ECX=0063b1b8 DS=0177 ESI=0063b220 FS=0faf
EDX=00000000 ES=0177 EDI=0063b1a4 GS=0000
Bajts in CS:EIP:
8b 04 82 50 e8 24 cc 1f 00 83 c4 04 89 45 f8 8b
Stack:
00000000 00000000 0144f412 0063b240 0144f556 02044788 0063b1b8 0063b240
0203bcc0 00000008 00000000 0063b1dc 00000001 02150fc0 ac00218e 4119657b








More information about the MapServer-users mailing list