arcgis javascript api4.x以basetilelayer方式加载天地图web墨卡托(wkid:3857)坐标系

news2024/10/6 8:22:34

需求:

arcgis javascript api4.x以basetilelayer方式加载天地图web墨卡托(wkid:3857)坐标系

效果图:

代码:

提示:

2个文件放同一个文件夹下

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;
  })
  
 

loadtdt3857.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','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,
                TileInfo,
                MyCustomTileLayer,
                TileLayer
            ) {
                var key = "天地图key"
                key = "6a92e00bdfafade25568c053a5ba6de4"
                // http://t0.tianditu.com/img_w/esri/wmts  可代替  http://t0.tianditu.gov.cn/img_w/wmts  效果一致
         var tiledLayer = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    id: '影像',
                    listMode: 'hide' //这个属性设置是为了在layerlist不显示出来
                });
                var tiledLayer_poi = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/cia_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    id: '影像标记',
                    listMode: 'hide'
                });
                var tiledLayer1 = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    id: '矢量',
                    visible: false,
                    listMode: 'hide'
                });
                var tiledLayer_poi1 = new MyCustomTileLayer({
                    urlTemplate: "http://t0.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TileMatrix={level}&TileCol={col}&TileRow={row}&tk=" +
                        key,
                    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: 3857  //102100
                    },
                    center: [114.3115879,30.5943680], //113.27434372047993,22.722786885699826
                    linked: false,
                    zoom:7,
                });
                


            });
        </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/1385676.html

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

相关文章

手把手教你学会接口自动化系列十一-将用例写在json中,持久化管理起来下

上一篇我写了登录&#xff0c;我们发现json还是没有什么大问题&#xff0c;还蛮好用的&#xff0c;但是我们再写下一个&#xff0c;比如线索新建接口的时候&#xff0c;我们写着写着会发现问题&#xff1a; 我们写获取url的没有问题&#xff0c;代码如下&#xff1a; # !/usr…

uniapp中uview组件库丰富的ActionSheet 操作菜单使用方法

目录 #平台差异说明 #基本使用 #配置顶部的提示信息和底部取消按钮 #如何知道点了第几项 #API #Props #Event 本组件用于从底部弹出一个操作菜单&#xff0c;供用户选择并返回结果。 本组件功能类似于uni的uni.showActionSheetAPI&#xff0c;配置更加灵活&#xff0c;所…

vue:使用【3.0】:拖拽数据

1、参考链接&#xff1a;vue.draggable中文文档 - itxst.com 2、想要实现的效果图&#xff1a;红框内容可以拖拽 3、安装 yarn add vuedraggablenext npm i -S vuedraggablenext 4、代码 <template><draggable:list"columns"ghost-class"ghost&qu…

手把收来教大家win10电脑分辨率怎么调

win10系统操作界面和方式和win7系统有很大不同&#xff0c;有些用户想要设置屏幕的分辨率&#xff0c;但是却不知道应该怎么操作&#xff1f;屏幕分辨率会影响我们使用电脑的视觉效果&#xff0c;经常使用电脑的朋友通常都会设置一个合适的分辨率。下面小编来教大家win10电脑分…

webpack的性能优化(一)——分包优化

1.什么是分包&#xff1f;为什么要分包&#xff1f; 默认情况下&#xff0c;Webpack 会将所有代码构建成一个单独的包&#xff0c;这在小型项目通常不会有明显的性能问题&#xff0c;但伴随着项目的推进&#xff0c;包体积逐步增长可能会导致应用的响应耗时越来越长。归根结底这…

什么是google算法?

谷歌算法本身指的是谷歌针对搜索引擎做的规定 要想在别人的地盘玩&#xff0c;那肯定要了解这个地盘的规定&#xff0c;不然做了什么违反了规定&#xff0c;谷歌肯定不会让你继续玩下去 要想做谷歌&#xff0c;那肯定要了解谷歌的算法&#xff0c;然而谷歌的算法也不是一成不变…

代码随想录 Leetcode202. 快乐数

题目&#xff1a; 代码(首刷自解 2024年1月15日&#xff09;&#xff1a; class Solution { public:bool isHappy(int n) {unordered_set<int> hash;while(n ! 1) {int sum 0;while(n/10 ! 0) {sum (n % 10)*(n % 10);n/10;}sum n*n;if (hash.find(sum) ! hash.end()…

SQL备忘--集合运算

前言 本文讨论的是两个子查询结果的合并问题&#xff0c; 是行维度下的合并处理 例如子查询A查出5条记录、子查询B查出3条记录&#xff0c;那么将两个结果合并&#xff0c;则共返回8条记录 行维度上要能进行合并&#xff0c;前置要求是&#xff1a;子查询的列字段是相同的&…

