arcgis javascript api4.x加载天地图wgs84(wkid:4326)坐标系

news2024/10/7 4:31:54

需求:

使用arcgis javascript api4.x以basetilelayer方式加载天地图wgs84(wkid:4326)坐标系

效果:

代码:

提示:(下述三个文件放同一个文件夹下)

4326.js

define(['exports', 'esri/layers/support/TileInfo', 'esri/config'], function (
    exports,
    TileInfo,
    esriConfig
  ) {
    'use strict'
    const lods = [
      {
        level: 1,
        levelValue: 1,
        resolution: 0.703125,
        scale: 295497593.05875003
      },
      {
        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-5,
        scale: 36071.483527679447
      },
      {
        level: 15,
        levelValue: 15,
        resolution: 4.291534423828125e-5,
        scale: 18035.741763839724
      },
      {
        level: 16,
        levelValue: 16,
        resolution: 2.1457672119140625e-5,
        scale: 9017.8708819198619
      },
      {
        level: 17,
        levelValue: 17,
        resolution: 1.0728836059570313e-5,
        scale: 4508.9354409599309
      },
      {
        level: 18,
        levelValue: 18,
        resolution: 5.3644180297851563e-6,
        scale: 2254.4677204799655
      },
      {
        level: 19,
        levelValue: 19,
        resolution: 2.68220901489257815e-6,
        scale: 1127.23386023998275
      },
      {
        level: 20,
        levelValue: 2,
        resolution: 1.341104507446289075e-6,
        scale: 563.616930119991375
      }
    ]
  
    const tileInfo = new TileInfo({
      dpi: 90.71428571427429,
      rows: 256,
      cols: 256,
      format: 'image/png',
      compressionQuality: 0,
      origin: {
        x: -180,
        y: 90
      },
      spatialReference: {
        wkid: 4326
      },
      lods: lods
    })
  
    exports.tileInfo = tileInfo
    exports.lods = lods
  })
 

MyCustomTileLayer.js

define(['exports', "esri/layers/BaseTileLayer","esri/request"], function (
    exports,
    BaseTileLayer,
    esriRequest
  ) {
    const MyCustomTileLayer = BaseTileLayer.createSubclass({
            // properties of the custom tile layer
            properties: {
              urlTemplate: null,
            },
  
          // override getTileUrl()
          // generate the tile url for a given level, row and column
          getTileUrl: function (level, row, col) {
            return this.urlTemplate.replace("{level}", level).replace("{col}", col).replace("{row}", row);
          },
  
          // This method fetches tiles for the specified level and size.
          // Override this method to process the data returned from the server.
          fetchTile: function (level, row, col, options) {
  
            // call getTileUrl() method to construct the URL to tiles
            // for a given level, row and col provided by the LayerView
            var url = this.getTileUrl(level, row, col);
  
            // request for tiles based on the generated url
            // the signal option ensures that obsolete requests are aborted
            return esriRequest(url, {
              responseType: "image",
              //signal: options && options.signal
               allowImageDataAccess: true 
            })
              .then(function (response) {
                // when esri request resolves successfully
                // get the image from the response
                var image = response.data;
                var width = this.tileInfo.size[0];
                var height = this.tileInfo.size[0];
  
                // create a canvas with 2D rendering context
                var canvas = document.createElement("canvas");
                var context = canvas.getContext("2d");
                canvas.width = width;
                canvas.height = height;
  
                // Apply the tint color provided by
                // by the application to the canvas
                if (this.tint) {
                  // Get a CSS color string in rgba form
                  // representing the tint Color instance.
                  context.fillStyle = this.tint.toCss();
                  context.fillRect(0, 0, width, height);
  
                  // Applies "difference" blending operation between canvas
                  // and steman tiles. Difference blending operation subtracts
                  // the bottom layer (canvas) from the top layer (tiles) or the
                  // other way round to always get a positive value.
                  context.globalCompositeOperation = "difference";
                }
  
                // Draw the blended image onto the canvas.
                context.drawImage(image, 0, 0, width, height);
  
                return canvas;
              }.bind(this));
          }
  
        });
  
  return MyCustomTileLayer;
  })
  
 

