Report views
A report is a custom view for one location or layer, often laid out for printing. The default view links to it with the location's params; the report script loads the location again.
Linking to a report
A location entry of type: link with a report object, or a layer's reports object, renders a link to the view:[1]
{
"type": "link",
"report": { "template": "site_report", "label": "Site report" }
}"reports": { "site_report": { "template": "site_report" } }The link opens ${DIR}/view?template=site_report&locale=…&layer=…&id=…&lat=…&lng=…&z=… in a new tab. id is only set for a location. A params object adds more URL params. report.dialog: true opens the view in an iframe dialog instead, except on mobile. type: report is a legacy alias of link; see entry types. layer.reports.drawer: false shows the layer's links without a drawer.[2]
Report script
The script of a location report, after the head of the custom view example. The page has #map, #info and #chart elements.
const { locale: key, layer: layerKey, id } = mapp.hooks.current;
const locale = await mapp.utils.xhr(
`${mapp.host}/api/workspace/locale?locale=${key}&layers=true`);
// Without hooks the report does not rewrite its own URL.
const mapview = await mapp.Mapview({
target: document.getElementById('map'), locale });
await mapview.addLayer(locale.layers.filter(
(layer) => ['base', layerKey].includes(layer.key)));
const location = await mapp.location.get({
layer: mapview.layers[layerKey], id });
// A report is read only.
location.infoj.forEach((entry) => delete entry.edit);
// Entries in this order: two fields and a dataview with target "chart".
document.getElementById('info').append(
mapp.ui.locations.infoj(location, ['name', 'size', 'sales_chart']));
location.flyTo();mapp.ui.locations.infoj(location, order)returns the entries as a grid.orderholds entrykey,fieldorquerystrings, which select and order the entries, or entry objects which are added as they are.[3]- A dataview entry whose
targetis the id of an element in the page is always shown in that element.[4] Charts and tables need the chartjs or tabulator plugin; see dataviews. mapp.ui.layers.legends[layer.style.theme.type](layer)returns a legend element for a map in the report.location.flyTo()fits the map to the location's geometries.- A JSON layer with
format: geojsonandfeaturescan show geometries from the location's entries on the report map. @media printand@pagerules in the view's style block lay out the printed pages.
Pitfalls
layer.reportsandentry.reportpass the map state in the URL, but the report loads the locale and layer itself. It sees only what the user's roles allow.- An entry with
skipEntry: trueis skipped byinfoj. To show a hidden dataview entry, callmapp.ui.Dataview(entry)and itsupdate(). mapp.location.getreturnsundefinedfor a layer withoutinfoj.- Report links are built from
mapp.hooks.current. A mapview withouthooksgives nolat,lngandz. - Interactions belong to the mapview, eg.
mapview.interactions.highlight(). Ui elements are DOM nodes: add them withappend(dropdown), notinnerHTML.