Back to contents pageHow to add a visualization control to an application

How to add a visualization control to an application

Summary

This article shows how to add a visualization control to your application using the Ubisense .NET API.





Prerequisites

You should know the information in the following articles:



Example material

Save this link to get a zip file of the example material


Guide

Before you start, remember to:

1) Add the visualization control to your toolbox and place it on your WinForm

To add a map component to your application you will actually be adding what Ubisense calls a visualization component. The component does not exist under your toolbox because you will need to add it. Right click on the Toolbox and choose 'Choose Items'. You will then need to browse to the UbisenseVisualization.dll found in C:\Program Files\Ubisense 2.1\bin. Once selected, you will then be able to add the component to the Toolbox.



Now it is as simple as dragging the component onto your form. At this point there are many things you can do with the map component but we will just highlight a few basics.





2) Initialize the visualization control

The Model property of the visualization should be set to an instance of a MapModel.


    namespace Visualization
    {
        public partial class Visualization : Form
        {
            public Visualization()
            {
                InitializeComponent();

                // Create a new MapModel
                visualization1.Model = new Ubisense.UVis.MapModel();

                // Other code ...

The visualization will view the area loaded in the model. The MapModel class has two overloaded methods. We can load an area by giving this method a Ubisense.UBuilding.Area instance or the name of the area we want to load.


    model.AreaCache.LoadArea("anArea");

    // OR

    model.AreaCache.LoadArea(areaObj);




3) Load an Area

The visualization control displays the area that is loaded into the model.

We could iterate over the contents of a building schema to find a suitable area to load. The following code loads the first area found:


    // Use a UBuilding.Contents cache client to find an area
    Ubisense.UBuilding.Contents.Schema building_schema = new
        Ubisense.UBuilding.Contents.Schema(false);
    building_schema.ConnectAsClient();

    // Iterate over the named areas in the database
    using (Ubisense.UBuilding.Contents.ReadTransaction xact =
        building_schema.ReadTransaction())
    {
        foreach (Ubisense.UBuilding.Contents.AreaProperties.RowType row in
            Ubisense.UBuilding.Contents.AreaProperties.name_(xact))
        {
            // Simply load the first area found
            visualization1.Model.AreaCache.LoadArea(row.name_.Name);
            break;
        }
    }

Note: You must handle the possible cases where the area has changed its name or there is not an area to load.


At this point you should switch off the "LoaderLock" managed debug assistant if you want to run a visualization in Visual Studio debug mode. This is a user option that is defined in a file that is not provided in the example source code. Click on "Debug > Exceptions", expand the "Managed Debug Assistants" list and un-check "LoaderLock".


When you run the example, the visualization control should now display the loaded area.



Default visualization control commands





Back to top