Maps

A map (MgMap object) is created from a map definition resource. The map definition contains basic information about the map, including things like

- the coordinate system used in the map
- the initial map extents
- references to the layer definitions for layers in the map

When the MgMap object is created, it is initialized with data from the map definition. As a user interacts with the map, the MgMap may change, but the map definition does not.

The map is saved in the session repository so it is available to all pages in the same session. You cannot save a map in the library repository.

Map creation is handled by the Viewers. When a Viewer first loads, it creates a map in the session repository. The map name is taken from the map definition name. For example, if a web layout references a map definition named Sheboygan.MapDefinition, then the Viewer will create a map named Sheboygan.Map.

If your application does not use a Viewer, you can create the map and store it in the repository yourself. To do this, your page must

- Create an MgMap object.
- Initialize the MgMap object from a map definition.
- Assign a name to the MgMap object.
- Save the map in the session repository.

For example, the following section of code creates an MgMap object named Sheboygan.Map, based on Sheboygan.MapDefinition.

    $mapDefId = new MgResourceIdentifier(

      "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");

    $map = new MgMap();

    $mapName = $mapDefId->GetName();

    $map->Create($resourceService, $mapDefId, $mapName);

    $mapId = new MgResourceIdentifier(

      "Session:$sessionId//$mapName." . MgResourceType::Map);

    $map->Save($resourceService, $mapId);