Search in sources :

Example 1 with BubbleMapLayer

use of org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer 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 2 with BubbleMapLayer

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

the class MgMapIntegrationTest method siteBoundsToAdminLevelsAreMappedAsBubbles.

@Test
public void siteBoundsToAdminLevelsAreMappedAsBubbles() throws IOException {
    BubbleMapLayer layer = new BubbleMapLayer();
    layer.addIndicator(NUMBER_OF_BENE_INDICATOR_ID);
    generateMap(layer, "mg-bubbles");
    assertThat(content.getMarkers().size(), equalTo(10));
    MapMarker marker = getMarkerForSite(1336279918);
    assertThat(marker.getX(), equalTo(262));
    assertThat(marker.getY(), equalTo(113));
}
Also used : MapMarker(org.activityinfo.legacy.shared.reports.content.MapMarker) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) Test(org.junit.Test)

Example 3 with BubbleMapLayer

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

the class GeoDigestModelBuilder method createLayer.

private BubbleMapLayer createLayer(List<Integer> siteIds) {
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Site, siteIds);
    BubbleMapLayer layer = new BubbleMapLayer(filter);
    layer.setLabelSequence(new ArabicNumberSequence());
    layer.setClustering(new AutomaticClustering());
    layer.setMinRadius(BUBBLE_SIZE);
    layer.setMaxRadius(BUBBLE_SIZE);
    layer.setBubbleColor(BUBBLE_COLOR);
    return layer;
}
Also used : ArabicNumberSequence(org.activityinfo.legacy.shared.reports.model.labeling.ArabicNumberSequence) Filter(org.activityinfo.legacy.shared.command.Filter) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) AutomaticClustering(org.activityinfo.legacy.shared.reports.model.clustering.AutomaticClustering)

Example 4 with BubbleMapLayer

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

the class GeoDigestModelBuilder method createDatabaseModel.

private void createDatabaseModel(GeoDigestModel model, Database database) throws IOException {
    DatabaseModel databaseModel = new DatabaseModel(model, database);
    List<Integer> siteIds = findSiteIds(database, model.getUserDigest().getFrom());
    LOGGER.finest("rendering geo digest for user " + model.getUserDigest().getUser().getId() + " and database " + database.getId() + " - found " + siteIds.size() + " site(s) that were edited since " + DateFormatter.formatDateTime(model.getUserDigest().getFrom()));
    if (!siteIds.isEmpty()) {
        MapReportElement reportModel = new MapReportElement();
        reportModel.setMaximumZoomLevel(9);
        BubbleMapLayer layer = createLayer(siteIds);
        reportModel.setLayers(layer);
        MapContent content = dispatcher.execute(new GenerateElement<MapContent>(reportModel));
        databaseModel.setContent(content);
        if (!content.getMarkers().isEmpty()) {
            reportModel.setContent(content);
            GeneratedResource storage = storageProvider.create("image/png", "map.png");
            try (OutputStream outputStream = storage.openOutputStream()) {
                imageMapRenderer.render(reportModel, outputStream);
            }
            databaseModel.setUrl(storage.getDownloadUri());
        }
    }
}
Also used : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) DatabaseModel(org.activityinfo.server.digest.geo.GeoDigestModel.DatabaseModel) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) OutputStream(java.io.OutputStream) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) GeneratedResource(org.activityinfo.server.generated.GeneratedResource)

Example 5 with BubbleMapLayer

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

the class ItextReportRendererTest method legendTest.

