[mapguide-users] MGOS 4 Final Release and GetLayers

David Bowen dbowenrci at gmail.com
Fri May 29 06:03:20 PDT 2026


Thanks Gordon. I tried commenting out the suggested line and it still
fails. When I run the following, $numberLayers comes back as 0:

            $sel = new MgSelection( $this->map );
            $sel->Open($this->resourceService,$mgMapID);
            $selLayers = $sel->GetLayers();
            $numberLayers = $selLayers->GetCount();

When I run the same script on the environment that has CodeIgniter still
installed, I get a result of 1. I'm not quite sure what's causing the issue
since the script looks similar between the two environments.

Any suggestions?

On Thu, May 28, 2026 at 11:47 AM Gordon Luckett <
gordon.luckett at arrowgeomatics.com> wrote:

> Perhaps this line is causing the issue?
>
> $this->originalSel = $sel->ToXml();
>
> I've just tested the GetLayers() and they work well.
>
> (after lauching from an InvokeURL in the Flexible Web Layout)
> $configFilePath = "C:\Program Files\OSGeo\MapGuide\Web\www\webconfig.ini";
> $mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['session']:
> $_GET['session'];
> $mapName = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['mapname']:
> $_GET['mapname'];
> MgInitializeWebTier($cofigFilePath);
> $userInfo = new MgUserInformation($mgSessionId);
> $siteConnection = new MgSiteConnection();
> $siteConnection->Open($userInfo);
> $resourceService = $siteConnection->CreateService(0);
> $featureService = $siteConnection->CreateService(2);
> $queryOptions = new MgFeatureQueryOptions();
>
> $map = new MgMap($siteConnection);
> $map->Open($mapName);
>         $selection = new MgSelection($map);
> $selection->Open($resourceService, $mapName);
>         $selectedLayers = $selection->GetLayers();
>       for ($i = 0; $i < $numberLayers; $i++)
>         {
>            $layer = $selectedLayers->GetItem($i);
>            $layerName = $layer->GetName();
>           echo $layerName . '<br>';
>       }
>
> Works well.
>
> gordon
>
>
> On Thu, May 28, 2026 at 11:27 AM David Bowen <dbowenrci at gmail.com> wrote:
>
>> Hello Gordon,
>>
>> Let me know if the following is what you're looking for. The script calls
>> the class Mg_initialize,, with the relevant sections below.
>>
>> init gets called when the class SelectionTools first gets initiated. the
>> function getMap gets called in the line you called out.
>>
>> function init( $MapName, $SessionId ) {
>>         $webconfig_ini ="PATH/OSGeo/MapGuide/Web/www/webconfig.ini";
>>         $mgMapID = $MapName;
>>         $mgSessionId = $SessionId;
>>
>>         try {
>>             MgInitializeWebTier( $webconfig_ini );
>>             $userInfo = new MgUserInformation( $mgSessionId );
>>             $this->siteConnection = new MgSiteConnection();
>>             $this->siteConnection->Open( $userInfo );
>>             $this->resourceService =
>> $this->siteConnection->CreateService( MgServiceType::ResourceService );
>>             $this->featureService = $this->siteConnection->CreateService(
>> MgServiceType::FeatureService );
>>             $this->map = new MgMap( $this->siteConnection );
>>             $this->map->Open( $mgMapID );
>>         } catch ( MgException $e ) {
>>             echo $e->GetMessage();
>>             echo $e->GetDetails();
>>             exit();
>>         }
>>     }
>>
>> function getMap() {
>>         return $this->map;
>>     }
>>
>> On Thu, May 28, 2026 at 9:15 AM Gordon Luckett <
>> gordon.luckett at arrowgeomatics.com> wrote:
>>
>>> I would be curious about the line:
>>>
>>> $this->MapGuideObject->getMap();
>>>
>>> Share this definition?
>>>
>>> On Mon, May 25, 2026 at 1:35 PM David Bowen via mapguide-users <
>>> mapguide-users at lists.osgeo.org> wrote:
>>>
>>>> We're updating our application from using an MVC framework to being a
>>>> PHP only application. We're getting an unexpected error when running a
>>>> spatial query that looks for corresponding data, from a specified layer,
>>>> that falls within a set distance of the geocoded coordinates. This
>>>> function worked as expected in the MVC framework and the only code change,
>>>> for this section of code, is how the MG_initialize library is loaded.
>>>>
>>>> Going through the function step-by-step, it appears that it's failing
>>>> when it attempts to retrieve the layers from MapGuide. Instead of returning
>>>> something, it's returning NULL. This triggers a Fusion error, where 1 of 2
>>>> different error messages are displayed.
>>>>
>>>> The first error message is:
>>>> Failed to retrieve message for "MgFileNotFoundException". Failed to
>>>> retrieve message for "MgFileIoErrNo". - MgInitializeWebTier line 155 file
>>>> C:\Workspace\mg-4.0\MgDev\Web\src\WebSupport\InitializeWebTier.cpp -
>>>> MgInitializeWebTierInternal line 116 file
>>>> C:\Workspace\mg-4.0\MgDev\Web\src\WebSupport\InitializeWebTier.cpp -
>>>> MgResources.LoadResources line 388 file
>>>> C:\Workspace\mg-4.0\MgDev\Common\Foundation\System\Resources.cpp -
>>>> MgResources.ParseFile line 632 file
>>>> C:\Workspace\mg-4.0\MgDev\Common\Foundation\System\Resources.cpp -
>>>> ByteSourceFileImpl.LoadFile line 127 file
>>>> C:\Workspace\mg-4.0\MgDev\Common\Foundation\System\ByteSourceFileImpl.cpp
>>>>
>>>> The second error message is:
>>>> Fatal error: Uncaught TypeError: extract(): Argument #1 ($array) must
>>>> be of type array, string given in PATH\map\view\page.php:116 Stack trace:
>>>> #0 PATH\map\view\page.php(116): extract() #1
>>>> PATH\maptools\sel_action.php(154): require_once('...') #2
>>>> PATH\maptools\sel_action.php(56): Sel_Action->selectionReport_ql() #3
>>>> PATH\maptools\sel_action.php(290): Sel_Action->__construct() #4 {main}
>>>> thrown in PATH\map\view\page.php on line 116
>>>>
>>>> The script is:
>>>> function __construct( $config ) {
>>>>         $mapName = $config[ 'mapname' ];
>>>>         $mgSessionID = $config[ 'mapsession' ];
>>>>         $this->mgMapID = $mapName;
>>>>         $this->mgSessionId = $mgSessionID;
>>>>         //Initialize a MapGuide object instance
>>>>         require_once('../library/mapguide/Mg_initialize.php');
>>>>         $this->MapGuideObject = new Mg_initialize();
>>>>         $this->MapGuideObject->init( $this->mgMapID, $this->mgSessionId
>>>> );
>>>> }
>>>>
>>>> function getSelection() {
>>>> $myMap = $this->MapGuideObject->getMap();
>>>>         $session = $this->mgSessionId;
>>>>         $mapName = $this->mgMapID;
>>>>         $objkeys = '';
>>>>         $errorMsg = null;
>>>>         $siteConnection = $this->MapGuideObject->getSiteConnection();
>>>>         // Get an instance of the Resource and Mapping Services and use
>>>> them to open the map and initialize a selection object.
>>>>         $resourceSrvc = $this->MapGuideObject->getResourceService();
>>>>         $featureSrvc = $this->MapGuideObject->getFeatureService();
>>>>         //Get selected map layers.
>>>>         $sel = new MgSelection( $myMap );
>>>>         $sel->Open( $resourceSrvc, $mapName );
>>>>         $this->originalSel = $sel->ToXml();
>>>>         // this is where it appears to fail
>>>>         $selLayers = $sel->GetLayers();
>>>>
>>>> //script continues but likely not relevant
>>>> }
>>>>
>>>> Any input would be greatly appreciated.
>>>> _______________________________________________
>>>> mapguide-users mailing list
>>>> mapguide-users at lists.osgeo.org
>>>> https://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20260529/1664e048/attachment.htm>


More information about the mapguide-users mailing list