WPF实现地图加载
WPF开发者QQ群: 340500857
微信公众号:WPF开发者 或者搜索:WPFDevelopers
前言
有小伙伴问如何加载高德地图。
效果预览:
一、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>
<LinearGradientBrush x:Key="MainColor" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF020621" Offset="0"/>
<GradientStop Color="#FF364BD8" Offset="1"/>
<GradientStop Color="#FF5A6BD8" Offset="0.499"/>
</LinearGradientBrush>
<ControlTemplate x:Key="CarTemplate" TargetType="map:Pushpin">
<Grid ToolTip="物资车辆">
<Ellipse Width="35" Height="35" Fill="White" StrokeThickness="3" Stroke="Red"/>
<Image Source="Images/Car/Car2.png" Width="25" Height="25"/>
</Grid>
</ControlTemplate>
<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"