基于Openlayer获取wms服务要素信息

OL实例如下:

<body>
    <div id="map" class="map">div>
    <div id="info"> div>
    <script>
      var wmsSource = new ol.source.ImageWMS({
        url: 'https://ahocevar.com/geoserver/wms',
        params: {'LAYERS': 'ne:ne'},
        serverType: 'geoserver',
        crossOrigin: 'anonymous'
      });

      var wmsLayer = new ol.layer.Image({
        source: wmsSource
      });

      var view = new ol.View({
        center: [0, 0],
        zoom: 1
      });

      var map = new ol.Map({
        layers: [wmsLayer],
        target: 'map',
        view: view
      });

      map.on('singleclick', function(evt) {
        document.getElementById('info').innerHTML = '';
        var viewResolution = /** @type {number} */ (view.getResolution());
        var url = wmsSource.getGetFeatureInfoUrl(
            evt.coordinate, viewResolution, 'EPSG:3857',
            {'INFO_FORMAT': 'text/html'});
        if (url) {
          document.getElementById('info').innerHTML =
              '';
        }
      });

      map.on('pointermove', function(evt) {
        if (evt.dragging) {
          return;
        }
        var pixel = map.getEventPixel(evt.originalEvent);
        var hit = map.forEachLayerAtPixel(pixel, function() {
          return true;
        });
        map.getTargetElement().style.cursor = hit ? 'pointer' : '';
      });
    script>
  body>
通过ol实例进行测试获取wms服务:
'https://ahocevar.com/geoserver/wms'
 
  
获取地图服务的结果如下:
自己用arcGIS发布的wms如何获取地图服务的结果如下:

正常发布的WMS:http://XXXX.XXXX.XXXX.XXX:XXXX/arcgis/rest/services/cjTest/MapServer  

在调用wms URL时需要对URL和请求参数进行设置。如下:

1. url 将rest除去,并在url中的MapServer后加/WMSServer ;说明本服务已wms调用。

修改前:

http:// XXXX.XXXX.XXXX.XXX:XXXX/arcgis/rest/services/cjTest/MapServer

修改后:

http:// XXXX.XXXX.XXXX.XXX:XXXX/arcgis/services/cjTest/MapServer/WMSServer

2.图层参数设置成发布的wms图层名称。

http://XXXX.XXXX.XXXX.XXX:XXXX/arcgis/services/cjTest/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=0&LAYERS=0&INFO_FORMAT=text%2Fhtml&I=50&J=50&CRS=EPSG%3A3857&STYLES=&WIDTH=101&HEIGHT=101&BBOX=13251481.821211813%2C3779523.7787383264%2C13282362.380639026%2C3810404.3381655374

红色部分为图层参数部分。

基于Openlayer获取wms服务要素信息_第1张图片

你可能感兴趣的:(WebGIS,wms)