| Querying dynamic point layer with php/mapscript |
|
|
|
|
php/mapscript allows to use mapserver very efficiently inside a php application. Some parts of the behaviour is still a bit undocumented. Querying dynamically created point layer is one of those missing parts. This article is based on MapServer version 4.10
To be able to query a dynamic layer, you need to have a layer definition in your mapfile. This definition MUST have a TEMPLATE attribute (either if it points on nothing). The following example should work :
LAYER NAME "my_layer" STATUS ON TYPE POINT TOLERANCE 10 LABELCACHE ON LABELMAXSCALE 400000 TRANSPARENCY ALPHA TEMPLATE nofile.html CLASS NAME "Points" COLOR 255 0 0 OUTLINECOLOR 255 0 0 SIZE 10 SYMBOL "circle" LABEL POSITION AUTO ANGLE AUTO SIZE 12 COLOR 0 0 0 TYPE truetype FONT DejaVuSans ANTIALIAS true OUTLINECOLOR 255 255 255 PARTIALS false ENCODING 'utf8' END END PROJECTION "+proj=lcc +lat_1=51.16666723333333 +lat_2=49.8333339 +lat_0=90 +lon_0=4.367486666666666 +x_0=150000.013 +y_0=5400088.438 +ellps=intl +units=m +no_defs" END END
Then you need to fill in your layer with points. This is a bit tricky because you cannot add pointObj to mapeserver shapeObj. Thus, you need to add a lineObj composed by only one point ;-) :
$shp = ms_newShapeObj(MS_SHAPE_POINT); $pt = ms_newLineObj(); $pt->addXY($point->x,$point->y); $shp->add($pt); $shp->set('classindex', $obj->get_classindex()); $shp->set('text', $obj->get_id()); $shp->set('index', $obj->get_internal_id());$lyr->addFeature($shp);
Finally, you can query your layer using a geographical point (not a pixel one !) :
// transform pixel to geo coords :echo "Foudn point $rslt->shapeindex"; } else {echo "No point found"; }
The key to solve this problem is to use the index of the shapeObj as key to find out which point has been selected. |
|
| Last Updated ( mardi, 09 octobre 2007 ) |
| < Prev | Next > |
|---|
| Newsflash | ||
|---|---|---|
|
||
| Popular |
|---|


