WPF实现Map加载

WPF开发者QQ群: 340500857 

欢迎转发、分享、点赞,谢谢大家~。  

接着上一篇

效果预览:

一、MainWindow.xaml代码如下:

<Window x:Class="WpfBingMap.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:map="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"xmlns:mapOverlays="clr-namespace:Microsoft.Maps.MapControl.WPF.Overlays;assembly=Microsoft.Maps.MapControl.WPF"xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"xmlns:local="clr-namespace:WpfBingMap"mc:Ignorable="d"Title="地图" Width="1024" Height="768"><Window.Resources><Geometry x:Key="PathFlag" PresentationOptions:Freeze="True">M687.5 125C500 125 375 13.7 187.5 62.5V31.3C187.5 31.3 187.5 0 156.3 0C125 0 125 31.3 125 31.3V1000H187.5V625C375 562.5 500 687.5 687.5 687.5C875 687.5 937.5 625 937.5 625V62.5C937.5 62.5 875 125 687.5 125Z</Geometry><SineEase x:Key="SineOut" EasingMode="EaseOut" /><Storyboard x:Key="AnimateRound" RepeatBehavior="Forever"><DoubleAnimation Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="Scale"Duration="0:0:01" To="2" EasingFunction="{StaticResource SineOut}" /><DoubleAnimation Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="Scale"Duration="0:0:01" To="2" EasingFunction="{StaticResource SineOut}" /><DoubleAnimation Storyboard.TargetProperty="Opacity"  Duration="0:0:01" To="0" EasingFunction="{StaticResource SineOut}" /></Storyboard><Style x:Key="alarmStyle" TargetType="map:Pushpin"><Setter Property="PositionOrigin" Value="Center"/><Setter Property="Width" Value="60"/><Setter Property="Height" Value="60"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="map:Pushpin"><Grid><Ellipse Height="40" Width="40" Fill="Red" RenderTransformOrigin="0.5,0.5"><Ellipse.OpacityMask><RadialGradientBrush><GradientStop Offset="0" Color="Transparent" /><GradientStop Offset="1" Color="Black" /></RadialGradientBrush></Ellipse.OpacityMask><Ellipse.RenderTransform><ScaleTransform x:Name="Scale"/></Ellipse.RenderTransform><Ellipse.Triggers><EventTrigger RoutedEvent="Loaded"><BeginStoryboard Storyboard="{StaticResource AnimateRound}"></BeginStoryboard></EventTrigger></Ellipse.Triggers></Ellipse><Viewbox Width="30" Height="30" VerticalAlignment="Top" HorizontalAlignment="Center"Margin="20,0,0,0"><Path Data="{StaticResource PathFlag}" Fill="Orange"/></Viewbox></Grid></ControlTemplate></Setter.Value></Setter>
</Style></Window.Resources><Grid><map:Map x:Name="map" ZoomLevel="5" Center="39.9132801985722,116.392009995601"CredentialsProvider="AgXB7m7fVYxKpjEZV9rGdrRPvLgawYhi4Wvw99kk4RDspoalC3B_vQ8GKJAoxrve"><!--<map:Map.Mode><map:MercatorMode/></map:Map.Mode><local:OpenstreetmapTileLayer UriFormat="https://tile.openstreetmap.org/{z}/{x}/{y}.png"/>--><map:MapItemsControl ItemsSource="{Binding PushpinArray,RelativeSource={RelativeSource AncestorType=local:MainWindow}}"><map:MapItemsControl.ItemTemplate><DataTemplate><map:Pushpin Location="{Binding Location}" Cursor="Hand" MouseDown="Pushpin_MouseDown"ToolTip="{Binding Title}"Background="Red"><TextBlock Text="{Binding ID}"/></map:Pushpin></DataTemplate></map:MapItemsControl.ItemTemplate></map:MapItemsControl><map:Pushpin Location="36.6797276003243,118.495410536117" Style="{StaticResource alarmStyle}"/><Canvas Width="50" Height="80" map:MapLayer.Position="31.9121578992881,107.233555852083" map:MapLayer.PositionOrigin="BottomCenter" Opacity="0.7"><Path Data="M 0,0 L 50,0 50,50 25,80 0,50 0,0" Fill="ForestGreen" Stroke="Wheat" StrokeThickness="2" /><TextBlock FontSize="10" Foreground="White" Padding="10" TextAlignment="Center">这里是 <LineBreak />四川 <LineBreak />通江县 <LineBreak /></TextBlock></Canvas></map:Map></Grid>
</Window>

二、MainWindow.xaml.cs代码如下:

