MapGuide API Reference
 All Classes Functions Variables Enumerations Enumerator Friends
MgMap Class Reference

Defines the runtime state of a map. More...

+ Inheritance diagram for MgMap:

List of all members.

Public Types

enum  WatermarkUsageType { WMS = 1, Viewer = 2 }
 Watermark usage environment.
WMS - Usage WMS watermark.
Viewer - Use Viewer watermark. More...

Public Member Functions

virtual void Create (MgResourceIdentifier *resource, CREFSTRING mapName)
 Initializes a new MgMap object given a map definition or tile set definition and a name for the map. This method is used for MapGuide Viewers or for offline map production.
virtual 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.
MgResourceIdentifierGetTileSetDefinition ()
 Returns the resource id of the Tile Set Definition that created this map, or the Tile Set Definition linked from the Map Definition used to created this map. If it was created from a Map Definition and that does not link to a Tile Set Definition, then NULL is returned.
INT32 GetWatermarkUsage ()
 Get the watermark usage.
 MgMap (MgSiteConnection *siteConnection)
 Constructs an MgMap object that takes an MgSiteConnection instance.
virtual void Open (CREFSTRING mapName)
 Loads the map object from a session repository.
void Save (MgResourceService *resourceService, MgResourceIdentifier *resourceId)
 Saves the Map using the specified resource service and resource identifier.
void Save ()
 Saves the Map.

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 a runtime map from a map definition
     $resourceID = new  MgResourceIdentifier('Library://Calgary/Maps/Calgary.MapDefinition');
     $map = new MgMap($site);
     $map->Create($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->GetExceptionMessage() . "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.";
 }

 /********************************************************************/
 ?>