supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow))
2014-08-21 16:21
411 查看
接着上一篇,添加可以拖拽的图钉。这次采用超图本身的接口。Pushpin和InfoWindow类。
xaml代码:
.cs后台代码:
初始化截图,如下:
点击按钮添加图钉,左键图钉弹出交互窗口,接着拖动图钉。截图如下:
点击“取消”按钮删除图钉和图层。点击“保存”截图如下:
唉,可能您也发现了,想要得到数据模版的控件 并且给他赋值 但是没有实现 只可以读取。初步认为是他的原因:dataTemplate.LoadContent()。
如果有哪位大神可以做到,请留言。交流一下。刚开始学习,不熟练。谢谢。
源码下载:http://download.csdn.net/detail/duyelang/7797581
xaml代码:
<Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <DataTemplate x:Key="LocationInfoWindowTemplate"> <StackPanel Width="312" Height="150"> <Grid Margin="5"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="40" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock VerticalAlignment="Center" Text="经度:" Grid.Row="0" Grid.Column="0"/> <TextBlock VerticalAlignment="Center" Text="纬度:" Grid.Row="1" Grid.Column="0"/> <TextBlock VerticalAlignment="Center" Text="类型:" Grid.Row="2" Grid.Column="0"/> <TextBox Margin="0,5,0,5" x:Name="txtLongitudePopup" Text="老的经度" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" /> <TextBox Margin="0,5,0,5" x:Name="txtLatitudePopup" Text="老的纬度" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/> <ComboBox x:Name="cboxPopConType" Margin="0,5,0,10" Grid.Row="2" Grid.Column="1"> <ComboBoxItem Tag="road" Content="道路" IsSelected="True"></ComboBoxItem> <ComboBoxItem Tag="bridge" Content="桥梁"></ComboBoxItem> <ComboBoxItem Tag="river" Content="河流"></ComboBoxItem> <ComboBoxItem Tag="farmland" Content="农田"></ComboBoxItem> </ComboBox> <StackPanel HorizontalAlignment="Right" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal"> <Button x:Name="btnPopSaveConLonLat" Click="btnPopSaveConLonLat_Click_1" Content="保存" Width="70"/> <Button x:Name="btnPopCancel" Click="btnPopCancel_Click_1" Content="取消" Width="70"/> </StackPanel> </Grid> </StackPanel> </DataTemplate> </Grid.Resources> <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(); public MainPage() { InitializeComponent(); } private void btnDrag_Click_1(object sender, RoutedEventArgs e) { //获取数据模版中的控件 开始想给他赋值 但是没有实现 只可以读取。初步认为是他的原因:dataTemplate.LoadContent() DataTemplate dataTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate; Grid grid = (Grid)VisualTreeHelper.GetChild(dataTemplate.LoadContent(), 0); ComboBox cbox = (ComboBox)grid.FindName("cboxPopConType"); TextBox txtLon = (TextBox)grid.FindName("txtLongitudePopup"); TextBox txtLat = (TextBox)grid.FindName("txtLatitudePopup"); txtLon.Text = "新的经度"; txtLat.Text = "新的纬度";</p><p> Drag_ElementsLayer.Children.Clear(); Pushpin p = new Pushpin(); InfoWindow window = new InfoWindow(MyMap); window.ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate; window.Title = "合同地理位置信息"; bool isMouseCaptured = false; p.MouseLeftButtonDown += (obj, ee) => { isMouseCaptured = true; MyMap.ScreenContainer.Children.Remove(window); MyMap.ScreenContainer.Children.Add(window); window.Location = p.Location; 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; window.ShowInfoWindow(); }; p.Location = MyMap.Center; p.Background = new SolidColorBrush(Colors.Blue); Drag_ElementsLayer.AddChild(p); MyMap.Layers.Add(Drag_ElementsLayer); } private void btnPopSaveConLonLat_Click_1(object sender, RoutedEventArgs e) { DataTemplate dataTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate; Grid grid = (Grid)VisualTreeHelper.GetChild(dataTemplate.LoadContent(), 0); ComboBox cbox = (ComboBox)grid.FindName("cboxPopConType"); ComboBoxItem item = cbox.SelectedItem as ComboBoxItem; TextBox txtLon = (TextBox)grid.FindName("txtLongitudePopup"); TextBox txtLat = (TextBox)grid.FindName("txtLatitudePopup");</p><p> MessageBox.Show("经度:" + txtLon.Text + "\n" + "纬度:" + txtLat.Text + "\n" + "类型:" + item.Tag.ToString()); }</p><p> private void btnPopCancel_Click_1(object sender, RoutedEventArgs e) { MyMap.ScreenContainer.Children.Clear(); Drag_ElementsLayer.Children.Clear(); MyMap.Layers.Remove(Drag_ElementsLayer); } } } </p>
初始化截图,如下:
点击按钮添加图钉,左键图钉弹出交互窗口,接着拖动图钉。截图如下:
点击“取消”按钮删除图钉和图层。点击“保存”截图如下:
唉,可能您也发现了,想要得到数据模版的控件 并且给他赋值 但是没有实现 只可以读取。初步认为是他的原因:dataTemplate.LoadContent()。
如果有哪位大神可以做到,请留言。交流一下。刚开始学习,不熟练。谢谢。
源码下载:http://download.csdn.net/detail/duyelang/7797581
相关文章推荐
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow)) 续 解决上一篇的问题
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法一)
- supermap 学习系列(二)——添加标注(鼠标点击弹出窗口)
- supermap学习系列(七)——用户自己在地图上添加点、线、面标注
- 一步一步学Silverlight 2系列(24):与浏览器交互相关辅助方法
- My Silverlight系列(2)——绝对定位下的控件动态添加操作
- TerryLee的一步一步学Silverlight 2系列学习(草稿)
- .Net学习难点讨论系列9 -泛型类型参数的约束 泛型方法
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(6):为网站添加Silverlight支持.zip(6.31 MB)
- [Silverlight2]一步一步学习Silverlight 2系列
- 微软论坛2009全新奉献,全新打造技术自测系列活动:一起学习Silverlight
- 【Silverlight】Bing Maps学习系列(四):使用图钉层(Pushpin layer)及地图图层(MapLayer)
- 一步一步学Silverlight 2系列(24):与浏览器交互相关辅助方法
- 一步一步学Silverlight 2系列(24):与浏览器交互相关辅助方法
- EXTJS学习系列提高篇:第十七篇(转载)作者殷良胜,ext2.2打造全新功能grid系列--添加记录篇
- Emit学习-基础篇-为动态类添加属性、构造函数、方法
- 一步一步学Silverlight 2系列(24):与浏览器交互相关辅助方法
- 【Silverlight】Bing Maps学习系列(四):使用图钉层(Pushpin layer)及地图图层(MapLayer) 推荐
- .Net学习难点讨论系列6 - .Net中对字符串处理的方法
- JS OO 学习笔记 ——JS封装使用prototype添加方法