adding label to point layer in PHPMapscript

Murat BEYHAN beyhan at DEPREM.GOV.TR
Tue Sep 26 02:48:03 PDT 2006


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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060926/b1112580/attachment.htm>


More information about the MapServer-users mailing list