分析---ネットワーク分析(近接施設分析)に完全なコードを添付
効果図
本編では最短パス解析と同様のサービスを使用
最短パスとの違い
基本アーキテクチャは最短パスと同じで、ここで直接コードを貼って、詳しくは最短パス分析を参照してください.
完全なコード
本編では最短パス解析と同様のサービスを使用
最短パスとの違い
var closestFacilityTask = new ClosestFacilityTask("http://localhost:6080/arcgis/rest/services/webgis/fzkt_wlfx_all/NAServer/ ");
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;
基本アーキテクチャは最短パスと同じで、ここで直接コードを貼って、詳しくは最短パス分析を参照してください.
完全なコード
<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 Facilitiestitle>
<link rel="stylesheet" href="https://js.arcgis.com/3.28/esri/css/esri.css" />
<script src="https://js.arcgis.com/3.28/">script>
<style type="text/css">
#map {
width: 100%;
height: 600px;
border: 1px solid #000;
}
.MapClass {
width: 100%;
height: 600px;
border: 1px solid #000;
}
style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js">script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.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=" " />
<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 ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/webgis/fzkt_wlfx_all/MapServer");
map.addLayer(layer)
closestFacilityTask = new ClosestFacilityTask("http://localhost:6080/arcgis/rest/services/webgis/fzkt_wlfx_all/NAServer/ ");
//
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
);
var selectPointID;
//
$("#server").click(function () {
selectPointID = 1;
});
//
$("#eventPoint").click(function () {
selectPointID = 2;
});
//
$("#barriers").click(function () {
selectPointID = 3;
});
on(map, "mouse-down", function (evt) {
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;
}
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;
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("NULL");
}
}
});
script>
body>
html>