adding label to point layer in PHPMapscript
Pietro Giannini
pgiannini at BYTEWISE.IT
Tue Sep 26 06:33:08 PDT 2006
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.
>
>
More information about the MapServer-users
mailing list