Search in sources :

Example 6 with MapReportElement

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

the class MapTemplate method createElement.

@Override
public void createElement(final AsyncCallback<ReportElement> callback) {
    final NewLayerWizard wizard = new NewLayerWizard(dispatcher, locator);
    WizardDialog dialog = new WizardDialog(wizard);
    dialog.setHeadingText(I18N.CONSTANTS.newMap());
    dialog.show(new WizardCallback() {

        @Override
        public void onFinished() {
            MapReportElement map = new MapReportElement();
            map.addLayer(wizard.createLayer());
            callback.onSuccess(map);
        }
    });
}
Also used : NewLayerWizard(org.activityinfo.ui.client.component.report.editor.map.NewLayerWizard) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) WizardCallback(org.activityinfo.ui.client.widget.wizard.WizardCallback) WizardDialog(org.activityinfo.ui.client.widget.wizard.WizardDialog)

Example 7 with MapReportElement

use of org.activityinfo.legacy.shared.reports.model.MapReportElement 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 8 with MapReportElement

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

the class PieMapMarkerTest method testPies.

@Test
public void testPies() {
    Dimension dimension = new Dimension(DimensionType.Indicator);
    dimension.setCategoryColor(101, 255);
    dimension.setCategoryColor(102, 0x00FF00);
    dimension.setCategoryColor(103, 0x0000FF);
    SiteDTO site1 = new SiteDTO();
    site1.setId(1);
    site1.setX(0d);
    site1.setY(0d);
    site1.setIndicatorValue(101, 50d);
    site1.setIndicatorValue(102, 40d);
    site1.setIndicatorValue(103, 10d);
    List<SiteDTO> sites = new ArrayList<SiteDTO>();
    sites.add(site1);
    PiechartMapLayer layer = new PiechartMapLayer();
    layer.addIndicatorId(101);
    layer.addIndicatorId(102);
    layer.addIndicatorId(103);
    // layer.getColorDimensions().add(dimension);
    MapReportElement mapElement = new MapReportElement();
    mapElement.addLayer(layer);
    MapContent content = new MapContent();
    TiledMap map = new TiledMap(640, 480, new AiLatLng(0, 0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(101, new Indicator());
    indicators.put(102, new Indicator());
    indicators.put(103, new Indicator());
    PiechartLayerGenerator generator = new PiechartLayerGenerator(layer, indicators);
    generator.setSites(sites);
    generator.generate(map, content);
    Assert.assertEquals(1, content.getMarkers().size());
    PieMapMarker marker = (PieMapMarker) content.getMarkers().get(0);
    Assert.assertEquals(3, marker.getSlices().size());
}
Also used : MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) PiechartMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer) Test(org.junit.Test)

Example 9 with MapReportElement

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

the class PolygonGeneratorTest method polygonWithHole.

@Test
public void polygonWithHole() throws IOException {
    AdminMarker marker = new AdminMarker();
    marker.setAdminEntityId(1930);
    marker.setColor("#FFBBBB");
    AdminOverlay overlay = new AdminOverlay(1383);
    overlay.setOutlineColor("#FF0000");
    overlay.addPolygon(marker);
    PolygonMapLayer layer = new PolygonMapLayer();
    layer.addIndicatorId(1);
    layer.setAdminLevelId(1383);
    MapContent content = new MapContent();
    content.setZoomLevel(8);
    content.setBaseMap(GoogleBaseMap.ROADMAP);
    content.setCenter(new AiLatLng(12.60500192642215, -7.98924994468689));
    content.getAdminOverlays().add(overlay);
    content.setFilterDescriptions(new ArrayList<FilterDescription>());
    PolygonLegend.ColorClass clazz1 = new PolygonLegend.ColorClass(1, 53.6, "0000FF");
    PolygonLegend.ColorClass clazz2 = new PolygonLegend.ColorClass(600, 600, "FF0000");
    PolygonLegend legend = new PolygonLegend(layer, Lists.newArrayList(clazz1, clazz2));
    content.getLegends().add(legend);
    IndicatorDTO indicator = new IndicatorDTO();
    indicator.setId(1);
    indicator.setName("Indicator Test");
    content.getIndicators().add(indicator);
    MapReportElement map = new MapReportElement();
    map.addLayer(layer);
    map.setContent(content);
    try (FileOutputStream fos = TestOutput.open(getClass(), "polygon-hole.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) PdfReportRenderer(org.activityinfo.server.report.renderer.itext.PdfReportRenderer) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) IndicatorDTO(org.activityinfo.legacy.shared.model.IndicatorDTO) FileOutputStream(java.io.FileOutputStream) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) Test(org.junit.Test)

Example 10 with MapReportElement

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

the class TableGeneratorTest method testMap.

// 
// @Test
// public void tableWithMap() {
// 
// MapReportElement map = new MapReportElement();
// map.setBaseMapId(GoogleBaseMap.ROADMAP.getId());
// 
// BubbleMapLayer layer = new BubbleMapLayer();
// layer.addIndicator(INDICATOR_ID);
// map.addLayer(layer);
// 
// TableElement table = new TableElement();
// table.setMap(map);
// 
// TableColumn column = new TableColumn("Location", "location.name");
// table.addColumn(column);
// 
// TableColumn mapColumn = new TableColumn("Map", "map");
// table.addColumn(mapColumn);
// 
// DispatcherSync dispatcher = createDispatcher();
// TableGenerator gtor = new TableGenerator(dispatcher, new
// MapGenerator(dispatcher, null, null));
// gtor.generate(user, table, null, null);
// 
// Assert.assertNotNull("content is set", table.getContent());
// 
// TableData data = table.getContent().getData();
// List<SiteDTO> rows = data.getRows();
// Assert.assertEquals("row count", 1, rows.size());
// 
// SiteDTO row = rows.get(0);
// assertThat((String)row.get(column.getSitePropertyName()),
// equalTo("tampa bay"));
// assertThat((String)row.get("map"), equalTo("1"));
// }
@Test
public void testMap() {
    TableElement table = new TableElement();
    table.addColumn(new TableColumn("Index", "map"));
    table.addColumn(new TableColumn("Site", "location.name"));
    MapReportElement map = new MapReportElement();
    map.setBaseMapId("map1");
    CircledMapLayer layer = new BubbleMapLayer();
    layer.setLabelSequence(new ArabicNumberSequence());
    map.addLayer(layer);
    table.setMap(map);
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(dummySite())).anyTimes();
    TileBaseMap baseMap1 = new TileBaseMap();
    baseMap1.setId("map1");
    baseMap1.setMinZoom(0);
    baseMap1.setMaxZoom(12);
    baseMap1.setCopyright("(C)");
    baseMap1.setName("Grand Canyon");
    baseMap1.setTileUrlPattern("http://s/test.png");
    expect(dispatcher.execute(isA(GetBaseMaps.class))).andReturn(new BaseMapResult(Collections.singletonList(baseMap1)));
    replay(dispatcher);
    TableGenerator gtor = new TableGenerator(dispatcher, new MapGenerator(dispatcher, new MockIndicatorDAO()));
    gtor.generate(user, table, null, null);
    MapContent mapContent = map.getContent();
    Assert.assertNotNull("map content", mapContent);
    Assert.assertEquals("marker count", 1, mapContent.getMarkers().size());
    Assert.assertEquals("label on marker", "1", ((BubbleMapMarker) mapContent.getMarkers().get(0)).getLabel());
    Map<Integer, String> siteLabels = mapContent.siteLabelMap();
    Assert.assertEquals("site id in map", "1", siteLabels.get(1));
    SiteDTO row = table.getContent().getData().getRows().get(0);
    Assert.assertEquals("label on row", "1", row.get("map"));
}
Also used : ArabicNumberSequence(org.activityinfo.legacy.shared.reports.model.labeling.ArabicNumberSequence) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) BaseMapResult(org.activityinfo.legacy.shared.command.result.BaseMapResult) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) TableElement(org.activityinfo.legacy.shared.reports.model.TableElement) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) CircledMapLayer(org.activityinfo.legacy.shared.reports.model.layers.CircledMapLayer) GetBaseMaps(org.activityinfo.legacy.shared.command.GetBaseMaps) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

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