forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_findPathService.html
More file actions
82 lines (80 loc) · 3.15 KB
/
05_findPathService.html
File metadata and controls
82 lines (80 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>网络分析服务-最佳路径分析</title>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/include-leaflet.js"></script>
<script type="text/javascript">
var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
var map, findPathService, findPathParameter,
baseUrl = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
serviceUrl = host + "/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
//最佳路径分析必须按照指定顺序对站点进行访问
map = L.map('map', {
crs: L.CRS.NonEarthCRS({
bounds: L.bounds([48.4, -7668.25], [8958.85, -55.58]),
origin: L.point(48.4, -55.58)
}),
center: [-3600, 5000],
maxZoom: 18,
zoom: 2
});
L.supermap.tiledMapLayer(baseUrl, {noWrap: true})
.addTo(map)
.once("load", function () {
findPathProcess();
});
function findPathProcess() {
//添加站点
var marker1 = L.marker([-3000, 4000]).addTo(map);
marker1.bindPopup("站点一");
var marker2 = L.marker([-2500, 5500]).addTo(map);
marker2.bindPopup("站点二");
var marker3 = L.marker([-4000, 6900]).addTo(map);
marker3.bindPopup("站点三");
//创建最佳路径分析服务实例
findPathService = L.supermap.networkAnalystService(serviceUrl);
//创建最佳路径分析参数实例
var resultSetting = new SuperMap.TransportationAnalystResultSetting({
returnEdgeFeatures: true,
returnEdgeGeometry: true,
returnEdgeIDs: true,
returnNodeFeatures: true,
returnNodeGeometry: true,
returnNodeIDs: true,
returnPathGuides: true,
returnRoutes: true
});
var analystParameter = new SuperMap.TransportationAnalystParameter({
resultSetting: resultSetting,
weightFieldName: "length"
});
findPathParameter = new SuperMap.FindPathParameters({
isAnalyzeById: false,
nodes: [L.latLng(-3000, 4000), L.latLng(-2500, 5500), L.latLng(-4000, 6900)],
hasLeastEdgeCount: false,
parameter: analystParameter
});
var myIcon = L.icon({
iconUrl: "../img/walk.png",
iconSize: [20, 20]
});
//进行查找
findPathService.findPath(findPathParameter, function (serviceResult) {
var result = serviceResult.result;
result.pathList.map(function (result) {
L.polyline(result.route).addTo(map);
L.geoJSON(result.pathGuideItems, {
pointToLayer: function (geoPoints, latlng) {
L.marker(latlng, {icon: myIcon}).addTo(map);
}
}).addTo(map);
})
});
}
</script>
</body>
</html>