arcgis jsapi 4.31 调用geoserver 发布的wms服务

服务的调用我也测试了网络搜索的很多方法,均未奏效,后来还是通过对官网例子的研究,找到了解决方案,调试的过程是非常痛苦的,最大的问题就是调用后没有任何反应,也不会给你任何的错误信息,这是最郁闷的

最终的解决方式是使用通用的动态图层来实现对geoserver发布的wms服务的调用,首先使用通用动态图层基类创建自定义子类,创建的代码来源于官网示例,直接上代码:

javascript 复制代码
      const CustomWMSLayer = BaseDynamicLayer.createSubclass({
          properties: {
            mapUrl: null,
            mapParameters: null
          },

          // Override the getImageUrl() method to generate URL
          // to an image for a given extent, width, and height.
          getImageUrl: function (extent, width, height){
            const urlVariables = this._prepareQuery(this.mapParameters, extent, width, height);
            const queryString = this._joinUrlVariables(urlVariables);
            return this.mapUrl + "?" + queryString;
          },

          // Prepare query parameters for the URL to an image to be generated
          _prepareQuery: function (queryParameters, extent, width, height) {
            const wkid = extent.spatialReference.isWebMercator ? 3857 : extent.spatialReference.wkid;
            const replacers = {
              width: width,
              height: height,
              wkid: wkid,
              xmin: extent.xmin,
              xmax: extent.xmax,
              ymin: extent.ymin,
              ymax: extent.ymax
            };

            const urlVariables = this._replace({}, queryParameters, replacers);
            return urlVariables;
          },

          // replace the url variables with the application provided values
          _replace: (urlVariables, queryParameters, replacers) => {
            Object.keys(queryParameters).forEach((key) => {
              urlVariables[key] = Object.keys(replacers).reduce((previous, replacerKey) => {
                return previous.replace("{" + replacerKey + "}", replacers[replacerKey]);
              }, queryParameters[key]);
            });

            return urlVariables;
          },

          // join the url parameters
          _joinUrlVariables: (urlVariables) => {
            return Object.keys(urlVariables).reduce((previous, key) => {
              return previous + (previous ? "&" : "") + key + "=" + urlVariables[key];
            }, "");
          }
        });
		
		const riverWmsLayer = new CustomWMSLayer({
          mapUrl: "http://IP:port/路径/wms",
          mapParameters: {
            SERVICE: "WMS",
            REQUEST: "GetMap",
            FORMAT: "image/png",
            TRANSPARENT: "TRUE",
            STYLES: "",
            VERSION: "1.3.0",
            LAYERS: "服务里图层名称",
            WIDTH: "{width}",
            HEIGHT: "{height}",
            CRS: "EPSG:{wkid}",
            BBOX: "{xmin},{ymin},{xmax},{ymax}",
			token: "token" //如果有就填入,没有就直接把token参数给删掉
          },

          //minScale: 20000,
          title: "地图上图层名字"
        });

完美调用。

参考:

ArcGIS Maps SDK for JavaScript | Overview | ArcGIS Maps SDK for JavaScript 4.32 | Esri Developer

相关推荐
如影随从3 小时前
11 - ArcGIS For JavaScript -- 高程分析
前端·javascript·arcgis·高程分析
菥菥爱嘻嘻3 小时前
React---day8
前端·react.js·arcgis
jr4283 小时前
【ArcGIS应用】ArcGIS‌应用如何进行影像分类?
arcgis
生态笔记1 天前
ArcGIS计算多个栅格数据的平均栅格
经验分享·arcgis
GIS思维2 天前
ArcGIS Pro字段计算器与计算几何不可用,显示灰色
arcgis·arcgis pro
流年viv3 天前
ArcGIS Pro 创建渔网格网过大,只有几个格网的解决方案
arcgis
新中地GIS开发老师3 天前
新中地三维GIS开发智慧城市效果和应用场景
javascript·arcgis·智慧城市·gis开发·webgis·地理信息科学
小小弯_Shelby5 天前
arcgis js 4.x 的geometryEngine计算距离、面积、缓冲区等报错、失败
arcgis
come112346 天前
全面解析:npm 命令、package.json 结构与 Vite 详解
arcgis·npm·json
UVE7 天前
【免费】【无需登录/关注】坐标系批量转换与可视化网页工具
arcgis·数据分析