@Test
public void legendTest() throws IOException {
    BubbleMapMarker marker1 = new BubbleMapMarker();
    marker1.setLat(-2.45);
    marker1.setLng(28.8);
    marker1.setX(100);
    marker1.setY(100);
    marker1.setRadius(25);
    marker1.setValue(300);
    TileBaseMap baseMap = new TileBaseMap();
    baseMap.setTileUrlPattern("//www.activityinfo.org/resources/tile/nordkivu.cd/{z}/{x}/{y}.png");
    BubbleMapLayer layer1 = new BubbleMapLayer();
    layer1.addIndicatorId(101);
    layer1.setMinRadius(10);
    layer1.setMaxRadius(10);
    BubbleLayerLegend legend1 = new BubbleLayerLegend();
    legend1.setDefinition(layer1);
    legend1.setMinValue(1000);
    legend1.setMaxValue(3000);
    BubbleMapLayer layer2 = new BubbleMapLayer();
    layer2.addIndicatorId(102);
    layer2.addIndicatorId(103);
    layer2.setMinRadius(10);
    layer2.setMaxRadius(25);
    BubbleLayerLegend legend2 = new BubbleLayerLegend();
    legend2.setDefinition(layer2);
    legend2.setMinValue(600);
    legend2.setMaxValue(999);
    IconMapLayer layer3 = new IconMapLayer();
    layer3.setIcon(MapIcon.Icon.Default.name());
    layer3.getIndicatorIds().add(101);
    IconLayerLegend legend3 = new IconLayerLegend();
    legend3.setDefinition(layer3);
    List<PieChartLegend> pieChartLegends = Lists.newArrayList();
    List<PiechartMapLayer> pieChartLayers = Lists.newArrayList();
    int[] indicatorIds = new int[] { 101, 102, 103 };
    for (int sliceCount = 1; sliceCount < 10; ++sliceCount) {
        PiechartMapLayer pieChartLayer = new PiechartMapLayer();
        for (int i = 0; i != sliceCount; ++i) {
            pieChartLayer.addIndicatorId(indicatorIds[i % indicatorIds.length]);
        }
        pieChartLayer.setMinRadius(25);
        pieChartLayer.setMaxRadius(25);
        PieChartLegend pieChartLegend = new PieChartLegend();
        pieChartLegend.setDefinition(pieChartLayer);
        pieChartLayers.add(pieChartLayer);
        pieChartLegends.add(pieChartLegend);
    }
    IndicatorDTO indicator101 = new IndicatorDTO();
    indicator101.setId(101);
    indicator101.setName("Nombre de salles de classe fonctionnelles (construites, rehabilitees, equipees) " + "pour l'education formelle et non formelle.");
    IndicatorDTO indicator102 = new IndicatorDTO();
    indicator102.setId(102);
    indicator102.setName("Nombre d'enfants ayant beneficie de kits scolaires, recreatifs et didactiques");
    IndicatorDTO indicator103 = new IndicatorDTO();
    indicator103.setId(103);
    indicator103.setName("Pourcentage des ménages qui utilsent la moustiquaire rationnellement");
    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));
    mapContent.getIndicators().addAll(Arrays.asList(indicator101, indicator102, indicator103));
    mapContent.addLegend(legend1);
    mapContent.addLegend(legend2);
    mapContent.addLegend(legend3);
    mapContent.getLegends().addAll(pieChartLegends);
    MapReportElement map = new MapReportElement();
    map.setTitle("My Map");
    map.setContent(mapContent);
    map.addLayer(layer1);
    map.addLayer(layer2);
    map.addLayer(layer3);
    map.getLayers().addAll(pieChartLayers);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(map);
    renderToPdf(report, "legend.pdf");
    renderToHtml(report, "legend.html");
    renderToRtf(report, "legend.rtf");
}
Also used : IconMapLayer(org.activityinfo.legacy.shared.reports.model.layers.IconMapLayer) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) Extents(org.activityinfo.model.type.geo.Extents) IndicatorDTO(org.activityinfo.legacy.shared.model.IndicatorDTO) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) PiechartMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer) Test(org.junit.Test)

Aggregations

BubbleMapLayer (org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer)9 Test (org.junit.Test)7 MapReportElement (org.activityinfo.legacy.shared.reports.model.MapReportElement)4 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)3 TileBaseMap (org.activityinfo.legacy.shared.model.TileBaseMap)2 AutomaticClustering (org.activityinfo.legacy.shared.reports.model.clustering.AutomaticClustering)2 ArabicNumberSequence (org.activityinfo.legacy.shared.reports.model.labeling.ArabicNumberSequence)2 PiechartMapLayer (org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetBaseMaps (org.activityinfo.legacy.shared.command.GetBaseMaps)1 BaseMapResult (org.activityinfo.legacy.shared.command.result.BaseMapResult)1 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)1 IndicatorDTO (org.activityinfo.legacy.shared.model.IndicatorDTO)1 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)1 BubbleMapMarker (org.activityinfo.legacy.shared.reports.content.BubbleMapMarker)1 MapMarker (org.activityinfo.legacy.shared.reports.content.MapMarker)1