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


Ignore:
Timestamp:
11/22/11 04:22:02 (13 years ago)
Author:
jng
Comment:

--

Legend:

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

    v1 v2  
    11= Creating and working with a Runtime Map =
    22
    3 The IMappingService interface provides the means of creating and working with the runtime map.
     3The IMappingService interface provides the means of creating and working with the runtime map. Note that you must call Save() on the Runtime Map before using any API that operates on the Runtime Map (eg. Rendering)
    44
    55The following example shows how to create a new RuntimeMap
     
    4747
    4848}}}
     49
     50This 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{{{
     53Session:<session-id>://<map-name>.Map
     54}}}
     55
     56(C#)
     57{{{
     58
     59IServerConnection 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
     66IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
     67
     68ResourceIdentifier rtMapId = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID);
     69RuntimeMap rtMap = mapSvc.OpenMap(rtMapId);
     70
     71}}}
     72
     73This 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
     78IServerConnection 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
     85IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
     86
     87ResourceIdentifier rtMapId = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID);
     88RuntimeMap rtMap = mapSvc.OpenMap(rtMapId);
     89
     90//Toggle visibility of the Parcels layer
     91rtMap.Layers["Parcels"].Visible = false;
     92
     93//Any changes to map state require calling Save()
     94rtMap.Save();
     95
     96}}}
     97
     98This example shows how to render an opened Runtime Map to a file
     99
     100(C#)
     101{{{
     102
     103IServerConnection 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
     110IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
     111
     112ResourceIdentifier rtMapId = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID);
     113RuntimeMap rtMap = mapSvc.OpenMap(rtMapId);
     114
     115using(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}}}