XServer.NET and WPF

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
Post Reply
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

XServer.NET and WPF

Post by Bernd Welter »

Here's some sample code for "how to use xServer.NET control within a WPF based application to access PTV Developer" - thanks to Oliver for the code!
( Here's also some sample for xServer access )
Bernd

Window1.xaml

Code: Select all

<Window x:Class="Demo.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mapcore="clr-namespace:Ptv.XServer.Controls.Map;assembly=Ptv.XServer.Controls.Map" 
    Title="Window1" Height="600" Width="800" Loaded="Window_Loaded">
    <Grid>
        <mapcore:WpfMap Name="Map" Center="8.4, 49" Zoom="12" />
    </Grid>
</Window>
Window1.xaml.cs

Code: Select all

using System.Windows;
using Ptv.XServer.Controls.Map.Layers.Tiled;
using Ptv.XServer.Controls.Map.Localization;
using Ptv.XServer.Controls.Map.TileProviders;
namespace Demo
{
    public partial class Window1
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var apiKey = "...";
            Map.Layers.Add(new TiledLayer("BaseMap")
            {
                TiledProvider = new RemoteTiledProvider
                {
                    MinZoom = 0,
                    MaxZoom = 22,
                    RequestBuilderDelegate = (x, y, z) =>
                       $"https://api.myptv.com/rastermaps/v1/image-tiles/{z}/{x}/{y}?style=silkysand&apiKey={apiKey}",
                },
                IsBaseMapLayer = true,
                Copyright = "© 2022 PTV Group, HERE",
                Caption = MapLocalizer.GetString(MapStringId.Background),
                Icon = Ptv.XServer.Controls.Map.Tools.ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png")
            });
        }
    }
}
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Post Reply