Thursday, 31 March 2011

The definitive MapGuide/Google Maps integration FAQ

We seem to get this same question over and over again on the mapguide-users mailing list. So I hope this post will definitively answer this question once and for all so that we can have more productive and meaningful discussions. So let's cut to the chase.

Q: Can Google Maps be shown in the AJAX viewer?
A: The answer is: NO

Why? The main reasons are:
  1. The Google Maps API has very tight restrictions on how it is used. I wouldn't be surprised if you'd violate some clause in the Google Maps terms of service if you did significant hacking to the AJAX viewer to have it display Google Maps data.
  2. The AJAX viewer does not use the OpenLayers javascript library. OpenLayers is probably the only legit way to use display Google Maps data.

So simply put, give up on this idea and move on... to Fusion.

Q: Can we show Google Maps in fusion?
A: The answer is: YES

Q: Are there any catches?
A: The answer is also: YES. Your map definition needs to be in the popular spherical mercator coordinate system (CS-Map code: WGS84.PseudoMercator, EPSG code: 3857). If you modified the Map Definition's coordinate system, you have to re-project your initial view extents as well. Note that MapGuide Studio will automatically re-project these extents for you. For Maestro, you will have to figure out these coordinates yourself.

Q: What versions of MapGuide supports this Google Map integration?
A: MapGuide Open Source >= 2.1 or MapGuide Enteprise >= 2010. For MGOS 2.1 and MGE2011, this support needs to be manually hacked in. In newer versions, the support is built-in to the fusion framework and has matching editor support in Studio/Maestro.

Q: Can I enable Google Maps fusion support with MapGuide Studio/Maestro?
A: YES. MapGuide Studio/Maestro have specialized UIs to make this dead simple (See my blog post I made for my old company for how to do this in Studio). In Maestro, the UI is pretty similar.

Q: Why can't I see my Google Maps layers when I [Print / Save Map / Quick Plot ] in fusion?
A: Because this is by design and is also the same reason you won't see Yahoo or Bing layers too. All the aforementioned widgets uses MapGuide's rendering APIs which know nothing about Google Maps. To get these widgets to show Google Maps would probably be another ToS violation.

Q: How can I get Google style popups when I select an object?
A: Use an OpenLayers.Popup and display it on a function listening to Fusion's MAP_SELECTION_ON event. I'm not going to say anymore. Google searching should fill in the rest of the details.

So what if you can't or don't want to use Fusion? Well your only remaining avenue is a purely custom solution via the OpenLayers library (which supports both Google Maps and MapGuide). I won't say much more on this either because there are bajillions of differnent OpenLayers examples/blogs/discussions out there for you to get ideas on figuring out the rest.

Oh, and do read that ToS throughly too!

12 comments:

diego said...

Hi, Well i did a fusion aplication, do you knows whwew the ApplicationDefination is saved? where is saved my application created by Mestro?... I have been looking in ...OSGeo/Mapguide/Server/repositores but I can fine my proyect created..

So If you know where is and where i can get .ApplicationDefinition will be greats,

tnks friend.
PD: Im using Maestro 3.0 and MapGuide OpenSource 2.1, tnks..

Jackie Ng said...

It is saved as an Application Definition resource in the Site Explorer.

You can access this Application Definition by loading it's public url (The fusion editor tells you what this url is once you saved it)

Jacqueline said...

I find that the MapGuide layers are not visible over the Google Maps basemap. The MapGuide layers are visible in the overview map, but the google map is not visible. Do you have any suggestions as to why this may be? I can give you more information if it would help. Thanks so much.

Jackie Ng said...

Did you run the checklist?

a. Map Definition is in WGS84.PseudoMercator coordinate system?
b. Map Definition extents adjusted to WGS84.PseudoMercator coordinates? Studio will auto-convert extents, Maestro will not.

Jacqueline said...

When I try to select a coordinate system, the validate button does not release the 'OK' button. I have tried the WKT, coordinate system code (WGS84.PseudoMercator) and EPSG code (3857). None have release the OK button and allowed me to proceed. I have not found this coordinate system in the coordinate list. Is it included? Thank you for your help!

Jackie Ng said...

Only available in MapGuide Open Source 2.2 / MapGuide Enterprise 2011 and newer releases.

Older releases do not have this coordinate system

Jacqueline said...

I installed MapGuide Open Source 2.2 and was able to select the PseudoMercator projection. I also set the extents manually. My fusion application zooms to the correct extent but still shows only the google map in the main window and it shows only the mapguide map in the overview window. Do you have any othe suggestions? Thanks.

Jackie Ng said...

Do you see map image requests being made to the mapagent in the Net tab of firebug?

Jacqueline said...

I can see that the request is being made to the mapagent for the google map but it gets hung up. All the other requests for mapguide layers are succesful. In firefox, no basemap appears. In google chrome the map appears but with mo mapguide layers visible. It works great with Bing Maps. The link to your Application Development blog was really useful, i'm a noob if you haven't already realized.

Jackie Ng said...

It could be that Maestro is putting the Google Maps V2 url instead of the V3 url.

Google Maps V2 is probably deprecated now which could be why it no longer works.

Finally, being a noob is okay. We're all noobs at one point in time, myself included :) What's important is knowing enough to no longer be one.

Jacqueline said...

Problem solved: You were right about the API key. Google Maps version 3 doesn't use one so the Maestro generated XML code is no longer correct. If you select 'edit as XML' and scroll to the bottom of the file where it calls the GoogleScript, edit the line to be:

http://maps.google.com/maps/api/js?sensor=false"></script>


Success! Thank you very much for your help.

fhocosta said...

Hi!
Could you help me?
i was wondering... do you think it is possible to run the 'google maps search' inside the fusion as a widget?