Ejemplo n.º 1
0
        /// <summary>
        /// A MapLayer that clusters a set of data based on the current map view and zoom level.
        /// This offers increased performance and a better user experience when rendering thousands of pushpins on a map.
        /// </summary>
#if WINDOWS_PHONE_APP
        public ClusteringLayer(MapControl map)
        {
            _map = map;

            _items = new ItemLocationCollection();
            _items.CollectionChanged += () =>
            {
                _allLocations.Clear();

                foreach (var i in _items)
                {
                    _allLocations.Add(i.Location);
                }

                Cluster();
            };

            _allLocations = new List <Geopoint>();

            this.Unloaded += (s, e) =>
            {
                if (_map != null)
                {
                    _map.ZoomLevelChanged -= _map_ViewChangeEnded;
                    _map.CenterChanged    -= _map_ViewChangeEnded;
                    _map.SizeChanged      -= _map_SizeChanged;
                }
            };

            Init();
        }
Ejemplo n.º 2
0
        public ClusteringLayer(Map map)
        {
            _map = map;

            _items = new ItemLocationCollection();
            _items.CollectionChanged += () =>
            {
                _allLocations.Clear();

                foreach (var i in _items)
                {
                    _allLocations.Add(i.Location);
                }

                Cluster();
            };

            _allLocations = new GeoCoordinateCollection();

            this.Unloaded += (s, e) =>
            {
                if (_map != null)
                {
                    _map.ViewChanged -= _map_ViewChangeEnded;
                    _map.SizeChanged -= _map_SizeChanged;
                }
            };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a range of ItemLocation's to the collection.
        /// This is more effienciet that adding item's individually
        /// as the CollectionChanged event will only be fired once.
        /// </summary>
        /// <param name="items"></param>
        public void AddRange(ItemLocationCollection items)
        {
            base.AddRange(items);

            if (CollectionChanged != null)
            {
                CollectionChanged();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Inserts a collection of locations at a specified index.
        /// </summary>
        /// <param name="index">Index to insert items at.</param>
        /// <param name="items">Collection of items to add.</param>
        public void InsertRange(int index, ItemLocationCollection items)
        {
            base.InsertRange(index, items);

            if (CollectionChanged != null)
            {
                CollectionChanged();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets a collection of items for a list of indicies.
        /// </summary>
        /// <param name="index">List of indicies.</param>
        /// <returns>Collection of items.</returns>
        public ItemLocationCollection GetItemsByIndex(List <int> index)
        {
            var items = new ItemLocationCollection();

            foreach (var i in index)
            {
                if (i < this.Count)
                {
                    items.Add(this[i]);
                }
            }

            return(items);
        }
Ejemplo n.º 6
0
        public ClusteringLayer()
        {
            _items = new ItemLocationCollection();
            _items.CollectionChanged += () =>
            {
                _allLocations.Clear();

                foreach (var i in _items)
                {
                    _allLocations.Add(i.Location);
                }

                Cluster();
            };

            _allLocations = new LocationCollection();

            this.Loaded += (s, e) =>
            {
                DependencyObject parent = this;
                while (parent != null && !(parent is Map))
                {
                    parent = VisualTreeHelper.GetParent(parent);

                    if (parent is MapLayer)
                    {
                        _parentLayer = parent as MapLayer;
                    }
                }

                if (parent != null && _parentLayer != null)
                {
                    _map = parent as Map;
                    Init();
                }
            };

            this.Unloaded += (s, e) =>
            {
                if (_map != null)
                {
#if WINDOWS_APP
                    _map.ViewChangeEnded -= _map_ViewChangeEnded;
#elif WPF
                    _map.ViewChangeEnd -= _map_ViewChangeEnded;
#endif
                    _map.SizeChanged -= _map_SizeChanged;
                }
            };
        }