openlayer WMS GetFeatureInfo(图层)

WMS GetFeatureInfo(图层)

所有功能: 6
酒店特色: 2
餐厅特色: 4

演示layersol/format/WMSGetFeatureInfoformat对象中使用该选项,该选项允许单个WMS GetFeatureInfo请求返回的功能要求按层名读取多个图层。

<!DOCTYPE html><html>

  <head>

    <title>WMS GetFeatureInfo (Layers)</title>

    <link rel=”stylesheet href=”https://openlayers.org/en/v5.1.3/css/ol.css type=”text/css“>

    <!– The line below is only needed for old environments like Internet Explorer and Android 4.x –>

    <script src=”https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL“></script>

  </head>

  <body>

    <table id=”info“>

      <tr>

        <td>All features:</td>

        <td id=”all“></td>

      </tr>

      <tr>

        <td>Hotel features:</td>

        <td id=”hotel“></td>

      </tr>

      <tr>

        <td>Restaurant features:</td>

        <td id=”restaurant“></td>

      </tr>

    </table>

    <script>

      import WMSGetFeatureInfo from ‘ol/format/WMSGetFeatureInfo.js’;

 

      fetch(‘data/wmsgetfeatureinfo/osm-restaurant-hotel.xml’).then(function(response) {

        return response.text();

      }).then(function(response) {

 

        // this is the standard way to read the features

        var allFeatures = new WMSGetFeatureInfo().readFeatures(response);

        document.getElementById(‘all’).innerText = allFeatures.length.toString();

 

        // when specifying the ‘layers’ options, only the features of those

        // layers are returned by the format

        var hotelFeatures = new WMSGetFeatureInfo({

          layers: [‘hotel’]

        }).readFeatures(response);

        document.getElementById(‘hotel’).innerText = hotelFeatures.length.toString();

 

        var restaurantFeatures = new WMSGetFeatureInfo({

          layers: [‘restaurant’]

        }).readFeatures(response);

        document.getElementById(‘restaurant’).innerText = restaurantFeatures.length.toString();

 

      });

    </script>

  </body></html>

 

转载自:https://blog.csdn.net/qq_36178899/article/details/81195701

You may also like...