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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

ArcGIS API For JS之网络分析(临近设施分析)

發布時間:2023/12/1 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ArcGIS API For JS之网络分析(临近设施分析) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ArcGIS 提供兩種網絡分析,即基于Geometric Network的有向網絡或者設施網絡和基于Network Dataset的無向網絡,在這里網絡的分析指后者,ArcGIS api支持網絡分析中的最短路徑分析、服務區分析、臨近設施分析。本文主要講的是臨近設施分析,關于發布網絡服務在這里就不在敘述了,三種分析發布相同,只是在后臺ArcMap中處理方式有點區別。

一、概述

1、概念

臨近設施服務計算事件和設施之間的行駛成本,并決定那一個距離最近,最后給出最佳的路徑,在這里認為,這算是最短距離的升級版本

2、相關的類

  • ClosestFacilityTask(執行命令,聲明需要一個Rest資源,即NAServer服務)
  • ClosestFacilityParameters(參數)
  • ClosestFacilitySolveResult(處理結果)(這里沒用到,該類用處非常大)

二、參數聲明與設置

closestFacilityTask = new ClosestFacilityTask("http://localhost:6080/arcgis/rest/services/Test/CloseFacilityTest/NAServer/CloseFacility");//臨近設施分析參數var params = new ClosestFacilityParameters();//單位params.impedenceAttribute = "Miles";params.defaultCutoff = 7.0;//是否返回事件信息params.returnIncidents = false;//是否返回路徑params.returnRoutes = true;//路徑是否有參數params.returnDirections = true;//服務點params.facilities = new FeatureSet();//事件點params.incidents = new FeatureSet();//點障礙params.pointBarriers = new FeatureSet();//空間參考params.outSpatialReference = map.SpatialReference;

?

在這里有很多參數可以設置,服務點、事件點、路徑、空間參考,是必須要設置的,其他參數可以根據自己需要設置,這里FeatureSet是要素類的輕量級的表示,相當于地理數據中的一個要素類,Feature的集合,FeatureSet中的每個Feature可能包含Geometry、屬性、符號、InfoTemplate。FeatureSet是api和arcgis server通訊的非常重要的對象。當使用查詢、地理出咯i和路徑分析的時候,FeatureSet常常作為這些分析功能的輸入或輸出參數。

三、符號樣式

//服務點符號樣式var facilityPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE,20,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([89, 95, 35]), 2),new Color([130, 159, 83, 0.40]));//事件點符號樣式var incidentPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,16,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([89, 95, 35]), 2),new Color([130, 159, 83, 0.40]));//障礙點的符號樣式var barrierSymbol = new SimpleMarkerSymbol();barrierSymbol.style = SimpleMarkerSymbol.STYLE_X;barrierSymbol.setSize(12);barrierSymbol.setColor(new Color("#f1a340"));incidentsGraphicsLayer = new GraphicsLayer();//結果路徑線符號樣式var routePolylineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color("#0078df"),4.0);

四、分析結果處理