public partial class MainWindow : Window{public IEnumerable PushpinArray{get { return (IEnumerable)GetValue(PushpinArrayProperty); }set { SetValue(PushpinArrayProperty, value); }}public static readonly DependencyProperty PushpinArrayProperty =DependencyProperty.Register("PushpinArray", typeof(IEnumerable), typeof(MainWindow), new PropertyMetadata(null));public MainWindow(){InitializeComponent();var pushpins = new List<PushpinModel>();pushpins.Add(new PushpinModel { ID=1, Location = new Location(39.8151940395589, 116.411970893135),Title="和义东里社区" });pushpins.Add(new PushpinModel { ID = 2, Location = new Location(39.9094878843105, 116.33299936282) ,Title="中国水科院南小区"});pushpins.Add(new PushpinModel { ID = 3, Location = new Location(39.9181518802641, 116.203328913478),Title="石景山山姆会员超市" });     pushpins.Add(new PushpinModel { ID = 4, Location = new Location(39.9081417418219, 116.331244439925), Title = "茂林居小区" });PushpinArray = pushpins;}private void Pushpin_MouseDown(object sender, MouseButtonEventArgs e){var model = sender as Pushpin;map.Center = model.Location;map.ZoomLevel = 16;}}public class PushpinModel{public Location Location { get; set; }public int ID { get; set; }public string Title { get; set; }}public class OpenstreetmapTileSource: TileSource{public override Uri GetUri(int x, int y, int zoomLevel){var uri= new Uri(UriFormat.Replace("{x}", x.ToString()).Replace("{y}", y.ToString()).Replace("{z}", zoomLevel.ToString()));Console.WriteLine(uri);return uri;}}public class OpenstreetmapTileLayer : MapTileLayer {public OpenstreetmapTileLayer(){TileSource = new OpenstreetmapTileSource();}public string UriFormat{get { return TileSource.UriFormat; }set { TileSource.UriFormat = value; }}}

源码地址

github:https://github.com/yanjinhuagood/WPFBingMap

gitee:https://gitee.com/yanjinhua/WPFBingMap.git

ArcGIS加载瓦片图源码地址

github:https://github.com/yanjinhuagood/ArcGISMap

WPF开发者QQ群: 340500857 

blogs: https://www.cnblogs.com/yanjinhua

Github:https://github.com/yanjinhuagood

出处:https://www.cnblogs.com/yanjinhua

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

转载请著名作者 出处 https://github.com/yanjinhuagood

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/302397.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

和哪个专业的男生谈恋爱最惨?

全世界只有3.14 % 的人关注了数据与算法之美艺术类专业艺术类的男生是最懂女孩们的心思&#xff0c;也是最浪漫的一类人群&#xff0c;弹琴唱歌跳舞画画样样擅长。这类男生所做的一切&#xff0c;皆可以把女孩们的心俘获到。但是呢&#xff0c;这类男孩的身边总是会有很多玩的很…

只能选择分卷文件的第一部分。_为机器学习模型选择正确的度量评估(第一部分)...

作者&#xff1a;Alvira Swalin编译&#xff1a;ronghuaiyang导读对不同的应用场景&#xff0c;需要不同的模型&#xff0c;对于不同的模型&#xff0c;需要不同的度量评估方式。本系列的第一部分主要关注回归的度量在后现代主义的世界里&#xff0c;相对主义的各种形式一直是最…

android学习笔记之多线程(二)

这个需要在输出&#xff0c;点击start后会隔一会输出一行字&#xff0c;点end会结束输出。 Code package tk.handleractivity;import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.Menu; import android.view.View; impor…

用implicit和explicit打通两种类型

我们知道&#xff0c;在c#中&#xff0c;如果两个类型没有继承关系 &#xff0c;是不能相互值赋的&#xff0c;但有两个关键字implicit和explicit&#xff0c;可以让 Date date DateTime.Now这样的赋值成为可能。注&#xff1a;c#是没有Date类型的&#xff0c;但DateTime有Dat…

多项式乘法与快速傅里叶变换

全世界只有3.14 % 的人关注了数据与算法之美第一节、多项式乘法我们知道&#xff0c;有两种表示多项式的方法&#xff0c;即系数表示法和点值表示法。什么是系数表示法?所谓的系数表示法&#xff0c;举个例子如下图所示&#xff0c;A&#xff08;x&#xff09;6x^3 7x^2 - 10…

mysql全局变量 error_记录——node-mysql连接池遇到的全局变量问题

记录一个折腾了快2个小时的BUG&#xff0c;目前还不清楚原理。系统分别在阿里云(测试用)、XL服务器上部署&#xff0c;此次BUG所在功能模块为生成表格并下载&#xff0c;表格数据由120(阿里云)上的数据库提供。阿里云上一切正常&#xff0c;无任何异常。部署到112后(XL服务器)&…

WPF 模仿QQ音乐首页歌单效果

qq音乐桌面版做的效果感觉很不错&#xff0c;今天就模仿一下它首页歌单的效果&#xff0c;从简单做起。。。看一下效果&#xff1a;&#xff0c;其实也很简单&#xff0c;就是布局和动画&#xff0c;触发器。。。还用到了ItemsControl下面就看看代码&#xff1a;MainWindow的xa…

