Search in sources :

Example 1 with MapContent

use of org.activityinfo.shared.report.content.MapContent in project activityinfo by bedatadriven.

the class MapGenerator method generate.

@Override
public void generate(User user, MapReportElement element, Filter inheritedFilter, DateRange dateRange) {
    Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
    Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
    MapContent content = new MapContent();
    content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
    Map<Integer, Indicator> indicators = queryIndicators(element);
    // Set up layer generators
    List<LayerGenerator> layerGenerators = new ArrayList<LayerGenerator>();
    for (MapLayer layer : element.getLayers()) {
        if (layer.isVisible()) {
            LayerGenerator layerGtor = createGenerator(layer, indicators);
            layerGtor.query(getDispatcher(), effectiveFilter);
            layerGenerators.add(layerGtor);
        }
    }
    // FIRST PASS: calculate extents and margins
    int width = element.getWidth();
    int height = element.getHeight();
    AiLatLng center;
    int zoom;
    Extents extents = Extents.emptyExtents();
    Margins margins = new Margins(0);
    for (LayerGenerator layerGtor : layerGenerators) {
        extents.grow(layerGtor.calculateExtents());
        margins.grow(layerGtor.calculateMargins());
    }
    content.setExtents(extents);
    if (element.getCenter() == null) {
        // Now we're ready to calculate the zoom level
        // and the projection
        zoom = TileMath.zoomLevelForExtents(extents, width, height);
        center = extents.center();
    } else {
        center = element.getCenter();
        zoom = element.getZoomLevel();
    }
    content.setCenter(center);
    // Retrieve the basemap and clamp zoom level
    BaseMap baseMap = findBaseMap(element, indicators.values());
    if (zoom < baseMap.getMinZoom()) {
        zoom = baseMap.getMinZoom();
    }
    if (zoom > baseMap.getMaxZoom()) {
        zoom = baseMap.getMaxZoom();
    }
    if (zoom > element.getMaximumZoomLevel()) {
        zoom = element.getMaximumZoomLevel();
    }
    TiledMap map = new TiledMap(width, height, center, zoom);
    content.setBaseMap(baseMap);
    content.setZoomLevel(zoom);
    if (baseMap == null) {
        baseMap = TileBaseMap.createNullMap(element.getBaseMapId());
        LOGGER.log(Level.SEVERE, "Could not find base map id=" + element.getBaseMapId());
    }
    // Generate the actual content
    for (LayerGenerator layerGtor : layerGenerators) {
        layerGtor.generate(map, content);
    }
    content.setIndicators(toDTOs(indicators.values()));
    element.setContent(content);
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) MapContent(org.activityinfo.shared.report.content.MapContent) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) PolygonMapLayer(org.activityinfo.shared.report.model.layers.PolygonMapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) ArrayList(java.util.ArrayList) Extents(org.activityinfo.shared.util.mapping.Extents) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) GoogleBaseMap(org.activityinfo.shared.map.GoogleBaseMap) BaseMap(org.activityinfo.shared.map.BaseMap) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) BubbleLayerGenerator(org.activityinfo.server.report.generator.map.BubbleLayerGenerator) PolygonLayerGenerator(org.activityinfo.server.report.generator.map.PolygonLayerGenerator) PiechartLayerGenerator(org.activityinfo.server.report.generator.map.PiechartLayerGenerator) IconLayerGenerator(org.activityinfo.server.report.generator.map.IconLayerGenerator) LayerGenerator(org.activityinfo.server.report.generator.map.LayerGenerator) Filter(org.activityinfo.shared.command.Filter) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Margins(org.activityinfo.server.report.generator.map.Margins) TiledMap(org.activityinfo.server.report.generator.map.TiledMap)

Example 2 with MapContent

use of org.activityinfo.shared.report.content.MapContent 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 : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) MapContent(org.activityinfo.shared.report.content.MapContent) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 3 with MapContent

use of org.activityinfo.shared.report.content.MapContent 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);
    FileOutputStream fos = new FileOutputStream("target/report-tests/polygon.pdf");
    PdfReportRenderer pdfr = new PdfReportRenderer(TestGeometry.get(), "");
    pdfr.render(map, fos);
    fos.close();
}
Also used : PolygonMapLayer(org.activityinfo.shared.report.model.layers.PolygonMapLayer) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) MapContent(org.activityinfo.shared.report.content.MapContent) PdfReportRenderer(org.activityinfo.server.report.renderer.itext.PdfReportRenderer) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test)

