123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title data-i18n="resources.title_findPath"></title>
- <style type="text/css">
- body {
- margin: 0;
- overflow: hidden;
- background: #fff;
- width: 100%;
- height: 100%
- }
- #map {
- position: absolute;
- width: 100%;
- height: 100%;
- }
- #toolbar {
- position: absolute;
- top: 50px;
- right: 10px;
- text-align: center;
- z-index: 100;
- border-radius: 4px;
- }
- </style>
- </head>
- <body>
- <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="findPath()"/>
- <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearElements()"/>
- </div>
- </div>
- <div id="map"></div>
- <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
- <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
- <script>
- var host = window.isLocal ? window.server : "https://iserver.supermap.io";
- var map, layer, vectorLayer, markerLayer,
- drawPoint, select,
- nodeArray = [], pathTime, pathListIndex = 0, routeCompsIndex = 0,
- style = {
- strokeColor: "#304DBE",
- strokeWidth: 3,
- pointerEvents: "visiblePainted",
- fill: false
- },
- styleGuidePoint = {
- pointRadius: 10,
- externalGraphic: "../img/walk.png"
- },
- styleGuideLine = {
- strokeColor: "#25FF25",
- strokeWidth: 6,
- fill: false
- },
- url1 = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
- url2 = host + "/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
- init();
- function init() {
- vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
- drawPoint = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Point);
- select = new SuperMap.Control.SelectFeature(vectorLayer, {
- onSelect: onFeatureSelect,
- onUnselect: onFeatureUnselect
- });
- drawPoint.events.on({"featureadded": drawCompleted});
- map = new SuperMap.Map("map", {
- controls: [
- new SuperMap.Control.Zoom(),
- new SuperMap.Control.Navigation({
- dragPanOptions: {
- enableKinetic: true
- }
- }),
- drawPoint,
- select], units: "m"
- });
- map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
- layer = new SuperMap.Layer.TiledDynamicRESTLayer("Changchun", url1, {
- transparent: true,
- cacheEnabled: true
- }, {maxResolution: "auto"});
- layer.events.on({"layerInitialized": addLayer});
- markerLayer = new SuperMap.Layer.Markers("Markers");
- }
- function addLayer() {
- map.addLayers([layer, vectorLayer, markerLayer]);
- map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 1);
- }
- function selectPoints() {
- widgets.alert.clearAlert();
- clearElements();
- drawPoint.activate();
- }
- function drawCompleted(drawGeometryArgs) {
- var point = drawGeometryArgs.feature.geometry,
- size = new SuperMap.Size(44, 33),
- offset = new SuperMap.Pixel(-(size.w / 2), -size.h),
- icon = new SuperMap.Icon("./images/marker.png", size, offset);
- markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon));
- nodeArray.push(point);
- }
- //选中时显示路径指引信息
- function onFeatureSelect(feature) {
- if (feature.attributes.description) {
- popup = new SuperMap.Popup("chicken",
- feature.geometry.getBounds().getCenterLonLat(),
- new SuperMap.Size(200, 30),
- "<div style='font-size:.8em; opacity: 0.8'>" + feature.attributes.description + "</div>",
- null, false);
- feature.popup = popup;
- map.addPopup(popup);
- }
- if (feature.geometry.CLASS_NAME != "SuperMap.Geometry.Point") {
- feature.style = styleGuideLine;
- vectorLayer.redraw();
- }
- }
- //清除要素时调用此函数
- function onFeatureUnselect(feature) {
- map.removePopup(feature.popup);
- feature.popup.destroy();
- feature.popup = null;
- if (feature.geometry.CLASS_NAME != "SuperMap.Geometry.Point") {
- feature.style = style;
- }
- vectorLayer.redraw();
- }
- function findPath() {
- widgets.alert.clearAlert();
- drawPoint.deactivate();
- var findPathService, parameter, analystParameter, resultSetting;
- resultSetting = new SuperMap.REST.TransportationAnalystResultSetting({
- returnEdgeFeatures: true,
- returnEdgeGeometry: true,
- returnEdgeIDs: true,
- returnNodeFeatures: true,
- returnNodeGeometry: true,
- returnNodeIDs: true,
- returnPathGuides: true,
- returnRoutes: true
- });
- analystParameter = new SuperMap.REST.TransportationAnalystParameter({
- resultSetting: resultSetting,
- weightFieldName: "length"
- });
- parameter = new SuperMap.REST.FindPathParameters({
- isAnalyzeById: false,
- nodes: nodeArray,
- hasLeastEdgeCount: false,
- parameter: analystParameter
- });
- if (nodeArray.length <= 1) {
- widgets.alert.showAlert(resources.msg_findPath,false);
- }
- findPathService = new SuperMap.REST.FindPathService(url2, {
- eventListeners: {"processCompleted": processCompleted}
- });
- findPathService.processAsync(parameter);
- }
- function processCompleted(findPathEventArgs) {
- var result = findPathEventArgs.result;
- allScheme(result);
- }
- function allScheme(result) {
- if (pathListIndex < result.pathList.length) {
- addPath(result);
- } else {
- pathListIndex = 0;
- //线绘制完成后会绘制关于路径指引点的信息
- addPathGuideItems(result);
- }
- }
- //以动画效果显示分析结果
- function addPath(result) {
- if (routeCompsIndex < result.pathList[pathListIndex].route.components[0].components.length) {
- var pathFeature = new SuperMap.Feature.Vector();
- var points = [];
- for (var k = 0; k < 2; k++) {
- if (result.pathList[pathListIndex].route.components[0].components[routeCompsIndex + k]) {
- points.push(new SuperMap.Geometry.Point(result.pathList[pathListIndex].route.components[0].components[routeCompsIndex + k].x, result.pathList[pathListIndex].route.components[0].components[routeCompsIndex + k].y));
- }
- }
- var curLine = new SuperMap.Geometry.LinearRing(points);
- pathFeature.geometry = curLine;
- pathFeature.style = style;
- vectorLayer.addFeatures(pathFeature);
- //每隔0.001毫秒加载一条弧段
- pathTime = setTimeout(function () {
- addPath(result);
- }, 0.001);
- routeCompsIndex++;
- } else {
- clearTimeout(pathTime);
- routeCompsIndex = 0;
- pathListIndex++;
- allScheme(result);
- }
- }
- function addPathGuideItems(result) {
- //vectorLayer.removeAllFeatures();
- //显示每个pathGuideItem和对应的描述信息
- for (var k = 0; k < result.pathList.length; k++) {
- var pathGuideItems = result.pathList[pathListIndex].pathGuideItems, len = pathGuideItems.length;
- for (var m = 0; m < len; m++) {
- if (pathGuideItems[m].geometry.CLASS_NAME !== "SuperMap.Geometry.Point") {
- continue;
- }
- var guideFeature = new SuperMap.Feature.Vector();
- guideFeature.geometry = pathGuideItems[m].geometry;
- guideFeature.attributes = {description: pathGuideItems[m].description};
- guideFeature.style = styleGuidePoint;
- vectorLayer.addFeatures(guideFeature);
- }
- }
- select.activate();
- }
- function clearElements() {
- widgets.alert.clearAlert();
- pathListIndex = 0;
- routeCompsIndex = 0;
- nodeArray = [];
- select.deactivate();
- if (vectorLayer.selectedFeatures.length > 0) {
- map.removePopup(vectorLayer.selectedFeatures[0].popup);
- }
- vectorLayer.removeAllFeatures();
- markerLayer.clearMarkers();
- }
- </script>
- </body>
- </html>
|