[mapguide-users] Regarding Linking of Layers with Map at run time

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Mon Feb 16 03:15:37 EST 2009


Fusion is primarily a client side framework. The server side uses the 
MapGuide interface,
just as the MaestroAPI does, so there should be no problems using both.

You should note that the server code for Fusion is PHP only,
but you can still use .Net code at the same time.

Regards, Kenneth Skovhede, GEOGRAF A/S



ravinder.singh at BIRLASOFT.COM skrev:
>
> Thanks Kenneth I used the MaestroAPI. Now I am able to change my layer 
> at run time in the map.
>
> But I want to confirm whether the same API's work with fusion? Because 
> I will be making fusion application finally.
>
>  
>
> *Regards,*
>
> Ravinder
>
>  
>
> ------------------------------------------------------------------------
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Kenneth 
> Skovhede, GEOGRAF A/S
> *Sent:* Saturday, February 14, 2009 5:21 PM
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] Regarding Linking of Layers with Map 
> at run time
>
>  
>
> I can't guess what you are trying to achieve with the code.
> MaestroAPI is not the only way, you can use the native API like you do,
> but you have to handle all the quirks yourself, which is not a trivial 
> task.
>
> This line is not valid C#:
>         MgResourceIdentifier webLayoutId = new 
> MgResourceIdentifier("Library:// Samples/ Sheboygan 
> /Layouts\BasicLayout.WebLayout");
>
> \B is not a valid string escape sequence, and there seems to be some 
> spaces, which may come from the mail program.
>
> I think you can get a better understanding of the MaestroAPI from 
> these two examples:
> http://trac.osgeo.org/mapguide/wiki/maestro/MaestroAPI/samples/AddInitialLayer
> http://trac.osgeo.org/mapguide/wiki/maestro/MaestroAPI/samples/CustomizedZoomWithWebLayout
>
>
>
> This piece of code seems to ovewrite the runtime map, with the Sheboygan:
>
>         MgMap map = new MgMap();
>
>         MgResourceIdentifier resId = new
>
>         
> MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
>
>         String mapName = resId.GetName();
>
>         map.Create(resourceSrvc, resId, mapName);
>
>         MgResourceIdentifier mapStateId = new 
> MgResourceIdentifier("Session:" + sessionId + "//" + mapName + "." + 
> MgResourceType.Map);
>
>         map.Save(resourceSrvc, mapStateId);
>
>
> This code seems to set the startup map in the library weblayout to the 
> sheboygan map:
>
>         MgResourceIdentifier webLayoutId = new 
> MgResourceIdentifier("Library:// Samples/ Sheboygan 
> /Layouts\BasicLayout.WebLayout");
>
>         MgByteReader byteReader = 
> resourceSrvc.GetResourceContent(webLayoutId);       
>
>         XmlDocument doc = new XmlDocument();
>
>         String xmlLayoutDef = byteReader.ToString();       
>
>         doc.LoadXml(xmlLayoutDef);
>
>         XmlNode parentNode = 
> doc.GetElementsByTagName("ResourceId").Item(0);
>
>         if (parentNode != null)
>
>         {
>
>             XmlNode mapRessource = 
> doc.SelectSingleNode("/WebLayout/Map/ResourceId");
>
>             if (mapRessource != null)
>
>             {
>
>                 mapRessource.InnerText = 
> "Library://Samples/Sheboygan/" + "Maps/Sheboygan" + 
> ".MapDefinition";                                                                
>
>
>                 String string1= doc.DocumentElement.OuterXml;
>
>                 resourceSrvc.SetResource(webLayoutId, new 
> MgByteReader(string1, "text/xml"), null);               
>
>             }
>
>         }     
>
>
> You cannot overwrite the runtime map, because the AJAX viewer always 
> overwrites the
> runtime map at startup, so the first segment of code has no effect.
> The last part seems correct, but the exception states that the xml is 
> broken in some way.
> I have seen others complain about the same problem, but I don't know 
> what happens.
> It seems that the SetResource or MgByteReader breaks the data in some way.
>
>
>
>
> Regards, Kenneth Skovhede, GEOGRAF A/S
>
>
>
> ravinder.singh at BIRLASOFT.COM <mailto:ravinder.singh at BIRLASOFT.COM> skrev:
>
> I have written the following code also, it uses xml and infact when 
> this code runs it runs perfectally without any problem, it does what I 
> wanted to do, it changes the map definition  in web layout, and it 
> runs perfectally if I run from maestro,  but when I try to run from my 
> .net page
>
>  
>
> <frame id="viewerFrame" frameborder="no" marginwidth="0" 
> marginheight="0" scrolling="no" 
> src="../mapviewernet/ajaxviewer.aspx?SESSION=<%=sessionId%>&WEBLAYOUT=<%=webLayout%>">
>
>  
>
> Then the problem comes. And it says the following error.
>
>  
>
> Type 'OSGeo.MapGuide.MgNullArgumentException' in Assembly 
> 'MapGuideDotNetApi, Version=2.0.0.2716, Culture=neutral, 
> PublicKeyToken=null' is not marked as serializable.
>
>  
>
> If I save the map once in maestro then the viewer also runs. I have 
> also tried to read the header of xml and passing in 
> resourceSrvc.SetResource as third parameter, the problem remains the same.
>
>  
>
> So I just want to confirm whether maestro API you suggested would be 
> the final and last way to do this thing, or some other way ? Because I 
> am not aware of using maestro api.
>
>  
>
>  
>
> //Here is my code
>
>  
>
> MgUserInformation userInfo_new = new MgUserInformation(sessionId);
>
>         MgSiteConnection siteConnection = new MgSiteConnection();
>
>         siteConnection.Open(userInfo_new);
>
>         MgResourceService resourceSrvc = 
> (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
>
>         MgMap map = new MgMap();
>
>         MgResourceIdentifier resId = new
>
>         
> MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
>
>         String mapName = resId.GetName();
>
>         map.Create(resourceSrvc, resId, mapName);
>
>         MgResourceIdentifier mapStateId = new 
> MgResourceIdentifier("Session:" + sessionId + "//" + mapName + "." + 
> MgResourceType.Map);
>
>         map.Save(resourceSrvc, mapStateId);
>
>         MgResourceIdentifier webLayoutId = new 
> MgResourceIdentifier("Library:// Samples/ Sheboygan 
> /Layouts\BasicLayout.WebLayout");
>
>         MgByteReader byteReader = 
> resourceSrvc.GetResourceContent(webLayoutId);       
>
>         XmlDocument doc = new XmlDocument();
>
>         String xmlLayoutDef = byteReader.ToString();       
>
>         doc.LoadXml(xmlLayoutDef);
>
>         XmlNode parentNode = 
> doc.GetElementsByTagName("ResourceId").Item(0);
>
>         if (parentNode != null)
>
>         {
>
>             XmlNode mapRessource = 
> doc.SelectSingleNode("/WebLayout/Map/ResourceId");
>
>             if (mapRessource != null)
>
>             {
>
>                 mapRessource.InnerText = 
> "Library://Samples/Sheboygan/" + "Maps/Sheboygan" + 
> ".MapDefinition";                                                                
>
>
>                 String string1= doc.DocumentElement.OuterXml;
>
>                 resourceSrvc.SetResource(webLayoutId, new 
> MgByteReader(string1, "text/xml"), null);               
>
>             }
>
>         }     
>
>  
>
>  
>
> *Regards,*
>
> Ravinder
>
> ------------------------------------------------------------------------
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> <mailto:mapguide-users-bounces at lists.osgeo.org> 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Kenneth 
> Skovhede, GEOGRAF A/S
> *Sent:* Saturday, February 14, 2009 4:33 PM
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] Regarding Linking of Layers with Map 
> at run time
>
>  
>
> The MgMap class represents a runtime map, not a MapDefinition.
> There is no such class a a MgMapDefinition, so you have to read/write 
> the xml.
> If you wish to use the standard viewer, you have to do this.
> I was very annoyed by this, so I created the MaestroAPI that has 
> classes for all the Xml documents,
> including the MapDefinition:
> http://trac.osgeo.org/mapguide/wiki/maestro/MaestroAPI
>
> If you start the viewer with an empty map, you can access the MgMap 
> object,
> and add layers as runtime layers, using the MgMap.Layers.Add method.
>
>
>
> Regards, Kenneth Skovhede, GEOGRAF A/S
>
>
>
> ravinder.singh at BIRLASOFT.COM <mailto:ravinder.singh at BIRLASOFT.COM> skrev:
>
> Hi Stefan,
>
>  
>
> I put the way you said but it gives the following error now.
>
>  
>
> Type 'OSGeo.MapGuide.MgXmlParserException' in Assembly 
> 'MapGuideDotNetApi, Version=2.0.0.2716, Culture=neutral, 
> PublicKeyToken=null' is not marked as serializable.
>
>  
>
> *Regards,*
>
> Ravinder Singh
>
> ------------------------------------------------------------------------
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> <mailto:mapguide-users-bounces at lists.osgeo.org> 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Stefan 
> Dalakov
> *Sent:* Friday, February 13, 2009 11:10 PM
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] Regarding Linking of Layers with Map 
> at run time
>
>  
>
> Try
> MgResourceIdentifier mapName = new MgResourceIdentifier("Session:" + 
> sessionId + "//Sheboygan.MapDefinition");
>
>
> Stefan Dalakov
>
> ravinder.singh at BIRLASOFT.COM <mailto:ravinder.singh at BIRLASOFT.COM> wrote:
>
> Hi All,
>
>  
>
> I have created the map definition in maestro and also created a web 
> layout, and I have hundreds of Maps, and each map will have a single 
> layer, but I don't want to create the hundreds of maps for each single 
> layer. For that purpose I though I will just make a single map and 
> will associate the layer at run time to that map. So I wrote the 
> following set of code for Sheboygan sample
>
>  
>
> But when I reach to map.Save(resourceSrvc, mapName)
>
>  
>
> it gives me the error
>
>  
>
> MgXmlParserException {"An exception occurred in the XML parser."}
>
>  
>
> And also I tried with Map.Open and then the following error comes
>
>  
>
> Resource was not found: 
> Session:b275c3b6-ffff-ffff-8000-001a4bb4a756_en_7F0000010AFC0AFB0AFA//Samples/Sheboygan/Sheboygan.MapDefinition
>
>  
>
> I have written the following code
>
>  
>
> MgUserInformation userInfo = new MgUserInformation(defaultUser, 
> defaultPassword);
>
>       MgSite site = new MgSite();
>
>       site.Open(userInfo);
>
>       sessionId = site.CreateSession();
>
> MgUserInformation userInfo_new = new MgUserInformation(sessionId);
>
>       MgSiteConnection siteConnection = new MgSiteConnection();
>
>       siteConnection.Open(userInfo_new);
>
> MgResourceService resourceSrvc = 
> (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);        
>
>
> MgResourceIdentifier mapName = new MgResourceIdentifier("Session:" + 
> sessionId + "//Samples/Sheboygan/Sheboygan.MapDefinition");
>
>       MgMap map = new MgMap();
>
>       map.Open(resourceSrvc, mapName); // Here the problem comes
>
>       map.Save(resourceSrvc, mapName); // Here the problem comes
>
>  
>
> I am using .net aspx with map guide 2.0
>
>  
>
> *Thanks & Regards,*
>
> Ravinder Singh
>
>  
>
> *********************************************************************************************************************************************************************
> "This message and any attachments are solely for the intended 
> recipient and may contain Birlasoft confidential or privileged 
> information. If you are not the intended recipient,any 
> disclosure,copying, use, or distribution of the information included 
> in this message and any attachments is
> prohibited. If you have received this communication in error, please 
> notify us by reply e-mail at (administrator at birlasoft.com 
> <mailto:administrator at birlasoft.com>) and permanently delete this 
> message and any attachments. Thank you."
> *********************************************************************************************************************************************************************
>
>  
>  
>  
>  
>  
>
>
> ------------------------------------------------------------------------
>
>
>  
>  
>  
>  
>  
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
>
>  
>
> *********************************************************************************************************************************************************************
> "This message and any attachments are solely for the intended 
> recipient and may contain Birlasoft confidential or privileged 
> information. If you are not the intended recipient,any 
> disclosure,copying, use, or distribution of the information included 
> in this message and any attachments is
> prohibited. If you have received this communication in error, please 
> notify us by reply e-mail at (administrator at birlasoft.com 
> <mailto:administrator at birlasoft.com>) and permanently delete this 
> message and any attachments. Thank you."
> *********************************************************************************************************************************************************************
>
>  
>  
>  
>
>
> ------------------------------------------------------------------------
>
>
>  
>  
>  
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
>
> *********************************************************************************************************************************************************************
> "This message and any attachments are solely for the intended 
> recipient and may contain Birlasoft confidential or privileged 
> information. If you are not the intended recipient,any 
> disclosure,copying, use, or distribution of the information included 
> in this message and any attachments is
> prohibited. If you have received this communication in error, please 
> notify us by reply e-mail at (administrator at birlasoft.com 
> <mailto:administrator at birlasoft.com>) and permanently delete this 
> message and any attachments. Thank you."
> *********************************************************************************************************************************************************************
>
>  
>
>
> ------------------------------------------------------------------------
>
>
>  
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
> *********************************************************************************************************************************************************************
> "This message and any attachments are solely for the intended 
> recipient and may contain Birlasoft confidential or privileged 
> information. If you are not the intended recipient,any 
> disclosure,copying, use, or distribution of the information included 
> in this message and any attachments is
> prohibited. If you have received this communication in error, please 
> notify us by reply e-mail at (administrator at birlasoft.com) and 
> permanently delete this message and any attachments. Thank you."
> *********************************************************************************************************************************************************************
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20090216/a6d71a20/attachment.html


More information about the mapguide-users mailing list