adding label to point layer in PHPMapscript

Murat BEYHAN beyhan at DEPREM.GOV.TR
Tue Sep 26 07:26:57 PDT 2006


Dear Pietro;
Thank you for your suggestion.
But still the label doesn't appearing 
I have change some point in yor result you sent me..
Please check it.
I really try to write label with point by using PHP but I couldn't find any
result on the list archive or on the web.
 Thank you very much for your interest....
the code which I changed a little are here.....

 $map_path="/var/www/html/zone/";
 $map = ms_newMapObj($map_path."zone.map");
 $map->setExtent($nMinX, $nMinY, $nMaxX, $nMaxY); 
 
 // create a temp layer to hold our points
 $point_layer = ms_newLayerObj($map);
 $point_layer->set("name", "markers");
 $point_layer->set("type", MS_LAYER_POINT);
 $point_layer->set("status", MS_DEFAULT);
 $point_layer->setProjection("proj=latlong",MS_TRUE);

 // create a class and style for this layer
 $point_class = ms_newClassObj($point_layer);
 $point_style = ms_newStyleObj($point_class);
 $koyadi="deneme";
 $point_layer->set("labelitem","$koyadi");
 $point_symbol = $map->getSymbolByName("cpoint");

 $point_style->set("symbol", $point_symbol);
 $point_style->set("size", 12);
 $point_style->color->setRGB(255,0,255);
 $point_style->outlinecolor->setRGB(255,255,0);
 
/*  setting a label on the class  */
// $label = $class->label;       /***** here also I have changed... as follows */
 $label = $point_class->label;
 $label->set("position", MS_CC);
 $label->set("font","arial");
 $label->set("type",MS_BITMAP);/*        I HAVE CHANGE THIS LINE BECAUSE
freetype format doesn't supporting my mapserver. I also try to find a solution
for that.*/
 $label->set("size","large");    /* also hereeeeeeee*/
$longitude=$lon;// comes from select queries from mysql as a result 
$latitude=$lat;// comes from select queries from mysql as a result 
/*  now the method is a bit more complicated as precedent  */
/*  create and locate a point object  */
 $point = ms_newPointObj();    /* is this will be $point_layer for my code???*/
 $point->setXY($longitude, $latitude);
/*  create a line object and add the point  */
 $line = ms_newLineObj();
 $line->add($point);
/*  create a shape object and add the mono-point line */
 $shape = ms_newShapeObj(MS_SHAPE_POINT);
 $shape->add($line);
/*  set the "text" property of the shape  */
 $shape->set("text","show must go on");
/*  add this shape to the layer  */
 $point_layer->addFeature($shape);  /* also hereeee*/

/*  now you can create the image of the map and save it  */
// $image = $oMap->draw();
 $image = $map->draw();
 
 $map_url=$image->saveWebImage();
/*  you don't need to invoke the   */
//     $point->draw($map, $layer, $image, 0, "");
/**************************************************/
// draw our image without the points
 $ref = $map->drawreferencemap();
 $legend=$map->drawLegend();



