Web API Reference | MapGuide Open Source |
Inherits MgMapBase.
Public Member Functions | |
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. | |
virtual void | Create (MgResourceIdentifier *mapDefinition, CREFSTRING mapName) |
Initializes a new MgMap object given a map definition and a name for the map. This method is used for MapGuide Viewers or for offline map production. | |
virtual 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. | |
MgMap (MgSiteConnection *siteConnection) | |
Constructs an MgMap object that takes an MgSiteConnection instance. | |
MgMap () | |
Constructs an empty un-initialized MgMap object. | |
virtual void | Open (CREFSTRING mapName) |
Loads the map object from a session repository. | |
virtual void | Open (MgResourceService *resourceService, CREFSTRING mapName) |
Loads the map object from a session repository. | |
void | Save () |
Saves the Map. | |
void | Save (MgResourceService *resourceService, MgResourceIdentifier *resourceId) |
Saves the Map using the specified resource service and resource identifier. | |
void | Save (MgResourceService *resourceService) |
Saves the Map using the specified resource service. |
<?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."; } /********************************************************************/ ?>