| 1 | |
| 2 | Commercial tiled map layers can be used as base layers within MapGuide flexible layouts, provided you make some modifications to your application and map projection. |
| 3 | |
| 4 | = What you will need = |
| 5 | * a commercial service api key |
| 6 | * A [http://mapguide.osgeo.org/ MapGuide 2.1 Server] |
| 7 | * [http://trac.osgeo.org/mapguide/wiki/maestro MapGuide Maestro] or familiarity with !MapGuide's !MapAgent utility. |
| 8 | * [https://mapguide.osgeo.org/download/releases/2.0.x-samples Sheboygan Sample data set] |
| 9 | |
| 10 | optional: |
| 11 | * [http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12299450 AutoDesk MapGuide Studio] |
| 12 | |
| 13 | = Getting Started = |
| 14 | |
| 15 | You will need to get a free key from a commercial mapping api provider. For Google maps, you can obtain one here: |
| 16 | |
| 17 | http://code.google.com/apis/maps/signup.html |
| 18 | |
| 19 | After submitting the request, you should get a sample script tag that looks like |
| 20 | {{{ |
| 21 | <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=<your key here>" type="text/javascript"></script> |
| 22 | }}} |
| 23 | |
| 24 | Note that the sensor argument has been set to false. |
| 25 | |
| 26 | If you haven't already done so, use the !MapGuide [http://localhost:8008/mapguide/mapadmin/login.php MapAdmin] page to load the Sheboygan sample data which will be used as an example overlay. |
| 27 | |
| 28 | = Step 1: Modify the application html = |
| 29 | |
| 30 | You can add a commercial base layer to any fusion application, but as an example we will modify the sample template that comes with MapGuide Open Source. |
| 31 | |
| 32 | You can find the template's index.html file in |
| 33 | {{{ |
| 34 | <MapGuide Install Directory>/WebServerExtensions/www/fusion/templates/mapguide/standard/ |
| 35 | }}} |
| 36 | |
| 37 | * Use a text editor to open the file and insert the script tag from the previous step right before the fusion tag: |
| 38 | {{{ |
| 39 | <script type="text/javascript" src="../../../lib/fusion.js"></script> |
| 40 | }}} |
| 41 | |
| 42 | = Step 2: Update the projection information in the !MapDefinition = |
| 43 | |
| 44 | Since the Google Map system uses a modified Mercator projection, any overlaid !MapGuide data needs to be transformed into the same map projection. !MapGuide can reproject vector data on the fly, meaning the original sample set can be used provided that we modify the !MapDefinition to use the Mercator output projection. |
| 45 | |
| 46 | * Using !MapGuide Maestro, connect to the !MapGuide server and make a duplicate of the /Samples/Sheboygan/Maps/Sheboygan !MapDefinition resource using the Edit menu copy and paste commands. Rename the copy to Sheboygan-m. |
| 47 | * Double click on the new file to open it and then click on the button next to 'Coordinate System' to bring up the Select Coordinate System dialog. Click the 'Type WKT code' radio button and then paste in the following definition: |
| 48 | {{{ |
| 49 | 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,0],AUTHORITY["EPSG","6055"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4055"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],AUTHORITY["EPSG","3785"],AXIS["X",EAST],AXIS["Y",NORTH]] |
| 50 | }}} |
| 51 | * Close the dialog box and then modify the Initial Map View coordinates so they make sense in the new projection: |
| 52 | |
| 53 | {{{ |
| 54 | Lower left X: -9774168, Y: 5415995 |
| 55 | }}} |
| 56 | {{{ |
| 57 | Upper right X: -9754637, Y: 5434757 |
| 58 | }}} |
| 59 | If you need to determine coordinates for your own data sets, you can convert them online using [http://proj4js.org Proj4js]. Pick the 'GOOGLE' CRS from the 'dest' list, enter your coordinates and click transform. |
| 60 | |
| 61 | You can use !AutoDesk !MapGuide Studio for the above steps by duplicating the !MapDefinition as above but picking 'Save as XML' from the file menu instead. The saved file can be edited in a text editor but you will then need to use the [http://localhost:8008/mapguide/mapagent/ MapAgent] interface to perform a !SetResource operation with the modified xml file. Studio does not have the correct projection built in and there is no way to add it to the !MapDefinition from application's user interface. !MapAgent can also be used to issue a !GetResource request to retrieve the initial xml file. |
| 62 | |
| 63 | = Step 3: Add a Google layer to the !ApplicationDefinition = |
| 64 | |
| 65 | * In the same folder as the index.html file, locate the !ApplicationDefinition.xml file and open it in your text editor. You may want to make a backup copy of the file with a different name. In the original file, replace the !MapSet tag contents with the following block: |
| 66 | {{{ |
| 67 | <MapGroup id="googleBase"> |
| 68 | <Map> |
| 69 | <Type>Google</Type> |
| 70 | <Extension> |
| 71 | <ResourceId>google</ResourceId> |
| 72 | </Extension> |
| 73 | </Map> |
| 74 | </MapGroup> |
| 75 | }}} |
| 76 | |
| 77 | * If you don't like the default Google map type, you can add an <Options> tag to the Google layer and change it: |
| 78 | |
| 79 | {{{ |
| 80 | G_NORMAL_MAP (default) : street map |
| 81 | G_PHYSICAL_MAP : terrain map |
| 82 | G_HYBRID_MAP : combined satellite and streets |
| 83 | G_SATELLITE_MAP : satellite map |
| 84 | }}} |
| 85 | |
| 86 | |
| 87 | i.e. |
| 88 | {{{ |
| 89 | <Map> |
| 90 | <Type>Google</Type> |
| 91 | <Extension> |
| 92 | <ResourceId>google</ResourceId> |
| 93 | <Options> |
| 94 | <type>G_PHYSICAL_MAP</type> |
| 95 | </Options> |
| 96 | </Extension> |
| 97 | </Map> |
| 98 | }}} |
| 99 | |
| 100 | * Add a second <Map> tag to your map group after the google <Map>. Take care that it remains within the <!MapGroup> tags. |
| 101 | |
| 102 | {{{ |
| 103 | <Map> |
| 104 | <Type>MapGuide</Type> |
| 105 | <SingleTile>true</SingleTile> |
| 106 | <Extension> |
| 107 | <Options> |
| 108 | <isBaseLayer>false</isBaseLayer> |
| 109 | </Options> |
| 110 | <ResourceId>Library://Samples/Sheboygan/Maps/Sheboygan-m.MapDefinition</ResourceId> |
| 111 | </Extension> |
| 112 | </Map> |
| 113 | }}} |
| 114 | |
| 115 | Note that the Google layer must be the base layer so any overlays must have the isBaseLayer: false option set. |
| 116 | |
| 117 | * Load the template in a browser: http://localhost:8008/mapguide/fusion/templates/mapguide/standard/ |