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

RadMap Clusterization: can the clustered icon color be set??

2 Answers 90 Views
Map
This is a migrated thread and some comments may be shown as answers.
Entropy69
Top achievements
Rank 1
Veteran
Entropy69 asked on 24 Mar 2020, 02:11 PM

In a RadMap I have several layers with each layer showing a different category of items, each with its own colored icon. 
For each layer I would like to change the color of the round icon containing the number of elements per cluster, is this possible? 
I would have expected a Behavior property on each MapLayer object,

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Mar 2020, 11:08 AM

Hello, Walther,

MapCluster offers a BackColor property that controls what will be the fill color when painting the cluster. However, all clusters created by the MapVisualElementFactory use common visual settings.

The possible solution that I can suggest in order to achieve different cluster color for the clusters belonging to different map layers, is to use a custom strategy. After generating the clusters, you can iterate them and specify their BackColor. Please refer to the following code snippet which result is illustrated in the below screenshot:

        public RadForm1()
        {
            InitializeComponent();

            string cacheFolder = @"..\..\cache";
            OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
            MapTileDownloader tileDownloader = osmProvider.TileDownloader as MapTileDownloader;
            tileDownloader.WebHeaders.Add(System.Net.HttpRequestHeader.UserAgent, "your application name");
            LocalFileCacheProvider cache = new LocalFileCacheProvider(cacheFolder);
            osmProvider.CacheProvider = cache;
            this.radMap1.MapElement.Providers.Add(osmProvider);

            MapLayer layer1 = new MapLayer("CitiesLayer1");
            this.radMap1.Layers.Add(layer1);
            MapLayer layer2 = new MapLayer("CitiesLayer2");
            this.radMap1.Layers.Add(layer2);

            MapPin element = new MapPin(new PointG(40.4467648, -80.01576030));
            element.Text = "Pittsburgh";
            element.BackColor = Color.Red;
            this.radMap1.Layers["CitiesLayer1"].Add(element);
            element = new MapPin(new PointG(40.8130697, -74.07439790));
            element.Text = "New York";
            element.BackColor = Color.Green;
            this.radMap1.Layers["CitiesLayer1"].Add(element);
            element = new MapPin(new PointG(42.3665137, -71.06160420));
            element.Text = "Boston";
            element.BackColor = Color.Blue;
            this.radMap1.Layers["CitiesLayer2"].Add(element);
            element = new MapPin(new PointG(43.6434661, -79.37909890));
            element.Text = "Toronto";
            element.BackColor = Color.Yellow;
            this.radMap1.Layers["CitiesLayer2"].Add(element);

            this.radMap1.Layers[0].ClusterStrategy = new AquaDistanceClusterStrategy();
            this.radMap1.Layers["CitiesLayer1"].ClusterDistance = 200;

            this.radMap1.Layers[1].ClusterStrategy = new RedDistanceClusterStrategy();
            this.radMap1.Layers["CitiesLayer2"].ClusterDistance = 200;
        }

        public class AquaDistanceClusterStrategy : DistanceClusterStrategy
        {
            public override List<MapCluster> GenerateClusters(IEnumerable<IClusterable> items, long distance, IMapViewport viewport)
            {
                List<MapCluster> clusters = base.GenerateClusters(items, distance, viewport);
                foreach (MapCluster c in clusters)
                {
                    c.BackColor = Color.Aqua;
                }
                return clusters;
            }
        }

        public class RedDistanceClusterStrategy : DistanceClusterStrategy
        {
            public override List<MapCluster> GenerateClusters(IEnumerable<IClusterable> items, long distance, IMapViewport viewport)
            {
                List<MapCluster> clusters = base.GenerateClusters(items, distance, viewport);
                foreach (MapCluster c in clusters)
                {
                    c.BackColor = Color.Red;
                }
                return clusters;
            }
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Entropy69
Top achievements
Rank 1
Veteran
answered on 25 Mar 2020, 01:59 PM
Helpful and perfectly clear, thnx for the quick response!
Tags
Map
Asked by
Entropy69
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Entropy69
Top achievements
Rank 1
Veteran
Share this question
or