• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Autodesk MapGuide Enterprise Developer

    Reply
    Member
    FMSUSC
    Posts: 4
    Registered: ‎08-20-2010

    Highlight Object API

    623 Views, 2 Replies
    08-27-2010 04:05 PM

    Hello,

     

    I want to create a function that when I click the item ID on the right pane, which is a website created by PHP, the object on the map will hightlight.

     

    Could someone know what's the procedure of operating APIs. Which API function I can use to create a hightlight effect.

     

    Thanks

    Please use plain text.
    Mentor
    Posts: 238
    Registered: ‎10-06-2008

    Re: Highlight Object API

    08-29-2010 05:54 PM in reply to: FMSUSC

    Create a MgSelection, build your query whose filter matches your item ID. Call MgFeatureService.SelectFeatures with this query. Feed the MgFeatureReader to your MgSelection (using AddFeatures() method).

     

    Then call ToXml() on your MgSelection to get the XML selection string, and write that out as the parameter to your client-side javascript SetSelectionXML() viewer API call.

     

    - Jackie

    Please use plain text.
    Member
    FMSUSC
    Posts: 4
    Registered: ‎08-20-2010

    Re: Highlight Object API

    09-01-2010 02:45 PM in reply to: FMSUSC

    Thank you.

     

    I tried according to your procedure but still have some problem. However, according to my code, the Javascript show a error message "syntax error /../../mapviewernet/setselection.aspx There must be exactly one feature in the set", and the map not hight light the item. I attached here if some one can figure out the problem will be a great help.

     

    ------------- my code ---------------------------------------------------

    <?php
     try
     {
          // Initialize
         MgInitializeWebTier('C:\Program Files\Autodesk\MapGuideEnterprise2010\WebServerExtensions\www\webconfig.ini');
         // Establish a connection with a MapGuide site.
         $user = new MgUserInformation('Administrator', 'admin');
         $siteConnection = new MgSiteConnection();
         $siteConnection->Open($user);
         // Create a session repository
         $site = $siteConnection->GetSite();
         $sessionID = $site->CreateSession();
         $user->SetMgSessionId($sessionID);
         // Get an instance of the required services.
         $featureService=$siteConnection->CreateService(2);

         // Get a runtime map from a map definition

         $map = new MgMap();
         $query=new MgFeatureQueryOptions();
         $query->SetFilter("KEY='P9092'");

         $DataResId= new MgResourceIdentifier('Library://admin/Data/alldonorplaquesshp.FeatureSource');
         $FeatureReader=$featureService->SelectFeatures($DataResId, "alldonorplaquesshp",$query);
         $layer=$map->GetLayers()->GetItem('Donor Plaques');
         $selection=new Mgselection($map);
         $selection->AddFeatures($layer,$FeatureReader,0);
         $selectionXml=$selection->ToXml();
         echo "<p id='Xml'>$selectionXml</p>";
     }
     catch (MgException $e)
     {
         echo "ERROR: " . $e->GetMessage() . "n";
         echo $e->GetDetails() . "n";
         echo $e->GetStackTrace() . "n";
     }
    ?>

     

    <script language="javascript" type="text/javascript">
      var getXml=document.getElementById('Xml').innerHTML;
      document.write(getXml);
      opener.parent.parent.mapFrame.SetSelectionXML(getXml);
    </script>

    ------------------ end -------------------------

    I can get a string of $selectionXml, something like "9QEAAA==", is the xml correct?

     

    Thank you all.

     

    Please use plain text.