ArcGIS API for Silverlight程式碼中使用Template模板
在專案開發中,會遇到點選中聚焦閃爍效果,但是因為在使用Symbol的時候,會設定一定的OffSetX和OffSetY,所以聚焦閃爍的時候,有些情況下,會出現閃爍點的位置和Symbol的位置不重疊現象,下面的方法就是解決這個問題的。
1、在Silverlight專案中新建一個資料夾Template,新建一個DefaultMarkerSymbol.xaml的Silverlight資源字典檔案,如下圖:
2、開啟DefaultMarkerSymbol.xaml檔案,刪掉裡面的內容,拷貝如下的內容:
<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:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="Normal">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="ellipse" 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.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)" From="1" To="0" Duration="00:00:01" />
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Ellipse Height="25" Width="25" Canvas.Left="0" Canvas.Top="0" RenderTransformOrigin="0.5,0.5" x:Name="ellipse" IsHitTestVisible="False">
<Ellipse.RenderTransform>
<ScaleTransform />
</Ellipse.RenderTransform>
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="#00FF0000" />
<GradientStop Color="#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="20" Width="20" Canvas.Left="0" Canvas.Top="0" Fill="#FFFF0000" x:Name="ellipse1" />
</Canvas>
</ControlTemplate >
3、Silverlight程式程式碼中使用,這裡是通過選中ListBox中的站點名稱,進行聚焦顯示,方法如下:
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; //選中點的位置
double expandPercentage = 10;
//加數值後,聚焦(這裡需要注意,進行地理座標和墨卡託座標的轉換)
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
{
//聚焦
myMap.ZoomTo(displayExtent);
ShowFocus(g);
}
catch (Exception)
{
}
}
/// <summary>
/// 顯示聚焦點
/// </summary>
public void ShowFocus(Graphic g)
{
GraphicsLayer graphicsLayerSW = myMap.Layers["GraphicsLayerRed"] as GraphicsLayer;
//產生紅色光暈
if (graphicsLayerSW.Graphics.Count < 1)
{
graphicsLayerSW.Graphics.Add(g);
}
else
{
graphicsLayerSW.Graphics.RemoveAt(0);
graphicsLayerSW.Graphics.Add(g);
}
}
相關文章
- c++ 模板模板引數("Template Template Parameters")C++
- Go HTML/template 模板使用方法GoHTML
- TeamTopologies/Team-API-template:用於定義團隊拓撲中團隊API 的模板API
- 模板方法模式(Template)模式
- Python:Template模板字串Python字串
- AS 使用 Flutter 程式碼模板Flutter
- ajax配合art-template模板引擎的使用
- c++11-17 模板核心知識(十二)—— 模板的模板引數 Template Template ParametersC++
- c++11-17 模板核心知識(十四)—— 解析模板之依賴型模板名稱 Dependent Names of Templates(.template/->template/::template)C++
- C++開發:template,模板C++
- WPF 資料模板Data Template
- 使用IntelliJ IDEA中的Live Templates自定義程式碼模板IntelliJIdea
- 修改帝國cms手機端模板位於 /e/api/template/phone 目錄API
- 小程式 template 模版使用方法
- ArcGis api配合vue開發入門系列(一)引入arcgis api以及載入地圖APIVue地圖
- PbootCms模板中如何寫 PHP 程式碼?bootPHP
- 使用C# (.NET Core) 實現模板方法模式 (Template Method Pattern)C#模式
- ES6, Angular,React和ABAP中的String Template(字串模板)AngularReact字串
- 傳單模板:Flyer Design - Flyer Template for Indeisgn
- go 模板(template)的常用基本語法Go
- OpenFaaS實戰之四:模板操作(template)
- PbootCms模板中怎麼寫PHP程式碼bootPHP
- PbootCMS 模板中怎麼寫PHP程式碼bootPHP
- Mubelotix/wasm-extension-template:一個易於使用的Rust Web模板ASMRustWeb
- WPF中如何使用後臺程式碼動態建立資料模板(DataTemplate)
- ABAP,Java,JavaScript裡的字串模板String TemplateJavaScript字串
- 【ES6基礎】模板字串(Template String)字串
- go template使用Go
- 在 PBootCMS 中,使用 {php} 和 {eval} 標籤可以在模板中執行 PHP 程式碼bootPHP
- js模板引擎art template陣列渲染的方法JS陣列
- C#設計模式-模板方法模式(Template Method)C#設計模式
- 小程式模板的使用
- [Vue原始碼]一起來學Vue模板編譯原理(一)-Template生成ASTVue原始碼編譯原理AST
- 程式碼模板 | 我的程式碼沒有else
- 自定義AndroidStudio程式碼模板Android
- qt程式建立及模板程式碼分析QT
- Silverlight實用竅門系列:4.Silverlight 4.0新增滑鼠右鍵選單和Silverlight全屏模式的進入退出。【附帶原始碼例項】...模式原始碼
- ArcGis API JS 4.X本地化部署與地圖的基礎使用APIJS地圖
- arcgis api for js回撥函式如何等待同步APIJS函式