$response = ''; $site = new MgSiteConnection(); $site->Open(new MgUserInformation($args['SESSION'])); $resourceService = $site->CreateService(MgServiceType::ResourceService); $featureService = $site->CreateService(MgServiceType::FeatureService); $layerName = $args['LAYERNAME']; $mapName = $args['MAPNAME']; $map = new MgMap($site); $map->Open($mapName); $layer = $map->GetLayers()->GetItem($layerName); $className = $layer->GetFeatureClassName(); $selection = new MgSelection($map); $selection->Open($resourceService, $mapName); $properties = new stdClass(); if ($selection->Contains($layer, $className)) { $featureReader = $selection->GetSelectedFeatures($layer, $className, new MgStringCollection()); /* Get the map SRS - we use this to convert distances */ $srsFactory = new MgCoordinateSystemFactory(); //safely get an SRS ... (in Utilities) $srsDefMap = GetMapSRS($map); $srsMap = $srsFactory->Create($srsDefMap); $featureResId = new MgResourceIdentifier($layer->GetFeatureSourceId()); $spatialContext = $featureService->GetSpatialContexts($featureResId, true); $srsLayerWkt = false; if ($spatialContext != null && $spatialContext->ReadNext() != null) { $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt(); /* skip this layer if the srs is empty */ } if ($srsLayerWkt == null) { $srsLayerWkt = $srsDefMap; }
$properties = new MgPropertyCollection(); $properties->Add(new MgGeometryProperty('BufferGeometry', $agfReaderWriter->Write($bufferGeometry))); $commands->Add(new MgInsertFeatures('BufferClass', $properties)); } $results = $featureService->UpdateFeatures($bufferFeatureResId, $commands, false); $bufferLayer->SetVisible(true); $bufferLayer->ForceRefresh(); $bufferLayer->SetDisplayInLegend(true); $map->Save($resourceService); */ // New way, post MapGuide 2.0 // Get the selected features from the MgSelection object $featureReader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), false); // Process each item in the MgFeatureReader. Get the // geometries from all the selected features and // merge them into a single geometry. $inputGeometries = new MgGeometryCollection(); while ($featureReader->ReadNext()) { $featureGeometryData = $featureReader->GetGeometry('SHPGEOM'); $featureGeometry = $agfReaderWriter->Read($featureGeometryData); $inputGeometries->Add($featureGeometry); } $geometryFactory = new MgGeometryFactory(); $mergedGeometries = $geometryFactory->CreateMultiGeometry($inputGeometries); // Add buffer features to the temporary feature source. // Create multiple concentric buffers to show area. // If the stylization for the layer draws the features // partially transparent, the concentric rings will be
public function GetSelectedFeatures($sessionId, $mapName, $layerName, $format) { $fmt = $this->ValidateRepresentation($format, array("xml", "geojson", "html")); $propList = $this->GetRequestParameter("properties", ""); $pageSize = $this->GetRequestParameter("pagesize", -1); $pageNo = $this->GetRequestParameter("page", -1); $orientation = $this->GetRequestParameter("orientation", "h"); //Internal debugging flag $chunk = $this->GetBooleanRequestParameter("chunk", true); try { $this->EnsureAuthenticationForSite($sessionId); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $resSvc = $siteConn->CreateService(MgServiceType::ResourceService); $featSvc = $siteConn->CreateService(MgServiceType::FeatureService); $map = new MgMap($siteConn); $map->Open($mapName); $selection = new MgSelection($map); $selection->Open($resSvc, $mapName); $layers = $selection->GetLayers(); if ($layers != null) { $lidx = -1; $layerCount = $layers->GetCount(); for ($i = 0; $i < $layerCount; $i++) { $currentlayer = $layers->GetItem($i); if ($currentlayer->GetName() == $layerName) { $lidx = $i; break; } } if ($lidx < 0) { $this->NotFound($this->app->localizer->getText("E_LAYER_NOT_IN_SELECTION", $layerName), $this->GetMimeTypeForFormat($fmt)); } else { $layer = $layers->GetItem($lidx); $bMapped = $this->GetBooleanRequestParameter("mappedonly", "0") == "1"; $transformto = $this->GetRequestParameter("transformto", ""); $transform = null; if ($transformto !== "") { $resId = new MgResourceIdentifier($layer->GetFeatureSourceId()); $tokens = explode(":", $layer->GetFeatureClassName()); $transform = MgUtils::GetTransform($featSvc, $resId, $tokens[0], $tokens[1], $transformto); } $owriter = null; if ($chunk === "0") { $owriter = new MgSlimChunkWriter($this->app); } else { $owriter = new MgHttpChunkWriter(); } //NOTE: This does not do a query to ascertain a total, this is already a pre-computed property of the selection set. $total = $selection->GetSelectedFeaturesCount($layer, $layer->GetFeatureClassName()); if (strlen($propList) > 0) { $tokens = explode(",", $propList); $propNames = new MgStringCollection(); foreach ($tokens as $propName) { $propNames->Add($propName); } $reader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), $propNames); } else { $reader = $selection->GetSelectedFeatures($layer, $layer->GetFeatureClassName(), $bMapped); } if ($pageSize > 0) { $pageReader = new MgPaginatedFeatureReader($reader, $pageSize, $pageNo, $total); $result = new MgReaderChunkedResult($featSvc, $pageReader, -1, $owriter, $this->app->localizer); } else { $result = new MgReaderChunkedResult($featSvc, $reader, -1, $owriter, $this->app->localizer); } $result->CheckAndSetDownloadHeaders($this->app, $format); if ($transform != null) { $result->SetTransform($transform); } if ($fmt === "html") { $result->SetAttributeDisplayOrientation($orientation); $result->SetHtmlParams($this->app); } $result->Output($format); } } else { $owriter = new MgHttpChunkWriter(); $reader = new MgNullFeatureReader(); $result = new MgReaderChunkedResult($featSvc, $reader, -1, $owriter, $this->app->localizer); if ($fmt === "html") { $result->SetAttributeDisplayOrientation($orientation); $result->SetHtmlParams($this->app); } $result->Output($format); } } catch (MgException $ex) { $this->OnException($ex, $this->GetMimeTypeForFormat($format)); } }