本文介绍了未定义WMSLayerInfo-Arcgis 4.13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,今天才刚开始使用arcgis,并尝试从geoserver添加wms图层.我正在使用javascript api v 4.13.

Folks, just started using arcgis today and attempting to add a wms layer from geoserver. I am using the javascript api v 4.13.

我从这个例子开始:

https://developers.arcgis .com/javascript/latest/sample-code/layers-wms/live/index.html

然后继续添加WMS层,如下所示(我添加了////TEST-START to END):

Then proceeded to add the WMS layer as follows (I added the section // TEST - START to END):

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>WMSLayer - 4.13</title>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.13/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.13/"></script>

    <script>
      require([
        "esri/Map",
        "esri/views/SceneView",
        "esri/layers/WMSLayer",
        "esri/layers/WMSLayerInfo",
        "esri/geometry/Extent"
      ], function(Map, SceneView, WMSLayer, WMSLayerInfo, Extent) {
        var layer = new WMSLayer({
          url: "https://ows.terrestris.de/osm/service",
          sublayers: [
            {
              name: "OSM-WMS"
            }
          ]
        });

        var map = new Map({
          basemap: {
            baseLayers: [layer]
          }
        });

        var view = new SceneView({
          container: "viewDiv",
          map: map
        });

        // TEST - START
    var layer1 = new WMSLayerInfo({
        name: 'sf:test1',
        title: 'sf:test1'
    });

    var resourceInfo = {
        extent: new Extent(3, 4, 5, 6, {
        wkid: 2236
    }),
        layerInfos: [layer1]
    };

    var wmsLayer = new WMSLayer('https://myserver/geoserver/sf/wms', {
        resourceInfo: resourceInfo,
        visibleLayers: ['sf:test1']
    });

    map.addLayers([wmsLayer]);

    // TEST - END



      });
      /***********************************
       * Data attribution:
       *  OpenStreetMap WMS by terrestris GmbH and Co. KG. Following sources were used:
       *  (c) OpenStreetMap contributors (http://www.openstreetmap.org/copyright)
       *  (c) OpenStreetMap Data (http://openstreetmapdata.com)
       *  (c) Natural Earth Data (http://www.naturalearthdata.com)
       *  (c) ASTER GDEM 30m (https://asterweb.jpl.nasa.gov/gdem.asp)
       *  (c) SRTM 450m by ViewfinderPanoramas (http://viewfinderpanoramas.org/)
       *  (c) Great Lakes Bathymetry by NGDC (http://www.ngdc.noaa.gov/mgg/greatlakes/)
       *  (c) SRTM 30m by NASA EOSDIS Land Processes Distributed Active Archive Center (LP DAAC, https://lpdaac.usgs.gov/)
       *********************************/
    </script>
  </head>
  <body>
    <div id="viewDiv"></div>
  </body>
</html>

我收到错误未定义WMSLayerInfo".我知道它可能非常基础,但是我无法在线找到答案.先谢谢你.

I am receiving the error "WMSLayerInfo is not defined". I know its probably something very basic but I cannot find the answer online. Thank you before hand.

推荐答案

在您的require语句中,您正在尝试加载"esri/layers/WMSLayerInfo"模块,该模块在Arcgis Javascript API v4.x中不存在

In your require statement, you are trying to load "esri/layers/WMSLayerInfo" module which does not exists in Arcgis Javascript API v4.x

只需将其从要加载的模块列表中删除.

Just remove it from the list of modules you are trying to load.

require([
        "esri/Map",
        "esri/views/SceneView",
        "esri/layers/WMSLayer",
        "esri/geometry/Extent"
      ], function(Map, SceneView, WMSLayer, Extent) {

})

不要忘记在代码中删除对WMSLayerInfo的任何引用,并确保使用 ArcGIS Javascript API v4.x文档.

Dont forget to remove any references to WMSLayerInfo in your code and be sure to use the ArcGIS Javascript API v4.x documentation.

这篇关于未定义WMSLayerInfo-Arcgis 4.13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:48