Thursday, July 24, 2008

Using Coldfusion with Mapguide Open Source

A long time ago, back in the old days, when Mapguide was only available as closed source, windows only commercial product, Coldfusion (4.x C++ days) was bundled for free along with Mapguide.

As a result there are a lot of spatial shops who (have) used Coldfusion. Mapguide Open Source doesn't list CFML as one of development languages supported, it does however, support Java.

To get access to the Mapguide API in Coldfusion it's quite easy, simply copy the following directories over into your Coldfusion lib directory (just make sure you choose to also install the java api when you install the webserver extentsions).

copy 'C:\Program Files\MapGuideOpenSource2.0\WebServerExtensions\www\WEB-INF\lib\*.*' C:\ColdFusion8\lib

copy 'C:\Program Files\MapGuideOpenSource2.0\WebServerExtensions\Tomcat\bin\*.*' C:\ColdFusion8\lib

Restart Coldfusion and then you can start to use the Mapguide WebApi

To get started, this is how you initialise the connection the Mapguide server in CFML


// Initialise the webtier connection
webconfigloc='C:\Program Files\MapGuideOpenSource2.0\WebServerExtensions\www\webconfig.ini';
MapGuideJavaApi=createObject("java","org.osgeo.mapguide.MapGuideJavaApi");
MapGuideJavaApi.MgInitializeWebTier(webconfigloc);

//Setup a session
mgUserInformation=createObject("java","org.osgeo.mapguide.MgUserInformation");
mgSiteConnection=createObject("java","org.osgeo.mapguide.MgSiteConnection");
mgUserInformation.setMgUsernamePassword(username, password);

//Create a session
mgSiteConnection.open(mgUserInformation);
session_Id=mgSiteConnection.GetSite().CreateSession();

//Get the resource service
resourceService=mgSiteConnection.CreateService(0);


The examples are pretty much all in PHP, but that's pretty easy to translate to CFML. With the above example, you can then simply dump the resourceService to see what's available.

No comments: