Mapping Service

The Mapping Service creates eMap and ePlot DWFs.

Generating an eMap DWF requires the DWF version and the URI of the map agent. Note that the HTTP header must include content length information, as in the following example.

    $dwfVersion = new MgDwfVersion("6.01", "1.2");

    $mapAgentUri =

      'http://localhost:8008/mapguide/mapagent/mapagent.exe';

    $byteReader = $mappingService->GenerateMap($map, $mapAgentUri,

      $dwfVersion);

    $outputBuffer = '';

    $buffer = '';

    while ($byteReader->Read($buffer, 50000) != 0)

    {

      $outputBuffer .= $buffer;

    }

    header('Content-Type: ' . $byteReader->GetMimeType());

    header('Content-Length: ' . strlen($outputBuffer));

    echo $outputBuffer;

An ePlot DWF is designed primarily for offline viewing or printing. It includes an MgPlotSpecification that defines the page size and margins. It can also include an optional MgLayout that defines additional components to include in the plot, like a legend or a custom logo. The layout is based on a print layout in the repository. For a description of the PrintLayout schema, see the MapGuide Web API Reference.

To create an ePlot DWF with more than one sheet, use an MgMapPlotCollection, where each item in the collection is an MgMapPlot that describes a single sheet.

NoteThe map name becomes the sheet name in the multi-plot DWF. Because each sheet in the DWF must have a unique name, you must create a separate MgMap object for each sheet in the DWF.

The following example creates a multi-plot DWF with two sheets. The second sheet displays the same map area as the first, but it adds the title and legend information from the print layout.

    $dwfVersion = new MgDwfVersion("6.01", "1.2");

    $plotSpec = new MgPlotSpecification(8.5, 11,

      MgPageUnitsType::Inches);

    $plotSpec->SetMargins(0.5, 0.5, 0.5, 0.5);

    $plotCollection = new MgMapPlotCollection();

    $plot1 = new MgMapPlot($map, $plotSpec, $layout);

    $plotCollection->Add($plot1);

    // Create a second map for the second sheet in the DWF. This

    // second map uses the print layout

    // to display a page title and legend.

    $map2 = new MgMap();

    $map2->Create($resourceService, $map->GetMapDefinition(),

      'Sheet 2');

    $layoutRes = new MgResourceIdentifier(

      "Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");

    $layout =  new MgLayout($layoutRes, "City of Sheboygan",

      MgPageUnitsType::Inches);

    $plot2 = new MgMapPlot($map2,

      $map->GetViewCenter()->GetCoordinate(), $map->GetViewScale(),

      $plotSpec, $layout);

    $plotCollection->Add($plot2);

    $byteReader = $mappingService->

      GenerateMultiPlot($plotCollection, $dwfVersion);

    // Now output the resulting DWF.

    $outputBuffer = '';

    $buffer = '';

    while ($byteReader->Read($buffer, 50000) != 0)

    {

      $outputBuffer .= $buffer;

    }

    header('Content-Type: ' . $byteReader->GetMimeType());

    header('Content-Length: ' . strlen($outputBuffer));

    echo $outputBuffer;