$properties = BuildSelectionArray($featureReader, $layerName, $properties, $bComputedProperties, $srsLayer, $bNeedsTransform, $oLayer, true); $featureReader->Close(); } } } $selection->Save($resourceService, $mapName); //print_r($properties); //echo "/* SelectionXML:".$selection->ToXML()."*/"; header('Content-type: application/json'); header('X-JSON: true'); $layers = $selection->GetLayers(); $result = NULL; $result->hasSelection = false; if ($layers && $layers->GetCount() >= 0) { $result->hasSelection = true; $oExtents = $selection->GetExtents($featureService); if ($oExtents) { $oMin = $oExtents->GetLowerLeftCoordinate(); $oMax = $oExtents->GetUpperRightCoordinate(); $result->extents = NULL; $result->extents->minx = $oMin->GetX(); $result->extents->miny = $oMin->GetY(); $result->extents->maxx = $oMax->GetX(); $result->extents->maxy = $oMax->GetY(); /*keep the full extents of the selection when saving the selection in the session*/ $properties->extents = NULL; $properties->extents->minx = $oMin->GetX(); $properties->extents->miny = $oMin->GetY(); $properties->extents->maxx = $oMax->GetX(); $properties->extents->maxy = $oMax->GetY(); }
$fi = $renderingSrvc->QueryFeatures($map, $layerNames, $inputGeom, MgFeatureSpatialOperations::Intersects, -1); if ($fi) { $resultSel = $fi->GetSelection(); if( $resultSel) { $resultSel->Save($resourceService, $mapName); //this needs to be re-opened for some reason $resultSel = new MgSelection($map); $resultSel->Open($resourceService, $mapName); $layers = $resultSel->GetLayers(); if ($layers && $layers->GetCount() >= 0) { $result->hasSelection = true; //set the extents for the selection object $oExtents = $resultSel->GetExtents($featureSrvc); if ($oExtents) { $oMin = $oExtents->GetLowerLeftCoordinate(); $oMax = $oExtents->GetUpperRightCoordinate(); $result->extents = NULL; $result->extents->minx = $oMin->GetX(); $result->extents->miny = $oMin->GetY(); $result->extents->maxx = $oMax->GetX(); $result->extents->maxy = $oMax->GetY(); /*keep the full extents of the selection when saving the selection in the session*/ $properties->extents = NULL; $properties->extents->minx = $oMin->GetX(); $properties->extents->miny = $oMin->GetY(); $properties->extents->maxx = $oMax->GetX(); $properties->extents->maxy = $oMax->GetY();
// 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"; $filter = $sel2->GenerateFilter($slayer, "IntKey"); echo "\nString Filter: " . $filter . "\n\n"; $query = new MgFeatureQueryOptions(); $query->AddFeatureProperty("KEY"); $query->AddFeatureProperty("NAME"); $query->SetFilter($filter); echo "Selected features\n"; $reader = $fsvc->SelectFeatures($id, "IntKey", $query); while ($reader->ReadNext() == true) { echo $reader->GetString("NAME") . "\n"; } echo "MgSelection from Reader\n"; $reader = $fsvc->SelectFeatures($id, "IntKey", $query); $selection = new MgSelection($map); $layer1 = $map->GetLayers()->GetItem(0); $selection->AddFeatures($layer1, $reader, 0); echo $selection->ToXml(); $envelope = $selection->GetExtents($fsvc); $ll = $envelope->GetLowerLeftCoordinate(); $ur = $envelope->GetUpperRightCoordinate(); echo "(" . $ll->GetX() . "," . $ll->GetY() . ") - (" . $ur->GetX() . "," . $ur->GetY() . ")\n"; } catch (MgException $exc) { echo $exc->GetExceptionMessage() . "\n"; echo $exc->GetDetails() . "\n"; } echo "Done.\n";
public function GetSelectionOverview($sessionId, $mapName, $format) { $fmt = $this->ValidateRepresentation($format, array("xml", "json")); $bIncludeBounds = $this->GetBooleanRequestParameter("bounds", false); $this->EnsureAuthenticationForSite($sessionId); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $resSvc = $siteConn->CreateService(MgServiceType::ResourceService); $featSvc = null; if ($bIncludeBounds) { $featSvc = $siteConn->CreateService(MgServiceType::FeatureService); } $map = new MgMap($siteConn); $map->Open($mapName); $selection = new MgSelection($map); $selection->Open($resSvc, $mapName); $output = "<SelectionOverview>"; if ($bIncludeBounds) { $env = $selection->GetExtents($featSvc); if ($env != null && !$env->IsNull()) { $ll = $env->GetLowerLeftCoordinate(); $ur = $env->GetUpperRightCoordinate(); $output .= "<Bounds>"; $output .= "<MinX>"; $output .= $ll->GetX(); $output .= "</MinX>"; $output .= "<MinY>"; $output .= $ll->GetY(); $output .= "</MinY>"; $output .= "<MaxX>"; $output .= $ur->GetX(); $output .= "</MaxX>"; $output .= "<MaxY>"; $output .= $ur->GetY(); $output .= "</MaxY>"; $output .= "</Bounds>"; } } $layers = $selection->GetLayers(); if ($layers != NULL) { for ($i = 0; $i < $layers->GetCount(); $i++) { $layer = $layers->GetItem($i); $layerName = $layer->GetName(); $output .= "<Layer>"; $output .= "<Name>"; $output .= $layerName; $output .= "</Name>"; $output .= "<SelectionCount>"; $output .= $selection->GetSelectedFeaturesCount($layer, $layer->GetFeatureClassName()); $output .= "</SelectionCount>"; $output .= "<FeaturesUrl>"; $innerFormat = $format == "json" ? "geojson" : $format; $output .= MgUtils::GetNamedRoute($this->app, "/session", "get_selected_features", array("sessionId" => $sessionId, "mapName" => $mapName, "layerName" => $layerName, "format" => $innerFormat)); $output .= "</FeaturesUrl>"; $output .= "</Layer>"; } } $output .= "</SelectionOverview>"; $bs = new MgByteSource($output, strlen($output)); $bs->SetMimeType(MgMimeType::Xml); $br = $bs->GetReader(); if ($format == "json") { $this->OutputXmlByteReaderAsJson($br); } else { $this->OutputByteReader($br); } }