Search in sources :

Example 6 with Extents

use of org.activityinfo.model.type.geo.Extents 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);
    // 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.legacy.shared.command.DimensionType) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) Extents(org.activityinfo.model.type.geo.Extents) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) GoogleBaseMap(org.activityinfo.legacy.shared.reports.content.GoogleBaseMap) Filter(org.activityinfo.legacy.shared.command.Filter) AiLatLng(org.activityinfo.model.type.geo.AiLatLng)

Example 7 with Extents

use of org.activityinfo.model.type.geo.Extents in project activityinfo by bedatadriven.

the class ActivityTest method testActivity.

@Test
public void testActivity() throws CommandException {
    /*
         * Initial data load
         */
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(1);
    /*
         * Create a new activity
         */
    LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
    ActivityFormDTO act = new ActivityFormDTO();
    act.setName("Warshing the dishes");
    act.setLocationType(locType);
    act.setReportingFrequency(ActivityFormDTO.REPORT_MONTHLY);
    act.setClassicView(false);
    CreateResult cresult = execute(CreateEntity.Activity(db, act));
    int newId = cresult.getNewId();
    /*
         * Reload schema to verify the changes have stuck
         */
    act = execute(new GetActivityForm(newId));
    assertEquals("name", "Warshing the dishes", act.getName());
    assertEquals("locationType", locType.getName(), act.getLocationType().getName());
    assertEquals("reportingFrequency", ActivityFormDTO.REPORT_MONTHLY, act.getReportingFrequency());
    assertEquals("public", Published.NOT_PUBLISHED.getIndex(), act.getPublished());
    assertEquals("classicView", false, act.getClassicView());
    Extents countryBounds = act.getLocationType().getCountryBounds();
    assertThat(countryBounds.getMinLat(), Matchers.equalTo(-13.0));
    assertThat(countryBounds.getMaxLat(), Matchers.equalTo(5.0));
    assertThat(countryBounds.getMinLon(), Matchers.equalTo(12.0));
    assertThat(countryBounds.getMaxLon(), Matchers.equalTo(31.0));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) Extents(org.activityinfo.model.type.geo.Extents) Test(org.junit.Test)

Example 8 with Extents

use of org.activityinfo.model.type.geo.Extents 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");
    renderToImage(map, "iconMarker.png");
}
Also used : IconMapLayer(org.activityinfo.legacy.shared.reports.model.layers.IconMapLayer) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) Extents(org.activityinfo.model.type.geo.Extents) Test(org.junit.Test)

Example 9 with Extents

use of org.activityinfo.model.type.geo.Extents 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://www.activityinfo.org/resources/tile/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");
    renderToRtf(report, "piechart.rtf");
}
Also used : DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) Extents(org.activityinfo.model.type.geo.Extents) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) Test(org.junit.Test)

Example 10 with Extents

use of org.activityinfo.model.type.geo.Extents 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 : TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) Extents(org.activityinfo.model.type.geo.Extents) BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) Test(org.junit.Test)

Aggregations

Extents (org.activityinfo.model.type.geo.Extents)16 TileBaseMap (org.activityinfo.legacy.shared.model.TileBaseMap)5 Test (org.junit.Test)5 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)3 BaseMap (org.activityinfo.legacy.shared.model.BaseMap)2 IconMapLayer (org.activityinfo.legacy.shared.reports.model.layers.IconMapLayer)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 ResultSet (java.sql.ResultSet)1 AdminEntity (org.activityinfo.geoadmin.model.AdminEntity)1 AdminLevel (org.activityinfo.geoadmin.model.AdminLevel)1 DimensionType (org.activityinfo.legacy.shared.command.DimensionType)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)1 HasAdminEntityValues (org.activityinfo.legacy.shared.model.HasAdminEntityValues)1 IndicatorDTO (org.activityinfo.legacy.shared.model.IndicatorDTO)1 GoogleBaseMap (org.activityinfo.legacy.shared.reports.content.GoogleBaseMap)1 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)1 MapMarker (org.activityinfo.legacy.shared.reports.content.MapMarker)1 Point (org.activityinfo.legacy.shared.reports.content.Point)1