wiki:maestro/MaestroAPI/samples/4.0/CreateRuntimeMap

Version 1 (modified by jng, 13 years ago) ( diff )

--

Creating and working with a Runtime Map

The IMappingService interface provides the means of creating and working with the runtime map.

The following example shows how to create a new RuntimeMap

(C#)

IServerConnection conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http", 
    "Username", "Administrator",
    "Password", "admin",
    "Url", "http://localhost/mapguide/mapagent/mapagent.fcgi");

//Create the Mapping Service. Some implementations of IServerConnection may not support this service, so
//its best to inspect the capability object of this connection to determine if this service type is supported
IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);

//Get our map definition
ResourceIdentifier resId = new ResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
IMapDefinition mdf = (IMapDefinition)conn.ResourceService.GetResource(resId.ToString());

//Calculate the meters per unit value, this requires the official MapGuide API. Otherwise, you need
//to know this value up-front in order to render images with this instance
double metersPerUnit = 1.0;
if (!string.IsNullOrEmpty(mdf.CoordinateSystem))
{
    MgCoordinateSystemFactory factory = new MgCoordinateSystemFactory();
    MgCoordinateSystem cs = factory.Create(mdf.CoordinateSystem);
    metersPerUnit = cs.ConvertCoordinateSystemUnitsToMeters(1.0);
}

//Generate our runtime map resource id. This must be session-based
ResourceIdentifier rtMapId = new ResourceIdentifier(resId.Name, ResourceTypes.RuntimeMap, conn.SessionID);

//Create the runtime map using our meters per unit value
RuntimeMap map = mapSvc.CreateRuntimeMap(rtMapId, mdf, metersPerUnit);

//Set some display parameters for this map
map.DisplayWidth = 1024;
map.DisplayHeight = 1024;
map.DisplayDpi = 96;

//We have to save it first before we can render from it or use any other API that requires this 
//current map state. Remember to call Save() everytime you change the state of the map
map.Save();

Note: See TracWiki for help on using the wiki.