| 47 | |
| 48 | (C#) |
| 49 | {{{ |
| 50 | import OSGeo.MapGuide.MaestroAPI; |
| 51 | ... |
| 52 | |
| 53 | //Read the setup, either from QueryString, Form, Cookies or hardcoded values |
| 54 | string username As = Request.Params("USERNAME") == null ? "Anonymous" : Request.Params("USERNAME"); |
| 55 | string password = Request.Params("PASSWORD") == null ? "" : Request.Params("PASSWORD"); |
| 56 | string layout = Request.Params("LAYOUT") == null ? "Library://MyLayout.WebLayout" : Request.Params("LAYOUT"); |
| 57 | string locale = Request.Params("LOCALE") == null ? "en" : Request.Params("LOCALE"); |
| 58 | |
| 59 | |
| 60 | //Setup connection |
| 61 | Uri host = new Uri("http://localhost/mapguide/mapagent/mapagent.fcgi"); |
| 62 | ServerConnectionI conn = new HttpServerConnection(host, username , password, locale, True); |
| 63 | |
| 64 | 'Obtain the weblayout and map |
| 65 | WebLayout weblayout = con.GetWebLayout(layout); |
| 66 | MapDefinition mapdefinition = con.GetMapDefinition(weblayout.Map.ResourceId); |
| 67 | |
| 68 | //Modify the initial view of the weblayout |
| 69 | weblayout.Map.InitialView = new MapViewType(); |
| 70 | weblayout.Map.InitialView.Scale = 2000 //Zoom to 1:2000 |
| 71 | weblayout.Map.InitialView.CenterX = (mapdefinition.Extents.MaxX - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinX; |
| 72 | weblayout.Map.InitialView.CenterY = (mapdefinition.Extents.MaxY - mapdefinition.Extents.MinX) + mapdefinition.Extents.MinY; |
| 73 | |
| 74 | //Obtain a unique session based id for the temporary weblayout (which is a copy of an existing WebLayout) |
| 75 | ResourceIdentifier tempid = new ResourceIdentifier(Guid.NewGuid(), OSGeo.MapGuide.MaestroAPI.ResourceTypes.WebLayout, con.SessionID); |
| 76 | |
| 77 | //Save the layout, otherwise you can't reference it |
| 78 | con.SaveResourceAs(weblayout, tempid); |
| 79 | |
| 80 | //Open the viewer, and use the temporary layout, since the map only exists in the |
| 81 | //current session, we must use that session, and NOT supply username/password |
| 82 | Response.Redirect("/mapguide/ajaxviewer/?LAYOUT=" + Server.UrlEncode(tempWebLayout) + "&SESSION=" + Server.UrlEncode(con.SessionID), true); |
| 83 | }}} |