problem plotting points on map using PHP/MapServer
Ben Madin
ben at REMOTEINFORMATION.COM.AU
Mon Sep 11 23:50:41 PDT 2006
G'day Ben,
I'm still working through this myself, but some thoughts below. there
is a very helpful powerpoint called php_mapscript_mum2.ppt from
DMSolutions, google it and get it.
Also, bookmark
http://www.maptools.org/php_mapscript/index.phtml?page=phpmapscript-
class-guide.html
if you haven't already.
>
> So far, I can draw the basic map with a country outline. However, I
> am unable to draw points on the map.
>
> I have set up the basic map, and added a class and a layer for the
> points. I then run the following code:
>
> $image=$map->draw();
> $point = ms_newPointObj();
> $point->setXY(-21.97, 64.15);
> $return = $point->draw($map, $pointsLayer, $image, 0, 'A beautiful
> point');
>
> $return is 0.
>
> Is there any way I can get further information as to what might be
> going wrong here, with more detail than just the success/failure
> methods?
>
I might have this wrong, but you seem to have to turn your pointObj
into a lineObj to add it to a shapeObj to add to the map. This is how
I do it : (the str_replace is to deal with , decimals)
$outbreakshape = ms_newShapeObj(MS_SHAPE_POINT);
#B now add the points...
foreach($dispmappoint->itemlist as $ob_id=>$locn) {
#B make a point
$outpoint = ms_newPointObj();
$outpoint -> setXY($locn[1],$locn[0]);
#B Add it to a line object
$obline = ms_newLineObj();
$obline->add($outpoint);
#B Add it to our shape
$outbreakshape->add($obline);
}
$dislayer->addFeature($outbreakshape); #B then add the feature to
the map.
Now try drawing it.
>
> Apparently the PHP function ms_newMapObj() must have a map file
> passed to it, although I noticed that the Python version does not.
> Is there a reason for this? At the moment, I have a dummy map file
> containing nothing which I have to use.
>
No, it doesn't need one (or it didn't @ 4.8) you can just use
$map=ms_newMapObj('',$mapserver_path);
> If I use something like $layer->name = 'Layername', the layer name
> is not set (in fact it is set to null). Using $layer->set('name',
> 'Layername') it seems fine. Not really a problem, just wondered why.
Others could answer this I'm sure... but although it seems a bit
annoying at first, it is great for reusing code. I guess they have
one function in the class that sets any variable.
Good luck, and if I have it wrong, I'd be delighted to be corrected,
or to see some smarter code.
cheers
Ben
--
Ben Madin
REMOTE INFORMATION
t : +61 8 9192 5455
f : +61 8 9192 5535
m : 0448 887 220
Broome WA 6725
ben at remoteinformation.com.au
Out here, it pays to know...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060912/2894033a/attachment.htm>
More information about the MapServer-users
mailing list