旅游系统最优路径分析不能实现,有一小段路径能分析

0 投票
<!DOCTYPE>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>旅行商分析</title>
        <script src='../libs/SuperMap.Include.js'></script>
        <script type="text/javascript">
            //            var host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host;
            var local, map, layer, vectorLayer, markerLayer,
            drawPoint, nodeArray = [], pathTime, i = 0, j = 0, result,
            style = {
                strokeColor: "#304DBE",
                strokeWidth: 3,
                pointerEvents: "visiblePainted",
                fill: false
            },
            url1 = "http://localhost:8090/iserver/services/map-China400/rest/maps/tangshan",
            url2 = "http://localhost:8090/iserver/services/transportationAnalyst-China400/rest/networkanalyst/BuildNetwork@China400";
            function init() {
                vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
                drawPoint = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Point);
                drawPoint.events.on({ "featureadded": drawCompleted });
                map = new SuperMap.Map("map", { controls: [
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    }),
                    drawPoint], units: "m"
                });
                layer = new SuperMap.Layer.TiledDynamicRESTLayer("tangshanlayer", url1, { transparent: true, cacheEnabled: true }, { maxResolution: "auto" });
                layer.events.on({ "layerInitialized": addLayer });
                vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
                markerLayer = new SuperMap.Layer.Markers("Markers");
            }

            function addLayer() {
                map.addLayers([layer, vectorLayer, markerLayer]);
                map.setCenter(new SuperMap.LonLat(13207243.52, 4823067.45), 1);
            }
            function selectPoints() {
                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("../theme/images/marker.png", size, offset);
                markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon));
                nodeArray.push(point);
            }
            function findTSPPaths() {
                drawPoint.deactivate();
                var findTSPPathsService, 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.FindTSPPathsParameters({
                    isAnalyzeById: false,
                    nodes: nodeArray,
                    endNodeAssigned: false,
                    parameter: analystParameter
                });
                if (nodeArray.length <= 1) {
                    alert("站点数目有误");
                }
                findTSPPathsService = new SuperMap.REST.FindTSPPathsService(url2, {
                    eventListeners: { "processCompleted": processComplete, "processFailed": processFail }
                });
                findTSPPathsService.processAsync(parameter);
                alert(1111);
            }

            function processComplete(findTSPPathsEventArgs) {
   
                result = findTSPPathsEventArgs.result;
                allScheme(result);
            }
            function processFail(findTSPPathsEventArgs) {
                alert("processFail");
                console.log(findTSPPathsEventArgs);
            }
            function allScheme(result) {
                console.log(result.tspPathList);
                if (i < result.tspPathList.length) {
                    addPath(result);
                } else {
                    i = 0;
                }
            }
            //以动画效果显示分析结果
            function addPath(result) {
                if (j < result.tspPathList[i].route.components[0].components.length) {
                    var pathFeature = new SuperMap.Feature.Vector();
                    var points = [];
                    for (var k = 0; k < 2; k++) {
                        if (result.tspPathList[i].route.components[0].components[j + k]) {
                            points.push(new SuperMap.Geometry.Point(result.tspPathList[i].route.components[0].components[j + k].x, result.tspPathList[i].route.components[0].components[j + k].y));
                        }
                    }
                    var curLine = new SuperMap.Geometry.LinearRing(points);
                    pathFeature.geometry = curLine;
                    pathFeature.style = style;
                    vectorLayer.addFeatures(pathFeature);

                    //每隔0.01毫秒加载一条弧段
                    pathTime = setTimeout(function () { addPath(result); }, 0.01);
                    j++;
                } else {
                    clearTimeout(pathTime);
                    j = 0;
                    i++;
                    allScheme(result);
                }
            }
            function clearElements() {
                nodeArray = [];
                i = 0;
                j = 0;
                markerLayer.clearMarkers();
                vectorLayer.removeAllFeatures();
            }
        </script>
    </head>
    <body onload="init()">
        <div id="toolbar">
            <input type="button" class="btn" value="选择站点" onclick="selectPoints()" />
            <input type="button" class="btn" value="提交" onclick="findTSPPaths()" />
            <input type="button" class="btn" value="清除" onclick="clearElements()" />
        </div>
        <div id="map"></div>
    </body>
</html>
5月 18, 2017 分类:  270次浏览 | 用户: zzzhang 才疏学浅 (11 分)

1个回答

0 投票
你好:

这里你把代码全发出来我们也不能运行调试啊。你也没有给出具体执行到哪里出现异常,我们也不能看到运行结果。

在这里我给你提供一个调试的思路吧。

1、在iDesktop中用同样的参数来执行相同的分析,如果iDesktop中能正常得出结果,那可以排除数据的问题,如果在iDesktop中也不可以,那就要检查网络数据集了。

2、findTSPPathsService.processAsync(parameter);这句代码发送过路径分析的请求之后有没有在function processComplete(findTSPPathsEventArgs) {}中得到返回结果呢?可以在控制台输出findTSPPathsEventArgs看一下。如果返回结果是正常的那说明是后边显示的地方出了问题,仔细检查后边的代码即可,如果这里不能在processComplete中得到结果,那就把参数设置为能在在iDesktop执行成功的参数即可。
5月 19, 2017 用户: 袁子翔 (5 分)
...