[mapguide-users] Re: Dynamically Setting Initial Map Position and
Scale
pwong
previn.wong at sce.com
Tue Jun 14 19:00:03 EDT 2011
I know this thread has been going awhile, but I'm running into the same issue
as previous posts. The sample is in php, I'm using C#. I think I have the
equivalent in C#. When I run the application. I get an error "Invalid
repository type.". I have set the web layout to have a "custom initial
extent" in Studio. Using Ajax Viewer.
Here's the code.
String sessionId = "";
string WlXML = "";
MapGuideApi.MgInitializeWebTier(@"E:\MapWorld\Autodesk\MapGuideEnterprise2011\WebServerExtensions\www\webconfig.ini");
MgUserInformation cred = new MgUserInformation();
cred.SetMgUsernamePassword("User", "UserX");
MgSiteConnection site = new MgSiteConnection();
site.Open(cred);
MgSite site1 = site.GetSite();
sessionId = site1.CreateSession();
String strwebLayout =
"Library://MapWorld_V1/Common/Layouts/MapWorld_V1_Basic_Layout_3.WebLayout";
//Get an MgWebLayout object
MgWebLayout webLayout = null;
MgResourceService resourceSrvc =
site.CreateService(MgServiceType.ResourceService) as MgResourceService;
MgResourceIdentifier webLayoutId = new
MgResourceIdentifier(strwebLayout);
//create XML document to change values
MgByteReader wlreader =
resourceSrvc.GetResourceContent(webLayoutId);
WlXML = wlreader.ToString();
XmlDocument doc = new XmlDocument();
doc.LoadXml (WlXML);
foreach (XmlNode Xnode in doc.GetElementsByTagName("CenterX"))
{
Xnode.InnerText = "-117.9202";
}
foreach (XmlNode Ynode in doc.GetElementsByTagName("CenterY"))
{
Ynode.InnerText = "33.8270";
}
foreach (XmlNode Snode in doc.GetElementsByTagName("Scale"))
{
Snode.InnerText = "2000";
}
//save the xml changes and read into memory
MemoryStream StreamSave = new MemoryStream();
doc.Save(StreamSave);
byte[] byteArr = StreamSave.ToArray();
MgByteSource vByte = new MgByteSource(byteArr, byteArr.Length);
//create a new weblayout with the changed weblayout data stream
String SessionmapName = webLayoutId.GetName();
String SessionWebLayout = "Session:" + sessionId + "//" +
SessionmapName + ".WebLayout";
MgResourceIdentifier sessionResourceId = new
MgResourceIdentifier(SessionWebLayout);
resourceSrvc.SetResource(sessionResourceId, vByte.GetReader(),
null);
And here's the Frameset that contains the map.
<frameset rows="45,*" border="0" framespacing="0">
<frame NAME="FrameTool" SRC="/mapguide2011/MapWorld_V1/title_public.php"
SCROLLING="YES" MARGINWIDTH="0" MARGINHEIGHT="0" frameborder="1">
<frame
src="/mapguide2011/mapviewernet/ajaxviewer.aspx?SESSION=<%=
sessionId %>&WEBLAYOUT=<%= sessionResourceId %>" name="ViewerFrame" />
</frameset>
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Dynamically-Setting-Initial-Map-Position-and-Scale-tp1818865p6476494.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list