| 49 | |
| 50 | This sample shows how to open an existing Runtime Map. If you want to open a runtime map created by the official API (ie. One created when loading a Web Layout or Application Definition), you will have to use a resource id of the following format: |
| 51 | |
| 52 | {{{ |
| 53 | Session:<session-id>://<map-name>.Map |
| 54 | }}} |
| 55 | |
| 56 | (C#) |
| 57 | {{{ |
| 58 | |
| 59 | IServerConnection conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http", |
| 60 | "Username", "Administrator", |
| 61 | "Password", "admin", |
| 62 | "Url", "http://localhost/mapguide/mapagent/mapagent.fcgi"); |
| 63 | |
| 64 | //Create the Mapping Service. Some implementations of IServerConnection may not support this service, so |
| 65 | //its best to inspect the capability object of this connection to determine if this service type is supported |
| 66 | IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); |
| 67 | |
| 68 | ResourceIdentifier rtMapId = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID); |
| 69 | RuntimeMap rtMap = mapSvc.OpenMap(rtMapId); |
| 70 | |
| 71 | }}} |
| 72 | |
| 73 | This samples shows to to manipulate the state of the runtime map. In this case, toggling the visibility of the Parcels layer |
| 74 | |
| 75 | (C#) |
| 76 | {{{ |
| 77 | |
| 78 | IServerConnection conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http", |
| 79 | "Username", "Administrator", |
| 80 | "Password", "admin", |
| 81 | "Url", "http://localhost/mapguide/mapagent/mapagent.fcgi"); |
| 82 | |
| 83 | //Create the Mapping Service. Some implementations of IServerConnection may not support this service, so |
| 84 | //its best to inspect the capability object of this connection to determine if this service type is supported |
| 85 | IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); |
| 86 | |
| 87 | ResourceIdentifier rtMapId = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID); |
| 88 | RuntimeMap rtMap = mapSvc.OpenMap(rtMapId); |
| 89 | |
| 90 | //Toggle visibility of the Parcels layer |
| 91 | rtMap.Layers["Parcels"].Visible = false; |
| 92 | |
| 93 | //Any changes to map state require calling Save() |
| 94 | rtMap.Save(); |
| 95 | |
| 96 | }}} |
| 97 | |
| 98 | This example shows how to render an opened Runtime Map to a file |
| 99 | |
| 100 | (C#) |
| 101 | {{{ |
| 102 | |
| 103 | IServerConnection conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http", |
| 104 | "Username", "Administrator", |
| 105 | "Password", "admin", |
| 106 | "Url", "http://localhost/mapguide/mapagent/mapagent.fcgi"); |
| 107 | |
| 108 | //Create the Mapping Service. Some implementations of IServerConnection may not support this service, so |
| 109 | //its best to inspect the capability object of this connection to determine if this service type is supported |
| 110 | IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); |
| 111 | |
| 112 | ResourceIdentifier rtMapId = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID); |
| 113 | RuntimeMap rtMap = mapSvc.OpenMap(rtMapId); |
| 114 | |
| 115 | using(Stream stream = mapSvc.RenderDynamicOverlay(map, null, "PNG")) |
| 116 | { |
| 117 | //Write this stream out to a file |
| 118 | using (var fs = new FileStream("RenderMap.png", FileMode.OpenOrCreate)) |
| 119 | { |
| 120 | int read = 0; |
| 121 | do |
| 122 | { |
| 123 | read = source.Read(buf, 0, buf.Length); |
| 124 | target.Write(buf, 0, read); |
| 125 | } while (read > 0); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | }}} |