| 1 | = Creating and working with a Runtime Map = |
| 2 | |
| 3 | The IMappingService interface provides the means of creating and working with the runtime map. |
| 4 | |
| 5 | The following example shows how to create a new RuntimeMap |
| 6 | |
| 7 | (C#) |
| 8 | {{{ |
| 9 | |
| 10 | IServerConnection 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 |
| 17 | IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); |
| 18 | |
| 19 | //Get our map definition |
| 20 | ResourceIdentifier resId = new ResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition"); |
| 21 | IMapDefinition 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 |
| 25 | double metersPerUnit = 1.0; |
| 26 | if (!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 |
| 34 | ResourceIdentifier rtMapId = new ResourceIdentifier(resId.Name, ResourceTypes.RuntimeMap, conn.SessionID); |
| 35 | |
| 36 | //Create the runtime map using our meters per unit value |
| 37 | RuntimeMap map = mapSvc.CreateRuntimeMap(rtMapId, mdf, metersPerUnit); |
| 38 | |
| 39 | //Set some display parameters for this map |
| 40 | map.DisplayWidth = 1024; |
| 41 | map.DisplayHeight = 1024; |
| 42 | map.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 |
| 46 | map.Save(); |
| 47 | |
| 48 | }}} |