loadtdt4326.html

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
        <title>(经纬度)天地图加载</title>
        <style>
            html,
            body,
            #viewDiv {
                width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
            }
        </style>
        <link rel="stylesheet" href="https://js.arcgis.com/4.23/esri/css/main.css" />
        <script src="https://js.arcgis.com/4.23/init.js"></script>
        <script>
            require(["esri/Map",
                "esri/views/MapView",
                "esri/layers/GraphicsLayer",
                "esri/Graphic",
                "esri/PopupTemplate",
                "esri/widgets/Popup",
                "esri/layers/MapImageLayer",
                "esri/widgets/Legend",
                "esri/layers/WebTileLayer",
                "esri/layers/WMTSLayer",
                "esri/widgets/BasemapGallery/support/LocalBasemapsSource",
                "esri/widgets/BasemapGallery",
                "esri/Basemap",
                "esri/layers/FeatureLayer",
                "esri/geometry/Extent",
                "esri/geometry/SpatialReference",
                'esri/config',
                './4326.js',
                
                'esri/layers/support/TileInfo',
                "./MyCustomTileLayer.js",
                "esri/layers/TileLayer",
            ], function(
                Map,
                MapView,
                GraphicsLayer,
                Graphic,
                PopupTemplate,
                Popup,
                MapImageLayer,
                Legend,
                WebTileLayer,
                WMTSLayer,
                LocalBasemapsSource,
                BasemapGallery,
                Basemap,
                FeatureLayer,
                Extent,
                SpatialReference,
                esriConfig,
                epsg4326,
                
                TileInfo,
                MyCustomTileLayer,
                TileLayer
            ) {
                var tileInfo = epsg4326.tileInfo;
                var key = "天地图key"
                key = "6a92e00bdfafade25568c053a5ba6de4"
                var tiledLayer = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/img_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    tileInfo: tileInfo,
                    id: '影像',
                    listMode: 'hide' //这个属性设置是为了在layerlist不显示出来
                });
                var tiledLayer_poi = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/cia_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    tileInfo: tileInfo,
                    id: '影像标记',
                    listMode: 'hide'
                });
                var tiledLayer1 = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    tileInfo: tileInfo,
                    id: '矢量',
                    visible: false,
                    listMode: 'hide'
                });
                var tiledLayer_poi1 = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/cva_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    tileInfo: tileInfo,
                    id: '矢量标记',
                    visible: false,
                    listMode: 'hide'
                });
                

                var basemap = new Basemap({
                    baseLayers: [tiledLayer, tiledLayer_poi, tiledLayer1, tiledLayer_poi1],
                })
                var map = new Map({
                    basemap: basemap
                });


                var view = new MapView({
                    container: "viewDiv",
                    map: map,
                    spatialReference: {
                        wkid: 4326
                    },
                    scale: tileInfo.lods[7],
                    center: [114.3115879,30.5943680], //113.27434372047993,22.722786885699826
                    linked: false,
                    zoom:7,
                    constraints: {
                      lods: tileInfo.lods,
                      minScale: tileInfo.lods[0].scale,
                      maxScale: tileInfo.lods[19].scale
                    },
                });
                
                // view.extent = new Extent({
                //   xmin: 113.36595023855007,
                //   ymin: 23.671927965183833,
                //   xmax: 114.5628763484501,
                //   ymax: 22.7009907263257,
                //   spatialReference: {
                //     wkid: 4326
                //   }
                // });


            });
        </script>
    </head>

    <body class="calcite">
        <div id="viewDiv"></div>
    </body>
</html>

参考资料:

https://www.cnblogs.com/hjyjack9563-bk/p/16067633.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1385927.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

五、mysql8忘记root用户密码怎么办?怎么修改用户密码?

