Abhilash Singh Chauhan
Abhilash Singh Chauhan

Reputation: 289

How to Fetch Specific data column from Geoserver WMS layer using openlayers?

I have a layer in Geoserver, which I am showing on the HTML webpage using openlayers, but it has a lot of columns,

and I want to show the specific 1-2 columns of the table only " by passing the string of column name ", instead of whole table.

Is there any way possible?


      map.on('singleclick', function (evt) {
        document.getElementById('info').innerHTML = '';
        var myviewResolution = myview.getResolution();
        var url = india_dist_rainfall_layer_source.getFeatureInfoUrl(
          evt.coordinate,
          myviewResolution,
          'EPSG:4326',
          {'INFO_FORMAT': 'text/html', 'FEATURE_COUNT': '5'},
          
        );
        if (url) {
          fetch(url)
            .then(function (response) { return response.text(); })
            .then(function (html) {
              document.getElementById('info').innerHTML = html;
            });
        }
      });

getFeatureInfoUrl

Upvotes: 2

Views: 1129

Answers (2)

Ian Turton
Ian Turton

Reputation: 10976

You could request the data in another format (e.g. JSON) and process it in your own code to give exactly the format that you need.

Alternatively, you could create a FreeMarker template to customise the HTML output.

Upvotes: 1

JGH
JGH

Reputation: 17906

You can use the WMS vendor option propertyName

var url = india_dist_rainfall_layer_source.getFeatureInfoUrl(
          evt.coordinate,
          myviewResolution,
          'EPSG:4326',
          {'INFO_FORMAT': 'text/html', 
           'FEATURE_COUNT': '5',
           'propertyName': 'forecastDate,rainfall'},  
        );

Upvotes: 2

Related Questions