-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy path05_findPathService.html
More file actions
141 lines (134 loc) · 5.64 KB
/
05_findPathService.html
File metadata and controls
141 lines (134 loc) · 5.64 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title data-i18n="resources.title_findPath"></title>
<style>
#toolbar {
position: absolute;
top: 50px;
right: 10px;
text-align: center;
z-index: 1000;
border-radius: 4px;
}
</style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="toolbar" class="panel panel-primary">
<div class='panel-heading'>
<h5 class='panel-title text-center' data-i18n="resources.text_findPath"></h5>
</div>
<div class='panel-body content'>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_sites" onclick="selectPoints()"/>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_submit" onclick="findPathProcess()"/>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearElements(true)"/>
</div>
</div>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" include="leaflet-geoman" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
var host = window.isLocal ? window.server : "https://iserver.supermap.io";
var map, findPathService, findPathParameter, resultLayer, guideLayer, nodeArray = [], markerArray = [],
baseUrl = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
serviceUrl = host + "/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
//最佳路径分析必须按照指定顺序对站点进行访问
map = L.map('map', {
crs: new L.supermap.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
});
new L.supermap.TiledMapLayer(baseUrl, { noWrap: true }).addTo(map);
function selectPoints() {
clearElements(true);
map.pm.enableDraw('Marker', {
tooltips: false,
markerStyle: {
icon: new L.icon({
iconUrl: '../img/marker.png',
iconSize: [44, 30]
})
}
});
map.on('pm:create', function(e) {
if (e.layer) {
var latLng = e.layer.getLatLng();
nodeArray.push(latLng);
markerArray.push(e.layer);
}
});
}
function findPathProcess() {
if (nodeArray.length < 2) {
return widgets.alert.showAlert(resources.msg_check, false);
}
clearElements();
//创建最佳路径分析服务实例
findPathService = new L.supermap.NetworkAnalystService(serviceUrl);
//创建最佳路径分析参数实例
var resultSetting = new L.supermap.TransportationAnalystResultSetting({
returnEdgeFeatures: true,
returnEdgeGeometry: true,
returnEdgeIDs: true,
returnNodeFeatures: true,
returnNodeGeometry: true,
returnNodeIDs: true,
returnPathGuides: true,
returnRoutes: true
});
var analystParameter = new L.supermap.TransportationAnalystParameter({
resultSetting: resultSetting,
weightFieldName: "length"
});
findPathParameter = new L.supermap.FindPathParameters({
isAnalyzeById: false,
nodes: nodeArray,
parameter: analystParameter
});
var myIcon = L.icon({
iconUrl: "../img/walk.png",
iconSize: [20, 20]
});
//进行查找
findPathService.findPath(findPathParameter).then(function (serviceResult) {
var result = serviceResult.result;
result.pathList && result.pathList.map(function (result) {
resultLayer = L.geoJSON(result.route).addTo(map);
guideLayer = L.geoJSON(result.pathGuideItems, {
pointToLayer: function (geoPoints, latlng) {
return L.marker(latlng, { icon: myIcon });
},
filter: function (geoJsonFeature) {
if (geoJsonFeature.geometry && geoJsonFeature.geometry.type === 'Point') {
return true;
}
return false;
}
}).addTo(map);
})
});
}
function clearElements(clearPoint) {
map.pm.disableDraw();
map.off('pm:create');
resultLayer && map.removeLayer(resultLayer);
guideLayer && map.removeLayer(guideLayer);
if (clearPoint) {
markerArray.forEach(function(marker) {
marker.pm.remove();
});
markerArray = [];
nodeArray = [];
}
}
</script>
</body>
</html>