【问题标题】:How to Fetch Specific data column from Geoserver WMS layer using openlayers?如何使用 openlayers 从 Geoserver WMS 层获取特定数据列?
【发布时间】:2021-01-08 08:59:46
【问题描述】:

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

【问题讨论】:

    标签: javascript openlayers geoserver wms openlayers-6


    【解决方案1】:

    您可以使用 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'},  
            );
    

    【讨论】:

      【解决方案2】:

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

      或者,您可以创建一个FreeMarker template 来自定义 HTML 输出。

      【讨论】:

        猜你喜欢
        • 2015-02-17
        • 2023-04-06
        • 2023-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-15
        相关资源
        最近更新 更多