supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow)) 续 解决上一篇的问题
2014-08-21 17:06
489 查看
哈哈,还是可以拖拽的图钉。我都快晕了。解决上一篇留下的问题。
xaml代码:
cs后台代码:
初始化截图和上一篇是一样的,如下:
点击按钮添加图钉,左键弹出交互窗口等和上一篇一样。不一样的是保存,截图如下:
点击保存按钮,截图如下:
切换图钉位置以及下拉框选项,可以和上一张对比一下,截图如下:
如果哪位大神有更好的方法,请联系。共同学习。谢谢。
xaml代码:
<Grid x:Name="LayoutRoot" Background="White"> <ic:Map x:Name="MyMap"> <!--地图地址 自己填写--> <is:TiledDynamicRESTLayer Url="<a target=_blank href="http://localhost:8090/iserver/services/map-china400/rest/maps/China">http://localhost:8090/iserver/services/map-china400/rest/maps/China</a>" /> </ic:Map> <Button x:Name="btnDrag" Content="点击" Height="23" Width="75" Click="btnDrag_Click_1" Margin="0,0,925,277" /> </Grid>
cs后台代码:
<p>namespace SL { public partial class MainPage : UserControl { private ElementsLayer Drag_ElementsLayer = new ElementsLayer(); private ComboBox GV_cboxPopConType; private TextBox GV_txtLon; private TextBox GV_txtLat; public MainPage() { InitializeComponent(); } private void btnDrag_Click_1(object sender, RoutedEventArgs e) { Drag_ElementsLayer.Children.Clear(); Pushpin p = new Pushpin(); InfoWindow window = GetPopupContent(); bool isMouseCaptured = false; p.MouseLeftButtonDown += (obj, ee) => { isMouseCaptured = true; MyMap.ScreenContainer.Children.Remove(window); MyMap.ScreenContainer.Children.Add(window); window.Location = p.Location; if (GV_txtLon != null) { GV_txtLon.Text = p.Location.X.ToString(); } if (GV_txtLat != null) { GV_txtLat.Text = p.Location.Y.ToString(); } window.ShowInfoWindow(); }; p.MouseMove += (obj, ee) => { if (isMouseCaptured) { MyMap.Action = null; Point2D new_point2d = MyMap.ScreenToMap(new Point(ee.GetPosition(null).X, ee.GetPosition(null).Y+37)); p.Location = new_point2d; window.CloseInfoWindow(); } }; p.MouseLeftButtonUp += (obj, ee) => { isMouseCaptured = false; MyMap.Action = new Pan(MyMap); Point2D new_point2d = MyMap.ScreenToMap(new Point(ee.GetPosition(null).X, ee.GetPosition(null).Y+37)); p.Location = new_point2d; window.Location = p.Location; if (GV_txtLon != null) { GV_txtLon.Text = p.Location.X.ToString(); } if (GV_txtLat != null) { GV_txtLat.Text = p.Location.Y.ToString(); } window.ShowInfoWindow(); }; p.Location = MyMap.Center; p.Background = new SolidColorBrush(Colors.Blue); Drag_ElementsLayer.AddChild(p); MyMap.Layers.Add(Drag_ElementsLayer); }</p><p> private InfoWindow GetPopupContent() { StackPanel spAll = new StackPanel(); StackPanel sp1 = new StackPanel() { Orientation = Orientation.Horizontal, Height = 29 }; StackPanel sp2 = new StackPanel() { Orientation = Orientation.Horizontal, Height = 29 }; StackPanel sp3 = new StackPanel() { Orientation = Orientation.Horizontal, Height = 29 }; StackPanel sp4 = new StackPanel() { Orientation = Orientation.Horizontal, Height = 29, HorizontalAlignment = HorizontalAlignment.Right }; TextBlock tblockLon = new TextBlock() { Text = "经度:", VerticalAlignment = VerticalAlignment.Center }; TextBlock tblockLat = new TextBlock() { Text = "纬度:", VerticalAlignment = VerticalAlignment.Center }; TextBlock tblockType = new TextBlock() { Text = "类型:", VerticalAlignment = VerticalAlignment.Center }; GV_txtLon = new TextBox() { Width = 256, Height = 23, }; GV_txtLat = new TextBox() { Width = 256, Height = 23 }; List<ComboBoxItem> ctg = new List<ComboBoxItem>() { new ComboBoxItem { Tag="road", Content="道路" }, new ComboBoxItem { Tag="bridge", Content="桥梁" }, new ComboBoxItem { Tag="river", Content="河流" }, new ComboBoxItem { Tag="farmland", Content="农田" }, }; GV_cboxPopConType = new ComboBox() { Width = 256, Height = 23, ItemsSource = ctg }; GV_cboxPopConType.SelectedIndex = 0; Button btnPopSaveConLonLat = new Button() { Content = "保存", Width = 75, Height = 23 }; btnPopSaveConLonLat.Click += btnPopSaveConLonLat_Click; Button btnPopCancel = new Button() { Content = "取消", Width = 75, Height = 23 }; btnPopCancel.Click += btnPopCancel_Click; sp1.Children.Add(tblockLon); sp1.Children.Add(GV_txtLon); sp2.Children.Add(tblockLat); sp2.Children.Add(GV_txtLat);</p><p> sp3.Children.Add(tblockType); sp3.Children.Add(GV_cboxPopConType);</p><p> sp4.Children.Add(btnPopSaveConLonLat); sp4.Children.Add(btnPopCancel);</p><p> spAll.Children.Add(sp1); spAll.Children.Add(sp2); spAll.Children.Add(sp3); spAll.Children.Add(sp4); InfoWindow window = new InfoWindow(MyMap); window.Width = 310; window.Height = 150; window.Content = spAll; window.Title = "地理位置信息"; return window; }</p><p> private void btnPopCancel_Click(object sender, RoutedEventArgs e) { MyMap.ScreenContainer.Children.Clear(); Drag_ElementsLayer.Children.Clear(); MyMap.Layers.Remove(Drag_ElementsLayer); }</p><p> private void btnPopSaveConLonLat_Click(object sender, RoutedEventArgs e) { string type = "", lon = "", lat = ""; if (GV_cboxPopConType != null) { ComboBoxItem item = GV_cboxPopConType.SelectedItem as ComboBoxItem; type = item.Tag.ToString(); } if (GV_txtLon != null) { lon = GV_txtLon.Text.Trim(); } if (GV_txtLat != null) { lat = GV_txtLat.Text.Trim(); } MessageBox.Show("经度:" + lon + "\n" + "纬度:" + lat + "\n" + "类型:" + type); } } }</p>
初始化截图和上一篇是一样的,如下:
点击按钮添加图钉,左键弹出交互窗口等和上一篇一样。不一样的是保存,截图如下:
点击保存按钮,截图如下:
切换图钉位置以及下拉框选项,可以和上一张对比一下,截图如下:
如果哪位大神有更好的方法,请联系。共同学习。谢谢。
相关文章推荐
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow))
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法一)
- <学习html>第三天笔记-链接标签;锚点定位、<base />标签;遇到标签之间关系的问题及解决方法
- 英文SilverLight 4 tools for vs 2010 安装于vs 2010中文版,无法拖拽数据源问题解决方法
- jbuilderx 光标定位问题解决方法(转载)
- 学习中遇到的问题以及解决方法
- 最近学习J2EE遇到的问题及解决方法(一)
- 添加/删除程序空白窗口及控制面板窗口显示异常问题的解决方法
- 接上一篇,在cs文件中往页面动态添加meta标签时出现“控件包含代码块(即 ),因此无法修改控件集合”错误的解决方法
- 我的嵌入式学习笔记(2)--scanf使用常见问题及解决方法
- 把同一个Resource添加到同一个Group中两个不同Application导致的问题及解决方法
- .Net程序打包安装与卸载制作 系列问题解决方法
- SilverLight学习笔记--如何解决Button不响应MouseLeftButtonDown与MouseLeftButtonUp事件的问题
- SilverLight Canvas is not support in wpf 的问题解决方法
- Citrix实施问题及解决方法系列-1
- vs2005自带水晶报表 之 小问题解决方法
- 添加/删除程序空白窗口及控制面板窗口显示异常问题的解决方法
- 整理ArcSDE 安装过程出现问题以及解决方法系列
- 基于对话框类不能添加成员变量的问题解决方法.
- Citrix实施问题及解决方法系列-2 推荐