Index: PlotAsPDF.php
===================================================================
--- PlotAsPDF.php (revision 0)
+++ PlotAsPDF.php (revision 0)
@@ -0,0 +1,358 @@
+SetMargins(0, 0, 0);
+ $pdf->SetHeaderMargin(0);
+ $pdf->SetFooterMargin(0);
+ // Prevent adding page automatically
+ $pdf->SetAutoPageBreak(false);
+
+ // Remove default header/footer
+ $pdf->setPrintHeader(false);
+ $pdf->setPrintFooter(false);
+ // Set default font size
+ $pdf->SetFont($font, "", 16, "", true);
+
+ // Add a page
+ $pdf->AddPage();
+
+ // Draw Map first, so if the margin is not enough for the Text, the Text will be displayed about the image
+ $pdf->Image($filelocation, $margin[2], $margin[0], $printSize->width, $printSize->height, "PNG", "", "", false, $printDpi, "", false, false, 1, false, false, false);
+
+ // Draw Title
+ DrawTitle();
+
+ // Draw Extent coordinates
+ DrawExtentCS();
+
+ // Draw Scale
+ DrawScale();
+
+ // Draw declaration
+ DrawDeclaration();
+
+ // Close and output PDF document
+ $pdf->Output($title.'.pdf', 'I');
+?>
+
+width = $width;
+ $this->height = $height;
+ }
+ }
+
+ function ParseLocaleDouble($stringValue)
+ {
+ $lc = localeconv();
+ $result = str_replace(".", $lc["decimal_point"], $stringValue);
+ return doubleval($result);
+ }
+
+ //This function try to get a more elegant number for the scale bar display.
+ //For example, convert 5.3 to 5, 5.5 to 6, 13 to 10, 230 to 200 and 1234 to 1200.
+ //Basically no number will execced 9999 in scale bar display, however we support that situation
+ //the minimum number for the return value is 0
+ function GetRoundNumber($number)
+ {
+ $number = abs($number);
+ $temp = $number = round($number);
+ $len = 0;
+
+ while($temp > 0)
+ {
+ $len++;
+ $temp /= 10;
+ $temp = floor($temp);
+ }
+
+ //10,20,30,40,50,60,70,80,90
+ if( 2 === $len )
+ {
+ $number = $number / 10;
+ $number = round($number);
+ $number = $number * 10;
+ }
+
+ //100,200,300,400,500,600,700,800,900
+ if( $len >= 3 )
+ {
+ $number = $number / 100;
+ $number = round($number);
+ $number = $number * 100;
+ }
+
+ //else, just 1,2,3,4,5,6,7,8,9
+ return $number;
+ }
+
+ function DrawScale()
+ {
+ global $pdf,$margin,$font,$scale;
+
+ $pageHeight = $pdf->getPageHeight();
+ $paddingBottom = 7; $textPadding = 5; $fontSize = 6;
+ $style = array("width" => 0.4, "cap" => "butt", "join" => "miter", "dash" => 0, "color" => array(0, 0, 0));
+
+ $start_x = ParseLocaleDouble($margin[2]);
+ $start_y = $pageHeight - $paddingBottom;
+
+ $lineMark_h = 3;
+ $textMarkPadding = 1.0;
+
+ //
+ $unit = "m";
+ $imageSpan = 20; // the 20 is a suggested scale bar length
+ $realSpan = $scale * 0.02; // $imageSpan / 1000
+
+ if($realSpan >= 1000)
+ {
+ $unit = "km";
+ $realSpan /= 1000;
+ $realSpan = GetRoundNumber($realSpan);
+ $imageSpan = ($realSpan * 1000000)/$scale;
+ }
+ else
+ {
+ $realSpan = GetRoundNumber($realSpan);
+ $imageSpan = ($realSpan * 1000) / $scale;
+ }
+
+ $end_x = $start_x + $imageSpan;
+ $end_y = $start_y;
+ $meterTextMark = $realSpan." ".$unit;
+
+ $pdf->SetFont($font, "", $fontSize, "", true);
+ $pdf->Line($start_x, $start_y, $end_x, $end_y, $style);
+ $pdf->Line($start_x, $start_y, $start_x, $start_y - $lineMark_h, $style);
+ $pdf->Line($end_x, $end_y, $end_x, $end_y - $lineMark_h, $style);
+ $fontSize = 7; $textHeight = 4;
+ $pdf->SetFont($font, "", $fontSize, "", true);
+ $pdf->Text($start_x + $textMarkPadding, $start_y - $textHeight, $meterTextMark);
+
+ $textStart_x = $end_x;
+ //
+
+ //
+ $unit ="ft"; $aFeetPerMeter = 3.2808; $aFeetPerMile = 5280; $aMeterPerFeet = 0.3048;
+ $imageSpan = 20; // the 20 is a suggested scale bar length, in "mm"
+ $realSpan = ( ($scale * $imageSpan) / 1000 ) * $aFeetPerMeter;
+
+ if($realSpan > $aFeetPerMile)
+ {
+ $unit = "mi";
+ $realSpan /= $aFeetPerMile;
+ $realSpan = GetRoundNumber($realSpan);
+ $imageSpan = ( $realSpan * $aFeetPerMile * $aMeterPerFeet * 1000 ) / $scale;
+ }
+ else
+ {
+ $realSpan = GetRoundNumber($realSpan);
+ $imageSpan = ( $realSpan * $aMeterPerFeet * 1000 ) / $scale;
+ }
+
+ $end_x = $start_x + $imageSpan;
+ $end_y = $start_y;
+
+ $feetTextMark = $realSpan.' '.$unit;
+
+ $pdf->Line($start_x, $start_y, $end_x, $end_y, $style);
+ $pdf->Line($start_x, $start_y, $start_x, $start_y + $lineMark_h, $style);
+ $pdf->Line($end_x, $end_y, $end_x, $end_y + $lineMark_h, $style);
+
+ $pdf->SetFont($font, "", $fontSize, "", true);
+ $pdf->Text($start_x + $textMarkPadding, $start_y + 1, $feetTextMark);
+ //
+
+ //determine where to begin to print the absolute scale and date info
+ if($end_x > $textStart_x)
+ {
+ $textStart_x = $end_x;
+ }
+
+ $textStart_x += $textPadding;
+
+ //write the scale
+ $fontSize = 8;
+ $pdf->SetFont($font, "", $fontSize, "", true);
+ $scaleText = "Scale 1:".$scale;
+ $pdf->Text($textStart_x, $end_y + 0.2, $scaleText);
+ //write the date
+ $date = date("M/d/Y");
+ $pdf->Text($textStart_x + 0.3, $end_y - 3.8, $date);
+ }
+
+ function DrawDeclaration()
+ {
+ global $pdf, $font, $margin, $printSize;
+
+ $declaration= $_POST["legalNotice"];
+ //$declaration_w = $pdf->GetStringWidth($declaration,$font,9);
+ $pdf->SetFont($font, "", 9, "", true);
+
+ $bottomPadding = 2.5;
+ $w = 100;
+ $h = 5;
+ $border = 0; //no border
+ $align = "L";//align left
+ $x = ParseLocaleDouble($margin[2]) + $printSize->width - $w;
+ $cellTotalHeight = $pdf->getStringHeight($w,$declaration);
+ $y = $pdf->getPageHeight() - $cellTotalHeight - $bottomPadding;
+
+ $pdf->MultiCell($w, $h, $declaration, $border, $align, false, 0, $x , $y , true);
+ }
+
+ function DrawExtentCS()
+ {
+ global $pdf, $font, $margin, $printSize;
+
+ if( $_POST["normalizedBox"] && trim($_POST["normalizedBox"]) != "" )
+ {
+ $fontSize = 9; $decimals = 6; $padding = 5; $textHeight = 5;
+
+ $normalizedBox = $_POST["normalizedBox"];
+ $extent_cs = explode(",",$normalizedBox);//0,1 ; 4,5
+ $lefttop_cs = " x:".number_format($extent_cs[0], $decimals).", y:".number_format($extent_cs[1], $decimals)." ";
+ $rightbuttom_cs = " x:".number_format($extent_cs[4], $decimals).", y:".number_format($extent_cs[5], $decimals)." ";
+ $pdf->SetFont($font, "", $fontSize, "", true);
+
+ //cell width
+ $lt_cellwidth = $pdf->GetStringWidth($lefttop_cs,$font,$fontSize);
+ $rb_cellwidth = $pdf->GetStringWidth($rightbuttom_cs,$font,$fontSize);
+ //cell location
+ $lefttop = array((ParseLocaleDouble($margin[2]) + $padding),(ParseLocaleDouble($margin[0]) + $padding));
+ $rightbuttom = array((ParseLocaleDouble($margin[2]) + $printSize->width - $rb_cellwidth - $padding),(ParseLocaleDouble($margin[0]) + $printSize->height - $padding - $textHeight));
+
+ $pdf->SetFillColor(255, 255, 255);
+
+ $pdf->SetXY($lefttop[0], $lefttop[1], false);
+ $pdf->Cell($lt_cellwidth, 0, $lefttop_cs, 1, 0, '', true, '', 0, false, 'T', 'M');
+
+ $pdf->SetXY($rightbuttom[0], $rightbuttom[1], false);
+ $pdf->Cell($rb_cellwidth, 0, $rightbuttom_cs, 1, 0, '', true, '', 0, false, 'T', 'M');
+ }
+ }
+
+ function DrawTitle()
+ {
+ global $pdf, $margin, $title, $subTitle,$font;
+
+ $html = '
'.$title.'
'.$subTitle.'
';
+
+ //print title left position
+ $titleWidth = $pdf->GetStringWidth($title, $font, "B", 18, false);
+ $x = ($pdf->getPageWidth() - $titleWidth) / 2;
+ if($x < 0.0)
+ {
+ $x = 0;
+ }
+
+ //print title top position
+ $y = 5;
+ if( $margin[0] > 0.0 )
+ {
+ $y = $margin[0] / 4;
+ }
+
+ // Print text using writeHTMLCell()
+ $pdf->writeHTMLCell(0, 0, $x, $y, $html, 0, 1, false, true, "C", true);
+ }
+?>
\ No newline at end of file
Index: PreviewDialog.js
===================================================================
--- PreviewDialog.js (revision 2531)
+++ PreviewDialog.js (working copy)
@@ -1,440 +0,0 @@
-/**
- * Copyright (C) 2010 Autodesk, Inc. All rights reserved.
- */
-
-var PreviewDialog = function(options)
-{
- this.initialize(options);
-};
-
-PreviewDialog.prototype =
-{
- jxDialog : null,
- previewFrame : null,
- innerDoc : null,
- indicator : null,
- previewPicture : null,
- printPicture : null,
- topLeftXYLabel : null,
- bottomRightXYLabel : null,
- previewContainer : null,
- pictureContainer : null,
- printButton : null,
- cancelButton : null,
- loadingErrorMessage : null,
- printStyle: null,
- previewStyle: null,
- // The offset from the border of the paper, in px
- csLabelOffset : 5,
- // The print margin, in inches
- printMargin: 0,
- mapInfo : {sessionID: "", name: ""},
- captureInfo : {topLeftCs : {x : 0, y : 0}, bottomRightCs : {x : 0, y : 0}, paperSize:{w : 0, h : 0}, scaleDenominator : 0, rotation : 0, params1 : "", params2 : ""},
- params : null,
-
- // The callback will be called right after the JxDialog content has been loaded.
- // The callback accepts 1 parameter: windowName (string)
- // Here it is used to submit the quick plot form to the preview frame.
- contentLoadedCallback : null,
-
- initialize : function(options)
- {
- this.mapInfo = options.mapInfo;
- this.captureInfo = options.captureInfo;
- this.params = options.params;
-
- this.jxDialog = new Jx.Dialog(
- {
- modal: true,
- width:400,
- height: 400,
- content: '' +
- ' ' +
- ' ' +
- ' ' +
- ' | ' +
- '
' +
- '
'
- });
-
- this.jxDialog.addEvent("open", this.jxDialogOpened.bind(this, true));
- this.jxDialog.addEvent("contentLoaded", this.jxDialogContentLoaded.bind(this));
- // Listen to the fade complete event to close the dialog
- var o = this.jxDialog.domObj.get("tween").addEvent("complete", this.closeJxDialog.bind(this));
- },
-
- open : function(contentLoadedCallback)
- {
- this.contentLoadedCallback = contentLoadedCallback;
- this.jxDialog.loadContent(this.jxDialog.content);
- this.jxDialog.open();
- },
-
- print : function()
- {
- //
- this.previewFrame.contentWindow.doPrint();
- },
-
- cancel : function()
- {
- this.indicator.style.display = "inline";
- this.indicator.style.visibility = "visible";
- this.indicator.setOpacity(1);
-
- this.loadingErrorMessage.fade(0);
- this.loadingErrorMessage.style.display = "none";
- // Hide the picture but don't set the 'display' style property to avoid messing the print layout up
- this.printPicture.style.height = "0px";
-
- if (this.topLeftXYLabel && this.bottomRightXYLabel)
- {
- this.topLeftXYLabel.setOpacity(0);
- this.bottomRightXYLabel.setOpacity(0);
- this.printLabel.setOpacity(0);
- // Remove the labels
- this.topLeftXYLabel.parentNode.removeChild(this.topLeftXYLabel);
- this.topLeftXYLabel = null;
- this.bottomRightXYLabel.parentNode.removeChild(this.bottomRightXYLabel);
- this.bottomRightXYLabel = null;
- this.printLabel.parentNode.removeChild(this.printLabel);
- this.printLabel = null;
- }
-
- this.isClosing = true;
- this.jxDialog.domObj.fade(0);
- },
-
- jxDialogContentLoaded : function()
- {
- // Set the window name for the preview frame
- this.previewFrame = $("PreviewFrame");
- this.previewFrame.contentWindow.name = "QuickPlotPreviewFrame";
-
- // Inform the listener that the content is ready, then the Quick Plot panel can submit its data to the preview frame
- if (this.contentLoadedCallback)
- {
- this.contentLoadedCallback(this.previewFrame.contentWindow.name);
- }
- },
-
- jxDialogOpened : function(setFrameUrl)
- {
- if (this.previewInnerIsLoaded)
- {
- // Resize the preview frame according to the monitor resolution
- this.innerDoc = this.previewFrame.contentWindow.document;
-
- // This is a workaround for JxLib3.0, which disable the getDimensions for Body.
- //var box = $(document.body).getDimensions();
- var box = null;
- if($("AppContainer") != null)
- {
- box =$("AppContainer").getDimensions();
- }
- else
- {
- box =$("thePage").getDimensions();
- }
-
- // Width of preview dialog = screen width * factor
- var factor = 0.5;
- this.previewContainer = $(this.innerDoc.getElementById("PreviewContainer"));
- this.previewContainer.style.width = box.width * factor + "px";
- this.resizePictureContainer();
-
- // Verify if the priview container "overflows" the visible screen area
- var containerBox = this.previewContainer.getContentBoxSize();
- if (containerBox.height > box.height)
- {
- var overhead = $(this.innerDoc.getElementById("legalNotice")).getMarginBoxSize().height + $(this.innerDoc.getElementById("AnnotationContainer")).getMarginBoxSize().height + 4 * this.previewContainer.cellSpacing;
- this.previewContainer.style.width = containerBox.width * box.height / containerBox.height - overhead + "px";
- this.resizePictureContainer();
- }
-
- // Get the styles for the print picture
- var rules = this.innerDoc.styleSheets[1].cssRules || this.innerDoc.styleSheets[1].rules;
- this.previewStyle = rules[0];
- rules = this.innerDoc.styleSheets[2].cssRules || this.innerDoc.styleSheets[2].rules;
- this.printStyle = rules[0];
-
- // Reset the background
- this.indicator.style.background = "url(progress_indicator.gif) no-repeat cneter center";
-
- this.loadingErrorMessage = $(this.innerDoc.getElementById("PictureLoadingErrorMessage"));
- this.loadingErrorMessage.setOpacity(0);
-
- // Set the picture url
- var src = "GeneratePicture.php?session_id=" + this.mapInfo.sessionID +
- "&map_name=" + this.mapInfo.name +
- "&print_dpi=" + this.params.printDpi +
- "&paper_size=" + this.captureInfo.paperSize.w + "," + this.captureInfo.paperSize.h +
- "&box=" + this.captureInfo.params1 +
- "&normalized_box=" + this.captureInfo.params2 +
- "&scale_denominator=" + this.captureInfo.scaleDenominator +
- "&rotation=" + this.captureInfo.rotation +
- "×tamp=" + (new Date()).getTime();
-
- this.printPicture = $(this.innerDoc.getElementById("PrintPicture"));
-
- // Listen to print picture onload vent
- this.printPicture.addEvent("load", this.printPictureLoaded.bind(this));
- this.printPicture.addEvent("error", this.printPictureLoadError.bind(this));
- this.printPicture.src = src;
-
- var innerBox = this.previewContainer.getMarginBoxSize();
- // Resize the frame according to the inner container's
- this.previewFrame.style.width = innerBox.width + "px";
- this.previewFrame.style.height = innerBox.height + "px";
-
- // Hide the title bar
- this.jxDialog.title.style.display = "none";
- // Hide the chrome
- this.jxDialog.chrome.style.display = "none";
-
- // Disable the print button until the image is ready
- this.printButton = this.innerDoc.getElementById("PrintButton");
- this.cancelButton = this.innerDoc.getElementById("CancelButton");
- this.printButton.disabled = true;
- this.cancelButton.disabled = true;
-
- var delta = {x: 22, y: 43};
- var container = $("PreviewContainer");
- var size = container.getMarginBoxSize();
- this.jxDialog.resize(size.width + delta.x, size.height + delta.y, true);
-
- this.jxDialog.domObj.fade(1);
- this.resizeIsPending = false;
-
- this.previewInnerIsLoaded = false;
- }
- else
- {
- this.jxDialog.domObj.setOpacity(0);
- this.resizeIsPending = true;
- }
- },
-
- resizePictureContainer: function()
- {
- this.innerDoc = this.previewFrame.contentWindow.document;
-
- this.indicator = $(this.innerDoc.getElementById("ProgressIndicator"));
- // Reset the size of the indicator first
- this.indicator.style.width = "";
- this.indicator.style.height = "";
- // Reset the size of the picture container
- this.pictureContainer = $(this.innerDoc.getElementById("PictureContainer"));
- this.pictureContainer.style.width = "";
- this.pictureContainer.style.height = "";
-
- // Resize
- var pcBox = this.pictureContainer.getContentBoxSize();
- var ratio = this.captureInfo.paperSize.w / this.captureInfo.paperSize.h;
-
- this.indicator.style.width = pcBox.width + "px";
- this.indicator.style.height = pcBox.width / ratio + "px";
-
- // Set an explicit size to the container
- this.pictureContainer.style.width = this.indicator.style.width;
- this.pictureContainer.style.height = this.indicator.style.height;
- },
-
- previewInnerLoaded: function()
- {
- //HACK: There is some state within these labels that gets invalidated in subsequent
- //previews (ie. You click "Generate" on the Quick Plot panel multiple times without cancelling out the dialog).
- //So detect this invalid state and remove these labels, forcing a rebuild
- if (this.topLeftXYLabel)
- {
- var tlDoc = this.topLeftXYLabel.getDocument();
- if (tlDoc.defaultView == null)
- {
- this.topLeftXYLabel.parentNode.removeChild(this.topLeftXYLabel);
- this.topLeftXYLabel = null;
- }
- }
-
- if (this.bottomRightXYLabel)
- {
- var brDoc = this.bottomRightXYLabel.getDocument();
- if (brDoc.defaultView == null)
- {
- this.bottomRightXYLabel.parentNode.removeChild(this.bottomRightXYLabel);
- this.bottomRightXYLabel = null;
- }
- }
-
- if (this.printLabel)
- {
- var prDoc = this.printLabel.getDocument();
- if (prDoc.defaultView == null)
- {
- this.printLabel.parentNode.removeChild(this.printLabel);
- this.printLabel = null;
- }
- }
-
- this.previewInnerIsLoaded = true;
- if (this.resizeIsPending)
- {
- this.jxDialogOpened(false);
- }
- },
-
- closeJxDialog : function()
- {
- if (this.isClosing)
- {
- this.jxDialog.close();
- this.isClosing = false;
- }
- },
-
- printPictureLoaded : function()
- {
- var size = {width: parseInt(this.indicator.style.width), height: parseInt(this.indicator.style.height)};
-
- this.indicator.fade(0);
- this.indicator.style.display = "none";
-
- // Set the preview size
- this.printPicture.setOpacity(0);
- // Clear the inline style
- this.printPicture.style.width = "";
- this.previewStyle.style.width = size.width + "px";
- this.previewStyle.style.height = size.height + "px";
- this.printPicture.fade(1);
-
- // Set the print size
- // NOTE: It works only with a 96 dpi device dpi
- var deviceDpi = 96;
- var idealSize = {width:(this.captureInfo.paperSize.w / 25.4 - 2 * this.printMargin) * deviceDpi, height:(this.captureInfo.paperSize.h / 25.4 - 2 * this.printMargin) * deviceDpi};
- // Get the size of the print frame
- var docSize = $(this.innerDoc.body).getContentBoxSize();
- var realHeight = idealSize.height - (docSize.height - size.height);
- var realWidth = realHeight * this.captureInfo.paperSize.w / this.captureInfo.paperSize.h;
- if (realWidth > idealSize.width)
- {
- realWidth = idealSize.width;
- realHeight = realWidth / (this.captureInfo.paperSize.w / this.captureInfo.paperSize.h);
- }
-
- this.printStyle.style.width = realWidth + "px";
- this.printStyle.style.height = realHeight + "px";
-
- var showLabels = (this.params.showCoordinateLabels == true);
- if (showLabels)
- {
- // Create the coordinates labels
- if (!this.topLeftXYLabel)
- {
- this.topLeftXYLabel = this.createCoordinateLabel(this.pictureContainer, this.captureInfo.topLeftCs.x, this.captureInfo.topLeftCs.y, "TopLeftXYLabel");
- this.topLeftXYLabel.setOpacity(0);
- }
-
- if (!this.bottomRightXYLabel)
- {
- this.bottomRightXYLabel = this.createCoordinateLabel(this.pictureContainer, this.captureInfo.bottomRightCs.x, this.captureInfo.bottomRightCs.y, "BottomRightXYLabel");
- this.bottomRightXYLabel.setOpacity(0);
- }
- }
- if (!this.printLabel)
- {
- this.printLabel = this.createCoordinateLabel(this.pictureContainer, this.captureInfo.bottomRightCs.x, this.captureInfo.bottomRightCs.y, "PrintLabel");
- }
-
- // Set the correct positions for the labels
- var pos = this.getContentPosition(this.pictureContainer);
- var picDim = this.pictureContainer.getContentBoxSize();
-
- var labelDim = null;
- if (showLabels) {
- this.topLeftXYLabel.style.left = pos.left + this.csLabelOffset + "px";
- this.topLeftXYLabel.style.top = pos.top + this.csLabelOffset + "px";
- labelDim = this.bottomRightXYLabel.getMarginBoxSize();
-
- this.bottomRightXYLabel.className = "ScreenOnly";
- this.bottomRightXYLabel.style.left = pos.left + picDim.width - this.csLabelOffset - labelDim.width + "px";
- this.bottomRightXYLabel.style.top = pos.top + picDim.height - this.csLabelOffset - labelDim.height + "px";
-
- this.topLeftXYLabel.fade(1);
- this.bottomRightXYLabel.fade(1);
- }
- labelDim = this.printLabel.getMarginBoxSize();
- this.printLabel.className = "PrintOnly";
- this.printLabel.style.left = pos.left + realWidth - this.csLabelOffset - labelDim.width + "px";
- this.printLabel.style.top = pos.top + realHeight - this.csLabelOffset - labelDim.height + "px";
-
- // Enable the print button
- this.printButton.disabled = false;
- this.cancelButton.disabled = false;
- },
-
- printPictureLoadError : function()
- {
- this.indicator.fade(0);
- this.indicator.style.display = "none";
- this.loadingErrorMessage.style.display = "inline";
- this.loadingErrorMessage.setOpacity(0);
- this.loadingErrorMessage.fade(1);
- this.cancelButton.disabled = false;
- },
-
- createCoordinateLabel: function(container, cX, cY, id)
- {
- cX = cX + "";
- cY = cY + "";
- var digits = 6;
-
- var index = cX.indexOf(".");
- if (index > -1)
- {
- cX = cX.substr(0, index + digits + 1);
- }
-
- index = cY.indexOf(".");
- if (index > -1)
- {
- cY = cY.substr(0, index + digits + 1);
- }
-
- var label = this.innerDoc.createElement("div");
- container.appendChild(label);
- label.id = id;
- label.style.cssText = "border:solid 1px black; padding:1px; background:#F2F2F2; color:black; font-size:8pt; z-index:1000; " +
- "position:absolute; white-space:nowrap";
- label.innerHTML = "X: " + cX + " Y: " + cY;
-
- return $(label);
- },
-
- getContentPosition: function(element)
- {
- var offsetLeft = 0;
- var offsetTop = 0;
- var border = 0;
-
- while (element && element.tagName.toLowerCase() != "body" && element.tagName.toLowerCase() != "html")
- {
- offsetLeft += element.offsetLeft;
- offsetTop += element.offsetTop;
-
- border = parseInt(element.style.borderLeftWidth);
- if (!isNaN(border))
- {
- offsetLeft += border;
- }
-
- border = parseInt(element.style.borderTopWidth);
- if (!isNaN(border))
- {
- offsetTop += border;
- }
-
- element = element.offsetParent;
- }
-
- return {left: offsetLeft, top: offsetTop};
- }
-};
\ No newline at end of file
Index: progress_indicator.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: QuickPlotPanel.js
===================================================================
--- QuickPlotPanel.js (revision 2531)
+++ QuickPlotPanel.js (working copy)
@@ -5,40 +5,55 @@
function panelLoaded()
{
var widget = getParent().Fusion.getWidgetsByType("QuickPlot")[0];
+
+ //set the legal notice from the quick plot widget info
+ var disclaimer = widget.disclaimer;
+ document.getElementById("legalNotice").value = disclaimer;
+
+ //set the paper list from the quick plot widget info
if (widget.paperList.length > 0)
{
- var list = document.getElementById("PaperList");
- list.options.length = 0;
+ var paperList = document.getElementById("PaperList");
+ paperList.options.length = 0;
- for (var i = 0; i < widget.paperList.length; i++) {
+ var i;
+ for (i = 0; i < widget.paperList.length; i++) {
var elOpt = document.createElement("option");
elOpt.text = widget.paperList[i].name;
elOpt.value = widget.paperList[i].size;
try {
- list.add(elOpt, null);
+ paperList.add(elOpt, null);
+ }catch (ex) {
+ paperList.add(elOpt); //IE
}
- catch (ex) {
- list.add(elOpt); //IE
- }
}
}
+
+ //set the scale list from the quick plot widget info
if (widget.scaleList.length > 0)
{
- var list = document.getElementById("ScalingList");
- list.options.length = 0;
+ var scaleList = document.getElementById("ScalingList");
+ scaleList.options.length = 0;
- for (var i = 0; i < widget.scaleList.length; i++) {
- var elOpt = document.createElement("option");
- elOpt.text = widget.scaleList[i].name;
- elOpt.value = widget.scaleList[i].scale;
+ for (i = 0; i < widget.scaleList.length; i++) {
+ var scaleOpt = document.createElement("option");
+ scaleOpt.text = widget.scaleList[i].name;
+ scaleOpt.value = widget.scaleList[i].scale;
try {
- list.add(elOpt, null);
+ scaleList.add(scaleOpt, null);
+ }catch (ex) {
+ scaleList.add(scaleOpt); //IE
}
- catch (ex) {
- list.add(elOpt); //IE
- }
}
}
+
+ //set the margin from the quick plot widget info
+ if(!!widget.margin)
+ {
+ var margin = widget.margin;
+ document.getElementById("margin").value = margin.top + "," + margin.buttom + "," +margin.left + "," + margin.right ;
+ }
+
restoreUI();
}
@@ -50,44 +65,41 @@
if (widget.persistPlotOptions)
{
// Read the last used options
- lastPaperSize = getParent().Cookie.read("QuickPlotLastUsedPaperSize");
- lastScale = getParent().Cookie.read("QuickPlotLastUsedScaling");
- lastDPI = getParent().Cookie.read("QuickPlotLastUsedDPI");
+ var lastPaperSize = getParent().Cookie.read("QuickPlotLastUsedPaperSize");
+ var lastScale = getParent().Cookie.read("QuickPlotLastUsedScaling");
+ var lastDPI = getParent().Cookie.read("QuickPlotLastUsedDPI");
+ var lastOrientation = getParent().Cookie.read("QuickPlotLastUsedOrientation");
- if (lastPaperSize != null)
- {
- document.getElementById("PaperList").value = lastPaperSize;
+
+ if (lastPaperSize != null){
+ document.getElementById("PaperList").value = lastPaperSize;
}
- if (lastScale != null)
- {
+ if (lastScale != null){
document.getElementById("ScalingList").value = lastScale;
}
- if (lastDPI != null)
- {
- document.getElementById("DPIList").value = lastDPI;
+ if (lastDPI != null){
+ document.getElementById("DPIList").value = lastDPI;
}
+
+ if (lastOrientation != null){
+ document.getElementById("OrientationList").value = lastOrientation;
+ }
}
- if (widget.defaultDpi)
- {
+ if (widget.defaultDpi){
document.getElementById("DPICtrl").style.display = "none";
document.getElementById("DPILabel").style.display = "none";
- }
- else
- {
+ }else{
document.getElementById("DPICtrl").style.display = "block";
document.getElementById("DPILabel").style.display = "block";
}
- if (widget.showSubTitle)
- {
+ if (widget.showSubTitle){
document.getElementById("SubTitleCtrl").style.display = "block";
document.getElementById("SubTitleLabel").style.display = "block";
- }
- else
- {
+ }else{
document.getElementById("SubTitleCtrl").style.display = "none";
document.getElementById("SubTitleLabel").style.display = "none";
}
@@ -95,71 +107,140 @@
function setAdvancedOptionsUI(enabled)
{
- document.getElementById("PaperList").disabled = !enabled;
- document.getElementById("ScalingList").disabled = !enabled;
- document.getElementById("DPIList").disabled = !enabled;
+ document.getElementById("PaperList").disabled = !enabled;
+ document.getElementById("ScalingList").disabled = !enabled;
+ document.getElementById("DPIList").disabled = !enabled;
+ document.getElementById("OrientationList").disabled = !enabled;
var mapCapturer = getParent().Fusion.getWidgetsByType("QuickPlot")[0].mapCapturer;
- if (enabled)
- {
+ if (enabled){
mapCapturer.enable();
drawCaptureBox();
- }
- else
- {
+ }else{
mapCapturer.disable();
}
}
function generatePlot()
{
- var widget = getParent().Fusion.getWidgetsByType("QuickPlot")[0];
- var mapCapturer = widget.mapCapturer;
-
- if (!advancedOptionsOn())
- {
- // Get paper size. Use the last used paper size by default
- mapCapturer.setSize(getPaperSize(), getScale());
-
+ var widget = getParent().Fusion.getWidgetsByType("QuickPlot")[0];
+ if(!!widget){
+ var map = widget.getMapLayer();
+ var mapCapturer = widget.mapCapturer;
}
+
+ //params
+ if(map){
+ var sessionID = map.getSessionID();
+ var mapName = map.getMapName();
+ }
- widget.preview(submitForm, getPrintDpi());
-}
+ if(mapCapturer){
+ var capture = mapCapturer.getCaptureBox();
+ if(capture){
+ var box = capture.params;
+ }
+
+ var rotation = mapCapturer.rotation;
+ var normalizedCapture = mapCapturer.getNormalizedCapture();
-function submitForm(windowName)
-{
- var form = document.getElementById("Form1");
- form.target = windowName;
-
- var widget = getParent().Fusion.getWidgetsByType("QuickPlot")[0];
+ if(!!normalizedCapture){
+ var normalized_box = normalizedCapture.params;//normalized_box
+ }
+ }
+ //get params and assign the value of hidden input
+ var printSize = getPrintSize();
+ getPrintDpi();
+ getScale();
+ getPaperType();
+ getOrientation();
+
+ document.getElementById("sessionId").value = sessionID;
+ document.getElementById("mapName").value = mapName;
+ document.getElementById("normalizedBox").value = normalized_box;
+ document.getElementById("printSize").value = printSize.w + "," + printSize.h;
+ document.getElementById("rotation").value = rotation;
+ document.getElementById("box").value = box;
+
if (widget.persistPlotOptions) {
// Save the advanced options to a cookie
var cookieDuration = 365;
getParent().Cookie.write("QuickPlotLastUsedPaperSize", document.getElementById("PaperList").value, {duration:cookieDuration});
getParent().Cookie.write("QuickPlotLastUsedScaling", document.getElementById("ScalingList").value, {duration:cookieDuration});
getParent().Cookie.write("QuickPlotLastUsedDPI", document.getElementById("DPIList").value, {duration:cookieDuration});
+ getParent().Cookie.write("QuickPlotLastUsedOrientation", document.getElementById("OrientationList").value, {duration:cookieDuration});
}
+
+ //update param
+ var form = document.getElementById("Form1");
+ form.target = "_blank";//windowName;
+
+ //use a random print id to avoid the browser cache problem
+ var vNum = Math.random() * 1000;
+ var randomId = "printId=" + vNum;
+
+ var actiontarget;
+ if ( form.action.indexOf("?") != -1)//form.action include "?"
+ {
+ actiontarget = form.action.slice(0,form.action.indexOf("?"));
+ }
+ else
+ {
+ actiontarget = form.action;
+ }
+ form.action = actiontarget + "?" + randomId;
form.submit();
}
-
function advancedOptionsOn()
{
var o = document.getElementById("AdvancedOptionsCheckBox");
- if (o && o.checked)
- {
+ if (o && o.checked){
return true;
}
-
return false;
}
-function getPaperSize()
+function getMargin()
{
+ var widget = getParent().Fusion.getWidgetsByType("QuickPlot")[0];
+ var margin;
+
+ if(!!widget.margin){
+ margin = widget.margin;
+ }else{
+ //the default margin
+ margin = {top: 25.4, buttom: 12.7, left: 12.7, right: 12.7};
+ }
+ return margin;
+}
+
+function getOrientation()
+{
+ document.getElementById("orientation").value = document.getElementById("OrientationList").value;
+ return document.getElementById("OrientationList").value;
+}
+
+function getPaperType()
+{
var value = document.getElementById("PaperList").value.split(",");
- var size = {w: parseFloat(value[0]), h: parseFloat(value[1])};
+ return value[2];
+}
+function getPrintSize()
+{
+ var value = document.getElementById("PaperList").value.split(",");
+ var size;
+ if( getOrientation() === "P" ){
+ size = {w: parseFloat(value[0]), h: parseFloat(value[1])};
+ }else if (getOrientation() === "L"){
+ size = {w: parseFloat(value[1]), h: parseFloat(value[0])};
+ }
+ var margins = getMargin();
+ size.h = size.h - margins.top - margins.buttom;
+ size.w = size.w - margins.left - margins.right;
+
if (!advancedOptionsOn())
{
// Calculate the paper size to make sure it has a same ratio with the viweport
@@ -168,49 +249,31 @@
var viewSize = map.getSize();
var viewRatio = viewSize.w / viewSize.h;
- if (paperRatio > viewRatio)
- {
+ if (paperRatio > viewRatio){
size.w = size.h * viewRatio;
- }
- else
- {
+ }else{
size.h = size.w / viewRatio;
- }
+ }
}
-
+
+ document.getElementById("paperSize").value = document.getElementById("PaperList").value;
return size;
}
function getScale()
{
var scale = 0;
- if (advancedOptionsOn())
- {
+ if (advancedOptionsOn()){
scale = document.getElementById("ScalingList").value;
- }
- else
- {
- var map = getParent().Fusion.getWidgetById("Map");
- /*
- var paperSize = getPaperSize();
- var viewerSize = map.getCurrentExtents().getSize();
- var factor = map.getMetersPerUnit();
-
- if (paperSize.w / paperSize.h > viewerSize.w / viewerSize.h)
- {
- scale = viewerSize.h * factor * 1000 / paperSize.h;
- }
- else
- {
- scale = viewerSize.w * factor * 1000 / paperSize.w;
- }*/
+ }else{
+ var map = getParent().Fusion.getWidgetById("Map");
scale = map.getScale();
}
scale = parseInt(scale);
// Set the value to a hidden field so that it could be sent by POST method
// We cannot rely on the ScalingList.value because we have to handle also the viewport print
- document.getElementById("ScaleDenominator").value = scale;
+ document.getElementById("scaleDenominator").value = scale;
return scale;
}
@@ -218,14 +281,17 @@
function getPrintDpi()
{
var widget = getParent().Fusion.getWidgetsByType("QuickPlot")[0];
- if (widget.defaultDpi)
+ if (widget.defaultDpi){
+ document.getElementById("dpi").value = widget.defaultDpi;
return widget.defaultDpi;
- else
+ }else{
+ document.getElementById("dpi").value = document.getElementById("DPIList").value;
return document.getElementById("DPIList").value;
+ }
}
function drawCaptureBox()
{
var mapCapturer = getParent().Fusion.getWidgetsByType("QuickPlot")[0].mapCapturer;
- mapCapturer.setSize(getPaperSize(), getScale());
+ mapCapturer.setSize(getPrintSize(), getScale());
}
Index: QuickPlotPanel.php
===================================================================
--- QuickPlotPanel.php (revision 2531)
+++ QuickPlotPanel.php (working copy)
@@ -16,13 +16,12 @@
SetLocalizedFilesPath(GetLocalizationPath());
$templ = Localize($templ, $locale, GetClientOS());
- $vpath = GetSurroundVirtualPath();
$jsPath = "";
print sprintf($templ, $popup, $jsPath);
function GetParameters($params)
{
- global $target, $cmdIndex, $clientWidth, $mapName, $sessionId, $popup, $us, $locale, $popup;
+ global $mapName, $sessionId, $popup, $us, $locale, $popup;
$locale = $params['locale'];
$mapName = $params['mapname'];
Index: QuickPlotPanel.templ
===================================================================
--- QuickPlotPanel.templ (revision 2531)
+++ QuickPlotPanel.templ (working copy)
@@ -76,17 +76,17 @@
-