123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_findMTSPPathsServiceLogistics"></title>
- <script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
- <div id="map" style="width: 100%;height:100%"></div>
- <script type="text/javascript">
- var map, options,
- baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
- serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
- var extent = [48.4, -7668.25, 8958.85, -55.58];
- var projection = new ol.proj.Projection({
- code:'',
- extent: extent,
- units: 'm'
- });
- new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
- var mapJSONObj = serviceResult.result;
- map = new ol.Map({
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}})
- .extend([new ol.supermap.control.Logo()]),
- view: new ol.View({
- center: [5000, -3700],
- zoom: 2,
- projection: projection,
- multiWorld: true
- })
- });
- options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest(options)
- });
- map.addLayer(layer);
- findMTSPPathsProcess();
- });
- function findMTSPPathsProcess() {
- //添加配送点
- var facilityPoint1 = new ol.geom.Point([6000, -5500]);
- var facilityPoint2 = new ol.geom.Point([5500, -2500]);
- var facilityPoint3 = new ol.geom.Point([2500, -3500]);
- var facilityFeature1 = new ol.Feature(facilityPoint1);
- var facilityFeature2 = new ol.Feature(facilityPoint2);
- var facilityFeature3 = new ol.Feature(facilityPoint3);
- var iconStyle_facility = new ol.style.Style({
- image: new ol.style.Icon(({
- src: '../img/marker-gold.png'
- }))
- });
- facilityFeature1.setStyle(iconStyle_facility);
- facilityFeature2.setStyle(iconStyle_facility);
- facilityFeature3.setStyle(iconStyle_facility);
- var facilitySource = new ol.source.Vector({
- features: [facilityFeature1, facilityFeature2, facilityFeature3]
- });
- var facilityLayer = new ol.layer.Vector({
- source: facilitySource
- });
- //添加配送目的地
- var destPoint1 = new ol.geom.Point([5000, -5000]);
- var destPoint2 = new ol.geom.Point([6500, -3200]);
- var destFeature1 = new ol.Feature(destPoint1);
- var destFeature2 = new ol.Feature(destPoint2);
- var iconStyle_dest = new ol.style.Style({
- image: new ol.style.Icon(({
- src: '../img/marker.png'
- }))
- });
- destFeature1.setStyle(iconStyle_dest);
- destFeature2.setStyle(iconStyle_dest);
- var destSource = new ol.source.Vector({
- features: [destFeature1, destFeature2]
- });
- var destLayer = new ol.layer.Vector({
- source: destSource
- });
- //创建多旅行商分析参数实例
- 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" //"length"或者"time"
- });
- var findMTSPPathsParameter = new SuperMap.FindMTSPPathsParameters({
- centers: [new ol.geom.Point([6000, -5500]), new ol.geom.Point([5500, -2500]), new ol.geom.Point([2500, -3500])],
- isAnalyzeById: false,
- nodes: [new ol.geom.Point([5000, -5000]), new ol.geom.Point([6500, -3200])],
- hasLeastTotalCost: true,
- parameter: analystParameter
- });
- //进行查找
- new ol.supermap.NetworkAnalystService(serviceUrl).findMTSPPaths(findMTSPPathsParameter, function (serviceResult) {
- serviceResult.result.pathList.map(function (result) {
- var vectorSource = new ol.source.Vector({
- features: (new ol.format.GeoJSON()).readFeatures(result.route)
- });
- var pathLayer = new ol.layer.Vector({
- source: vectorSource,
- style: new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: 'rgba(100, 100, 225, 10)',
- width: 3
- }),
- fill: new ol.style.Fill({
- color: 'rgba(0, 0, 255, 0.1)'
- })
- })
- });
- map.addLayer(pathLayer);
- });
- map.addLayer(facilityLayer);
- map.addLayer(destLayer);
- });
- }
- </script>
- </body>
- </html>
|