This is a migrated thread and some comments may be shown as answers.

Clustering help

16 Answers 127 Views
Map
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 25 Sep 2014, 08:05 AM
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!

16 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 26 Sep 2014, 06:27 AM
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.
 
0
James
Top achievements
Rank 1
answered on 26 Sep 2014, 07:58 AM
Thank you very much, it's Friday afternoon here so I'll give this a try next week!
0
James
Top achievements
Rank 1
answered on 02 Oct 2014, 01:43 AM
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.
0
Petar Mladenov
Telerik team
answered on 02 Oct 2014, 07:13 AM
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.
 
0
James
Top achievements
Rank 1
answered on 03 Oct 2014, 06:46 AM
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
0
Petar Mladenov
Telerik team
answered on 03 Oct 2014, 07:32 AM
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.
 
0
James
Top achievements
Rank 1
answered on 07 Oct 2014, 01:06 AM
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
0
Petar Mladenov
Telerik team
answered on 07 Oct 2014, 08:09 AM
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.

 
0
Parker
Top achievements
Rank 1
answered on 14 Oct 2014, 07:00 PM
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
0
Petar Mladenov
Telerik team
answered on 15 Oct 2014, 08:17 AM
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.

 
0
Parker
Top achievements
Rank 1
answered on 16 Oct 2014, 11:08 PM
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”.
0
Petar Mladenov
Telerik team
answered on 17 Oct 2014, 12:05 PM
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.

 
0
Parker
Top achievements
Rank 1
answered on 17 Oct 2014, 04:20 PM
Thanks that worked.  I did add an else.

if (cluster != null && cluster.Children.Count() == 1)
                        {
                            cluster.ClusterState = ClusterState.Expanded;
                        }
                        else
                        {
                            cluster.ClusterState = ClusterState.Collapsed;
                        }
0
vinutha
Top achievements
Rank 1
answered on 05 Dec 2014, 10:58 AM
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
0
Petar Mladenov
Telerik team
answered on 08 Dec 2014, 07:58 AM
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.

 
0
vinutha
Top achievements
Rank 1
answered on 09 Dec 2014, 07:36 AM
HI ,

Thank you so much. It worked.


Regards
Vinutha
Tags
Map
Asked by
James
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
James
Top achievements
Rank 1
Parker
Top achievements
Rank 1
vinutha
Top achievements
Rank 1
Share this question
or