日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/5/22 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (转)Arcgis for Js之Graphiclayer扩展详解 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

http://blog.csdn.net/gisshixisheng/article/details/41208185

在前兩節(jié),講到了兩種不同方式的聚類,一種是基于距離的,一種是基于區(qū)域范圍的,兩種不同的聚類都是通過(guò)擴(kuò)展esri/layers/GraphicsLayer方法來(lái)實(shí)現(xiàn)的。在本節(jié),就詳細(xì)的講講esri/layers/GraphicsLayer方法的擴(kuò)展。

?

首先,在講解擴(kuò)展之前,先看看API中esri/layers/GraphicsLayer的一些參數(shù)和方法等。

1、創(chuàng)建一個(gè)GraphicLayer

在ESRI官方的API中,創(chuàng)建GraphicLayer有兩種方式:

例如:

或者:

在第二種方式的options的參數(shù)包括:

2、GraphicLayer的屬性

GraphicLayer的屬性包括:

其中,有幾個(gè)比較常見(jiàn)和重要的屬性為:

a、graphics:數(shù)組,返回的參數(shù)是一個(gè)數(shù)組,為GraphicLayer中包含的Graphic對(duì)象。

b、visiable:布爾型,Graphiclayer是否可見(jiàn)。

c、visiableAtMapScale:布爾型,在特定比例尺下的可見(jiàn)性。

3、Graphiclayer的方法

圖中,紅框標(biāo)出的是Graphiclayer最常用的方法,詳細(xì)的介紹很清楚,在此不再做贅述了。

?

接下來(lái),擴(kuò)展Graphiclayer。

GraphicLayer藏得很深,位于library\3.9\3.9\js\esri\layers\GraphicsLayer.js,雖然對(duì)參數(shù)變量代碼做了混淆,但是有些東西還是沒(méi)做變化。在做GraphicLayer擴(kuò)展時(shí),有幾個(gè)是比較常用的:

a、_setMap

?

[javascript]?view plaincopy print?
  • //?重構(gòu)esri/layers/GraphicsLayer方法??
  • _setMap:?function(map,?surface)?{??
  • ????//?GraphicsLayer?will?add?its?own?listener?here??
  • ????var?div?=?this.inherited(arguments);??
  • ????return?div;??
  • }??

  • b、_unsetMap

    ?

    ?

    [html]?view plaincopy print?
  • _unsetMap:?function()?{??
  • ????this.inherited(arguments);??
  • }??
  • ?

    c、_draw

    ?

    [javascript]?view plaincopy print?
  • _draw:function(graphic,?redrawFlag,?zoomFlag){??
  • ????if?(!this._map)?{??
  • ????????return;??
  • ????}??
  • }??
  • 此外,還有一些地圖控制的,如:_onPanStartHandler,_onZoomStartHandler,_onExtentChangeHandler等。擴(kuò)展GraphicLayer的大概框架代碼如下:

    ?

    ?

    [javascript]?view plaincopy print?
  • define([??
  • ????"dojo/_base/declare",??
  • ????"esri/layers/GraphicsLayer"??
  • ],?function?(??
  • ????declare,??
  • ????GraphicsLayer??
  • ????)?{??
  • ????return?declare([GraphicsLayer],?{??
  • ????????constructor:?function(options)?{??
  • ????????//參數(shù)設(shè)置??
  • ????????????this._id?=?options.id?||?"";??
  • ????????????this._divId?=?options.chartDiv?||?"chart";??
  • ????????},??
  • ????????//?重構(gòu)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;??
  • ????????????}??
  • ????????????//??
  • ????????}??
  • ????});??
  • });??

  • 例子:添加統(tǒng)計(jì)圖

    ?

    統(tǒng)計(jì)圖通過(guò)dojo chart實(shí)現(xiàn),代碼如下:

    ?

    [javascript]?view plaincopy print?
  • 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;??
  • ????????},??
  • ????????//?重構(gòu)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();??
  • ????????????}??
  • ????????}??
  • ????});??
  • });??
  • ?

    實(shí)現(xiàn)后的效果如下:

    源碼下載地址:

    鏈接:http://pan.baidu.com/s/1i3EbnF3 密碼:cvbf

    總結(jié)

    以上是生活随笔為你收集整理的(转)Arcgis for Js之Graphiclayer扩展详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。