ArcGIS API for Silverlight 滑鼠移入移出地圖要素彈出視窗(優化處理)
在之前部落格裡的ArcGIS API for Silverlight 彈出框例項中,是通過點選地圖要素,彈出框,但是由於沒有控制元素個數,只是通過顯示隱藏來進行的話,在滑鼠移入和移出操作中,會出現滑鼠移入的時候,總不能立刻彈出框,而是需要多次才行,使用者體驗較差,現在通過控制加入一個彈出框,移出時去除剛加入的彈出框,嚴格控制彈出框個數來實現。
核心程式碼如下:
//滑鼠移入事件
graphic.MouseEnter += new MouseEventHandler(swz_graphic_MouseEnter);
graphic.MouseLeave += new MouseEventHandler(swz_graphic_MouseLeave);
void swz_graphic_MouseEnter(object sender, MouseEventArgs e)
{
Point p = e.GetPosition(LayoutRoot);
p.X = p.X - 40;
p.Y = p.Y - 165;
//滑鼠左鍵,顯示ToolTip資訊
Graphic g = sender as Graphic;
tip_Base.g_TipSW_LeftBottom = new TipSW_LeftBottom(this, p, g.Attributes["SWZMC"].ToString(), g.Attributes["SWZBM"].ToString());
}
void swz_graphic_MouseLeave(object sender, MouseEventArgs e)
{
tip_Base.g_TipSW_LeftBottom.closeWindow(this);
}
public partial class TipSW_LeftBottom : UserControl
{
MainPage mp;
string l_name;
string l_swzbm;
public TipSW_LeftBottom()
{
InitializeComponent();
}
public TipSW_LeftBottom(MainPage mp, Point p, string name, string swzbm)
{
InitializeComponent();
this.mp = mp;
this.l_name = name;
this.l_swzbm = swzbm;
//處理標題的間距問題
string tmp = name;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < tmp.Length; i++)
{
sb.Append(tmp[i] + " ");
}
this.title.Content = sb.ToString();
//繫結洪水預報的資料
getDataSoapClient client = new getDataSoapClient();
client.getHSYBInfoCompleted += new EventHandler<getHSYBInfoCompletedEventArgs>(client_getHSYBInfoCompleted);
client.getHSYBInfoAsync(name.Trim());
getXQYJInfoSoapClient client2 = new getXQYJInfoSoapClient();
client2.GetAllSWZCompleted += new EventHandler<GetAllSWZCompletedEventArgs>(client_GetAllSWZCompleted);
client2.GetAllSWZAsync();
this.Margin = new Thickness(p.X, p.Y, 0, 0);
mp.LayoutRoot.Children.Add(this);
}
#region 通用方法,只需要更改Show,在例項化窗體的時候,傳入不同的引數即可
private Point _location;
private bool _isShowing;
private Popup _popup;
private Grid _grid;
private Canvas _canvas;
private FrameworkElement _content;
//初始化並顯示彈出窗體.公共方法在顯示選單項時呼叫
public void Show(Point location, string name,string swzbm)
{
this.l_name = name;
this.l_swzbm = swzbm;
if (_isShowing)
throw new InvalidOperationException();
_isShowing = true;
_location = location;
ConstructPopup(this);
_popup.IsOpen = true;
//處理標題的間距問題
string tmp = name;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < tmp.Length; i++)
{
sb.Append(tmp[i] + " ");
}
this.title.Content = sb.ToString();
//繫結洪水預報的資料
getDataSoapClient client = new getDataSoapClient();
client.getHSYBInfoCompleted += new EventHandler<getHSYBInfoCompletedEventArgs>(client_getHSYBInfoCompleted);
client.getHSYBInfoAsync(name.Trim());
//水位站資料
getXQYJInfoSoapClient client2 = new getXQYJInfoSoapClient();
client2.GetAllSWZCompleted += new EventHandler<GetAllSWZCompletedEventArgs>(client_GetAllSWZCompleted);
client2.GetAllSWZAsync();
}
public void Show(Point location)
{
if (_isShowing)
throw new InvalidOperationException();
_isShowing = true;
_location = location;
ConstructPopup(this);
_popup.IsOpen = true;
}
//關閉彈出窗體
public void Close()
{
_isShowing = false;
if (_popup != null)
{
_popup.IsOpen = false;
}
}
//彈出框外面點選則關閉該視窗
protected virtual void OnClickOutside()
{
Close();
}
// 用Grid來佈局,初始化彈出窗體
//在Grid裡面新增一個Canvas,用來監測選單項外面的滑鼠點選事件
private void ConstructPopup(FrameworkElement _element)
{
if (_popup != null)
return;
_popup = new Popup();
_grid = new Grid();
_popup.Child = _grid;
_canvas = new Canvas();
_canvas.MouseLeftButtonDown += (sender, args) => { OnClickOutside(); };
_canvas.MouseRightButtonDown += (sender, args) => { args.Handled = true; OnClickOutside(); };
_canvas.Background = new SolidColorBrush(Colors.Transparent);
_grid.Children.Add(_canvas);
_content = _element;
_content.HorizontalAlignment = HorizontalAlignment.Left;
_content.VerticalAlignment = VerticalAlignment.Top;
_content.Margin = new Thickness(_location.X, _location.Y, 0, 0);
_grid.Children.Add(_content);
UpdateSize();
}
/// <summary>
/// 更新大小
/// </summary>
private void UpdateSize()
{
_grid.Width = Application.Current.Host.Content.ActualWidth;
_grid.Height = Application.Current.Host.Content.ActualHeight;
if (_canvas != null)
{
_canvas.Width = _grid.Width;
_canvas.Height = _grid.Height;
}
}
#endregion
#region WebService 呼叫方法及關閉窗體方法
void client_GetAllSWZCompleted(object sender, GetAllSWZCompletedEventArgs e)
{
try
{
ObservableCollection<RiverFall> lists = e.Result;
foreach (RiverFall item in lists)
{
if (item.SWZBM == l_swzbm)
{
this.dt.Content = item.DTNow.ToString("yyyy年M月d日H時");
this.sw.Content = "水位:" + item.SW.ToString("N2") + "m";
}
}
}
catch (Exception ex)
{
this.dt.Content = "沒有監測到該站點資料";
this.sw.Content = "";
}
}
void client_getHSYBInfoCompleted(object sender, getHSYBInfoCompletedEventArgs e)
{
try
{
IList<洪水預報> ret = e.Result;
if (ret.Count > 0)
{
foreach (洪水預報 r in ret)
{
this.tbhsyb.Text = r.標題.Length > 9 ? r.標題.Substring(0, 7) + "..." : r.標題;
this.tbhsyb.Foreground = new SolidColorBrush(Colors.Red);
}
}
else
{
this.tbhsyb.Text = "暫無預報";
this.tbhsyb.Foreground = new SolidColorBrush(Colors.Black);
}
}
catch
{
}
}
//用於移除剛加入的彈出框,在主窗體滑鼠移出後,呼叫此方法
public void closeWindow(MainPage mp)
{
mp.LayoutRoot.Children.RemoveAt(mp.LayoutRoot.Children.Count - 1);
}
#endregion
}
這裡程式碼中仍然保留了原先的點選彈出框的Show方法,可以根據需要呼叫Show方法或直接例項化帶引數的建構函式都可以。相關文章
- ArcGIS API for Silverlight 點選地圖上的要素,彈出視窗(使用Telerik RadWindow)API地圖
- ArcGIS API for Silverlight 點選地圖彈出自定義窗體API地圖
- jQuery滑鼠移入移出jQuery
- ArcGIS API for Silverlight開發中滑鼠左鍵點選地圖上的點彈出視窗及右鍵點選彈出快捷選單的實現程式碼API地圖
- ArcGIS API for Silverlight 當DataGrid選中項時,地圖聚焦彈出視窗,並可以播放音訊檔案API地圖音訊
- vue 滑鼠移入顯示圖示 ,滑鼠移出隱藏圖示Vue
- ArcGIS API for Silverlight 載入google地圖APIGo地圖
- JavaScript滑鼠移入和移出切換樣式JavaScript
- ArcGIS API for Silverlight 地圖元素點閃爍,線流動顯示的處理方式API地圖
- ArcGIS API for Silverlight實現地圖測距功能API地圖
- ArcGIS API for Silverlight載入google地圖(後續篇)APIGo地圖
- ArcGIS API for Silverlight載入BingMap遙感地圖API地圖
- vue地圖視覺化 ArcGIS篇(3)Vue地圖視覺化
- jQuery獲取滑鼠從哪個方向移入和移出元素jQuery
- 防止滑鼠移出移入子元素觸發mouseout和mouseover事件事件
- ArcGIS API for Silverlight 滑鼠移動顯示地理座標API
- ArcGIS API for Silverlight 地圖載入進度條類之MapProgressBarAPI地圖APP
- 判斷滑鼠指標移入移出的方向程式碼例項指標
- 彈出視窗
- 在Watir中整合AutoIt處理JavaScript彈出視窗的方法JavaScript
- ArcGIS API for Silverlight 中根據座標點在地圖上打標記API地圖
- ArcGIS API for Silverlight 地圖中解決點眾多的簇解決方法API地圖
- Prism 彈出視窗
- ArcGIS API for Silverlight中載入Google地形圖(瓦片圖)APIGo
- GridView滑鼠經過感知以及點選行彈出視窗View
- 解決ArcGIS API for Silverlight 載入地圖的內外網訪問問題API地圖
- CSS實現滑鼠移入彈出下拉框CSS
- 彈出視窗程式碼
- 頁面彈窗處理方案
- ArcGis api配合vue開發入門系列(一)引入arcgis api以及載入地圖APIVue地圖
- JS彈出視窗視窗的位置和大小JS
- jQuery地圖熱點效果-滑鼠經過彈出提示層資訊jQuery地圖
- ArcGIS API for Silverlight地圖載入眾多點時,使用Clusterer解決重疊問題API地圖
- 基於ArcGIS API for Javascript的地圖編輯工具APIJavaScript地圖
- 除錯彈出式視窗除錯
- 彈出視窗messagebox
- ArcGIS API for Silverlight 學習筆記API筆記
- Silverlight Rectangle控制元件滑鼠移入時的提示框控制元件