[mapguide-users] What is %24CurrentSelection???

Chris Claydon chris.claydon at autodesk.com
Tue Mar 17 10:48:04 EDT 2009


In a basic web layout, I'm pretty sure $CurrentSelection returns you the current selection in XML format. This corresponds to the string you get if you call ToXml() on an MgSelection object using the web tier API.

It appears that the flexible web layout code does not treat $CurrentSelection as a special case, and simply returns the URL-encoded version of variable name itself.

The solution is to get hold of the MgSelection object for the current map selection within the invoked PHP code. The following PHP code will dump out the selection XML. You should be able to extend it pretty easily to extract exactly what you need from the selection...

(Note that you may need to adjust the path to the webconfig.ini file in the call to MgInitializeWebTier)

Hope this helps,

Chris.

<?php
    
    $mapName = "";
    $sessionId = "";
        
    try 
    {
        // Initialize the web tier API
        MgInitializeWebTier("C:/Program Files/Autodesk/MapGuideEnterprise2009/WebServerExtensions/www/webconfig.ini");
        
        // Read the map name and session ID
        GetRequestParameters();

        // Create a site connection
        $user = new MgUserInformation($sessionId);
        $siteConnection = new MgSiteConnection();
        $siteConnection->Open($user);
        
        // Create a resource service instance
        $resourceService = $siteConnection->CreateService(0);
                
        // Retrieve the selection
        $selection = new MgSelection();
        $selection->Open($resourceService, $mapName);
        
        // Output the selection
        echo $selection->ToXml();
    }
    catch(MgException $e) 
    {
        // Output error details
        echo "<Message>" . $e->GetMessage() . "</Message>";
        echo "<Details>" . $e->GetDetails() . "</Details>";
    }
        
        
    function GetParameters($params)
    {
        global $mapName;
        global $sessionId;

        $mapName = $params['MAPNAME'];
        $sessionId = $params['SESSION'];
    }

    function GetRequestParameters()
    {
        if($_SERVER['REQUEST_METHOD'] == "POST")
            GetParameters($_POST);
        else
            GetParameters($_GET);
    }
?>



-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of achectl
Sent: Tuesday, March 17, 2009 3:16 AM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] What is %24CurrentSelection???


I would like to delineate how I do the invokeURL command as below:

My system:
MapGuide 2009
PHP bundle option
Window XP Pro
MapGuide Studio 2009

http://n2.nabble.com/file/n2490302/1.jpg 
1.	I use Sheboygan demo data 
2.	create the invokeurl commands of flexible web layout
3.	URL to invoke is http://127.0.0.1/date.php
4.	Key is the ID; Value is $CurrentSelection
5.	Layer is the Buildings (SDF)

http://n2.nabble.com/file/n2490302/2.jpg  
1.	Building selected
2.	InvokeURL command highlighted

http://n2.nabble.com/file/n2490302/3.jpg 
1.	New window prompted
2.	The url is http://127.0.0.1/date.php?ID=%24CurrentSelection

My question is why the ID value is %24CurrentSelection, it is not the ID of
the building layer attribute?
Or I have do wrong setting?

Notes: I have amended a little of invokeURL.js. I coped it as below:

/**
 * Fusion.Widget.InvokeURL
 *
 * $Id: $
 *
 * Copyright (c) 2007, DM Solutions Group Inc.
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
"Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */


/***************************************************************************
 * Class: Fusion.Widget.InvokeURL
 *
 * A widget that will open the configured URL in the target element.
 * 
 * If the Target property points to TaskPane widget, the task will be listed
in
 * the menu list of the TaskPane and loaded there.
 * Otherwise if the target is an existing HTML elementt in the page it will
be 
 * loaded there, otherwise it will open a new window with that name.
 *
 * **********************************************************************/

Fusion.Widget.InvokeURL = Class.create();
Fusion.Widget.InvokeURL.prototype = {
    sFeatures : 'menubar=yes,location=no,resizable=yes,status=yes',

    initialize : function(widgetTag) {
        //console.log('InvokeURL.initialize');
        Object.inheritFrom(this, Fusion.Widget.prototype, [widgetTag,
false]);
        Object.inheritFrom(this, Fusion.Tool.ButtonBase.prototype, []);

        var json = widgetTag.extension;
        this.sTarget = json.Target ? json.Target[0] : "InvokeUrlWindow";
        this.sBaseUrl = json.Url[0];  //must be supplied
        
        this.bSelectionOnly = (json.DisableIfSelectionEmpty &&
                           (json.DisableIfSelectionEmpty[0] == 'true' ||
                            json.DisableIfSelectionEmpty[0] == '1')) ? true
: false;
                            
        this.additionalParameters = [];
        if (json.AdditionalParameter) {
            for (var i=0; i<json.AdditionalParameter.length; i++) {
                var p = json.AdditionalParameter[i];
                var k = p.Key[0];
                var v = p.Value[0];
                this.additionalParameters.push(k+'='+encodeURIComponent(v));
            }
        }
        
        this.enable = Fusion.Widget.InvokeURL.prototype.enable;
        this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_ON,
this.enable.bind(this));
        this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_OFF,
this.enable.bind(this));
        this.disable();
    },

    enable: function() {
        var map = this.getMap();
        if (this.bSelectionOnly || !map) {
            if (map && map.hasSelection()) {
                if (this.action) {
                    this.action.setEnabled(true);
                } else {
                    Fusion.Tool.ButtonBase.prototype.enable.apply(this,[]);
                }
            } else {
                if (this.action) {
                    this.action.setEnabled(false);
                } else {
                    this.disable();
                }
            }
        } else {
            if (this.action) {
                this.action.setEnabled(true);
            } else {
                Fusion.Tool.ButtonBase.prototype.enable.apply(this,[]);
            }
        }
    },
    
    execute : function() {
        var url = this.sBaseUrl;
        //add in other parameters to the url here
        
        var map = this.getMap();
        var params = [];
        //params.push('LOCALE='+Fusion.locale);
        //params.push('SESSION='+map.getSessionID());
        //params.push('MAPNAME='+map.getMapName());
        params = params.concat(this.additionalParameters);
        if (url.indexOf('?') < 0) {
            url += '?';
        } else if (url.slice(-1) != '&') {
            url += '&';
        }
        url += params.join('&');
        var taskPaneTarget = Fusion.getWidgetById(this.sTarget);
        if ( taskPaneTarget ) {
            taskPaneTarget.setContent(url);
        } else {
            var pageElement = $(this.sTarget);
            if ( pageElement ) {
                pageElement.src = url;
            } else {
                window.open(url, this.sTarget, this.sFeatures);
            }
        }
    }
};

-- 
View this message in context: http://n2.nabble.com/What-is--24CurrentSelection----tp2490302p2490302.html
Sent from the MapGuide Users mailing list archive at Nabble.com.

_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users


More information about the mapguide-users mailing list