Changes between Initial Version and Version 1 of maestro/MaestroAPI/samples/4.0/CreateRuntimeMap


Ignore:
Timestamp:
Nov 22, 2011, 4:10:15 AM (12 years ago)
Author:
jng
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • maestro/MaestroAPI/samples/4.0/CreateRuntimeMap

    v1 v1  
     1= Creating and working with a Runtime Map =
     2
     3The IMappingService interface provides the means of creating and working with the runtime map.
     4
     5The following example shows how to create a new RuntimeMap
     6
     7(C#)
     8{{{
     9
     10IServerConnection conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http",
     11    "Username", "Administrator",
     12    "Password", "admin",
     13    "Url", "http://localhost/mapguide/mapagent/mapagent.fcgi");
     14
     15//Create the Mapping Service. Some implementations of IServerConnection may not support this service, so
     16//its best to inspect the capability object of this connection to determine if this service type is supported
     17IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
     18
     19//Get our map definition
     20ResourceIdentifier resId = new ResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
     21IMapDefinition mdf = (IMapDefinition)conn.ResourceService.GetResource(resId.ToString());
     22
     23//Calculate the meters per unit value, this requires the official MapGuide API. Otherwise, you need
     24//to know this value up-front in order to render images with this instance
     25double metersPerUnit = 1.0;
     26if (!string.IsNullOrEmpty(mdf.CoordinateSystem))
     27{
     28    MgCoordinateSystemFactory factory = new MgCoordinateSystemFactory();
     29    MgCoordinateSystem cs = factory.Create(mdf.CoordinateSystem);
     30    metersPerUnit = cs.ConvertCoordinateSystemUnitsToMeters(1.0);
     31}
     32
     33//Generate our runtime map resource id. This must be session-based
     34ResourceIdentifier rtMapId = new ResourceIdentifier(resId.Name, ResourceTypes.RuntimeMap, conn.SessionID);
     35
     36//Create the runtime map using our meters per unit value
     37RuntimeMap map = mapSvc.CreateRuntimeMap(rtMapId, mdf, metersPerUnit);
     38
     39//Set some display parameters for this map
     40map.DisplayWidth = 1024;
     41map.DisplayHeight = 1024;
     42map.DisplayDpi = 96;
     43
     44//We have to save it first before we can render from it or use any other API that requires this
     45//current map state. Remember to call Save() everytime you change the state of the map
     46map.Save();
     47
     48}}}