source:
trunk/workshop-routing-foss4g/chapters/php_server.rst
@
64
Revision 63, 2.5 KB checked in by djay, 13 years ago (diff) |
---|
Server side script with PHP
We will use a PHP script to make the routing query and send the result back to the web client.
The following steps are necessary:
- Retrieve the start and end point coordinates.
- Find the closest edge to start/end point.
- Take either the start or end vertex of this edge (for Dijkstra/ A-Star) or the complete edge (Shooting-Star) as start of the route and end respectively.
- Make the Shortest Path database query.
- Transform the query result to XML or better GeoJSON and send it back to the web client.
Note
To keep this example as simple as possible with focus on routing queries, this PHP script doesn't validate request parameters nore does it deal with PHP security issues.
Let's start with some PHP template and then place this file in a directory, which is accessible by Apache:
Closest edge
Usually the start and end point, which we retrieved from the client, is not the start or end vertex of an edge. It is more convenient to look for the closest edge than for the closest vertex, because Shooting Star algorithm is âedge-basedâ. For âvertex-basedâ algorithms (Dijkstra, A-Star) we can choose arbitrary start or end of the selected edge.
Routing query
GeoJSON output
OpenLayers allows to draw lines directly using GeoJSON format, so our script returns a GeoJSON FeatureCollection object: