[Mapguide_users] Re: OnSelection Event?

Jim O'Leary joleary.public at gmail.com
Sun Jan 7 00:35:04 EST 2007


Does this code refresh the task pane each time a selection is made? I only
want this to happen for this application. If you are going to put a hook
into OnSelectionChanged(), would it not be better to have one that the
application can implement or not as it chooses?

At any rate, I understand from your example that you can pass the output of
getSelectionXML() on the client to the server, and instantiate a MGSelection
object with it. Using the MGSelection superclass method GetLayers(), you
then retrieve references to all of the layers that have been selected. With
that you can drive the API down to the properties. Here is my implementation
in PHP, using the getSelectionXML method of markupeditor.php in the recent
samples. The output of getSelectionXML() on the client is assigne to a form
variable with the name "selectionXML". Then on the server...

        $selection = new MgSelection($map,$_REQUEST['selectionXML']);
        $selectedLayers = $selection->GetLayers();
        $numberLayers = $selectedLayers->GetCount();
        $wktReaderWriter = new MgWktReaderWriter();  //for getPropertyValue
        $agfReaderWriter = new MgAgfReaderWriter();  // for getPropertyValue
        $featureService =
$this->site->CreateService(MgServiceType::FeatureService);        

        for ($i = 0; $i < $numberLayers; $i++)
        {
            $layer = $selectedLayers->GetItem($i);
            $layerName = $layer->GetName();
            // markupmanager.php has $markupLayer->SetName('_' .
$markupLayerResId->GetName());
            // so slice off the beginning _ to get the actual layer name in
the repository
            $layerName = substr($layerName,1);
            $resourceIdentifier = new
MgResourceIdentifier("Library://Wildlife/Data/$layerName.FeatureSource");
            $featureReader =
$featureService->SelectFeatures($resourceIdentifier,"MarkupSchema:Markup",$noQueryOptions);//
no query options
            while ($featureReader->ReadNext())
            {
                $propCount = $featureReader->GetPropertyCount();
                for($j=0; $j<$propCount; $j++)
                {
                    $propertyName = $featureReader->GetPropertyName($j);
                    $boolVal = $featureReader->IsNull($propertyName);
                    if ($boolVal) 
                    {
                         continue;
                    }// end if
                    $propertyType =
$featureReader->GetPropertyType($propertyName);
                    // GetPropertyValue is based on the
printPropertyValueFromFeatReader sample code in
                    // the MgFeatureReader Class Reference in Web API
Reference. See below.
                    $propertyValue =
getPropertyValue($featureReader,$propertyType,$propertyName);
                }// end propcount for
            }// end ReadNext while
        }// end numberLayers for


//-------------------------getPropertyValue
BEGINS---------------------------
/**
  * Gets data for a layer property
  */
function getPropertyValue(&$featureReader, $propertyType, $propertyName)
{
    global $agfReaderWriter;
    global $wktReaderWriter;
    switch ($propertyType) 
    {
        case MgPropertyType::Null :
            break;
          case MgPropertyType::Boolean :
                 $val = $featureReader->GetBoolean($propertyName);
                 $valStr = printBoolean($val);
                 break;
          case MgPropertyType::Byte :
                 $val = $featureReader->GetByte($propertyName);
                 break;
          case MgPropertyType::DateTime :
                 $val = $featureReader->GetDateTime($propertyName);
                 break;
          case MgPropertyType::Single :
                 $val = $featureReader->GetSingle($propertyName);
                 break;
          case MgPropertyType::Double :
                 $val = $featureReader->GetDouble($propertyName);
                 break;
          case MgPropertyType::Int16 :
                 $val = $featureReader->GetInt16($propertyName);
                 break;
          case MgPropertyType::Int32 :
                 $val = $featureReader->GetInt32($propertyName);
                 break;
          case MgPropertyType::Int64 :
                 $val = $featureReader->GetInt64($propertyName);
                 break;
          case MgPropertyType::String :
                 $val = $featureReader->GetString($propertyName);
                 break;
          case MgPropertyType::Blob :
                 fwrite($logFileHandle, "$propertyName is blobn");
                 break;
          case MgPropertyType::Clob :
                 break;
          case MgPropertyType::Feature :
                 $val = $featureReader->GetFeatureObject($propertyName);
                break;
          case MgPropertyType::Geometry :
                 break;
          case MgPropertyType::Raster :
                 $val = $featureReader->GetRaster($propertyName);
                 break;
       }// end switch
       return $val;
}//end of getPropertyValue
//------------------------------getPropertyValue
ENDS------------------------

Thanks for your help.



