(转)Arcgis for Js之Graphiclayer扩展详解
http://blog.csdn.net/gisshixisheng/article/details/41208185
在前两节,讲到了两种不同方式的聚类,一种是基于距离的,一种是基于区域范围的,两种不同的聚类都是通过扩展esri/layers/GraphicsLayer方法来实现的。在本节,就详细的讲讲esri/layers/GraphicsLayer方法的扩展。
首先,在讲解扩展之前,先看看API中esri/layers/GraphicsLayer的一些参数和方法等。
1、创建一个GraphicLayer
在ESRI官方的API中,创建GraphicLayer有两种方式:
例如:
或者:
在第二种方式的options的参数包括:
2、GraphicLayer的属性
GraphicLayer的属性包括:
其中,有几个比较常见和重要的属性为:
a、graphics:数组,返回的参数是一个数组,为GraphicLayer中包含的Graphic对象。
b、visiable:布尔型,Graphiclayer是否可见。
c、visiableAtMapScale:布尔型,在特定比例尺下的可见性。
3、Graphiclayer的方法
图中,红框标出的是Graphiclayer最常用的方法,详细的介绍很清楚,在此不再做赘述了。
接下来,扩展Graphiclayer。
GraphicLayer藏得很深,位于library\3.9\3.9\js\esri\layers\GraphicsLayer.js,虽然对参数变量代码做了混淆,但是有些东西还是没做变化。在做GraphicLayer扩展时,有几个是比较常用的:
a、_setMap
- // 重构esri/layers/GraphicsLayer方法
- _setMap: function(map, surface) {
- // GraphicsLayer will add its own listener here
- var div = this.inherited(arguments);
- return div;
- }
b、_unsetMap
- _unsetMap: function() {
- this.inherited(arguments);
- }
c、_draw
- _draw:function(graphic, redrawFlag, zoomFlag){
- if (!this._map) {
- return;
- }
- }
此外,还有一些地图控制的,如:_onPanStartHandler,_onZoomStartHandler,_onExtentChangeHandler等。扩展GraphicLayer的大概框架代码如下:
- define([
- "dojo/_base/declare",
- "esri/layers/GraphicsLayer"
- ], function (
- declare,
- GraphicsLayer
- ) {
- return declare([GraphicsLayer], {
- constructor: function(options) {
- //参数设置
- this._id = options.id || "";
- this._divId = options.chartDiv || "chart";
- },
- // 重构esri/layers/GraphicsLayer方法
- _setMap: function(map, surface) {
- // GraphicsLayer will add its own listener here
- var div = this.inherited(arguments);
- return div;
- },
- _unsetMap: function() {
- this.inherited(arguments);
- },
- //拖拽
- _onPanStartHandler: function() {
- //
- },
- //缩放
- _onZoomStartHandler:function(){
- //
- },
- _onExtentChangeHandler: function(delta, extent, levelChange, lod) {
- //
- },
- _draw:function(graphic){
- if (!this._map) {
- return;
- }
- //
- }
- });
- });
例子:添加统计图
统计图通过dojo chart实现,代码如下:
- define([
- "dojo/_base/declare",
- "esri/layers/GraphicsLayer",
- "esri/geometry/Point",
- "esri/graphic",
- "dojox/charting/Chart2D",
- "dojox/charting/themes/PlotKit/blue",
- "dojox/charting/action2d/Highlight",
- "dojox/charting/action2d/Tooltip"
- ], function (
- declare,
- GraphicsLayer,
- Point,
- Graphic,
- Chart2D,
- theme,
- Highlight,
- Tooltip
- ) {
- return declare([GraphicsLayer], {
- constructor: function(options) {
- this._id = options.id || "";
- this._divId = options.chartDiv || "chart";
- this._charttype = options.chartType || "Pie";
- this._chartSize = options.size || 50;
- },
- // 重构esri/layers/GraphicsLayer方法
- _setMap: function(map, surface) {
- // GraphicsLayer will add its own listener here
- var div = this.inherited(arguments);
- return div;
- },
- _unsetMap: function() {
- this.inherited(arguments);
- },
- hide: function() {
- dojo.style(dojo.byId(this._divId),{
- "display": "none"
- });
- },
- show: function() {
- dojo.style(dojo.byId(this._divId),{
- "display": ""
- });
- },
- //拖拽
- _onPanStartHandler: function() {
- this.hide();
- },
- //缩放
- _onZoomStartHandler:function(){
- this.hide();
- },
- _onExtentChangeHandler: function() {
- this._refresh(true);
- },
- _refresh: function(redraw) {
- var that=this;
- var gs = this.graphics,
- _draw = this._draw;
- for (i = 0; i < gs.length; i++) {
- _draw(gs[i], redraw);
- }
- this.show();
- },
- _draw:function(graphic, redraw){
- if (!this._map) {
- return;
- }
- if(graphic instanceof Graphic)//判断graphic是否为MapChartGraphic类型
- {
- this._drawChart(graphic,redraw);
- }
- },
- _drawChart:function(graphic,redraw){
- var showMapPt = graphic.geometry,
- attribute = graphic.attributes;
- var showPt = map.toScreen(showMapPt);
- var id=attribute.code,
- series = [attribute.male, attribute.female];
- if(redraw){
- dojo.byId(this._divId).removeChild(dojo.byId("div"+id));
- }
- if(attribute){
- var _chartDiv = dojo.doc.createElement("div");
- _chartDiv.id ="div"+id;
- dojo.style(_chartDiv, {
- "left": (showPt.x-this._chartSize/4) + "px",
- "top": (showPt.y-this._chartSize/2) + "px",
- "position": "absolute",
- "width": this._chartSize + "px",
- "height": this._chartSize + "px"
- });
- dojo.byId(this._divId).appendChild(_chartDiv);
- var _chart = new Chart2D(_chartDiv);
- var _themes = dojox.charting.themes.PlotKit.blue;
- _themes.chart.fill = "transparent";
- _themes.chart.stroke = "transparent";
- _themes.plotarea.fill = "transparent";
- _chart.setTheme(_themes);
- switch(this._charttype){
- case "Pie":{//饼状图
- _chart.addPlot("default", {
- type: this._charttype,
- labels:false
- });
- break;
- }
- case "StackedColumns":{//柱状堆积图
- _chart.addPlot("default", {
- type: this._charttype,
- labels:false,
- markers: true,
- gap: 2
- });
- break;
- }
- case "Lines":{//柱状堆积图
- _chart.addPlot("default", {
- type: this._charttype,
- labels:false,
- markers: true,
- radius: 1,
- tension:"X"
- });
- break;
- }
- default:{//柱状图
- _chart.addPlot("default", {
- type: this._charttype,
- labels:false,
- gap: 3
- });
- chart.addAxis("y", { vertical:true, fixLower: "major", fixUpper: "major" });
- break;
- }
- }
- _chart.addSeries(id, series,{stroke: {width:1}});
- //效果
- new Highlight(_chart, "default", {highlight: "lightskyblue"});
- new Tooltip(_chart, "default");
- _chart.render();
- }
- }
- });
- });
实现后的效果如下:
源码下载地址:
链接:http://pan.baidu.com/s/1i3EbnF3 密码:cvbf
(转)Arcgis for Js之Graphiclayer扩展详解相关推荐
- nodejs 本地php服务器,node.js创建本地服务器详解
本文主要和大家分享node.js创建本地服务器详解,简易上手node.js后,我们就可以在自己电脑上创建本地服务器了.希望能帮助到大家. 一.先上代码.//请求Node.js自带的http模块. va ...
- js打印三角形超详解
js打印三角形超详解 j控制星星的总行数,i控制每行星星的打印个数 打印图形如下: (1) (2) //str=""用来存储星星// 理解步骤1:在一行输出6个星星如何操作,在循环 ...
- Three.js - 摄像机的使用详解(透视投影摄像机、正交投影摄像机)
一.两种摄像机的区别与比较 Three.js 库提供了两种不同的摄像机:透视投影摄像机和正交投影摄像机. 透视投影摄像机:这种摄像机的效果更贴近真实世界.也就是物体离摄像机越远,它们就会被渲染得越小. ...
- computed用发_Vue.js中computed使用详解
这次给大家带来Vue.js中computed使用详解,Vue.js中computed使用的注意事项有哪些,下面就是实战案例,一起来看一下. JS属性: JavaScript有一个特性是Object.d ...
- JS事件的三个阶段详解
JS事件的三个阶段详解 一.JS事件的三个阶段 二.冒泡阶段触发事件 三.捕获阶段触发事件 四.阻止冒泡行为 五.阻止事件冒泡和默认行为 一.JS事件的三个阶段 事件处理机制的三个阶段:1.捕获 2. ...
- PHP中cal_days_in_month函数和calendar扩展详解
PHP中cal_days_in_month函数和calendar扩展详解 问题: 在开发中无意间发现cal_days_in_month函数不可使用.然后就开始研究学习. 1.cal_days_in_m ...
- js调试控制台使用详解图解
一 实例图解 四种不同的console输出函数,输出信息前显示不同的图标: $查看某个元素: console.dir()可以显示一个对象所有的属性和方法: 分组显示信息: 显示digitalData对 ...
- PHP扩展详解(一)
为什么80%的码农都做不了架构师?>>> PHP详解 一个php实例,当被调用的时候,都会一次经过Module init,Request init,Request shutdo ...
- Js中apply方法详解说明
Js apply 方法 详解 我在一开始看到JavaScript的函数apply和call时,非常的模糊,看也看不懂,最近在网上看到一些文章对apply方法和call的一些示例,总算是看的有点眉目了, ...
最新文章
- tornado 09 cookie和session
- 执行delete触发器及示例演示
- html制作表格保存为txt文件,可将HTML表格导出为Excel|csv|txt文件的jQuery插件
- apple mac 下使用机械键盘的办法,键盘映射工具软件,apple mac Mechanical keyboard
- 删除一行下方单元格上移_快速删除Excel工作表多余空单元格
- Linux iNode 双网卡,已解决: Zynq 7000 双网卡配置-内核DTS该如何配置 - Community Forums...
- 【codevs2800】送外卖,状态压缩DP练习
- 新的一年,和大家一起进步
- 放弃大厂高薪的程序员,涌进体制内
- Excel 英文切换大小写;Excel 中去除重复项
- 《Python股票量化交易从入门到实践》学习记录
- vue axois 封装请求 | vue 解决跨域问题
- 如何用计算机表达无理数,利用泰勒级数计算无理数和以及其他任意无理数的近似值.doc...
- 【复现】CNVD-2020-10487-Tomcat-Ajp-lfi
- Linux内核同步原语之信号量(Semaphore)
- 【沧海拾昧】微机原理:可编程串行接口芯片8251A
- 冯诺曼伊体系 计算机五大逻辑,科学网—再谈冯·诺伊曼结构 - 姜咏江的博文
- 55.网页设计规则#3_图片和插图
- 武林大会之国产数据库风云榜-2021年11月
- esp-idf手动设置系统时间