[mapguide-users] Newbie needs help with project to query web

Kenneth, GEOGRAF A/S ks at geograf.dk
Sat May 3 08:43:47 EDT 2008


You will have to use te C# API at some point.
The problem is that the map is loading by itself, and is outside the 
control of your application.
This means that it is difficult to detect when the map is ready.
You want to know when the map is ready, because you cannot modify the 
map before it is ready.
The javascript code registers a "selection changed" handler, which is 
installed when the map has loaded.
A very simple way of activating your selection code would be to have a 
hidden iframe, and reload it:
(A better way would be to use an AJAX call, which has less overhead.)
<iframe style="display: none" src="" id="maploaded" ></iframe>
<script>
function OnMapLoaded()
{
    document.getElementById('maploaded').src = 'maploaded.aspx';
}
</script>

In the code below, insert "OnMapLoaded();" instead of the comment below 
"InitDocument();"

You can then do selection handling and whatever in the "maploaded.aspx" 
page.
Once done, the page should output a javascript like:
<script>parent.mapFrame.Refresh();</script>
So the map display follows whatever modifications the C# code does.

Regards, Kenneth, GEOGRAF A/S



Nick Aizen skrev:
>
> Thanks, this is a big help, my question is about the java script code:
>
>  
>
> <!-- Javascript part -->
>
> <script type="text/javascript">
>
>     var mapFrame = null;   // A reference to the map frame
>
>     var originalMapFrameOnSelectionChanged = null // storage for the
>
> original onSelectionChanged function
>
>     function OnSelectionChanged() // when something is selected on the map
>
>     {
>
>         alert('Your handler works perfectly');
>
>         originalMapFrameOnSelectionChanged();
>
>     }
>
>  
>
>     function InitDocument()
>
>     {
>
>         var win = document.getElementById('viewerFrame');
>
>         if (win.contentWindow) //FF returns the actual tag, IE returns
>
> the iframe
>
>           win = win.contentWindow;
>
>         mapFrameRef = win.GetMapFrame();
>
>         originalMapFrameOnSelectionChanged =
>
> mapFrameRef.parent.OnSelectionChanged;
>
>         mapFrameRef.parent.OnSelectionChanged =
>
> OnSelectionChanged;            
>
>     } 
>
>  
>
>     function RetryInit()
>
>     {
>
>         if (mapFrame != null)
>
>             return;
>
>           
>
>         try
>
>         {
>
>             InitDocument();
>
>             //At this point, you can post a "PageLoaded" via a form or 
> AJAX
>
>         }
>
>         catch (e)
>
>         {
>
>             mapFrame = null;
>
>         }
>
>       
>
>         if (originalMapFrameOnSelectionChanged == null)
>
>         {
>
>             mapFrame = null;
>
>             window.setTimeout("RetryInit();", 500);
>
>         }
>
> </script>
>
>  
>
>  
>
> What does it actually do? I know this is not a java script tutoral, 
> was wondering how this intergrates with mapGuide. Could I just call a 
> C# function so I may use the MG API to manipulate the map?
>
>  
>
>  
>
> Regards,
>
>  
>
>  
>
> *Nick Aizen*
>
>  
>
>  
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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/20080503/8513c0ba/attachment.html


More information about the mapguide-users mailing list