コード例 #1
0
        private void buildButton_Click(object sender, EventArgs e)
        {
            UpdateStatus("Working", 0);

            BackgroundWorker bw = new BackgroundWorker
            {
                WorkerReportsProgress = true
            };

            bw.DoWork += delegate(object o, DoWorkEventArgs args)
            {
                Dictionary <BoundaryType, List <Placemark> > features = new Dictionary <BoundaryType, List <Placemark> >();
                int fileCounter = 0;
                foreach (BoundaryType boundaryType in Constants.MapSources.Keys)
                {
                    if (o is BackgroundWorker worker)
                    {
                        worker.ReportProgress(100 * (fileCounter + 1) / Constants.MapSources.Keys.Count, $"Processing {boundaryType}");
                    }

                    fileCounter++;

                    MapBuilder.ApplyRandomColoring(Constants.MapSources[boundaryType], Constants.BinaryColors);

                    features[boundaryType] = KmlHelper.LoadPlacemarksFromKml(Constants.MapSources[boundaryType]);
                    Console.WriteLine($"{boundaryType}: {features[boundaryType].Count} features");

                    //Code to display all feature names
                    //foreach (Feature feature in features[area])
                    //{
                    //    Console.WriteLine(KmlHelper.GetFeatureName(feature));
                    //}
                    //Console.WriteLine();
                }
            };

            bw.ProgressChanged += delegate(object o, ProgressChangedEventArgs args)
            {
                UpdateStatus((string)args.UserState, args.ProgressPercentage);
            };

            bw.RunWorkerCompleted += delegate
            {
                UpdateStatus("Finished", 0);
            };

            bw.RunWorkerAsync();
        }
コード例 #2
0
ファイル: MapBuilder.cs プロジェクト: OrangeAndGreen/MapMaker
        public static void ApplyRandomColoring(string kmlFilename, List <Color> colors)
        {
            KmlFile file = KmlHelper.Load(kmlFilename);

            List <Style> styles = GenerateStyles(colors);

            List <Placemark> placemarks = KmlHelper.LoadPlacemarksFromKml(file);

            foreach (Placemark feature in placemarks)
            {
                ApplyRandomFeatureColoring(feature, colors);
            }

            string outputFilename = kmlFilename.Insert(kmlFilename.LastIndexOf('.'), "_random");

            KmlHelper.WriteNewKml(outputFilename, placemarks, styles);
        }