繁体   English   中英

如何使用 openlayers 从 Geoserver WMS 层获取特定数据列?

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

我在 Geoserver 中有一个层,我使用openlayers在 HTML 网页上显示它,但它有很多列,

我只想“通过传递列名的字符串”来显示表的特定 1-2 列,而不是整个表。

有什么办法可以吗?


      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

您可以使用 WMS 供应商选项propertyName

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

您可以请求其他格式的数据(例如 JSON)并在您自己的代码中处理它以提供您需要的格式。

或者,您可以创建一个FreeMarker 模板来自定义 HTML output。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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