汕尾市企业网站seo点击软件,WordPress多功能主题Cosy,wordpress双首页,百度热门关键词WPF开发者QQ群#xff1a; 340500857 前言 有小伙伴问如何加载高德地图。欢迎转发、分享、点赞#xff0c;谢谢大家~。 接着上一篇源码中放了我的 BingMap Key 请大家不要滥用#xff0c;谢谢。也可以自行申请 BingMap Key https://www.bingmapsportal.com/效果预览#x… WPF开发者QQ群 340500857 前言 有小伙伴问如何加载高德地图。欢迎转发、分享、点赞谢谢大家~。 接着上一篇源码中放了我的 BingMap Key 请大家不要滥用谢谢。也可以自行申请 BingMap Key https://www.bingmapsportal.com/效果预览更多效果请下载源码体验一、MainWindow.xaml代码如下Window x:ClassWpfBingMap.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:mapclr-namespace:Microsoft.Maps.MapControl.WPF;assemblyMicrosoft.Maps.MapControl.WPFxmlns:mapOverlaysclr-namespace:Microsoft.Maps.MapControl.WPF.Overlays;assemblyMicrosoft.Maps.MapControl.WPFxmlns:PresentationOptionshttp://schemas.microsoft.com/winfx/2006/xaml/presentation/optionsxmlns:localclr-namespace:WpfBingMapmc:IgnorabledTitle地图 Width1024 Height768Window.ResourcesLinearGradientBrush x:KeyMainColor EndPoint0.5,1 StartPoint0.5,0GradientStop Color#FF020621 Offset0/GradientStop Color#FF364BD8 Offset1/GradientStop Color#FF5A6BD8 Offset0.499//LinearGradientBrushControlTemplate x:KeyCarTemplate TargetTypemap:PushpinGrid ToolTip物资车辆Ellipse Width35 Height35 FillWhite StrokeThickness3 StrokeRed/Image SourceImages/Car/Car2.png Width25 Height25//Grid/ControlTemplateGeometry x:KeyPathFlag PresentationOptions:FreezeTrueM687.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/GeometrySineEase x:KeySineOut EasingModeEaseOut /Storyboard x:KeyAnimateRound RepeatBehaviorForeverDoubleAnimation Storyboard.TargetPropertyScaleX Storyboard.TargetNameScaleDuration0:0:01 To2 EasingFunction{StaticResource SineOut} /DoubleAnimation Storyboard.TargetPropertyScaleY Storyboard.TargetNameScaleDuration0:0:01 To2 EasingFunction{StaticResource SineOut} /DoubleAnimation Storyboard.TargetPropertyOpacity Duration0:0:01 To0 EasingFunction{StaticResource SineOut} //StoryboardStyle x:KeyalarmStyle TargetTypemap:PushpinSetter PropertyPositionOrigin ValueCenter/Setter PropertyWidth Value60/Setter PropertyHeight Value60/Setter PropertyTemplateSetter.ValueControlTemplate TargetTypemap:PushpinGridEllipse Height40 Width40 FillRed RenderTransformOrigin0.5,0.5Ellipse.OpacityMaskRadialGradientBrushGradientStop Offset0 ColorTransparent /GradientStop Offset1 ColorBlack //RadialGradientBrush/Ellipse.OpacityMaskEllipse.RenderTransformScaleTransform x:NameScale//Ellipse.RenderTransformEllipse.TriggersEventTrigger RoutedEventLoadedBeginStoryboard Storyboard{StaticResource AnimateRound}/BeginStoryboard/EventTrigger/Ellipse.Triggers/EllipseViewbox Width30 Height30 VerticalAlignmentTop HorizontalAlignmentCenterMargin20,0,0,0Path Data{StaticResource PathFlag} FillOrange//Viewbox/Grid/ControlTemplate/Setter.Value/Setter
/Style/Window.ResourcesGridmap:Map x:Namemap ZoomLevel5 Center39.9132801985722,116.392009995601CredentialsProviderAgXB7m7fVYxKpjEZV9rGdrRPvLgawYhi4Wvw99kk4RDspoalC3B_vQ8GKJAoxrvemap:Map.Modemap:MercatorMode//map:Map.Mode!--local:OpenstreetmapTileLayer UriFormathttps://tile.openstreetmap.org/{z}/{x}/{y}.png/--local:AMapTitleLayer/map:MapItemsControl ItemsSource{Binding PushpinArray,RelativeSource{RelativeSource AncestorTypelocal:MainWindow}}map:MapItemsControl.ItemTemplateDataTemplatemap:Pushpin Location{Binding Location} CursorHand MouseDownPushpin_MouseDownToolTip{Binding Title}BackgroundRedTextBlock Text{Binding ID}//map:Pushpin/DataTemplate/map:MapItemsControl.ItemTemplate/map:MapItemsControlmap:Pushpin Location36.6797276003243,118.495410536117 Style{StaticResource alarmStyle}/Canvas Width50 Height80 map:MapLayer.Position31.9121578992881,107.233555852083 map:MapLayer.PositionOriginBottomCenter Opacity0.7Path DataM 0,0 L 50,0 50,50 25,80 0,50 0,0 FillForestGreen StrokeWheat StrokeThickness2 /TextBlock FontSize10 ForegroundWhite Padding10 TextAlignmentCenter这里是 LineBreak /四川 LineBreak /通江县 LineBreak //TextBlock/Canvasmap:MapLayer x:NameCarLayer//map:MapDockPanelGrid DockPanel.DockTop!--Rectangle Width400 Height60 RenderTransformOrigin0.5,0.5Rectangle.RenderTransformSkewTransform AngleX40//Rectangle.RenderTransformRectangle.FillLinearGradientBrush EndPoint0.5,1 StartPoint0.5,0GradientStop Color#FF020621 Offset0/GradientStop Color#FF364BD8 Offset1/GradientStop Color#FF5A6BD8 Offset0.499//LinearGradientBrush/Rectangle.Fill/Rectangle--Path DataM75.811064,0 L275.81107,0 275.81107,39.999999 267.12714,39.999999 267.12798,40.000499 67.127973,40.000499 0,0.00050140842 75.811064,0.00050140842 zWidth200 Height30 StretchFill Opacity.8 Stroke#FFCCFEFF StrokeThickness1.5 Fill{StaticResource MainColor}Path.RenderTransformSkewTransform AngleX-40//Path.RenderTransform/PathTextBlock Text预警指挥平台 ForegroundWhite VerticalAlignmentCenter HorizontalAlignmentCenterFontSize16 FontWeightBlack//GridGrid DockPanel.DockLeft Width200HorizontalAlignmentLeft Grid.RowDefinitionsRowDefinition HeightAuto/RowDefinition/RowDefinition HeightAuto//Grid.RowDefinitionsRectangle Grid.RowSpan3 Fill#FF364BD8 Opacity.8 Stroke#FFCCFEFF StrokeThickness1.5/TextBlock Text数据信息 FontSize16 ForegroundWhite Margin10,10,0,0/ItemsControl ItemsSource{Binding PushpinArray,RelativeSource{RelativeSource AncestorTypelocal:MainWindow}}Margin4,10 Grid.Row1ItemsControl.ItemTemplateDataTemplateGrid Margin4 x:NamePART_GridMouseLeftButtonDownPART_Grid_MouseLeftButtonDownTag{Binding ID}Grid.ResourcesStyle TargetTypeTextBlockSetter PropertyForeground ValueWhite/Setter PropertyFontSize Value16/
/Style/Grid.ResourcesGrid.ColumnDefinitionsColumnDefinition WidthAuto/ColumnDefinition//Grid.ColumnDefinitionsEllipse Width20 Height20 FillOrangeRed/TextBlock Text{Binding ID} HorizontalAlignmentCenter/TextBlock Margin4,0 Grid.Column1 Text{Binding Title}//GridDataTemplate.TriggersTrigger PropertyIsMouseOver ValueTrueSetter PropertyBackground TargetNamePART_Grid Value#FF020621//Trigger/DataTemplate.Triggers/DataTemplate/ItemsControl.ItemTemplate/ItemsControlButton Content物资轨迹 ClickBtnCar_Click Grid.Row2 Height40//Grid/DockPanel/Grid
/Window二、MainWindow.xaml.cs代码如下/*** 作者闫驚鏵* https://github.com/yanjinhuagood/WPFBingMap.git* **/using Microsoft.Maps.MapControl.WPF;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;/** * 39.0654365763652,115.513103745601,0
38.5861378332358,114.897869370601,0
38.0690298850334,114.238689683101,0
37.4436424646135,113.491619370601,0
36.8833163124675,112.832439683101,0
36.6015984304246,112.480877183101,0
36.2125510101126,112.041424058101,035.6074752751952,111.426189683101,034.9977887035825,110.591228745601,0
34.456028305434,109.932049058101,0
33.9836399832877,109.580486558101,0
33.5086116028286,108.965252183101,0
33.1046158275268,108.525799058101,032.6617655474571,108.042400620601,0
32.179523137361,107.515056870601,0* **/namespace WpfBingMap
{/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{private LocationCollection _polyLocations;private MapPolyline mapPolyline;private Pushpin carPushpin;private DispatcherTimer dispatcherTimer;private ListLocation locations;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();//this.map.Mode new MercatorMode();//this.map.Children.Add(new AMapTitleLayer());//this.map.MouseDown Map_MouseDown;var pushpins new ListPushpinModel();pushpins.Add(new PushpinModel { ID1, 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.9219204792284, 116.203500574855),Title石景山山姆会员超市 });pushpins.Add(new PushpinModel { ID 4, Location new Location(39.9081417418219, 116.331244439925), Title 茂林居小区 });PushpinArray pushpins;_polyLocations new LocationCollection();//_polyLocations.Add(new Location(39.9082973053021, 116.63105019548));//_polyLocations.Add(new Location(39.9155572462212, 116.192505993178));//_polyLocations.Add(new Location(39.8065773542251, 116.276113341099));_polyLocations.Add(new Location(39.9082973053021, 116.63105019548));_polyLocations.Add(new Location(31.9121578992881, 107.233555852083));mapPolyline new MapPolyline {Stroke Brushes.Green,StrokeThickness 2,Locations _polyLocations,};CarLayer.Children.Add(mapPolyline);carPushpin new Pushpin{Template this.Resources[CarTemplate] as ControlTemplate,//Location new Location(39.9082973053021, 116.63105019548),//_polyLocations[0],Location new Location(31.9121578992881, 107.233555852083),PositionOrigin PositionOrigin.Center,};CarLayer.Children.Add(carPushpin);dispatcherTimer new DispatcherTimer();dispatcherTimer.Interval TimeSpan.FromSeconds(1.5);dispatcherTimer.Tick DispatcherTimer_Tick;}int index 0;private void DispatcherTimer_Tick(object sender, EventArgs e){//carPushpin.Location carPushpin.Location//var currtLocation carPushpin.Location;//if (currtLocation _polyLocations[1])//{// dispatcherTimer.Stop();// return;//}//currtLocation.Longitude currtLocation.Longitude - 0.233555852083;//currtLocation.Latitude currtLocation.Latitude - 0.9121578992881;//map.Center currtLocation;//map.ZoomLevel 16;if (index 0){index locations.Count - 1;dispatcherTimer.Stop();return; }carPushpin.Location locations[index];index--;//map.Center carPushpin.Location;}private void BtnCar_Click(object sender, RoutedEventArgs e){locations new ListLocation();locations.Add(new Location(39.9082973053021, 116.63105019548));locations.Add(new Location(39.0654365763652, 115.513103745601));locations.Add(new Location(38.5861378332358, 114.897869370601));locations.Add(new Location(38.0690298850334, 114.238689683101));locations.Add(new Location(37.4436424646135, 113.491619370601));locations.Add(new Location(36.8833163124675, 112.832439683101));locations.Add(new Location(36.6015984304246, 112.480877183101));locations.Add(new Location(36.2125510101126, 112.041424058101));locations.Add(new Location(35.6074752751952, 111.426189683101));locations.Add(new Location(34.9977887035825, 110.591228745601));locations.Add(new Location(34.456028305434, 109.932049058101));locations.Add(new Location(33.9836399832877, 109.580486558101));locations.Add(new Location(33.5086116028286, 108.965252183101));locations.Add(new Location(33.1046158275268, 108.525799058101));locations.Add(new Location(32.6617655474571, 108.042400620601));locations.Add(new Location(32.179523137361, 107.515056870601));locations.Add(new Location(31.9121578992881, 107.233555852083));index locations.Count - 1;dispatcherTimer.Start();//var tt Enumerable.Range((int)_polyLocations[1].Latitude, (int)_polyLocations[0].Latitude).ToList();//for (int i 0; i tt.Count(); i)//{// Console.WriteLine(tt[i]);//}}private void Map_MouseDown(object sender, MouseButtonEventArgs e){Point mousePosition e.GetPosition(this);Location pinLocation this.map.ViewportPointToLocation(mousePosition);Console.WriteLine(pinLocation);}private void Pushpin_MouseDown(object sender, MouseButtonEventArgs e){var model sender as Pushpin;map.Center model.Location;map.ZoomLevel 16;}private void PART_Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){var grid sender as Grid;var model PushpinArray.OfTypePushpinModel().FirstOrDefault(xx.ID.Equals(grid.Tag));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 url string.Format(https://www.openstreetmap.org/#map{z}/{x}/{y},zoomLevel,x,y);// //return new Uri(url, UriKind.Absolute);// 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; }// }//}public class AMapTitleLayer : MapTileLayer{public AMapTitleLayer(){TileSource new AMapTileSource();}public string UriFormat{get { return TileSource.UriFormat; }set { TileSource.UriFormat value; }}}public class AMapTileSource: TileSource{public override Uri GetUri(int x, int y, int zoomLevel){//string url https://webrd01.is.autonavi.com/appmaptile?langzh_cnsize1scale1style8x x y y z zoomLevel;//https://www.amap.com/service/regeo?longitude115.975052latitude39.778747//string url https://wprd01.is.autonavi.com/appmaptile?x x y y z zoomLevel langzh_cnsize1scale1style8;string url string.Format(http://wprd01.is.autonavi.com/appmaptile?x{0}y{1}z{2}langzh_cnsize1scl1style7,x,y,zoomLevel);return new Uri(url, UriKind.Absolute);}}}源码地址githubhttps://github.com/yanjinhuagood/WPFBingMapgiteehttps://gitee.com/yanjinhua/WPFBingMap.gitArcGIS加载瓦片图源码地址githubhttps://github.com/yanjinhuagood/ArcGISMapWPF开发者QQ群 340500857 blogs https://www.cnblogs.com/yanjinhuaGithubhttps://github.com/yanjinhuagood出处https://www.cnblogs.com/yanjinhua版权本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。转载请著名作者 出处 https://github.com/yanjinhuagood