[fusion-commits] r2505 - in trunk: text widgets/Redline widgets/Redline/classes widgets/Redline/templates

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed Jan 4 01:04:14 EST 2012


Author: jng
Date: 2012-01-03 22:04:13 -0800 (Tue, 03 Jan 2012)
New Revision: 2505

Added:
   trunk/widgets/Redline/templates/markupfeaturesource.xml
   trunk/widgets/Redline/uploadmarkup.php
Modified:
   trunk/text/en
   trunk/widgets/Redline/classes/markupmanager.php
   trunk/widgets/Redline/markupmain.php
Log:
#508: Improve redline widget usability (part 4): Add support for uploading previously downloaded redline SDF files or SDF files with an identical schema. Note we currently don't do any validation on the uploaded file. We assume it matches the data file requirements (ie. Originally created by this widget or has an identical schema)

Modified: trunk/text/en
===================================================================
--- trunk/text/en	2012-01-04 05:12:13 UTC (rev 2504)
+++ trunk/text/en	2012-01-04 06:04:13 UTC (rev 2505)
@@ -313,6 +313,14 @@
 REDLINEUPDATETEXT       = Update Text
 REDLINEEDITCLOSE        = Close
 
+# Redline Upload
+REDLINEUPLOAD           = Upload Redline
+REDLINEDATAFILE         = Redline Data File
+REDLINEUPLOADNOTE       = Note: Data file must be a SDF file and you can only data files that have either been originally created by this widget or have an identical feature schema.
+REDLINEUPLOADREQUIRED   = Redline Data File not specified
+REDLINEUPLOADTEXT       = Upload
+REDLINEUPLOADCLOSE      = Close
+
 # HtmlViewerAbout
 HTMLABOUTTITLE          = About %s
 HTMLABOUTTITLEBAR       = MapGuide Viewer

Modified: trunk/widgets/Redline/classes/markupmanager.php
===================================================================
--- trunk/widgets/Redline/classes/markupmanager.php	2012-01-04 05:12:13 UTC (rev 2504)
+++ trunk/widgets/Redline/classes/markupmanager.php	2012-01-04 06:04:13 UTC (rev 2505)
@@ -308,36 +308,10 @@
 		}
 	}
     
-	function CreateMarkup()
-	{
-        $markupName = $this->args["MARKUPNAME"];
-		$this->UniqueMarkupName($markupName);
-		
-		$resourceService = $this->site->CreateService(MgServiceType::ResourceService);
-		$featureService = $this->site->CreateService(MgServiceType::FeatureService);
-        
-        $map = new MgMap();
-		$map->Open($resourceService, $this->args['MAPNAME']);
+    function CreateMarkupLayerDefinitionContent($featureSourceId)
+    {
+        // Create the Markup Layer Definition. Create or update, this code is the same.
 
-        $featureSourceId = "";
-        $bUpdate = array_key_exists("EDITMARKUPLAYER", $this->args) && array_key_exists("MARKUPLAYERNAME", $this->args) && array_key_exists("EDITFEATURESOURCE", $this->args);
-        
-		// Create the Markup Feature Source (SDF) if not updating
-        if (!$bUpdate)
-        {
-            $markupSdfResId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $markupName . '.FeatureSource');
-            
-            $markupSchema = MarkupSchemaFactory::CreateMarkupSchema();
-            $sdfParams = new MgCreateSdfParams('Default', $map->GetMapSRS(), $markupSchema);
-            $featureService->CreateFeatureSource($markupSdfResId, $sdfParams);
-            $featureSourceId = $markupSdfResId->ToString();
-        }
-        else 
-        {
-            $featureSourceId = $this->args["EDITFEATURESOURCE"];
-        }
-		// Create the Markup Layer Definition. Create or update, this code is the same.
-
 		$hexFgTransparency = sprintf("%02x", 255 * (100 - $this->args['FILLTRANSPARENCY']) / 100); // Convert % to an alpha value
 		$hexBgTransparency = $this->args['FILLBACKTRANS'] ? "FF" : "00";							 // All or nothing
 		$bold = array_key_exists('LABELBOLD', $this->args) ? "true" : "false";
@@ -391,7 +365,40 @@
 			$this->args['BORDERTHICKNESS'], 					//<Thickness> - Fill
 			'FF' . $this->args['BORDERCOLOR'], 					//<Color> - Fill
 			$this->args['BORDERSIZEUNITS']); 					//<Unit> - Fill
