Class MapLayoutReport
- All Implemented Interfaces:
Selectable<Report>
,Comparable<Report>
NOTE: THIS CLASS IS IN ALPHA STATUS AND THE API IS SUBJECT TO CHANGE. USE AT YOUR OWN RISK. This version is being provided as a technology preview. Features may be added or removed as this technology is improved.
LayoutReports may be rendered as PNG images or PDF files. When producing a layout in PNG format only the first page defined in the report will be rendered. The PDF format provides a number of useful navigation features such as a table of contents, selectable layers, bookmarks, and in the case of map layers, embedded and selectable attribute data.
MapLayoutReports are composed of a hierarchical tree of graphics and container objects.
The main branches of the tree are pages. Pages act as containers to
hold report objects such as text boxes and map layers. Some elements
(e.g. MapLayoutReport.Group
, MapLayoutReport.Grid
) are containers themselves, and
can be used to group elements together.
The process to create a Layout Report is to first create the base MapLayoutReport object. Within this object add pages, and within the pages add the desired graphics elements. Use the grouping elements to assist with alignment, spacing and formatting. Once all of the elements have been added the ReportWriter will produce the report upon request.
Pages are added to reports using the page()
or
page(double, double)
command. The first form adds a page
using the default size specified when the report was created.
The second form uses an explicit page size.
Once a page is created, use the methods provided by the MapLayoutReport.Page
object to add graphics and formatting elements. Here is an example
of a simple LayoutReport:
// Create the layout object specifying inches as the layout units r = new MapLayoutReport("sample.pdf", "Sample Layout Report", MapLayoutReport.INCH, 23.39, 33.11, "") // Add a page with specified neatline, margin and insets .page().neatline(1).margin(0.5).inset(0.5) // Add a group so that the set may be selectively displayed or hidden .addGroup("Base Features") // Add the map layer and legend. The layerList is the same // as for the MapReport .addMap(0, 0, 21.39, 31.11, "Sample Features", layerList2, 0).inset(0.1).p() .addLegend(1, 8.3, 5, -1, "Sample Features Legend", -1).background(Color.white).inset(0.4).p().p() // Add a group to hold the ornamentation .addGroup("Map Surrounds") .addScalebar(1, 16, 5, 2, "Scale bar", 0).title("Kilometers").showRatio(true).background(Color.white).inset(0.5).p() .addText(1, 4.6, 8, 4, "Title", "Title goes here").vertical(MapLayoutReport.TOP).background(Color.white).inset(0.2).p() .addNorthArrow(5, 16, 2, 2, "North Arrow", 0).background(Color.white).inset(0.5).p() .addText(0, 30.3, 6, 1.1, "Credits", "<html><center><i>I made this map</i></center></html>") .background(Color.white).horizontal(MapLayoutReport.LEFT).inset(0.2) // Return the report object .r(); // Add the layout report to the report writer reportWriter.addReport(r);
Fluid style
The above example shows the LayoutReport being created using a 'fluid' programming style. This style creates the report and adds the graphics elements all in a single statment. Each of the methods returns an object, and the next method is chained on to that object.
Some methods will create and return a new object, such as the
page()
method. Many of the formatting methods simply
return a reference to the same object as they are operating on
(such as the background() method).
As well there are methods (e.g MapLayoutReport.MapElement.p()
, MapLayoutReport.MapElement.r()
)
that traverse back up the hierarchy of Group and Page container objects.
In the above example most objects are terminated with a p()
method which returns to the parent object. Sometimes there will be
two p()
methods calls in a row, in order to ascend out of
both the object and the group that the object is in.
The basis for the fluid style is that every method operates on the
object provided by the previous methods, and returns an object
reference used by the next method.
The traditional programming style uses more intermediate variables and statements are separated by semicolons. Here below is an example of the non-fluid style for the same report as above. The result is the same, but the syntax is more verbose and explicit. The choice of which style to use is largely a matter of taste and the two styles may be mixed. The traditional style may be required in scripts that perform looping or conditional flow control.
// Create the layout object specifying inches as the layout units r = new MapLayoutReport("sample.pdf", "Sample Layout Report", MapLayoutReport.INCH, 23.39, 33.11, ""); // Add a page with specified neatline, margin and insets p1 = r.page(); p1.neatline(1).margin(0.5).inset(0.5); // Add a group so that the set may be selectively displayed or hidden g1 = p1.addGroup("Base Features"); // Add the map layer and legend. The layerList is the same // as for the MapReport g1.addMap(0, 0, 21.39, 31.11, "Sample Features", layerList2, 0).inset(0.1); g1.addLegend(1, 8.3, 5, -1, "Sample Features Legend", -1).background(Color.white).inset(0.4); // Add a group to hold the ornamentation g2 = p1.addGroup("Map Surrounds"); g2.addScalebar(1, 16, 5, 2, "Scale bar", 0).title("Kilometers").showRatio(true).background(Color.white).inset(0.5); g2.addText(1, 4.6, 8, 4, "Title", "Title goes here").vertical(MapLayoutReport.TOP).background(Color.white).inset(0.2); g2.addNorthArrow(5, 16, 2, 2, "North Arrow", 0).background(Color.white).inset(0.5); g2.addText(0, 30.3, 6, 1.1, "Credits", "<html><center><i>I made this map</i></center></html>") .background(Color.white).horizontal(MapLayoutReport.LEFT).inset(0.2); // Add the layout report to the report writer reportWriter.addReport(r);
Object hierarchy
All of the elements that can be placed within a layout descend from theMapLayoutReport.MapElement
object. The MapElement class contains the
following methods for navigation up the object hierachy:
Method | Purpose |
---|---|
p | Return a reference to the parent container object. Using this reference you may add more elements to the same container. |
top | Return a reference to the topmost container that holds all of the pages in the document. From this object you may add more pages to the document. |
r | Return a reference to the report object. Ultimately this reference must be added to a ReportWriter in order to be useful. |
In addition to navigation methods, map elements also have formatting methods to set appearance and control other PDF features. The following methods are available to all map elements. All of these methods return a reference to the object being operated on, and may be chained together.
Method | Purpose |
---|---|
margin | Set a margin around the element. The background and neatline will be drawn within the margin. |
background | Set the background colour of the element. |
neatline | Draw a neatline around the element. |
inset | Set a margin within the neatline. The element content will render within the inset. |
visible | Specify that the element should initially be set to invisible. The visibility status may be changed interactively in the PDF table of contents. |
hidden | Specify that the element should not have an entry in the PDF table of contents. The element will be displayed in the layout, but will not appear in the TOC. |
bookmark | Specify that the element should be bookmarked in the PDF bookmark list. |
zoom | Specify a zoom factor for the element. This will influence the size of fonts and line thicknesses for some objects. |
Additional methods are available to query the status of each map element.
See the MapLayoutReport.MapElement
documentation for details.
MapLayoutReport.Page
elements inherit from the MapLayoutReport.Group
element. Groups (and Pages)
may contain graphic elements as well as other group containers. The following
methods may be used to add elements to a group. Most of these methods require a
position to place the graphic object, in the form of a starting x/y location of
the top left corner (relative to the container insets), and a width and height
(all specified in page units).
Many also require a label that uniquely identifies the object.
Method | Purpose |
---|---|
addText | Add a text box |
addReportChart | Add a chart from an already defined report |
addReportTable | Add a table from an already defined report |
addNorthArrow | Add a north arrow ornamentation |
addLegend | Add a legend box based on a map layer list |
addMap | Add a map based on a map layer list |
addScalebar | Add a scalebar |
addCircle | Add a circle |
addEllipse | Add an ellipse |
addRectangle | Add a rectangle |
addRoundedRectangle | Add a rounded rectangle |
addLine | Add a line |
addGroup | Add a group container |
addGrid | Add a grid container |
Check the MapLayoutReport.Group
element for a description of these methods and their parameters.
Page units
Page sizes and graphic element positional information (upper left starting positions and sizes) are specified using a measurement system that is selected when the report is created. The following measurement systems may be used:Name | System |
---|---|
MapLayoutReport.INCH | Imperial inches |
MapLayoutReport.CM | Centimetres |
MapLayoutReport.FEET | Imperial feet |
MapLayoutReport.METRE | METRE |
Substitution values
Several special values are available to be used in text boxes. These values will be substituted in to the text when the following symbols are encountered:Symbol | Value |
---|---|
{%_title%} | The report title |
{%_date%} | The current date when the report is rendered |
{%_datetime%} | The current date and time when the report is rendered |
{%_filename%} | The filename for the report |
{%_metadata%} | Scenario metadata |
{%_description%} | The description provided in the ScenarioSet. |
In addition to these symbols, any additional query values used when the report is created are also available. For example the scenario name is available using the "{%scenario%}" symbol.
Here is an example of using the {%_title%} variable to display the report title within the layout:
g2.addText(1, 4.6, 8, 4, "Title", "<html><center><h2>{%_title%}</h2>Reports details</center></html>") .vertical(MapLayoutReport.TOP).background(Color.white).inset(0.2);
Working with groups and grids
You must specify the position of the upper left corner when you add any map element to a page or group (note that a page is a specialized group). The position is specified in the appropriate page units, and is relative to the upper left corner of the insets of the containing group.When you position a group within a page or another group, all of the element position references become relative to that group. If you move the group to a different position, then all of the element positions will remain in the same relative position to the new location of the group.
MapLayoutReport.Grid
elements are a special type of group that partition the space
in the group in to panes. The number of rows and columns in the grid is
specified in the method call, as are the propotional sizes of the rows and
columns. Once the grid is created then panes (or rectangular selections of
panes) may be selected using the MapLayoutReport.Grid.pane(int, int)
methods. These object
return a group object that is positioned over the selected panes of the grid.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The base class for simple graphics shapes such as circles and rectangles.class
The Grid element is a tool that helps to lay out elements in a rectangular grid.class
A group is a containter for map elements.class
The legend element will render the map legend for the given LayerList.class
MapElement is the abstract base class for the components of a MapLayout.class
The Mapper element will render the LayerList as a map.class
A simple north arrowclass
The Page element represent a new page within the report.class
Draw a chart or MapReport objectclass
Draw a report tableclass
The scalebar element will a scalebar for the given mapper.class
A text element can contain any arbitrary HTML code, such as text, lists or images.class
The TopGroup is the main grouping for the report.Nested classes/interfaces inherited from class ca.spatial.reportwriter.Report
Report.GetNodesAt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Constant representing a bottom alignmentstatic int
Constant representing a center alignmentstatic int
Constant representing units of measure in centimetresstatic int
Constant representing units of measure in feetstatic int
Constant representing units of measure in inchesstatic int
Constant representing units of measure in kilometresstatic int
Constant representing a left alignmentstatic int
Constant representing units of measure in metresstatic int
Constant representing units of measure in milesstatic int
Constant representing units of measure in pixelsstatic int
Constant representing a right alignmentstatic int
Constant representing a top alignmentString[]
An array containing the sub-types produced by this report.Fields inherited from class ca.spatial.reportwriter.Report
AREA, LINE, PIE, SIDE_BY_SIDE_BARS, STACKED_BARS
-
Constructor Summary
ConstructorsConstructorDescriptionMapLayoutReport(String filename, String title, int pageunits, double width, double height, String htmlText)
Create the base MapLayoutReport object. -
Method Summary
Modifier and TypeMethodDescriptionca.spatial.reportwriter.Report.DataCache
doReport(String name, PrintStream out, Map<String,Object> param, ca.spatial.reportwriter.Report.DataCache cache)
The method used by the report writer to format the requested report.Return the file name of this reportdouble
Get the default page widthGet the HTML text used to accompany PNG format reportsGet the baseline map element group.getMapper(int index)
Return a reference to a previously defined map.int
Get the page units used in this report, as an integer constantstatic String
getPageUnitsString(int pageunits)
Get the page units string for an integer constantString[]
getTypes()
An accessor function to retrieve the list of report types supported by this report.double
getWidth()
Get the default page widthpage()
Start a new page in the top level group, using the default page sizepage(double width, double height)
Start a new page in the top level group, using the specified page sizevoid
setHtmlText(String htmlText)
Set the HTML text that will accompany PNG format reportsMethods inherited from class ca.spatial.reportwriter.Report
addDefaultParam, chartImg, compareTo, csvLink, doesAnyTypes, doesCSV, doesGIF, doesHTML, doesPNG, doesType, encodeFileURL, encodeURL, endMainContent, escapeRegexChars, footer, formatColumnHeadings, formatColumnHeadings, getAdditionalFiles, getAttributeStore, getBasepart, getBasepart, getDefaultFilename, getDisplayFormat, getExtension, getExtension, getFilename, getFolderpart, getFolderpart, getLength, getNamepart, getNamepart, getPathToRoot, getReportFor, getTitle, header, htmlText, indexLink, interpolateParams, isDhandler, isIndexed, isSelected, parentIndex, patternToRegex, setAttributeStore, setDefaultParams, setDisplayFormat, setIndexed, setSelected, setTitle, toString, uniqueLabels
-
Field Details
-
PIXEL
public static final int PIXELConstant representing units of measure in pixels- See Also:
- Constant Field Values
-
INCH
public static final int INCHConstant representing units of measure in inches- See Also:
- Constant Field Values
-
FEET
public static final int FEETConstant representing units of measure in feet- See Also:
- Constant Field Values
-
MILE
public static final int MILEConstant representing units of measure in miles- See Also:
- Constant Field Values
-
CM
public static final int CMConstant representing units of measure in centimetres- See Also:
- Constant Field Values
-
METRE
public static final int METREConstant representing units of measure in metres- See Also:
- Constant Field Values
-
KM
public static final int KMConstant representing units of measure in kilometres- See Also:
- Constant Field Values
-
LEFT
public static final int LEFTConstant representing a left alignment- See Also:
- Constant Field Values
-
CENTER
public static final int CENTERConstant representing a center alignment- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHTConstant representing a right alignment- See Also:
- Constant Field Values
-
TOP
public static final int TOPConstant representing a top alignment- See Also:
- Constant Field Values
-
BOTTOM
public static final int BOTTOMConstant representing a bottom alignment- See Also:
- Constant Field Values
-
TYPES
An array containing the sub-types produced by this report. The MapLayoutReport may produce a PDF file, in which case the type fields will be null. Otherwise it may produce a PNG image file, in which the types will be "html" and "png".
-
-
Constructor Details
-
MapLayoutReport
public MapLayoutReport(String filename, String title, int pageunits, double width, double height, String htmlText)Create the base MapLayoutReport object. This object is a container for pages, and the pages contain the objects to be drawn.- Parameters:
filename
- the file name in the report writertitle
- the report titlepageunits
- the units to use to reference locations on the page. May be PIXEL, INCH, FEET, MILE, CM, METRE or KM.width
- the default page width for new pagesheight
- the default page height for new pageshtmlText
- optional html data the is included if the output is formatted as png.
-
-
Method Details
-
getFullFilename
Return the file name of this report -
setHtmlText
Set the HTML text that will accompany PNG format reports- Parameters:
htmlText
- the text to display on the PNG report
-
getHtmlText
Get the HTML text used to accompany PNG format reports -
getWidth
public double getWidth()Get the default page width -
getHeight
public double getHeight()Get the default page width -
getPageUnits
public int getPageUnits()Get the page units used in this report, as an integer constant -
getPageUnitsString
Get the page units string for an integer constant- Parameters:
pageunits
- an integer code for a page unit system
-
getMapElement
Get the baseline map element group. This is the group that map elaments can be added to. -
page
Start a new page in the top level group, using the default page size -
page
Start a new page in the top level group, using the specified page size- Parameters:
width
- the default page widthheight
- the default page height
-
getMapper
Return a reference to a previously defined map. If the index number if ge 0, then return the map defined in the sequential order starting at 0. If the index value is lt 0, then return the return the map defined in reverse sequential order. For example, if index = 0 then return the first map. If index is -1 then return the most recently defined map.- Parameters:
index
- the index of the mapper to return
-
doReport
public ca.spatial.reportwriter.Report.DataCache doReport(String name, PrintStream out, Map<String,Object> param, ca.spatial.reportwriter.Report.DataCache cache)Description copied from class:Report
The method used by the report writer to format the requested report. This method is implemented in every custom report. Application programs generally do not need to call this method, but instead use the report writer methods to obtain reports. -
getTypes
Description copied from class:Report
An accessor function to retrieve the list of report types supported by this report. See the documentation for the TYPES variable for the list of sub-types.
-