Ejemplo n.º 1
0
$mapName = $args['MAPNAME'];
try {
    // Initialize the Web Extensions and connect to the server using
    // the Web Extensions session identifier stored in PHP session state.
    MgInitializeWebTier($webconfigFilePath);
    $userInfo = new MgUserInformation($sessionId);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    // Create an instance of ResourceService and use that to open the
    // current map instance stored in session state.
    $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
    $map = new MgMap();
    $map->Open($resourceService, $mapName);
    $mappingService = $siteConnection->CreateService(MgServiceType::MappingService);
    $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);
    $layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
    $layout = new MgLayout($layoutRes, "City of Sheboygan", MgPageUnitsType::Inches);
    $byteReader = $mappingService->GeneratePlot($map, $plotSpec, $layout, $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;
} catch (MgException $e) {
    $result = $e->GetExceptionMessage() . "<br><br>" . $e->GetDetails();
 public function GeneratePlot($sessionId, $mapName, $format)
 {
     $fmt = $this->ValidateRepresentation($format, array("dwf", "pdf"));
     $this->EnsureAuthenticationForSite($sessionId);
     $siteConn = new MgSiteConnection();
     $siteConn->Open($this->userInfo);
     $map = new MgMap($siteConn);
     $map->Open($mapName);
     $mappingSvc = $siteConn->CreateService(MgServiceType::MappingService);
     $title = $this->GetRequestParameter("title", "");
     $paperSize = $this->GetRequestParameter("papersize", 'A4');
     $orientation = $this->GetRequestParameter("orientation", 'P');
     $marginLeft = floatval($this->GetRequestParameter("marginleft", 0.5));
     $marginRight = floatval($this->GetRequestParameter("marginright", 0.5));
     $marginTop = floatval($this->GetRequestParameter("margintop", $title == "" ? 0.5 : 1.0));
     $marginBottom = floatval($this->GetRequestParameter("marginbottom", 0.5));
     if ($fmt == "dwf") {
         $size = MgUtils::GetPaperSize($this->app, $paperSize);
         //If landscape, flip the width/height
         $width = $orientation == 'L' ? MgUtils::MMToIn($size[1]) : MgUtils::MMToIn($size[0]);
         $height = $orientation == 'L' ? MgUtils::MMToIn($size[0]) : MgUtils::MMToIn($size[1]);
         $printLayoutStr = $this->GetRequestParameter("printlayout", null);
         $dwfVersion = new MgDwfVersion("6.01", "1.2");
         $plotSpec = new MgPlotSpecification($width, $height, MgPageUnitsType::Inches);
         $plotSpec->SetMargins($marginLeft, $marginTop, $marginRight, $marginBottom);
         $layout = null;
         if ($printLayoutStr != null) {
             $layoutRes = new MgResourceIdentifier($printLayoutStr);
             $layout = new MgLayout($layoutRes, $title, MgPageUnitsType::Inches);
         }
         $br = $mappingSvc->GeneratePlot($map, $plotSpec, $layout, $dwfVersion);
         //Apply download headers
         $downloadFlag = $this->app->request->params("download");
         if ($downloadFlag && ($downloadFlag === "1" || $downloadFlag === "true")) {
             $name = $this->app->request->params("downloadname");
             if (!$name) {
                 $name = "download";
             }
             $name .= ".dwf";
             $this->app->response->header("Content-Disposition", "attachment; filename=" . $name);
         }
         $this->OutputByteReader($br);
     } else {
         //pdf
         $bLayered = $this->app->request->params("layeredpdf");
         if ($bLayered == null) {
             $bLayered = false;
         } else {
             $bLayered = $bLayered == "1" || $bLayered == "true";
         }
         $renderingService = $siteConn->CreateService(MgServiceType::RenderingService);
         $plotter = new MgPdfPlotter($this->app, $renderingService, $map);
         $plotter->SetTitle($title);
         $plotter->SetPaperType($paperSize);
         $plotter->SetOrientation($orientation);
         $plotter->ShowCoordinates(true);
         $plotter->ShowNorthArrow(true);
         $plotter->ShowScaleBar(true);
         $plotter->ShowDisclaimer(true);
         $plotter->SetLayered($bLayered);
         $plotter->SetMargins($marginTop, $marginBottom, $marginLeft, $marginRight);
         $mapCenter = $map->GetViewCenter();
         //Apply download headers
         $downloadFlag = $this->app->request->params("download");
         if ($downloadFlag && ($downloadFlag === "1" || $downloadFlag === "true")) {
             $name = $this->app->request->params("downloadname");
             if (!$name) {
                 $name = "download";
             }
             $name .= ".pdf";
             $plotter->Plot($mapCenter->GetCoordinate(), $map->GetViewScale(), $name);
         } else {
             $plotter->Plot($mapCenter->GetCoordinate(), $map->GetViewScale());
         }
     }
 }
Ejemplo n.º 3
0
$mapName = $args['MAPNAME'];
try {
    // Initialize the Web Extensions and connect to the server using
    // the Web Extensions session identifier stored in PHP session state.
    MgInitializeWebTier($webconfigFilePath);
    $userInfo = new MgUserInformation($sessionId);
    $siteConnection = new MgSiteConnection();
    $siteConnection->Open($userInfo);
    // Create an instance of ResourceService and use that to open the
    // current map instance stored in session state.
    $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
    $map = new MgMap();
    $map->Open($resourceService, $mapName);
    $mappingService = $siteConnection->CreateService(MgServiceType::MappingService);
    $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);
    $layout = null;
    $layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
    $layout = new MgLayout($layoutRes, "City of Sheboygan", MgPageUnitsType::Inches);
    $plotCollection = new MgMapPlotCollection();
    $plot1 = new MgMapPlot($map, $plotSpec, $layout);
    $plot1->SetCenterAndScale($map->GetViewCenter()->GetCoordinate(), $map->GetViewScale() * 2);
    $plotCollection->Add($plot1);
    // Create a second map for the second sheet in the DWF. This second sheet uses the print layout
    // to display a page title and legend.
    $map2 = new MgMap();
    $map2->Create($resourceService, $map->GetMapDefinition(), 'Sheet 2');
    $plot2 = new MgMapPlot($map2, $plotSpec, $layout);
    $plot2->SetCenterAndScale($map->GetViewCenter()->GetCoordinate(), $map->GetViewScale());
    // $plot2 = new MgMapPlot($map2, $map->GetViewCenter()->GetCoordinate(), $map->GetViewScale(), $plotSpec, $layout);