Search in sources :

Example 1 with BubbleMapMarker

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

the class ItextReportRendererTest method htmlImages.

@Test
public void htmlImages() throws IOException {
    DummyPivotTableData data = new DummyPivotTableData();
    PivotChartContent chartContent = new PivotChartContent();
    chartContent.setData(data.table);
    chartContent.setYMin(0);
    chartContent.setYStep(100);
    chartContent.setFilterDescriptions(Collections.EMPTY_LIST);
    PivotChartReportElement chart = new PivotChartReportElement(Type.Pie);
    chart.setTitle("My Pie Chart");
    chart.setCategoryDimensions(data.colDims);
    chart.setSeriesDimensions(data.rowDims);
    chart.setContent(chartContent);
    PivotContent tableContent = new PivotContent();
    tableContent.setFilterDescriptions(Collections.EMPTY_LIST);
    tableContent.setData(data.table);
    PivotTableReportElement table = new PivotTableReportElement();
    table.setColumnDimensions(data.colDims);
    table.setRowDimensions(data.rowDims);
    table.setTitle("My Table");
    table.setContent(tableContent);
    BubbleMapMarker marker1 = new BubbleMapMarker();
    marker1.setLat(-2.45);
    marker1.setLng(28.8);
    marker1.setX(100);
    marker1.setY(100);
    marker1.setRadius(25);
    TileBaseMap baseMap = new TileBaseMap();
    baseMap.setTileUrlPattern("http://mt{s}.aimaps.net/nordkivu.cd/v1/z{z}/{x}x{y}.png");
    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);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(chart);
    report.addElement(table);
    report.addElement(new TextReportElement("Testing 1..2.3.. français"));
    report.addElement(map);
    renderToPdf(report, "piechart.pdf");
    renderToHtml(report, "piechart.html");
    // renderToHtmlUsingWriter(report, "piechart2.html");
    renderToRtf(report, "piechart.rtf");
}
Also used : 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) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) Extents(org.activityinfo.shared.util.mapping.Extents) TextReportElement(org.activityinfo.shared.report.model.TextReportElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) PivotContent(org.activityinfo.shared.report.content.PivotContent) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotChartContent(org.activityinfo.shared.report.content.PivotChartContent) Test(org.junit.Test)

Example 2 with BubbleMapMarker

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

the class ItextReportRendererTest method googleMapsBaseMap.

@Test
public void googleMapsBaseMap() throws IOException {
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    TileBaseMap referenceBaseMap = new TileBaseMap();
    referenceBaseMap.setTileUrlPattern("http://www.activityinfo.org/resources/tile/admin.cd/{z}/{x}/{y}.png");
    referenceBaseMap.setName("Administrative Map");
    BaseMap[] baseMaps = new BaseMap[] { referenceBaseMap, GoogleBaseMap.HYBRID, GoogleBaseMap.ROADMAP, GoogleBaseMap.SATELLITE, GoogleBaseMap.TERRAIN };
    for (BaseMap baseMap : baseMaps) {
        BubbleMapMarker marker1 = new BubbleMapMarker();
        marker1.setLat(-2.45);
        marker1.setLng(28.8);
        marker1.setX(100);
        marker1.setY(100);
        marker1.setRadius(25);
        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 satelliteMap = new MapReportElement();
        satelliteMap.setTitle(baseMap.toString());
        satelliteMap.setContent(mapContent);
        report.addElement(satelliteMap);
    }
    // renderToPdf(report, "google map.pdf");
    // renderToHtml(report, "google map.html");
    renderToRtf(report, "google map.rtf");
}
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) Report(org.activityinfo.shared.report.model.Report) MapContent(org.activityinfo.shared.report.content.MapContent) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Extents(org.activityinfo.shared.util.mapping.Extents) GoogleBaseMap(org.activityinfo.shared.map.GoogleBaseMap) BaseMap(org.activityinfo.shared.map.BaseMap) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) Test(org.junit.Test)

Example 3 with BubbleMapMarker

use of org.activityinfo.shared.report.content.BubbleMapMarker 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 4 with BubbleMapMarker

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

the class BubbleLayerGenerator method generate.

