关于前端:记录一次arcgis-for-js自定义切片底图

40次阅读

共计 3820 个字符,预计需要花费 10 分钟才能阅读完成。

需要:将天地图底图切换为 WMTS 瓦片底图
资料:

  1. arcgis 服务端 wmts 的 mapserver 服务
  2. arcgis for js 4.X

第一次操作:
计划构思:思考到是 wmts 服务,首先应用BaseTileLayer
spatialReference 抉择 4490

export const tdtlayer = async () => {
  let BaseTileLayer = await arcgisPackage.BaseTileLayer;
  let Request = await arcgisPackage.Request;
  let TDT = await BaseTileLayer.createSubclass({
    properties: {urlTemplate: null,},
    spatialReference: config.centerPoint.spatialReference,
    title: "天地图影像地图",
    getTileUrl: function (level, row, col) {
      let url ="https://192.168.***.***:6443/arcgis/rest/services/*******/ImageBaseMap/MapServer" +
        col +
        "&y=" +
        row +
        "&l=" +
        level;
      return url;
    },
    fetchTile: function (level, row, col) {let url = this.getTileUrl(level, row, col);
      return Request(url, {responseType: "image",}).then((response) => {
        let image = response.data;
        let width = this.tileInfo.size[0];
        let height = this.tileInfo.size[0];

        let canvas = document.createElement("canvas");
        let context = canvas.getContext("2d");
        canvas.width = width;
        canvas.height = height;

        context.drawImage(image, 0, 0, width, height);

        return canvas;
      });
    },
  });
  let layer = await new TDT();
  return layer;
};

后果:失败,始终失去 3857 投影。

第二次操作
构思计划:采纳 4.X 罕用的WebTileLayer

export const tdtJWDShiLianglayer = async () => {
  let TileInfo = await arcgisPackage.TileInfo;
  let WebTileLayer = await arcgisPackage.WebTileLayer;
  var tileInfo = new TileInfo({
    dpi: 90.71428571427429,// 解析度,即像素
    rows: 256,
    cols: 256,
    compressionQuality: 0,// 压缩像素值
    origin: {
      x: -180,
      y: 90
    },
    spatialReference: {wkid: 4490},
    lods: [// 定义平铺计划的细节级别数组
        {level: 2, levelValue: 2, resolution: 0.3515625, scale: 147748796.52937502},
        {level: 3, levelValue: 3, resolution: 0.17578125, scale: 73874398.264687508},
        {level: 4, levelValue: 4, resolution: 0.087890625, scale: 36937199.132343754},
        {level: 5, levelValue: 5, resolution: 0.0439453125, scale: 18468599.566171877},
        {level: 6, levelValue: 6, resolution: 0.02197265625, scale: 9234299.7830859385},
        {level: 7, levelValue: 7, resolution: 0.010986328125, scale: 4617149.8915429693},
        {level: 8, levelValue: 8, resolution: 0.0054931640625, scale: 2308574.9457714846},
        {level: 9, levelValue: 9, resolution: 0.00274658203125, scale: 1154287.4728857423},
        {level: 10, levelValue: 10, resolution: 0.001373291015625, scale: 577143.73644287116},
        {level: 11, levelValue: 11, resolution: 0.0006866455078125, scale: 288571.86822143558},
        {level: 12, levelValue: 12, resolution: 0.00034332275390625, scale: 144285.93411071779},
        {level: 13, levelValue: 13, resolution: 0.000171661376953125, scale: 72142.967055358895},
        {level: 14, levelValue: 14, resolution: 8.58306884765625e-005, scale: 36071.483527679447},
        {level: 15, levelValue: 15, resolution: 4.291534423828125e-005, scale: 18035.741763839724},
        {level: 16, levelValue: 16, resolution: 2.1457672119140625e-005, scale: 9017.8708819198619},
        {level: 17, levelValue: 17, resolution: 1.0728836059570313e-005, scale: 4508.9354409599309},
        {level: 18, levelValue: 18, resolution: 5.3644180297851563e-006, scale: 2254.4677204799655},
        {level: 19, levelValue: 19, resolution: 2.68220901489257815e-006, scale: 1127.23386023998275},
        {level: 20, levelValue: 20, resolution: 1.341104507446289075e-006, scale: 563.616930119991375}
    ]
  });
  var tiledLayer = new WebTileLayer('https://192.168.***.***:6443/arcgis/rest/services/*******/ImageBaseMap/MapServer?T=vec_c&X={col}&Y={row}&L={level}',{
    tileInfo: tileInfo,
    spatialReference: {wkid: 4490},
  });
  return tiledLayer
}

后果:失败,起因还是投影坐标系改不了

第三次操作:
构思计划:抉择 MapImageLayer
后果:胜利,然而性能十分差,须要一次加载,舍弃。

第”三. 九“次操作:
构思计划:抉择 WMTSLayer
如果是 arcgis 发的服务肯定要记得在 url 前面加上 WMTS,这个官网文档没有提及,十分坑!!!!!!!

export const TestCustomWMTS = async () => {
  //wmtslayer
  const WMTSLayer = await arcgisPackage.WMTSLayer;
  let wmtsLayers = new WMTSLayer({url: "https://192.168.***.***:6443/arcgis/rest/services/*******/ImageBaseMap/MapServer/WMTS", // url to the service});
  return wmtsLayers
}

后果:胜利,然而无奈定位,察看 layer 对象,发现他的投影坐标系是 4326,预计大抵起因就是这个导致的。于是察看 api 文档,发现 wmtslayer 没有 SpatialReference 属性,随后放弃。

第四次操作
构思计划:抉择TileLayer,次要思考到该项 wmts 服务是用 arcgis server 公布的,所以尝试一下。

export const TestCustomWMTS = async () => {
  let TileLayer = await arcgisPackage.TileLayer;
  var tiledLayer = new TileLayer({url:'https://192.168.***.***:6443/arcgis/rest/services/*******/ImageBaseMap/MapServer',});
  return tiledLayer
}

后果:胜利

正文完
 0