Original: Using template templates in ArcGIS API for Silverlight code
In the development of the project, you will encounter the spot focus blink effect, but because when using the symbol, will set a certain offsetx and offsety, so when the focus flashes, in some cases, there will be flashing point position and the position of symbol does not overlap phenomenon, The following approach is to solve this problem.
1. Create a new folder template in the Silverlight project and create a new Defaultmarkersymbol.xaml Silverlight resource dictionary file, such as:
2, open the Defaultmarkersymbol.xaml file, delete the contents, copy the following content:
<controltemplate xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http// Schemas.microsoft.com/winfx/2006/xaml "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 " Xmlns:vsm= "Clr-namespace:system.windows;assembly=system.windows" xmlns:esri= "http://schemas.esri.com/arcgis/ client/2009 "> <Canvas> <vsm:VisualStateManager.VisualStateGroups> <vsm:visualst Ategroup x:name= "CommonStates" > <vsm:visualstate x:name= "Normal" > <storyboar D repeatbehavior= "Forever" > <doubleanimation begintime= "00:00:00" Storyboard.targetname= "Elli PSE "storyboard.targetproperty=" (uielement.rendertransform). (Scaletransform.scalex) "from=" 1 "to=" 5 "duration=" 00:00:01 "/> <doubleanimation begintime=" 0 : 0:0 " Storyboard.targetname= "Ellipse" storyboard.targetproperty= "(uielement.rendertransform). (Scaletransform.scaley) " from= "1" to= "5" duration= "00:00:01"/> <doubleanimation begintime= "00:00:00" Storyboard.targ Etname= "Ellipse" storyboard.targetproperty= "(uielement.opacity)" from= "1" to= "0" duration= "00:00:01"/> </Storyboard> </vsm:VisualState> </vsm:VisualStateGroup> </vsm:v isualstatemanager.visualstategroups> <ellipse height= "width=" canvas.left= "0" Canvas.Top= "0" RenderTra Nsformorigin= "0.5,0.5" x:name= "ellipse" ishittestvisible= "False" > <Ellipse.RenderTransform> <scaletransform/> </Ellipse.RenderTransform> <Ellipse.Fill> & Lt radialgradientbrush> <gradientstop color= "#00FF0000"/> <gradientstop Co Lor= "#FFFF0000" offset= "0.25"/> <gradientstop color= "#00FF0000" offset= "0.5"/> <gradientstoP color= "#FFFF0000" offset= "0.75"/> <gradientstop color= "#00FF0000" offset= "1"/> </RadialGradientBrush> </Ellipse.Fill> </Ellipse> <ellipse height= "W" Idth= "canvas.left=" 0 "canvas.top=" 0 "fill=" #FFFF0000 "x:name=" Ellipse1 "/> </canvas></ ControlTemplate >
3. Used in Silverlight program code, here is the focus display by checking the site name in the listbox as follows:
private void Lbsearchsite_selectionchanged (object sender, System.Windows.Controls.SelectionChangedEventArgs e) { Rainfall Findresult = e.addeditems[0] as rainfall; Graphic g = new Graphic () {Geometry = Mercator. Fromgeographic (New MapPoint (double). Parse (FindResult.Latitute.ToString (). Trim ()), double. Parse (FindResult.Longitute.ToString (). Trim ())))}; Markersymbol symbol = new Markersymbol (); String contentstr = new StreamReader (Application.getresourcestream ( New Uri ("/mapclient;component/template/defaultmarkersymbol.xaml", urikind.relative)) . Stream). ReadToEnd (); Symbol. ControlTemplate = (ControlTemplate) xamlreader.load (CONTENTSTR); Symbol. OffsetX = 10; Symbol. OffsetY = 10; G.symbol = Symbol; ESRI. ArcGIS.Client.Geometry.Envelope selectedfeatureextent = MercAtor. Togeographic (G.geometry). Extent; The position of the selected point double expandpercentage = 10; After adding a value, focus (note here to convert the geographic coordinates and Mercator coordinates) Double Widthexpand = (selectedfeatureextent.width + 5) * (Expandpercentage/ 100); Double Heightexpand = (selectedfeatureextent.height + 5) * (EXPANDPERCENTAGE/100); ESRI. ArcGIS.Client.Geometry.Envelope displayextent = new Envelope (Wkidconvert.lonlat2mercator (New MapPoint ( Selectedfeatureextent.xmin-(WIDTHEXPAND/2), Selectedfeatureextent.ymin-(HEIGHTEXPAND/2))), Wkidconvert.lonlat2mercator (New MapPoint (Selectedfeatureextent.xmax + (WIDTHEXPAND/2), Selectedfeatureextent.ymax + (HEIGHTEXPAND/2)))) {spatialreference = new spatialreference (102100)}; try {//Focus mymap.zoomto (displayextent); Showfocus (g); } catch (Exception) {}}//<summary> Show focus point//</summary> public void Showfocus (Graphic g) {Graphicslayer graphics LAYERSW = mymap.layers["graphicslayerred"] as Graphicslayer; Generate Red Glow if (GraphicsLayerSW.Graphics.Count < 1) {GRAPHICSLAYERSW.GRAPHICS.ADD (g) ; } else {graphicsLayerSW.Graphics.RemoveAt (0); GRAPHICSLAYERSW.GRAPHICS.ADD (g); } }
4, as follows:
Using template templates in ArcGIS API for Silverlight code