using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;

namespace EsriMapSamples
{
    [System.ComponentModel.Description("When rendering a large number of points in a map, symbols frequently overlap making it difficult to distinguish between points. Clustering solves this issue by grouping points within a given cluster distance together.")]
    public partial class Clustering : UserControl
    {
        private FlareClusterer _flareClusterer;

        public Clustering()
        {
            InitializeComponent();

            //create cluster object
            _flareClusterer = new FlareClusterer();
            _flareClusterer.MaximumFlareCount = 9;
            _flareClusterer.FlareBackground = new SolidColorBrush(Color.FromArgb(153, 255, 0, 0));
            _flareClusterer.FlareForeground = new SolidColorBrush(Colors.White);
        }

        private void checkClustering_Checked(object sender, RoutedEventArgs e)
        {
            ToggleClustering();
        }

        private void checkClustering_Unchecked(object sender, RoutedEventArgs e)
        {
            ToggleClustering();
        }

        private void ToggleClustering()
        {
            if (map1 != null)
            {
                FeatureLayer featureLayer = map1.Layers["FeatureLayer1"] as FeatureLayer;
                if (featureLayer != null)
                {
                    if ((bool)checkClustering.IsChecked)
                    {
                        featureLayer.Clusterer = _flareClusterer;
                    }
                    else
                    {
                        featureLayer.Clusterer = null;
                    }
                }
            }
        }
    }
}