Example 4 with MapContent

use of org.activityinfo.shared.report.content.MapContent in project activityinfo by bedatadriven.

the class PiechartMapLayerGeneratorTest method testSomething.

@Test
public void testSomething() {
    SiteDTO siteData = new SiteDTO();
    siteData.setId(42);
    siteData.setX(15.0);
    siteData.setY(0.0);
    siteData.setIndicatorValue(1, 50.0);
    siteData.setIndicatorValue(2, 10.0);
    siteData.setIndicatorValue(3, 20.0);
    siteData.setIndicatorValue(4, 40.0);
    PiechartMapLayer pcml = new PiechartMapLayer();
    pcml.setMinRadius(10);
    pcml.setMaxRadius(50);
    pcml.addIndicatorId(1);
    pcml.addIndicatorId(2);
    pcml.addIndicatorId(3);
    pcml.addIndicatorId(4);
    pcml.setClustering(new NoClustering());
    TiledMap map = new TiledMap(500, 600, new AiLatLng(15.0, 0.0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(1, new Indicator());
    indicators.put(2, new Indicator());
    indicators.put(3, new Indicator());
    indicators.put(4, new Indicator());
    PiechartLayerGenerator gen = new PiechartLayerGenerator(pcml, indicators);
    gen.setSites(Arrays.asList(siteData));
    MapContent mc = new MapContent();
    gen.generate(map, mc);
    assertThat(mc.getMarkers().size(), equalTo(1));
    assertThat(((PieMapMarker) mc.getMarkers().get(0)).getSlices().size(), equalTo(4));
}
Also used : MapContent(org.activityinfo.shared.report.content.MapContent) NoClustering(org.activityinfo.shared.report.model.clustering.NoClustering) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Test(org.junit.Test)

Example 5 with MapContent

use of org.activityinfo.shared.report.content.MapContent in project activityinfo by bedatadriven.

the class ItextReportRendererTest method iconTest.

@Test
public void iconTest() throws IOException {
    IconMapMarker marker1 = new IconMapMarker();
    marker1.setIcon(MapIcon.fromEnum(Icon.Default));
    marker1.setLat(-2.45);
    marker1.setLng(28.8);
    marker1.setX(100);
    marker1.setY(100);
    TileBaseMap baseMap = new TileBaseMap();
    baseMap.setTileUrlPattern("//www.activityinfo.org/resources/tile/nordkivu.cd/{z}/{x}/{y}.png");
    IconMapLayer layer3 = new IconMapLayer();
    layer3.setIcon(MapIcon.Icon.Default.name());
    layer3.getIndicatorIds().add(101);
    MapContent mapContent = new MapContent();
    mapContent.setFilterDescriptions(Collections.EMPTY_LIST);
    mapContent.setBaseMap(baseMap);
    mapContent.setZoomLevel(8);
    mapContent.setCenter(new Extents(-2.2, -2.1, 28.85, 28.9).center());
    mapContent.setMarkers(Arrays.asList((MapMarker) marker1));
    MapReportElement map = new MapReportElement();
    map.setTitle("My Map");
    map.setContent(mapContent);
    map.addLayer(layer3);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(map);
    renderToPdf(report, "iconMarker.pdf");
    renderToHtml(report, "iconMarker.html");
    renderToRtf(report, "iconMarker.rtf");
    renderToPpt(map, "iconMarker.ppt");
    renderToImage(map, "iconMarker.png");
}
Also used : MapReportElement(org.activityinfo.shared.report.model.MapReportElement) ReportContent(org.activityinfo.shared.report.content.ReportContent) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) Extents(org.activityinfo.shared.util.mapping.Extents) Test(org.junit.Test)

Aggregations

MapContent (org.activityinfo.shared.report.content.MapContent)14 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)12 Test (org.junit.Test)11 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)6 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)6 IconMapMarker (org.activityinfo.shared.report.content.IconMapMarker)6 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)5 MapMarker (org.activityinfo.shared.report.content.MapMarker)5 Extents (org.activityinfo.shared.util.mapping.Extents)5 ReportContent (org.activityinfo.shared.report.content.ReportContent)4 Report (org.activityinfo.shared.report.model.Report)4 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)4 IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)4 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)4 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)3 SiteDTO (org.activityinfo.shared.dto.SiteDTO)3 PolygonMapLayer (org.activityinfo.shared.report.model.layers.PolygonMapLayer)3 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 PdfReportRenderer (org.activityinfo.server.report.renderer.itext.PdfReportRenderer)2