Very simple map client: Difference between revisions

From Maria GDK Wiki
Jump to navigation Jump to search
()
()
 
(12 intermediate revisions by one other user not shown)
Line 3: Line 3:
[[File:verysimpleclient.png|right|thumb|Very simple map client]]
[[File:verysimpleclient.png|right|thumb|Very simple map client]]


== Prerequisites ==
== General ==


* Make sure that all '''''[[Development requirements|Development Requirements]]''''' are met!
; Note
* You will need to include the '''''TPG.Maria.MapLayer''''' NuGet package as a minimum.
:* Make sure that all '''''[[Development requirements|Development Requirements]]''''' are met!
* Sample code for this section is found in the '''''MariaVerySimpleClient''''' solution folder of the '''''SampleProjects''''' solution.
:* You will need to include the '''''TPG.MariaGDK''''' NuGet package.  
:* Sample code for this section is found in the '''''MariaVerySimpleClient''''' solution folder of the '''''SampleProjects''''' solution.
:* For general troubleshooting, see [[Development_troubleshooting|Development troubleshooting]]


== Creating the Map Client ==
== Creating the Map Client ==
Line 25: Line 27:
=== Add required NuGet packages ===
=== Add required NuGet packages ===


From the NuGet Package Manager, load the '''''TPG.Maria.MapLayer''''' package, as described in [[Development requirements#Loading Maria GDK Packages|Maria GDK Nuget Packages]] in Development Requirements.
From the NuGet Package Manager, load the '''''TPG.MariaGDK''''' package, as described in [[Development requirements#Loading Maria GDK Packages|Maria GDK Nuget Packages]] in Development Requirements.


=== Include MariaUserControl ===
=== Include MariaUserControl ===
Line 32: Line 34:
* Also add an eventhandler for the window closing event, in the xaml and code behind.
* Also add an eventhandler for the window closing event, in the xaml and code behind.


<source lang="xml"><Window x:Class="VerySimpleMapClient.MainWindow"
<source lang="xml">
 
<Window x:Class="VerySimpleMapClient.MainWindow"
         . . .
         . . .
         xmlns:mariaUserControl="clr-namespace:TPG.Maria.MariaUserControl;assembly=TPG.Maria.MariaUserControl"
         xmlns:mariaUserControl="clr-namespace:TPG.Maria.MariaUserControl;assembly=TPG.Maria.MariaUserControl"
Line 38: Line 42:
         Closing="WindowClosing">
         Closing="WindowClosing">
     <Grid>
     <Grid>
         <mariaUserControl:MariaUserControl Name="MariaCtrl" />
         <mariaUserControl:MariaUserControl Name="MariaCtrl"
                                          IsPanNavigationVisible="True"
                                          IsScaleBarVisible="True"
                                          IsRulerVisible="True"/>
     </Grid>
     </Grid>
</Window></source>
</Window>
<source lang="c#">private void WindowClosing(object sender, CancelEventArgs e)
 
</source>
 
<source lang="c#">
private void WindowClosing(object sender, CancelEventArgs e)
{
{
     MariaCtrl.Dispose();
     MariaCtrl.Dispose();
}</source>
}
</source>
 
== Creating the Map Layer with Map Service Connection ==
== Creating the Map Layer with Map Service Connection ==


=== Service Configuration Setup ===
=== Service Configuration Setup ===


Create service configuration for connections to the Catalog service and Template service as a minimum. See [[Basic_map_client#Service_configuration|Service Configuration]]
Create service configuration for connections to the Catalog service and Template service as a minimum.  
 
Add the following to your '''''app.config''''' file, after the '''''startup''''' section:
 
<source lang="xml">
 
  <system.serviceModel>
    <bindings>
      <!-- Basic HTTP -->
      <basicHttpBinding>
        <binding name="myHttpBinding"
                maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
                closeTimeout="00:10:00" openTimeout="00:10:00"
                receiveTimeout="00:10:00" sendTimeout="00:10:00">         
          <readerQuotas maxArrayLength="2147483647"/>
        </binding>
      </basicHttpBinding>         
    </bindings>
 
    <client>
      <!-- Catalog service HTTP  -->
      <endpoint name="MapCatalogService"
                address="http://tpg-mariagdkpro:9008/catalog"
                contract="TPG.GeoFramework.MapServiceInterfaces.IMapCatalogService"
                binding="basicHttpBinding" bindingConfiguration="myHttpBinding" />
      <!-- Template service HTTP -->
      <endpoint name="TemplateService"
                address="http://tpg-mariagdkpro:9008/maptemplates"
                contract="TPG.GeoFramework.MapTemplateServiceContracts.IMapTemplateService"
                binding="basicHttpBinding" bindingConfiguration="myHttpBinding" />   
    </client>
 
    <behaviors>
      <endpointBehaviors>
        <behavior name="myEndpointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <extensions></extensions>
  </system.serviceModel>
 
</source>
 
For more info, see  [[Basic_map_client#Service_configuration|Service Configuration]]


=== Include layer handling. ===
=== Include layer handling. ===
Line 60: Line 118:


<source lang="c#">   
<source lang="c#">   
public MapLayer MapLayer { get; private set; }
private MariaMapLayerManager _mapLayerManager;
 
public IMariaMapLayer MapLayer { get; private set; }
public IMariaMapLayer MiniMapLayer { get; private set; }
public IMariaMapLayer MiniMapLayer { get; private set; }
public MainWindow()
public MainWindow()
{
{
Line 73: Line 134:


     // Service connection specified by app.config
     // Service connection specified by app.config
     var mapLayerManager = new MariaMapLayerManager();
     _mapLayerManager = new MariaMapLayerManager();
     MapLayer = new MapLayer(mapLayerManager);
 
     MapLayer = new MapLayer(_mapLayerManager);
     MapLayer.LayerInitialized += OnMapLayerInitialized;
     MapLayer.LayerInitialized += OnMapLayerInitialized;
     MariaCtrl.Layers.Add(MapLayer);
     MariaCtrl.Layers.Add(MapLayer);


     MiniMapLayer = new MapLayer(mapCatalogServiceClient, mapTemplateServiceClient);
     MiniMapLayer = new MapLayer(_mapLayerManager);
     MiniMapLayer.LayerInitialized += OnMiniMapLayerInitialized;
     MiniMapLayer.LayerInitialized += OnMiniMapLayerInitialized;
     MariaCtrl.MiniMapLayer = MiniMapLayer;
     MariaCtrl.MiniMapLayer = MiniMapLayer;
Line 97: Line 159:
private MapTemplate PreferredMapTemplate()
private MapTemplate PreferredMapTemplate()
{
{
     var preferred = "WorldMap";
     var preferred = "TOPO";
     foreach (var template in MapLayer.ActiveMapTemplates)
     foreach (var template in MapLayer.ActiveMapTemplates)
     {
     {

Latest revision as of 15:37, 3 January 2022

This page describes how to create a very simple Maria GDK map client.

Very simple map client

General

Note
  • Make sure that all Development Requirements are met!
  • You will need to include the TPG.MariaGDK NuGet package.
  • Sample code for this section is found in the MariaVerySimpleClient solution folder of the SampleProjects solution.
  • For general troubleshooting, see Development troubleshooting

Creating the Map Client

Create a new project

In Visual Studio, create a WPF Application project - VerySimpleMapClient - to be used for your map client.

Map Client Project

You will now have a new WPF window, MainWindow.xaml, with "code behind" file, MainWindow.xaml.cs.

Map Client Window

Set the title of the window to "Very Simple Map Client".

Add required NuGet packages

From the NuGet Package Manager, load the TPG.MariaGDK package, as described in Maria GDK Nuget Packages in Development Requirements.

Include MariaUserControl

  • Add MariaUserControl to the main window xaml.
  • Also add an eventhandler for the window closing event, in the xaml and code behind.
<Window x:Class="VerySimpleMapClient.MainWindow"
        . . .
        xmlns:mariaUserControl="clr-namespace:TPG.Maria.MariaUserControl;assembly=TPG.Maria.MariaUserControl"
        . . .
        Closing="WindowClosing">
    <Grid>
        <mariaUserControl:MariaUserControl Name="MariaCtrl" 
                                           IsPanNavigationVisible="True"
                                           IsScaleBarVisible="True"
                                           IsRulerVisible="True"/>
    </Grid>
</Window>
private void WindowClosing(object sender, CancelEventArgs e)
{
    MariaCtrl.Dispose();
}

Creating the Map Layer with Map Service Connection

Service Configuration Setup

Create service configuration for connections to the Catalog service and Template service as a minimum.

Add the following to your app.config file, after the startup section:

  <system.serviceModel>
    <bindings>
      <!-- Basic HTTP -->
      <basicHttpBinding>
        <binding name="myHttpBinding" 
                 maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" 
                 closeTimeout="00:10:00" openTimeout="00:10:00" 
                 receiveTimeout="00:10:00" sendTimeout="00:10:00">          
          <readerQuotas maxArrayLength="2147483647"/>
        </binding>
      </basicHttpBinding>           
    </bindings>

    <client>
      <!-- Catalog service HTTP  -->
      <endpoint name="MapCatalogService"
                address="http://tpg-mariagdkpro:9008/catalog"
                contract="TPG.GeoFramework.MapServiceInterfaces.IMapCatalogService"
                binding="basicHttpBinding" bindingConfiguration="myHttpBinding" />
 
      <!-- Template service HTTP -->
      <endpoint name="TemplateService"
                address="http://tpg-mariagdkpro:9008/maptemplates"
                contract="TPG.GeoFramework.MapTemplateServiceContracts.IMapTemplateService"
                binding="basicHttpBinding" bindingConfiguration="myHttpBinding" />     
    </client>

    <behaviors>
      <endpointBehaviors>
        <behavior name="myEndpointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <extensions></extensions>
  </system.serviceModel>

For more info, see Service Configuration

Include layer handling.

In the MainWindow constructor:

  • Initialize MariaCtrl
  • Initialize the binding and service client connetions:
  • Initialize the map- and minimap- layers, and add eventhandlers for the LayerInitialized event in each
   
private MariaMapLayerManager _mapLayerManager;

public IMariaMapLayer MapLayer { get; private set; }
public IMariaMapLayer MiniMapLayer { get; private set; }

public MainWindow()
{
    InitializeComponent();
    MariaCtrl.Layers = new ObservableCollection<IMariaLayer>();
    MariaCtrl.IsMiniMapVisible = true;
    MariaCtrl.IsPanNavigationVisible = true;
    MariaCtrl.IsCenterPositionIndicatorEnabled = true;
    MariaCtrl.IsRulerVisible = true;
    MariaCtrl.IsScaleBarVisible = true;

    // Service connection specified by app.config
    _mapLayerManager = new MariaMapLayerManager();

    MapLayer = new MapLayer(_mapLayerManager);
    MapLayer.LayerInitialized += OnMapLayerInitialized;
    MariaCtrl.Layers.Add(MapLayer);

    MiniMapLayer = new MapLayer(_mapLayerManager);
    MiniMapLayer.LayerInitialized += OnMiniMapLayerInitialized;
    MariaCtrl.MiniMapLayer = MiniMapLayer;
}

private void OnMapLayerInitialized()
{
    MariaCtrl.CenterScale = 100000;
    MariaCtrl.CenterPosition = new GeoPos(60, 10);

    MapLayer.ActiveMapTemplate = PreferredMapTemplate();
}
private void OnMiniMapLayerInitialized()
{
    MiniMapLayer.ActiveMapTemplate = PreferredMapTemplate();
}

private MapTemplate PreferredMapTemplate()
{
    var preferred = "TOPO";
    foreach (var template in MapLayer.ActiveMapTemplates)
    {
        if (template.Name == preferred)
            return template;
    }
    return MapLayer.ActiveMapTemplates.Any() ? MapLayer.ActiveMapTemplates.First() : null;
}

Running the project, the application window should look like this:

Very simple map client