${iServer2_NetworkModelSetting_Title}

${iServer2_NetworkModelSetting_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);
        }
        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);
        }
        internal static string ToJson(NetworkModelSetting networkModelSetting)
        {
            if (networkModelSetting == null)
            {
                return null;
            }

            string json = "{";

            List<string> list = new List<string>();
            if (!string.IsNullOrEmpty(networkModelSetting.NetworkDatasetName))
            {
                list.Add(string.Format("\"networkDatasetName\":\"{0}\"", networkModelSetting.NetworkDatasetName));
            }

            if (!string.IsNullOrEmpty(networkModelSetting.NetworkDataSourceName))
            {
                list.Add(string.Format("\"networkDataSourceName\":\"{0}\"", networkModelSetting.NetworkDataSourceName));
            }

            list.Add(string.Format("\"tolerance\":\"{0}\"", networkModelSetting.Tolerance));

            if (!string.IsNullOrEmpty(networkModelSetting.NodeIDField))
            {
                list.Add(string.Format("\"nodeIDField\":\"{0}\"", networkModelSetting.NodeIDField));
            }

            if (!string.IsNullOrEmpty(networkModelSetting.EdgeIDField))
            {
                list.Add(string.Format("\"edgeIDField\":\"{0}\"", networkModelSetting.EdgeIDField));
            }

            if (networkModelSetting.WeightFieldInfos != null)
            {
                List<string> infos = new List<string>();
                foreach (WeightFieldInfo info in networkModelSetting.WeightFieldInfos)
                {
                    infos.Add(WeightFieldInfo.ToJson(info));
                }
                list.Add(string.Format("\"weightFieldInfos\":[{0}]", string.Join(",", infos.ToArray())));
            }

            if (!string.IsNullOrEmpty(networkModelSetting.TNodeIDField))
            {
                list.Add(string.Format("\"tNodeIDField\":\"{0}\"", networkModelSetting.TNodeIDField));
            }

            if (!string.IsNullOrEmpty(networkModelSetting.FNodeIDField))
            {
                list.Add(string.Format("\"fNodeIDField\":\"{0}\"", networkModelSetting.FNodeIDField));
            }

            if (!string.IsNullOrEmpty(networkModelSetting.NodeNameField))
            {
                list.Add(string.Format("\"nodeNameField\":\"{0}\"", networkModelSetting.NodeNameField));
            }
            else
            {
                list.Add("\"nodeNameField\":\"\"");
            }

            if (!string.IsNullOrEmpty(networkModelSetting.EdgeNameField))
            {
                list.Add(string.Format("\"edgeNameField\":\"{0}\"", networkModelSetting.EdgeNameField));
            }
            else
            {
                list.Add("\"edgeNameField\":\"\"");
            }

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

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

            if (networkModelSetting.TurnTableSetting != null)
            {
                list.Add(string.Format("\"turnTableSetting\":[{0}]", TurnTableSetting.ToJson(networkModelSetting.TurnTableSetting)));
            }
            else if (networkModelSetting.TurnTableSetting == null)
            {
                list.Add("\"turnTableSetting\":null");
            }

            json += string.Join(",", list.ToArray());
            json += "}";

            return json;
        }