其他分享
首页 > 其他分享> > ol3调用wms

ol3调用wms

作者:互联网

<!DOCTYPE html>
<html>
  <head>
    <title>WMS GetFeatureInfo (Image Layer)</title>
    <link rel="stylesheet" href="http://openlayers.org/en/v3.15.1/css/ol.css" type="text/css">
    <script src="http://openlayers.org/en/v3.15.1/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <div id="info">&nbsp;</div>
    <script>
      var wmsSource = new ol.source.ImageWMS({
        url: 'http://192.168.0.106:6080/arcgis/services/ShaanXi/MapServer/WMSServer',
        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 =
              '<iframe seamless src="' + url + '"></iframe>';
        }
      });

      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>
</html>

 

标签:map,调用,wms,ol3,ol,var,new,evt,view
来源: https://www.cnblogs.com/devgis/p/16542774.html