Solved! Go to Solution.
public class MyFlareClusterer : FlareClusterer { protected override Graphic OnCreateGraphic(GraphicCollection cluster, ESRI.ArcGIS.Client.Geometry.MapPoint point, int maxClusterCount) { if (cluster != null) { if (cluster.Any(g => g.Selected)) { var graphics = new GraphicCollection(cluster.Where(g => g.Selected)); return base.OnCreateGraphic(graphics, point, maxClusterCount); } else { foreach (var g in cluster) return g; } } return null; } }
private void Editor_EditCompleted(object sender, Editor.EditEventArgs e) { if(e.Action == Editor.EditAction.Select) { var l = MyMap.Layers["CensusDemographics"] as FeatureLayer; l.Clusterer.ClusterGraphicsAsync(l.Graphics, MyMap.Resolution); } }
<esri:FeatureLayer.Clusterer> <local:MyFlareClusterer FlareBackground="Yellow" FlareForeground="#99000000" MaximumFlareCount="20" Radius="10" Gradient="{StaticResource BlueGradient}" /> </esri:FeatureLayer.Clusterer>
<LinearGradientBrush x:Key="BlueGradient" MappingMode="RelativeToBoundingBox" > <GradientStop Color="#990011FF" Offset="0"/> <GradientStop Color="#990055FF" Offset="0.25"/> <GradientStop Color="#990099FF" Offset="0.5"/> <GradientStop Color="#9900CCFF" Offset="0.75"/> <GradientStop Color="#9900FFFF" Offset="1"/> </LinearGradientBrush>
public class MyFlareClusterer : FlareClusterer { protected override Graphic OnCreateGraphic(GraphicCollection cluster, ESRI.ArcGIS.Client.Geometry.MapPoint point, int maxClusterCount) { if (cluster != null) { if (cluster.Any(g => g.Selected)) { var graphics = new GraphicCollection(cluster.Where(g => g.Selected)); return base.OnCreateGraphic(graphics, point, maxClusterCount); } else { foreach (var g in cluster) return g; } } return null; } }
private void Editor_EditCompleted(object sender, Editor.EditEventArgs e) { if(e.Action == Editor.EditAction.Select) { var l = MyMap.Layers["CensusDemographics"] as FeatureLayer; l.Clusterer.ClusterGraphicsAsync(l.Graphics, MyMap.Resolution); } }
<esri:FeatureLayer.Clusterer> <local:MyFlareClusterer FlareBackground="Yellow" FlareForeground="#99000000" MaximumFlareCount="20" Radius="10" Gradient="{StaticResource BlueGradient}" /> </esri:FeatureLayer.Clusterer>
<LinearGradientBrush x:Key="BlueGradient" MappingMode="RelativeToBoundingBox" > <GradientStop Color="#990011FF" Offset="0"/> <GradientStop Color="#990055FF" Offset="0.25"/> <GradientStop Color="#990099FF" Offset="0.5"/> <GradientStop Color="#9900CCFF" Offset="0.75"/> <GradientStop Color="#9900FFFF" Offset="1"/> </LinearGradientBrush>
foreach (var g in cluster) return g;
return new Graphic();
You can create your own FlareClusterer and override OnCreateGraphic().
You can try the following code:public class MyFlareClusterer : FlareClusterer { protected override Graphic OnCreateGraphic(GraphicCollection cluster, ESRI.ArcGIS.Client.Geometry.MapPoint point, int maxClusterCount) { if (cluster != null) { if (cluster.Any(g => g.Selected)) { var graphics = new GraphicCollection(cluster.Where(g => g.Selected)); return base.OnCreateGraphic(graphics, point, maxClusterCount); } else { foreach (var g in cluster) return g; } } return null; } }
I'm not sure if you wanted to refresh the cluster when selection is changed, but if you are using Editor. You can trigger clustering by subscribing to EditCompleted event.private void Editor_EditCompleted(object sender, Editor.EditEventArgs e) { if(e.Action == Editor.EditAction.Select) { var l = MyMap.Layers["CensusDemographics"] as FeatureLayer; l.Clusterer.ClusterGraphicsAsync(l.Graphics, MyMap.Resolution); } }
You can look at tweak this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerSelection. Remove the ArcGISDynamicLayer, change FeatureLayer.Mode to OnDemand, remove the "Renderer="{StaticResource YellowMarkerRenderer}"" and add the following:<esri:FeatureLayer.Clusterer> <local:MyFlareClusterer FlareBackground="Yellow" FlareForeground="#99000000" MaximumFlareCount="20" Radius="10" Gradient="{StaticResource BlueGradient}" /> </esri:FeatureLayer.Clusterer>
Under Resources, you can set your gradient.<LinearGradientBrush x:Key="BlueGradient" MappingMode="RelativeToBoundingBox" > <GradientStop Color="#990011FF" Offset="0"/> <GradientStop Color="#990055FF" Offset="0.25"/> <GradientStop Color="#990099FF" Offset="0.5"/> <GradientStop Color="#9900CCFF" Offset="0.75"/> <GradientStop Color="#9900FFFF" Offset="1"/> </LinearGradientBrush>