Open($userInfo); $featureSrvc = $site->CreateService(MgServiceType::FeatureService); $resourceSrvc = $site->CreateService(MgServiceType::ResourceService); $featuresId = new MgResourceIdentifier($resName); $schemaName = substr(strrchr($schemaName, "/"), 1); $featureName = $schemaName . ':' . $className; $classDef = $featureSrvc->GetClassDefinition($featuresId, $schemaName, $className); $geomProp = $classDef->GetProperties()->GetItem($geomName); $spatialContext = $geomProp->GetSpatialContextAssociation(); $featureReader = $featureSrvc->SelectFeatures($featuresId, $className, null); while($featureReader->ReadNext()) $totalEntries++; $featureReader->Close(); // Create a layer definition $layerfactory = new LayerDefinitionFactory(); $layerDefinition = CreateLayerDef($layerfactory, $resName, $featureName, $geomName, $geomType); // Save the layer definition to a resource stored in the session repository $byteSource = new MgByteSource($layerDefinition, strlen($layerDefinition)); $byteSource->SetMimeType(MgMimeType::Xml); $resName = 'Session:' . $sessionId . '//' . $className . '.LayerDefinition'; $resId = new MgResourceIdentifier($resName); $resourceSrvc->SetResource($resId, $byteSource->GetReader(), null); // Finds the coordinate system $agfReaderWriter = new MgAgfReaderWriter(); $spatialcontextReader = $featureSrvc->GetSpatialContexts($featuresId, false); while ($spatialcontextReader->ReadNext()) { if ($spatialcontextReader->GetName() == $spatialContext) { $coordinate = $spatialcontextReader->GetCoordinateSystemWkt(); // Finds the extent $extentByteReader = $spatialcontextReader->GetExtent(); if($extentByteReader->ToString()==null) { throw new Exception(ErrorMessages::NullExtent); } break; } } $spatialcontextReader->Close(); $extentGeometry = $agfReaderWriter->Read($extentByteReader); $iterator = $extentGeometry->GetCoordinates(); while($iterator->MoveNext()) { $x = $iterator->GetCurrent()->GetX(); $y = $iterator->GetCurrent()->GetY(); if($firstTime) { $maxX = $x; $minX = $x; $maxY = $y; $minY = $y; $firstTime = false; } if($maxX<$x) $maxX = $x; if($minX>$x||$minX==0) $minX = $x; if($maxY<$y) $maxY = $y; if($minY>$y||$minY==0) $minY = $y; } // Create a map definition $mapfactory = new MapDefinitionFactory(); $mapDefinition = CreateMapDef($mapfactory, $className, $resName, $coordinate, $minX, $maxX, $minY, $maxY); // Save the map definition to a resource stored in the session repository $byteSource = new MgByteSource($mapDefinition, strlen($mapDefinition)); $byteSource->SetMimeType(MgMimeType::Xml); $resName = 'Session:' . $sessionId . '//' . $className . '.MapDefinition'; $resId = new MgResourceIdentifier($resName); $resourceSrvc->SetResource($resId, $byteSource->GetReader(), null); // Create a web layout $webfactory = new WebLayoutFactory(); $webLayout = CreateWebLay($webfactory, $resName, $useBasicViewer); // Save the web layout to a resource stored in the session repository $byteSource = new MgByteSource($webLayout, strlen($webLayout)); $byteSource->SetMimeType(MgMimeType::Xml); if($useBasicViewer) { $resName = 'Session:' . $sessionId . '//' . $className . '.WebLayout'; $viewerRequest = '../mapviewerajax/?SESSION=' . $sessionId . '&WEBLAYOUT=' . $resName; } else { $resName = 'Session:' . $sessionId . '//' . $className . '.ApplicationDefinition'; $viewerRequest = '../fusion/templates/mapguide/preview/indexNoLegend.html?SESSION=' . $sessionId . '&APPLICATIONDEFINITION=' . $resName; } $resId = new MgResourceIdentifier($resName); $resourceSrvc->SetResource($resId, $byteSource->GetReader(), null); } catch (MgSessionExpiredException $s) { $validSession = 0; echo ErrorMessages::SessionExpired; } catch (MgException $mge) { $validSession = 0; echo $mge->GetMessage(); } catch (Exception $e) { $validSession = 0; echo $e->GetMessage(); } ?>