目录 1、忘记密码怎么修改密码 1&#xff09;、首先停止mysql的服务 2&#xff09;、新建一个文本文件&#xff0c;文本文件中就写一条修改密码的语句 3&#xff09;、使用管理员权限运行cmd命令行&#xff0c;运行以下命令&#xff1a; 4&#xff09;、然后按CTRLC结束上…

Jetbrains ai assistant激活后仍无法使用,怎么回事?

用正式的ai assistant激活码激活后仍然无法使用 首先获取了ai assistant激活码&#xff0c;激活后如下 地址&#xff1a;https://web.52shizhan.cn 上图是已经激活成功了&#xff0c;但是在右侧这里打开ai assistant不可用 点击开始使用ai assistant 出错 以上是用了ai as…

ssm基于web的学生考勤管理系统论文

基于Web的学生考勤管理系统的设计与实现 摘 要 当下&#xff0c;正处于信息化的时代&#xff0c;许多行业顺应时代的变化&#xff0c;结合使用计算机技术向数字化、信息化建设迈进。以前学校对于学生考勤信息的管理和控制&#xff0c;采用人工登记的方式保存相关数据&#xff…

[Kubernetes]10. k8s部署Goweb+mysql项目实战演练

一.安装docker构建镜像 如果要本地构建镜像的话,对应节点还需要安装docker,安装教程见:[Docker]一.Docker 简介与安装 linux环境,centos8下 docker及docker compose安装教程 k8s部署Goweb+mysql项目有两种方法:第一种是传统部署方法,第二种是通过ConfigMap实现应用配置分离部署…

数据库第一次作业