Kori Maleski-2 wrote:
> 
>  
> 
> Jim,
> 
> The following descripe the methods I use:
> 
> In the mainframe.templ, insert a function call in the OneSelectionChanged 
> Event:
> 
> function OnSelectionChanged() {
> 
>     var selCount = mapFrame.GetSelectedCount();
> 
>       SendSelection(); //ß------------------My new function call
> 
>     if(hasStatusbar == 1)
> 
>         sbFrame.SetFeatureSelectedMsg(FormatMessage((selCount > 
> 1? "__#FEATURESSELECTED#__": "__#FEATURESELECTED#__"), new Array
> (selCount, "unused")));
> 
>     var stateChanged = false;
> 
>     for(var i = 0; i < selectionAwareCmds.length; i++)
> 
> ...
> 
>  
> Then add your new function:
> 
>  function SendSelection() {
> 
>       var selCount = mapFrame.GetSelectedCount();
> 
>       if(selCount != 0){
> 
>              if(hasTaskpane != 0){
> 
>                   GetTaskFrame().GetTaskPane().location.href =
> homePage.replace
> ("/MapGuide/MapViewerNet/","") + "?SESSION=" + mapFrame.GetSessionId() 
> + "&LOCALE=" + locale + "&MAPNAME=" +
> encodeURIComponent(mapFrame.GetMapName
> ()) + "&SELECTION=" + mapFrame.GetSelectionXML();
> 
>             }
>          
>       }
> } 
> 
>  
> In this instance, the designated homepage of the taskpane will be sent the 
> specified UR parameters.
> 
> Following the edits to mainframe.templ – 
> 
> RESTART THE MAPGUIDE SERVER SERVICE – you may have to restart IIS or
> whatever 
> webserver you are using.
> 
> 
> In your recipient page (.NET flavour here:
> 
> 
> Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
> Handles MyBase.Load
> 
>  
>             Dim l_sSelect As String
>             Dim l_sMapName As String
>             Dim l_sSession As String
> 
>             l_sMapName = Request("MAPNAME")
>             l_sSession = Request("SESSION")
>             l_sSelect = Request("SELECTION")
> 
>             If l_sSelect <> "" Then
> 
>                 'connect to the site
>                 Dim l_oCred As New MgUserInformation(l_sSession)
>                 Dim l_oSite As New MgSiteConnection()
>                 l_oSite.Open(l_oCred)
>                 'create services
>                 Dim l_oFeatureSrvc As MgFeatureService =
> l_oSite.CreateService
> (MgServiceType.FeatureService)
>                 Dim l_oResourceSrvc As MgResourceService = 
> l_oSite.CreateService(MgServiceType.ResourceService)
>                 'Create a temporary map runtime object, locate the layer
>                 Dim l_oMap As New MgMap()
>                 l_oMap.Open(l_oResourceSrvc, l_sMapName)
>                 'Create a Selection object for the selection XML
>                 Dim l_oSel As MgSelection = New MgSelection(l_oMap,
> l_sSelect)
>                 Dim l_cSelLayers As MgReadOnlyLayerCollection = 
> l_oSel.GetLayers()
> 
> ...
>                
> 
> Then use the API to read the features as required.  
>  
> 
> Cheers,
> 
> Kori Maleski
> 
> 
> 
> Quoting Jim O'Leary <joleary.public at gmail.com>:
> 
>> 
>> Has anyone come up with a solution to the original question in this
>> thread?
>> How do you extract property names and values from the XML string that you
>> get either from GetSelectionXML? 
>> 
>> Jason's clever code (May 4, 2006) captures the map's OnSelectionChanged
>> event. You can then get the selections on the client side using
>> GetSelectionXML(), which yields something like: 
>> 
>> <?xml version="1.0" encoding="UTF-8"?><FeatureSet
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:noNamespaceSchemaLocation="FeatureSet-1.0.0.xsd"> <Layer
>> id="ea15105a-ffff-ffff-8003-00a0d13b3329">  <Class
>> id="MarkupSchema:Markup"> 
>> 
>> <ID>AQAAAA==</ID>  </Class> </Layer></FeatureSet> 
>> 
>> I'm assuming that you put the keys and values in this string in a query
>> string and submit a form to the server to recreate this XML string. You
>> could also write this XML to a uniquely named file and then pass the
>> filename to the server. 
>> 
>> Assuming that you can recreate this XML string one way or the other on
>> the
>> server, how do you then extract name = value pairs from the feature(s)
>> that
>> you have selected? 
>> 
>> Thanks. 
>> 
>> 
>> Willem Schwarte wrote:
>> > 
>> > I've just read the dev manual and want to try to create a little test
>> > program, to get me started on understanding the flow of events etc.. 
>> > 
>> >  
>> > 
>> > What I want is:
>> > 
>> >  
>> > 
>> > When something gets selected, read a property and call an asp-page in
>> > another frame (in short).
>> > 
>> >  
>> > 
>> > But how can I tell if something is selected?
>> > 
>> > I suppose there is no onSelectionChanged event like in MG6.5. So this
>> > would be done on a onClick? Where would I put the code for this?
>> > 
>> >  
>> > 
>> > Willem
>> > 
>> >  
>> > 
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/OnSelection-Event--tf1561860.html#a8199139
>> 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
>> 
> 
> 
> _______________________________________________
> 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/OnSelection-Event--tf1561860.html#a8201792
Sent from the MapGuide Users mailing list archive at Nabble.com.




More information about the Mapguide-users mailing list