Creating a Camera Based on a GIS Map

From SIMboxWiki
Jump to navigation Jump to search

In some cases, a COC may need to contain a map based on GIS data as opposed to a map (like satellite view) based on the terrain. This can be for creating a simple moving map, for example, for a GPS application or for showing the terrain in alternative views like ground radar, FLIR, etc.. A GIS map can also contain multiple layers so it can be used to display various types of information on top of the map itself. Rendering a GIS based map will usually provide better performance than rendering a satellite view based camera. In order to use it you can create a GIS map that shows a top view of the terrain.

Follow these steps to create a camera that is based on a GIS map.

  1. Create a COC project and attach it to the gauge where you want the map to appear. 
    Add #include "utl.Filesystem.h".
  2. Create a Mask region where you want the map to be displayed. This will enable you to rotate the AGI containing the map (described later) while maintaining the visible portion in the same place and orientation. Therefore the GIS map AGI (created later) should be larger than the mask. In this example we create a centered mask region with height and width of 100 pixels and place it on the gauge. Add this code to CreateDisplayObjects().
    agiRect GisCameraMask = { -50, -50, 100, 100 };
    m_hCameraMask = Agi::CreateMaskRegion(GisCameraMask, _T("GisCameraMask"));
  3. Create the AGI that shows a GIS map using the Agi::CreateGis interface. The following example creates an AGI with height and width of 200 pixels using the default GIS map included in the OpenFlight Vegas terrain. You will need to create your own GIS map file to suit your needs (see more details at the end of the article).
    Add this code to CreateDisplayObjects()
    wstring resourceDir = SimApi::Control::getResourcePathW();
    wstring mapPath= _T("GIS Data\\Terrain\\OpenFlight Vegas\\GIS\\");
    wstring gisMapFullPath = SimUtil::FileSystem::CombinePath(resourceDir, mapPath);
    m_hMapAgi = Agi::CreateGis(gisMapFullPath.c_str(),200,200,512,NULL, goCenter);
    Agi::GisSetExtent(m_hMapAgi,m_CamLeft, m_CamBottom, m_CamRight, m_CamTop );
  4. Place the mask on the gauge and the map AGI on the mask.
    Add this code to BuildDisplayObjectsHierarchyTree()
    Agi::Add(m_hCameraMask, _hParentElement);
    Agi::SetXY(m_hCameraMask, 0.00f, 0.00f);

    Agi::Add(m_hMapAgi, m_hCameraMask);
    Agi::SetXY(m_hMapAgi, 0.00f, 0.00f);
  5. The actual map area is larger than the map AGI size so to set the position of the map we used the interface: Agi::GisSetExtent(m_hMapAgi, Left, Bottom, Right, Top)
    This interface accepts the longitude and latitude of the edges of the map. In order to get them from the entity location, use the following code that updates COC member variables of type double. Updating these values will enable you to move the map Up/down/Left/Right. Call this function to initialize the map during init(). Set the m_ZoomLevel member value in the COC constructor. A value of 1.0 will mean that the map AGI will contain a square showing 2 degrees in both longitude and latitude. The visible portion will depend on the mask size.
  6. In the update() function of the COC you will need to update the map location and heading to match the movements of the entity.
    Note: Updating the map location every frame may degrade performance, so consider performing the update only every few frames as needed.
  7. In order to enable zooming in and out, create 2 user inputs that increase and decrease the value of m_ZoomLevel.

How to create your own GIS map

The GIS map should be created according to the GIS map standard and your own display needs. The process of creating a GIS map is detailed in the ‘Creating a new GIS map’ manual in the product documentation.

The GIS map file (.map format) the COC loads contains the definitions of the GIS layers in the map. You can see an example of the file system structure for the default GIS map supplied with the OpenFlight Vegas terrain at:

"Sitec\Resource\GIS Data\Terrain\OpenFlight Vegas\GIS\"

You will usually need a single layer file so the additional layers (Airports, Highways, Cities) defined in are not required. A single layer file requires only the following resources:

  1. The map itself in tiff format (usually inside ‘satellite_image’ directory). The path to the tiff file needs to be specified inside the layer definition.
  2. Fonts directory
  3. The fonts.lst file in the same directory

These files and directories should be placed somewhere under the Sitec\Resource directory and the map path used by ‘Agi::CreateGis’ should be adjusted accordingly.