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

相关推荐
安迁岚1 天前
基于珠三角城市热岛热点核心中心点的等级化点格局分析
人工智能·arcgis·信息可视化·数据挖掘·数据分析·地统计
赵钰老师2 天前
地理信息系统(ArcGIS)在水文水资源、水环境中的应用
arcgis·数据分析
wand codemonkey5 天前
【第四步+前后分离调】用VS Code工具写Vue3项目需要写哪些写哪些文件才能实现联调
arcgis
三*一5 天前
Mapbox GL JS 自研面要素整形工具开发实录
开发语言·javascript·arcgis·ecmascript
qq_381338505 天前
前端状态管理新范式:Zustand、Jotai 与 Preact Signals 深度对比
前端·arcgis
智航GIS6 天前
ArcGIS大师之路500技---077ArcGIS Pro 划分工具-按指定面积精确切割图斑
arcgis
wuyu09206 天前
arcgis for js 4.x 引入天地图的地图服务
arcgis
GIS思维6 天前
ArcGIS及ArcGIS Pro数据标准入库怎么快一点?
arcgis·arcgispro·数据入库
城数派7 天前
1958-2024年全球4km分辨率逐月土壤湿度栅格数据
数据库·arcgis·信息可视化·excel
DXM05217 天前
第11期:实战| ArcGIS Pro 遥感影像预处理
人工智能·arcgis·#arcpy·#arcgis 二次开发·#gis 自动化