首页 / 浏览问题 / 云GIS / 问题详情
iClient for js
14EXP 2017年05月04日
//最近设施分析 开始 CloFac
        var CloFacVectorLayer, CloFacMarkerLayer1,
        CloFacMarkerLayer2, CloFacDrawPoint, CloFaceEventPoint, n = 0,
        facilityPoints = [
        new SuperMap.Geometry.Point(6000, -5500),
        new SuperMap.Geometry.Point(5500, -2500),
        new SuperMap.Geometry.Point(2500, -3500)],
        CloFacStyle = {
            strokeColor: "#304DBE",
            strokeWidth: 3,
            pointerEvents: "visiblePainted",
            fill: false
        };
        function CloFacInit() {
            CloFacVectorLayer = new SuperMap.Layer.Vector("CloFacVectorLayer");
            CloFacDrawPoint = new SuperMap.Control.DrawFeature(CloFacVectorLayer, SuperMap.Handler.Point);
            CloFacDrawPoint.events.on({ "featureadded": CloFacdrawCompleted });
            map.addControl(CloFacDrawPoint);
          
            
            CloFacMarkerLayer1 = new SuperMap.Layer.Markers("CloFacMarkerLayer1");
            CloFacMarkerLayer2 = new SuperMap.Layer.Markers("CloFacMarkerLayer2");

            var size = new SuperMap.Size(44, 40),
            offset = new SuperMap.Pixel(-(size.w / 2), -size.h),
            icon1 = new SuperMap.Icon("../theme/images/marker-gold.png", size, offset),
            icon2 = new SuperMap.Icon("../theme/images/marker-gold.png", size, offset),
            icon3 = new SuperMap.Icon("../theme/images/marker-gold.png", size, offset);
            CloFacMarkerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(506572.4, 4341566.5), icon1));
            CloFacMarkerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(506812.938, 4340690), icon2));
            CloFacMarkerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(507672.281, 4342141), icon3));
            map.addLayers([CloFacVectorLayer, CloFacMarkerLayer1, CloFacMarkerLayer2]);
        }

        function CloFacSelectEventPoint() {
            CloFacClearElements();
            CloFacDrawPoint.activate();
        }
        function CloFacdrawCompleted(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);
            CloFacMarkerLayer2.addMarker(new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon));
            CloFaceEventPoint = point;
            n++;
            if (n >= 1) {
                CloFacDrawPoint.deactivate();
            }
        }
        function findClosestFacilities() {
            CloFacDrawPoint.deactivate();
            if (!CloFaceEventPoint) {
                alert("请选择事件点!");
                return;
            }
            var findClosestFacilitiesService, parameter, analystParameter, resultSetting;
            resultSetting = new SuperMap.REST.TransportationAnalystResultSetting({
                returnEdgeFeatures: true,
                returnEdgeGeometry: true,
                returnEdgeIDs: true,
                returnNodeFeatures: true,
                returnNodeGeometry: true,
                returnNodeIDs: true,
                returnPathGuides: true,
                returnRoutes: true
            });
            //var edgeWeightNamesSelect = document.getElementById("edgeWeightNames");
           // var weightFieldName = edgeWeightNamesSelect.options[edgeWeightNamesSelect.selectedIndex].text;

            //var turnWeightFieldSelect = document.getElementById("turnNodeWeightNames");
            //var turnNodeWeightNames = turnWeightFieldSelect.options[turnWeightFieldSelect.selectedIndex].text;
            analystParameter = new SuperMap.REST.TransportationAnalystParameter({
                resultSetting: resultSetting
               // turnWeightField: turnNodeWeightNames,
                //weightFieldName: weightFieldName
            });
            parameter = new SuperMap.REST.FindClosestFacilitiesParameters({
                event: CloFaceEventPoint,
                expectFacilityCount: 1,
                isAnalyzeById: false,
                facilities: facilityPoints,
                parameter: analystParameter
            });
            findClosestFacilitiesService = new SuperMap.REST.FindClosestFacilitiesService(url2, {
                eventListeners: { "processCompleted": CloFacprocessCompleted }
            });
            findClosestFacilitiesService.processAsync(parameter);
        }
        function CloFacprocessCompleted(findClosestFacilitiesEventArgs) {
            alert(1);
            var result = findClosestFacilitiesEventArgs.result,
            features = [];
            console.log(result.facilityPathList);//null
            if (result.facilityPathList) {
                alert(result.facilityPathList.length);
                for (var i = 0, facilityPathList = result.facilityPathList, len = facilityPathList.length; i < len; i++) {
                    var feature = new SuperMap.Feature.Vector();
                    feature.geometry = facilityPathList[i].route;
                    feature.style = CloFacStyle;
                    features.push(feature);
                }
            }
            CloFacVectorLayer.addFeatures(features);
        }
        function CloFacClearElements() {
            CloFaceEventPoint = null;
            n = 0;
            CloFacMarkerLayer2.clearMarkers();
            CloFacVectorLayer.removeAllFeatures();
        }
        function CloFacClearAll() {
            map.removeControl(CloFacDrawPoint);
            map.removeLayer(CloFacVectorLayer);
            map.removeLayer(CloFacMarkerLayer1);
            map.removeLayer(CloFacMarkerLayer2);
        }

上面是我的最近设施分析代码,其中在 事件成功回调函数 CloFacprocessCompleted 中的变量result.facilityPathList为null,请问问题可能出现在哪里?

1个回答

您好,如果您想完成最近设施分析的话,一定要去指定一个权重字段和一个转向字段,要不然系统无法判断您的最近设施是哪个点,就会出现返回空值的情况。
1,695EXP 2017年05月04日
谢谢,明白了
...