+            
+        return $markupLayerDefinition;
+    }
+    
+	function CreateMarkup()
+	{
+        $markupName = $this->args["MARKUPNAME"];
+		$this->UniqueMarkupName($markupName);
 		
+		$resourceService = $this->site->CreateService(MgServiceType::ResourceService);
+		$featureService = $this->site->CreateService(MgServiceType::FeatureService);
+        
+        $map = new MgMap();
+		$map->Open($resourceService, $this->args['MAPNAME']);
+
+        $featureSourceId = "";
+        $bUpdate = array_key_exists("EDITMARKUPLAYER", $this->args) && array_key_exists("MARKUPLAYERNAME", $this->args) && array_key_exists("EDITFEATURESOURCE", $this->args);
+        
+		// Create the Markup Feature Source (SDF) if not updating
+        if (!$bUpdate)
+        {
+            $markupSdfResId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $markupName . '.FeatureSource');
+            
+            $markupSchema = MarkupSchemaFactory::CreateMarkupSchema();
+            $sdfParams = new MgCreateSdfParams('Default', $map->GetMapSRS(), $markupSchema);
+            $featureService->CreateFeatureSource($markupSdfResId, $sdfParams);
+            $featureSourceId = $markupSdfResId->ToString();
+        }
+        else 
+        {
+            $featureSourceId = $this->args["EDITFEATURESOURCE"];
+        }
+		
+		$markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($featureSourceId);
 		$byteSource = new MgByteSource($markupLayerDefinition, strlen($markupLayerDefinition));
         //Save to new resource or overwrite existing
         $layerDefId = new MgResourceIdentifier($bUpdate ? $this->args["EDITMARKUPLAYER"] : ($this->GetResourceIdPrefix() . $markupName . '.LayerDefinition'));
@@ -474,7 +481,85 @@
         header("Content-Length: " . strlen($outputBuffer));
         echo $outputBuffer;
     }
+    
+    function UploadMarkup()
+    {
+        $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
+        $featureService = $this->site->CreateService(MgServiceType::FeatureService);
+        $bs = new MgByteSource($_FILES["UPLOADFILE"]["tmp_name"]);
+        $br = $bs->GetReader();
 
+        $uploadFileParts = pathinfo($_FILES["UPLOADFILE"]["name"]);
+        //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");
+		$markupSdfResId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $baseName . '.FeatureSource');
+        
+        $dataName = $baseName . "." . $ext;
+        $fsXml = sprintf(file_get_contents("templates/markupfeaturesource.xml"), $dataName);
+        $bs2 = new MgByteSource($fsXml, strlen($fsXml));
+        $resourceService->SetResource($markupSdfResId, $bs2->GetReader(), null);
+        $resourceService->SetResourceData($markupSdfResId, $dataName, "File", $bs->GetReader());
+        
+        //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($markupSdfResId->ToString());
+        
+		$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", $markupSdfResId->ToString()));
+        $props->Add(new MgStringProperty("LayerDefinition", $markupLayerResId->ToString()));
+        $props->Add(new MgStringProperty("Name", $markupLayerResId->GetName()));
+        $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();
+    }
+
 	function GetOpenMarkup()
 	{
 		$openMarkup = array();

Modified: trunk/widgets/Redline/markupmain.php
===================================================================
--- trunk/widgets/Redline/markupmain.php	2012-01-04 05:12:13 UTC (rev 2504)
+++ trunk/widgets/Redline/markupmain.php	2012-01-04 06:04:13 UTC (rev 2505)
@@ -50,6 +50,10 @@
 				$markupManager->CloseMarkup();
 				$refreshMap = true;
 				break;
+            case MarkupCommand::Upload:
+                $markupManager->UploadMarkup();
+                $refreshMap = true;
+                break;
             case MarkupCommand::Download:
                 $markupManager->DownloadMarkup();
                 break;
@@ -287,9 +291,7 @@
 			<input class="Ctrl" type="button" id="deleteBtn" onClick="SubmitCommand(CMD_DELETE)" value="<?=$deleteLocal?>" style="width:85px">
 			<input class="Ctrl" type="button" id="refreshBtn" onClick="SubmitCommand(CMD_REFRESH)" value="<?=$refreshLocal?>" style="width:85px">
             <input class="Ctrl" type="button" id="downloadBtn" onClick="SubmitCommand(CMD_DOWNLOAD)" value="<?=$downloadLocal?>" style="width:85px">
-            <!--
             <input class="Ctrl" type="button" id="uploadBtn" onClick="SubmitCommand(CMD_UPLOAD)" value="<?=$uploadLocal?>" style="width:85px">
-            -->
 			<br><br>
 		</td>
 	</tr>

Added: trunk/widgets/Redline/templates/markupfeaturesource.xml
===================================================================
--- trunk/widgets/Redline/templates/markupfeaturesource.xml	                        (rev 0)
+++ trunk/widgets/Redline/templates/markupfeaturesource.xml	2012-01-04 06:04:13 UTC (rev 2505)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FeatureSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="FeatureSource-1.0.0.xsd">
+  <Provider>OSGeo.SDF</Provider>
+  <Parameter>
+    <Name>File</Name>
+    <Value>%%MG_DATA_FILE_PATH%%%s</Value>
+  </Parameter>
+  <Parameter>
+    <Name>ReadOnly</Name>
+    <Value>FALSE</Value>
+  </Parameter>
+</FeatureSource>
\ No newline at end of file

Added: trunk/widgets/Redline/uploadmarkup.php
===================================================================
--- trunk/widgets/Redline/uploadmarkup.php	                        (rev 0)
+++ trunk/widgets/Redline/uploadmarkup.php	2012-01-04 06:04:13 UTC (rev 2505)
@@ -0,0 +1,116 @@
+<?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';
+
+	$args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;
+
+	$errorMsg = null;
+	$errorDetail = null;
+
+    SetLocalizedFilesPath(GetLocalizationPath());
+    if(isset($_REQUEST['LOCALE'])) {
+        $locale = $_REQUEST['LOCALE'];
+    } else {
+        $locale = GetDefaultLocale();
+    }
+
+	try
+	{
+        $uploadTitleLocal = GetLocalizedString('REDLINEUPLOAD', $locale );
+        $uploadFileLocal = GetLocalizedString('REDLINEDATAFILE', $locale );
+        $uploadNoteLocal = GetLocalizedString('REDLINEUPLOADNOTE', $locale );
+        $uploadLocal = GetLocalizedString('REDLINEUPLOADTEXT', $locale );
+        $uploadFileRequiredLocal = GetLocalizedString('REDLINEUPLOADREQUIRED', $locale);
+        $closeLocal = GetLocalizedString('REDLINEUPLOADCLOSE', $locale );
+	}
+	catch (MgException $e)
+	{
+		$errorMsg = $e->GetMessage();
+		$errorDetail = $e->GetDetails();
+	}
+?>
+<html>
+<head>
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+	<title><?=$uploadTitleLocal?></title>
+    <link rel="stylesheet" href="Redline.css" type="text/css">
+    <script language="javascript" src="../../layers/MapGuide/MapGuideViewerApi.js"></script>
+    <script language="javascript" src="../../common/browserdetect.js"></script>
+	<script language="javascript">
+        var session = '<?= $args['SESSION'] ?>';
+        var mapName = '<?= $args['MAPNAME'] ?>';
+        
+        function CheckFileName()
+        {
+            if (document.getElementById("uploadFile").value.length > 0)
+                return true;
+                
+            alert("<?= $uploadFileRequiredLocal ?>");
+            return false;
+        }
+        
+        function CloseUpload()
+		{
+			var uploadForm = document.getElementById("uploadForm");
+            document.getElementById("cmdType").value = "";
+			uploadForm.action = "markupmain.php";
+			
+			uploadForm.submit();
+		}
+	</script>
+</head>
+
+<body marginwidth=5 marginheight=5 leftmargin=5 topmargin=5 bottommargin=5 rightmargin=5>
+
+<?php if ($errorMsg == null) { ?>
+
+<form action="markupmain.php" method="post" enctype="multipart/form-data" id="uploadForm" target="_self">
+<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
+<table class="RegText" border="0" cellspacing="0" width="100%">
+	<tr>
+		<td colspan="2" class="Title"><?= $uploadTitleLocal ?><hr></td>
+	</tr>
+	<tr>
+		<td colspan="2" class="SubTitle"><?= $uploadFileLocal ?></td>
+	</tr>
+	<tr>
+		<td colspan="2">
+			<input class="Ctrl" id="uploadFile" name="UPLOADFILE" type="file" style="width:100%"><br></td>
+		</td>
+	</tr>
+	<tr><td colspan="2" height="2px"></td></tr>
+	<tr>
+		<td colspan="2">
+			<input class="Ctrl" name="" type="submit" onClick="return CheckFileName()" value="<?=$uploadLocal?>" style="width:85px">
+			<input class="Ctrl" name="" type="button" onClick="CloseUpload()" value="<?=$closeLocal?>" style="width:85px">
+            <input type="hidden" name="MARKUPCOMMAND" id="cmdType" value="<?= MarkupCommand::Upload ?>" />
+            <input type="hidden" name="MAPNAME" id="MAPNAME" value="<?= $args["MAPNAME"] ?>" />
+            <input type="hidden" name="SESSION" id="SESSION" value="<?= $args["SESSION"] ?>" />
+		</td>
+	</tr>
+    <tr><td colspan="2" height="2px"></td></tr>
+    <tr><td colspan="2"><strong><?= $uploadNoteLocal ?></strong></td></tr>
+</table>
+</form>
+
+<?php } else { ?>
+
+<table class="RegText" border="0" cellspacing="0" width="100%%">
+	<tr><td class="Title">Error<hr></td></tr>
+	<tr><td><?= $errorMsg ?></td></tr>
+	<tr><td><?= $errorDetail ?></td></tr>
+</table>
+
+<?php } ?>
+
+</body>
+
+</html>



More information about the fusion-commits mailing list