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

相关推荐
受伤的僵尸2 小时前
为什么Arcgis/Qgis里我的图是扁的
arcgis
weixin_贾5 小时前
ArcGIS+ENVI实战:从零制作生态影响评价专题图(以植被类型与土壤侵蚀为例)
arcgis·土地利用·dem·水文分析·土壤侵蚀·arcgis栅格·envi遥感影像
Q一件事2 天前
Arcgis出图出现横条/条纹问题的解决方案
arcgis
凌然先生3 天前
17.如何利用ArcGIS进行空间统计分析
经验分享·笔记·arcgis·电脑
GIS思维4 天前
ArcGIS图斑属性自动智能填写!告别手动低效输入
arcgis
ByteCraze4 天前
一文讲透 npm 包版本管理规范
前端·arcgis·npm
龙仔CLL5 天前
微前端乾坤vue3项目使用tinymce,通过npm,yarn,pnpm包安装成功,但是引用报错无法使用
javascript·arcgis·npm
Yolo566Q5 天前
空间数据采集与管理丨在 ArcGIS Pro 中利用模型构建器批处理多维数据
arcgis
网上邻居YY6 天前
Arcgis表格数据导入+可视化--小白教程(以景观多样性指数为例)
图像处理·计算机视觉·arcgis·excel转表
非科班Java出身GISer6 天前
ArcGIS JSAPI 学习教程 - 可视域分析图层介绍-创建与编辑
arcgis·arcgis 可视域分析·arcgis js 可视域·arcgis 可视域分析图层·arcgis js 可视域图层·arcgis 可视域