0

I have added vector layer(features) on the map. when i click on the feature , in the back end it has to take the latlon values and retrieve the data from database(using php) and display the values in the popup. i am able to retrieve the values from the database, but the values are displaying in another page but not in the popup my code is

function createPopup(feature) {

    var temp=temponclick(feature.geometry.x ,feature.geometry.y,name);
            popup1 = new GeoExt.Popup({
        title: 'My Popup',
        location: feature,
        width:200,

        html: temp,
        maximizable: true,
        collapsible: true,
        anchorPosition: "auto"
    });

    popup1.on({
        close: function() {
            if(OpenLayers.Util.indexOf(vectorLayer.selectedFeatures,
                                       this.feature) > -1) {
                selectCtrl.unselect(this.feature);
            }
        }
    });
    popup1.show();
}

vectorLayer.events.on({
    featureselected: function(e) {

        createPopup(e.feature);

    }
});

  mapPanel.map.addControl(selectCtrl);
  selectCtrl.activate();

 function temponclick(x, y,name) {

     var url = 'temperature.php?';
 var query = 'x=' + x + '&y=' + y+ '&name=' + name;

 window.location = url + query;
}

temperature.php

while( $row = mysql_fetch_assoc($result) ) {
echo '<input type="label" id="temp"  value="' . $row['temperature'] . '"  />';

}

?> 

1 Answer 1

0

I think your temponclick function has to return the html value sent from the temperature.php not redirect to it. what I suggest is to do an AJAX Call to the temperature.php from your function temponclick(..) with a POST method and then return the data retrieved from it here is an example of it:

$.ajax({
        url: 'temperature.php',
        type: 'POST',
        data: {
            x: x,
            y: y,
            name: name
        },
        success:function(response){
            console.log("data retrieved");
            temp=response;
        }
    });

this should be added in your temponclick function after that, you return the temp value:

   return temp;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.