[mapguide-users] Get coordinates fusion templates
RenoSun
renolionheart at gmail.com
Thu Jan 4 11:40:09 PST 2018
Here is the custom print (snipping tool) that we are using with Fusion:
1. The example here is using ASP .NET C# with MapGuide API
(http://mapguideAPIEnabledSite/PrintSelect.aspx)
2. Custom Invoke URL widget
PrintSelect.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PrintSelect.aspx.cs"
Debug="true" Inherits="PrintLayout" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Print</title>
</head>
<body>
<form id="form1" runat="server">
<input type="button" name="" value="Select Print Area" class="Ctrl"
id="btnRectangle" style="width:100%" onclick="OnDigitizeRectangle()"/>
<br />
<asp:Button ID="btnPrintLetter" runat="server" Text="Generate Image
(8½ x 11)" Width="100%" Enabled="false" OnClick="btnPrintLetter_Click" />
<asp:Button ID="btnPrint11x17" runat="server" Text="Generate Image
(11 x 17)" Width="100%" Enabled="false" OnClick="btnPrint11x17_Click" />
<hr />
<asp:Label ID="lblPrintSettings" runat="server" Font-Names="Calibri,
Arial" Text="The following image will be optimised to best fill
the selected paper size in either landscape or portrait mode,
depending on the dimensions of the selection. Do not forget to set
printer settings accordingly before printing" style="text-align:
justify;"></asp:Label>
<asp:HiddenField ID="hidX1" runat="server" />
<asp:HiddenField ID="hidX2" runat="server" />
<asp:HiddenField ID="hidY1" runat="server" />
<asp:HiddenField ID="hidY2" runat="server" />
</form>
</body>
</html>
PrintSelect.aspx.cs:
/* NOTES
*
* Printable area is adapted for IE whose standard margins are 3/4" each.
Firefox standard margins are 1/2" each.
*
* New paper sizes can be added by adding a button to PrintSelect.aspx,
linking the event handler and calling
* the PrintMap subroutine with the number of pixels for each dimension as
the passed values, as per the below formula.
*
* The dpi of generated images is always 96. A larger dpi specified in the
url which generates the .png map image will
* result in a more zoomed-in map being produced and will skew calculations
involving scale, as scale will not be the
* only variable in determining the zoom level of the map.
*
* EQUATIONS AND FORMULAE
*
* Native Resolution = 96dpi (1 dpi = 1 image pixel. Higher dpi means a
larger image of the same quality.)
*
* magicNumber: Is a ratio which uses the map scale to link a selected
distance to the number of pixels
* which represent it in a generated image. Given that images are always
generated at the same dpi (96),
* this number never changes
*
*
* 1 pixel = n x 1/scale
*
* (distance in METRES)/((distance on page in PIXELS) * n) = 1/scale -
Shorthand version: m/(p*n) = scale^-1
*
* Printable pixels on a page dimension: ((length in inches) - 1.5) * 96
*/
using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class PrintLayout : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPrintLetter_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "Print Map",
String.Format("", ImageURL(672, 912)));
}
protected void btnPrint11x17_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "Print Map",
String.Format("", ImageURL(912, 1488)));
}
protected string ImageURL(double pageWidth, double pageHeight)
{
string sessionID =
Server.UrlDecode(Request.QueryString.Get("SESSION"));
string mapName =
Server.UrlDecode(Request.QueryString.Get("MAPNAME"));
string url;
double widthPixels, heightPixels, widthMetres, heightMetres, scale,
scaleSelection, drawingHeightCm,
scaleMetric, centreX = 0, centreY = 0;
double x1 = double.Parse(hidX1.Value), x2 =
double.Parse(hidX2.Value);
double y1 = double.Parse(hidY1.Value), y2 =
double.Parse(hidY2.Value), magicNumber = (2.642e-4);
//dpi = 96
//Determine the width and height of the selection in metres
widthMetres = Math.Abs(x2 - x1);
heightMetres = Math.Abs(y2 - y1);
scaleSelection = Math.Abs(widthMetres / heightMetres);
//Determine the selection centrepoint in metres
if ((x1 > x2) && (y1 > y2))
{
centreX = x1 - (widthMetres / 2);
centreY = y1 - (heightMetres / 2);
}
else if ((x1 < x2) && (y1 > y2))
{
centreX = x1 + (widthMetres / 2);
centreY = y1 - (heightMetres / 2);
}
else if ((x1 > x2) && (y1 < y2))
{
centreX = x1 - (widthMetres / 2);
centreY = y1 + (heightMetres / 2);
}
else if ((x1 < x2) && (y1 < y2))
{
centreX = x1 + (widthMetres / 2);
centreY = y1 + (heightMetres / 2);
}
// Determine the orientation of the selection and how to properly
scale it
if (scaleSelection <= (pageWidth / pageHeight))
{
//Portrait and proportionally longer and narrower than page or
same dimensions - Match selection height to page height
heightPixels = pageHeight;
widthPixels = pageHeight * widthMetres / heightMetres;
}
else if (scaleSelection > (pageWidth / pageHeight) && scaleSelection
< 1)
{
//Portrait but proportionally squarer than page - Match
selection width to page width
widthPixels = pageWidth;
heightPixels = pageWidth * heightMetres / widthMetres;
}
else if (scaleSelection == 1)
{
//Square
heightPixels = widthPixels = pageWidth;
}
else if (scaleSelection > 1 && scaleSelection < (pageHeight /
pageWidth))
{
//Landscape but proportionally squarer than page - match
selection height to page width and scale
heightPixels = pageWidth;
widthPixels = heightPixels * widthMetres / heightMetres;
}
else if (scaleSelection >= (pageHeight / pageWidth))
{
//Landscape but proportionally wider and shorter than page or
same dimensions - Match selection width to page height and scale
widthPixels = pageHeight;
heightPixels = widthPixels * heightMetres / widthMetres;
}
else
{
//Error - Should never occur
return "";
}
scale = heightMetres / (heightPixels * magicNumber);
//Determine the drawing scale to put in the web page title
drawingHeightCm = heightPixels / 96 * 2.54;
scaleMetric = Math.Round(heightMetres / drawingHeightCm, 2);
url =
"/mapguideAPIEnabledSite/PrintMap.aspx?OPERATION=GETMAPIMAGE&VERSION=1.0.0&FORMAT=PNG&LOCALE=en&MAPNAME="
+
mapName + "&SESSION=" + sessionID + "&SETDISPLAYWIDTH=" +
widthPixels + "&SETDISPLAYHEIGHT=" + heightPixels +
"&SETDISPLAYDPI=96&SETVIEWSCALE=" + scale + "&SETVIEWCENTERX=" +
centreX + "&SETVIEWCENTERY=" + centreY +
"&CLIENTAGENT=Fusion%20Viewer&SCALEMETRIC=" + scaleMetric;
return url;
}
}
PrintMap.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PrintMap.aspx.cs"
Inherits="PrintMap" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="imgMap" runat="server" />
</div>
</form>
</body>
</html>
PrintMap.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class PrintMap : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string src, mapName, sessionID, widthPixels, heightPixels, scale,
centreX, centreY, scaleMetric, scaleImperial;
mapName = Request.QueryString["MAPNAME"];
sessionID = Request.QueryString["SESSION"];
widthPixels = Request.QueryString["SETDISPLAYWIDTH"];
heightPixels = Request.QueryString["SETDISPLAYHEIGHT"];
scale = Request.QueryString["SETVIEWSCALE"];
centreX = Request.QueryString["SETVIEWCENTERX"];
centreY = Request.QueryString["SETVIEWCENTERY"];
scaleMetric = Request.QueryString["SCALEMETRIC"];
src =
"/mapguide/mapagent/mapagent.fcgi?OPERATION=GETMAPIMAGE&VERSION=1.0.0&FORMAT=PNG&LOCALE=en&MAPNAME="
+
mapName + "&SESSION=" + sessionID + "&SETDISPLAYWIDTH=" +
widthPixels + "&SETDISPLAYHEIGHT=" + heightPixels +
"&SETDISPLAYDPI=96&SETVIEWSCALE=" + scale + "&SETVIEWCENTERX=" +
centreX + "&SETVIEWCENTERY=" + centreY +
"&CLIENTAGENT=Fusion%20Viewer";
imgMap.ImageUrl = src;
Page.Title = "GIS Map Print - 1cm ≈ " + scaleMetric + "m";
}
}
Custom Invoke URL widget:
<http://osgeo-org.1560.x6.nabble.com/file/t368332/Custom_Invoke_URL_widget.png>
Hope these codes may help...
--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
More information about the mapguide-users
mailing list