Back to contents pageHow to select from a list the area shown on a visualization control

How to select from a list the area shown on a visualization control

Summary

This article shows how to add a drop-down list of areas to choose from, so that your visualization control shows that area, using the Ubisense .NET API.





Prerequisites

You should know the information in the following article:



Example material

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


Guide

Before you start, remember to:



1) Add a ToolStrip to your WinForm

Add a ToolStrip from the toolbox to your WinForm as shown. Leave its default name for this example, toolStrip1:





2) Create a Ubisense.UVis.ToolStripAreaCombo

This is a toolstrip combo box control that shows all the currently available building areas. Selecting an area from the combo box loads the area into the associated Ubisense.UVis.MapModel:


    Ubisense.UVis.ToolStripAreaCombo areas = new Ubisense.UVis.ToolStripAreaCombo();



3) Add the combo box to the toolstrip

Now add the newly created areas to the toolstrip that you added:


    toolStrip1.Items.Add(areas);



4) Set the map model to use

Ubisense.UVis.ToolStripAreaCombo instances have a public method SetModel which sets the map model to use for the available areas. Note that this method will throw an exception if there is no area to load. Create your map model and apply it to your visualization, then apply it to the Ubisense.UVis.ToolStripAreaCombo as follows:


    Ubisense.UVis.MapModel map = new Ubisense.UVis.MapModel();
    visualization1.Model = map;

    areas.SetModel(map);



5) Define your AreaChanged handler

You need to handle changes to which Ubisense.UBuilding.Area is selected in the combo box as follows:


    private void AreaChanged(Ubisense.UVis.ToolStripAreaCombo control,
        Ubisense.UBuilding.Area area, string name)
    {
        // Load the new area
        visualization1.Model.AreaCache.LoadArea(area);
    }



6) Add the AreaChanged handler

Add the AreaChanged handler that you defined in the previous section as follows. Note that you need to add this line before you call areas.SetModel if you want the map to show an area immediately:


    areas.AreaChanged +=
        new Ubisense.UVis.ToolStripAreaCombo.AreaChangedHandler(AreaChanged);

Now, when you run your application, selecting an area from the combo box will load that area into the visualization control. Remember that there are cases when the list of available areas is changed in another application, which this example does not attempt to handle.



Back to top