接着上一篇,添加可以拖拽的图钉。这次采用超图本身的接口。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,5" x:name="txtLongitudePopup" Text="老的经度" GrID.Row="0" GrID.Column="1" GrID.ColumnSpan="2" /> <TextBox margin="0,5" x:name="txtLatitudePopup" Text="老的纬度" GrID.Row="1" GrID.Column="1" GrID.ColumnSpan="2"/> <ComboBox x:name="cBoxPopConType" margin="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,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>
初始化截图,如下:
点击按钮添加图钉,左键图钉d出交互窗口,接着拖动图钉。截图如下:
点击“取消”按钮删除图钉和图层。点击“保存”截图如下:
唉,可能您也发现了,想要得到数据模版的控件 并且给他赋值 但是没有实现 只可以读取。初步认为是他的原因:dataTemplate.LoadContent()。
如果有哪位大神可以做到,请留言。交流一下。刚开始学习,不熟练。谢谢。
源码下载:http://download.csdn.net/detail/duyelang/7797581
总结以上是内存溢出为你收集整理的supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow))全部内容,希望文章能够帮你解决supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow))所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)