public function GetMapKml($resId, $format = "kml") { //Check for unsupported representations $fmt = $this->ValidateRepresentation($format, array("kml", "kmz")); $native = $this->GetBooleanRequestParameter("native", "0") == "1"; //Internal debugging flag $chunk = $this->GetBooleanRequestParameter("chunk", true); $sessionId = ""; if ($resId->GetRepositoryType() == MgRepositoryType::Session) { $sessionId = $resId->GetRepositoryName(); } else { $sessionId = $this->GetRequestParameter("session", ""); } $this->EnsureAuthenticationForSite($sessionId, true); $siteConn = new MgSiteConnection(); if ($sessionId !== "") { $userInfo = new MgUserInformation($sessionId); $siteConn->Open($userInfo); } else { $siteConn->Open($this->userInfo); $site = $siteConn->GetSite(); $sessionId = $site->CreateSession(); $userInfo = new MgUserInformation($sessionId); $siteConn->Open($userInfo); } if ($native) { $mdfIdStr = $resId->ToString(); $selfUrl = MgUtils::GetSelfUrlRoot($this->app->config("SelfUrl")); $this->app->redirect("{$selfUrl}/../mapagent/mapagent.fcgi?OPERATION=GETMAPKML&VERSION=1.0.0&SESSION={$sessionId}&MAPDEFINITION={$mdfIdStr}&CLIENTAGENT=MapGuide REST Extension"); } else { $map = new MgMap($siteConn); $map->Create($resId, $resId->GetName()); $this->_GetKmlForMap($map, $sessionId, $format, $chunk); } }
public function GeneratePlotFromMapDefinition($resId, $format) { $fmt = $this->ValidateRepresentation($format, array("dwf", "pdf")); $x = $this->GetRequestParameter("x", ""); $y = $this->GetRequestParameter("y", ""); $scale = $this->GetRequestParameter("scale", ""); if ($x == "") { $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "x"), MgMimeType::Html); } if ($y == "") { $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "y"), MgMimeType::Html); } if ($scale == "") { $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "scale"), MgMimeType::Html); } $this->EnsureAuthenticationForSite(); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $map = new MgMap($siteConn); $map->Create($resId, "Plot"); $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)); $geomFact = new MgGeometryFactory(); $center = $geomFact->CreateCoordinateXY(floatval($x), floatval($y)); 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); $mappingSvc = $siteConn->CreateService(MgServiceType::MappingService); $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, $center, floatval($scale), $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 //FIXME: Initial visibility state is inconsistent (probably because this map hasn't been rendered //yet). As a result, adding layered PDF support won't really work here. /* $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); //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($center, floatval($scale), $name); } else { $plotter->Plot($center, floatval($scale)); } } }
* Purpose: get map initial information *****************************************************************************/ include 'Common.php'; include 'Utilities.php'; try { $mappingService = $siteConnection->CreateService(MgServiceType::MappingService); $featureService = $siteConnection->CreateService(MgServiceType::FeatureService); // Get a runtime map from a map definition if (isset($_REQUEST['mapid'])) { $mapid = $_REQUEST['mapid']; //echo $mapid; $resourceID = new MgResourceIdentifier($mapid); $map = new MgMap(); $mapTitle = $resourceID->GetName(); //echo "<br> maname $mapName <br>"; $map->Create($resourceService, $resourceID, $mapTitle); $mapName = uniqid($mapTitle); $mapStateId = new MgResourceIdentifier("Session:" . $sessionID . "//" . $mapName . "." . MgResourceType::Map); //create an empty selection object and store it in the session repository $sel = new MgSelection($map); $sel->Save($resourceService, $mapName); $map->Save($resourceService, $mapStateId); } else { $map = new MgMap(); $map->Open($resourceService, $mapName); $mapTitle = $map->GetName(); $mapid = $map->GetMapDefinition()->ToString(); } //$sessionId = $map->GetSessionId(); //$mapName = $map->GetName() ; $extents = $map->GetMapExtent();
echo "Deleting existing feature source\n"; $rsvc->DeleteResource($id); echo "Creating new feature source\n"; $fsvc->CreateFeatureSource($id, $params); // We need to add some data to the sdf before using it. The spatial context // reader must have an extent. $cmdColl = new MgFeatureCommandCollection(); for ($i = 1; $i <= 20; $i++) { $insert = $intFeature->InsertCommand($i); $cmdColl->Add($insert); } echo "Updating features\n"; $fsvc->UpdateFeatures($id, $cmdColl, false); $mapId = new MgResourceIdentifier("Library://TrevorWekel/NewSdf.MapDefinition"); $map = new MgMap(); $map->Create($rsvc, $mapId, "NewMap"); echo "Building Selection from Add()\n"; $sel = new MgSelection($map); $slayer = $map->GetLayers()->GetItem(0); $sel->AddFeatureIdInt32($slayer, "IntKey", 1); $sel->AddFeatureIdInt32($slayer, "IntKey", 10); $sel->AddFeatureIdInt32($slayer, "IntKey", 20); echo "XML FeatureSet is\n" . $sel->ToXml() . "\n"; echo "\nString Filter: " . $sel->GenerateFilter($slayer, "StringKey") . "\n\n"; echo "Building Selection from XML\n"; $sel2 = new MgSelection($map, $sel->ToXml()); // Test basic methods $layerColl = $sel2->GetLayers(); $newLayer = $layerColl->GetItem(0); echo "First layer selected is " . $newLayer->GetName() . "\n"; echo "BadKey Filter: " . $sel2->GenerateFilter($slayer, "BadKey") . "\n";
// create the map instance and store it with the session // $userInfo = new MgUserInformation(); $userInfo->SetMgSessionId($sessionId); $userInfo->SetClientIp(GetClientIp()); $userInfo->SetClientAgent(GetClientAgent()); $site = new MgSiteConnection(); $site->Open($userInfo); $tileSrvc = $site->CreateService(MgServiceType::TileService); $tileSizeX = $tileSrvc->GetDefaultTileSizeX(); $tileSizeY = $tileSrvc->GetDefaultTileSizeY(); $resourceSrvc = $site->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $resId = new MgResourceIdentifier($mapDefinition); $mapName = $resId->GetName(); $map->Create($resourceSrvc, $resId, $mapName); //create an empty selection object and store it in the session repository $sel = new MgSelection($map); $sel->Save($resourceSrvc, $mapName); //get the map extent and calculate the scale factor // $mapExtent = $map->GetMapExtent(); $srs = $map->GetMapSRS(); if ($srs != "") { $csFactory = new MgCoordinateSystemFactory(); $cs = $csFactory->Create($srs); $metersPerUnit = $cs->ConvertCoordinateSystemUnitsToMeters(1.0); $unitsType = $cs->GetUnits(); } else { $metersPerUnit = 1.0; $unitsType = GetLocalizedString("DISTANCEMETERS", $locale);
$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; } header('Content-Type: ' . $byteReader->GetMimeType()); header('Content-Length: ' . strlen($outputBuffer)); echo $outputBuffer; } catch (MgException $e) {
public function GetTileXYZ($resId, $groupName, $x, $y, $z, $type, $layerNames = NULL) { $fmt = $this->ValidateRepresentation($type, array("json", "png", "png8", "jpg", "gif")); $path = self::GetTilePath($this->app, $resId, $groupName, $z, $x, $y, $type, $layerNames); clearstatcache(); $dir = dirname($path); $lockPath = "{$dir}/lock_" . $y . ".lck"; $attempts = 0; while (!@is_dir($dir)) { try { mkdir($dir, 0777, true); } catch (Exception $e) { //Another tile request may have already created this since $attempts++; //Bail after MAX_RETRY_ATTEMPTS if ($attempts >= self::MAX_RETRY_ATTEMPTS) { $this->ServerError($this->app->localizer->getText("E_FAILED_TO_CREATE_DIR_AFTER_N_ATTEMPTS", $attempts), $this->GetMimeTypeForFormat($type)); } } } //If there's a dangling lock file, attempt to remove it if (file_exists($lockPath)) { unlink($lockPath); } $fpLockFile = fopen($lockPath, "a+"); //Message of any exception caught will be set to this variable $tileError = null; $requestId = rand(); $this->app->log->debug("({$requestId}) Checking if {$path} exists"); $attempts = 0; while (!file_exists($path)) { //Bail after MAX_RETRY_ATTEMPTS if ($attempts >= self::MAX_RETRY_ATTEMPTS) { $this->ServerError($this->app->localizer->getText("E_FAILED_TO_GENERATE_TILE_AFTER_N_ATTEMPTS", $attempts), $this->GetMimeTypeForFormat($type)); } $attempts++; $this->app->log->debug("({$requestId}) {$path} does not exist. Locking for writing"); $bLocked = false; flock($fpLockFile, LOCK_EX); fwrite($fpLockFile, "."); $bLocked = true; $this->app->log->debug("({$requestId}) Acquired lock for {$path}. Checking if path exists again."); //check once more to see if the cache file was created while waiting for //the lock clearstatcache(); if (!file_exists($path)) { try { $this->app->log->debug("({$requestId}) Rendering tile to {$path}"); $bOldPath = true; if ($type != "json") { //if this is MGOS 3.0 and we're dealing with a tile set, we invoke GETTILEIMAGE as that we can pass in Tile Set Definition //resource ids without issues. We cannot create MgMaps from Tile Set Definitions that are not using the default tile provider. // //The given tile set is assumed to be using the XYZ provider, the case where the Tile Set Definition is using the default provider //is not handled if ($this->app->MG_VERSION[0] >= 3 && $resId->GetResourceType() == "TileSetDefinition") { $bOldPath = false; $sessionId = ""; if ($resId->GetRepositoryType() === MgRepositoryType::Session && $this->app->request->get("session") == null) { $sessionId = $resId->GetRepositoryName(); } $resIdStr = $resId->ToString(); $that = $this; $this->EnsureAuthenticationForHttp(function ($req, $param) use($that, $resIdStr, $groupName, $x, $y, $z, $requestId, $path) { $param->AddParameter("OPERATION", "GETTILEIMAGE"); $param->AddParameter("VERSION", "1.2.0"); $param->AddParameter("MAPDEFINITION", $resIdStr); $param->AddParameter("BASEMAPLAYERGROUPNAME", $groupName); $param->AddParameter("SCALEINDEX", $z); $param->AddParameter("TILEROW", $x); $param->AddParameter("TILECOL", $y); $that->app->log->debug("({$requestId}) Executing GETTILEIMAGE"); $that->ExecuteHttpRequest($req, function ($result, $status) use($path) { if ($status == 200) { //Need to dump the rendered tile to the specified path so the caching stuff below can still do its thing $resultObj = $result->GetResultObject(); $sink = new MgByteSink($resultObj); $sink->ToFile($path); } }); }, true, "", $sessionId); //Tile access can be anonymous, so allow for it if credentials/session specified, but if this is a session-based Map Definition, use the session id as the nominated one } } //Pre MGOS 3.0 code path if ($bOldPath) { $this->app->log->debug("({$requestId}) Going down old code path"); $this->EnsureAuthenticationForSite("", true); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $map = new MgMap($siteConn); $map->Create($resId, "VectorTileMap"); $renderSvc = $siteConn->CreateService(MgServiceType::RenderingService); $groups = $map->GetLayerGroups(); $baseGroup = $groups->GetItem($groupName); //Will throw MgObjectNotFoundException -> 404 if no such group exists $factory = new MgCoordinateSystemFactory(); $mapCsWkt = $map->GetMapSRS(); $mapCs = $factory->Create($mapCsWkt); $mapExtent = $map->GetMapExtent(); $mapExLL = $mapExtent->GetLowerLeftCoordinate(); $mapExUR = $mapExtent->GetUpperRightCoordinate(); $metersPerUnit = $mapCs->ConvertCoordinateSystemUnitsToMeters(1.0); $this->app->log->debug("({$requestId}) Calc bounds from XYZ"); //XYZ to lat/lon math. From this we can convert to the bounds in the map's CS // //Source: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames $n = pow(2, $z); $lonMin = $x / $n * 360.0 - 180.0; $latMin = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n)))); $lonMax = ($x + 1) / $n * 360.0 - 180.0; $latMax = rad2deg(atan(sinh(pi() * (1 - 2 * ($y + 1) / $n)))); $boundsMinX = min($lonMin, $lonMax); $boundsMinY = min($latMin, $latMax); $boundsMaxX = max($lonMax, $lonMin); $boundsMaxY = max($latMax, $latMin); if ($mapCs->GetCsCode() != "LL84") { $llCs = $factory->CreateFromCode("LL84"); $trans = $factory->GetTransform($llCs, $mapCs); $ul = $trans->Transform($lonMin, $latMin); $lr = $trans->Transform($lonMax, $latMax); $boundsMinX = min($lr->GetX(), $ul->GetX()); $boundsMinY = min($lr->GetY(), $ul->GetY()); $boundsMaxX = max($lr->GetX(), $ul->GetX()); $boundsMaxY = max($lr->GetY(), $ul->GetY()); } //Set all layers under group to be visible $layers = $map->GetLayers(); $layerCount = $layers->GetCount(); $groupCount = $groups->GetCount(); //Turn all groups that are not the given group to be hidden for ($i = 0; $i < $groupCount; $i++) { $group = $groups->GetItem($i); if ($group->GetName() != $groupName) { $group->SetVisible(false); } else { $group->SetVisible(true); } } for ($i = 0; $i < $layerCount; $i++) { $layer = $layers->GetItem($i); $group = $layer->GetGroup(); if (null == $group) { continue; } if ($group->GetName() != $groupName && $layer->GetLayerType() == MgLayerType::Dynamic) { $layer->SetVisible(false); continue; } if ($layer->GetLayerType() == MgLayerType::Dynamic) { $layer->SetVisible(true); } } if ($type == "json") { //error_log("($requestId) Render vector tile"); $this->PutVectorTileXYZ($map, $groupName, $siteConn, $metersPerUnit, $factory, $path, $boundsMinX, $boundsMinY, $boundsMaxX, $boundsMaxY, $layerNames); } else { $format = strtoupper($type); //error_log("($requestId) Render image tile"); $this->PutTileImageXYZ($map, $groupName, $renderSvc, $path, $format, $boundsMinX, $boundsMinY, $boundsMaxX, $boundsMaxY, $layerNames, $requestId); } } } catch (MgException $ex) { if ($bLocked) { $this->app->log->debug("({$requestId}) MgException caught " . $ex->GetDetails() . "\n" . $ex->getTraceAsString() . "\n. Releasing lock for {$path}"); $tileError = $ex->GetExceptionMessage(); flock($fpLockFile, LOCK_UN); $bLocked = false; } if ($ex instanceof MgResourceNotFoundException || $ex instanceof MgObjectNotFoundException) { $this->NotFound($ex->GetExceptionMessage(), $this->GetMimeTypeForFormat($fmt)); } else { if ($ex instanceof MgConnectionFailedException) { $this->ServiceUnavailable($ex->GetExceptionMessage(), $this->GetMimeTypeForFormat($fmt)); } } } catch (Exception $ex) { if ($bLocked) { $tileError = get_class($ex) . " - " . $ex->getMessage(); $this->app->log->debug("({$requestId}) Exception caught ({$tileError}). Releasing lock for {$path}"); flock($fpLockFile, LOCK_UN); $bLocked = false; } } } if ($bLocked) { $this->app->log->debug("({$requestId}) Releasing lock for {$path}"); flock($fpLockFile, LOCK_UN); $bLocked = false; } } //An exception occurred, try to clean up lock before bailing if ($tileError != null) { try { fclose($fpLockFile); unlink($lockPath); } catch (Exception $ex) { $this->app->log->debug("({$requestId}) Failed to delete lock file. Perhaps another concurrent request to the same tile is happening?"); } throw new Exception($tileError); } $modTime = filemtime($path); $this->app->lastModified($modTime); $this->app->log->debug("({$requestId}) Acquiring shared lock for {$path}"); //acquire shared lock for reading to prevent a problem that could occur //if a tile exists but is only partially generated. flock($fpLockFile, LOCK_SH); $this->app->log->debug("({$requestId}) Outputting {$path}"); $ext = strtoupper(pathinfo($path, PATHINFO_EXTENSION)); $mimeType = ""; switch ($ext) { case "PNG": //MgImageFormats::Png: $mimeType = MgMimeType::Png; break; case "GIF": //MgImageFormats::Gif: $mimeType = MgMimeType::Gif; break; case "JPG": //MgImageFormats::Jpeg: $mimeType = MgMimeType::Jpeg; break; case "JSON": $mimeType = MgMimeType::Json; break; } $this->app->response->header("Content-Type", $mimeType); $this->app->expires("+6 months"); $this->app->response->header("Cache-Control", "max-age=31536000, must-revalidate"); $this->app->response->setBody(file_get_contents($path)); $this->app->log->debug("({$requestId}) Releasing shared lock for {$path}"); //Release lock flock($fpLockFile, LOCK_UN); //Try to delete the lock file try { fclose($fpLockFile); unlink($lockPath); } catch (Exception $ex) { $this->app->log->debug("({$requestId}) Failed to delete lock file. Perhaps another concurrent request to the same tile is happening?"); } }
public function CreateMap($resId) { $mdfIdStr = $this->app->request->params("mapdefinition"); if ($mdfIdStr == null) { $this->BadRequest($this->app->localizer->getText("E_MISSING_REQUIRED_PARAMETER", "mapdefinition"), $this->GetMimeTypeForFormat($format)); } else { $mdfId = new MgResourceIdentifier($mdfIdStr); if ($mdfId->GetResourceType() != MgResourceType::MapDefinition) { $this->BadRequest($this->app->localizer->getText("E_INVALID_MAP_DEFINITION_PARAMETER", "mapdefinition"), $this->GetMimeTypeForFormat($format)); } else { //$this->EnsureAuthenticationForSite(); $userInfo = new MgUserInformation($resId->GetRepositoryName()); $siteConn = new MgSiteConnection(); $siteConn->Open($userInfo); $resSvc = $siteConn->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $map->Create($resSvc, $mdfId, $resId->GetName()); $sel = new MgSelection($map); $sel->Save($resSvc, $resId->GetName()); $map->Save($resSvc, $resId); $this->app->response->setStatus(201); $this->app->response->setBody(MgUtils::GetNamedRoute($this->app, "/session", "session_resource_id", array("sessionId" => $resId->GetRepositoryName(), "resName" => $resId->GetName() . "." . $resId->GetResourceType()))); } } }
function GetProfilingResults() { //profiling map parameters global $mapResourceId; global $mapProfileResult; global $scale; global $centerPoint; global $clientWidth; global $clientHeigth; list($x, $y) = explode("*", $centerPoint); $x = trim($x); $y = trim($y); $geometryFactory = new MgGeometryFactory(); //[centerPoint] $coordNewCenter = $geometryFactory->CreateCoordinateXY($x, $y); //[backgroundColor] $bgc = GetBackGroundColor($mapResourceId); //[imageFormat] $imageFormat = "PNG"; //userInfo are saved in the session global $userInfo; //connect to the site and get a resource service instance //create profiling service too $siteConn = new MgSiteConnection(); $siteConn->Open($userInfo); $resourceService = $siteConn->CreateService(MgServiceType::ResourceService); $profilingService = $siteConn->CreateService(MgServiceType::ProfilingService); //the profiling result is saved as xml file, the file name is unique //the format is like this "YYYYMMDDHHMMSS10" $newXmlFileId = date("YmdHis") . rand(10, 99); $resourceID = new MgResourceIdentifier($mapResourceId); // Get a runtime map from a map definition $map = new MgMap(); $map->Create($resourceService, $resourceID, $newXmlFileId); //The result will not show base layers RemoveBaseLayers($map); //get the profiling map result $byteReader = $profilingService->ProfileRenderMap($map, NULL, $coordNewCenter, $scale, $clientWidth, $clientHeigth, $bgc, $imageFormat, false); //read the content into a string $profilingResourceContent = ""; $chunk = ""; do { $chunkSize = $byteReader->Read($chunk, 4096); $profilingResourceContent = $profilingResourceContent . $chunk; } while ($chunkSize != 0); //save the file on the server $newXmlFileName = "profilingmapxml/" . $newXmlFileId . ".xml"; $fp = fopen($newXmlFileName, "w"); fwrite($fp, $profilingResourceContent); fclose($fp); //put the file name in the session $_SESSION["ProfilingResultFile"] = $newXmlFileName; //read the result into the DOM $resultSource = new DOMDocument(); $resultSource->load($newXmlFileName); $mapProfileResult->ReadFromXML($resultSource); $mapProfileResult->GetBaseLayerCount(); }