Search in sources :

Example 1 with MapReportElement

use of org.activityinfo.legacy.shared.reports.model.MapReportElement in project activityinfo by bedatadriven.

the class ExcelMapDataExporter method render.

@Override
public void render(ReportElement element, OutputStream stm) throws IOException {
    if (!(element instanceof MapReportElement)) {
        throw new RuntimeException("ExcelMapDataExporter accepts only MapElements");
    }
    MapContent content = ((MapReportElement) element).getContent();
    Workbook book = new HSSFWorkbook();
    Sheet sheet = book.createSheet();
    Helper helper = new Helper(book);
    Row headerRow = sheet.createRow(0);
    helper.addCell(headerRow, 0, "Latitude");
    helper.addCell(headerRow, 1, "Longitude");
    helper.addCell(headerRow, 2, "Value");
    helper.addCell(headerRow, 3, "Color");
    helper.addCell(headerRow, 4, "Icon");
    int rowIndex = 1;
    for (MapMarker marker : content.getMarkers()) {
        Row dataRow = sheet.createRow(rowIndex++);
        helper.addCell(dataRow, 0, marker.getLat());
        helper.addCell(dataRow, 1, marker.getLng());
        if (marker instanceof BubbleMapMarker) {
            BubbleMapMarker bmarker = (BubbleMapMarker) marker;
            helper.addCell(dataRow, 2, bmarker.getValue());
            helper.addCell(dataRow, 3, bmarker.getColor());
        }
        if (marker instanceof IconMapMarker) {
            IconMapMarker imarker = (IconMapMarker) marker;
            if (imarker.getIcon() != null) {
                helper.addCell(dataRow, 4, imarker.getIcon().getName());
            }
        }
    }
    book.write(stm);
}
Also used : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) MapMarker(org.activityinfo.legacy.shared.reports.content.MapMarker) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 2 with MapReportElement

use of org.activityinfo.legacy.shared.reports.model.MapReportElement in project activityinfo by bedatadriven.

the class MapGeneratorTest method adminMapBubbles.

@Test
public void adminMapBubbles() {
    AdministrativeLevelClustering clustering = new AdministrativeLevelClustering();
    clustering.getAdminLevels().add(1);
    BubbleMapLayer layer = new BubbleMapLayer();
    layer.setClustering(clustering);
    layer.addIndicator(1);
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Site, 3);
    MapReportElement map = new MapReportElement();
    map.addLayer(layer);
    map.setFilter(filter);
    MapContent result = (MapContent) execute(new GenerateElement(map));
    System.out.println(result.getMarkers());
    BubbleMapMarker marker = (BubbleMapMarker) result.getMarkers().get(0);
    assertThat(marker.getSiteIds().size(), equalTo(1));
    assertThat(marker.getSiteIds().get(0), equalTo(3));
    assertThat(marker.getValue(), equalTo(10000d));
    assertThat(result.getUnmappedSites().size(), equalTo(0));
    System.out.println(marker.getTitle());
}
Also used : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) AdministrativeLevelClustering(org.activityinfo.legacy.shared.reports.model.clustering.AdministrativeLevelClustering) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) Test(org.junit.Test)

Example 3 with MapReportElement

use of org.activityinfo.legacy.shared.reports.model.MapReportElement in project activityinfo by bedatadriven.

the class MapGeneratorTest method adminMapIcon.

@Test
public void adminMapIcon() {
    AdministrativeLevelClustering clustering = new AdministrativeLevelClustering();
    clustering.getAdminLevels().add(1);
    IconMapLayer layer = new IconMapLayer();
    layer.setClustering(clustering);
    layer.getIndicatorIds().add(1);
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Site, 3);
    MapReportElement map = new MapReportElement();
    map.addLayer(layer);
    map.setFilter(filter);
    MapContent result = (MapContent) execute(new GenerateElement(map));
    System.out.println(result.getMarkers());
    IconMapMarker marker = (IconMapMarker) result.getMarkers().get(0);
    assertThat(marker.getSiteIds().size(), equalTo(1));
    assertThat(marker.getSiteIds().get(0), equalTo(3));
    System.out.println(marker.getTitle());
    // assertThat(marker., equalTo(10000d));
    assertThat(result.getUnmappedSites().size(), equalTo(0));
}
Also used : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) AdministrativeLevelClustering(org.activityinfo.legacy.shared.reports.model.clustering.AdministrativeLevelClustering) IconMapLayer(org.activityinfo.legacy.shared.reports.model.layers.IconMapLayer) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) Test(org.junit.Test)

Example 4 with MapReportElement

use of org.activityinfo.legacy.shared.reports.model.MapReportElement in project activityinfo by bedatadriven.

the class PolygonGeneratorTest method basicTest.

@Test
public void basicTest() throws IOException {
    PolygonMapLayer layer = new PolygonMapLayer();
    layer.addIndicatorId(1);
    layer.setAdminLevelId(1383);
    MapReportElement map = new MapReportElement();
    map.addLayer(layer);
    MapContent content = execute(new GenerateElement<MapContent>(map));
    map.setContent(content);
    Reports.toPdf(getClass(), map, "polygon");
    try (FileOutputStream fos = TestOutput.open(getClass(), "polygon.pdf")) {
        PdfReportRenderer renderer = new PdfReportRenderer(TestGeometry.get(), MAP_ICON_PATH);
        renderer.render(map, fos);
    }
}
Also used : PolygonMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PolygonMapLayer) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) PdfReportRenderer(org.activityinfo.server.report.renderer.itext.PdfReportRenderer) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test)

Example 5 with MapReportElement

use of org.activityinfo.legacy.shared.reports.model.MapReportElement in project activityinfo by bedatadriven.

the class MgMapIntegrationTest method generateMap.

private void generateMap(MapLayer layer, String fileName) throws IOException {
    map = new MapReportElement();
    map.addLayer(layer);
    content = (MapContent) execute(new GenerateElement(map));
    renderToFile(map, fileName);
}
Also used : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) GenerateElement(org.activityinfo.legacy.shared.command.GenerateElement)

Aggregations

MapReportElement (org.activityinfo.legacy.shared.reports.model.MapReportElement)11 Test (org.junit.Test)7 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)6 BubbleMapLayer (org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer)4 FileOutputStream (java.io.FileOutputStream)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 BubbleMapMarker (org.activityinfo.legacy.shared.reports.content.BubbleMapMarker)2 IconMapMarker (org.activityinfo.legacy.shared.reports.content.IconMapMarker)2 AdministrativeLevelClustering (org.activityinfo.legacy.shared.reports.model.clustering.AdministrativeLevelClustering)2 PiechartMapLayer (org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer)2 PolygonMapLayer (org.activityinfo.legacy.shared.reports.model.layers.PolygonMapLayer)2 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)2 PdfReportRenderer (org.activityinfo.server.report.renderer.itext.PdfReportRenderer)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 GenerateElement (org.activityinfo.legacy.shared.command.GenerateElement)1 GetBaseMaps (org.activityinfo.legacy.shared.command.GetBaseMaps)1 BaseMapResult (org.activityinfo.legacy.shared.command.result.BaseMapResult)1