Advertisement
Guest User

Untitled

a guest
Jan 24th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?
  2. $status=$_GET["status"];
  3. //echo "<pre>Simple check to see if connection works :-)</pre>n"; flush();
  4. error_reporting(E_ALL); ini_set('display_errors', true);
  5. extension_loaded('pgsql') || die('pgsql module unavailable');
  6.  
  7. // If you will send SQL queries as parameters please read beforehand http://en.wikipedia.org/wiki/SQL_injection !!!!!!
  8. $link = pg_Connect("host=xxx port=xxx dbname=xxx user=xxx password=xxx");
  9. /* if(!$link){
  10. //echo "Couldn't make a connection! ". pg_last_error();
  11. exit;
  12. }
  13. else {
  14. //echo 'connected to server';
  15. }*/
  16.  
  17. $result = pg_query($link, 'select name,country,status,st_asgeojson(the_geom) as geojson from tablename where status=' . $status);
  18. $numrows = pg_numrows($result);
  19.  
  20. // Output Array as GeoJson
  21. //$resultArray = pg_fetch_all($result);
  22. //echo json_encode($resultArray);
  23.  
  24. $geojson = array(
  25. 'type' => 'FeatureCollection',
  26. 'features' => array()
  27. );
  28.  
  29. // Add edges to GeoJSON array
  30. while($edge=pg_fetch_assoc($result)) {
  31.  
  32. $feature = array(
  33. 'type' => 'Feature',
  34. 'geometry' => json_decode($edge['geojson'], true),
  35. 'crs' => array(
  36. 'type' => 'EPSG',
  37. 'properties' => array('code' => '4326' )),
  38. 'properties' => array(
  39. 'name' => $edge['name'],
  40. 'status' => $edge['status'])
  41. );
  42.  
  43. // Add feature array to feature collection array
  44. array_push($geojson['features'], $feature);
  45. }
  46.  
  47. //close database connectin
  48. pg_close($link);
  49.  
  50. // Return routing result
  51. header('Content-type: application/json',true);
  52. echo json_encode($geojson);
  53.  
  54. ?>
  55.  
  56. var statusA= "'active'";
  57. var geojson = new L.geoJson.ajax("php/request.php?status="+statusA, {
  58. style:style,
  59. onEachFeature:popUp,
  60. pointToLayer:function(feature,latlng){
  61. return L.circleMarker(latlng)}});
  62.  
  63. onEachFeature:popUp
  64.  
  65. // function for the popup window
  66. function popUp(feature,layer){
  67. layer.bindPopup('<b>' + feature.properties.name + '</b></br><small>('+ feature.properties.status + ' )</small>');
  68. layer.on('mouseover', function(e){
  69. this.openPopup();
  70. });
  71. };
  72.  
  73. geojson.addTo(map);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement