Web API Reference MapGuide Open Source

MgMap Class Reference
[MgMap]

Inherits MgResource.

Inheritance diagram for MgMap:

Inheritance graph
[legend]
List of all members.

Detailed Description

Defines the runtime state of a map.

Remarks:
This corresponds with the state of the map as seen by the client. Note that this may differ from the MapDefinition stored in the resource repository. For example, the user may have altered the scale or hidden layers.
You can use the Save and Open methods to store the runtime state into the session repository and retrieve it from the session repository.

Example (PHP)
This example shows information about a map:
/// <?php
/// try
/// {
///     // Include constants like MgServiceType::ResourceService
///     include 'C:\\Inetpub\\wwwroot\\PhpMapAgent\\MgConstants.php';
///     // Initialize
///     MgInitializeWebTier('C:\\Inetpub\\wwwroot\\PhpMapAgent\\webconfig.ini');
///     // Establish a connection with a MapGuide site.
///     $user = new MgUserInformation('Administrator', 'admin');
///     $siteConnection = new MgSiteConnection();
///     $siteConnection->Open($user);
///     // Create a session repository
///     $site = $siteConnection->GetSite();
///     $sessionID = $site->CreateSession();
///     $user->SetMgSessionId($sessionID);
///     // Get an instance of the required services.
///     $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
///     $mappingService = $siteConnection->CreateService(MgServiceType::MappingService);
///
///     // Get a runtime map from a map definition
///     $resourceID = new  MgResourceIdentifier('Library://Calgary/Maps/Calgary.MapDefinition');
///     $map = new MgMap();
///     $map->Create($resourceService, $resourceID, 'Calgary');
///
///     // Show information about the map
///     echo "Name of map:               '" . $map->GetName() . "'n";
///     echo "   Session ID of map:      " . $map->GetSessionId() . "n";
///     echo "   Object ID:              " . $map->GetObjectId() . "n";
///
///     $envelope = $map->GetDataExtent();
///     echo "   Envelope:               ";
///     PrintEnvelope($envelope);
///
///     $extent = $map->GetMapExtent();
///     echo "   lower left coordinate:  ";
///     PrintCoordinate( $extent->GetLowerLeftCoordinate() );
///     echo "   upper right coordinate: " ;
///     PrintCoordinate( $extent->GetUpperRightCoordinate() );
///
///     $point = $map->GetViewCenter();
///     echo "   view center:            ";
///     PrintPoint($point);
///
///     echo "   View scale:             " . $map->GetViewScale() . "n";
///     echo "   Display dpi:            " . $map->GetDisplayDpi() . "n";
///     echo "   Display width:          " . $map->GetDisplayWidth() . "n";
///     echo "   Display height:         " . $map->GetDisplayHeight() . "n";
///
///     $layerCollection = $map->GetLayers();
///     echo "   Layers: n";
///     PrintLayerCollection( $layerCollection );
///
///     $layerGroupCollection = $map->GetLayerGroups();
///     echo "   Layer groups: n";
///     PrintLayerGroupCollection( $layerGroupCollection );
///
///     echo "   Finite display scales: n";
///     PrintFiniteDisplayScales( $map );
///
///     echo "Done n";
/// \}
/// catch (MgException $e)
/// {
///     echo "ERROR: " . $e->GetMessage() . "n";
///     echo $e->GetDetails() . "n";
///     echo $e->GetStackTrace() . "n";
/// \}
///
/// /********************************************************************/
/// function PrintEnvelope($envelope)
/// {
///     echo "depth = " . $envelope->GetDepth() . ", height = " . $envelope->GetHeight() . ", width = " . $envelope->GetWidth() . "n";
/// \}
///
/// /********************************************************************/
/// function PrintCoordinate($coordinate)
/// {
///     echo "(" . $coordinate->GetX() . ", " . $coordinate->GetY() . ", " . $coordinate->GetZ() . ") n";
/// \}
///
/// /********************************************************************/
/// function PrintPoint($point)
/// {
///     PrintCoordinate( $point->GetCoordinate() );
/// \}
///
/// /********************************************************************/
/// function PrintLayerCollection($layerCollection)
/// {
///     for ($i = 0; $i < $layerCollection->GetCount(); $i++)
///     {
///         $layer = $layerCollection->GetItem($i);
///         echo "      layer #" . ($i + 1) . ": n" ;
///         PrintLayer($layer);
///     }
/// \}
///
/// /********************************************************************/
/// function PrintLayer($layer)
/// {
///     echo "      name:                '" . $layer->GetName() . "'n";
///     $layerDefinition = $layer->GetLayerDefinition();
///     echo "      layer definition:    '" . $layerDefinition->ToString()  . "'n";
///     echo "      legend label:        '" . $layer->GetLegendLabel()  . "'n";
///     echo "      display in legend:   " . ConvertBooleanToString($layer->GetDisplayInLegend()) . "n";
///     echo "      expand in legend:    " . ConvertBooleanToString($layer->GetExpandInLegend()) . "n";
///     echo "      selectable:          " . ConvertBooleanToString($layer->GetSelectable()) . "n";
///     echo "      potentially visible: " . ConvertBooleanToString($layer->GetVisible()) . "n";
///     echo "      actually visible:    " . ConvertBooleanToString($layer->IsVisible()) . "n";
///     echo "      needs refresh:       " . ConvertBooleanToString($layer->NeedsRefresh()) . "n";
/// \}
///
/// /********************************************************************/
/// function PrintLayerGroupCollection($layerGroupCollection)
/// {
///     for ($i = 0; $i < $layerGroupCollection->GetCount(); $i++)
///     {
///         $layerGroup = $layerGroupCollection->GetItem($i);
///         echo "      layer group #" . ($i + 1) . ": " ;
///         PrintLayerGroup($layerGroup);
///     }
/// \}
///
/// /********************************************************************/
/// function PrintLayerGroup($layerGroup)
/// {
///     echo "      layer group name        '" . $layerGroup->GetName() . "'n";
///     echo "      display in legend:      " . ConvertBooleanToString($layerGroup->GetDisplayInLegend()) . "n";
///     echo "      expand in legend:       " . ConvertBooleanToString($layerGroup->GetExpandInLegend()) . "n";
///     $parentGroup = $layerGroup->GetGroup();
///     echo "      group                   " . $parentGroup->GetName() . "n";
///     echo "      legend label            " . $layerGroup->GetLegendLabel() . "n";
///     echo "      object ID               " . $layerGroup->GetObjectId() . "n";
///     echo "      potentially visible:    " . ConvertBooleanToString($layerGroup->GetVisible()) . "n";
///     echo "      actually visible:       " . ConvertBooleanToString($layerGroup->IsVisible()) . "n";
/// \}
///
/// /********************************************************************/
/// function PrintFiniteDisplayScales($map)
/// {
///     for ($i = 0; $i < $map->GetFiniteDisplayScaleCount(); $i++)
///     {
///         echo "      finite display scale #" . ($i + 1) . ": " . $map->GetFiniteDisplayScaleAt($i) . "'n";
///     }
/// \}
///
/// /********************************************************************/
/// // Converts a boolean to "yes" or "no".
/// function ConvertBooleanToString($boolean)
/// {
///     if (is_bool($boolean))
///         return ($boolean ? "yes" : "no");
///     else
///         return "ERROR in ConvertBooleanToString.";
/// \}
///
/// /********************************************************************/
/// ?>
/// 


Public Member Functions

void Create (CREFSTRING mapSRS, MgEnvelope *mapExtent, CREFSTRING mapName)
 Initializes a new Map object given a spatial reference system, spatial extent of the map, and a name for the map. This method is used for the WMS service implementation and creates a map without any layers.
void Create (MgResourceService *resourceService, MgResourceIdentifier *mapDefinition, CREFSTRING mapName)
 Initializes a new MgMap object given a resource service, map definition, and a name for the map. This method is used for MapGuide Viewers or for offline map production.
MgEnvelopeGetDataExtent ()
 Returns the extent of the data to be generated for the map in the spatial reference system of the map.
INT32 GetDisplayDpi ()
 Returns the number of dots per inch of the map display.
INT32 GetDisplayHeight ()
 Returns the current height of the map display in pixels.
INT32 GetDisplayWidth ()
 Returns the current width of the map display in pixels.
double GetFiniteDisplayScaleAt (INT32 index)
 Gets the finite display scale at the specified index.
INT32 GetFiniteDisplayScaleCount ()
 Gets the number of finite display scales in the map.
MgLayerGroupCollectionGetLayerGroups ()
 Returns this maps layer groups.
MgLayerCollectionGetLayers ()
 Returns this maps layers.
MgResourceIdentifierGetMapDefinition ()
 Returns the resource identifier that specifies the location of the map definition that was used to create this map.
MgEnvelopeGetMapExtent ()
 Returns the the overall extent of the map.
STRING GetMapSRS ()
 Gets the spatial reference system used to display this map.
STRING GetName ()
 Gets the name of this map.
STRING GetObjectId ()
 Gets an identifier that can be used to uniquely identify this map.
STRING GetSessionId ()
 Gets the identifier of the session associated with this map.
MgPointGetViewCenter ()
 Gets the current center point of the map, in the spatial reference system of the map.
double GetViewScale ()
 Gets the current scale of the map.
 MgMap ()
 Constructs an empty un-initialized MgMap object.
virtual void Open (MgResourceService *resourceService, CREFSTRING mapName)
 Loads the map object from a session repository.