CreateService(MgServiceType::MappingService); $renderingService = $siteConnection->CreateService(MgServiceType::RenderingService); $map = new MgMap(); $map->Open($resourceService, $mapName); $selection = new MgSelection($map); $selection->Open($resourceService, $mapName); //get current center as a coordinate $center = $map->GetViewCenter()->GetCoordinate(); //plot with the passed scale, if provided $scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : $map->GetViewScale(); 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'); $oImg = $mappingService->GeneratePlot($map, $center, $scale, $oPlotSpec, $oLayout, $dwfVersion); } else { //render as an image if (isset($imgHeight) && isset($imgWidth)) { $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; } ?>