function showRoute(solveResult) {//路徑分析的結果var routeResults = solveResult.routes;//路徑分析的長度var res = routeResults.length;if (res > 0) {for (var i = 0; i < res; i++) {var graphicroute = routeResults[i];var graphic = graphicroute;graphic.setSymbol(routePolylineSymbol);map.graphics.add(graphic);}}else {alert("沒有返回結果");}}

五、全部源碼

<!DOCTYPE html> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"><title>Closest Facilities</title><link rel="stylesheet" href="https://js.arcgis.com/3.25/dijit/themes/claro/claro.css"><link rel="stylesheet" href="https://js.arcgis.com/3.25/esri/css/esri.css"><style type="text/css">#map{width: 100%;height: 600px;border: 1px solid #000;}</style><script src="https://js.arcgis.com/3.25/"></script><script src="../Scripts/jquery-1.7.1.js"></script></head><body><div id="map"></div><input id="server" type="button" value="服務點" /><input id="eventPoint" type="button" value="事件點" /><input id="barriers" type="button" value="障礙點" /><input id="analyse" type="button" value="分析" /><input id="clear" type="button" value="清除" /><script> require(["dojo/on","dojo/dom","dojo/_base/array","esri/Color","dojo/parser","dijit/registry","esri/urlUtils","esri/map","esri/lang","esri/graphic","esri/InfoTemplate","esri/layers/GraphicsLayer","esri/renderers/SimpleRenderer","esri/layers/ArcGISDynamicMapServiceLayer","esri/geometry/Point","esri/tasks/FeatureSet","esri/tasks/ClosestFacilityTask","esri/tasks/ClosestFacilityParameters","esri/symbols/SimpleMarkerSymbol","esri/symbols/SimpleLineSymbol","esri/symbols/TextSymbol","dijit/form/ComboBox","dijit/layout/BorderContainer","dijit/layout/ContentPane"], function (on, dom, array, Color, parser, registry,urlUtils, Map, esriLang, Graphic, InfoTemplate, GraphicsLayer, SimpleRenderer, ArcGISDynamicMapServiceLayer,Point, FeatureSet,ClosestFacilityTask, ClosestFacilityParameters,SimpleMarkerSymbol, SimpleLineSymbol, TextSymbol) {var incidentsGraphicsLayer, routeGraphicLayer, closestFacilityTask;var map = new Map("map");var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/Test/CloseFacilityTest/MapServer");map.addLayer(layer)closestFacilityTask = new ClosestFacilityTask("http://localhost:6080/arcgis/rest/services/Test/CloseFacilityTest/NAServer/CloseFacility");//臨近設施分析參數var params = new ClosestFacilityParameters();//單位params.impedenceAttribute = "Miles";params.defaultCutoff = 7.0;//是否返回事件信息params.returnIncidents = false;//是否返回路徑params.returnRoutes = true;//路徑是否有參數params.returnDirections = true;//服務點params.facilities = new FeatureSet();//事件點params.incidents = new FeatureSet();//點障礙params.pointBarriers = new FeatureSet();//空間參考params.outSpatialReference = map.SpatialReference;//服務點符號樣式var facilityPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE,20,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([89, 95, 35]), 2),new Color([130, 159, 83, 0.40]));//事件點符號樣式var incidentPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,16,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([89, 95, 35]), 2),new Color([130, 159, 83, 0.40]));//障礙點的符號樣式var barrierSymbol = new SimpleMarkerSymbol();barrierSymbol.style = SimpleMarkerSymbol.STYLE_X;barrierSymbol.setSize(12);barrierSymbol.setColor(new Color("#f1a340"));incidentsGraphicsLayer = new GraphicsLayer();//結果路徑線符號樣式var routePolylineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color("#0078df"),4.0);//定義一個標志//selectPointID=0什么都不做//selectPointID=1是添加服務點//selectPointID=2是添加事件點//selectPointID=3是添加障礙點var selectPointID;//添加服務點$("#server").click(function () {selectPointID = 1;});//添加事件點$("#eventPoint").click(function () {selectPointID = 2;});//添加障礙點$("#barriers").click(function () {selectPointID = 3;});//清除所有障礙、事件、服務點和路徑線on(map, "mouse-down", function (evt) {//通過selectPointID判斷是添加是停靠點還是障礙點switch (selectPointID) {case 0:break;case 1://獲得服務點的坐標var pointServer = evt.mapPoint;var gr = new Graphic(pointServer, facilityPointSymbol);//構建服務點的參數params.facilities.features.push(gr);break;case 2://獲得事件點的坐標var pointEvent = evt.mapPoint;var gr = new Graphic(pointEvent, incidentPointSymbol);//構建事件點的參數params.incidents.features.push(gr);break;case 3://獲得障礙點的坐標var pointBarrier = evt.mapPoint;var gr = new Graphic(pointBarrier, barrierSymbol);//構建障礙點的參數params.pointBarriers.features.push(gr);break;}//如果selectPointID不等于0,將點的坐標在地圖上顯示出來if (selectPointID != 0) {addTextPoint("服務點", pointServer, facilityPointSymbol);addTextPoint("事件點", pointEvent, incidentPointSymbol);addTextPoint("障礙點", pointBarrier, barrierSymbol);}});//文本符號:文本信息,點坐標,符號function addTextPoint(text, point, symbol) {var textSymbol = new TextSymbol(text);textSymbol.setColor(new Color([128, 0, 0]));var graphicText = Graphic(point, textSymbol);var graphicpoint = new Graphic(point, symbol);//用默認的圖層添加map.graphics.add(graphicpoint);map.graphics.add(graphicText);}//分析執行事件$("#analyse").click(function () {selectPointID = 0;//如果服務點或者事件點的個數有一個為0,提示用戶參數輸入不對if (params.facilities.features.length == 0 || params.incidents.features.length == 0) {alert("輸入參數不全,無法分析");return;}//執行路徑分析函數closestFacilityTask.solve(params, showRoute)});//處理路徑分析返回的結果。function showRoute(solveResult) {//路徑分析的結果var routeResults = solveResult.routes;//路徑分析的長度var res = routeResults.length;if (res > 0) {for (var i = 0; i < res; i++) {var graphicroute = routeResults[i];var graphic = graphicroute;graphic.setSymbol(routePolylineSymbol);map.graphics.add(graphic);}}else {alert("沒有返回結果");}}});</script> </body> </html>

六、成果圖

七、總結

在這里我為了省事參數設置的不多,三種分析其實差別不是很大,使用的方式也比較相似,如果說惡心應該是在發布數據之前的構造網絡,錯誤出一堆,奈何我對著不是個很了解,浪費了很多的時間,技術不行還需要很多努力。

?

轉載于:https://www.cnblogs.com/tuboshu/p/10752345.html

總結

以上是生活随笔為你收集整理的ArcGIS API For JS之网络分析(临近设施分析)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。