前言

关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 4.x for js:esri 官网 api,里面详细的介绍 arcgis api 4.x 各个类的介绍,还有就是在线例子:esri 官网在线例子,这个也是学习 arcgis api 4.x 的好素材。

参考资料
https://blog.csdn.net/weixin_39676449/article/details/82155812
https://blog.csdn.net/yy284872497/article/details/85228643
https://github.com/xcsf/ArcGIS-API-for-JS-with-Echarts

arcgis api 4.x for js 集成 echarts 实现迁徙图效果的关键问题在于 echarts 坐标系以及 arcgis 坐标系不一致,因此要进行 echarts坐标系与 arcgis 坐标系的转换,这里采用的方法是注册一个坐标系统命名为 arcgis(名称可自由拟定)的坐标系。在此基础上,采用 dojo 的 define 定义了一个名为 EchartsLayer 的模块。

define(["dojo/_base/declare", "dojo/_base/lang", "esri/geometry/Point", "esri/geometry/SpatialReference"],
function (declare, lang, n, SpatialReference) {
return declare("EchartsLayer", null, {
name:"EchartsLayer",
view: null,
box: null,
chart: null,
chartOption: null,
visible:true,
constructor: function (view, option) { echarts.registerCoordinateSystem('arcgis', this.getE3CoordinateSystem(view));
this.init(view,option);
},
init:function(view, option) {
this.setBaseMap(view);
this.createLayer();
//this.setChartOption(option); },
……

最终实现效果图:

2D 视图效果

3D 视图效果

创建 EchartsLayer 模块的构造函数,需要注册 arcgis 坐标系函数

//需要先引用echarts.js
echarts.registerCoordinateSystem('arcgis', this.defineCoordinateSystem(view));

在 defineCoordinateSystem() 函数中,对 echarts 里面的几个函数进行了重写,其中主要包含 dataToPoint、pointToData 等坐标转换内容。

  • dataToPoint 函数重写
CoordSystem.prototype.dataToPoint = function dataToPoint(data) {
var point = {
type:"point",
x:data[0],
y:data[1],
spatialReference:new SpatialReference(4326)
};
var px = map.toScreen(point);
var mapOffset = this._mapOffset;
return [px.x - mapOffset[0], px.y - mapOffset[1]];
}

更多的详情见GIS之家小专栏

文章尾部提供源代码下载,对本专栏感兴趣的话,可以关注一波

最新文章

  1. Java资源大全中文版(Awesome最新版)
  2. JSP生成Excel报表
  3. js的并行加载以及顺序执行
  4. 关于已配置log4j,运行tomcat时显示警告的分析
  5. tomcat8编码
  6. 查看造成等待事件的具体SQL语句
  7. ReplaceGoogleCDN:将 Google CDN 更换国家
  8. linux系统tomcat项目部署和tomcat访问日志
  9. redis秒杀
  10. harbor镜像仓库-02-https访问配置
  11. HGOI 20190218 题解
  12. 20155228 2017-5-10 课堂测试:Arrays和String单元测试
  13. idea中deBug方法
  14. Pandas的使用(2)
  15. PTA (Advanced Level) 1009 Product of Polynomials
  16. hdu 1856 求集合里元素的个数 输出最大的个数是多少
  17. Android之用自定义的shape去实现shadow效果
  18. 超级好用的C++万能头文件
  19. C#自定义处理事件(作者还没完全理解事件和委托,所以有可能错漏百出)
  20. Javascript 5种设计风格

热门文章

  1. 可编程实验板EPM1270T144C5使用说明
  2. C#封装继承
  3. TensorFlow实现简单线性回归示例代码
  4. 天下代码一大抄,整个案例的搬是什么鬼!疑似冒充蚂蚁金服高级Java开发工程师?你大爷
  5. C lang:Array_Multidimensional arrays
  6. MySQL数据库~~~~ 完整性约束
  7. Tornado—三种启动tornado的方式
  8. Ubuntu下配置IP地址
  9. 由随机数rand5实现随机数rand7
  10. Python导入运行的当前模块报错