Esempio n. 1
0
        public static Cluster Initialize(ISupportCoordLocation item)
        {
            List <ISupportCoordLocation> items = new List <ISupportCoordLocation>();

            items.Add(item);
            return(new Cluster(items));
        }
        MapVectorItemCollection ClusterizeImpl(MapVectorItemCollection sourceItems)
        {
            // Separate localizable and non localizable items.
            List <MapItem> nonLocalizableItems = new List <MapItem>();
            List <Cluster> clusters            = new List <Cluster>();

            foreach (MapItem item in sourceItems)
            {
                ISupportCoordLocation localizableItem = item as ISupportCoordLocation;
                if (localizableItem != null)
                {
                    clusters.Add(Cluster.Initialize(localizableItem));
                }
                else
                {
                    nonLocalizableItems.Add(item);
                }
            }

            // Arrange initial clusters in increasing order of distance to a closest cluster.
            clusters = Arrange(clusters);

            // Aggregate localizable items.
            while (clusters.Count > ClusterCount)
            {
                MergeCloserstClusters(ref clusters);
            }

            // Convert internal cluster helpers to Map items.
            MapVectorItemCollection clusterRepresentatives = CreateItemsCollection();

            for (int i = 0; i < clusters.Count; ++i)
            {
                Cluster cluster        = clusters[i];
                MapDot  representative = new MapDot()
                {
                    Location = new GeoPoint(cluster.CenterPoint.Y, cluster.CenterPoint.X), Size = 100
                };
                for (int j = 0; j < cluster.Items.Count; ++j)
                {
                    representative.ClusteredItems.Add(cluster.Items[j] as MapItem);
                }
                clusterRepresentatives.Add(representative);
            }
            for (int i = 0; i < nonLocalizableItems.Count; ++i)
            {
                clusterRepresentatives.Add(nonLocalizableItems[i]);
            }
            return(clusterRepresentatives);
        }
Esempio n. 3
0
        MapItemCollection ClusterizeImpl(IEnumerable <MapItem> sourceItems)
        {
            // Separate localizable and non localizable items.
            List <MapItem> nonLocalizableItems = new List <MapItem>();
            List <Cluster> clusters            = new List <Cluster>();

            foreach (MapItem item in sourceItems)
            {
                ISupportCoordLocation localizableItem = item as ISupportCoordLocation;
                if (localizableItem != null)
                {
                    clusters.Add(Cluster.Initialize(localizableItem));
                }
                else
                {
                    nonLocalizableItems.Add(item);
                }
            }

            // Arrange initial clusters in increasing order of distance to a closest cluster.
            clusters = Arrange(clusters);

            // Aggregate localizable items.
            while (clusters.Count > ClusterCount)
            {
                MergeCloserstClusters(ref clusters);
            }

            // Convert internal cluster helpers to Map items.
            MapItemCollection clusterRepresentatives = new MapItemCollection(owner);

            for (int i = 0; i < clusters.Count; ++i)
            {
                Cluster cluster        = clusters[i];
                MapDot  representative = new MapDot()
                {
                    Location = new GeoPoint(cluster.CenterPoint.Y, cluster.CenterPoint.X), Size = 100
                };
                representative.ClusteredItems       = cluster.Items.Select(item => item as MapItem).ToList();
                representative.TitleOptions.Pattern = representative.ClusteredItems.Count.ToString();
                clusterRepresentatives.Add(representative);
            }
            clusterRepresentatives.AddRange(nonLocalizableItems);
            return(clusterRepresentatives);
        }