arcgis js api 4.x加载geoserver发布的地方坐标系(自定义坐标系)的wms服务

问题描述:之前研究过arcgis js api 4.x加载arcgis server 发布的地方坐标系的wms服务,后来研究出来能正常加载了,想了解的可以看我之前的博客。但是一直困于加载geoserver发布的地方坐标系的wms服务,一直都是用的WMSLayer这个调用,一直报坐标系不兼容的错误。

1.地方坐标系不是标准的坐标系,没有对应的EPSG编码,是为了加密对标准坐标进行偏移等操作形成的新的坐标系。

2.在geoserver发布服务的时候,不占用现有的EPSG编码,需要在epsg.properties文件中追加一条地方坐标系的geoserver格式的wkt,可以参照类似格式将自己的坐标系wkt串调整。追加完需要重启geoserver服务3.geoserver发布服务的时候选择坐标系选择 刚加的epsg:0;如果选择的数据的srid与0不一样需要将数据的srid改变或转换下,如原来的数据的srid是4547,我可以通过这种select语句方式改变srid为0 ,如果不改变,预览wms服务时会报srid不一致的错误!

select objectid,ST_GeomFromText(ST_AsText(geom), 0) geom,safegrade from gis

4.发布完wms服务,能正常预览后,需要用arcgis js api 4.x写代码了,这是重点!

构造一个CustomWMSLayer类,然后进行实例化传参,最后map加载gisLayer即可。大功告成!!!

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

                getImageUrl: function (extent, width, height) {
                    const urlVariables = this._prepareQuery(
                        this.mapParameters,
                        extent,
                        width,
                        height
                    );
                    const queryString = this._joinUrlVariables(urlVariables);
                    return this.mapUrl + "?" + queryString;
                },

                _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: (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;
                },

                _joinUrlVariables: (urlVariables) => {
                    return Object.keys(urlVariables).reduce((previous, key) => {
                        return (
                            previous + (previous ? "&" : "") + key + "=" + urlVariables[key]
                        );
                    }, "");
                }
            });

            const gisLayer = new CustomWMSLayer({
                mapUrl: "http://localhost:9000/geoserver/topp/wms",
                mapParameters: {
                    SERVICE: "WMS",
                    REQUEST: "GetMap",
                    FORMAT: "image/png",
                    TRANSPARENT: "TRUE",
                    STYLES: "",
                    VERSION: "1.3.0",
                    LAYERS: "topp:gis",
                    WIDTH: "{width}",
                    HEIGHT: "{height}",
                    CRS: "EPSG:0",
                    BBOX: "{xmin},{ymin},{xmax},{ymax}"
                },
            });

参考文档为arcgis js api官方文档Sandbox | Sample Code | ArcGIS Maps SDK for JavaScript 4.27 | ArcGIS Developers

相关推荐
玩大数据的龙威2 天前
农经权二轮延包—付费软件插件与免费软件插件汇总
python·arcgis
墨黎芜2 天前
ArcGIS从入门到精通——地图符号、注记的初步使用
学习·arcgis·信息可视化
GIS地信小匠3 天前
(31)ArcGIS Pro 定义投影与批量投影:矢量数据坐标转换工具实操
arcgis·空间分析·数据处理·gis教程·arcgls pro
非科班Java出身GISer4 天前
ArcGIS JS 基础教程(3):地图缩放、平移、旋转(基础交互)
arcgis·arcgis js地图交互·arcgis js缩放·arcgis js平移·arcgis js旋转·arcgis js基础交互
城数派4 天前
2025年我国省市县三级的平均坡度数据(Excel\Shp格式)
arcgis·信息可视化·数据分析·excel
装疯迷窍_A4 天前
以举证方位线生成工具为例,分享如何在Arcgis中创建Python工具箱(含源码)
开发语言·python·arcgis·变更调查·举证照片
Trustport5 天前
ArcGIS Maps SDK For Kotlin 加载Layout中的MapView出错
android·开发语言·arcgis·kotlin
GIS地信小匠5 天前
(30)ArcGIS Pro 查找相同项+删除相同项:矢量数据去重实操
arcgis·空间分析·数据处理·gis教程·arcgls pro
城数派6 天前
2025年我国乡镇的平均高程数据(Excel\Shp格式)
数据库·arcgis·信息可视化·数据分析·excel
城数派7 天前
2025年省市县三级的平均高程数据(Excel\Shp格式)
数据库·arcgis·信息可视化·excel