1. General
# Public class sumclusterer: graphicsclusterer {public sumclusterer () {minimumcolor = colors. red; maximumcolor = colors. yellow; symbolscale = 2; base. radius = 100;} Public String aggresponcolumn {Get; set;} public double symbolscale {Get; set;} public color minimumcolor {Get; set;} public color maximumcolor {Get; set;} protected override graphic oncreategraphic (graphiccollection cluster, mappoint point, int maxclustercount) {If (cluster. count = 1) return Cluster [0]; graphic = NULL; double sum = 0; foreach (Graphic g in cluster) {If (G. attributes. containskey (aggresponcolumn) {try {sum + = convert. todouble (G. attributes [aggresponcolumn]);} catch {}} double size = (sum + 450)/30; size = (math. log (sum * symbolscale/10) * 10 + 20); If (size <12) size = 12; graphic = new graphic () {symbol = new clustersymbol () {size = size}, geometry = point}; graphic. attributes. add ("count", sum); graphic. attributes. add ("size", size); graphic. attributes. add ("color", interpolatecolor (size-12,100); Return graphic;} Private Static brush interpolatecolor (double value, double max) {value = (INT) math. round (value * 255.0/max); If (value> 255) value = 255; else if (value <0) value = 0; return New solidcolorbrush (color. fromargb (127,255, (byte) value, 0) ;}} internal class clustersymbol: ESRI. arcGIS. client. symbols. markersymbol {public clustersymbol () {string template = @ "<controltemplate xmlns =" "http://schemas.microsoft.com/client/2007" "xmlns: X = "" http://schemas.microsoft.com/winfx/2006/xaml "> <grid ishittestvisible =" "false" "> <ellipsefill =" "{binding attributes [color]}" "width =" "{binding attributes [size]} "" Height = "" {binding attributes [size]} ""/> <grid horizontalalignment = "" center "" verticalignment = "" center ""> <textblock text = "" {binding attributes [count]} "" fontsize = "" 9 "" margin = "" 1, 1, 99000000 "" fontweight = "" bold "" foreground = "" # ""/> <textblocktext = "" {binding attributes [count]} "" fontsize = "" 9" "margin =" "0, 0, 1, 1 "" fontweight = "" bold "" foreground = "" White ""/> </GRID> </controltemplate> "; this. controltemplate = system. windows. markup. xamlreader. load (Template) as controltemplate;} public double size {Get; set;} public override double offsetx {get {return size/2;} set {Throw new notsupportedexception ();}} public override double offsety {get {return size/2;} set {Throw new notsupportedexception () ;}}# endregion
Void client_getmonitorinfocompleted (Object sender, getmonitorinfocompletedeventargs e) {observablecollection <monitorinfo> List = E. result; ESRI. arcGIS. client. projection. webmercator Mercator = new ESRI. arcGIS. client. projection. webmercator (); graphicslayer = mymap. layers ["mygraphicslayer"] As graphicslayer; // clears graphicslayer of map data each time it is loaded. cleargraphics (); Uri uri = NULL; graphic = NULL; foreach (monitorinfo item in list) {If (! String. isnullorempty (item. latitute. tostring ())&&! String. isnullorempty (item. longitute. tostring () {// when there is a coordinate value, add the monitoring point to the map graphic = new graphic () {geometry = Mercator. fromgeographic (New mappoint (double. parse (item. latitute. tostring (). trim (), double. parse (item. longitute. tostring (). trim (), symbol = layoutroot. resources ["defaultmarkersymbol"] as symbol,}; // manually add attributes to graphic (the association between the required and database tables) graphic. attributes ["ID"] = item. ID; graphic. attributes ["name"] = item. name; graphic. attributes ["areaid"] = item. countyareaid; For (INT I = 0; I <areaid. length; I ++) {If (areaid [I] = item. id. tostring () {Switch (seedlingtype [I]) {Case "1": uri = new uri ("images/red.png", urikind. relative); break; Case "2": uri = new uri ("images/yellow.png", urikind. relative); break; Case "3": uri = new uri ("images/green.png", urikind. relative); break; Case "4": uri = new uri ("images/red.png", urikind. relative); break; default: Break ;}} bitmapimage image = new bitmapimage (URI); // defines the symbol style, including the fill color symbol = new picturemarkersymbol () {offsetx = 8, offsety = 8, source = image}; graphic. symbol = symbol; // Add the graphics to graphicslayer to go to graphicslayer. graphics. add (graphic); // provides the Cluster Aggregation Function graphicslayer for many monitoring sites. clusterer = new sumclusterer () {aggresponcolumn = "areaid", symbolscale = 0.008}; // left-click graphic. mouseleftbuttondown + = new mousebuttoneventhandler (feature_mouseleftbuttondown); graphic. mouseleftbuttonup + = new mousebuttoneventhandler (feature_mouseleftbuttonup); // right-click the menu graphic. mouserightbuttondown + = new mousebuttoneventhandler (feature_mouserightbuttondown); graphic. mouserightbuttonup + = new mousebuttoneventhandler (feature_mouserightbuttonup);} else {// No processing, no vertex information added} // coordinates ESRI. arcGIS. client. geometry. envelope selectedfeatureextent = graphic. geometry. extent; // The Position of the last vertex. Double expandpercentage = 30; double widthexpand = selectedfeatureextent. width * (expandpercentage/100); double heightexpand = selectedfeatureextent. height * (expandpercentage/100); ESRI. arcGIS. client. geometry. envelope displayextent = new ESRI. arcGIS. client. geometry. envelope (selectedfeatureextent. xmin-(widthexpand/2), selectedfeatureextent. ymin-(heightexpand/2), selectedfeatureextent. xmax + (widthexpand/2), selectedfeatureextent. ymax + (heightexpand/2); mymap. zoomto (displayextent );}}