简体   繁体   中英

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;
            });
        }
      });

获取FeatureInfoUrl

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'},  
        );

You could request the data in another format (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM