${iServer2_NetworkAnalystParam_Title}

${iServer2_NetworkAnalystParam_Description}

        //最近设施查找
        private void FindClosestFacility_Click(object sender, RoutedEventArgs e)
        {
            //设置权重字段列表
            WeightFieldInfo weightFieldInfo = new WeightFieldInfo { Name = "length", TFWeightField = "SmLength", FTWeightField = "SmLength" };
            List<WeightFieldInfo> list = new List<WeightFieldInfo>();
            list.Add(weightFieldInfo);

            //设置网络分析模型
            NetworkModelSetting networkModelSetting = new NetworkModelSetting
            {
                NetworkDatasetName = "RoadNet",
                NetworkDataSourceName = "changchun",
                Tolerance = 30,
                NodeIDField = "SMNODEID",
                EdgeIDField = "SmID",
                WeightFieldInfos = list,
                TNodeIDField = "SMTNODE",
                FNodeIDField = "SMFNODE",

            };

            //设置网络分析参数
            NetworkAnalystParam networkAnalystParam = new NetworkAnalystParam
            {
                Point2Ds = points,
                IsPathsReturn = true,
                WeightName = "length"
            };

            //设置最近设施查找参数
            ProximityParam proximityParam = new ProximityParam
            {
                FacilityCount = 1,
                MaxImpedance = 100000,
                NetworkAnalystParam = networkAnalystParam
            };

            //设置最近设施分析参数
            ClosestFacilityParameters paramters = new ClosestFacilityParameters
            {
                MapName = "Changchun",
                EventPoint = eventp,
                NetworkSetting = networkModelSetting,
                ProximityParam = proximityParam
            };

            //与服务器交换
            ClosestFacilityService service = new ClosestFacilityService("http://localhost:7080/demo");
            service.ProcessAsync(paramters);
            service.Failed += new EventHandler<ServiceFailedEventArgs>(service_Failed);
            service.ProcessCompleted += new EventHandler<NetworkAnalystEventArgs>(service_ProcessCompleted);
        }
        private void PathAnalyst_Click(object sender, RoutedEventArgs e)
        {
            //设置权重字段列表
            WeightFieldInfo weightFieldInfo = new WeightFieldInfo { Name = "length", TFWeightField = "SmLength", FTWeightField = "SmLength" };
            List<WeightFieldInfo> list = new List<WeightFieldInfo>();
            list.Add(weightFieldInfo);

            //设置网络分析模型
            NetworkModelSetting networkModelSetting = new NetworkModelSetting
            {
                NetworkDatasetName = "RoadNet",
                NetworkDataSourceName = "changchun",
                Tolerance = 300,
                NodeIDField = "SMNODEID",
                EdgeIDField = "SmID",
                WeightFieldInfos = list,
                TNodeIDField = "SMTNODE",
                FNodeIDField = "SMFNODE",
            };

            //设置网络分析参数
            NetworkAnalystParam networkAnalystParam = new NetworkAnalystParam
            {
                Point2Ds = points,
                //IsPathsReturn = true,
                WeightName = "length",
            };

            //设置服务区分析子参数
            ServiceAreaParam serviceArea = new ServiceAreaParam
            {
                NetworkAnalystParam = networkAnalystParam,
                Weights = listweights
            };

            //设置服务区分析参数
            ServiceAreaParameters parameters = new ServiceAreaParameters
            {
                MapName = "Changchun",
                NetworkSetting = networkModelSetting,
                ServiceAreaParam = serviceArea
            };

            //与服务器交互
            ServiceAreaService service = new ServiceAreaService("http://localhost:7080/demo");
            service.ProcessAsync(parameters);
            service.Failed += new EventHandler<ServiceFailedEventArgs>(service_Failed);
            service.ProcessCompleted += new EventHandler<ServiceAreaEventArgs>(service_ProcessCompleted);
        }
        internal static string ToJson(NetworkAnalystParam networkAnalystParam)
        {
            if (networkAnalystParam == null)
            {
                return null;
            }
            string json = "{";

            List<string> list = new List<string>();

            if (!string.IsNullOrEmpty(networkAnalystParam.WeightName))
            {
                list.Add(string.Format("\"weightName\":\"{0}\"", networkAnalystParam.WeightName));
            }
            else
            {
                list.Add("\"weightName\":\"\"");
            }

            if (networkAnalystParam.NodeIDs != null && networkAnalystParam.NodeIDs.Count > 0)
            {
                List<string> temp = new List<string>();
                foreach (int id in networkAnalystParam.NodeIDs)
                {
                    temp.Add(id.ToString());
                }
                list.Add(string.Format("\"nodeIDs\":\"{0}\"", string.Join(",", temp.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"nodeIDs\":null"));
            }

            if (networkAnalystParam.Point2Ds != null && networkAnalystParam.Point2Ds.Count > 0)
            {
                List<string> tempPS = new List<string>();
                foreach (Point2D p in networkAnalystParam.Point2Ds)
                {
                    tempPS.Add(JsonHelper.FromPoint2D(p));
                }
                list.Add(string.Format("\"point2Ds\":[{0}]", string.Join(",", tempPS.ToArray())));
            }

            if (networkAnalystParam.BarrierNodes != null && networkAnalystParam.BarrierNodes.Count > 0)
            {
                List<string> tempBD = new List<string>();
                foreach (int bd in networkAnalystParam.BarrierNodes)
                {
                    tempBD.Add(bd.ToString());
                }
                list.Add(string.Format("\"barrierNodes\":[{0}]", string.Join(",", tempBD.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"barrierNodes\":null"));
            }

            if (networkAnalystParam.BarrierEdges != null && networkAnalystParam.BarrierEdges.Count > 0)
            {
                List<string> tempBE = new List<string>();
                foreach (int be in networkAnalystParam.BarrierEdges)
                {
                    tempBE.Add(be.ToString());
                }
                list.Add(string.Format("\"barrierEdges\":[{0}]", string.Join(",", tempBE.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"barrierEdges\":null"));
            }

            if (!string.IsNullOrEmpty(networkAnalystParam.TurnWeightField))
            {
                list.Add(string.Format("\"turnWeightField\":\"{0}\"", networkAnalystParam.TurnWeightField));
            }
            else
            {
                list.Add(string.Format("\"turnWeightField\":\"\""));
            }

            list.Add(string.Format("\"isNodesReturn\":{0}", networkAnalystParam.IsNodesReturn));

            list.Add(string.Format("\"isEdgesReturn\":{0}", networkAnalystParam.IsEdgesReturn));

            list.Add(string.Format("\"isPathGuidesReturn\":{0}", networkAnalystParam.IsPathGuidesReturn));

            list.Add(string.Format("\"isPathsReturn\":{0}", networkAnalystParam.IsPathsReturn));

            list.Add(string.Format("\"isStopsReturn\":{0}", networkAnalystParam.IsStopsReturn));

            json += string.Join(",", list.ToArray());
            json += "}";
            return json;
        }
        private void PathAnalyst_Click(object sender, RoutedEventArgs e)
        {
            TSPPathParam pathParam = new TSPPathParam();

            //设置权重字段列表
            WeightFieldInfo weightFieldInfo = new WeightFieldInfo { Name = "length", TFWeightField = "SmLength", FTWeightField = "SmLength" };
            List<WeightFieldInfo> list = new List<WeightFieldInfo>();
            list.Add(weightFieldInfo);

            //设置网络分析模型
            NetworkModelSetting networkModelSetting = new NetworkModelSetting
            {
                NetworkDatasetName = "RoadNet",
                NetworkDataSourceName = "changchun",
                Tolerance = 300,
                NodeIDField = "SMNODEID",
                EdgeIDField = "SmID",
                WeightFieldInfos = list,
                TNodeIDField = "SMTNODE",
                FNodeIDField = "SMFNODE",
            };

            //设置网络分析参数
            NetworkAnalystParam networkAnalystParam = new NetworkAnalystParam
            {
                Point2Ds = points,
                IsPathsReturn = true,
                WeightName = "length",

            };

            //设置旅行商参数,判断是否指定终点
            if (terminal.IsChecked == true)
            {
                pathParam = new TSPPathParam
                {
                    NetworkAnalystParam = networkAnalystParam,
                    IsEndNodeAssigned = true

                };
            }
            else
            {
                pathParam = new TSPPathParam
                {
                    NetworkAnalystParam = networkAnalystParam,

                };
            }

            //设置旅行商分析参数
            FindTSPPathParameters parameters = new FindTSPPathParameters
            {
                MapName = "Changchun",
                NetworkSetting = networkModelSetting,
                TSPPathParam = pathParam
            };

            //与服务器交换
            FindTSPPathService service = new FindTSPPathService("http://localhost:7080/demo");
            service.ProcessAsync(parameters);
            service.Failed += new EventHandler<ServiceFailedEventArgs>(service_Failed);
            service.ProcessCompleted += new EventHandler<NetworkAnalystEventArgs>(service_ProcessCompleted);
        }