[Geomoose-users] PDF legend print in GM3

flavio rigolon flavio.rigolon at gmail.com
Tue Nov 17 00:21:02 PST 2020


Il giorno lun 16 nov 2020 alle ore 17:12 Christopher Hughes
<chughes at co.lincoln.or.us> ha scritto:
>
> Hi Flavio,

Hi Chris and thanks for the answer!

>
> Within that 'letter-landscape-legend' you referenced, there should be a legend element that specifies where the legend appears (as well
> as a legend title and a box around the legend):
>
>         {
>             type: 'text',
>             x: 7.6, y: .9,
>             text: 'Legend',
>         },
>         {
>             type: 'legend',
>             x: 7.61, y: 1.0
>         },
>         {
>             type: 'rect',
>             x: 7.6, y: .75,
>             width: 2.4,
>             height: 7,
>             strokeWidth: .01,
>          }
>
> You also need to make sure that you're telling it to use custom layouts in the print preview variable (if you haven't already). You can
> try making minor adjustments other than the legend to make sure your custom layout is being used. I've also found it's easier to copy
> the entire example and implement that before making my customizations.
>
>  var print_preview = app.add(gm3.components.PrintModal, 'print-preview', {
>    layouts: custom_layouts
>  });
>

Yes, I did it. I copied the entire example you mentioned (that I've
found on the page) and pasted it in the app.js. So I added it to the
var print_preview as you said. I can choose my new layout from the
drop down menu I named "A4-verticale" (so it should be correctly
loaded) but the generated PDF doesn't contain the legend: only the
title, map, scale bar, title legend appear, and a rectangle for legend
frame, but the legend is not there.
I use millimeters (mm) as units so I thought the problem was there
(perhaps my error on positioning the objects) but the same behaviour I
encountered in my local demo site with demo data (after modifying the
app.js for the new layout like above) in which I didn't modify any
units.

This is my settings in app.js:

 {
   label: 'A4-verticale',
   orientation: 'portrait',
   page: 'a4',
   units: 'mm',
   elements: [
       {
           type: 'text',
           size: 18, fontStyle: 'bold',
           x: 10, y: 15, text: '{{title}}'
       },
       {
           type: 'map',
           x: 10, y: 18.5,
           width: 160, height: 160
       },
       {
           type: 'rect',
           x: 10, y: 18.5,
           width: 160, height: 160,
           strokeWidth: .1
       },
       {
           type: 'text',
           x: 10, y: 185, text: 'Stampato il {{day}}/{{month}}/{{year}}'
       },
       {
           type: 'text',
           x: 10, y: 190,
           text: 'Legenda',
       },
       {
           type: 'legend',
           x: 10, y: 193
       },
       {
           type: 'rect',
           x: 10, y: 193,
           width: 100, height: 100,
           strokeWidth: .1
       }

   ]
 }

and then:

  var print_preview = app.add(gm3.components.PrintModal, 'print-preview', {
    layouts: custom_layouts
  });


Here is a link to the output:
https://www.dropbox.com/s/nrc15pmplvf5lmv/geomoose_print_test.png?dl=0

Thanks again for any hints
flavio


More information about the Geomoose-users mailing list