Search in sources :

Example 6 with MapDef

use of org.geotoolkit.report.graphic.map.MapDef in project geotoolkit by Geomatys.

the class JasperReportServiceTest method testHTML.

@Test
public void testHTML() throws JRException, IOException, DataStoreException {
    final MapLayers context = createContext();
    final URL template = JasperReportServiceTest.class.getResource("/report/MapReport.jrxml");
    final Entry<JasperReport, FeatureType> entry = JasperReportService.prepareTemplate(template);
    final JasperReport report = entry.getKey();
    final FeatureType type = entry.getValue();
    List<Feature> collection = new ArrayList<>();
    Feature feature = type.newInstance();
    CanvasDef cdef = new CanvasDef(new Dimension(1, 1), context.getEnvelope().get());
    cdef.setBackground(Color.RED);
    feature.setPropertyValue("map", new MapDef(cdef, new SceneDef(context), null));
    collection.add(feature);
    final File tempfile = File.createTempFile("report", ".html");
    tempfile.deleteOnExit();
    OutputDef output = new OutputDef(JasperReportService.MIME_HTML, tempfile);
    JasperReportService.generateReport(report, collection, null, output);
    // just test it's not empty
    assertTrue(tempfile.length() > 1000);
}
Also used : FeatureType(org.opengis.feature.FeatureType) ArrayList(java.util.ArrayList) JasperReport(net.sf.jasperreports.engine.JasperReport) Dimension(java.awt.Dimension) Feature(org.opengis.feature.Feature) URL(java.net.URL) MapDef(org.geotoolkit.report.graphic.map.MapDef) SceneDef(org.geotoolkit.display2d.service.SceneDef) OutputDef(org.geotoolkit.display2d.service.OutputDef) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) File(java.io.File) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Aggregations

MapDef (org.geotoolkit.report.graphic.map.MapDef)6 Dimension (java.awt.Dimension)3 File (java.io.File)3 JasperReport (net.sf.jasperreports.engine.JasperReport)3 MapLayers (org.apache.sis.portrayal.MapLayers)3 CanvasDef (org.geotoolkit.display2d.service.CanvasDef)3 OutputDef (org.geotoolkit.display2d.service.OutputDef)3 SceneDef (org.geotoolkit.display2d.service.SceneDef)3 Attribute (org.opengis.feature.Attribute)3 Feature (org.opengis.feature.Feature)3 FeatureType (org.opengis.feature.FeatureType)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Font (java.awt.Font)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Random (java.util.Random)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1