ArcGIS api for javascript——地理处理任务-瓶中信
描述
如果在海洋中丢下一个瓶子,本例使用颗粒追踪模型显示指定的天数后瓶子在的地方。首先,输入一个追踪瓶子的天数。然后单击按钮并在海洋里的任意地方画一个点来开始模型。几秒以后将看到一条线出现描述瓶子将去的地方。
关于这个模型的更多信息,见本例中引用的ArcGIS Server地理处理任务的服务目录页: http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle。这个页面列出了模型的参数并包含一个如何创建模型的帮助URL。
本例使用绘画工具栏帮助画点。工具栏不是一个可以加到页面的用户界面组件。而是一个帮助类,能够画某一几何体类型。更多信息见示例使用一个绘画工具栏。
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <meta http-equiv="X-UA-Compatible" content="IE=7" /> 6 <title>ArcGIS Geoprocessing and ArcGIS Server JavaScript API</title> 7 <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.5/js/dojo/dijit/themes/tundra/tundra.css"> 8 <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.5"></script> 9 <script type="text/javascript"> 10 dojo.require("esri.map"); 11 dojo.require("esri.tasks.gp"); 12 dojo.require("esri.toolbars.draw"); 13 14 var map, gp, toolbar; 15 16 function init() { 17 map = new esri.Map("mapDiv"); 18 var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"); 19 map.addLayer(streetMap); 20 gp = new esri.tasks.Geoprocessor("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle"); 21 //esri.toolbars.Draw(map, options) 创建一个新的绘图对象。地图是必要的参数。 22 toolbar = new esri.toolbars.Draw(map); 23 24 dojo.connect(toolbar,"onDrawEnd",executeParticleTrack); 25 26 } 27 28 function executeParticleTrack(geometry) { 29 30 31 map.graphics.clear(); 32 //使用一张图片定义样式。这是最常用的渲染方式之一。 33 //我们通常的应用都会使用这一样式,使地图图元的意义更加明朗,地图也更加的美观。 34 var simplePictureMarkerSymbol = new esri.symbol.PictureMarkerSymbol('http://www.esri.com/graphics/aexicon.jpg', 26, 26); 35 var graphic = new esri.Graphic(geometry,simplePictureMarkerSymbol); 36 map.graphics.add(graphic); 37 toolbar.deactivate();//None 关闭工具栏并激活地图导航. 38 39 40 var features = []; 41 features.push(graphic); 42 var featureSet = new esri.tasks.FeatureSet(); 43 featureSet.features = features; 44 45 var params = { "Input_Point":featureSet, "Days": dojo.byId("days").value }; 46 gp.execute(params, displayTrack); 47 48 } 49 50 function displayTrack(results, messages) { 51 alert(222); 52 var simpleLineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,255,0]), 1); 53 var features = results[0].value.features; 54 for(var i=0,j=features.length;i<j;i++) { 55 var feature = features[i]; 56 feature.setSymbol(simpleLineSymbol); 57 map.graphics.add(feature); 58 } 59 60 } 61 62 dojo.addOnLoad(init); 63 </script> 64 </head> 65 <body class="tundra"> 66 <table> 67 <tbody> 68 <tr> 69 <td>Select tool to draw and execute the particle tracker model. 70 <br>Start season is Spring. Number of days to track = <input type="text" id="days" value="180" size="3"/>. 71 <button onclick="toolbar.activate(esri.toolbars.Draw.POINT);">Draw and execute particle track.</button> 72 </td> 73 </tr> 74 <tr> 75 <td id="mapDiv" style="width:800px; height:600px; border:1px solid #000;"></td> 76 </tr> 77 </tbody> 78 </table> 79 </body> 80 </html>