require([
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/layers/GraphicsLayer",
"esri/tasks/RouteTask",
"esri/tasks/support/RouteParameters",
"esri/tasks/support/FeatureSet",
"esri/layers/MapImageLayer",
"esri/layers/TileLayer",
"esri/Basemap",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/TextSymbol",
"esri/widgets/Home"
], function (
Map,
MapView,
Graphic,
GraphicsLayer,
RouteTask,
RouteParameters,
FeatureSet,
MapImageLayer,
TileLayer,
Basemap,
SimpleMarkerSymbol,
TextSymbol,
Home
) {
// Point the URL to a valid route service that uses an
// ArcGIS Online hosted service proxy
var routeTask = new RouteTask({
url:
"https://192.168.1.244:6443/arc ... ot%3B
});
// The stops and route result will be stored in this layer
var routeLayer = new GraphicsLayer();
// Setup the route parameters
var routeParams = new RouteParameters({
stops: new FeatureSet(),
barriers:new FeatureSet(),
returnDirections:false,
returnRoutes:true,
outSpatialReference: {
// autocasts as new SpatialReference()
wkid: 3857
}
});
// Define the symbology used to display the stops
var stopSymbol = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "circle",
color: "blue",
size: 10,
outline: {
// autocasts as new SimpleLineSymbol()
width: 3
}
};
var barriersSymbol = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "x",
color:"red",
size: 10,
outline: {
// autocasts as new SimpleLineSymbol()
width: 4
}
};
var map = new Map({
basemap: "",
layers: [layer,routeLayer] // Add the route layer to the map
});
var view = new MapView({
container: "viewDiv", // Reference to the scene div created in step 5
map: map// Reference to the map object created before the scene
});
var homeBtn = new Home({
view: view
});
view.ui.add(homeBtn, "top-left");
view.scale = 240;
view.center = [115.782939, 33.869338]; // Sets the center point of the view at a specified lon/lat
view.zoom = 15; // Sets
var selectPointID;
//给停靠点按钮添加点击事件
document.getElementById("stop").addEventListener("click",function(){
selectPointID = 1;
});
3 个回复
AriaGIS
赞同来自:
精灵的光轨
赞同来自:
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/layers/GraphicsLayer",
"esri/tasks/RouteTask",
"esri/tasks/support/RouteParameters",
"esri/tasks/support/FeatureSet",
"esri/layers/MapImageLayer",
"esri/layers/TileLayer",
"esri/Basemap",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/TextSymbol",
"esri/widgets/Home"
], function (
Map,
MapView,
Graphic,
GraphicsLayer,
RouteTask,
RouteParameters,
FeatureSet,
MapImageLayer,
TileLayer,
Basemap,
SimpleMarkerSymbol,
TextSymbol,
Home
) {
// Point the URL to a valid route service that uses an
// ArcGIS Online hosted service proxy
var routeTask = new RouteTask({
url:
"https://192.168.1.244:6443/arc ... ot%3B
});
// The stops and route result will be stored in this layer
var routeLayer = new GraphicsLayer();
// Setup the route parameters
var routeParams = new RouteParameters({
stops: new FeatureSet(),
barriers:new FeatureSet(),
returnDirections:false,
returnRoutes:true,
outSpatialReference: {
// autocasts as new SpatialReference()
wkid: 3857
}
});
// Define the symbology used to display the stops
var stopSymbol = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "circle",
color: "blue",
size: 10,
outline: {
// autocasts as new SimpleLineSymbol()
width: 3
}
};
var barriersSymbol = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "x",
color:"red",
size: 10,
outline: {
// autocasts as new SimpleLineSymbol()
width: 4
}
};
var layer=new MapImageLayer({
url:"https:///arcgis/rest/services/ ... ot%3B
});
var map = new Map({
basemap: "",
layers: [layer,routeLayer] // Add the route layer to the map
});
var view = new MapView({
container: "viewDiv", // Reference to the scene div created in step 5
map: map// Reference to the map object created before the scene
});
var homeBtn = new Home({
view: view
});
view.ui.add(homeBtn, "top-left");
view.scale = 240;
view.center = [115.782939, 33.869338]; // Sets the center point of the view at a specified lon/lat
view.zoom = 15; // Sets
var selectPointID;
//给停靠点按钮添加点击事件
document.getElementById("stop").addEventListener("click",function(){
selectPointID = 1;
});
//给障碍点按钮添加点击事件
document.getElementById("barriers").addEventListener("click",function(){
selectPointID = 2;
})
view.on("click", function(event){
//通过selectPointID判断是添加是停靠点还是障碍点
switch (selectPointID) {
case 0:
break;
case 1:
var stop = new Graphic({
geometry: event.mapPoint,
symbol: stopSymbol
});
routeLayer.add(stop);
routeParams.stops.features.push(stop);
break;
case 2:
//获得障碍点的坐标
var barrier=new Graphic({
geometry: event.mapPoint,
symbol: barriersSymbol
});
routeLayer.add(barrier);
// Execute the route task if 2 or more stops are input
routeParams.barriers.features.push(barrier);
break;
}
//如果selectPointID不等于0,将点的坐标在地图上显示出来
if (selectPointID != 0) {
addTextPoint("停靠点", stop, stopSymbol);
addTextPoint("障碍点", barrier, barriersSymbol);
selectPointID = 0;
}
});
function addTextPoint(text,point,symbol) {
var textSymbol = {
type: "text", // autocasts as new TextSymbol()
text: text,
color:[128, 0, 0],
};
var graphicText = new Graphic({
geometry:point,
symbol: textSymbol
});
var graphicpoint = new Graphic({
geometry: point,
symbol: symbol
} );
//用默认的图层添加
view.graphics.add(graphicpoint);
view.graphics.add(graphicText);
};
document.getElementById("analyse").addEventListener("click",function(){
//如果障碍点或者停靠点的个数有一个为0,提示用户参数输入不对
if (routeParams.stops.features.length == 0 || routeParams.barriers.features.length==0)
{
alert("输入参数不全,无法分析");
return;
}
//执行路径分析函数
routeTask.solve(routeParams).then(showRoute)
});
function showRoute(solveResult) {
//路径分析的结果
var routeResults = solveResult.routeResults;
//路径分析的长度
var res = routeResults.length;
//路径的符号
var routeSymbol = {
type: "simple-line", // autocasts as SimpleLineSymbol()
color: [0, 0, 255, 0.5],
width: 5
};
if (res > 0) {
for (var i = 0; i < res; i++) {
var routeResult = routeResults[i].route;
routeResult.symbol=routeSymbol;
routeLayer.add(routeResult);
}
}
else {
alert("没有返回结果");
}
}
});
许丹石
赞同来自:
要回复问题请先登录或注册
发起人
相关问题
问题状态