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

本文主要是介绍arcgis javascript api4.x以basetilelayer方式加载天地图web墨卡托(wkid:3857)坐标系,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

需求:

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 layerproperties: {urlTemplate: null,},// override getTileUrl()// generate the tile url for a given level, row and columngetTileUrl: 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 LayerViewvar url = this.getTileUrl(level, row, col);// request for tiles based on the generated url// the signal option ensures that obsolete requests are abortedreturn esriRequest(url, {responseType: "image",//signal: options && options.signalallowImageDataAccess: true }).then(function (response) {// when esri request resolves successfully// get the image from the responsevar image = response.data;var width = this.tileInfo.size[0];var height = this.tileInfo.size[0];// create a canvas with 2D rendering contextvar 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 canvasif (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.722786885699826linked: false,zoom:7,});});</script></head><body class="calcite"><div id="viewDiv"></div></body>
</html>

参考资料:

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

这篇关于arcgis javascript api4.x以basetilelayer方式加载天地图web墨卡托(wkid:3857)坐标系的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/609073

相关文章

Spring Cloud Hystrix原理与注意事项小结

《SpringCloudHystrix原理与注意事项小结》本文介绍了Hystrix的基本概念、工作原理以及其在实际开发中的应用方式,通过对Hystrix的深入学习,开发者可以在分布式系统中实现精细... 目录一、Spring Cloud Hystrix概述和设计目标(一)Spring Cloud Hystr

Spring Boot整合消息队列RabbitMQ的实现示例

《SpringBoot整合消息队列RabbitMQ的实现示例》本文主要介绍了SpringBoot整合消息队列RabbitMQ的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的... 目录RabbitMQ 简介与安装1. RabbitMQ 简介2. RabbitMQ 安装Spring

nginx upstream六种方式分配小结

《nginxupstream六种方式分配小结》本文主要介绍了nginxupstream六种方式分配小结,包括轮询、加权轮询、IP哈希、公平轮询、URL哈希和备份服务器,具有一定的参考价格,感兴趣的可... 目录1 轮询(默认)2 weight3 ip_hash4 fair(第三方)5 url_hash(第三

springMVC返回Http响应的实现

《springMVC返回Http响应的实现》本文主要介绍了在SpringBoot中使用@Controller、@ResponseBody和@RestController注解进行HTTP响应返回的方法,... 目录一、返回页面二、@Controller和@ResponseBody与RestController

JAVA集成本地部署的DeepSeek的图文教程

《JAVA集成本地部署的DeepSeek的图文教程》本文主要介绍了JAVA集成本地部署的DeepSeek的图文教程,包含配置环境变量及下载DeepSeek-R1模型并启动,具有一定的参考价值,感兴趣的... 目录一、下载部署DeepSeek1.下载ollama2.下载DeepSeek-R1模型并启动 二、J

springboot rocketmq配置生产者和消息者的步骤

《springbootrocketmq配置生产者和消息者的步骤》本文介绍了如何在SpringBoot中集成RocketMQ,包括添加依赖、配置application.yml、创建生产者和消费者,并展... 目录1. 添加依赖2. 配置application.yml3. 创建生产者4. 创建消费者5. 使用在

Spring Retry 实现乐观锁重试实践记录

《SpringRetry实现乐观锁重试实践记录》本文介绍了在秒杀商品SKU表中使用乐观锁和MybatisPlus配置乐观锁的方法,并分析了测试环境和生产环境的隔离级别对乐观锁的影响,通过简单验证,... 目录一、场景分析 二、简单验证 2.1、可重复读 2.2、读已提交 三、最佳实践 3.1、配置重试模板

Spring中@Lazy注解的使用技巧与实例解析

《Spring中@Lazy注解的使用技巧与实例解析》@Lazy注解在Spring框架中用于延迟Bean的初始化,优化应用启动性能,它不仅适用于@Bean和@Component,还可以用于注入点,通过将... 目录一、@Lazy注解的作用(一)延迟Bean的初始化(二)与@Autowired结合使用二、实例解

SpringBoot使用Jasypt对YML文件配置内容加密的方法(数据库密码加密)

《SpringBoot使用Jasypt对YML文件配置内容加密的方法(数据库密码加密)》本文介绍了如何在SpringBoot项目中使用Jasypt对application.yml文件中的敏感信息(如数... 目录SpringBoot使用Jasypt对YML文件配置内容进行加密(例:数据库密码加密)前言一、J

Java中有什么工具可以进行代码反编译详解

《Java中有什么工具可以进行代码反编译详解》:本文主要介绍Java中有什么工具可以进行代码反编译的相关资,料,包括JD-GUI、CFR、Procyon、Fernflower、Javap、Byte... 目录1.JD-GUI2.CFR3.Procyon Decompiler4.Fernflower5.Jav