Clustering help

17 posts, 0 answers
  1. James
    James avatar
    6 posts
    Member since:
    Nov 2013

    Posted 25 Sep 2014 Link to this post

    Hey guys,

    I've switched from using the DynamicLayer to the VirtualizationLayer so I can cluster my map icons in an effort to increase performance. I'm currently at the stage with the VirtualizationLayer as I was with the DynamicLayer and am about to tackle the clustering. I've got custom UserControls which I use for map icons and by looking at this example (http://demos.telerik.com/silverlight/#Map/ClusterVirtualization) it seems to only provide an option to async load shape files? I've also noticed the example here which seems more in sync with what I want to achieve. Finally to my question - can the virtualizationlayer cluster my data for me or will I manually have to work out which of my map icons will be hidden in the same group?

    Hope I've made it clear if not I can provide some clarification.

    Thanks guys!
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 26 Sep 2014 Link to this post

    Hi James,

    I guess you mean Visualization Layer and not Virtualization Layer. With it you can use both async readers and manually adding items via code behind or data binding. You can check tha attached clustering sample in which the data is loaded in code behind and no asyn shapes readers are used.

    The Visualization Layer automatically creates clusters depending on the zoom level, the locations of the items and several properties which are described in the Map Clustering Help Article. If you need anything additional / custom behavior, could you please describe it in details, this way we would be better able to advice you ? Thank you in advance for your cooperation.

    Regards,
    Petar Mladenov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
  4. James
    James avatar
    6 posts
    Member since:
    Nov 2013

    Posted 26 Sep 2014 Link to this post

    Thank you very much, it's Friday afternoon here so I'll give this a try next week!
  5. James
    James avatar
    6 posts
    Member since:
    Nov 2013

    Posted 01 Oct 2014 Link to this post

    Thanks that example helped me a lot and it's pretty much working as intended at the moment. One thing additionally that I'd like to fix is after you set the ItemsSource to the map collection if there are any clusteres with only a single item in them they still show the clustered icon with a "1" on it (I've attached a screenshot). This is fixed when you zoom or click on it (it will swap to the actual map icon) but is there any way I can avoid clustering of singular items?

    Thanks.
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 02 Oct 2014 Link to this post

    Hi James,

    It is strange that you experience such issue. What is your telerik assemblies version ? Are you reproducing it with our latest official binaries ? Are you able to reproduce it in the project I sent you here or in the Clustering SDK sample ? We can change this thread to "General Feedback" and you will be able to send us an isolated sample that we can investigate locally if needed.

    Regards,
    Petar Mladenov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  7. James
    James avatar
    6 posts
    Member since:
    Nov 2013

    Posted 03 Oct 2014 in reply to Petar Mladenov Link to this post

    Your example works fine, I can't understand why It's not working for me.

    Name: Telerik.Windows.Controls.DataVisualization
    Version: 2013.2.724.1050
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Oct 2014 Link to this post

    Hello James,

    Your version is old and we have released several official versions after it. Most probably you have hit an issue that is already fixed in our latest official binaries. Is it possible for you to try your project with our latest bits ?

    Regards,
    Petar Mladenov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  9. James
    James avatar
    6 posts
    Member since:
    Nov 2013

    Posted 06 Oct 2014 in reply to Petar Mladenov Link to this post

    Thanks Petar,

    I'll get the new binaries today and try it out. Another thing I was wondering was if there was a way that I can access the cluster data from the visualization layer after a zoom event? What I want to do is color the clusters based on the count property. 

    Regards,

    James
  10. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 07 Oct 2014 Link to this post

    Hello James,

    The ClusterData object which has Count property is actually the DataContext of the Cluster and therefore it is also a DataContext of what you define in the ClusterTemplate. This means that you can bind the Color of the Cluster to the ClusterData with Converter, for example like so:
    <DataTemplate x:Key="ClusterTemplate">
        <Grid x:Name="ParentRoot"
           Width="Auto" Height="{Binding Path=Data.ClusterHeight}"
              telerik:MapLayer.Location="{Binding Path=Center}"
              telerik:MapLayer.HotSpot="0.5,1"
              MouseLeftButtonUp="ClusterMouseClick">
            <Path Fill="{Binding Converter={StaticResource countToBruShConverter}}"
    public class CountToBrushConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              ClusterData cluster = value as ClusterData;
              if (cluster != null)
              {
                  Color color = Color.FromArgb((byte)255, (byte)(100 * cluster.Count % 255), 0, 0);
                  return new SolidColorBrush() { Color = color };
              }
              return null;
          }

    This is implemented in the attached sample as wel..

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  11. Parker
    Parker avatar
    7 posts
    Member since:
    Dec 2013

    Posted 14 Oct 2014 in reply to Petar Mladenov Link to this post

    I am on the most recent version of Telerik controls (2014.2.729) and I'm having the same issue.  Specifically I'm clustering my points on the map and I'm getting clusters of 1.  If I zoom in or out they will reset to the item image that I want.

    How do I make the map stop clustering single items?

    Thanks
  12. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 15 Oct 2014 Link to this post

    Hi Parker,

    We are unable to reproduce such issue as mentioned before. Is it possible for you to open a new support thread with an isolated project attached, which reproduces such issue. This will help us identify it and log it in our bug tracking system. Thank you in advance for your cooperation.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  13. Parker
    Parker avatar
    7 posts
    Member since:
    Dec 2013

    Posted 16 Oct 2014 in reply to Petar Mladenov Link to this post

    Here are the steps to recreate the issue:
    1.  Add a map with a visualization layer with clustering on named “layer”.
    2.  Add a button with this code-behind. 
      
           private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
            {
                var random = new Random();
                var pinpoint = new Ellipse() { Height = 4, Width = 4, Fill = new SolidColorBrush(Colors.Red) };
                var location = new Location(39 + random.NextDouble() , -111 + random.NextDouble() );
                MapLayer.SetLocation(pinpoint, location);
                layer.Items.Add(pinpoint);
            }
    3.  Zoom to the frame of Utah, US
    4.  Click the button multiple times. Eventually, you will get a cluster that says “1”.
  14. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 17 Oct 2014 Link to this post

    Hi Parker,

    Thank you for these details. They helped us reproduce the issue and we logged it as a bug in our feedback portal where you can track its status. We updated your telerik account points as a thanks for your cooperation.
    As a workaround you can try expanding the clusters manually. For example like so:
    this.VisualizationLayer1.Items.Add(pinpoint);
     
               var cluster = this.VisualizationLayer1.GetClusterForItem(pinpoint);
               if (cluster != null && cluster.Children.Count() == 1)
               {
                   cluster.ClusterState = ClusterState.Expanded;
               }
    Let us know if this fits well in your scenario.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  15. Parker
    Parker avatar
    7 posts
    Member since:
    Dec 2013

    Posted 17 Oct 2014 in reply to Petar Mladenov Link to this post

    Thanks that worked.  I did add an else.

    if (cluster != null && cluster.Children.Count() == 1)
                            {
                                cluster.ClusterState = ClusterState.Expanded;
                            }
                            else
                            {
                                cluster.ClusterState = ClusterState.Collapsed;
                            }
  16. vinutha
    vinutha avatar
    11 posts
    Member since:
    Dec 2014

    Posted 05 Dec 2014 in reply to Petar Mladenov Link to this post

    Hi,

      Could please help me to get the Children id the Cluster Item , I want to displaythe list of children when i right click the cluster. 


    Regards Vinutha
  17. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 08 Dec 2014 Link to this post

    Hi Vinutha,

    I extended the solution from this post with code for MouseRightButtonDown on Cluster. 
    private void ClusterRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
          {
              FrameworkElement element = sender as FrameworkElement;
              if (element != null)
              {
                  ClusterData cluster = element.DataContext as ClusterData;
                  if (cluster != null)
                  {
                      var list = cluster.Children.ToList();
                      string res = "";
                      foreach (var item in list)
                      {
                          res += list.IndexOf(item) +" => "  +(item as MyMapItem).Title + "\n\n";
                      }
                      MessageBox.Show(res);
                  }
              }
          }
    Please check it out in the attachment and let me know if this is what you need.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  18. vinutha
    vinutha avatar
    11 posts
    Member since:
    Dec 2014

    Posted 09 Dec 2014 in reply to Petar Mladenov Link to this post

    HI ,

    Thank you so much. It worked.


    Regards
    Vinutha
Back to Top
DevCraft banner