Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="popup">
- <tr><select id="a1_title"></select></div></tr>
- <tr><select id="a2_title"></select></div></tr>
- <!-- Button (Double) -->
- <div class="form-group">
- <label class="col-md-4 control-label" for="cancel"></label>
- <button type="button" id="cancel" class="btn btn-default cancel">Cancel</button>
- <button type="submit" id="save" class="btn btn-success submit">OK</button>
- </div>
- </div>
- <div id="map" class="map"><div>
- // JavaScript Document
- $(document).ready(function(){
- $.getJSON("php/drpdwn.php", success = function(data){
- var items="";
- for(var i = 0; i< data.length; i++){
- // RETAIN JSON KEY AS OPTION VALUE, JSON VALUE AS OPTION TEXT items +="<option value='"+data[i].id+"'>" + data[i].name+"</option>";
- }
- $("#a1_title").append(items);
- $("#a1_title").change();
- });
- $("#a1_title").change(function(){
- // OBTAIN SELECTED VALUE
- var selectedValue = $(this).find(":selected").text();
- if( selectedValue == "Landuse/landcover") {
- $.getJSON("php/lulc_db.php",success = function(data){
- var items="";
- for(var i = 0; i< data.length; i++){
- items+="<option value='"+data[i]+"'>" + data[i] +"</option>";
- }
- // REMOVE PREVIOUS ITEMS
- var myNode = document.getElementById("a2_title");
- while (myNode.firstChild) {
- myNode.removeChild(myNode.firstChild);
- }
- // ADD NEW ITEMS
- $("#a2_title").append(items);
- });
- $("#a2_title").change(function(){
- //the main problem start from here
- //this the only one which is not working
- var selectedtext = $(this).find(":selected").text();
- if( selectedValue == "Built Up") {
- alert("k");
- $('input[type="submit"]').on('click',function(){
- $.getJSON("php/geojson.php?layer="+ $(this).text(),success = function(data){
- console.log(data);
- });
- }); }
- });
- }
- else if( selectedValue == "Soil") {
- $.getJSON("php/soil_db.php",success = function(data){
- var items="";
- for(var i = 0; i< data.length; i++){
- items+="<option value='"+data[i]+"'>"+data[i]+"</option>";
- }
- // REMOVE PREVIOUS ITEMS
- var myNode = document.getElementById("a2_title");
- while (myNode.firstChild) {
- myNode.removeChild(myNode.firstChild);
- }
- // ADD NEW ITEMS
- $("#a2_title").append(items);
- });
- }
- });
- });
- <?php
- if(isset($_GET["layer"]))
- {
- $host = "localhost";
- $user = "postgres";
- $pass = "admin";
- $db = "Querybuilderdb";
- $con = pg_connect("host=$host dbname=$db user=$user password=$pass")
- or die ("Could not connect to servern");
- $sql = "SELECT gid, level_1 , st_asgeojson(geom) AS geojson FROM pachgaon_lulc where level_1='{$layer}' ";
- $rs = pg_query($con, $sql);
- if (!$rs) {
- echo "An SQL error occured.n";
- exit;
- }
- # Build GeoJSON feature collection array
- $geojson = array(
- 'type' => 'FeatureCollection',
- 'features' => array()
- );
- # Loop through rows to build feature arrays
- while ($row = pg_fetch_array($rs)) {
- $properties = $row;
- # Remove geojson and geometry fields from properties
- unset($properties['geojson']);
- $feature = array(
- 'type' => 'Feature',
- 'id' => $row['gid'],
- 'properties' => array(
- 'name' => $row['level_1']
- ),
- 'geometry' => json_decode($row['geojson']),
- );
- array_push($geojson['features'], $feature);
- }
- header('Content-type: application/json');
- echo json_encode($geojson);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement