public function GetSiteVersion($format) { //Check for unsupported representations $fmt = $this->ValidateRepresentation($format, array("xml", "json")); try { $this->EnsureAuthenticationForSite(); $admin = new MgServerAdmin(); $admin->Open($this->userInfo); $body = MgBoxedValue::String($admin->GetSiteVersion(), $fmt); if ($fmt == "xml") { $this->app->response->header("Content-Type", MgMimeType::Xml); } else { $this->app->response->header("Content-Type", MgMimeType::Json); } $this->app->response->setBody($body); } catch (MgException $ex) { $this->OnException($ex); } }
function GetSiteVersion() { global $user; $serverAdmin = new MgServerAdmin(); $serverAdmin->Open($user); /* use these lines for MGOS < 2.2 $infoProps = $serverAdmin->GetInformationProperties(); $versionProp = $infoProps->GetItem(MgServerInformationProperties::ServerVersion); $serverVersion = $versionProp->GetValue();*/ $serverVersion = $serverAdmin->GetSiteVersion(); return $serverVersion; }
public function DescribeRuntimeMap($sessionId, $mapName, $format) { $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($sessionId, false); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); //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()); $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", "DESCRIBERUNTIMEMAP"); $param->AddParameter("VERSION", "2.6.0"); $param->AddParameter("SESSION", $sessionId); $param->AddParameter("MAPNAME", $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->Open($mapName); $mapDefId = $map->GetMapDefinition(); $mapDefIdStr = $mapDefId->ToString(); $br = $this->DescribeRuntimeMapXml($mapDefIdStr, $map, $sessionId, $mapName, $iconFormat, $iconWidth, $iconHeight, $reqFeatures, $iconsPerScaleRange, $resSvc, $mappingSvc); if ($format == "json") { $this->OutputXmlByteReaderAsJson($br); } else { $this->OutputByteReader($br); } } }
public function QueryMapFeatures($sessionId, $mapName) { //TODO: Append only works in featurefilter mode. Add append support for geometry-based selections $layerNames = $this->app->request->params("layernames"); $geometry = $this->app->request->params("geometry"); $maxFeatures = $this->app->request->params("maxfeatures"); $selVariant = $this->app->request->params("selectionvariant"); $selColor = $this->app->request->params("selectioncolor"); $selFormat = $this->app->request->params("selectionformat"); $persist = $this->app->request->params("persist"); $reqData = $this->app->request->params("requestdata"); $featFilter = $this->app->request->params("featurefilter"); $bSelectionXml = $this->app->request->params("selectionxml"); $bAppend = $this->app->request->params("append"); $layerAttFilter = $this->app->request->params("layerattributefilter"); $format = $this->app->request->params("format"); //Convert or coerce to defaults if ($format == null) { $format = "xml"; } else { $format = strtolower($format); } if ($maxFeatures == null) { $maxFeatures = -1; } else { $maxFeatures = intval($maxFeatures); } if ($selFormat == null) { $selFormat = "PNG"; } else { $selFormat = strtoupper($selFormat); } if ($layerAttFilter == null) { $layerAttFilter = 3; } else { $layerAttFilter = intval($layerAttFilter); } if ($persist == null) { $persist = true; } else { $persist = $persist == "1" || $persist == "true"; } if ($bSelectionXml == null) { $bSelectionXml = true; } else { $bSelectionXml = $bSelectionXml == "1" || $bSelectionXml == "true"; } if ($bAppend == null) { $bAppend = true; } else { $bAppend = $bAppend == "1" || $bAppend == "true"; } if ($reqData == null) { $reqData = 0; } else { $reqData = intval($reqData); } if ($selColor == null) { $selColor = "0x0000FFFF"; } try { $this->EnsureAuthenticationForSite($sessionId); $siteConn = new MgSiteConnection(); $siteConn->Open($this->userInfo); $admin = new MgServerAdmin(); $admin->Open($this->userInfo); $version = explode(".", $admin->GetSiteVersion()); $bCanUseNative = false; //If appending, we can't use the native operation as that operation does not support appending if (intval($version[0]) > 2) { //3.0 or greater $bCanUseNative = !$bAppend; } else { if (intval($version[0]) == 2 && intval($version[1]) >= 6) { //2.6 or greater $bCanUseNative = !$bAppend; } } //$this->app->log->debug("APPEND: $bAppend"); //$this->app->log->debug("FILTER (Before): $featFilter"); if (!$bSelectionXml) { //Append only works in the absence of geometry if ($geometry == null && $featFilter != null) { $featFilter = $this->TranslateToSelectionXml($siteConn, $mapName, $featFilter, $bAppend); //$this->app->log->debug("FeatFilter: $featFilter"); } } else { //Append only works in the absence of geometry if ($geometry == null && $bAppend) { $featFilter = $this->AppendSelectionXml($siteConn, $mapName, $featFilter); } } //$this->app->log->debug("GEOMETRY: $geometry"); //$this->app->log->debug("FILTER: $featFilter"); //$this->app->log->debug("Can use native: $bCanUseNative"); if ($bCanUseNative) { $req = new MgHttpRequest(""); $param = $req->GetRequestParam(); $param->AddParameter("OPERATION", "QUERYMAPFEATURES"); $param->AddParameter("VERSION", "2.6.0"); $param->AddParameter("SESSION", $sessionId); $param->AddParameter("MAPNAME", $mapName); $param->AddParameter("GEOMETRY", $geometry); $param->AddParameter("SELECTIONVARIANT", $selVariant); $param->AddParameter("MAXFEATURES", $maxFeatures); $param->AddParameter("LAYERNAMES", $layerNames); $param->AddParameter("PERSIST", $persist ? "1" : "0"); $param->AddParameter("LAYERATTRIBUTEFILTER", $layerAttFilter); if ($featFilter != null) { $param->AddParameter("FEATUREFILTER", $featFilter); } $param->AddParameter("REQUESTDATA", $reqData); $param->AddParameter("SELECTIONCOLOR", $selColor); $param->AddParameter("SELECTIONFORMAT", $selFormat); 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); $renderSvc = $siteConn->CreateService(MgServiceType::RenderingService); $layersToQuery = null; if ($layerNames != null) { $layersToQuery = new MgStringCollection(); $names = explode(",", $layerNames); foreach ($names as $name) { $layersToQuery->Add($name); } } $variant = 0; if ($selVariant === "TOUCHES") { $variant = MgFeatureSpatialOperations::Touches; } else { if ($selVariant === "INTERSECTS") { $variant = MgFeatureSpatialOperations::Intersects; } else { if ($selVariant === "WITHIN") { $variant = MgFeatureSpatialOperations::Within; } else { if ($selVariant === "ENVELOPEINTERSECTS") { $variant = MgFeatureSpatialOperations::EnvelopeIntersects; } } } } $map = new MgMap($siteConn); $map->Open($mapName); $selection = new MgSelection($map); $wktRw = new MgWktReaderWriter(); $selectGeom = null; if ($geometry != null) { $selectGeom = $wktRw->Read($geometry); } $featInfo = $renderSvc->QueryFeatures($map, $layersToQuery, $selectGeom, $variant, $featFilter, $maxFeatures, $layerAttFilter); $bHasNewSelection = false; if ($persist) { $sel = $featInfo->GetSelection(); if ($sel != null) { $selXml = $sel->ToXml(); //$this->app->log->debug("Query selection:\n$selXml"); if ($bAppend) { $selOrig = new MgSelection($map); $selOrig->Open($resSvc, $mapName); $selAppend = new MgSelection($map, $selXml); self::MergeSelections($selOrig, $selAppend); $selNewXml = $selOrig->ToXml(); //$this->app->log->debug("Appended selection:\n$selNewXml"); $selection->FromXml($selNewXml); } else { $selection->FromXml($selXml); } $bHasNewSelection = true; } $selection->Save($resSvc, $mapName); } // Render an image of this selection if requested $inlineSelectionImg = null; if (($reqData & self::REQUEST_INLINE_SELECTION) == self::REQUEST_INLINE_SELECTION && $bHasNewSelection) { $color = new MgColor($selColor); $renderOpts = new MgRenderingOptions($selFormat, self::RenderSelection | self::KeepSelection, $color); $inlineSelectionImg = $renderSvc->RenderDynamicOverlay($map, $selection, $renderOpts); } // Collect any attributes of selected features $bRequestAttributes = ($reqData & self::REQUEST_ATTRIBUTES) == self::REQUEST_ATTRIBUTES; $xml = $this->CollectQueryMapFeaturesResult($resSvc, $reqData, $featInfo, $selection, $bRequestAttributes, $inlineSelectionImg); $bs = new MgByteSource($xml, strlen($xml)); $bs->SetMimeType(MgMimeType::Xml); $br = $bs->GetReader(); if ($format == "json") { $this->OutputXmlByteReaderAsJson($br); } else { $this->OutputByteReader($br); } } } catch (MgException $ex) { $this->OnException($ex, $this->GetMimeTypeForFormat($format)); } }