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 小时前
Openlayers调用ArcGis地图服务之五 —— 要素识别(/identify)
前端·arcgis·vue·数据可视化
非科班Java出身GISer2 小时前
ArcGIS Maps SDK for JavaScript 5.0 组件化开发指南
javascript·arcgis·components·arcgis js 组件化·arcgis js5.0·arcgis js5.0初始化
Gene_202221 小时前
ubuntu22.04安装Claude Code及其在vscode跑通
ide·vscode·arcgis
GIS地信小匠2 天前
(34)ArcGIS Pro 要素折点转点工具:线面节点批量提取实操
arcgis·空间分析·数据处理·gis教程·arcgls pro
蜂蜜狮子头2 天前
arcgis计算几何周长、面积被禁用
arcgis
非科班Java出身GISer2 天前
ArcGIS JS 基础教程(5):地图限制缩放级别和显示范围
arcgis·arcgis js限制范围·arcgis js 限制·arcgis js地图限制·arcgis js 范围
无心使然云中漫步4 天前
Openlayers调用ArcGis地图服务之一 —— 地图切片(/tile)
前端·arcgis·vue·数据可视化
无心使然云中漫步4 天前
Openlayers调用ArcGis地图服务之三 —— 要素查询(/query)
前端·arcgis·vue·数据可视化
无心使然云中漫步5 天前
Openlayers调用ArcGis地图服务之二 —— 动态地图(/export)
前端·arcgis·vue·数据可视化
IT菜鸟程5 天前
漏洞修复案例:ArcGIS Server REST 服务目录敏感信息泄露
网络·安全·arcgis