Friday, 27 May 2011

Introducing the (re-vamped) Maestro API: Part 1

MapGuide Maestro may seem to be just an authoring application for MapGuide Open Source, but behind the scenes, it uses a set of core libraries that can do so much more. These libraries represent the Maestro API.

Before I talk about the Maestro API, I want to talk about the official MapGuide API that you should be familiar with by now.

The official MapGuide API that you use to create your MapGuide applications is a set of language wrappers (PHP/Java/.net) around the native MapGuide API as shown in the diagram below.



The MapGuide server has a large set of functionality that handles authoring and managing maps and spatial data. This functionality is only exposed through a few methods that allow reading and writing of Xml. The C++ classes communicate with the MapGuide server through dedicated TCP/IP ports.

This means that it is only possible to interact with servers on the local intranet (opening the port is not recommended for security reasons) and is the main reason why most applications using the official MapGuide API are either Web Applications or applications that reside on the MapGuide Web Tier.

So what is the Maestro API? To answer that I will need the assistance of a few diagrams.

Here's a diagram which may be familiar to some of you



Each client-tier application shown utilises services provided by the MapGuide Web Server Extensions.
  • Autodesk MapGuide Studio: Resource and Feature Service.
  • Google Earth: KML Service
  • AJAX Viewer / Fusion: Rendering, Tile and Mapping Services
As you can see from the diagram, MapGuide Maestro is a just another client-tier application consuming and utilising services exposed by the MapGuide Web Extensions.

What kind of services? Does this page look familiar to you?



This is the test pages for the mapagent. Every one of those links represents an element of the MapGuide API exposed over the web as a service operation by the MapGuide Web Extensions. You can invoke these operations by issuing standard HTTP GET and POST requests to the mapagent url.

Because invocation is done via HTTP and not via some custom or proprietary protocol, you can use any library that can send HTTP requests to talk to the MapGuide Web Extensions and thus create your own MapGuide client applications.

Before the Maestro API, writing a MapGuide client application would've taken lots of work to do even the basic things. Doing a simple GETRESOURCECONTENT operation would look something like this:

 string sessionId;
string url = ""http://localhost/mapguide/mapagent/mapagent.fcgi?OPERATION=GETRESOURCECONTENT&VERSION=1.0.0&SESSION=" + sessionId + "&RESOURCEID=Library://Samples/Sheboygan/Data/Parcels.FeatureSource";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
using(Stream st = resp.GetResponseStream())
{
//Read and process XML content inside this stream
}

A lot of boilerplate is required, from setting up the request/response, processing the response stream into a readable form and then more boilerplate with System.Xml.* classes to parse and process the XML content.

Enter the Maestro API, which abstracts away all of that boilerplate so you can do something like this instead.
 string username = ...;