@Override
public void generate(TiledMap map, MapContent content) {
    // define our symbol scaling
    RadiiCalculator radiiCalculator;
    if (layer.getScaling() == ScalingType.None || layer.getMinRadius() == layer.getMaxRadius()) {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    } else if (layer.getScaling() == ScalingType.Graduated) {
        radiiCalculator = new GsLogCalculator(layer.getMinRadius(), layer.getMaxRadius());
    } else {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    }
    BubbleIntersectionCalculator intersectionCalculator = new BubbleIntersectionCalculator(layer.getMaxRadius());
    Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), radiiCalculator, intersectionCalculator);
    // create the list of input point values
    List<PointValue> points = new ArrayList<PointValue>();
    List<PointValue> unmapped = new ArrayList<PointValue>();
    generatePoints(sites, map, layer, clusterer, points, unmapped);
    // Cluster points by the clustering algorithm set in the layer
    List<Cluster> clusters = clusterer.cluster(map, points);
    // add unmapped sites
    for (PointValue pv : unmapped) {
        content.getUnmappedSites().add(pv.getSite().getId());
    }
    BubbleLayerLegend legend = new BubbleLayerLegend();
    legend.setDefinition(layer);
    // create the markers
    List<BubbleMapMarker> markers = new ArrayList<BubbleMapMarker>();
    for (Cluster cluster : clusters) {
        Point px = cluster.getPoint();
        AiLatLng latlng = map.fromPixelToLatLng(px);
        BubbleMapMarker marker = new BubbleMapMarker();
        for (PointValue pv : cluster.getPointValues()) {
            marker.getSiteIds().add(pv.getSite().getId());
        }
        marker.setX(px.getX());
        marker.setY(px.getY());
        marker.setValue(cluster.sumValues());
        marker.setRadius((int) cluster.getRadius());
        marker.setLat(latlng.getLat());
        marker.setLng(latlng.getLng());
        marker.setAlpha(layer.getAlpha());
        marker.setTitle(formatTitle(cluster));
        marker.setIndicatorIds(new HashSet<Integer>(layer.getIndicatorIds()));
        marker.setClusterAmount(cluster.getPointValues().size());
        marker.setClustering(layer.getClustering());
        marker.setColor(layer.getBubbleColor());
        if (marker.getValue() < legend.getMinValue()) {
            legend.setMinValue(marker.getValue());
        }
        if (marker.getValue() > legend.getMaxValue()) {
            legend.setMaxValue(marker.getValue());
        }
        markers.add(marker);
    }
    // sort order by symbol radius descending
    // (this assures that smaller symbols are drawn on
    // top of larger ones)
    Collections.sort(markers, new Comparator<MapMarker>() {

        @Override
        public int compare(MapMarker o1, MapMarker o2) {
            if (o1.getSize() > o2.getSize()) {
                return -1;
            } else if (o1.getSize() < o2.getSize()) {
                return 1;
            }
            return 0;
        }
    });
    // number markers if applicable
    if (layer.getLabelSequence() != null) {
        numberMarkers(markers);
    }
    content.addLegend(legend);
    content.getMarkers().addAll(markers);
}
Also used : BubbleLayerLegend(org.activityinfo.shared.report.content.BubbleLayerLegend) MapMarker(org.activityinfo.shared.report.content.MapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) PointValue(org.activityinfo.shared.report.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Point(org.activityinfo.shared.report.content.Point) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) AiLatLng(org.activityinfo.shared.report.content.AiLatLng)

Example 5 with BubbleMapMarker

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

the class PPTMapRenderer method render.

public void render(MapReportElement element, SlideShow ppt) throws IOException {
    // add first slide
    Slide slide = ppt.createSlide();
    // calculate map offset
    Dimension pageSize = ppt.getPageSize();
    int offsetX = ((int) pageSize.getWidth() - element.getWidth()) / 2;
    int offsetY = ((int) pageSize.getHeight() - element.getHeight()) / 2;
    // add the map background image
    drawBasemap(element, new PPTTileHandler(ppt, slide));
    // keep a list of map icons
    Map<String, Integer> iconPictureIndex = new HashMap<String, Integer>();
    // Add the indicator markers to the slide as shapes
    for (MapMarker marker : element.getContent().getMarkers()) {
        if (inView(element, marker)) {
            if (marker instanceof IconMapMarker) {
                addIconMarker(ppt, slide, offsetX, offsetY, iconPictureIndex, (IconMapMarker) marker);
            } else if (marker instanceof BubbleMapMarker) {
                addBubble(slide, offsetX, offsetY, (BubbleMapMarker) marker);
            }
        }
    }
}
Also used : MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Slide(org.apache.poi.hslf.model.Slide) HashMap(java.util.HashMap) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Dimension(com.google.code.appengine.awt.Dimension)

Aggregations

BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)8 MapMarker (org.activityinfo.shared.report.content.MapMarker)6 IconMapMarker (org.activityinfo.shared.report.content.IconMapMarker)5 MapContent (org.activityinfo.shared.report.content.MapContent)5 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)5 Test (org.junit.Test)4 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)3 ReportContent (org.activityinfo.shared.report.content.ReportContent)3 Report (org.activityinfo.shared.report.model.Report)3 Extents (org.activityinfo.shared.util.mapping.Extents)3 ArrayList (java.util.ArrayList)2 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)2 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)2 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)2 BubbleLayerLegend (org.activityinfo.shared.report.content.BubbleLayerLegend)2 PieChartLegend (org.activityinfo.shared.report.content.PieChartLegend)2 Point (org.activityinfo.shared.report.content.Point)2 PointValue (org.activityinfo.shared.report.model.PointValue)2 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)2 Dimension (com.google.code.appengine.awt.Dimension)1