收藏 : 50个Excel逆天功能,一秒变“表哥”

全世界只有3.14 % 的人关注了数据与算法之美Excel的50个逆天功能&#xff0c;动画教程珍藏版&#xff01;先看几个简单的&#xff1a;1、自动筛选2、在Excel中字符替换3、在Excel中冻结行列标题4、在Excel中为导入外部数据5、在Excel中行列快速转换6、共享Excel工作簿7、在Exce…

实战~~整个网络无法浏览,提示网络不存在或者尚未启动

今天早上接到同事的电脑&#xff0c;说其他人访问不到他的电脑&#xff0c;他电脑上有文件要共享才能进行工作~~故障现象&#xff1a;能上网&#xff0c;能PING通其他电脑&#xff0c;但是通过网上邻居和IP不能访问其他电脑上的资源。 这是在故障本机上的提示~~ 这是其他工作站…

python ctp接口_使用ctp的python接口

在github上查到一个项目ctpwrapper在按照文档按照的时候报错>>>pip install cython --upgrade>>>pip install ctpwrapper --upgrade在安装第二个命令的时候第一个问题安装yum install -y gcc-c 解决第二个问题ctpwrapper/MdApi.cpp:39:20: 致命错误:Python.h…

C# 并行和多线程编程——认识和使用Task

对于多线程&#xff0c;我们经常使用的是Thread。在我们了解Task之前&#xff0c;如果我们要使用多核的功能可能就会自己来开线程&#xff0c;然而这种线程模型在.net 4.0之后被一种称为基于“任务的编程模型”所冲击&#xff0c;因为task会比thread具有更小的性能开销&#xf…

formula 返回list_python正则实现计算器功能

本文实例为大家分享了python正则实现计算器功能的具体代码&#xff0c;供大家参考&#xff0c;具体内容如下 # -*- coding: utf-8 -*-# Author :Gogh# Time :2017/12/4 20:16# Email :361910002qq.comimport redef operator_update(formula):# 对formula公式进行 去除空字符&am…

Facebook上的一道题,超过50万的评论和1万3500次分享

全世界只有3.14 % 的人关注了数据与算法之美近日&#xff0c;有网友在Facebook发了一道数学题&#xff1a;发布以后&#xff0c;目前已经收到超过50万的评论和1万3500次分享&#xff0c;图中包含四个等式&#xff0c;前面三个已经有答案了&#xff0c;最后一个问题要求你得出相…

闲聊linux中的input设备(转)

转自&#xff1a;http://blog.csdn.net/lmm670/article/details/6080998 用过linux的哥们都知道&#xff0c;linux所有的设备都是以文件的形式实现的&#xff0c;要访问一个设备&#xff0c;我们只需要以open、read、write的形式对设备的进行操作就可以了。在linux系统的/dev目…

Polly的7种策略

概念Polly是一个被.net基金会支持认可的框架&#xff0c;Polly是一个.NET弹性和瞬态故障处理库&#xff0c;允许开发人员以流畅和线程安全的方式表达策略&#xff0c;如重试、断路器、超时、舱壁隔离和回退。Polly的7种策略1、重试&#xff08;Retry&#xff09;:当程序发生短暂…

从数学入手,3招打破机器学习的边界

全世界只有3.14 % 的人关注了数据与算法之美本文约2007余字&#xff0c;阅读需要约6分钟&#xff1b;系统资料领取见文末&#xff1b;关键词&#xff1a;人工智能&#xff0c;机器学习&#xff0c;深度学习&#xff0c;数学&#xff0c;学习建议01.机器学习工程师的边界是什么&…

mysql not exists 效率高_mysql not in、left join、IS NULL、NOT EXISTS 效率问题记录

语句一&#xff1a;select count(*) from A where A.a not in (select a from B)语句二&#xff1a;select count(*) from A left join B on A.a B.a where B.a is null语句三&#xff1a;select count(*) from A where not exists (select a from B where A.a B.a)知道以上三…

POJ 3981(字符串替换)

字符串替换Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7290 Accepted: 3451Description 编写一个C程序实现将字符串中的所有"you"替换成"we"Input 输入包含多行数据 每行数据是一个字符串&#xff0c;长度不超过1000 数据以EOF结束Output…

.NET Core 基于 Grafana Loki 日志初体验

介绍Loki: like Prometheus, but for logs.Loki是一个轻量级的日志系统&#xff0c;受到Prometheus项目的启发&#xff0c;由Grafana团队设计和开发&#xff0c;所以在Grafana中是原生支持的&#xff0c;具有可水平扩展&#xff0c;高度可用等特性&#xff0c;通过存储压缩的、…

mysql80重置密码_MySQL8.0修改密码问题

MySQL5.7和之前的用户修改密码方式&#xff1a;mysql -uroot -e "Set passwordpassword(‘123’);"mysql -uroot -p123.com -e "use mysql;update user set authentication_stringpassword(456) where userroot;"update mysql.user set authentication_str…