$layout = isset($_REQUEST['layout']) ? $_REQUEST['layout'] : null; $scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : null; $imgWidth = isset($_REQUEST['width']) ? $_REQUEST['width'] : null; $imgHeight = isset($_REQUEST['height']) ? $_REQUEST['height'] : null; $pageHeight = isset($_REQUEST['pageheight']) ? $_REQUEST['pageheight'] : 11; $pageWidth = isset($_REQUEST['pagewidth']) ? $_REQUEST['pagewidth'] : 8.5; $aMargins = isset($_REQUEST['margins']) ? explode(',', $_REQUEST['margins']) : array(0, 0, 0, 0); try { $mappingService = $siteConnection->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)) {
function DownloadMarkupAsKml($kmz = false) { $kmlService = $this->site->CreateService(MgServiceType::KmlService); $resourceService = $this->site->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $map->Open($resourceService, $this->args['MAPNAME']); $markupLayerResId = new MgResourceIdentifier($this->args['MARKUPLAYER']); $downloadName = $markupLayerResId->GetName() . "." . ($kmz ? "kmz" : "kml"); //Find layer under _Markup with this layer def id $layerGroups = $map->GetLayerGroups(); if (!$layerGroups->Contains("_Markup")) { throw new Exception(GetLocalizedString("REDLINENOOPENLAYERS", $locale)); } $layers = $map->GetLayers(); $markupLayer = null; for ($i = 0; $i < $layers->GetCount(); $i++) { $layer = $layers->GetItem($i); $ldfId = $layer->GetLayerDefinition(); if (strcmp($ldfId->ToString(), $markupLayerResId->ToString()) == 0) { $markupLayer = $layer; break; } } if ($markupLayer == null) { throw new Exception(GetLocalizedString("REDLINEOPENLAYERNOTFOUND", $locale)); } //View extent crunching time $geomFact = new MgGeometryFactory(); $csFactory = new MgCoordinateSystemFactory(); $mapCs = $csFactory->Create($map->GetMapSRS()); $metersPerUnit = $mapCs->ConvertCoordinateSystemUnitsToMeters(1.0); $mapScale = $map->GetViewScale(); $devW = $map->GetDisplayWidth(); $devH = $map->GetDisplayHeight(); $mapDpi = $map->GetDisplayDpi(); $metersPerPixel = 0.0254 / $mapDpi; $mcsW = $mapScale * $devW * $metersPerPixel / $metersPerUnit; $mcsH = $mapScale * $devH * $metersPerPixel / $metersPerUnit; $center = $map->GetViewCenter(); $coord = $center->GetCoordinate(); $coord0 = $geomFact->CreateCoordinateXY($coord->GetX() - 0.5 * $mcsW, $coord->GetY() - 0.5 * $mcsH); $coord1 = $geomFact->CreateCoordinateXY($coord->GetX() + 0.5 * $mcsW, $coord->GetY() + 0.5 * $mcsH); $bbox = new MgEnvelope($coord0, $coord1); //Call the service API $br = $kmlService->GetFeaturesKml($markupLayer, $bbox, $devW, $devH, $mapDpi, 0, $kmz ? "KMZ" : "KML"); $len = $br->GetLength(); $outputBuffer = ''; $buffer = ''; while ($br->Read($buffer, 50000) != 0) { $outputBuffer .= $buffer; } header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename={$downloadName}"); header("Content-Length: " . strlen($outputBuffer)); echo $outputBuffer; }
$currentScale = 0; try { // Initialize the Web Extensions and connect to the Server using // the Web Extensions session identifier stored in PHP session state. MgInitializeWebTier($configFilePath); $userInfo = new MgUserInformation($mgSessionId); $siteConnection = new MgSiteConnection(); $siteConnection->Open($userInfo); // Create a ReserviceService object and use it to open the Map // object from the sessions repository. Use the Map object to // determine the current scale of the map for display on this // page. $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $map->Open($resourceService, 'Sheboygan'); $viewCenter = $map->GetViewCenter(); $viewScale = $map->GetViewScale(); } catch (MgException $e) { echo $e->GetExceptionMessage(); echo $e->GetDetails(); } ?> <form id="plotForm" action="plot.php" method="get" target="_blank"> <input name="SESSION" type="hidden" value="<?php echo $mgSessionId; ?> "> <input name="Scale" id="scaleValue" type="hidden" value="0"> <input name="UseLayout" id="useLayoutValue" type="hidden" value="false"> </form>
$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); $plotCollection->Add($plot2); $byteReader = $mappingService->GenerateMultiPlot($plotCollection, $dwfVersion); // Now output the resulting DWF. $outputBuffer = ''; $buffer = ''; while ($byteReader->Read($buffer, 50000) != 0) { $outputBuffer .= $buffer;