[mapguide-users] re: flexible web layouts

Jason Birch Jason.Birch at nanaimo.ca
Sun Apr 19 21:39:17 EDT 2009


Hi,

Thanks for pointing out the example.

I had the same lack of success getting Google Maps to show up by using the methods outlined on DMSG's research blog.  It looked like I had everything right, but neither map would load.  I'd put it on a back burner until I had more time to play with it.

On the MGE site, they take a different path.  The ApplicationDefinition only contains the definition of a MapGuide map--which has been set to the Google Maps (Popular Visualization) and projects the underlying data on the fly--and InvokeScript widgets  that allow switching between streets, satellites, hybrid.  The real magic is in the HTML template.  There are three important things here:

- The Google Maps js is included at the top of the script

- The fusionInitialized callback registers addGoogleStuff() to be called when the map is loaded

- The addGoogleStuff() callback adds the google streets layer, sets the MapGuide layer to not be a base layer, turns off fractional zoom, and sets the google streets layer as the base layer.

The only really hard part of this (once it's figured out) appears to be setting the MapDefinition to use the Popular Visualisation projection and setting the extents.  You can grab the CS definition from the $wktGoogle variable in the attached script, and manually edit your MapDefinition's XML to use this as the CoordinateSystem.  Make sure to convert your " to " .  You can also extract the extents of an existing layer in the Popular Visualization projection using the attached script; just edit the first couple lines to point to the location of your WebServerExtensions directory, and the resource ID of a layer that covers the entire extent of your area.

Jason

________________________________
From: girish kumar bv
Sent: Sunday, April 19, 2009 11:08 AM
Subject: [mapguide-users] re: flexible web layouts

Can anyone provide neccessary steps/procedure to integrate google maps with mapguide using flexible web layout. I tried through Application definition.xml but with no success

There is an example on http://enterprise.mapguide.com/landing/index.php
-------------- next part --------------
<?php

$featureResource = "Library://ParcelData.FeatureSource";

$installDir = 'C:/Program Files/OSGeo/MapGuide Web/';

$wktGoogle = '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]]';
$wktLL84 = 'GEOGCS["LL84",DATUM["WGS84",SPHEROID["WGS84",6378137.000,298.25722293]],PRIMEM["Greenwich",0],UNIT["Degree",0.01745329251994]]';

function getExtents($geom)
{

    try
    {

      $ll = $geom->GetLowerLeftCoordinate();
      $ur = $geom->GetUpperRightCoordinate();
      
      return array (
         'x1' => $ll->GetX(),
         'y1' => $ll->GetY(),
         'x2' => $ur->GetX(),
         'y2' => $ur->GetY()
         );

    }
    catch (MgException $e) {
      return NULL;
    }
    
}

try
{

require($installDir."/www/mapviewerphp/constants.php");

MgInitializeWebTier($installDir."www/webconfig.ini");

$agfReaderWriter = new MgAgfReaderWriter();
$wktReaderWriter = new MgWktReaderWriter();

$csFactory = new MgCoordinateSystemFactory();

$csGoogle = $csFactory->Create($wktGoogle);
$csLL84 = $csFactory->Create($wktLL84);

$user = new MgUserInformation("Anonymous", "");
$siteConnection = new MgSiteConnection();
$siteConnection->Open($user);

$featureService = $siteConnection->CreateService(MgServiceType::FeatureService);

$resourceID = new MgResourceIdentifier($featureResource);

$scReader = $featureService->GetSpatialContexts($resourceID,false);

$scReader->ReadNext();

$wktSourceCs = $scReader->GetCoordinateSystemWkt();
$csSource = $csFactory->Create($wktSourceCs);

$extentBinary = $scReader->GetExtent();

$extentAgfSource = $agfReaderWriter->Read($extentBinary)->Envelope();

$extentAgfLL84 = $agfReaderWriter->Read($extentBinary, $csFactory->GetTransform($csSource,$csLL84))->Envelope();

$extentAgfGoogle = $agfReaderWriter->Read($extentBinary, $csFactory->GetTransform($csSource,$csGoogle))->Envelope();

header('Content-type: text/plain');

print "Feature Source:\r\n\r\n";
print $featureResource;

print "\r\n\r\nSource Coordinates:\r\n\r\n";
print_r(getExtents($extentAgfSource));

print "\r\n\r\nLL84 Coordinates:\r\n\r\n";
print_r(getExtents($extentAgfLL84));

print "\r\n\r\nGoogle Coordinates:\r\n\r\n";
print_r(getExtents($extentAgfGoogle));

}
catch (MgException $e) {
    echo "ERROR: " . $e->GetMessage() . "\n";
    echo $e->GetDetails() . "\n";
    echo $e->GetStackTrace() . "\n";
    exit;
}

?>


More information about the mapguide-users mailing list