Archive for January, 2007

KML Support in MapGuide 1.1.0

With the final 1.1.0 release of MapGuide Open Source just around the corner, I thought I’d talk about the initial support for KML 2.1 (Google Earth 4.0 or newer only) in this release.

Key Features:

  • Any Map Definition that you publish to the MapGuide server repository can be accessed as KML
  • KML 2.1 Regions are used, so you only serve data when necessary
  • Published scale ranges are honoured (to an approximate level with oblique views)
  • MapTips are published as feature descriptions

As an example, I’m going to use the default MapDefinition that comes with the Sheboygan sample data set (available on the MapGuide Open Source website).

Here is a picture of the map as it appears in Autodesk MapGuide Studio:

Sheboygan Map Definition in MapGuide Studio

This is the request I sent to the MapAgent to view this MapDefinition in Google Earth:

http://localhost:8008/mapguide/mapagent/mapagent.fcgi?
OPERATION=GetMapKml&
VERSION=1.0.0&
MAPDEFINITION=Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition

Which gave me the following KML:

Sheboygan Map Definition as KML

Which in turn looks like this in Google Earth:

Sheboygan Map Definition in Google Earth

Although you could just push out any of your maps to Google Earth, in practice you will likely want to create a special Map Definition just for GE so that you can account for some of the display limitations in Google Earth.

So, how do you publish your maps to Google Earth? Using the ever-helpful MapGuide MapAgent. The MapAgent is a URL-based web service which interacts with the MapGuide Server based on the parameters you pass. In the case of KML, the primary parameter that is important to you is OPERATION=GetMapKml. Full documentation for this parameter can be found on the KML in MapGuide RFC page, but the basics follow…

Required parameters:

  • OPERATION=GetMapKml - tells the MapAgent that you want a KML version of the Map Definition
  • VERSION=1.0.0 - can currently only be 1.0.0
  • MAPDEFINITION=<PathToYourMapDefinition> - path to your map definition in the repository. For example: Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition

Optional parameters:

  • FORMAT=<KML|KMZ|XML> - allows you to publish in either KML, compressed KML (KMZ) or, for easy debugging, XML
  • DPI=<default: 96> - is used to perform the viewer-to-map calculations required to honour the scale ranges defined in your map
  • USERNAME=<Anonymous or whatever you want> - (unsupported) can be used to prevent an authentication prompt on first request. Generating this initial request from a server-side script that creates a session is the preferred method.
  • PASSWORD=<no value for Anonymous, or whatever you want> - (unsupported) as above.

If you want to play around with these parameters some more to see what they do, the MapAgent test html pages that come with MapGuide 1.1.0 include test cases for the KML service. This can be found by default at http://localhost:8008/mapguide/mapagent/index.html .

If you have any questions about this functionality, or want to help expand the functionality offered by this tool, please join us in the MapGuide Open Source community.

-J

No Comments