[mapguide-users] RE: Custom OnSelection Events - a better way?

Brad L bradl at mai-eng.com
Thu Mar 1 14:50:57 EST 2007


in the page_load event I get the sessionID from the Params collection

Dim sessionID As String = Request.Params("sessionID")

I then call a custom class I wrote that gets the current selection

Dim MG As New MGInteract
Dim myUnit As Long = MG.get_Selected_Unit(sessionID)

The get_Selected_Unit function:
1. opens a MGsiteConnection using the passed sessionID
2. opens a MGMap
3. gets the MGSelection of the map
4. gets layer information from the selection
5. opens an MGFeatureReader
6. uses the readnext method of the MGFeatureReader to get the key of the
selected item
7. returns the key back to the calling page

With the key of the selected object in hand you can get the data you need
from your database and display it on the page.

I'm know there are other ways of doing this but this has worked well for me
to date, especially when you want to display information from a data source
(or consolidate multiple sources) outside of your weblayout and the defined
mapguide viewer.

Let me know if this helps.

Brad Leighninger
Mathews & Associates, Inc
417-869-6009


ctallman wrote:
> 
> Brad,
>  
> I've been messing with this code and I have a question. 
>  
> The page that your code forwards to, how does that page access the data
> from the selected object?  Do you use a query string request or is it
> easier than that?
>  
> Chris
> 
> ________________________________
> 
> From: mapguide-users-bounces at lists.osgeo.org
> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Brad
> Leighninger
> Sent: Wednesday, February 28, 2007 2:48 PM
> To: MapGuide Users Mail List
> Subject: RE: [mapguide-users] Custom OnSelection Events - a better way?
> 
> 
> 
> On that same post Jason Birch wrote an override for the
> OnSelectionChanged Event and placed it in the page where he called his
> viewer.
> 
>  
> 
> http://www.nabble.com/RE%3A-OnSelection-Event--p4242868s16610.html
> 
>  
> 
> This should modify the event to run custom code in that instance of the
> viewer only.
> 
>  
> 
> I modified it a bit to check to make sure only one item was selected and
> to send the sessionID to a custom page where the api is used to get the
> map and its selection set to display the data.  I think you need to use
> a full URL to call your custom page because a relative URL will be
> relative to the viewer application.  This has worked well for me in the
> AJAX viewer.  Jason stated that it will not work in the DWF viewer but I
> haven't tried it.
> 
>  
> 
> function MyOnSelectionChangedHandler()
> 
>         {
> 
>             originalOnSelectionChanged();
> 
>             var mapFrame=ViewerFrame.GetMapFrame();
> 
>             var selCount=mapFrame.GetSelectedCount();
> 
>             if(selCount==1)
> 
>             {
> 
>                 var sessionID=mapFrame.GetSessionId()
> parent.tabspage.selecteddetails.location.href="http://mysite/mypage.aspx
> ?sessionID="+sessionID
> 
>             }
> 
>         }
> 
>  
> 
> Brad Leighninger
> 
> Mathews & Associates, Inc.
> 
> 417-869-6009
> 
> ________________________________
> 
> From: mapguide-users-bounces at lists.osgeo.org
> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Buscher,
> Shane
> Sent: Wednesday, February 28, 2007 1:01 PM
> To: Mapguide_users at lists.osgeo.org
> Subject: [mapguide-users] Custom OnSelection Events - a better way?
> 
>  
> 
> I needed a way to capture a selected feature, get it's attributes, then
> show the results in the task frame.  I was able to achieve this by
> customizing the OnSelectionChanged javascript function in the
> mainframe.templ (thanks to Kori
> http://www.nabble.com/OnSelection-Event--tf1561860s16610.html#a4241783
> <http://www.nabble.com/OnSelection-Event--tf1561860s16610.html#a4241783>
> ).  The Viewer API does not expose this event, so the downside is that
> you're forced into modifying MapGuide source code that will get executed
> for all applications.   I'm developing in an enterprise environment, so
> I need to be careful with dabbling in 3rd party source code and want to
> avoid unexpected results with other applications that we'll write.  If I
> (or someone else) ever did a reinstall of the web extensions and forgot
> there was a customized mainframe.templ, we'd be hosed.  Is there any
> better way to handle this?
> 
> Regards,
> 
> Shane
> 
> 
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Custom-OnSelection-Events---a-better-way--tf3321037s16610.html#a9257121
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list