private static void AddCountryGeographyToPlot(
            PlotModel newPlot,
            Dictionary <string, int> countryToReadLookUp,
            List <OxyColor> colors,
            Models.Geography.CountryGeography country)
        {
            OxyColor color     = OxyColors.LightGray;
            string   tagString = "";

            if (countryToReadLookUp.ContainsKey(country.Name))
            {
                color     = colors[countryToReadLookUp[country.Name]];
                tagString = "\nBooks Read = " + countryToReadLookUp[country.Name].ToString();
            }

            string trackerFormat = "{0}\nLat/Long ( {4:0.###} ,{2:0.###} )" + tagString;

            OxyPlotUtilities.AddCountryGeographyAreaSeriesToPlot(newPlot, country, color, country.Name, tagString, trackerFormat);
        }
        public static void AddCountryGeographyAreaSeriesToPlot(
            PlotModel newPlot, Models.Geography.CountryGeography country, OxyColor colour, string title, string tag, string trackerFormat)
        {
            int i          = 0;
            var landBlocks = country.LandBlocks.OrderByDescending(b => b.TotalArea);

            foreach (var boundary in landBlocks)
            {
                var areaSeries = new AreaSeries
                {
                    Color          = colour,
                    Title          = title,
                    RenderInLegend = false,
                    Tag            = tag
                };
                var points = boundary.Points;
                if (points.Count > PolygonReducer.MaxPolygonPoints)
                {
                    points = PolygonReducer.AdaptativePolygonReduce(points, PolygonReducer.MaxPolygonPoints);
                }

                foreach (var point in points)
                {
                    double ptX = 0;
                    double ptY = 0;
                    point.GetCoordinates(out ptX, out ptY);

                    DataPoint dataPoint = new DataPoint(ptX, ptY);
                    areaSeries.Points.Add(dataPoint);
                }

                areaSeries.TrackerFormatString = trackerFormat;
                newPlot.Series.Add(areaSeries);

                // just do the 10 biggest bits per country (looks to be enough)
                i++;
                if (i > 10)
                {
                    break;
                }
            }
        }
        private PlotModel SetupWorldCountriesMapPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Countries of the World and Books Read"
            };

            SetupLatitudeAndLongitudeAxes(newPlot);

            // make up a lit of the countries with books read
            int maxBooksRead = -1;
            Dictionary <string, int> countryToReadLookUp = new Dictionary <string, int>();

            foreach (var authorCountry in _mainModel.AuthorCountries)
            {
                maxBooksRead = Math.Max(authorCountry.TotalBooksReadFromCountry, maxBooksRead);
                countryToReadLookUp.Add(authorCountry.Country, authorCountry.TotalBooksReadFromCountry);
            }
            List <OxyColor> colors;
            OxyPalette      faintPalette;

            maxBooksRead =
                OxyPlotUtilities.SetupFaintPaletteForRange(maxBooksRead, out colors, out faintPalette, 128);

            foreach (Models.Database.Nation nation in _mainModel.Nations)
            {
                Models.Geography.CountryGeography country = nation.Geography;
                if (country != null)
                {
                    AddCountryGeographyToPlot(newPlot, countryToReadLookUp, colors, country);
                }
            }

            newPlot.Axes.Add(new LinearColorAxis
            {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Books Read", Maximum = maxBooksRead, Minimum = 0
            });

            // finally update the model with the new plot
            return(newPlot);
        }
        private PlotModel SetupWorldCountriesMapPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Countries of the World"
            };

            SetupLatitudeAndLongitudeAxes(newPlot);

            int flagCount = 0;

            foreach (Models.Database.Nation nation in _mainModel.Nations)
            {
                Models.Geography.CountryGeography country = nation.Geography;
                if (country != null)
                {
                    OxyColor colour        = OxyColors.LightGreen;
                    string   title         = country.Name;
                    string   tag           = "";
                    string   trackerFormat = "{0}";
                    OxyPlotUtilities.AddCountryGeographyAreaSeriesToPlot(newPlot, country, colour, title, tag, trackerFormat);
                }

                if (!string.IsNullOrEmpty(nation.ImageUri) && flagCount < 10)
                {
                    Models.Geography.PolygonPoint capitalCity =
                        new Models.Geography.PolygonPoint(nation.Longitude, nation.Latitude);
                    double x, y;
                    capitalCity.GetCoordinates(out x, out y);

                    try
                    {
                        WebRequest req    = WebRequest.Create(nation.ImageUri);
                        Stream     stream = req.GetResponse().GetResponseStream();
                        var        bitmap = new System.Drawing.Bitmap(stream);

                        MemoryStream memoryStream = new MemoryStream();
                        bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
                        var asBytes = memoryStream.ToArray();

                        var typeOfImage = GetImageFormat(asBytes);

                        if (typeOfImage == ImageFormat.Unknown)
                        {
                            continue;
                        }

                        OxyImage image = new OxyImage(asBytes);
                        newPlot.Annotations.Add(
                            new ImageAnnotation
                        {
                            ImageSource = image,
                            Opacity     = 0.5,

                            X      = new PlotLength(x, PlotLengthUnit.Data),
                            Y      = new PlotLength(y, PlotLengthUnit.Data),
                            Width  = new PlotLength(30, PlotLengthUnit.ScreenUnits),
                            Height = new PlotLength(20, PlotLengthUnit.ScreenUnits),
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment   = VerticalAlignment.Middle
                        });


                        //newPlot.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(x, y), Text = nation.Capital });

                        flagCount++;
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }
            }

            // finally update the model with the new plot
            return(newPlot);
        }