string password = ...;
IServerConnection conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http",
"Url", "http://localhost/mapguide/mapagent/mapagent.fcgi",
"Username", username,
"Password", password);
IFeatureSource res = (IFeatureSource)conn.ResourceService.GetResource("Library://Samples/Sheboygan/Data/Parcels.FeatureSource);

The MaestroAPI conveniently exposes all the XML response structures in the MapGuide server as managed .Net classes and interfaces (notice how instead of a XML stream that needs manual processing, we get a strongly typed IFeatureSource interface).

The Maestro API reads and writes .net native streams and classes (so instead of an MgByteReader objects, you get System.IO.Stream objects or deserialized classes/interfaces). For example, this makes things like processing the result of a Rendering Service API much easier as a System.IO.Stream can be fed directly into a System.Drawing.Image object for display, whereas an MgByteReader requires manual extraction of its binary content that then has to be converted to a .net native form.

So in summary, the Maestro API is a class library wrapper for the mapagent that allows you to communicate with a MapGuide Server over the web using well-defined classes and interfaces. Because we only communicate over the web via HTTP, the Maestro API is also a 100% managed .net library using all the .net constructs and classes available to us, unlike the official MapGuide API which is a managed wrapper to native (C++) code. It is this quality of being pure managed code that makes the Maestro API usable in Mono and a reason why MapGuide Maestro also works in Linux and MacOSX.

All these features makes development of MapGuide Client Applications using the Maestro API incredibly easy and simple! If it's exposed in the mapagent, you can do it with the Maestro API!

Stay tuned for part 2, where I delve into the design of Maestro API and introduce the main classes in this API.

Thursday, 26 May 2011

Announcing: MapGuide Maestro 3.1 SDK

As I touched briefly in my previous post, complementing the 3.1 release of Maestro is the Maestro SDK allowing you to create your own applications using the Maestro API.

The Maestro SDK includes:
  • The Core Maestro API libraries
  • Maestro API documentation in CHM format
  • A set of C# Desktop/Web samples illustrating various uses of the Maestro API in different contexts.
New SDK releases will be made the same time I make new releases of Maestro.

As I promised 2 months ago, stay tuned for an in-depth overview of the (re-vamped) Maestro API, what it can do for you and how it differs from the official MapGuide API.

Download

Wednesday, 25 May 2011

Announcing: MapGuide Maestro 3.1

I am happy to announce the release of MapGuide Maestro 3.1

This release includes something that is noticeably absent in the 3.0 release: Documentation

This release now includes a user guide which is accessible via the Help application menu and also shows a random "tip of the day" on startup.

In terms of actual new features, there is:
  • A new command to view all the spatial contexts of a Feature Source (accessible from the context menu or the Feature Source editor)
  • Support in the Layer Definition editor for defining KML extrusions (MapGuide RFC16). Many thanks to James Murphy for supplying me the needed data to test this new feature.
And the usual assortment of fixes for bugs and issues reported since the 3.0 release

This is also the first release to include a separate SDK package for those who want to develop applications using the re-vamped Maestro API. This is in the final stages of preparation and I will make an announcement on this as soon as it is ready.

Download

Saturday, 30 April 2011

Announcing: MapGuide Maestro 3.0 Final

12 months, 145 tickets and 309 revisions later, I am happy to announce the final release of MapGuide Maestro 3.0 is now available.

This release includes the following changes from RC1:
  • Added missing editor support for creating and editing point styles that reference symbols from a symbol library
  • Added a more graceful way to handle unsupported element in a Load Procedure or Layer Definition when you open them in their respective specialized editors.
  • Added support for aliases when building GDAL configuration documents.
  • Many fixes from RC1.
For a comprehensive list of changes from the very beginning, see the changelog.

Download

Wednesday, 27 April 2011

The out-of-the-box MapGuide/FDO experience (or: Why the installer doesn't install all FDO providers by default)

When you install MapGuide Open Source, you have the choice of the following FDO providers to install:
  • ArcSDE
  • GDAL
  • Oracle (King.Oracle)
  • MySQL
  • ODBC
  • OGR
  • PostGIS (old one)
  • PostgreSQL (new one)
  • SDF
  • SHP
  • SQLite
  • MS SQL Server Spatial (>= 2008)
  • WFS
  • WMS
For those not astutely aware, the following provider options do not get installed by default:
  • ArcSDE
  • Oracle (King.Oracle)
  • MySQL
  • PostGIS (old one)
  • PostgreSQL (new one)
The reason for this is simple. These FDO providers require additional components that are not included with the MapGuide installer due to any of the following:
  • Licensing restrictions preventing component redistribution (ArcSDE)
  • Substantially increased installer footprint (Oracle)
  • The components that are bundled (if we did bundle them) may be older or newer than what is provided by your existing DBMS installation (MySQL, PostgreSQL)
  • Any combination of the above points.
So there is an implicit assumption that if you do enable any of the above FDO providers during installation, you will need to do some extra post-installation configuration to have a functioning FDO provider. This cannot be avoided.

So what exactly do you need to do for each provider?

For ArcSDE:
For Oracle:
For MySQL:
  • You need to ensure that libmysql.dll from your MySQL installation is either in the same directory as the FDO provider dll, or the path to libmysql.dll is in the PATH environment variable (which is what Windows will use to search for dlls that need to be loaded). If you are installing MapGuide on the same machine where MySQL is installed, you shouldn't need to do anything.
For PostgreSQL/PostGIS:
  • You need to ensure that libpq.dll (and its dependencies) from your PostgreSQL installation is either in the same directory as the FDO provider dll, or the path to libpq.dll is in the PATH environment variable (which is what Windows will use to search for dlls that need to be loaded). If you are installing MapGuide on the same machine where PostgreSQL is installed, you shouldn't need to do anything.
Still stuck? Well understand that the root problem for any of the above is that the FDO provider failed to find one or more dlls that it needs in order to properly function. You can use the Dependency Walker tool to determine if your FDO provider has all its dependencies satisfied and can be loaded without issues. Here's a screenshot of Dependency Walker on the King Oracle provider dll on a fresh MapGuide installation.


Notice the question mark on OCI.dll? OCI.dll is part of the Oracle Instant Client which the King.Oracle provider requires to properly function. A question mark indicates that this dll could not be found.

So the solution is to ensure that OCI.dll (and its dependencies) are located in a directory that Windows will search dlls for. Reloading the provider dll in Dependency Walker should no longer show a question mark beside OCI.dll meaning that the provider dll has all its dependencies satisfied, meaning this provider should now be fully functional.

One more thing about this: If you did have to carry out any of these extra configuration steps, remember to restart your MapGuide Server if it is already running.

So in summary:
  • Some FDO providers are not installed by default because they require additional components. These components are not bundled into the installer for reasons explained in this post.
  • This post should hopefully point you in the right direction to configure and troubleshoot these providers should you choose to install them.

Tuesday, 19 April 2011

Announcing: MapGuide Maestro 3.0 RC1

Here is 1st release candidate of Maestro 3.0

This release adds
  • Support for validating XML content against local XSD files in the XML editor
  • Coloring for active and inactive tabs
  • F2 keybinding to rename resources
  • A new option to determine whether validation is performed on save (default is: true)
  • More missing features from Maestro 2.x
And of course: many fixes for defects found in the previous beta and earlier releases.

Showstopper bugs withstanding, I will be releasing the final build of Maestro 3.0 sometime next week.

Download