Use Flare Cluster with dynamically created points

3167
5
12-03-2013 11:28 AM
JohnPreston
Occasional Contributor
Hi I have x,y coordiates storred in a database, which i load and create points on a map. There are points that overlap and I was wondering if the flare clusterer worked with points that are dynamically added to the map?

Here is how I add points to the graphics layer...

For Each item In ddsRequests.DataView
                Dim mappointX As Double = Convert.ToDouble(item.XCoordinate)
                Dim mappointY As Double = Convert.ToDouble(item.YCoordinate)
                Dim mappoint As New ESRI.ArcGIS.Client.Geometry.MapPoint
                Dim DefaultMarkerSymbol As New SimpleMarkerSymbol
                Dim clr As New SolidColorBrush
                clr.Color = Color.FromArgb(255, 255, 0, 0)
                clr.Opacity = "0.5"
                DefaultMarkerSymbol.Size = 10
                DefaultMarkerSymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
                DefaultMarkerSymbol.Color = clr
                Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("GraphicsLayer1"), GraphicsLayer)
                mappoint.X = mappointX
                mappoint.Y = mappointY
                Dim IP As New IdentifyParameters With {.Geometry = mappoint, .LayerOption = LayerOption.all, .SpatialReference = MyMap.SpatialReference}
                Dim graphic As New Graphic() With {.Symbol = DefaultMarkerSymbol, .Geometry = mappoint}
                graphicsLayer.Graphics.Add(graphic)
                MyMap.Layers.Add(graphicsLayer)
            Next
        End If

Thank you!
0 Kudos
5 Replies
PietaSwanepoel2
Occasional Contributor
Should be fairly easy to do. Haven't tried it but here is the logic

The map.xml bit for clusterer looks like this:

  
<esri:GraphicsLayer.Clusterer>
    <esri:FlareClusterer>
        <esri:FlareClusterer.Gradient>
     <LinearGradientBrush>
         <GradientStop Color="#7FFFFF00" Offset="0" />
  <GradientStop Color="#7FFF0000" Offset="1" />
     </LinearGradientBrush>
 </esri:FlareClusterer.Gradient>
     </esri:FlareClusterer>
</esri:GraphicsLayer.Clusterer>


To reference it programmatically:
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("GraphicsLayer1"), GraphicsLayer)
graphicsLayer.Cluster.....


Fill in the reset of the code
0 Kudos
JohnPreston
Occasional Contributor
Thanks Peita,

I get an error when using "graphicsLayer.Cluster" Is this the correct format?

John
0 Kudos
PietaSwanepoel2
Occasional Contributor
I used  C# to check that. Noticed you use VB. Assummed the reference to the graphics layer is called "graphicsLayer", similar to your example.
Full reference would be in
ESRI.ArcGIS.Client.Clusterer
ESRI.ArcGIS.Client.GraphicsClusterer
ESRI.ArcGIS.Client.FlareClusterer

Scratched some more in map.xml and found more attributes to set:
  <esri:GraphicsLayer.Clusterer>
   <esri:FlareClusterer Radius="25" MaximumFlareCount="5" FlareBackground="#FF9BBB59" FlareForeground="#FF000000">
    <esri:FlareClusterer.Gradient>
     <LinearGradientBrush>
      <GradientStop Color="#7FFFFF00" Offset="0" />
      <GradientStop Color="#7FFF0000" Offset="1" />
     </LinearGradientBrush>
    </esri:FlareClusterer.Gradient>
   </esri:FlareClusterer>
  </esri:GraphicsLayer.Clusterer>


I haven't tested this or implemented it. Was just a suggestion of how to maybe get there
0 Kudos
JohnPreston
Occasional Contributor
Thanks Pieta, yes you are correct the graphics layer is names "graphicslayer"

I added the references you suggested, but I'm still not sure what to do with "graphicsLayer.Cluster". The error I get says "Cluster is not a member of ArcGIS GraphicsLayer." However, Clusterer is a property do you mean "graphicsLayer.Clusterer"? If so are there other properties to set?

John
0 Kudos
JohnPreston
Occasional Contributor
I got it. I was missing the spatialreference setting

ddsRequests.DataView.MoveCurrentToFirst()
            Dim DefaultMarkerSymbol As New SimpleMarkerSymbol
            Dim clr As New SolidColorBrush
            clr.Color = Color.FromArgb(255, 255, 0, 0)
            clr.Opacity = "0.5"
            DefaultMarkerSymbol.Size = 20
            DefaultMarkerSymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
            DefaultMarkerSymbol.Color = clr
            Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
            For Each item In ddsRequests.DataView
                Dim mappoint As New ESRI.ArcGIS.Client.Geometry.MapPoint
                Dim mappointX As Double = Convert.ToDouble(item.XCoordinate)
                Dim mappointY As Double = Convert.ToDouble(item.YCoordinate)
                mappoint.X = mappointX
                mappoint.Y = mappointY
                mappoint.SpatialReference = New SpatialReference(2926)               
                Dim graphic As New Graphic() With {.Symbol = DefaultMarkerSymbol, .Geometry = mappoint}
                graphic.Geometry.SpatialReference = New SpatialReference(2926)
                graphicsLayer.Graphics.Add(graphic)
            Next
0 Kudos