September 15, 2010

Mapguide Enterprise 2011 – Fusion and Selection XML

Filed under: Mapguide,RADE — Tags: , , — Darrin Maidlow @ 3:00 pm

I’ve been working to migrate the  Mapguide 2010 code to work with 2011.  In 2010, I only implemented support for the DWF and Ajax viewer.  With the release of 2011, the new  ability to include mapping data from Google, Yahoo and Microsoft in Fusion are huge so I opted to migrate everything over.  The DWF viewer is already deprecated and I suspect the Ajax viewer will likely go next.

With 2010 and the Ajax viewer we had to get the selection from the MapFrame using the GetSelectionXML() method.  Then we had to encode, and send this value up to the web tier for processing.  I had all kinds of business logic that I was hoping to re-use with a minimal amount of modifications so I was trying to find how to recreate this functionality with Fusion.  I figured out how the selections worked on the client side using the new callback system and was getting the selection object – but I could not find anything definitively saying “There is no selection XML on the client side anymore”.    So…

There is no selection XML on the client side any more when using Fusion.

There I said it.  It makes sense too – first getting this large XML string and sending it up was a pain in the ass.  Encoding it, creating a form to submit it, etc.   I should have clued into this sooner – Fusion is updating the selection on the server side as needed. 

So in order to minimally impact the existing code – I added an additional check to some of the calls that looks a little something like this:

   1: if (String.IsNullOrEmpty(selectionXml))
   2: {
   3:     MgResourceService resSvc = (MgResourceService)siteConn.CreateService(MgServiceType.ResourceService);
   4:     sel.Open(resSvc, map.GetName());
   5:     selectionXml = sel.ToXml();
   6: }

Those four lines of code are a lot easier than all the screwing around needed in 2010 to get the selection XML.   With that small modification my existing code is working perfectly!

hope this helps someone =)


  1. This post is exactly the case I’m encountering. My application was using AJAX viewer. A .net page is submitted to taskPanelFrame part when a feature is selected. Now, I’m trying to change it to Fusion in MapGuide Enterprise 2011 and I didn’t figure out how to do same thing. I tried to create a dialog widget and have it show up by default; when you pick a feature on the map, some information can be shown up on the widget. That’s done by pure JavaScript. I wanted to collect section by JavaScript and pass it to a .net page. No success on this. How did you do that? Could you share some codes to me?

    Comment by Steven Wu — December 21, 2011 @ 2:06 pm

  2. Hi Steven,

    I apologize for the delay in replying. I took a couple of weeks off over the holidays with pretty much zero computer access. It was great! :)

    First off – I have to warn you that my Mapguide is a little rusty :). I’ve been working a lot in AutoCAD and with WCF client / server apps lately. If I understand what you’re trying to accomplish you want to update some controls on the page based on back end data and you need to get the selected key value(s) in order to run your business logic to retrieve the needed data. This is slightly different than what I was trying to accomplish. I was trying to port my Ajax viewer based code to Fusion. The only way to get the key values with the Ajax viewer was to get the selection XML and pass that into the server. As the post states this is not the way it works with fusion.

    Going from memory you have a couple of options. First, you could create some sort of web service call that is accessible via javascript. You could hook into the selectionOn event of the viewer. When the selection changes you could fire some javascript that hits this web server and talks to the server. The server would retrieve the selection and key values using the methodology defined in this post and return the needed data. This would allow you to create some ajax sexy that would refresh automagically on selection. You could also go for the form submit method here too with the screen refresh. I have never worked with Mapguide widgets though – I’ve opted in the development of the ChasmTech RADE application to make our UI the primary element and really we’re just displaying the map in the fusion window. All of our reporting and dialogs are handled in our own windowing system.

    It looks like the Mapguide Tutorial does a decent job of explaining some of the underlying principles you will need here including working with the selection in javascript. You can find that here

    Hope that helps!

    Comment by Darrin Maidlow — January 3, 2012 @ 6:53 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress