Open($userInfo); // Create the necessary services. $renderingService = $siteConnection-> CreateService(MgServiceType::RenderingService); // Open the map and get its SRS $map = new MgMap($siteConnection); $map->Open($mapName); $srsWkt = $map->GetMapSRS(); $coordinateSystemFactory = new MgCoordinateSystemFactory(); $srs = $coordinateSystemFactory->Create($srsWkt); if ($xmlSelection != '') { $selection = new MgSelection($map, $xmlSelection); } else { $selection = new MgSelection($map); } $color = new MgColor(205, 189, 156); $geometryFactory = new MgGeometryFactory(); $mapCenterCoordinate = $geometryFactory-> CreateCoordinateXY($mapCenterX, $mapCenterY); // Convert the height in pixels to map units. // Create an envelope that contains the image area to display. $displayInInches = $imageHeight / 96; $displayInMeters = $displayInInches * .0254; $mapHeightInMeters = $displayInMeters * $mapScale; $mapHeightInMapUnits = $srs->ConvertMetersToCoordinateSystemUnits($mapHeightInMeters); $envelopeOffsetY = $mapHeightInMapUnits / 2; $envelopeOffsetX = $imageWidth / $imageHeight * $envelopeOffsetY; $envelope = new MgEnvelope($mapCenterX - $envelopeOffsetX, $mapCenterY - $envelopeOffsetY, $mapCenterX + $envelopeOffsetX, $mapCenterY + $envelopeOffsetY); // Render the image and send it to the browser. $byteReader = $renderingService->RenderMap($map, $selection, $envelope, $imageWidth, $imageHeight, $color, 'PNG'); header("Content-type: " . $byteReader->GetMimeType() ); $buffer = ''; while ($byteReader->Read($buffer, 50000) != 0) { echo $buffer; } } catch (MgException $e) { echo '

' . $e->GetExceptionMessage() . '

'; echo '

' . $e->GetDetails() . '

'; } ?>