On Tue, 26 Sep 2006 15:33:08 +0200, Pietro Giannini wrote
> hi Murat,
> i tried so, and works:
> 
> /****************************************/
> /*  setting a label on the class  */
>   $label = $class->label;
>   $label->set("position", MS_CC);
>   $label->set("font","arial");
>   $label->set("type",MS_TRUEYPE);
>   $label->set("size",12);
> 
> /*  now the method is a bit more complicated as precedent  */
> /*  create and locate a point object  */
>   $point = ms_newPointObj();
>   $point->setXY($longitude, $latitude);
> /*  create a line object and add the point  */
>   $line = ms_newLineObj();
>   $line->add($point);
> /*  create a shape object and add the mono-point line */
>   $shape = ms_newShapeObj(MS_SHAPE_POINT);
>   $shape->add($line);
> /*  set the "text" property of the shape  */
>   $shape->set("text","show must go on");
> /*  add this shape to the layer  */
>   $layer->addFeature($shape);
> 
> /*  now you can create the image of the map and save it  */
>   $image = $oMap->draw();
>   $map_url=$image->saveWebImage();
> /*  you don't need to invoke the   */
> //	$point->draw($map, $layer, $image, 0, "");
> /**************************************************/
> 
> best regards
> 
> Pietro
> 
> ___________________________
>       Pietro Giannini
>   Bytewise srl - Area GIS
> 41°50'38.58"N 12°29'13.39"E
> 
> On Mar, 26 Settembre 2006 11:48, Murat BEYHAN disse:
> > Dear Jacob,
> > Thank you for your suggestion.
> > The following php codes bring one of the record from mysql I mean only one
> > row.
> >
> > That row consist of the cityname (iladi), districtname (ilceadi) and
> > village name (koyadi).
> >
> > $query = "SELECT * FROM $db_tb WHERE iladi LIKE '$iladi' AND
> > ilceadi LIKE '$ilceadi' AND koyadi LIKE '$koyadi'";
> >
> > $result = mysql_query($query) or die("Query failed : " . mysql_error());
> >
> > $num = mysql_numrows($result);
> >                     $i=0;
> > while ($i < $num) {
> > $koyadi    = mysql_result($result,$i,"koyadi");
> > $ilceadi     = mysql_result($result,$i,"ilceadi");
> > $iladi       = mysql_result($result,$i,"iladi");
> > $zone         = mysql_result($result,$i,"zone");
> > $lon          = mysql_result($result,$i,"lon");
> > $lat          = mysql_result($result,$i,"lat");
> >                     ++$i;
> > }
> >
> >> Have you tested whether any part of this code works? Which part is
> >> giving you trouble? Does your PHP log say anything?
> > By using this query result I'm drawing point of the village on the map.
> > The part of this issue does work succesfully. I mean drawing of the point
> > was achieved already by the support of the list user.
> > The second step Which I intend to write the name of village near to point.
> >
> > So I was changed the name of koyadi into villagename in order to
> > understand for people in my message. sorry.
> > Now I have tried to ad your suggestion into the php code but still the
> > name of village doesnt appearing on the map..
> > I hope I could explained What I'm trying to do.
> > Thanks.
> > Murat
> >
> > The new codes are here after your suggestion. But I2m not sure exacly
> > where I have to put your suggestion on the code.
> > $map_path="/var/www/html/zone/";
> >  $map = ms_newMapObj($map_path."zone.map");
> >  $map->setExtent($nMinX, $nMinY, $nMaxX, $nMaxY);
> >
> > // create a temp layer to hold our points
> > $point_layer = ms_newLayerObj($map);
> > $point_layer->set("name", "markers");
> > $point_layer->set("type", MS_LAYER_POINT);
> > $point_layer->set("status", MS_DEFAULT);
> > $point_layer->setProjection("proj=latlong",MS_TRUE);
> >
> > // create a class and style for this layer
> > $point_class = ms_newClassObj($point_layer);
> > $point_style = ms_newStyleObj($point_class);
> > $point_layer->set("labelitem","$koyadi");
> > $point_symbol = $map->getSymbolByName("cpoint");
> >
> > $point_style->set("symbol", $point_symbol);
> > $point_style->set("size", 12);
> > $point_style->color->setRGB(255,0,255);
> > $point_style->outlinecolor->setRGB(255,255,0);
> >
> > $label = $point_class->label;
> > $label->set("position", MS_CC);
> >
> > $label->set("font","sans");
> > $label->set("type",MS_TRUEYPE);
> > $label->set("size",MS_MEDIUM);
> > $label->color->setRGB(22,8,3);
> > $label->backgroundcolor->setRGB(0,0,0);
> > $label->set(minsize,4);
> > $label->set(maxsize,100000);
> >
> > // draw our image without the points
> >  $ref = $map->drawreferencemap();
> >  $legend=$map->drawLegend();
> >
> > $image = $map->draw();
> >
> > // initialize our point and add it to the map
> > $point = ms_newPointObj();
> > $longitude=$lon;// comes from select queries from mysql as a result
> > $latitude=$lat;// comes from select queries from mysql as a result
> > echo $longitude, ' ', $lat;
> >
> > $point->setXY($longitude, $latitude);
> >
> > $point->draw($map, $point_layer, $image, 0, "");
> >
> >   $map_url=$image->saveWebImage();
> >   $ref_url = $ref->saveWebImage();
> >   $legend_url=$legend->saveWebImage();
> >
> >
> >
> > On Tue, 26 Sep 2006 16:04:33 +0800, Delfos, Jacob wrote
> >> Murat,
> >>
> >> Are you sure you want all your villages to have the same label
> >> ($villagename)?
> >> I think you may want to define a labelitem:
> >>
> >> $point_layer->set("labelitem","villagename"); // "villagename" is the
> >> name of the attribute of the layer
> >>
> >> Also, you quoted "$koyadi", which is probably not correct. Or remove the
> >> '$'.
> >>
> >> Have you tested whether any part of this code works? Which part is
> >> giving you trouble? Does your PHP log say anything?
> >>
> >> regards,
> >>
> >> Jacob
> >>
> >
> >
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
> >
> >
> 
> -- 
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the MapServer-users mailing list