Search in sources :

Example 1 with MapContent

use of org.activityinfo.legacy.shared.reports.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 : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) MapMarker(org.activityinfo.legacy.shared.reports.content.MapMarker) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) BubbleMapMarker(org.activityinfo.legacy.shared.reports.content.BubbleMapMarker) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 2 with MapContent

use of org.activityinfo.legacy.shared.reports.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);
    // 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 3 with MapContent

use of org.activityinfo.legacy.shared.reports.content.MapContent 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 4 with MapContent

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

the class MapGeneratorTest method adminMapIcon.

@Test
public void adminMapIcon() {
    AdministrativeLevelClustering clustering = new AdministrativeLevelClustering();
    clustering.getAdminLevels().add(1);
    IconMapLayer layer = new IconMapLayer();
    layer.setClustering(clustering);
    layer.getIndicatorIds().add(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());
    IconMapMarker marker = (IconMapMarker) result.getMarkers().get(0);
    assertThat(marker.getSiteIds().size(), equalTo(1));
    assertThat(marker.getSiteIds().get(0), equalTo(3));
    System.out.println(marker.getTitle());
    // assertThat(marker., equalTo(10000d));
    assertThat(result.getUnmappedSites().size(), equalTo(0));
}
Also used : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) AdministrativeLevelClustering(org.activityinfo.legacy.shared.reports.model.clustering.AdministrativeLevelClustering) IconMapLayer(org.activityinfo.legacy.shared.reports.model.layers.IconMapLayer) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) Test(org.junit.Test)

Example 5 with MapContent

use of org.activityinfo.legacy.shared.reports.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.legacy.shared.reports.content.MapContent) NoClustering(org.activityinfo.legacy.shared.reports.model.clustering.NoClustering) 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) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Test(org.junit.Test)

Aggregations

MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)8 MapReportElement (org.activityinfo.legacy.shared.reports.model.MapReportElement)6 Test (org.junit.Test)5 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 BubbleMapLayer (org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer)3 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)3 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)3 TileBaseMap (org.activityinfo.legacy.shared.model.TileBaseMap)2 BubbleMapMarker (org.activityinfo.legacy.shared.reports.content.BubbleMapMarker)2 IconMapMarker (org.activityinfo.legacy.shared.reports.content.IconMapMarker)2 PieMapMarker (org.activityinfo.legacy.shared.reports.content.PieMapMarker)2 AdministrativeLevelClustering (org.activityinfo.legacy.shared.reports.model.clustering.AdministrativeLevelClustering)2 PiechartMapLayer (org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 DimensionType (org.activityinfo.legacy.shared.command.DimensionType)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