Beispiel #1
0
 /// <summary>
 /// Adds the pins from the given container
 /// </summary>
 public void Merge(PushpinContainer pinContainer)
 {
     foreach (var pin in pinContainer._pushpins)
     {
         _pushpins.Add(pin);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Re-render the pushpins based on the current zoom level
        /// </summary>
        private void RenderPins()
        {
            List<PushpinContainer> pinsToAdd = new List<PushpinContainer>();

            // consider each pin in turn
            foreach (var pin in _pins)
            {
                var newPinContainer = new PushpinContainer(pin,
                  _map.LocationToViewportPoint(pin.Location), _map);

                bool addNewPin = true;

                // determine how close they are to existing pins
                foreach (var pinContainer in pinsToAdd)
                {
                    double distance = ComputeDistance(pinContainer.ScreenLocation, newPinContainer.ScreenLocation);

                    // if the distance threshold is exceeded, do not add this pin, instead
                    // add it to a cluster
                    if (distance < DistanceThreshold)
                    {
                        pinContainer.Merge(newPinContainer);
                        addNewPin = false;
                        break;
                    }
                }

                if (addNewPin)
                {
                    pinsToAdd.Add(newPinContainer);
                }
            }

            // asynchronously update the map
            _map.Dispatcher.BeginInvoke(() =>
              {
                  _pinLayer.Children.Clear();
                  foreach (var projectedPin in pinsToAdd.Where(pin => PointIsVisibleInMap(pin.ScreenLocation, _map)))
                  {
                      _pinLayer.Children.Add(projectedPin.GetElement(ClusterTemplate));
                  }
              });
        }