Maria globe client: Difference between revisions

From Maria GDK Wiki
Jump to navigation Jump to search
()
()
Line 37: Line 37:
=== Add view models ===
=== Add view models ===


* Add a view model class (''MainViewModel'') for communication with the Maria component, and another (''MapViewModel'') for map handling. Both including inheritance from ViewModelBase, for details see [[Map_interaction_client/Prepare_your_application_for_interactions|''Prepare your application for interactions'']].
* Add a view model class (''MainViewModel'') for communication with the Maria component, and another (''MapViewModel'') for map handling. Both including inheritance of '''''ViewModelBase''''', for details see [[Map_interaction_client/Prepare_your_application_for_interactions|''Prepare your application for interactions'']].


* Set the data context of your client window to the '''''MainViewModel''''', and implement an event handler for the '''''WindowClosing''''' event. For details see [[Basic map client|Maria Basic Map Client]].
* Set the data context of your client window to the '''''MainViewModel''''', and implement an event handler for the '''''WindowClosing''''' event. For details see [[Basic map client|Maria Basic Map Client]].


==== MainViewModel ====
=== MainViewModel ===
 
Extend the inheritances to include the '''''IMariaGlobeMapViewModel''''' and implement the interface.


Add the following fields, properties and constructor to the '''''MainViewModel''''':
<source lang="c#">
<source lang="c#">
private IMariaMapLayer _mapLayer;
public class MainViewModel : ViewModelBase, IMariaGlobeMapViewModel
private IMariaMapLayer _miniMapLayer;
{
    public IGlobeMapManager GlobeMapManager { get; }
    public IDrawObjectLayerFactory DrawObjectLayerFactory { get; private set; }
    public IGlobeMapViewModel GlobeMapViewModel { get; set; }
...
</source>


public MapViewModel MapViewModel { get; }
Add the following fields, properties:
public ObservableCollection<IMariaLayer> Layers { get; set; }


public IMapTemplateServiceClient MapTemplateServiceClient { get; private set; }
<source lang="c#">
public IMapCatalogServiceClient MapCatalogServiceClient { get; private set; }
. . .
public GlobeMapManager GlobeMapManager { get; }
    private IMariaMapLayer _mapLayer;
    private IMariaMapLayer _miniMapLayer;


internal MainViewModel()
    public MapViewModel MapViewModel { get; }
    public ObservableCollection<IMariaLayer> Layers { get; set; }
. . .
</source>
 
In the constructor:
* initialise the Layer property
* set up the map services
* create the GlobeMapManager
* create map layer, mini-map layer and add to the '''''Layers''''' property
* instanciate the MapViewModel
 
 
<source lang="c#">
...
public MainViewModel()
{
{
     Layers = new ObservableCollection<IMariaLayer>();
     Layers = new ObservableCollection<IMariaLayer>();
Line 63: Line 84:


     // Set up template client
     // Set up template client
     MapTemplateServiceClient = new MapTemplateServiceClientFactory(
     var mapTemplateServiceClient = new MapTemplateServiceClientFactory(
         bindingFactory,
         bindingFactory,
         endpointAddressFactory).New("http://tpg-geostore:9008/maptemplates", BindingType.BasicHttp);
         endpointAddressFactory).New("http://tpg-geostore:9008/maptemplates", BindingType.BasicHttp);


     // Set up catalog service client and connect to service
     // Set up catalog service client and connect to service
     MapCatalogServiceClient = new MapCatalogServiceClient(
     var mapCatalogServiceClient = new MapCatalogServiceClient(
         bindingFactory.New(BindingType.BasicHttp),
         bindingFactory.New(BindingType.BasicHttp),
         endpointAddressFactory.New("http://tpg-geostore:9008/catalog"));
         endpointAddressFactory.New("http://tpg-geostore:9008/catalog"));


 
     GlobeMapManager = new GlobeMapManager(mapCatalogServiceClient, mapTemplateServiceClient);
     GlobeMapManager = new GlobeMapManager(MapCatalogServiceClient, MapTemplateServiceClient);
     GlobeMapManager.TileCacheManager.MaxCacheSize = 250;
     GlobeMapManager.TileCacheManager.MaxCacheSize = 250;


     _mapLayer = new MapLayer(GlobeMapManager);
     _mapLayer = new MapLayer(GlobeMapManager);
     _miniMapLayer = new MapLayer(GlobeMapManager);
     _miniMapLayer = new MapLayer(GlobeMapManager);
    MapViewModel = new MapViewModel(_mapLayer, _miniMapLayer, this);
     Layers.Add(_mapLayer);
     Layers.Add(_mapLayer);
    MapViewModel = new MapViewModel(_mapLayer, _miniMapLayer);
}
}


</source>
</source>
Make the class disposable by including and implementing  '''''IDisposable'''''.
<source lang="c#">
...
public class MainViewModel : ViewModelBase, IMariaGlobeMapViewModel, IDisposable
{
...
    public void Dispose()
    {
        _mapLayer?.Dispose();
        _miniMapLayer?.Dispose();
        GlobeMapViewModel?.Dispose();
    }
</source>


==== MapViewModel ====
==== MapViewModel ====

Revision as of 10:15, 13 September 2019

This page describes how to create a Maria GDK map client utilising MariaGlobeMapControl with 2D and 3D visualisation of map, tracks and draw objects.

Maria Globe Client

General

  • You will need to include the following NuGet package:
    • TPG.Maria.MariaGlobeMapControl (Currently available Teleplan Globe internal only)
  • Sample code is found in the MariaGlobeClient project, in the Sample Projects solution.
    • Note that the sample code is specifying the service connections in code, and not by app.config.

Utilising the globe control

Including MariaGlobeMapControl

Create a WPF Application, and add the necessary NuGet references. For details, see Maria Basic Map Client.

Add the MariaGlobeMapControl to the Main window xaml.

<Window x:Class="MariaGlobeClient.MainWindow"
        . . .
        Title="MariaGlobeClient" Height="600" Width="600">
    <Grid>
        <MariaGlobeMapControl x:Name="MariaGlobeCtrl" Background="#E9ECFA"                                                  
                              Is3DMode="False"
                              MouseMoveDistanceToStartTracking="0"
                              ZoomOnDblClick="False"
                              DegreeToLockRotateAndScale="2"
                              PercentageToLockScaleOnly="2.0"
                              IsProgressIndicatorVisible="False" />
    </Grid>
</Window>

Add view models

  • Add a view model class (MainViewModel) for communication with the Maria component, and another (MapViewModel) for map handling. Both including inheritance of ViewModelBase, for details see Prepare your application for interactions.
  • Set the data context of your client window to the MainViewModel, and implement an event handler for the WindowClosing event. For details see Maria Basic Map Client.

MainViewModel

Extend the inheritances to include the IMariaGlobeMapViewModel and implement the interface.

public class MainViewModel : ViewModelBase, IMariaGlobeMapViewModel
{
    public IGlobeMapManager GlobeMapManager { get; }
    public IDrawObjectLayerFactory DrawObjectLayerFactory { get; private set; }
    public IGlobeMapViewModel GlobeMapViewModel { get; set; }
...

Add the following fields, properties:

. . .
    private IMariaMapLayer _mapLayer;
    private IMariaMapLayer _miniMapLayer;

    public MapViewModel MapViewModel { get; }
    public ObservableCollection<IMariaLayer> Layers { get; set; }
. . .

In the constructor:

  • initialise the Layer property
  • set up the map services
  • create the GlobeMapManager
  • create map layer, mini-map layer and add to the Layers property
  • instanciate the MapViewModel


...
public MainViewModel()
{
    Layers = new ObservableCollection<IMariaLayer>();

    IBindingFactory bindingFactory = new BindingFactory();
    IEndpointAddressFactory endpointAddressFactory = new EndpointAddressFactory();

    // Set up template client
    var mapTemplateServiceClient = new MapTemplateServiceClientFactory(
        bindingFactory,
        endpointAddressFactory).New("http://tpg-geostore:9008/maptemplates", BindingType.BasicHttp);

    // Set up catalog service client and connect to service
    var mapCatalogServiceClient = new MapCatalogServiceClient(
        bindingFactory.New(BindingType.BasicHttp),
        endpointAddressFactory.New("http://tpg-geostore:9008/catalog"));

    GlobeMapManager = new GlobeMapManager(mapCatalogServiceClient, mapTemplateServiceClient);
    GlobeMapManager.TileCacheManager.MaxCacheSize = 250;

    _mapLayer = new MapLayer(GlobeMapManager);
    _miniMapLayer = new MapLayer(GlobeMapManager);
    Layers.Add(_mapLayer);

    MapViewModel = new MapViewModel(_mapLayer, _miniMapLayer);
}

Make the class disposable by including and implementing IDisposable.

...
 public class MainViewModel : ViewModelBase, IMariaGlobeMapViewModel, IDisposable
{
...
    public void Dispose()
    {
        _mapLayer?.Dispose();
        _miniMapLayer?.Dispose();
        GlobeMapViewModel?.Dispose();
    }


MapViewModel