在前两节,讲到了两种不同方式的聚类,一种是基于距离的,一种是基于区域范围的,两种不同的聚类都是通过扩展esri/layers/GraphicsLayer方法来实现的。在本节,就具体的讲讲esri/layers/GraphicsLayer方法的扩展。

首先。在解说扩展之前,先看看API中esri/layers/GraphicsLayer的一些參数和方法等。

1、创建一个GraphicLayer

在ESRI官方的API中,创建GraphicLayer有两种方式:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR0lTU2hpWGlTaGVuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

比如:

或者:

在另外一种方式的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 password:cvbf

如有疑问,请联系:

QQ:1004740957

E-Mail:niujp08@qq.com

Arcgis for Js之Graphiclayer扩展具体解释的更多相关文章

  1. Arcgis for Js之Graphiclayer扩展详解

    在前两节,讲到了两种不同方式的聚类,一种是基于距离的,一种是基于区域范围的,两种不同的聚类都是通过扩展esri/layers/GraphicsLayer方法来实现的.在本节,就详细的讲讲esri/la ...

  2. (转)Arcgis for Js之Graphiclayer扩展详解

    http://blog.csdn.net/gisshixisheng/article/details/41208185 在前两节,讲到了两种不同方式的聚类,一种是基于距离的,一种是基于区域范围的,两种 ...

  3. Arcgis for Js实现graphiclayer的空间查询

    本节讲的是Arcgis for Js的针对graphiclayer的空间查询,内容很简单,代码如下: <!DOCTYPE html> <html> <head> & ...

  4. Arcgis for Js实现graphiclayer的空间查询(续)

    上文中,实现了简单的针对graphiclayer的空间查询工作,在本节,将更加详细的介绍针对graphiclayer的空间查询.首先,空间查询的方式:提供多种类型的空间查询,包括点周边.线周边.面内等 ...

  5. Arcgis for JS之Cluster聚类分析的实现(基于区域范围的)

    原文:Arcgis for JS之Cluster聚类分析的实现(基于区域范围的) 咱们书接上文,在上文,实现了基于距离的空间聚类的算法实现,在本文,将继续介绍空间聚类之基于区域范围的实现方式,好了,闲 ...

  6. Arcgis for JS之Cluster聚类分析的实现

    原文:Arcgis for JS之Cluster聚类分析的实现 在做项目的时候,碰见了这样一个问题:给地图上标注点对象,数据是从数据库来 的,包含XY坐标信息的,通过graphic和graphicla ...

  7. (译+注解)node.js的C++扩展入门

    声明:本文主要翻译自node.js addons官方文档.部分解释为作者自己添加. 编程环境: 1. 操作系统 Mac OS X 10.9.51. node.js v4.4.22. npm v3.9. ...

  8. arcgis for js开发之路径分析

    arcgis for js开发之路径分析 //方法封装 function routeplan(x1, x2, y1, y2, barrierPathArray, isDraw, callback) { ...

  9. Arcgis for js开发之直线、圆、箭头、多边形、集结地等绘制方法

    p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...

随机推荐

  1. 2013 吉林通化邀请赛 Play Game 记忆化搜索

    dp[ba][ta][bb][tb]表示a堆牌从下面拿了ba张,从上面拿了ta张.b堆牌从下面拿了bb张,从上面拿了tb张.当前玩家能得到的最大的分数. 扩展方式有4种,ba+1,ta+1,bb+1, ...

  2. Android开发人员必知的开发资源

    developer.android.com 官方开发人员网站推荐资源 在动手编写第一个 Android 应用之前,用心读一读 Android Design 章节.尤其是以下的这些文章: Devices ...

  3. c语言太easy笔误的,这将做

    调试发现时间写的一样NB代码 test.c int add(string); int main() { char* p = "11222"; add(p); return 0; } ...

  4. oracle 之 内存—鞭辟近里(三)

    oracle 之 内存—鞭辟近里(三) 今天是2013-07-08,今天晚上突然接到一个电话,我的外甥问我的qq是多少,我感觉很吃惊,他长大了.在他现在这个年龄就开始接触网络,我难免有少许担心,希望他 ...

  5. cisco路由器IPSEC VPN配置(隧道模式)

    拓扑如下: R1配置hostname R1enable password cisco  crypto isakmp policy 1        #创建IKE协商策略,编号为1 encr 3des  ...

  6. Wix学习整理(7)——在开始菜单中为HelloWorld添加卸载快捷方式

    原文:Wix学习整理(7)--在开始菜单中为HelloWorld添加卸载快捷方式 通过前面的几篇随笔,我们已经给我们的HelloWorld提供了填写注册表信息,以及开始菜单快捷方式和桌面快捷方式.这些 ...

  7. APS.NET Cookie

    Cookie 提供了一种在 Web 应用程序中存储用户特定信息(如历史记录或用户首选项)的方法. Cookie 是一小段文本.伴随着请求和响应在 Web server和client之间来回传输.Coo ...

  8. Unity3D游戏开发从零单排(四) - 制作一个iOS游戏

    提要 此篇是一个国外教程的翻译,尽管有点老,可是适合新手入门. 自己去写代码.debug,布置场景,能够收获到非常多.游戏邦上已经有前面两部分的译文,这里翻译的是游戏的最后一个部分. 欢迎回来 在第一 ...

  9. JavaScript RegExp对象

    一.什么是RegExp         1.RegExp 是正則表達式的缩写. 2.当您检索某个文本时,能够使用一种模式来描写叙述要检索的内容.RegExp 就是这样的模式. 3.简单的模式能够是一个 ...

  10. HDU4344(大数分解)

    题目:Mark the Rope 题意就是给一个数,然后求这个数的所有因子中组成的最大的一个子集,其中1和本身除外,使得在这个子集中元素两两互素,求最大子集的元素个 数,并且求出和最大的值. 找规律就 ...