1.创建一个英雄表 create table t_hero ( id int primary key auto_increment, name varchar(10) unique not null, gender char(5) check (gender in (男,女)), grade char(5) default 5星, groups char(5) check (groups in (毁灭,巡猎,智识,存护,…

4.2V锂电线性1.2A充电芯片WT4056

4.2V锂电线性1.2A充电芯片WT4056 WT4056是一款专为单节锂离子电池设计的恒流/恒压线性充电器。其简洁的外部电路设计使其非常适用于便携设备的供电&#xff0c;同时兼容USB电源和适配器电源。该充电器内部采用了防倒充电路&#xff0c;无需额外添加外部隔离二极管。通过热反馈…

Zabbix监控(1)

目录 一.什么是zabbix Zabbix 组件&#xff1a; 主动模式&#xff1a; 被动模式&#xff1a; Zabbix 工作原理&#xff1a; zabbix 监控原理&#xff1a; 二.Zabbix 6.0 部署 先安装nginx&#xff0c;php&#xff08;yum源安装&#xff09;&#xff1a; 安装nginx&…

用bat脚本执行py文件以及批量执行py文件(全网超详细)

1.前言 对于python代码&#xff0c;每次执行一个文件就要运行一个命令&#xff0c;太过麻烦 在Windows电脑上&#xff0c;想一次性执行多个python文件的代码&#xff0c;就需要用到bat脚本 2.python代码 先写几个python代码的文件 如下图 3.py文件为中文&#xff0c;用bat执…

Javaweb之SpringBootWeb案例的详细解析

SpringBootWeb案例 前面我们已经讲解了Web前端开发的基础知识&#xff0c;也讲解了Web后端开发的基础(HTTP协议、请求响应)&#xff0c;并且也讲解了数据库MySQL&#xff0c;以及通过Mybatis框架如何来完成数据库的基本操作。 那接下来&#xff0c;我们就通过一个案例&#xf…

MATLAB实验Simulink的应用

本文MATLAB源码&#xff0c;下载后直接打开运行即可[点击跳转下载]-附实验报告https://download.csdn.net/download/Coin_Collecter/88740734 一、实验目的 1.熟悉Simulink操作环境。 2.掌握建立系统仿真模型以及系统仿真分析的方法。 二、实验内容 1.利用Simulink仿真下列曲…

【数据结构】哈希表详解,举例说明 java中的 HashMap

一、哈希表&#xff08;Hash Table&#xff09;简介&#xff1a; 哈希表是一种数据结构&#xff0c;用于实现字典或映射等抽象数据类型。它通过把关键字映射到表中的一个位置来实现快速的数据检索。哈希表的基本思想是利用哈希函数将关键字映射到数组的索引位置上&#xff0c;…

centos7 arm服务器编译安装openssl 1.1.1版本

前言 在centos7中&#xff0c;默认安装的openssl版本是1.0.2&#xff0c;太低了&#xff0c;在python项目开发中&#xff0c;由于需要用到requests包&#xff0c;这时候就会出现如下错误“ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1”&#xff1a; 解决办法就只能…

10万字200道软件测试经典面试总结(附答案)

&#x1f345; 视频学习&#xff1a;文末有免费的配套视频可观看 &#x1f345; 关注公众号【互联网杂货铺】&#xff0c;回复 1 &#xff0c;获取《110万字200道软件测试经典面试总结&#xff08;附答案&#xff09;》pdf&#xff0c;背题更方便&#xff0c;一文在手&#xff…

lvgl模拟器

学习目标 能够搭建lvgl模拟器开发环境 学习内容 项目源码准备 http://docs.lvgl.io/latest/en/html/get-started 下载模拟器项目 GitHub - lvgl/lv_port_pc_eclipse: PC simulator project for LVGL embedded GUI Library. Recommended on Linux and Mac. 下载lvgl源码 …

一键制作底片效果,让视频复古感倍增!

你是否厌倦了千篇一律的视频效果&#xff0c;想要尝试一些与众不同的视觉体验&#xff1f;是否想要让你的视频散发出一种复古、怀旧的气息&#xff1f;现在&#xff0c;有了我们的底片效果制作工具&#xff0c;这些愿望全部实现 首先第一步&#xff0c;我们要进入视频剪辑高手…

echarts柱状图顶部设置倾斜并且展示数字

将下面代码直接复制粘贴在此运行就能查看效果Apache ECharts&#xff0c;一款基于JavaScript的数据可视化图表库&#xff0c;提供直观&#xff0c;生动&#xff0c;可交互&#xff0c;可个性化定制的数据可视化图表。https://echarts.apache.org/examples/zh/editor.html?care…

脚本计算器1.5

python是热门语言,库多&#xff0c;界面设计麻烦。 aardio是国人开发的编程语言&#xff0c;可以快速开发界面。 aardio核心下载包只有几兆&#xff0c;免安装&#xff0c;写import py3执行可以自动安装python嵌入包 import py3; import web.form; var wb web.form(mainFor…

eBPF运行时安全

引言 eBPF作为当前linux系统上最为炙手可热的技术&#xff0c;通常被用于网络流量过滤和分析、系统调用跟踪、性能优化、安全监控&#xff0c;当下比较知名的项目有Cilium、Falco等。 Cilium 是一个开源的容器网络和安全性项目&#xff0c;致力于提供高效的容器通信和强大的安…

关于cdn资源失效的问题,一个月了都解决不了,七牛云技术这么差的吗?

起因 最近登录我的gpt镜像网站后&#xff0c;发现关于面具的图片资源都失效了 CoCo-AI 于是紧急使用 F12 排查原因 发现所有图片拿出来都已经无法访问了。看来是资源出了问题 在网上一番搜索后发现是 cdn.staticfile.org 失效导致的&#xff0c;而该静态资源属于七牛云&#…

关于晶振回流焊工艺,你知道哪些呢!

晶振&#xff0c;作为现代电子设备中的核心元件&#xff0c;其制造过程需要经过多道精密的工艺流程。其中&#xff0c;回流焊工艺是晶振制造过程中一个至关重要的环节。本文将详细介绍回流焊工艺在晶振制造中的应用&#xff0c;以及关键的注意事项。 一、回流焊工艺简介 回流…