首页 / 浏览问题 / 云GIS / 问题详情
如何获取classic示例代码中的旅行商分析的线路
617
12EXP 2019年06月13日
var curLine;
        //var pathFeature = new SuperMap.Feature.Vector();
        //以动画效果显示分析结果
        function addPath(result2) {
            if (j < result2.tspPathList[i].route.components[0].components.length) {
                
                var points = [];
                for (var k = 0; k < 2; k++) {
                    if (result2.tspPathList[i].route.components[0].components[j + k]) {
                        points.push(new SuperMap.Geometry.Point(result2.tspPathList[i].route.components[0].components[j + k].x, result2.tspPathList[i].route.components[0].components[j + k].y));
                    }
                }
                var pathFeature = new SuperMap.Feature.Vector();
                curLine = new SuperMap.Geometry.LinearRing(points);
                pathFeature.geometry = curLine;  //curline 是geometry
                //line = curLine;
                pathFeature.style = style;
                vectorLayer.addFeatures(pathFeature);//pathFeature是巡逻路径
                //每隔0.01毫秒加载一条弧段
                pathTime = setTimeout(function () {
                    addPath(result2);
                }, 0.03 );
                j++;
            } else {
                clearTimeout(pathTime);
                j = 0;
                i++;
                allScheme(result2);
            }

//添加
    function addXLFeature() {
            if (!curLine) {
	            widgets.alert.showAlert("请先选择路径",true);
	            return;
	        }
            
            curLine.id = "100000";
            var editFeatureParameter,
              editFeatureService,
              features = {
                  fieldNames: [],
                  fieldValues: [],
                  geometry: curLine
              };
            editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
                features: [features],
                editType: SuperMap.REST.EditType.ADD,
                returnContent: false
            });
            editFeatureService = new SuperMap.REST.EditFeaturesService(url3, {
                eventListeners: {
                    "processCompleted": addXLFeaturesProcessCompleted,
                    "processFailed": processFailed
                }
            });
            editFeatureService.processAsync(editFeatureParameter);
        
        }

(我想要获取到旅行商分析结果的线路,并通过添加地物,把线路数据添加到地图中,可是添进去的总是一个点数据,下边是我的代码

1个回答

把这个function也传上来看一下     addXLFeaturesProcessCompleted
5,668EXP 2019年06月13日
       function addXLFeaturesProcessCompleted(editFeaturesEventArgs) {
            
            var addResultIds = editFeaturesEventArgs.result.IDs,
                resourceInfo = editFeaturesEventArgs.result.resourceInfo;
            if (addResultIds === null && resourceInfo === null) return;
            if ((addResultIds && addResultIds.length > 0) || (resourceInfo && 
                  resourceInfo.succeed)) {
                //widgets.alert.showAlert("新增线路成功",true,240);
                selectline();
                //重新加载图层
            } else {
                widgets.alert.showAlert("新增线路失败",false,240);
            }
        }
    
        //选择新添加的路线
        function selectline(){
            var queryParam, queryBySQLParams, queryBySQLService;
            queryParam = new SuperMap.REST.FilterParameter({
                name: "巡逻记录@XY",
                attributeFilter: "Name is NULL" //新添加进去的线属性值为空
            });
            queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
                queryParams: [queryParam]
            });
            queryBySQLService = new SuperMap.REST.QueryBySQLService(url1, {
                eventListeners: { "processCompleted": addpopup, "processFailed": processFailed }
            });
            queryBySQLService.processAsync(queryBySQLParams);
        }

        //添加属性信息
        var infowin = null;
        var myXLID;
        function addpopup(queryEventArgs){  
            var i, j, feature;
            result = queryEventArgs.result;
            features=[];
            if (result && result.recordsets) {
                for (i = 0; i < result.recordsets.length; i++) {
                    if (result.recordsets[i].features) {
                        for (j = 0; j < result.recordsets[i].features.length; j++) {
                            feature = result.recordsets[i].features[j];}
                    }
                }
            }

            myXLID=feature.fid;
            console.log(myXLID);
            var contentHTML="<div id='info' style='font-size:.8em; opacity:0.8; overflow-y:hidden; width:250px'>"+
            "<span style='font-weight:bold; font-size:18px; color:black'>巡逻记录</span><br>";
            contentHTML +="<span style='font-weight:bold; color:black'>"+"姓名:"+"</span>"
            contentHTML +="<input class='form-control' id='txtXLNAME' placeholder='请输入保安姓名'/><br>";
            contentHTML +="<span style='font-weight:bold; color:black'>"+"时间:"+"</span>"
            contentHTML +="<input class='form-control' name='txtDate1' type='text' placeholder='请输入巡逻时间' id='txtDate' onclick=\"SetDate(this,'yyyy/MM/dd hh:mm:ss')\" readonly='readonly' /> <br>";
            contentHTML +="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' class='btn btn-default' value='保存' onclick='UpdateXL()'/><br>";
            contentHTML +="</div>";
            var popup=new SuperMap.Popup.FramedCloud("chicken",
            //new SuperMap.LonLat(507581, 4342020),
            feature.geometry.getBounds().getCenterLonLat(),//这里拿到的feature没有问题
            null,
            contentHTML,
            null,
            true,
            null,
            true
            );
            infowin = popup;
            map.addPopup(popup);
        }

我的思路是,获取到线路结果,然后保存进地图,这样保存的话,属性值为空,保存完成后将这条路线查询出来,弹出弹框,添加属性信息,,可是我查询出来的只有一个点

...