Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
100 views
in Technique[技术] by (71.8m points)

javascript - On selecting the radio button of a layer, Popup of different layer opens instead of the selected one

In Continuation to, " How to fetch the URL of specific GeoServer layer by switching radio button? "

I have tried to generate the URL of specific GeoServer layer after selecting the radio button of that layer.

       $('input[name="WeatherParameterLayerRadioButton"]').on('click', function() {
        var radioValue = $('input[name="WeatherParameterLayerRadioButton"]:checked').val(); 

for which, I have created an array of Layers

        let district_url_pass = [
          rainfall_layer, 
          maximum_temperature_layer, 
          minimum_temperature_layer,
          cloud_cover_layer]

In the console,

the multiple URL's are being generated,

and the last returned URL is of the layer selected trough Radio Button,

But the Pop-Up of different layer appears on the map.

Like if I select the rainfall, the popup of cloud_cover opens up. layer

        if (radioValue == 'Rainfall_layer') {
          Rainfall_layer_url_pass = district_url_pass[0];

          map.on('click',function(evt){
            var resolution=map.getView().getResolution();
            var coordinate=evt.coordinate;  
            var projection=map.getView().getProjection();
    
          var Rainfall_layer_url=Rainfall_layer_url_pass.getSource().getFeatureInfoUrl(
            coordinate,
            resolution,
            projection,
          {
          'INFO_FORMAT':'application/json',
          'FEATURE_COUNT': '5', 
          'propertyName': 'issue_date,forecast_date,district_name,rainfall'
           })
          console.log("Rainfall_layer_url:"+Rainfall_layer_url)
            if (Rainfall_layer_url){
                $.getJSON(Rainfall_layer_url,function(Rainfall_data){
    
    
                  popup_content.innerHTML = 
    
                  '<table id="weather_forecast_table"> <caption> The forecast Issued on:&nbsp;' + Rainfall_data.features[0].properties.issue_date + ',' + '&nbsp; 
for next 5 days of district:
&nbsp;'+ Rainfall_data.features[0].properties.district_name+ '&nbsp; </caption> <tr><th>&nbsp; Forecast Date&nbsp; </th> <th> &nbsp; Rainfall (mm) &nbsp; </th>  <tr> <td>&nbsp; ' + Rainfall_data.features[0].properties.forecast_date + '&nbsp; </td> <td>&nbsp; ' + Rainfall_data.features[0].properties.rainfall + '&nbsp; </td></tr> <tr><td>&nbsp; ' + Rainfall_data.features[1].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Rainfall_data.features[1].properties.rainfall + '&nbsp; </td> <tr><td>&nbsp; ' + Rainfall_data.features[2].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Rainfall_data.features[2].properties.rainfall + '&nbsp; </td> <tr><td>&nbsp; ' + Rainfall_data.features[3].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Rainfall_data.features[3].properties.rainfall + '&nbsp; </td><tr><td>&nbsp; ' + Rainfall_data.features[4].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Rainfall_data.features[4].properties.rainfall + '&nbsp; </td> </tr></table>'
    
                  overlay.setPosition(coordinate);
                
                })
              }
             })
     
        }
        else if (radioValue == 'Maximum_temperature_layer') {
          Maximum_temperature_url_pass = district_url_pass[1];

          map.on('click',function(evt){
            var resolution=map.getView().getResolution();
            var coordinate=evt.coordinate;  
            var projection=map.getView().getProjection();
    
          var Maximum_temperature_url = Maximum_temperature_url_pass.getSource().getFeatureInfoUrl(
            coordinate,
            resolution,
            projection,
          {
          'INFO_FORMAT':'application/json',
          'FEATURE_COUNT': '5', 
          'propertyName': 'issue_date,forecast_date,district_name,temperature_max'
           })
          console.log("Maximum_temperature_url:"+Maximum_temperature_url)
            if (Maximum_temperature_url){
                $.getJSON(Maximum_temperature_url,function(Maximum_temperature_data){
    
    
                  popup_content.innerHTML = 
    
                  '<table id="weather_forecast_table"> <caption> The forecast Issued on:&nbsp;' + Maximum_temperature_data.features[0].properties.issue_date + ',' + '&nbsp; 
for next 5 days of district:
&nbsp;'+ Maximum_temperature_data.features[0].properties.district_name+ '&nbsp; </caption> <tr><th>&nbsp; Forecast Date&nbsp; </th> <th> &nbsp; Maximum Temperature  (°C) &nbsp; </th>  <tr> <td>&nbsp; ' + Maximum_temperature_data.features[0].properties.forecast_date + '&nbsp; </td> <td>&nbsp; ' + Maximum_temperature_data.features[0].properties.temperature_max + '&nbsp; </td></tr> <tr><td>&nbsp; ' + Maximum_temperature_data.features[1].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Maximum_temperature_data.features[1].properties.temperature_max + '&nbsp; </td> <tr><td>&nbsp; ' + Maximum_temperature_data.features[2].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Maximum_temperature_data.features[2].properties.temperature_max + '&nbsp; </td> <tr><td>&nbsp; ' + Maximum_temperature_data.features[3].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Maximum_temperature_data.features[3].properties.temperature_max + '&nbsp; </td><tr><td>&nbsp; ' + Maximum_temperature_data.features[4].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Maximum_temperature_data.features[4].properties.temperature_max + '&nbsp; </td> </tr></table>'
    
                  overlay.setPosition(coordinate);
                
                })
              }
             })    

        }
        else if (radioValue == 'Minimum_temperature_layer') {
          Minimum_temperature_url_pass = district_url_pass[2];

          map.on('click',function(evt){
            var resolution=map.getView().getResolution();
            var coordinate=evt.coordinate;  
            var projection=map.getView().getProjection();
    
          var Minimum_temperature_url = Minimum_temperature_url_pass.getSource().getFeatureInfoUrl(
            coordinate,
            resolution,
            projection,
          {
          'INFO_FORMAT':'application/json',
          'FEATURE_COUNT': '5', 
          'propertyName': 'issue_date,forecast_date,district_name,temperature_min'
           })
          console.log("Minimum_temperature_url:"+Minimum_temperature_url)
            if (Minimum_temperature_url){
                $.getJSON(Minimum_temperature_url,function(Minimum_temperature_data){
    
    
                  popup_content.innerHTML = 
    
                  '<table id="weather_forecast_table"> <caption> The forecast Issued on:&nbsp;' + Minimum_temperature_data.features[0].properties.issue_date + ',' + '&nbsp; 
for next 5 days of district:
&nbsp;'+ Minimum_temperature_data.features[0].properties.district_name+ '&nbsp; </caption> <tr><th>&nbsp; Forecast Date&nbsp; </th> <th> &nbsp; Minimum Temperature  (°C) &nbsp; </th>  <tr> <td>&nbsp; ' + Minimum_temperature_data.features[0].properties.forecast_date + '&nbsp; </td> <td>&nbsp; ' + Minimum_temperature_data.features[0].properties.temperature_min + '&nbsp; </td></tr> <tr><td>&nbsp; ' + Minimum_temperature_data.features[1].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Minimum_temperature_data.features[1].properties.temperature_min + '&nbsp; </td> <tr><td>&nbsp; ' + Minimum_temperature_data.features[2].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Minimum_temperature_data.features[2].properties.temperature_min + '&nbsp; </td> <tr><td>&nbsp; ' + Minimum_temperature_data.features[3].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Minimum_temperature_data.features[3].properties.temperature_min + '&nbsp; </td><tr><td>&nbsp; ' + Minimum_temperature_data.features[4].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Minimum_temperature_data.features[4].properties.temperature_min + '&nbsp; </td> </tr></table>'
    
                  overlay.setPosition(coordinate);
                
                })
              }
             })    



        }
        
        else {
          Cloud_cover_url_pass = district_url_pass[3];

          map.on('click',function(evt){
            var resolution=map.getView().getResolution();
            var coordinate=evt.coordinate;  
            var projection=map.getView().getProjection();
    
          var Cloud_cover_url=Cloud_cover_url_pass.getSource().getFeatureInfoUrl(
            coordinate,
            resolution,
            projection,
          {
          'INFO_FORMAT':'application/json',
          'FEATURE_COUNT': '5', 
          //'propertyName': 'issue_date, forecast_date, district_name, cloud_cover',
          'propertyName': 'issue_date,forecast_date,district_name,cloud_cover',
           })
          console.log("Cloud_cover_url:"+Cloud_cover_url)
            if (Cloud_cover_url){
                $.getJSON(Cloud_cover_url,function(Cloud_cover_data){
    
    
                  popup_content.innerHTML = 
    
                  '<table id="weather_forecast_table"> <caption> The forecast Issued on:&nbsp;' + Cloud_cover_data.features[0].properties.issue_date + ',' + '&nbsp; 
for next 5 days of district:
&nbsp;'+ Cloud_cover_data.features[0].properties.district_name+ '&nbsp; </caption> <tr><th>&nbsp; Forecast Date&nbsp; </th> <th> &nbsp; Cloud Cover (Octa) &nbsp; </th>  <tr> <td>&nbsp; ' + Cloud_cover_data.features[0].properties.forecast_date + '&nbsp; </td> <td>&nbsp; ' + Cloud_cover_data.features[0].properties.cloud_cover + '&nbsp; </td></tr> <tr><td>&nbsp; ' + Cloud_cover_data.features[1].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Cloud_cover_data.features[1].properties.cloud_cover + '&nbsp; </td> <tr><td>&nbsp; ' + Cloud_cover_data.features[2].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Cloud_cover_data.features[2].properties.cloud_cover + '&nbsp; </td> <tr><td>&nbsp; ' + Cloud_cover_data.features[3].properties.forecast_date + '&nbsp; </td><td>&nbsp; ' + Cloud_cover_data.features[3].properties.cloud_cover + '&nbsp; </td><tr><td>&nbsp; ' + Cloud_cover_data.features[4].properties.fore

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...