Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $status=$_GET["status"];
- //echo "<pre>Simple check to see if connection works :-)</pre>n"; flush();
- error_reporting(E_ALL); ini_set('display_errors', true);
- extension_loaded('pgsql') || die('pgsql module unavailable');
- // If you will send SQL queries as parameters please read beforehand http://en.wikipedia.org/wiki/SQL_injection !!!!!!
- $link = pg_Connect("host=xxx port=xxx dbname=xxx user=xxx password=xxx");
- /* if(!$link){
- //echo "Couldn't make a connection! ". pg_last_error();
- exit;
- }
- else {
- //echo 'connected to server';
- }*/
- $result = pg_query($link, 'select name,country,status,st_asgeojson(the_geom) as geojson from tablename where status=' . $status);
- $numrows = pg_numrows($result);
- // Output Array as GeoJson
- //$resultArray = pg_fetch_all($result);
- //echo json_encode($resultArray);
- $geojson = array(
- 'type' => 'FeatureCollection',
- 'features' => array()
- );
- // Add edges to GeoJSON array
- while($edge=pg_fetch_assoc($result)) {
- $feature = array(
- 'type' => 'Feature',
- 'geometry' => json_decode($edge['geojson'], true),
- 'crs' => array(
- 'type' => 'EPSG',
- 'properties' => array('code' => '4326' )),
- 'properties' => array(
- 'name' => $edge['name'],
- 'status' => $edge['status'])
- );
- // Add feature array to feature collection array
- array_push($geojson['features'], $feature);
- }
- //close database connectin
- pg_close($link);
- // Return routing result
- header('Content-type: application/json',true);
- echo json_encode($geojson);
- ?>
- var statusA= "'active'";
- var geojson = new L.geoJson.ajax("php/request.php?status="+statusA, {
- style:style,
- onEachFeature:popUp,
- pointToLayer:function(feature,latlng){
- return L.circleMarker(latlng)}});
- onEachFeature:popUp
- // function for the popup window
- function popUp(feature,layer){
- layer.bindPopup('<b>' + feature.properties.name + '</b></br><small>('+ feature.properties.status + ' )</small>');
- layer.on('mouseover', function(e){
- this.openPopup();
- });
- };
- geojson.addTo(map);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement