Integration of MapGuide and Google Maps (Integrate Google Maps into MapGuide Enterprise Fusion viewer)

Source: Internet
Author: User

As you know, Google Maps is more and more popular around the world. Is it possible to integrate Google Maps into my MapGuide Enterprise Fusion viewer as base map? Yes, it is!

As MapGuide Fusion viewer uses a subset of OpenLayers, it allows us to access to the underlying OpenLayers API. in this article, we will show you how to integrate Google Maps into our existing Fusion Viewer template. of cause, you can do that similarly to integrate Yahoo Maps or Virtual Earth Maps as well.

 

Firstly, we need to make a copy of our existing Fusion template, such as Slate.

Copy and rename C: \ Program Files \ Autodesk \ MapGuideEnterprise2010 \ WebServerExtensions \ www \ fusion \ templates \ mapguide \ slate as GoogleSlate at the same fold with slate.

And copy and rename C: \ Program Files \ Autodesk \ MapGuideEnterprise2010 \ WebServerExtensions \ www \ fusion \ templates \ mapguide \ slate. xml as GoogleSlate. xml at the same folder with slate. xml (Please note that the filename of xml shocould be same with the template folder ).

 

Secondly, we will make some changes in the GoogleSlate. xml. Open it in notepad or any other text editor you like, change the lines like this:

Code
<Name> GoogleSlate </Name>

<LocationUrl> fusion/templates/mapguide/GoogleSlate/index.html </LocationUrl>

<Description> GoogleSlate template </Description>

<PreviewImageUrl> fusion/templates/mapguide/GoogleSlate/preview.png </PreviewImageUrl>

 

Now, we need to add Google Maps in to this new template. to do that, we need to apply a Google Map API key. the Google Maps API lets you embed Google Maps in your own web pages with JavaScript. A single Maps API key is valid for a single "directory" or domain. you must have a Google Account to get a Maps API key, and your API key will be connected to your Google Account. you can refer to http://code.google.com/apis/maps/ for more information. when you are done with that, you will get a JavaScript library like this:

<Script src = 'HTTP: // maps.google.com/maps? File = api & amp; v = 2 & amp; key = comment '> </script>

 

Let's open the index.html in GoogleSlate folder using notepad, add the Google Maps API library before the fusion script library.

Code
<! -- Add the Google Map API Javascript llibrary -->

<Script src = 'HTTP: // maps.google.com/maps? File = api & amp; v = 2 & amp; key = comment '> </script>

<Script type = "text/javascript" src = "http://www.cnblogs.com/../lib/fusionSF-compressed.js"> </script>

We need to register a MAP_LOADED event for the map when fusion is initialized:

Code
Var fusionInitialized = function (){

$ ('Appcontainer'). resize ({forceResize: true });

$ ('Appcontainer'). style. visibility = 'notificable ';

// Register the MAP_LOADED event to load Google base map when map is loaded

// Firstly, we need to get the map widget object

Fusion. getWidgetById ('map'). registerForEvent (Fusion. Event. MAP_LOADED, addGoogleBaseMap );

}

Create the Map_LOADED event handler to the add Google Maps as base map:

Code
// Add the google map as base map

Var addGoogleBaseMap = function ()

{

Var mapWidget = Fusion. getWidgetById ('map ');

Var map = mapWidget. oMapOL;

MapWidget. fractionalZoom = false;

Map. setOptions ({fractionalZoom: false, numZoomLevels: 20 });

Var googleStreetsLayer = new OpenLayers. Layer. Google ('Google Streets ', {type: G_NORMAL_MAP, isBaseLayer: true, sphericalMercator: true });

Map. addLayer (googleStreetsLayer );

Map. setBaseLayer (googleStreetsLayer );

Var mgLayers = map. getLayersByClass ('openlayers. Layer. mapguide ');

If (mgLayers. length! = 0)

{

Var mgLayer = mgLayers [0];

If (mgLayer. isBaseLayer)

{

Map. setBaseLayer (googleStreetsLayer );

MgLayer. setIsBaseLayer (false );

MgLayer. setVisibility (true );

}

}

}

If you changed the preview. pgn and refresh in MapGuide Studio, you will find a new Fusion template (GoogleSlate) available now. if Studio is already running, the list of available templates can be refreshed by right-clicking in the display of templates, and selecting "Refresh ".

 

OK, we are almost there. you can put a map into this new template and try. but before that, there is still a one more thing we shoshould pay attention. as the Google Maps use EPSG: 3785 (Popular Visualisation CRS/Mercator) coordinate system, in order to make your map match with Google Maps perfectly, you showould use EPSG: 3785 in your map as well. you can change the WKT of coordinate system by editing the XML of MapDefiniation. the OpenSource tool Meastro can do that conveniently.

 

 

You can change the value of <CoordinateSystem> as below:

Code
<CoordinateSystem> PROJCS ["Popular Visualisation CRS/Mercator", GEOGCS ["Popular Visualisation CRS", DATUM ["Popular Visualisation Datum", SPHEROID ["Popular Visualisation Sphere", 6378137, 0, AUTHORITY ["EPSG", 7059], TOWGS84 [0, 0, 0, 0, 0, 0], AUTHORITY ["EPSG", 6055], PRIMEM ["Greenwich", 0, AUTHORITY ["EPSG", "8901"], UNIT ["degree", 0.0174532925199433, AUTHORITY ["EPSG", "9102"], AXIS ["E", EAST], AXIS ["N", NORTH], AUTHORITY ["EPSG", 4055], PROJECTION ["Mercator"], PARAMETER ["False_Easting", 0], PARAMETER ["False_Northing", 0], PARAMETER ["Central_Meridian", 0], PARAMETER ["Latitude_of_origin", 0], UNIT ["metre", 1, AUTHORITY ["EPSG", "9001"], AXIS ["East", EAST], AXIS ["North", NORTH], AUTHORITY ["EPSG", 3785] </CoordinateSystem>

 

Now, select the new template and set the map, and review, you shoshould see the Google Maps is integrated into your map allocation as base map. Is it cool? Try it now J

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.