function MultiGeometryFromSelection($featureSrvc, $map, $selText) { $sel = new MgSelection($map, $selText); $selLayers = $sel->GetLayers(); $geomColl = new MgGeometryCollection(); $agfRW = new MgAgfReaderWriter(); $simplyPolygonOnly = true; for ($i = 0; $i < $selLayers->GetCount(); $i++) { $layer = $selLayers->GetItem($i); $filter = $sel->GenerateFilter($layer, $layer->GetFeatureClassName()); $query = new MgFeatureQueryOptions(); $query->SetFilter($filter); $featureSource = new MgResourceIdentifier($layer->GetFeatureSourceId()); $features = $featureSrvc->SelectFeatures($featureSource, $layer->GetFeatureClassName(), $query); if ($features) { $classDef = $features->GetClassDefinition(); $geomPropName = $classDef->GetDefaultGeometryPropertyName(); $j = 0; while ($features->ReadNext()) { $geomReader = $features->GetGeometry($geomPropName); $geom = $agfRW->Read($geomReader); $type = $geom->GetGeometryType(); if ($type == MgGeometryType::MultiPolygon || $type == MgGeometryType::CurvePolygon || $type == MgGeometryType::MultiCurvePolygon) { $simplyPolygonOnly = false; } else { if ($type != MgGeometryType::Polygon) { continue; } } $geomColl->Add($geom); } } } if ($geomColl->GetCount() == 0) { return null; } $gf = new MgGeometryFactory(); if ($simplyPolygonOnly) { $polyColl = new MgPolygonCollection(); for ($i = 0; $i < $geomColl->GetCount(); $i++) { $polyColl->Add($geomColl->GetItem($i)); } return $gf->CreateMultiPolygon($polyColl); } else { return $gf->CreateMultiGeometry($geomColl); } }
// 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";
include 'Common.php'; if (InitializationErrorOccurred()) { DisplayInitializationErrorText(); exit; } include '../../../common/php/Utilities.php'; include 'Utilities.php'; $selText = ""; GetRequestParameters(); try { //load the map runtime state // $map = new MgMap(); $map->Open($resourceService, $mapName); // Create the selection set $selection = new MgSelection($map); if ($selText != "") { $selection->FromXml($selText); } //now return a data struture which is the same as Query.php $featureService = $siteConnection->CreateService(MgServiceType::FeatureService); /* 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); /*holds selection array*/ $properties = NULL; $properties->layers = array(); //process header('Content-type: application/json');
$mapName = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST['MAPNAME'] : $_GET['MAPNAME']; try { // Initialize the Web Extensions and connect to the Server using // the Web Extensions session identifier stored in PHP session state. MgInitializeWebTier($webconfigFilePath); $userInfo = new MgUserInformation($sessionId); $siteConnection = new MgSiteConnection(); $siteConnection->Open($userInfo); $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService); $featureService = $siteConnection->CreateService(MgServiceType::FeatureService); $queryOptions = new MgFeatureQueryOptions(); $map = new MgMap($siteConnection); $map->Open($mapName); // Check for selection data passed via HTTP POST if (isset($_POST['SELECTION']) && $_POST['SELECTION'] != '') { $selection = new MgSelection($map, $_POST['SELECTION']); $selectedLayers = $selection->GetLayers(); } else { $selectedLayers = 0; } if ($selectedLayers) { include 'bufferfunctions.php'; $bufferRingSize = 100; // measured in metres $bufferRingCount = 5; // Set up some objects for coordinate conversion $mapWktSrs = $map->GetMapSRS(); $agfReaderWriter = new MgAgfReaderWriter(); $wktReaderWriter = new MgWktReaderWriter(); $coordinateSystemFactory = new MgCoordinateSystemFactory(); $srs = $coordinateSystemFactory->Create($mapWktSrs);
try { InitializeWebTier(); $cred = new MgUserInformation($sessionId); $cred->SetClientIp(GetClientIp()); $cred->SetClientAgent(GetClientAgent()); //connect to the site and get an instance of the resoucre service // $site = new MgSiteConnection(); $site->Open($cred); $resourceSrvc = $site->CreateService(MgServiceType::ResourceService); //load the map runtime state // $map = new MgMap(); $map->Open($resourceSrvc, $mapName); // Create the selection set and save it $sel = new MgSelection($map); if ($selText != "") { $sel->FromXml($selText); } $sel->Save($resourceSrvc, $mapName); if ($queryInfo) { //Query feature info for the feature in the selection set. This will return the current set //along with property info //There must be only one feature in the feature set $layers = $sel->GetLayers(); if ($layers == null || $layers->GetCount() != 1) { echo "Error: There must be exactly one feature in the set."; ///NOXLATE dbg report only return; } $layer = $layers->GetItem(0);
echo $onfe->GetStackTrace() . "\n"; if ($featureReader) { $featureReader->Close(); } } catch (MgException $e) { //what should we do with general exceptions? echo "/*general exception:"; echo "ERROR: " . $e->GetExceptionMessage(); echo $e->GetDetails() . "*/"; if ($featureReader) { $featureReader->Close(); } } } if ($bExtendSelection) { $selection = new MgSelection($map); $queryOptions = new MgFeatureQueryOptions(); $layers = $map->GetLayers(); foreach ($aLayers as $szLayer => $aLayer) { $oLayer = $layers->GetItem($szLayer); foreach ($aLayer as $szClass => $aFilter) { /* get the feature source from the layer */ $featureResId = new MgResourceIdentifier($oLayer->GetFeatureSourceId()); $featureGeometryName = $oLayer->GetFeatureGeometryName(); $szFilter = implode(' OR ', $aFilter); $queryOptions->setFilter($szFilter); /* the class that is used for this layer will be used to select features */ $class = $oLayer->GetFeatureClassName(); /* select the features */ $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
* * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ /***************************************************************************** * Purpose: clear active selection from the map *****************************************************************************/ include "Common.php"; if (InitializationErrorOccurred()) { DisplayInitializationErrorText(); exit; } try { $resourceSrvc = $siteConnection->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $map->Open($resourceSrvc, $mapName); $sel = new MgSelection($map); $sel->Save($resourceSrvc, $mapName); } catch (MgException $e) { echo "ERROR: " . $e->GetExceptionMessage() . "\n"; echo $e->GetDetails() . "\n"; echo $e->GetStackTrace() . "\n"; }
public function CreateRuntimeMap($format) { $session = $this->app->request->params("session"); $mapDefIdStr = $this->app->request->params("mapdefinition"); $mapName = $this->app->request->params("targetmapname"); $reqFeatures = $this->app->request->params("requestedfeatures"); $iconFormat = $this->app->request->params("iconformat"); $iconWidth = $this->app->request->params("iconwidth"); $iconHeight = $this->app->request->params("iconheight"); $iconsPerScaleRange = $this->app->request->params("iconsperscalerange"); $this->EnsureAuthenticationForSite($session); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); if ($session == null) { $site = $siteConn->GetSite(); $session = $site->CreateSession(); $this->userInfo = new MgUserInformation($session); $siteConn->Open($this->userInfo); } $mdfId = new MgResourceIdentifier($mapDefIdStr); if ($mapName == null) { $mapName = $mdfId->GetName(); } //Assign default values or coerce existing ones to their expected types if ($reqFeatures != null) { $reqFeatures = intval($reqFeatures); } if ($iconFormat == null) { $iconFormat = "PNG"; } if ($iconWidth == null) { $iconWidth = 16; } else { $iconWidth = intval($iconWidth); } if ($iconHeight == null) { $iconHeight = 16; } else { $iconHeight = intval($iconHeight); } if ($iconsPerScaleRange == null) { $iconsPerScaleRange = 25; } else { $iconsPerScaleRange = intval($iconsPerScaleRange); } if ($format == null) { $format = "xml"; } else { $format = strtolower($format); } /* $admin = new MgServerAdmin(); $admin->Open($this->userInfo); $version = explode(".", $admin->GetSiteVersion()); */ $version = $this->app->MG_VERSION; $bCanUseNative = false; if (intval($version[0]) > 2) { //3.0 or greater $bCanUseNative = true; } else { if (intval($version[0]) == 2 && intval($version[1]) >= 6) { //2.6 or greater $bCanUseNative = true; } } if ($bCanUseNative) { $req = new MgHttpRequest(""); $param = $req->GetRequestParam(); $param->AddParameter("OPERATION", "CREATERUNTIMEMAP"); //Hmmm, this may violate REST API design, but if we're on MGOS 3.0 or newer, we must return linked tile set //information to the client if applicable. Meaning this API could return 2 different results depending on the //underlying MGOS version. if (intval($version[0]) >= 3) { $param->AddParameter("VERSION", "3.0.0"); } else { $param->AddParameter("VERSION", "2.6.0"); } $param->AddParameter("SESSION", $session); $param->AddParameter("MAPDEFINITION", $mapDefIdStr); $param->AddParameter("TARGETMAPNAME", $mapName); $param->AddParameter("REQUESTEDFEATURES", $reqFeatures); $param->AddParameter("ICONSPERSCALERANGE", $iconsPerScaleRange); $param->AddParameter("ICONFORMAT", $iconFormat); $param->AddParameter("ICONWIDTH", $iconWidth); $param->AddParameter("ICONHEIGHT", $iconHeight); if ($format === "json") { $param->AddParameter("FORMAT", MgMimeType::Json); } else { $param->AddParameter("FORMAT", MgMimeType::Xml); } $this->ExecuteHttpRequest($req); } else { //Shim the response $resSvc = $siteConn->CreateService(MgServiceType::ResourceService); $mappingSvc = $siteConn->CreateService(MgServiceType::MappingService); $map = new MgMap($siteConn); $map->Create($mdfId, $mapName); $mapStateId = new MgResourceIdentifier("Session:{$session}//{$mapName}.Map"); $sel = new MgSelection($map); $sel->Save($resSvc, $mapName); $map->Save($resSvc, $mapStateId); $br = $this->DescribeRuntimeMapXml($mapDefIdStr, $map, $session, $mapName, $iconFormat, $iconWidth, $iconHeight, $reqFeatures, $iconsPerScaleRange, $resSvc, $mappingSvc); if ($format == "json") { $this->OutputXmlByteReaderAsJson($br); } else { $this->OutputByteReader($br); } } }
//finally, creation of the feature source $sdfParams = new MgCreateSdfParams("LatLong", $srsDefMap, $schema); $featureSrvc->CreateFeatureSource($dataSourceId, $sdfParams); //Add layer to map $layer = new MgLayer($layerDefId, $resourceSrvc); $layer->SetName($bufferName); $layer->SetLegendLabel($bufferName); $layer->SetDisplayInLegend(true); $layer->SetSelectable(true); $layers->Insert(0, $layer); } else { //data source already exist. clear its content // ClearDataSource($featureSrvc, $dataSourceId, $featureName); } $sel = new MgSelection($map, $selText); $selLayers = $sel->GetLayers(); $agfRW = new MgAgfReaderWriter(); $bufferGeometries = new MgGeometryCollection(); $commands = new MgFeatureCommandCollection(); $featId = 0; $propCollection = new MgBatchPropertyCollection(); $excludedLayers = 0; $srsDs = null; $inputGeometries = new MgGeometryCollection(); $bufferFeatures = 0; $allCompatible = false; for ($li = 0; $li < $selLayers->GetCount(); $li++) { $selLayer = $selLayers->GetItem($li); $inputLayer = false; $selLayerName = $selLayer->GetName();
function GetSelectionXML() { $resourceService = $this->site->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $map->Open($resourceService, $this->args['MAPNAME']); $markupLayer = $map->GetLayers()->GetItem('_' . $this->GetMarkupName()); $selection = new MgSelection($map); $selection->AddFeatureIdInt32($markupLayer, $markupLayer->GetFeatureClassName(), (int) $this->args['MARKUPFEATURE']); return $selection->ToXML(); }
require_once 'classes/featureinfo.php'; $args = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST : $_GET; try { $responseType = 'text/plain'; $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 */
//finally, creation of the feature source $sdfParams = new MgCreateSdfParams("LatLong", $srsDefMap, $schema); $featureSrvc->CreateFeatureSource($dataSourceId, $sdfParams); //Add layer to map $layer = new MgLayer($layerDefId, $resourceSrvc); $layer->SetName($bufferName); $layer->SetLegendLabel($bufferName); $layer->SetDisplayInLegend(true); $layer->SetSelectable(true); $layers->Insert(0, $layer); } else { //data source already exist. clear its content // ClearDataSource($featureSrvc, $dataSourceId, $featureName); } $sel = new MgSelection($map); $sel->Open($resourceSrvc, $mapName); $selLayers = $sel->GetLayers(); $agfRW = new MgAgfReaderWriter(); $bufferGeometries = new MgGeometryCollection(); $commands = new MgFeatureCommandCollection(); $featId = 0; $propCollection = new MgBatchPropertyCollection(); $excludedLayers = 0; $srsDs = null; $inputGeometries = new MgGeometryCollection(); $bufferFeatures = 0; $allCompatible = false; for ($li = 0; $li < $selLayers->GetCount(); $li++) { $selLayer = $selLayers->GetItem($li); $inputLayer = false;
$featureSourceId = new MgResourceIdentifier($featureSourceName); CreateFeatureSource($map, $featureSourceId, $layerName, $featureService, MgFeatureGeometricType::Surface, $schemaName); //create the output layer definition of poylgon type $layerDefinition = "Session:" . $sessionID . "//" . $layerName . ".LayerDefinition"; $layerId = new MgResourceIdentifier($layerDefinition); BuildLayerContent($resourceService, $layerId, $featureSourceName, $schemaName, $layerName, $fillColor, $borderColor); $layer = new MGLayer($layerId, $resourceService); $layer->SetName($layerName); $layer->SetLegendLabel($layerName); $layer->SetDisplayInLegend(true); $layer->SetSelectable(true); $layers->Insert(0, $layer); } //loop through the selection of the input layer. If no selection, select all features $queryOptions = new MgFeatureQueryOptions(); $selection = new MgSelection($map); $selection->Open($resourceService, $mapName); $selLayers = $selection->GetLayers(); /* if we are merging, put all the geometries into a single geometry collection */ $inputGeometries = new MgGeometryCollection(); /* store the insert commands for creating buffers */ $oCommandsColl = new MgFeatureCommandCollection(); $nCount = $selLayers->GetCount(); for ($i = 0; $i < $nCount; $i++) { $selLayer = $selLayers->GetItem($i); $featureClassName = $selLayer->GetFeatureClassName(); $filter = $selection->GenerateFilter($selLayer, $featureClassName); if ($filter == '') { continue; }
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ include 'Common.php'; include '../../common/php/Utilities.php'; include 'Utilities.php'; $selText = ""; GetRequestParameters(); try { //load the map runtime state // $map = new MgMap(); $map->Open($resourceService, $mapName); // Create the selection set and save it $selection = new MgSelection($map); if ($selText != "") { $selection->FromXml($selText); } $selection->Save($resourceService, $mapName); //now return a data struture which is the same as Query.php $featureService = $siteConnection->CreateService(MgServiceType::FeatureService); /* 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); /*holds selection array*/ $properties = NULL; $properties->layers = array(); //process
public function UpdateSelectionFromXml($sessionId, $mapName) { $this->EnsureAuthenticationForSite($sessionId); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $resSvc = $siteConn->CreateService(MgServiceType::ResourceService); $map = new MgMap($siteConn); $map->Open($mapName); $xml = trim($this->app->request->getBody()); $selection = new MgSelection($map); $selection->FromXml($xml); $selection->Save($resSvc, $mapName); }
$val = $features->GetInt32($propName); break; case MgPropertyType::Int64: $val = $features->GetInt64($propName); break; case MgPropertyType::String: $val = $features->GetString($propName); break; case MgPropertyType::DateTime: $val = $features->GetDateTime($propName)->ToString(); break; } } // Generate XML to selection this feature // $sel = new MgSelection($map); $idProps = new MgPropertyCollection(); foreach ($idPropNames as $id) { $idPropType = $features->GetPropertyType($id); switch ($idPropType) { case MgPropertyType::Int32: $idProps->Add(new MgInt32Property($id, $features->GetInt32($id))); break; case MgPropertyType::String: $idProps->Add(new MgStringProperty($id, $features->GetString($id))); break; case MgPropertyType::Int64: $idProps->Add(new MgInt64Property($id, $features->GetInt64($id))); break; case MgPropertyType::Double: $idProps->Add(new MgDoubleProperty($id, $features->GetDouble($id)));
function GetSelectionXML() { $resourceService = $this->site->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $map->Open($resourceService, $this->args['MAPNAME']); $markupLayer = $map->GetLayers()->GetItem('_' . $this->GetMarkupName()); $selection = new MgSelection($map); $className = $markupLayer->GetFeatureClassName(); $ids = $this->args['MARKUPFEATURE']; if (is_array($ids)) { foreach ($ids as $id) { $selection->AddFeatureIdInt32($markupLayer, $className, (int) $id); } } else { $selection->AddFeatureIdInt32($markupLayer, $className, (int) $ids); } return $selection->ToXML(); }
$mapName = $args['MAPNAME']; try { // Initialize the Web Extensions and connect to the Server using // the Web Extensions session identifier stored in PHP session state. MgInitializeWebTier($webconfigFilePath); $userInfo = new MgUserInformation($sessionId); $siteConnection = new MgSiteConnection(); $siteConnection->Open($userInfo); $featureService = $siteConnection->CreateService(MgServiceType::FeatureService); $map = new MgMap($siteConnection); $map->Open($mapName); // ---------------------------------------------------------- // Use the following code for AJAX or DWF Viewers // This requires passing selection data via HTTP POST if (isset($_POST['SELECTION']) && $_POST['SELECTION'] != '') { $selection = new MgSelection($map, $_POST['SELECTION']); $layers = $selection->GetLayers(); } else { $layers = 0; } // --------------------------------------------------------- // --------------------------------------------------------- // Use the following code for AJAX Viewers only. // This does not require passing selection data via HTTP POST. // // $selection = new MgSelection($map); // $selection->Open($resourceService, $mapName); // $layers = $selection->GetLayers(); // --------------------------------------------------------- if ($layers) { $queryOptions = new MgFeatureQueryOptions();
if (InitializationErrorOccurred()) { DisplayInitializationErrorText(); exit; } include '../../../common/php/Utilities.php'; include 'Utilities.php'; $selText = ""; $getExtents = false; GetRequestParameters(); try { //load the map runtime state // $map = new MgMap(); $map->Open($resourceService, $mapName); // Create the selection set and save it $selection = new MgSelection($map); if ($selText != "") { $selection->FromXml($selText); } $selection->Save($resourceService, $mapName); //now return a data struture which is the same as Query.php //process header('Content-type: application/json'); header('X-JSON: true'); $layers = $selection->GetLayers(); $result = new stdClass(); $result->hasSelection = false; if ($layers && $layers->GetCount() >= 0) { $result->hasSelection = true; $result->extents = new stdClass(); if ($getExtents) {
$featureReader->ReadNext(); $districtGeometryData = $featureReader->GetGeometry('Data'); // Convert the AGF binary data to MgGeometry. $agfReaderWriter = new MgAgfReaderWriter(); $districtGeometry = $agfReaderWriter->Read($districtGeometryData); // Create a filter to select the desired features. Combine // a basic filter and a spatial filter. $queryOptions = new MgFeatureQueryOptions(); $queryOptions->SetFilter("RNAME LIKE 'SCHMITT%'"); $queryOptions->SetSpatialFilter('SHPGEOM', $districtGeometry, MgFeatureSpatialOperations::Inside); // Get the features from the feature source, // turn it into a selection, then save the selection as XML. $layer = $map->GetLayers()->GetItem('Parcels'); $featureReader = $layer->SelectFeatures($queryOptions); $layer = $map->GetLayers()->GetItem('Parcels'); $selection = new MgSelection($map); $selection->AddFeatures($layer, $featureReader, 0); $selectionXml = $selection->ToXml(); echo 'Selecting parcels owned by Schmitt in District 1'; } catch (MgException $e) { echo $e->GetExceptionMessage(); echo $e->GetDetails(); } ?> </body> <script language="javascript"> <!-- Emit this function and assocate it with the onLoad event for the --> <!-- page so that it gets executed when this page loads in the -->
function GetSelectionXML() { $json = new Services_JSON(); $resourceService = $this->site->CreateService(MgServiceType::ResourceService); $featureService = $this->site->CreateService(MgServiceType::FeatureService); $map = new MgMap(); $map->Open($resourceService, $this->args['MAPNAME']); $layer = $map->GetLayers()->GetItem($this->args['LAYERNAME']); $resId = new MgResourceIdentifier($layer->GetFeatureSourceId()); $featureClass = $layer->GetFeatureClassName(); $schemaAndClass = explode(":", $featureClass); $classDef = $featureService->GetClassDefinition($resId, $schemaAndClass[0], $schemaAndClass[1]); $properties = new MgPropertyCollection(); $idList = $json->decode($this->args['IDLIST']); foreach ($idList as $key => $value) { switch ($classDef->GetProperties()->GetItem($key)->GetDataType()) { case MgPropertyType::Boolean: $properties->Add(new MgBooleanProperty($key, $value)); break; case MgPropertyType::Byte: $properties->Add(new MgByteProperty($key, $value)); break; case MgPropertyType::Single: $properties->Add(new MgSingleProperty($key, $value)); break; case MgPropertyType::Double: $properties->Add(new MgDoubleProperty($key, $value)); break; case MgPropertyType::Int16: $properties->Add(new MgInt16Property($key, $value)); break; case MgPropertyType::Int32: $properties->Add(new MgInt32Property($key, $value)); break; case MgPropertyType::Int64: $properties->Add(new MgInt64Property($key, $value)); break; case MgPropertyType::String: $properties->Add(new MgStringProperty($key, $value)); break; case MgPropertyType::DateTime: $properties->Add(new MgDateTimeProperty($key, $value)); break; case MgPropertyType::Null: case MgPropertyType::Blob: case MgPropertyType::Clob: case MgPropertyType::Feature: case MgPropertyType::Geometry: case MgPropertyType::Raster: break; } } $selection = new MgSelection($map); $selection->AddFeatureIds($layer, $featureClass, $properties); return $selection->ToXml(); }
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(); @($oMin = $extents->GetLowerLeftCoordinate()); @($oMax = $extents->GetUpperRightCoordinate()); @($srs = $map->GetMapSRS()); if ($srs != "") {
exit; } $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'PNG'; $layout = isset($_REQUEST['layout']) ? $_REQUEST['layout'] : null; $scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : null; $imgWidth = isset($_REQUEST['width']) ? $_REQUEST['width'] : null; $imgHeight = isset($_REQUEST['height']) ? $_REQUEST['height'] : null; $pageHeight = isset($_REQUEST['pageheight']) ? $_REQUEST['pageheight'] : 11; $pageWidth = isset($_REQUEST['pagewidth']) ? $_REQUEST['pagewidth'] : 8.5; $aMargins = isset($_REQUEST['margins']) ? explode(',', $_REQUEST['margins']) : array(0, 0, 0, 0); try { $mappingService = $siteConnection->CreateService(MgServiceType::MappingService); $renderingService = $siteConnection->CreateService(MgServiceType::RenderingService); $map = new MgMap(); $map->Open($resourceService, $mapName); $selection = new MgSelection($map); $selection->Open($resourceService, $mapName); //get current center as a coordinate $center = $map->GetViewCenter()->GetCoordinate(); //plot with the passed scale, if provided $scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : $map->GetViewScale(); if ($format == 'DWF') { $oLayout = null; if ($layout) { $layoutId = new MgResourceIdentifier($layout); $layoutId->Validate(); $oLayout = new MgLayout($layoutId, 'Map', 'meters'); } $oPlotSpec = new MgPlotSpecification($pageWidth, $pageHeight, MgPageUnitsType::Inches, $aMargins[0], $aMargins[1], $aMargins[2], $aMargins[3]); $dwfVersion = new MgDwfVersion('6.01', '1.2'); $oImg = $mappingService->GeneratePlot($map, $center, $scale, $oPlotSpec, $oLayout, $dwfVersion);
case MgPropertyType::Int16: $val = $features->GetInt16($propName); break; case MgPropertyType::Int32: $val = $features->GetInt32($propName); break; case MgPropertyType::Int64: $val = $features->GetInt64($propName); break; case MgPropertyType::String: $val = $features->GetString($propName); break; } // Generate XML to selection this feature // $sel = new MgSelection($map); if ($multiIds) { throw new SearchError(GetLocalizedString("SEARCHNOMULTIPROP", $locale), $searchError); } else { if ($i == 0) { $idPropType = $features->GetPropertyType($idPropName); } switch ($idPropType) { case MgPropertyType::Int32: $sel->AddFeatureIdInt32($layer, $featureClassName, $features->GetInt32($idPropName)); break; case MgPropertyType::String: $sel->AddFeatureIdString($layer, $featureClassName, $features->GetString($idPropName)); break; default: throw new SearchError(FormatMessage("SEARCHTYYPENOTSUP", $locale, array($idPropType)), $searchError);