CreateService(MgServiceType::MappingService); $renderingService = $siteConnection->CreateService(MgServiceType::RenderingService); $map = new MgMap(); $map->Open($resourceService, $mapName); $selection = new MgSelection($map); $selection->Open($resourceService, $mapName); //compute center $extent = $map->GetMapExtent(); $centerX = $extent->GetLowerLeftCoordinate()->GetX() + ($extent->GetWidth())/2; $centerY = $extent->GetLowerLeftCoordinate()->GetY() + ($extent->GetHeight())/2; $geomFactory = new MgGeometryFactory(); $center = $geomFactory->CreateCoordinateXY($centerX, $centerY); if ($format == 'DWF') { $oLayout = null; if ($layout) { $layoutId = new MgResourceIdentifier($layout); $layoutId->Validate(); $oLayout = new MgLayout($layoutId,'Map', 'meters'); }; $oPlotSpec = new MgPlotSpecification($pageWidth,$pageHeight,MgPageUnitsType::Inches, $aMargins[0], $aMargins[1], $aMargins[2], $aMargins[3] ); $dwfVersion = new MgDwfVersion('6.01','1.2'); if ($scale) { //plot with the passed scale $coordSysFactory = new MgCoordinateSystemFactory(); $coordSystem = $coordSysFactory->Create($map->GetMapSRS()); $metersPerUnit = $coordSystem->ConvertCoordinateSystemUnitsToMeters(1.0); $metersPerPixel = 1.0/(100.0 / 2.54 * $map->GetDisplayDpi()); $height = $map->GetDisplayHeight(); $width = $map->GetDisplayWidth(); $mapWidth = $scale * $width * $metersPerPixel/$metersPerUnit; $mapHeight = $scale * $height * $metersPerPixel/$metersPerUnit; $extent = new MgEnvelope( $center->GetX() - 0.5*$mapWidth, $center->GetY() - 0.5*$mapHeight, $center->GetX() + 0.5*$mapWidth, $center->GetY() + 0.5*$mapHeight); //this is broken because the swig api has an error //$center = $map->GetViewCenter(); // echo $oPlotSpec; exit; //echo $map->GetName()." ".$center->GetX().", ". // $center->GetY().", ". // $scale." paper height: ". //$oPlotSpec->GetPaperHeight().", layout: ".$oLayout->GetTitle().", dwfVersion ".$dwfVersion->GetFileVersion()."\n"; // $oImg = $mappingService->GeneratePlot($map, // $center, // $scale, // $oPlotSpec, // $oLayout, // $dwfVersion); $oImg = $mappingService->GeneratePlot($map, $extent, true, $oPlotSpec, $oLayout, $dwfVersion); } else { //use current extents for plot $oImg = $mappingService->GeneratePlot($map, $extent, false, $oPlotSpec, $oLayout, $dwfVersion); } } else { //render as an image if (isset($imgHeight) && isset($imgWidth)) { $scale = $map->GetViewScale(); $oImg = $renderingService->RenderMap($map, $selection, $center, $scale, $imgWidth, $imgHeight, new MgColor(255,255,255), $format); }else{ $oImg = $renderingService->RenderMap($map, $selection, $format); }; }; } catch (MgException $e) { echo "ERROR: " . $e->GetMessage() . "\n"; echo $e->GetDetails() . "\n"; echo $e->GetStackTrace() . "\n"; exit; } header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header( "Content-type: image/$format" ); header( "Content-disposition: attachment; filename=$mapName.$format" ); $buffer = ''; while ($oImg->Read($buffer, 4096) > 0) { echo $buffer; } ?>