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

相关推荐
allenjiao6 天前
Cesium粒子系统模拟风场动态效果
javascript·arcgis·gis·webgl·cesium·三维·风场
杨超越luckly7 天前
HTML应用指南:利用GET请求获取全国Apple Store 零售店位置信息
大数据·前端·arcgis·html·数据可视化·门店
典学长编程8 天前
前端开发(HTML,CSS,VUE,JS)从入门到精通!第八天(Vue框架及其安装)(完结篇) 重点 ! ! !
arcgis·vue·vue路由·vue脚手架·router
Wild Iris9 天前
【ArcGIS】分区统计中出现Null值且Nodata无法忽略的问题以及shp擦除(erase)的使用——以NDVI去水体为例
arcgis
新中地GIS开发老师11 天前
2025Mapbox零基础入门教程(14)定位功能
前端·javascript·arcgis·gis·mapbox·gis开发·地理信息科学
杨超越luckly16 天前
HTML应用指南:利用GET请求获取全国小米之家门店位置信息
前端·arcgis·html·数据可视化·shp
新中地GIS开发老师17 天前
准大一GIS专业新生,如何挑选电脑?
javascript·arcgis·电脑·gis·大学生·webgis·地理信息科学
Bigemap软件18 天前
BigemapPro吸附功能 | 绘图共点共边,标绘从此无缝衔接!
arcgis·信息可视化·软件需求·地图·bigemappro
杨超越luckly23 天前
HTML应用指南:利用GET请求获取全国奈雪的茶门店位置信息
大数据·前端·python·arcgis·信息可视化·html
zhou_x_b23 天前
解决栅格数据裁剪矢量数据问题两种方法,ArcGIS解决与PYTHON解决
arcgis