supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow))
来源:互联网 发布:网络摄像头安装调试 编辑:程序博客网 时间:2024/05/07 16:55
接着上一篇,添加可以拖拽的图钉。这次采用超图本身的接口。Pushpin和InfoWindow类。
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
0 0
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow)) 续 解决上一篇的问题
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow))
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法一)
- 【Silverlight】Bing Maps学习系列(四):使用图钉层(Pushpin layer)及地图图层(MapLayer)
- 【Silverlight】Bing Maps学习系列(四):使用图钉层(Pushpin layer)及地图图层(MapLayer)
- 【Silverlight】Bing Maps开发应用与技巧五:实现图钉(Pushpin)的可拖放性(Draggable)扩展
- 【Silverlight】Bing Maps开发应用与技巧六:使用样式美化图钉(Pushpin)控件的ToolTip外观
- Android — 之百度地图定位+添加Mark+InfoWindow
- supermap 学习系列(二)——添加标注(鼠标点击弹出窗口)
- SuperMap超图的热力图
- 超图学习之-数据导入
- 滤镜系列之(二) ffmpeg自带常用滤镜
- 使用超图SuperMap制作气象类专题图全攻略(一)
- Android Google Maps V2之添加Pushpin(Marker)
- 自驾出游系列之(二): 自驾游应该了解的各地春节民俗
- Silverlight 学习笔记之【二】
- iOS之UITableView(二)系统自带的刷新UIrefreshControl
- Quartz学习笔记(二) 转自 learnworld 之 spring任务调度方法之Quartz (推荐)
- IOS7 兼容适配总结
- MFC添加界面的背景图片方法总结
- Error: could not find java.dll如何解决
- 在VB6中写的一个发送简单邮件的类
- 他仿佛看见了文同学正笑盈盈
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow))
- Best Time to Buy and Sell Stock II 多次买卖股票的最佳时机
- OAF中Delete、Update表内容方法小结
- flex样式
- 大师的智慧
- Oracle性能分析3:TKPROF介绍
- Codeforces Round #262 (Div. 2)思维训练
- DSP28377 -CMD文件(一)
- iOS 学习总结之动画