图1html
图2node
图3程序员
-------------------------------------华丽丽的分割线-----------------------------------浏览器
图4网络
图5框架
……图片欣赏到这吧,我想各位已经知道要表达什么了。先来解释一下图片,图一、2和3是十二、13和14三年的生产总值在ArcMap的不一样表达,是否是以为表达很简单、很直观也很粗暴!图4和图5展现的是全国农林牧渔业发生洪涝灾害后的统计状况,这个但是在浏览器上展现的噢,只是展现的,然而。。。。。。然而在这个网络流行的社会,咱们不会为了看到这样一副美丽直观的地图来携带这个ArcMap或者对每一种表达都发一个如图4和图5这样效果的服务。并且,还不能和地图交互,同时,伟大的ArcGIS API for JavaScript也没有提供相关接口,是否是感受到天已经黑了。dom
他们的心里是崩溃的……ide
伟大的GISer来了———想要和地图交互效果的众生们,大家的黎明就要来了!测试
话说回来,实现图表上图,我的理解有两种方式。优化
某天在AGS群里忽然发现有个大神(望留名)已经实现的在地图上面展现图表的,并且本身写了图标的样式。部分代码以下:
constructor: function (parameters) { lang.mixin(this, parameters); isContentShowing = false; domClass.add(this.domNode, "myInfoWindow"); this._content = domConstruct.create("div", { "class": "content" }, this.domNode); this._eventConnections = []; domUtils.hide(this.domNode); this.isShowing = false; }, setMap: function (map) { this.inherited(arguments); this._eventConnections.push(map.on("pan", lang.hitch(this, this.__onMapPan))); this._eventConnections.push(map.on("extent-change", lang.hitch(this, this.__onMapExtChg))); this._eventConnections.push(map.on("zoom-start", lang.hitch(this, this.__onMapZmStart))); this._eventConnections.push(map.on("zoom", lang.hitch(this, this.onMapZm))); },
其代码调用部分:
var infoWindow = new ChartInfoWindow({ domNode: domConstruct.create('div', null, document.getElementById('map')) }); infoWindow.setMap(map); var nodeChart = null; nodeChart = domConstruct.create("div", { id: 'nodeTest' + i, style: "width:120px;height:50px" }, win.body()); var chart = makeChart(nodeChart,showFields,max,i); //optinalChart = chart; infoWindow.resize(122, 52); //计算几何的中心位置,将图表信息框放置于此 var labelPt = new Point(Data[i][1],Data[i][2],map.SpatialReference); infoWindow.setContent(nodeChart); infoWindow.__mcoords = labelPt; infoWindow.show(map.toScreen(labelPt));
按照程序员的作法,确定是啃源码!一看,其大体思路是infowindowbase,一看调用,确实有点费劲,内心痒痒、因此走起了个人代码优化之路,通过混天地暗的奋斗,终于搞定。
constructor: function (parameters) {//map, chartPoint, chart, width, height lang.mixin(this, parameters); isContentShowing = false; this.domNode= domConstruct.create('div',null, document.getElementById('map_root').parentNode); domClass.add(this.domNode, "myInfoWindow"); domUtils.hide(this.domNode); this._content = domConstruct.create("div", { "class": "content"}, this.domNode); this.setContent(this.chart); this.__mcoords= this.chartPoint; this._eventConnections = []; this.isShowing = false; this.setMap(this.map); this.show(this.map.toScreen(this.chartPoint)); this.resize(this.width, this.height); },
调用部分:
var chartInfo= new ChartInfoWindow({ map: map, chart:nodeChart, chartPoint: chartPoint, width: 123, height: 123 });一点运行心情如同下面这图画。
哈哈,不说废话了,直接看结果。
写在最后:
代码实现了从地图要素中读取属性数据,而后用dojo的图表展现出来。固然也可使用Echarts、amCharts、D3或者highCharts等等的。祝好运。
测试示例依然存在一些Bug和美观问题,如背景非透明(这是图表框架限制的……)、图表压盖等。还请期待。