This sample demonstrates applying custom colors to a
FlareClusterer. In the sample XAML, custom colors are applied via
the FlareClusterer's Background, Foreground, and Gradient
properties.
Download Sample Application
< UserControl x:Class = " ArcGISWPFSDK.SimpleClusterer "
xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "
xmlns:x = " http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:esri = " http://schemas.esri.com/arcgis/client/2009 " >
< Grid x:Name = " LayoutRoot " Background = " White " >
< Grid.Resources >
< esri : SimpleMarkerSymbol x:Key = " MediumMarkerSymbol " Color = " #FF00BB00 " Size = " 12 " Style = " Circle " />
< 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 >
</ Grid.Resources >
< esri : Map x:Name = " MyMap " PropertyChanged = " MyMap_PropertyChanged " WrapAround = " True " >
< esri : ArcGISTiledMapServiceLayer ID = " StreetMapLayer "
Url = " http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer " />
< esri : GraphicsLayer ID = " MyGraphicsLayer " >
< esri : GraphicsLayer.Clusterer >
< esri : FlareClusterer
FlareBackground = " Yellow "
FlareForeground = " #99000000 "
MaximumFlareCount = " 5 " Radius = " 15 "
Gradient = " {StaticResource BlueGradient} " />
</ esri : GraphicsLayer.Clusterer >
</ esri : GraphicsLayer >
</ esri : Map >
</ Grid >
</ UserControl >
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
namespace ArcGISWPFSDK
{
public partial class SimpleClusterer : UserControl
{
public SimpleClusterer()
{
InitializeComponent();
}
void MyMap_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "SpatialReference" )
{
LoadGraphics();
MyMap.PropertyChanged -= MyMap_PropertyChanged;
}
}
private void LoadGraphics()
{
QueryTask queryTask =
new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0" );
queryTask.ExecuteCompleted += queryTask_ExecuteCompleted;
Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.OutSpatialReference = MyMap.SpatialReference;
query.ReturnGeometry = true ;
query.Where = "1=1" ;
queryTask.ExecuteAsync(query);
}
void queryTask_ExecuteCompleted(object sender, QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
if (featureSet == null || featureSet.Features.Count < 1)
{
MessageBox.Show("No features retured from query" );
return ;
}
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer" ] as GraphicsLayer;
foreach (Graphic graphic in featureSet.Features)
{
graphic.Symbol = LayoutRoot.Resources["MediumMarkerSymbol" ] as ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol;
graphicsLayer.Graphics.Add(graphic);
}
}
}
}
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Namespace ArcGISWPFSDK
Partial Public Class SimpleClusterer
Inherits UserControl
Public Sub New ()
InitializeComponent()
End Sub
Private Sub MyMap_PropertyChanged(sender As Object , e As System.ComponentModel.PropertyChangedEventArgs)
If e.PropertyName = "SpatialReference" Then
LoadGraphics()
RemoveHandler MyMap.PropertyChanged, AddressOf MyMap_PropertyChanged
End If
End Sub
Private Sub LoadGraphics()
Dim queryTask As New QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0" )
AddHandler queryTask.ExecuteCompleted, AddressOf queryTask_ExecuteCompleted
Dim query As Query = New ESRI.ArcGIS.Client.Tasks.Query()
query.OutSpatialReference = MyMap.SpatialReference
query.ReturnGeometry = True
query.Where = "1=1"
queryTask.ExecuteAsync(query)
End Sub
Private Sub queryTask_ExecuteCompleted(sender As Object , args As QueryEventArgs)
Dim featureSet As FeatureSet = args.FeatureSet
If featureSet Is Nothing OrElse featureSet.Features.Count < 1 Then
MessageBox.Show("No features retured from query" )
Return
End If
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer" ), GraphicsLayer)
For Each graphic As Graphic In featureSet.Features
graphic.Symbol = TryCast(LayoutRoot.Resources("MediumMarkerSymbol" ), ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol)
graphicsLayer.Graphics.Add(graphic)
Next
End Sub
End Class
End Namespace
5/16/2014