MapClass.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. dojo.require("esri.map");
  2. dojo.require("esri.symbol");
  3. dojo.require("esri.tasks.geometry");
  4. dojo.require("esri.tasks.GeometryService");
  5. dojo.require("esri.tasks.BufferParameters");
  6. dojo.require("esri.toolbars.draw");
  7. dojo.require("esri.geometry.Extent");
  8. dojo.require("esri.layers.MapImageLayer");
  9. dojo.require("esri.layers.TileLayer");
  10. //dojo.require("esri.layers");
  11. var fullExtent;
  12. // var infoTemplate = new esri.InfoTemplate("${FIELD_NAME}", "Field ID : ${FIELD_KID}<br />Produces Gas : ${PROD_GAS}<br />Produces Oil : ${PROD_OIL}<br />Status : ${STATUS}");
  13. function init() {
  14. map = new esri.Map("mapDiv", {
  15. sliderOrientation: "vertical",
  16. sliderPosition: "top-right",
  17. sliderStyle: "large",
  18. logo:false
  19. });
  20. var view = new MapView({
  21. container: "mapDiv", // Reference to the DOM node that will contain the view
  22. map: map // References the map object created in step 3
  23. });
  24. dyAddMapLayerByConfig();
  25. AddMapGraphicLayers();
  26. map.on("load", LoadInfo);
  27. }
  28. function dyAddMapLayerByConfig(){
  29. var serverUrl;
  30. var serverType;
  31. var serverLabel;
  32. var serverVisible;
  33. var xmlUtil = new XMLUtil();
  34. var xmlDoc = xmlUtil.loadXmlFromFile("config/config_local.xml");
  35. var mapXml = xmlDoc.getElementsByTagName("map");
  36. var mapNodes = mapXml[0].childNodes;
  37. for (var i=0;i<mapNodes.length;i++){
  38. var nodeObj = mapNodes[i];
  39. if(nodeObj.nodeType == 1){
  40. var tagName = xmlUtil.getNodeTagName(nodeObj);
  41. var value = xmlUtil.getNodeValue(nodeObj);
  42. if(tagName == "geometryservice"){
  43. serverType = "geometryservice";
  44. serverUrl = value;
  45. dyAddMapLayer(serverUrl,serverType,serverLabel,serverVisible);
  46. }
  47. else if(tagName == "fullextent"){
  48. var extentArray = value.split(",");
  49. fullExtent = new esri.geometry.Extent(parseFloat(extentArray[0]),parseFloat(extentArray[1]),parseFloat(extentArray[2]),parseFloat(extentArray[3]));
  50. }
  51. else if (tagName == "basemaps"){
  52. var childNodes = nodeObj.childNodes;
  53. for (var j=0;j<childNodes.length;j++){
  54. var childNode = childNodes[j];
  55. if(childNode.nodeType == 1){
  56. for (var k=0;k<childNode.attributes.length;k++){
  57. var attribute = childNode.attributes[k];
  58. var attributeName = attribute.name;
  59. if(attributeName == "label"){
  60. serverLabel = attribute.value;
  61. }
  62. if(attributeName == "type"){
  63. serverType = attribute.value;
  64. }
  65. if(attributeName == "visible"){
  66. if (attribute.value == "false")
  67. serverVisible = false;
  68. else
  69. serverVisible = true;
  70. }
  71. }
  72. serverUrl = xmlUtil.getNodeValue(childNode);
  73. dyAddMapLayer(serverUrl,serverType,serverLabel,serverVisible);
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80. function dyAddMapLayer(serverUrl,serverType,serverLabel,serverVisible){
  81. var layer;
  82. switch(serverType){
  83. case "geometryservice":{
  84. geometryService = new esri.tasks.GeometryService(serverUrl);
  85. break;
  86. }
  87. case "tiled":{
  88. layer = new esri.layers.MapImageLayer({ url:serverUrl,"id": serverLabel });
  89. layer.visible = serverVisible;
  90. break;
  91. }
  92. case "dynamic":{
  93. layer = new esri.layers.TileLayer({url:serverUrl, "id": serverLabel });
  94. layer.visible = serverVisible;
  95. break;
  96. }
  97. case "featurelayer":{
  98. break;
  99. }
  100. }
  101. map.addLayer(layer);
  102. }
  103. function changeMapLayer(layerName,type){
  104. if(isEmptyValue(type) == true){
  105. type = "tiled";
  106. }
  107. for (var i=0; i<map.layerIds.length;i++){
  108. var layeridName = map.layerIds[i];
  109. var BaseLayer = map._layers[layeridName];
  110. if(type = "tiled"){
  111. if(BaseLayer.declaredClass == "esri.layers.ArcGISTiledMapServiceLayer"){
  112. if(layeridName == layerName){
  113. BaseLayer.show();
  114. }
  115. else{
  116. BaseLayer.hide();
  117. // map.getLayer(layeridName).hide();
  118. }
  119. }
  120. }
  121. else{
  122. if(BaseLayer.declaredClass == "esri.layers.ArcGISDynamicMapServiceLayer"){
  123. if(layeridName == layerName){
  124. BaseLayer.show();
  125. }
  126. else{
  127. BaseLayer.hide();
  128. }
  129. }
  130. }
  131. // map.getLayer(layerName).show();
  132. }
  133. }
  134. var drawtool;
  135. var initExtent;
  136. var FullExtent;
  137. var geometryService;
  138. var GraphicsLayer_labelLayer;//查询结果标签图层
  139. var GraphicsLayer_myLayer;//查询结果撒点图层
  140. var GraphicsLayer_identityLayer;//点查询结果图层
  141. var GraphicsLayer_extendLayer;//查询结果边界范围撒点图层
  142. var GraphicsLayer_fickerLayer;//闪烁特效图层
  143. var GraphicsLayer_DrawLayer;//绘制图层
  144. var GraphicsLayer_flyTipLayer;//飞行提示图层
  145. //地图添加公共标注图层
  146. function AddMapGraphicLayers()
  147. {
  148. GraphicsLayer_labelLayer = new esri.layers.GraphicsLayer();
  149. GraphicsLayer_myLayer = new esri.layers.GraphicsLayer();
  150. GraphicsLayer_identityLayer = new esri.layers.GraphicsLayer();
  151. GraphicsLayer_extendLayer = new esri.layers.GraphicsLayer();
  152. GraphicsLayer_fickerLayer = new esri.layers.GraphicsLayer();
  153. GraphicsLayer_DrawLayer = new esri.layers.GraphicsLayer();
  154. GraphicsLayer_flyTipLayer = new esri.layers.GraphicsLayer();
  155. map.addLayer(GraphicsLayer_labelLayer);
  156. map.addLayer(GraphicsLayer_identityLayer);
  157. map.addLayer(GraphicsLayer_extendLayer);
  158. map.addLayer(GraphicsLayer_DrawLayer);
  159. map.addLayer(GraphicsLayer_flyTipLayer);
  160. map.addLayer(GraphicsLayer_myLayer);
  161. map.addLayer(GraphicsLayer_fickerLayer);
  162. }
  163. var dynamicLayerURL; //动态查询图层URL
  164. //通过where条件查询图层信息
  165. function QueryObjectByWhere(LayerName,where,returnFields,KeyValue){
  166. KeyValue = KeyValue?KeyValue:"Query";
  167. var query = new esri.tasks.Query();
  168. var QueryLayerID = GetLayerIdbyName(LayerName);
  169. if(QueryLayerID == -1){
  170. return "无查询图层";
  171. }
  172. var queryTask = new esri.tasks.QueryTask(dynamicLayerURL+"/"+QueryLayerID);
  173. queryTask.where = " 1=1 ";
  174. if(where != ""){
  175. query.where = where;
  176. }
  177. query.outSpatialReference = map.spatialReference;
  178. query.returnGeometry = true;
  179. query.outFields = ["*"];
  180. if(returnFields != ""){
  181. query.outFields = returnFields;
  182. }
  183. queryTask.execute(query,
  184. function handleQueryResult(results){
  185. QueryObjectByWhereCompHandle(results, KeyValue);
  186. }
  187. ,function errorHandler(err){
  188. QueryObjectByWhereFaultHandle("查询不成功!",KeyValue);
  189. // return "查询不成功!";
  190. });
  191. }
  192. function QueryObjectByGeometry(LayerName,queryGeometry,where,returnFields,KeyValue) {
  193. KeyValue = KeyValue ? KeyValue : "Query";
  194. var query = new esri.tasks.Query();
  195. var QueryLayerID = GetLayerIdbyName(LayerName);
  196. if (QueryLayerID == -1) {
  197. return "无查询图层";
  198. }
  199. var queryTask = new esri.tasks.QueryTask(dynamicLayerURL + "/" + QueryLayerID);
  200. if (queryGeometry != null) {
  201. queryGeometry.spatialReference = map.spatialReference;
  202. query.geometry = queryGeometry;
  203. }
  204. queryTask.where = " 1=1 ";
  205. if (where != "") {
  206. query.where = where;
  207. }
  208. query.outSpatialReference = map.spatialReference;
  209. query.returnGeometry = true;
  210. query.outFields = ["*"];
  211. if (returnFields != "") {
  212. query.outFields = returnFields;
  213. }
  214. queryTask.execute(query,
  215. function handleQueryResultByGeometry(results) {
  216. QueryObjectByWhereCompHandle(results, KeyValue);
  217. }
  218. , function errorHandlerByGeometry(err) {
  219. QueryObjectByWhereFaultHandle("查询不成功!",KeyValue);
  220. });
  221. }
  222. //-----------------------------------------Symbol------------------------------------------------------------------------------
  223. function GetSymbol_SimpleMarkerSymbol(style,size,color,alpha,outlineStyle,outline_Color,outlineAlpha,outlineWidth)
  224. {
  225. style = style?style:esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE;
  226. size = size?size:10;
  227. color = color?color:"#ff0000";
  228. alpha = alpha?alpha:0.8;
  229. outlineStyle = outlineStyle?outlineStyle:esri.symbol.SimpleLineSymbol.STYLE_SOLID;
  230. outline_Color = outline_Color?outline_Color:"#ff0000";
  231. outlineAlpha = outlineAlpha?outlineAlpha:0.9;
  232. outlineWidth = outlineWidth?outlineWidth:1;
  233. //(style, size, outline, color) style:STYLE_CIRCLE;STYLE_CROSS;STYLE_DIAMOND;STYLE_PATH;STYLE_SQUARE;STYLE_X
  234. var defaultPointSymbol ;
  235. require(["esri/symbols/SimpleMarkerSymbol", "esri/symbols/PictureFillSymbol", "esri/symbols/SimpleLineSymbol","esri/symbols/SimpleFillSymbol","esri/Color"],
  236. function(SimpleMarkerSymbol,PictureFillSymbol,SimpleLineSymbol,SimpleFillSymbol,Color) {
  237. defaultPointSymbol = new SimpleMarkerSymbol();
  238. defaultPointSymbol.style = style;
  239. defaultPointSymbol.size = size;
  240. //SetPointColor
  241. var PointColor = new Color(color);
  242. PointColor.a = alpha;
  243. defaultPointSymbol.color = PointColor;
  244. //SetOutLine
  245. var outlineColor = new Color(outline_Color);
  246. outlineColor.a = outlineAlpha;
  247. defaultPointSymbol.outline = new SimpleLineSymbol(outlineStyle,outlineColor,outlineWidth);
  248. return defaultPointSymbol;
  249. });
  250. return defaultPointSymbol;
  251. }
  252. function GetSymbol_SimpleLineSymbol(style, color, width ,alpha)
  253. {
  254. style = style?style:esri.symbol.SimpleLineSymbol.STYLE_SOLID;
  255. color = color?color:"#ff0000";
  256. width = width?width:2;
  257. alpha = alpha?alpha:1;
  258. //(style, color, width)style:STYLE_DASH;STYLE_DASHDOT;STYLE_DASHDOTDOT;STYLE_DOT;STYLE_LONGDASH;STYLE_LONGDASHDOT;STYLE_NULL;STYLE_SHORTDASH;STYLE_SHORTDASHDOT;STYLE_SHORTDASHDOTDOT;STYLE_SHORTDOT;STYLE_SOLID
  259. var defaultLineSymbol ;
  260. require(["esri/symbols/SimpleMarkerSymbol", "esri/symbols/PictureFillSymbol", "esri/symbols/SimpleLineSymbol","esri/symbols/SimpleFillSymbol","esri/Color"],
  261. function(SimpleMarkerSymbol,PictureFillSymbol,SimpleLineSymbol,SimpleFillSymbol,Color) {
  262. defaultLineSymbol = new SimpleLineSymbol();
  263. defaultLineSymbol.style = style;
  264. defaultLineSymbol.width = width;
  265. //SetLineColor
  266. var LineColor = new Color(color);
  267. LineColor.a = alpha;
  268. defaultLineSymbol.color = LineColor;
  269. return defaultLineSymbol;
  270. });
  271. return defaultLineSymbol;
  272. }
  273. function GetSymbol_SimpleFillSymbol(style, color,alpha,outlineStyle,outline_Color,outlineAlpha,outlineWidth)
  274. {
  275. if(style == undefined){
  276. style = esri.symbol.SimpleFillSymbol.STYLE_SOLID;
  277. }
  278. else{
  279. }
  280. // style = (style==undefined)?style:esri.symbol.SimpleFillSymbol.STYLE_SOLIDE;
  281. color = color!=undefined?color:"#ff0000";
  282. alpha = alpha!=undefined?alpha:0.3;
  283. outlineStyle = outlineStyle!=undefined?outlineStyle:esri.symbol.SimpleLineSymbol.STYLE_SOLID;
  284. outline_Color = outline_Color!=undefined?outline_Color:"#ff0000";
  285. outlineAlpha = outlineAlpha!=undefined?outlineAlpha:0.9;
  286. outlineWidth = outlineWidth!=undefined?outlineWidth:1;
  287. //(style, outline, color) style:STYLE_BACKWARD_DIAGONAL;STYLE_CROSS ;STYLE_DIAGONAL_CROSS;STYLE_FORWARD_DIAGONAL;STYLE_HORIZONTAL;STYLE_NULL;STYLE_SOLID ;STYLE_VERTICAL
  288. var defaultFillSymbol ;
  289. require(["esri/symbols/SimpleMarkerSymbol", "esri/symbols/PictureFillSymbol", "esri/symbols/SimpleLineSymbol","esri/symbols/SimpleFillSymbol","esri/Color"],
  290. function(SimpleMarkerSymbol,PictureFillSymbol,SimpleLineSymbol,SimpleFillSymbol,Color) {
  291. defaultFillSymbol = new SimpleFillSymbol();
  292. defaultFillSymbol.style = style;
  293. //SetFillColor
  294. var FillColor = new Color(color);
  295. FillColor.a = alpha;
  296. defaultFillSymbol.color = FillColor;
  297. //SetOutLine
  298. var outlineColor = new Color(outline_Color);
  299. outlineColor.a = outlineAlpha;
  300. defaultFillSymbol.outline = new SimpleLineSymbol(outlineStyle,outlineColor,outlineWidth);
  301. return defaultFillSymbol;
  302. });
  303. return defaultFillSymbol;
  304. }
  305. //-----------------------------------------------Symbol End---------------------------------------------------------------
  306. function QueryResultHandler(results)
  307. {
  308. var defaultPointSymbol = GetSymbol_SimpleMarkerSymbol();
  309. var defaultPolylineSymbol = GetSymbol_SimpleLineSymbol();
  310. var defaultFillSymbol = GetSymbol_SimpleFillSymbol();
  311. var graphicShow;
  312. var showFeaturesArray = new Array();
  313. dojo.forEach(results, function (graphic, i){
  314. switch (graphic.geometry.type){
  315. case "point":{
  316. graphic.symbol = defaultPointSymbol;
  317. break;
  318. }
  319. case "polyline":{
  320. graphic.symbol = defaultPolylineSymbol;
  321. break;
  322. }
  323. case "polygon":{
  324. graphic.symbol = defaultFillSymbol;
  325. break;
  326. }
  327. }
  328. graphicShow = graphic;
  329. showFeaturesArray.push(graphic);
  330. });
  331. AddObjectToMap(map,GraphicsLayer_myLayer,showFeaturesArray);
  332. // GraphicsLayer_myLayer.add(graphicShow);
  333. }
  334. function AddObjectToMap(myMap, graphicLayer, graphics, isClearLayer,isZoomToObj, zoomBuffer, isFicker, extendFactor,FickerCount,FickerDelay)
  335. {
  336. isClearLayer = isClearLayer==true?true:false;
  337. isZoomToObj = isZoomToObj==true?true:false;
  338. zoomBuffer = zoomBuffer?zoomBuffer:100;
  339. isFicker = isFicker==true?true:false;
  340. extendFactor = extendFactor?extendFactor:1.2;
  341. if (graphicLayer == null || graphics == null || graphics.length <= 0) {
  342. return;
  343. }
  344. if (isClearLayer){
  345. graphicLayer.clear();
  346. }
  347. dojo.forEach(graphics, function (graphic, i) {
  348. if (graphic.geometry instanceof esri.geometry.Point) {
  349. var myGeometry = graphic.geometry;
  350. var pathArray = new Array();
  351. var pointArray = new Array();
  352. var centerPoint = myGeometry;
  353. var beginPoint = new esri.geometry.Point(centerPoint.x - zoomBuffer, centerPoint.y - zoomBuffer, centerPoint.spatialReference);
  354. pointArray.push(beginPoint);
  355. var endPoint = new esri.geometry.Point(centerPoint.x + zoomBuffer, centerPoint.y + zoomBuffer, centerPoint.spatialReference);
  356. pointArray.push(endPoint);
  357. pathArray.push(pointArray);
  358. var polyLine = new esri.geometry.Polyline();
  359. polyLine.spatialReference = myMap.spatialReference;//必须与map保持一致
  360. polyLine.addPath([new esri.geometry.Point(beginPoint.x, beginPoint.y, beginPoint.spatialReference), new esri.geometry.Point(endPoint.x, endPoint.y, endPoint.spatialReference)]);
  361. //取对象范围
  362. if (i == 0) {
  363. currentExtent = polyLine.getExtent();
  364. }
  365. else {
  366. currentExtent = currentExtent.union(polyLine.getExtent());
  367. }
  368. }
  369. else if (graphic.geometry instanceof esri.geometry.Polyline) {
  370. if (i == 0) {
  371. currentExtent = graphic.geometry.getExtent();
  372. }
  373. else
  374. {
  375. currentExtent = currentExtent.union(graphic.geometry.getExtent());
  376. }
  377. }
  378. else if (graphic.geometry instanceof esri.geometry.Polygon) {
  379. if (i == 0) {
  380. currentExtent = graphic.geometry.getExtent();
  381. }
  382. else {
  383. currentExtent = currentExtent.union(graphic.geometry.getExtent());
  384. }
  385. }
  386. graphicLayer.add(graphic);
  387. });
  388. if(FickerCount == undefined){
  389. FickerCount = 3;
  390. }
  391. if(FickerDelay == undefined){
  392. FickerDelay = 800;
  393. }
  394. if (isZoomToObj && isFicker) {
  395. myMap.setExtent(currentExtent.expand(extendFactor), true);
  396. fickerGraphic(graphicLayer,graphics,FickerCount,FickerDelay);
  397. }
  398. else if (isZoomToObj && !isFicker) {
  399. myMap.setExtent(currentExtent.expand(extendFactor), true);
  400. }
  401. else if (!isZoomToObj && isFicker) {
  402. fickerGraphic(graphicLayer,graphics,FickerCount,FickerDelay);
  403. }
  404. }
  405. var interval_;
  406. function fickerGraphic(originLayer,graphics,fickerCount,fickerDelay){
  407. clearInterval(interval_);
  408. // originLayer.hide();
  409. var fickeredCount;//当前闪烁次数
  410. // originLayer.clear();
  411. // dojo.forEach(graphics, function (graphic, i) {
  412. // originLayer.add(graphic);
  413. // });
  414. fickeredCount = 0;
  415. interval_ = setInterval(function () {
  416. if(fickeredCount<fickerCount){
  417. originLayer.hide();
  418. setTimeout(function () {
  419. originLayer.show();
  420. },fickerDelay/2);
  421. }
  422. else if (fickeredCount == fickerCount){
  423. originLayer.show();
  424. clearInterval(interval_);
  425. }
  426. fickeredCount++;
  427. },fickerDelay);
  428. }
  429. //获取动态图层LayerInfo 及 动态图层URL
  430. function GetDynamicServiceLayer()
  431. {
  432. var layerInfo;
  433. for (var i=0; i<map.layerIds.length;i++){
  434. var layeridName = map.layerIds[i];
  435. var BaseLayer = map._layers[layeridName];
  436. if(BaseLayer.declaredClass == "esri.layers.ArcGISDynamicMapServiceLayer"){
  437. layerInfo = map._layers[layeridName].layerInfos;
  438. dynamicLayerURL = BaseLayer._url.path;
  439. return layerInfo;
  440. }
  441. }
  442. return null;
  443. }
  444. //通过图层名称获取图层ID
  445. function GetLayerIdbyName(name)
  446. {
  447. var index = map.getLayer(name);
  448. var layerInfo;
  449. layerInfo = GetDynamicServiceLayer();
  450. if (layerInfo != null){
  451. for (var j=0 ; j<layerInfo.length ;j++){
  452. var currnetLayer = layerInfo[j];
  453. if(currnetLayer.name == name){
  454. return currnetLayer.id;
  455. }
  456. }
  457. }
  458. return -1;
  459. }
  460. //------------------------------------------------------------------GeometryService-----------------------------------------------------------------
  461. function DrawGraphic(drawType){
  462. drawTool = new esri.toolbars.Draw(map);
  463. drawTool.on("draw-end", DrawEnd);
  464. switch (drawType) {
  465. case "POINT": {
  466. drawType = esri.toolbars.Draw.POINT;
  467. break;
  468. }
  469. case "MULTI_POINT":{
  470. drawType = esri.toolbars.Draw.POINT;
  471. break;
  472. }
  473. case "POLYGON":{
  474. drawType = esri.toolbars.Draw.POLYGON;
  475. break;
  476. }
  477. case "LINE": {
  478. drawType = esri.toolbars.Draw.POLYLINE;
  479. break;
  480. }
  481. case "CIRCLE":{
  482. drawType = esri.toolbars.Draw.CIRCLE;
  483. break;
  484. }
  485. }
  486. GraphicsLayer_DrawLayer.clear();
  487. // drawType = drawType?drawType:esri.toolbars.Draw.POINT;
  488. //POINT,MULTI_POINT,POLYLINE,POLYGON,FREEHAND_POLYLINE,FREEHAND_POLYGON,LINE,EXTENT
  489. drawTool.activate(drawType);
  490. }
  491. function DrawEnd(evt){
  492. drawTool.deactivate();
  493. var geometry = evt.geometry;
  494. var symbol;
  495. switch (evt.geometry.type){
  496. case "point":{
  497. symbol = GetSymbol_SimpleMarkerSymbol();
  498. break;
  499. }
  500. case "polyline":{
  501. symbol = GetSymbol_SimpleLineSymbol();
  502. break;
  503. }
  504. case "polygon":{
  505. symbol = GetSymbol_SimpleFillSymbol();
  506. break;
  507. }
  508. }
  509. var graphic = new esri.Graphic(geometry,symbol);
  510. AddObjectToMap(map,GraphicsLayer_DrawLayer,[graphic],false,false,100,false,1);
  511. }
  512. function mydraw(drawType){
  513. drawTool = new esri.toolbars.Draw(map);
  514. drawTool.on("draw-end", addToMap);
  515. switch (drawType) {
  516. case "POINT": {
  517. drawType = esri.toolbars.Draw.POINT;
  518. break;
  519. }
  520. case "MULTI_POINT":{
  521. drawType = esri.toolbars.Draw.POINT;
  522. break;
  523. }
  524. case "POLYGON":{
  525. drawType = esri.toolbars.Draw.POLYGON;
  526. break;
  527. }
  528. case "LINE": {
  529. drawType = esri.toolbars.Draw.POLYLINE;
  530. break;
  531. }
  532. case "CIRCLE":{
  533. drawType = esri.toolbars.Draw.CIRCLE;
  534. break;
  535. }
  536. }
  537. GraphicsLayer_DrawLayer.clear();
  538. // drawType = drawType?drawType:esri.toolbars.Draw.POINT;
  539. //POINT,MULTI_POINT,POLYLINE,POLYGON,FREEHAND_POLYLINE,FREEHAND_POLYGON,LINE,EXTENT
  540. drawTool.activate(drawType);
  541. }
  542. function addToMap(evt) {
  543. drawTool.deactivate();
  544. var geometry = evt.geometry;
  545. //geometry.spatialReference = new esri.SpatialReference({ wkid: 4326 });
  546. var graphic = new esri.Graphic(geometry, GetSymbol_SimpleMarkerSymbol());
  547. AddObjectToMap(map,GraphicsLayer_DrawLayer,[graphic],false,false,100,false,1);
  548. GenerateBuffer([geometry]);
  549. }
  550. function GenerateBuffer(geometriesArray)
  551. {
  552. if(geometryService)
  553. {
  554. var params = new esri.tasks.BufferParameters();
  555. params.geometries = geometriesArray;
  556. params.distances = [100];
  557. params.unit = esri.tasks.GeometryService.UNIT_MILE;
  558. params.unionResults = true;
  559. params.bufferSpatialReference = map.spatialReference;
  560. params.outSpatialReference = map.spatialReference;
  561. geometryService.buffer(params, doBufferComplete, doBufferFault);
  562. }
  563. }
  564. function doBufferComplete(event)
  565. {
  566. var graphic = new esri.Graphic(event[0], GetSymbol_SimpleFillSymbol());
  567. AddObjectToMap(map,GraphicsLayer_extendLayer ,[graphic],false,true,100,false,1.5)
  568. //myMap.graphics.add(graphic);
  569. }
  570. function doBufferFault(event)
  571. {
  572. alert("fault");
  573. }
  574. function setFullExtent(){
  575. fullExtent.spatialReference = map.spatialReference;
  576. map.setExtent(fullExtent, true);
  577. }