drawing points from mysql with php/mapscript
Mark Brooks
mark_brooks at NCSU.EDU
Mon Dec 5 16:00:04 PST 2005
Thanks to all who offered their advice! I ended up using a little bit
of this code below and of course, I switched my lat/lon pair around.
Thanks:)
Mark
Gavin Simpson wrote:
> On Mon, 2005-12-05 at 11:37 -0500, Mark Brooks wrote:
>
>>I'm trying to draw points from a MySQL database onto a map with
>>PHP/Mapscript. I found no clear examples online and so far have had
>>little luck at being successful. Does anyone out there have any
>>examples you could share?
>
> <snip>
>
>>And a watered-down snippet from my php code to draw the dynamic points
>>from mysql:
>>
>>$image = $map->draw();
>>$this_layer = $map->getLayerByName('sites');
>>$this_layer->set('status', MS_ON);
>>//query database for points
>>$query = "select bla bla";
>>$sresult = mysql_query($query);
>>// loop through database results, adding the new point to the layer
>>while ($site = mysql_fetch_assoc($sresult)){
>> $mypoint = ms_newPointObj();
>> $mypoint->setXY($site['lat'],$site['lon']);
>> $mypoint->draw($map,$this_layer,$image,0,$site['name']); }
>
> <snip>
>
>>What am I missing?
>
>
> Does this help?
>
> $layer = $map->getLayerByName("samples");
>
> for ($i = 0; $row = mysql_fetch_array($samplesQuery); $i++)
> {
> $pt = ms_newPointObj();
> $pt->setXY($row["fullEasting"], $row["fullNorthing"]);
> $line = ms_newLineObj();
> $line->add($pt);
> $shape = ms_newShapeObj(MS_SHAPE_POINT);
> $shape->add($line);
> $shape->set("index", $i);
> $shape->set("text", $row["siteCode"]);
> $layer->addFeature($shape);
> $pt->draw($map, $layer, $image, 0, $row["siteCode"]);
> }
>
> You first create a point, then a lineObj to hold the point, then a
> shapeObj of type MS_SHAPE_POINT and add the lineObj to the shapeObj,
> then add the shapeObj to a layer, then draw the point on the named
> layer/map/image.
>
> The above example shows these steps - I wanted this in a for loop with
> an index so I could set the index for each point and I also set the text
> for each point so i can retrieve info later.
>
> HTH,
>
> G
>
More information about the MapServer-users
mailing list