首页 > 其他分享 >通过arcgis of Js 4.x 加载 高德地图

通过arcgis of Js 4.x 加载 高德地图

时间:2024-07-04 15:58:18浏览次数:1  
标签:canvas level Js arcgis var new row 高德 esri

关于如何加载高德地图,目前在网上找到的切片图片加载的高德地图
主要是参考官方demo上的
Custom TileLayer
然后修改进行使用的

具体代码如下:

<!DOCTYPE html>
<html>
 
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Custom TileLayer - 4.6</title>
 
  <link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
 
  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>
 
  <script src="https://js.arcgis.com/4.6/"></script>
 
  <script>
    require([
      "esri/Map",
	  "esri/views/MapView",
      "esri/config",
      "esri/request",
      "esri/Color",
      "esri/views/SceneView",
      "esri/widgets/LayerList",
      "esri/layers/BaseTileLayer", 
      "dojo/domReady!"
    ], function(
      Map,MapView, esriConfig, esriRequest, Color,
      SceneView, LayerList, BaseTileLayer
    ) {
 
      // *******************************************************
      // Custom tile layer class code
      // Create a subclass of BaseTileLayer
      // *******************************************************
 
      var TintLayer = BaseTileLayer.createSubclass({
        properties: {
          urlTemplate: null,
          tint: {
            value: null,
            type: Color
          }
        },
 
        // generate the tile url for a given level, row and column
        getTileUrl: function(level, row, col) {
          return this.urlTemplate.replace("{z}", level).replace("{x}",
            col).replace("{y}", 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) { 
		  //构建切片URL
          var url = this.getTileUrl(level, row, col); 
          // request for tiles based on the generated url
          // set allowImageDataAccess to true to allow
          // cross-domain access to create WebGL textures for 3D.
          return esriRequest(url, {
              responseType: "image",
              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; 
              // Draw the blended image onto the canvas.
              context.drawImage(image, 0, 0, width, height); 
              return canvas;
            }.bind(this));
        }
      });
 
      // *******************************************************
      // Start of JavaScript application
      // *******************************************************
 
      // Add stamen url to the list of servers known to support CORS specification.
      esriConfig.request.corsEnabledServers.push("webst01.is.autonavi.com"); 
      // Create a new instance of the TintLayer and set its properties
      var stamenTileLayer = new TintLayer({
        urlTemplate: "http://wprd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scl=1&style=7&x={x}&y={y}&z={z}",
        tint: new Color("#004FBB"),
        title: "高德"
      });   
	  
  
      // add the new instance of the custom tile layer the map
      var map = new Map({
        layers: [stamenTileLayer]
      });
 
      // create a new scene view and add the map
      var view = new MapView({
      	container: "viewDiv",
      	map: map,
      	zoom: 6,
      	center: [123.9634086609, 35.9595912264],
      });
	    
		
      // create a layer list widget
      // var layerList = new LayerList({
      //   view: view,
      // });
      // view.ui.add(layerList, "top-right");
    });
  </script>
</head>
 
<body>
  <div id="viewDiv"></div>
</body>
 
</html>

标签:canvas,level,Js,arcgis,var,new,row,高德,esri
From: https://www.cnblogs.com/ZerlinM/p/18284020

相关文章

  • Vue.js 起步
     每个Vue应用都需要通过实例化Vue来实现。语法格式如下:varvm=newVue({//选项})接下来让我们通过实例来看下Vue构造器中需要哪些内容:实例<divid="vue_det"><h1>site:{{site}}</h1><h1>url:{{url}}</h1><h1>{{details()}}</h1>&l......
  • 程序员必备的JSON可视化工具
    JSON文本难于阅读,格式化也不够直观,而且当数据量大的时候还会造成卡顿,今天推荐一个JSON可视化工具,让你一眼看穿JSON——jsoncrack图片无论您是从事大型项目的开发人员,还是希望发现隐藏见解的数据爱好者,JSONCrack都拥有释放数据全部潜力所需的工具和功能。jsoncrackJSONCrack......
  • 基于Java+Jsp Struts Mysql实现的图书馆管理系统设计与实现
    一、前言介绍:1.1项目摘要随着信息技术的飞速发展,传统图书馆的管理方式已经难以满足现代读者的需求。传统的图书馆管理方式通常依赖于人工操作,如图书的借阅、归还、分类、编目等,这些过程不仅效率低下,而且容易出错。同时,随着图书馆藏书量的不断增加,如何有效地管理这些图书......
  • 基于Java+Jsp+Springmvc+Mybatis3+Mysql实现的SSM个人博客系统设计与实现
    一、前言介绍:1.1项目摘要随着互联网技术的快速发展和普及,个人博客作为一种表达自我、分享知识和经验的方式,受到了越来越多人的青睐。传统的博客平台虽然提供了丰富的功能和便捷的服务,但往往难以满足个性化、定制化的需求。因此,开发一款基于SSM(Spring+SpringMVC+MyBat......
  • selenium11_js语法
    1.JS语法js中元素定位方法,如下5种方法:a.通过id获取,获取的是单个document.getElementById("id")b.通过name获取,获取的是多个document.getElementsByName("name")[0]c.通过标签名选取元素,获取的是多个document.getElementsByTagName("tag")d.通过CLASS类选取元素,获取的是多个......
  • 【社招+校招】华为OD机试 - 运维日志排序(Java & JS & Python & C)
    鱼弦:公众号【红尘灯塔】,CSDN博客专家、内容合伙人、新星导师、全栈领域优质创作者、51CTO(Top红人+专家博主)、github开源爱好者(go-zero源码二次开发、游戏后端架构https://github.com/Peakchen)运维日志排序算法实现(Java、JavaScript、Python、C、C++)算法概述运维日志......
  • 【校招+社招】华为OD机试 - 统计射击比赛成绩(Java & JS & Python)
    鱼弦:公众号【红尘灯塔】,CSDN博客专家、内容合伙人、新星导师、全栈领域优质创作者、51CTO(Top红人+专家博主)、github开源爱好者(go-zero源码二次开发、游戏后端架构https://github.com/Peakchen)统计射击比赛成绩(Java、JavaScript、Python和C++)算法实现问题描述:在一......
  • Three.js
    右手坐标系//每秒转一圈constclock=newTHREE.Clock()functiontick(){consttime=clock.getElapsedTime()mesh.rotation.y=time*Math.PI*2//一秒转一圈renderer.render(scene,camera)window.requestAnimationFrame(tick)}tick()const......
  • nodejs删除和重新安装
    若重新安装nodejs本人使用卸载并重新安装的方法,简单暴力卸载1.找到以前安装nodejs的文件路径,直接删除2.例如我的在D盘路径,直接卸载3.然后删除配置环境:右键此电脑——属性——高级系统设置——高级——环境变量4.找到用户变量在path关于node与npm并删除5.系统变......
  • js 深度对象筛选器
    要实现JavaScript深度对象筛选器,可以使用filter()方法结合自定义的过滤函数来处理对象数组。以下是一个示例,假设有一个包含用户信息的对象数组,需要筛选出满足特定条件的用户:constusers=[{id:1,name:'Alice',age:25,hobbies:['reading','usic']},{i......