关于你不知道的前端文件上传方式

1、原生方法 我们开发中比较常用的有使用 input 属性的 type 设置为 file,这里我们就不进行过多的阐述&#xff0c;已经老生常谈了。 今天我们主要介绍两个新的属性 showDirectoryPicker 和 showOpenFilePicker 这里是官方文档 1、showDirectoryPicker showDirectoryPicker方…

20240115-【UNITY 学习】第一人称移动增加斜坡移动、冲刺和蹲伏功能

直接修改或者替换PlayerMovement_01.cs using System.Collections; using System.Collections.Generic; using UnityEngine;public class PlayerMovement_02 : MonoBehaviour {private float moveSpeed; // 玩家移动速度public float walkSpeed 7; // 行走速度public float sp…

内网搭建文件服务器

文件下载地址 Releases rejetto/hfs GitHubHFS is a web file server to run on your computer. Share folders or even a single file thanks to the virtual file system. - Releases rejetto/hfshttps://github.com/rejetto/hfs/releases http://192.168.100.33/apk/ 就…

.net core IResultFilter 的 OnResultExecuted和OnResultExecuting的区别

//全局过滤器 builder.Services.AddMvc(m > { m.Filters.Add<AllResultFilter>(); }); 1、实现过滤器 public class AllResultFilter : IResultFilter {/// <summary>/// 结果执行后方法/// 不可更改结果/// </summary>/// <param name"con…

spring常见漏洞(2)

Spring Web Flow框架远程代码执行(CVE-2017-4971)漏洞&#xff0c;是由于Spring Web Flow的数据绑定问题带来的表达式注入&#xff0c;从而导致任意代码执行。 影响版本 2.4.0-2.4.4、Older unsupported versions are also affected 漏洞分析 view对象处理用户事件&#xf…

【外汇天眼】误入假冒Ctrl Investments无法出金,投资者:太相信网友了!

在当下这个互联网迅速发展的时代&#xff0c;各类交友类APP成为人们拓展社交圈的新渠道。一方面这样的交友软件在满足了用户基础的社交要求&#xff0c;另一方面网络世界所交往的朋友能给用户带来的神秘感和新鲜感&#xff0c;所以导致一部分年轻人离不开这些交友软件。然而&am…

STM32快速复制MX25L1606E系列Flash

去年做了一个使用RS485对PIC18F45K80系列单片机进行在线升级的程序&#xff0c;如果是小批量的出厂烧录程序和升级验证&#xff08;出厂前肯定要测试单片机是否能正常读写Flash&#xff09;是可以的&#xff0c;但是后来产品订单量很大&#xff0c;生产线的烧录及升级验证就很缓…

QT上位机开发(多线程处理)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 目前大部分cpu都是多核cpu&#xff0c;所以如果不用多线程进行数据处理的话&#xff0c;实在是太浪费资源了。另外&#xff0c;很多的操作都是阻塞…

数据中心温湿度监测,这个细节你真的看懂了吗?

在当今数字化和智能化的时代&#xff0c;温湿度监控系统成为了各行业中不可或缺的关键技术&#xff0c;其在维护设备、保障产品质量和确保生产环境稳定性方面发挥着至关重要的作用。 随着科技的不断进步&#xff0c;企业和机构越来越意识到对环境参数的实时监测对于提高效率、降…

采样次数与频率的关系

采样次数&#xff08;Sampling Points&#xff09; 在给定时间内记录信号值的次数。 假设在1秒内对一个连续信号采样10次&#xff0c;这意味着每0.1秒记录一次信号值。 假设在1秒内对一个连续信号采样100次&#xff0c;这意味着每0.01秒记录一次信号值。 频率&#xff08;Fre…

GitLab CI 实现项目A更新代码自动触发项目B更新错误码文档

一、CI/CD简介 CI/CD 是持续集成&#xff08;Continuous Integration&#xff09;和持续交付/持续部署&#xff08;Continuous Delivery/Continuous Deployment&#xff09;的缩写&#xff0c;是一种软件开发和交付的最佳实践。这两个概念通常一起使用&#xff0c;但有些时候它…

XCTF:Hidden-Message[WriteUP]

使用Wireshark打开文件 分析能分析的流&#xff0c;这里直接选择UDP流 分别有两段流&#xff0c;内容都是关于物理的 和flag没啥关系&#xff0c;只能从别的方面下手 分析&#xff1a;整个数据包&#xff0c;全部由UDP协议组成 其中发送IP和接收IP固定不变&#xff0c;数据长…