在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
上一篇《ArcGIS Server 10.2 实战(一)Asp.net MVC与JSON数据妙用实现动态生成要素图层》介绍了如何用JSON转要素的地理处理服务,实现了动态创建点要素并加载到相应的地图上,但是对于线、面要素,由于动态生成时需要较大的JSON数据,这个方法就不太合适了,下面介绍另一个可行的方法,用动态的方法修改现有面要素的指定字段数据。 首先还是先谈谈问题的背景,需要制作一个专题地图,用于对于各块地域的数据进行分级填色,每天都有一套数据对应有一个专题地图,同样不可能每天都制作图层和发布,因此需要图层中的数据可根据从外部数据源的查询到的数据动态的变化。好,下面就来解决这个问题。 饮水思源,转载勿删:www.evkchina.com 1.创建ArcGIS模型:用数据管理工具》字段》计算字段,设置输入表、字段名、表达式、表达式类型(采用PYTHON_9.3)和代码块,其中表达式(expressionP)和代码块(codeblockP)为模型参数,流域排放总量等级作为模型参数并勾选添加至显示。 2.地理处理服务的发布在《ArcGIS Server 10.2 实战(一)Asp.net MVC与JSON数据妙用实现动态生成要素图层》中已经略有介绍,就不细说了。 3.在javascript中使用地理处理服务:调用发布的javascript代码为,具体代码解读可以参照Arcgis官网给出的例子(https://developers.arcgis.com/en/javascript/jssamples/gp_resultmapservice.html)。
<script type="text/javascript"> require([ "dojo/dom", "dojo/_base/array", "dojo/date/locale", "dojo/parser", "dijit/registry", "esri/domUtils", "esri/map", "esri/graphic", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer", "esri/tasks/Geoprocessor", "esri/dijit/Legend", "dijit/form/DateTextBox", "dijit/layout/BorderContainer", "dijit/layout/ContentPane"], function (dom, array, locale, parser, registry, domUtils, Map, Graphic, ArcGISDynamicMapServiceLayer, FeatureLayer, Geoprocessor, Legend) { var gpServiceUrl = "http://huang-pc:6080/arcgis/rest/services/dianchi/liuyuZL/GPServer/liuyuZL", mapserviceurl = "http://huang-pc:6080/arcgis/rest/services/dianchi/liuyuZL/MapServer/jobs", legend; parser.parse(); var map = new Map("map", { basemap: "satellite", center: [102.7038, 24.8270], logo: false, zoom: 11 }); var riversLayer = new ArcGISDynamicMapServiceLayer("http://huang-pc:6080/arcgis/rest/services/dianchi/rivers/MapServer", { "id": "rivers" }); //Run the gp task when the app loads to display default incidents // map.on("load", findHotspot); function findHotspot() { //cleanup any results from previous runs cleanup(); mysubmitJob(); } function cleanup() { //hide the legend and remove the existing hotspot layer domUtils.hide(dom.byId('legendDiv')); var hotspotLayer = map.getLayer('HotspotLayer'); if (hotspotLayer) { map.removeLayer(hotspotLayer); map.removeLayer(map.getLayer('rivers')); } } var jobs = 0; var jobstatus = ""; var interval; function mysubmitJob() { var thedate = $("#theDate").val(); var wq = $("#dataType").val(); $.ajax({ type: "POST", url:"@Url.Action("R2GISViewLYcodeblockP", "Home")", data:{"year" : thedate, "wq" : wq}, success:function (data) { var codeblockp = data.codeblockP; $("#lastdate").text("当年总量累加至" + data.lastDate); var submitjoburl = gpServiceUrl + "/submitJob"; $.ajax({ type: 'get', dataType: "jsonp", url: submitjoburl, data: { codeblockP: codeblockp, expressionP: "setData ( !DSN! )", f: "pjson" }, jsonpCallback: "jsonpCallback", success: function (data) { jobs = 0; if (data.jobStatus == "esriJobSucceeded") { doMapJob(data); } else { getJobStatus(data.jobId); } } }); } }); } function getJobStatus(sjobid) { clearTimeout(interval); domUtils.show(dom.byId('status')); if (jobs < 60) { var sjoburl = gpServiceUrl + "/jobs/" + sjobid; $.ajax({ type: "get", dataType: "jsonp", url: sjoburl, data: { f: "pjson" }, jsonpCallback: "jsonpCallback", success: function (data) { switch (data.jobStatus) { case 'esriJobSubmitted': jobstatus = '已提交...'; dom.byId('status').innerHTML = jobstatus; jobs = jobs + 1; interval = setTimeout(function () { getJobStatus(data.jobId) }, 1000); break; case 'esriJobExecuting': jobstatus = '处理中...'; dom.byId('status').innerHTML = jobstatus; jobs = jobs + 1; interval = setTimeout(function () { getJobStatus(data.jobId) }, 1000); break; case 'esriJobSucceeded': clearTimeout(interval); domUtils.hide(dom.byId('status')); doMapJob(data); break; case 'esriJobFailed': clearTimeout(interval); jobstatus = '查询失败'; dom.byId('status').innerHTML = jobstatus; gpJobFailed(); } } }); } else { clearTimeout(interval); jobstatus = '查询失败'; dom.byId('status').innerHTML = jobstatus; gpJobFailed(); } } function gpJobFailed() { //domUtils.hide(dom.byId('status')); } function doMapJob(jobinfo) { //construct the result map service url using the id from jobinfo we'll add a new layer to the map var mapurl = mapserviceurl + "/" + jobinfo.jobId; var hotspotLayer = new ArcGISDynamicMapServiceLayer(mapurl, { "id": "HotspotLayer", "opacity": 1 }); //add the hotspot layer to the map map.addLayers([hotspotLayer]); map.addLayers([riversLayer]); map.on("layers-add-result", function (evtObj) { domUtils.show(dom.byId('legendDiv')); if (!legend) { //add the legend to show the resulting layer. var layerInfo = array.map(evtObj.layers, function (layer, index) { return { layer: layer.layer, title: "结果图层" }; }); legend = new Legend({ map: map, layerInfos: layerInfo }, "legendDiv"); legend.startup(); } }); } app = { findHotspot: findHotspot }; return app; }); </script>
其中,function mysubmitJob()中的"@Url.Action("R2GISViewLYcodeblockP", "Home")"是Asp.net MVC中的写法,是异步调用URL home/R2GISViewLYcodeblockP,返回代码块的内容,而且这里不必要使用跨域的写法,一般ajax异步就可以,方法代码如下
public ActionResult R2GISViewLYcodeblockP(int year, string wq) { var codeblockp = new LiuYUData().getZLData(year, wq); JsonResult jsonData = new JsonResult { Data = codeblockp }; return Json(jsonData.Data); }
public LYData getZLData(int year, string wq) { var lydata = new LYData(); lydata.lastDate = "(无数据累加)"; string zldata = ""; var zls = db.R2_WQs.Where(m => m.DateTime.Value.Year == year && m.Object == wq + " 年总量").ToList(); if (zls.Count > 0) { zldata = "def setData ( dsn ):\n"; foreach (var zl in zls) { zldata = zldata + " if dsn == " + "\"" + zl.DSNID.Substring(0, zl.DSNID.Length - 2) + "\":\n" + " return " + zl.ZLWarn.ToString() + "\n"; } zldata = zldata + " else:\n return 0"; lydata.codeblockP = zldata; lydata.lastDate = zls[0].DateTime.Value.ToString("yyyy年MM月dd日", DateTimeFormatInfo.InvariantInfo); } return lydata; }
饮水思源,转载勿删:http://www.cnblogs.com/evkchina/p/3429793.html,请支持关注北京易维清www.evkchina.com 到此为止,问题就结束了。 由于时间关系,很多具体的细节没有在这里说到,请见谅,欢迎在本文评论中交流学习。 这里是用计算字段的代码块来对图层要素进行动态修改数据内容,感觉这种方法很笨重奇怪,但是寻找了很久也没有一个好的接口根据外部数据动态修改图层要素数据,有没有别的更简便的方法呢,请各位大神指教。 |
请发表评论