public function addMultipleMarkup($count) { for ($ii = 1; $ii <= $count; $ii++) { $markup = new Markup\SimpleTemplateMarkup("name{$ii}", "p{$ii}", "c{$ii}"); $this->mgr->registerMarkup($markup); } }
public function testSimpleTemplateGeneration() { $markupMgr = new MarkupManager(); $filePath = __DIR__ . "/mocks/basic_template"; $cmpPath = __DIR__ . "/mocks/generated_template"; $date = date(DATE_RFC2822, time()); $markupName = new Markup\SimpleTemplateMarkup('name', 'NAME', 'John Doe'); $markupTime = new Markup\MethodInvocationMarkup('time', 'TIME', array('date', array(DATE_RFC2822, time()))); $markupMgr->registerMarkup($markupName)->registerMarkup($markupTime); Templater::loadCache(file_get_contents($filePath)); Templater::setMarkupMgr($markupMgr); Templater::generateTemplate(); $generatedTemplate = Templater::retrieveTemplate(); self::assertEquals(trim(file_get_contents($cmpPath)) . " " . $date, trim($generatedTemplate)); }
function UploadMarkup() { $locale = "en"; if (array_key_exists("LOCALE", $this->args)) { $locale = $this->args["LOCALE"]; } $uploadFileParts = pathinfo($_FILES["UPLOADFILE"]["name"]); $fdoProvider = $this->GetProviderFromExtension($uploadFileParts["extension"]); if ($fdoProvider == null) { throw new Exception(GetLocalizedString("REDLINEUPLOADUNKNOWNPROVIDER", $locale)); } $resourceService = $this->site->CreateService(MgServiceType::ResourceService); $featureService = $this->site->CreateService(MgServiceType::FeatureService); $bs = new MgByteSource($_FILES["UPLOADFILE"]["tmp_name"]); $br = $bs->GetReader(); //Use file name to drive all parameters $baseName = $uploadFileParts["filename"]; $this->UniqueMarkupName($baseName); //Guard against potential duplicates $ext = $uploadFileParts["extension"]; $markupLayerResId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $baseName . ".LayerDefinition"); $markupFsId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $baseName . '.FeatureSource'); //Set up feature source document $dataName = $baseName . "." . $ext; $fileParam = "File"; $shpFileParts = array(); if (strcmp($fdoProvider, "OSGeo.SHP") == 0) { $dataName = null; $fileParam = "DefaultFileLocation"; $zip = new ZipArchive(); if ($zip->open($_FILES["UPLOADFILE"]["tmp_name"]) === TRUE) { for ($i = 0; $i < $zip->numFiles; $i++) { $stat = $zip->statIndex($i); $filePath = tempnam(sys_get_temp_dir(), "upload"); //Dump to temp file file_put_contents($filePath, $zip->getFromIndex($i)); //Stash for later upload and cleanup $entry = $stat["name"]; $shpFileParts[$entry] = $filePath; if (substr($entry, strlen($entry) - strlen(".shp")) == ".shp") { $dataName = $entry; } } //Abort if we can't find a .shp file. This is not a valid zip file if ($dataName == null) { throw new Exception(GetLocalizedString("REDLINEUPLOADSHPZIPERROR", $locale)); } } else { throw new Exception(GetLocalizedString("REDLINEUPLOADSHPZIPERROR", $locale)); } } $extraXml = ""; if (strcmp($fdoProvider, "OSGeo.SDF") == 0) { //Need to set ReadOnly = false for SDF $extraXml = "<Parameter><Name>ReadOnly</Name><Value>FALSE</Value></Parameter>"; } $fsXml = sprintf(file_get_contents("templates/markupfeaturesource.xml"), $fdoProvider, $fileParam, $dataName, $extraXml); $bs2 = new MgByteSource($fsXml, strlen($fsXml)); $resourceService->SetResource($markupFsId, $bs2->GetReader(), null); if (count($shpFileParts) > 0) { foreach ($shpFileParts as $name => $path) { $bs3 = new MgByteSource($path); $resourceService->SetResourceData($markupFsId, $name, "File", $bs3->GetReader()); //Cleanup unlink($path); } } else { //Not a SHP file $resourceService->SetResourceData($markupFsId, $dataName, "File", $bs->GetReader()); } //Query the geometry types $schemas = $featureService->DescribeSchema($markupFsId, "", null); $schema = $schemas->GetItem(0); $classes = $schema->GetClasses(); $klass = $classes->GetItem(0); $geomProp = $klass->GetDefaultGeometryPropertyName(); $clsProps = $klass->GetProperties(); $className = $schema->GetName() . ":" . $klass->GetName(); $geomTypes = -1; if ($clsProps->IndexOf($geomProp) >= 0) { $geom = $clsProps->GetItem($geomProp); $geomTypes = $geom->GetGeometryTypes(); //Since we're here. Validate the schema requirements. If this was created by this widget previously //it will be valid $idProps = $klass->GetIdentityProperties(); if ($idProps->GetCount() != 1) { throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale)); } else { //Must be auto-generated (implying numerical as well) $keyProp = $idProps->GetItem(0); if (!$keyProp->IsAutoGenerated()) { throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale)); } } if ($clsProps->IndexOf("Text") < 0) { throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale)); } } else { throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale)); } //Set up default style args $this->args["MARKUPNAME"] = $baseName; $this->args["MARKERCOLOR"] = DefaultStyle::MARKER_COLOR; $this->args["MARKERTYPE"] = DefaultStyle::MARKER_TYPE; $this->args["MARKERSIZEUNITS"] = DefaultStyle::MARKER_SIZE_UNITS; $this->args["MARKERSIZE"] = DefaultStyle::MARKER_SIZE; $this->args["LINECOLOR"] = DefaultStyle::LINE_COLOR; $this->args["LINEPATTERN"] = DefaultStyle::LINE_PATTERN; $this->args["LINESIZEUNITS"] = DefaultStyle::LINE_SIZE_UNITS; $this->args["LINETHICKNESS"] = DefaultStyle::LINE_THICKNESS; $this->args["FILLPATTERN"] = DefaultStyle::FILL_PATTERN; $this->args["FILLTRANSPARENCY"] = DefaultStyle::FILL_TRANSPARENCY; $this->args["FILLFORECOLOR"] = DefaultStyle::FILL_FORE_COLOR; $this->args["FILLBACKCOLOR"] = DefaultStyle::FILL_BACK_COLOR; $this->args["FILLBACKTRANS"] = DefaultStyle::FILL_BACK_TRANS; $this->args["BORDERPATTERN"] = DefaultStyle::BORDER_PATTERN; $this->args["BORDERSIZEUNITS"] = DefaultStyle::BORDER_SIZE_UNITS; $this->args["BORDERCOLOR"] = DefaultStyle::BORDER_COLOR; $this->args["BORDERTHICKNESS"] = DefaultStyle::BORDER_THICKNESS; $this->args["LABELSIZEUNITS"] = DefaultStyle::LABEL_SIZE_UNITS; $this->args["LABELFONTSIZE"] = DefaultStyle::LABEL_FONT_SIZE; //Omission is considered false, which is the default. If you ever change //the default style values, uncomment the matching "true" values //$this->args["LABELBOLD"] = DefaultStyle::LABEL_BOLD; //$this->args["LABELITALIC"] = DefaultStyle::LABEL_ITALIC; //$this->args["LABELUNDERLINE"] = DefaultStyle::LABEL_UNDERLINE; $this->args["LABELFORECOLOR"] = DefaultStyle::LABEL_FORE_COLOR; $this->args["LABELBACKCOLOR"] = DefaultStyle::LABEL_BACK_COLOR; $this->args["LABELBACKSTYLE"] = DefaultStyle::LABEL_BACK_STYLE; $markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($markupFsId->ToString(), $className); $layerBs = new MgByteSource($markupLayerDefinition, strlen($markupLayerDefinition)); //Save to new resource or overwrite existing $resourceService->SetResource($markupLayerResId, $layerBs->GetReader(), null); //Add to markup registry $cmds = new MgFeatureCommandCollection(); $props = new MgPropertyCollection(); $props->Add(new MgStringProperty("ResourceId", $markupFsId->ToString())); $props->Add(new MgStringProperty("LayerDefinition", $markupLayerResId->ToString())); $props->Add(new MgStringProperty("Name", $markupLayerResId->GetName())); $props->Add(new MgStringProperty("FdoProvider", $fdoProvider)); $props->Add(new MgInt32Property("GeometryTypes", $geomTypes)); $insertCmd = new MgInsertFeatures("Default:MarkupRegistry", $props); $cmds->Add($insertCmd); $res = $featureService->UpdateFeatures($this->markupRegistryId, $cmds, false); MarkupManager::CleanupReaders($res); //Add to map $this->args["MARKUPLAYER"] = $markupLayerResId->ToString(); $this->OpenMarkup(); }
<?php $fusionMGpath = '../../layers/MapGuide/php/'; require_once $fusionMGpath . 'Common.php'; if (InitializationErrorOccurred()) { DisplayInitializationErrorHTML(); exit; } require_once $fusionMGpath . 'Utilities.php'; require_once $fusionMGpath . 'JSON.php'; require_once 'classes/markupcommand.php'; require_once 'classes/defaultstyle.php'; require_once 'classes/markupmanager.php'; $args = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST : $_GET; $markupManager = new MarkupManager($args); //Get the layer style and feature source for this Layer Definition. The whole UI is initialized from the values found here $style = $markupManager->GetLayerStyle($args["EDITMARKUPLAYER"]); $editFeatureSource = $markupManager->GetFeatureSource($args["EDITMARKUPLAYER"]); $errorMsg = null; $errorDetail = null; $defaultFormat = null; $defaultGeomType = null; if (array_key_exists("REDLINEFORMAT", $args) && array_key_exists("REDLINEGEOMTYPE", $args)) { if (strcmp($args["REDLINEFORMAT"], "SDF") == 0) { $defaultFormat = $args["REDLINEFORMAT"]; $defaultGeomType = $args["REDLINEGEOMTYPE"]; } else { if (strcmp($args["REDLINEFORMAT"], "SHP") == 0) { $defaultFormat = $args["REDLINEFORMAT"]; $defaultGeomType = $args["REDLINEGEOMTYPE"]; } else {
if (strcmp($args["REDLINEFORMAT"], "SQLite") == 0) { $defaultFormat = $args["REDLINEFORMAT"]; $defaultCmd = MarkupCommand::CreateSqlite; $defaultGeomType = $args["REDLINEGEOMTYPE"]; } } } } SetLocalizedFilesPath(GetLocalizationPath()); if (isset($_REQUEST['LOCALE'])) { $locale = $_REQUEST['LOCALE']; } else { $locale = GetDefaultLocale(); } try { $markupManager = new MarkupManager($args); if (array_key_exists('MARKUPCOMMAND', $args)) { $cmd = $args['MARKUPCOMMAND']; switch ($cmd) { case MarkupCommand::EditStyle: $markupManager->CreateMarkup(); $refreshMap = true; break; case MarkupCommand::Open: $markupManager->OpenMarkup(); $refreshMap = true; break; case MarkupCommand::Delete: $markupManager->DeleteMarkup(); break; case MarkupCommand::Refresh:
$args["BORDERCOLOR"] = DefaultStyle::BORDER_COLOR; $args["BORDERTHICKNESS"] = DefaultStyle::BORDER_THICKNESS; $args["LABELSIZEUNITS"] = DefaultStyle::LABEL_SIZE_UNITS; $args["LABELFONTSIZE"] = DefaultStyle::LABEL_FONT_SIZE; //Omission is considered false, which is the default. If you ever change //the default style values, uncomment the matching "true" values //$args["LABELBOLD"] = DefaultStyle::LABEL_BOLD; //$args["LABELITALIC"] = DefaultStyle::LABEL_ITALIC; //$args["LABELUNDERLINE"] = DefaultStyle::LABEL_UNDERLINE; $args["LABELFORECOLOR"] = DefaultStyle::LABEL_FORE_COLOR; $args["LABELBACKCOLOR"] = DefaultStyle::LABEL_BACK_COLOR; $args["LABELBACKSTYLE"] = DefaultStyle::LABEL_BACK_STYLE; $markupManager = new MarkupManager($args); $layerDef = $markupManager->CreateMarkup(); $resId = new MgResourceIdentifier($layerDef); $layerName = $resId->GetName(); $markupManager->SetArgument("MARKUPLAYER", $layerDef); $markupManager->OpenMarkup(); $responseJson = "{ success: true, refreshMap: true, layerDefinition: '$layerDef', layerName: '$layerName' }"; } catch (MgException $mge) { $errorMsg = $mge->GetExceptionMessage(); $errorDetail = $mge->GetDetails(); $stackTrace = $mge->GetStackTrace(); $responseJson = "{success: false, refreshMap: false, message:'$errorMsg\nDetail: $errorDetail\nStack Trace: $stackTrace'}"; }