Exemple #1
0
        public void RenderPointMap(DashboardHelper dashboardHelper, string latVar, string longVar, Brush pointColor, string timeVar, SimpleMarkerSymbol.SimpleMarkerStyle style, string description)
        {
            this.dashboardHelper = dashboardHelper;
            this.latVar          = latVar;
            this.longVar         = longVar;
            this.timeVar         = timeVar;
            this.style           = style;
            this.description     = description;
            this.pointColor      = (SolidColorBrush)pointColor;

            GraphicsLayer pointLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer;

            if (pointLayer != null)
            {
                pointLayer.Graphics.Clear();
            }
            else
            {
                pointLayer    = new GraphicsLayer();
                pointLayer.ID = layerId.ToString();
                myMap.Layers.Add(pointLayer);
            }

            CustomCoordinateList coordinateList = GetCoordinates(dashboardHelper, latVar, longVar, timeVar);

            for (int i = 0; i < coordinateList.Coordinates.Count; i++)
            {
                ExtendedGraphic graphic = new ExtendedGraphic()
                {
                    Geometry = new MapPoint(coordinateList.Coordinates[i].X, coordinateList.Coordinates[i].Y, geoReference),
                    RecordId = coordinateList.Coordinates[i].RecordId,
                    Symbol   = MarkerSymbol
                };
                if (coordinateList.Coordinates[i].TimeSpan.HasValue)
                {
                    graphic.TimeExtent = new TimeExtent(coordinateList.Coordinates[i].TimeSpan.Value);
                }
                else
                {
                    graphic.TimeExtent = new TimeExtent(DateTime.MinValue, DateTime.MaxValue);
                }
                graphic.MouseLeftButtonUp += new MouseButtonEventHandler(graphic_MouseLeftButtonUp);
                pointLayer.Graphics.Add(graphic);
            }

            if (LegendStackPanel == null)
            {
                LegendStackPanel = new StackPanel();
            }

            LegendStackPanel.Children.Clear();

            if (string.IsNullOrEmpty(description))
            {
                description = SharedStrings.CASES;
            }

            if (!string.IsNullOrEmpty(description))
            {
                System.Windows.Controls.ListBox legendList = new System.Windows.Controls.ListBox();
                legendList.Padding         = new Thickness(0, 10, 0, 0);
                legendList.Background      = Brushes.White;
                legendList.BorderBrush     = Brushes.Black;
                legendList.BorderThickness = new Thickness(0);
                legendList.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);

                TextBlock classTextBlock = new TextBlock();
                classTextBlock.Text                = description;
                classTextBlock.FontFamily          = new FontFamily("Segoe");
                classTextBlock.FontSize            = 12;
                classTextBlock.MaxWidth            = 256;
                classTextBlock.TextWrapping        = TextWrapping.Wrap;
                classTextBlock.HorizontalAlignment = HorizontalAlignment.Center;
                classTextBlock.VerticalAlignment   = VerticalAlignment.Center;
                classTextBlock.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);

                TextBlock symbolTextBlock = new TextBlock();
                switch (style)
                {
                case SimpleMarkerSymbol.SimpleMarkerStyle.Circle:
                    symbolTextBlock.Text     = "●";
                    symbolTextBlock.FontSize = 16;
                    break;

                case SimpleMarkerSymbol.SimpleMarkerStyle.Cross:
                    symbolTextBlock.Text       = "+";
                    symbolTextBlock.FontSize   = 18;
                    symbolTextBlock.FontWeight = FontWeights.Bold;
                    break;

                case SimpleMarkerSymbol.SimpleMarkerStyle.Diamond:
                    symbolTextBlock.Text     = "♦";
                    symbolTextBlock.FontSize = 17;
                    break;

                case SimpleMarkerSymbol.SimpleMarkerStyle.Square:
                    symbolTextBlock.Text     = "■";
                    symbolTextBlock.FontSize = 16;
                    break;

                case SimpleMarkerSymbol.SimpleMarkerStyle.Triangle:
                    symbolTextBlock.Text     = "▲";
                    symbolTextBlock.FontSize = 16;
                    break;

                default:
                    symbolTextBlock.Text     = "▲";
                    symbolTextBlock.FontSize = 16;
                    break;
                }
                symbolTextBlock.FontSize = 28;

                symbolTextBlock.VerticalAlignment = VerticalAlignment.Top;
                symbolTextBlock.Margin            = new Thickness(0, 4, 7, 4);
                symbolTextBlock.Foreground        = this.pointColor;

                StackPanel classStackPanel = new StackPanel();
                classStackPanel.Margin      = new Thickness(10, 0, 10, 10);
                classStackPanel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                classStackPanel.Children.Add(symbolTextBlock);
                classStackPanel.Children.Add(classTextBlock);

                legendList.Items.Add(classStackPanel);

                LegendStackPanel.Children.Add(legendList);
            }

            if (coordinateList.Coordinates.Count > 0)
            {
                myMap.Extent = new Envelope(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(minX - 0.01, minY - 0.01, geoReference)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(maxX + 0.01, maxY + 0.01, geoReference)));
                if (!string.IsNullOrEmpty(timeVar))
                {
                    if (minTime != null && maxTime != null)
                    {
                        intervalCounts = new List <KeyValuePair <DateTime, int> >();
                        DateTime previousInterval        = DateTime.MinValue;
                        IEnumerable <DateTime> intervals = TimeSlider.CreateTimeStopsByTimeInterval(new TimeExtent(minTime, maxTime), new TimeSpan(1, 0, 0, 0));
                        foreach (DateTime interval in intervals)
                        {
                            int count = pointLayer.Graphics.Count(x => x.TimeExtent.Start <= interval && x.TimeExtent.Start >= previousInterval);
                            intervalCounts.Add(new KeyValuePair <DateTime, int>(interval.Date, count));
                            previousInterval = interval;
                        }
                        if (DateRangeDefined != null)
                        {
                            DateRangeDefined(minTime, maxTime, intervalCounts);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private CustomCoordinateList GetCoordinates(DashboardHelper dashboardHelper, string latVar, string longVar, string timeVar)
        {
            List <string> columnNames = new List <string>();

            if (dashboardHelper.IsUsingEpiProject)
            {
                columnNames.Add("UniqueKey");
            }
            columnNames.Add(latVar);
            if (!columnNames.Exists(delegate(string s) { return(s.Equals(longVar)); }))
            {
                columnNames.Add(longVar);
            }
            if (!string.IsNullOrEmpty(timeVar))
            {
                if (!columnNames.Exists(delegate(string s) { return(s.Equals(timeVar)); }))
                {
                    columnNames.Add(timeVar);
                }
            }
            DataTable data = dashboardHelper.GenerateTable(columnNames);

            minTime = DateTime.MaxValue;
            maxTime = DateTime.MinValue;
            minX    = double.MaxValue;
            maxX    = double.MinValue;
            minY    = double.MaxValue;
            maxY    = double.MinValue;

            CustomCoordinateList coordinateList = new CustomCoordinateList();

            if (data != null)
            {
                foreach (DataRow row in data.Rows)
                {
                    if (row[latVar] != DBNull.Value && row[longVar] != DBNull.Value)
                    {
                        double latitude  = double.Parse(row[latVar].ToString());
                        double longitude = double.Parse(row[longVar].ToString());
                        if (latitude <= 90 && latitude >= -90 && longitude <= 180 && longitude >= -180)
                        {
                            int uniqueKey = 0;
                            if (dashboardHelper.IsUsingEpiProject)
                            {
                                uniqueKey = (int)row["UniqueKey"];
                            }
                            if (string.IsNullOrEmpty(timeVar))
                            {
                                coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, null));
                            }
                            else if (!data.Columns.Contains(timeVar))
                            {
                                coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, null));
                            }
                            else
                            {
                                if (row[timeVar] != DBNull.Value)
                                {
                                    DateTime time = (DateTime)row[timeVar];
                                    minTime = minTime < time ? minTime : time;
                                    maxTime = maxTime > time ? maxTime : time;

                                    coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, time));
                                }
                                else
                                {
                                    coordinateList.Coordinates.Add(new CustomCoordinate(uniqueKey, latitude, longitude, null));
                                }
                            }
                            minY = Math.Min(minY, latitude);
                            maxY = Math.Max(maxY, latitude);
                            minX = Math.Min(minX, longitude);
                            maxX = Math.Max(maxX, longitude);
                        }
                    }
                }
            }
            return(coordinateList);
        }
        public void RenderClusterMap(DashboardHelper dashboardHelper, string latVar, string longVar, Brush clusterColor, string timeVar, string description)
        {
            this.dashboardHelper = dashboardHelper;
            this.latVar          = latVar;
            this.longVar         = longVar;
            this.timeVar         = timeVar;
            this.description     = description;
            this.clusterColor    = (SolidColorBrush)clusterColor;

            GraphicsLayer clusterLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer;

            if (clusterLayer != null)
            {
                clusterLayer.Graphics.Clear();
            }
            else
            {
                clusterLayer    = new GraphicsLayer();
                clusterLayer.ID = layerId.ToString();
                myMap.Layers.Add(clusterLayer);
            }

            CustomCoordinateList coordinateList = GetCoordinates(dashboardHelper, latVar, longVar, timeVar);

            for (int i = 0; i < coordinateList.Coordinates.Count; i++)
            {
                ExtendedGraphic graphic = new ExtendedGraphic()
                {
                    Geometry = new MapPoint(coordinateList.Coordinates[i].X, coordinateList.Coordinates[i].Y, geoReference),
                    RecordId = coordinateList.Coordinates[i].RecordId,
                    Symbol   = MarkerSymbol
                };
                if (coordinateList.Coordinates[i].TimeSpan.HasValue)
                {
                    graphic.TimeExtent = new TimeExtent(coordinateList.Coordinates[i].TimeSpan.Value);
                }
                else
                {
                    graphic.TimeExtent = new TimeExtent(DateTime.MinValue, DateTime.MaxValue);
                }
                graphic.MouseLeftButtonUp += new MouseButtonEventHandler(graphic_MouseLeftButtonUp);
                clusterLayer.Graphics.Add(graphic);
            }
            Brush flareForeground;

            if (System.Drawing.Color.FromArgb(this.clusterColor.Color.A, this.clusterColor.Color.R, this.clusterColor.Color.G, this.clusterColor.Color.B).GetBrightness() > 0.5)
            {
                flareForeground = new SolidColorBrush(Colors.Black);
            }
            else
            {
                flareForeground = new SolidColorBrush(Colors.White);
            }
            FlareClusterer clusterer = new FlareClusterer()
            {
                FlareBackground   = clusterColor,
                FlareForeground   = flareForeground,
                MaximumFlareCount = 10,
                Radius            = 15,
                Gradient          = ClustererGradient
            };

            clusterLayer.Clusterer = clusterer;

            if (LegendStackPanel == null)
            {
                LegendStackPanel = new StackPanel();
            }

            LegendStackPanel.Children.Clear();

            if (string.IsNullOrEmpty(description))
            {
                description = SharedStrings.CASES;
            }

            System.Windows.Controls.ListBox legendList = new System.Windows.Controls.ListBox();
            legendList.Padding         = new Thickness(0, 10, 0, 0);
            legendList.Background      = Brushes.White;
            legendList.BorderBrush     = Brushes.Black;
            legendList.BorderThickness = new Thickness(0);
            legendList.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);

            TextBlock classTextBlock = new TextBlock();

            classTextBlock.Text                = description;
            classTextBlock.FontFamily          = new FontFamily("Segoe");
            classTextBlock.FontSize            = 12;
            classTextBlock.MaxWidth            = 256;
            classTextBlock.TextWrapping        = TextWrapping.Wrap;
            classTextBlock.HorizontalAlignment = HorizontalAlignment.Center;
            classTextBlock.VerticalAlignment   = VerticalAlignment.Center;
            classTextBlock.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);

            Ellipse circle = new Ellipse();

            circle.Width             = 14;
            circle.Height            = 14;
            circle.VerticalAlignment = VerticalAlignment.Top;
            circle.Margin            = new Thickness(0, 4, 7, 4);
            circle.Fill = this.clusterColor;

            StackPanel classStackPanel = new StackPanel();

            classStackPanel.Margin      = new Thickness(10, 0, 10, 10);
            classStackPanel.Orientation = System.Windows.Controls.Orientation.Horizontal;
            classStackPanel.Children.Add(circle);
            classStackPanel.Children.Add(classTextBlock);

            legendList.Items.Add(classStackPanel);

            LegendStackPanel.Children.Add(legendList);


            if (coordinateList.Coordinates.Count > 0)
            {
                myMap.Extent = new Envelope(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(minX - 0.01, minY - 0.01, geoReference)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(maxX + 0.01, maxY + 0.01, geoReference)));
                if (!string.IsNullOrEmpty(timeVar))
                {
                    if (minTime != null && maxTime != null)
                    {
                        intervalCounts = new List <KeyValuePair <DateTime, int> >();
                        DateTime previousInterval        = DateTime.MinValue;
                        IEnumerable <DateTime> intervals = TimeSlider.CreateTimeStopsByTimeInterval(new TimeExtent(minTime, maxTime), new TimeSpan(1, 0, 0, 0));
                        foreach (DateTime interval in intervals)
                        {
                            int count = clusterLayer.Graphics.Count(x => x.TimeExtent.Start <= interval && x.TimeExtent.Start >= previousInterval);
                            intervalCounts.Add(new KeyValuePair <DateTime, int>(interval.Date, count));
                            previousInterval = interval;
                        }
                        if (DateRangeDefined != null)
                        {
                            DateRangeDefined(minTime, maxTime, intervalCounts);
                        }
                    }
                }
            }
        }