Search in sources :

Example 1 with IconMapLayer

use of org.activityinfo.shared.report.model.layers.IconMapLayer in project activityinfo by bedatadriven.

the class ReportJsonFactory method encodeLayers.

public JsonArray encodeLayers(List<MapLayer> layers) {
    JsonArray jsonLayers = new JsonArray();
    for (int i = 0; i < layers.size(); i++) {
        MapLayer layer = layers.get(i);
        JsonObject jsonLayer = new JsonObject();
        if (layer instanceof BubbleMapLayer) {
            jsonLayer.addProperty("layerType", layer.getTypeName());
            jsonLayer.add("colorDimensions", encodeDimensionList(((BubbleMapLayer) layer).getColorDimensions()));
            jsonLayer.addProperty("bubbleColor", ((BubbleMapLayer) layer).getBubbleColor());
            jsonLayer.addProperty("labelColor", ((BubbleMapLayer) layer).getLabelColor());
            jsonLayer.addProperty("minRadius", ((BubbleMapLayer) layer).getMinRadius());
            jsonLayer.addProperty("maxRadius", ((BubbleMapLayer) layer).getMaxRadius());
            jsonLayer.addProperty("alpha", ((BubbleMapLayer) layer).getAlpha());
            jsonLayer.addProperty("scaling", ((BubbleMapLayer) layer).getScaling().toString());
        } else if (layer instanceof PiechartMapLayer) {
            jsonLayer.addProperty("layerType", layer.getTypeName());
            jsonLayer.add("slices", encodeSlicesList(((PiechartMapLayer) layer).getSlices()));
            jsonLayer.addProperty("minRadius", ((PiechartMapLayer) layer).getMinRadius());
            jsonLayer.addProperty("maxRadius", ((PiechartMapLayer) layer).getMaxRadius());
            jsonLayer.addProperty("alpha", ((PiechartMapLayer) layer).getAlpha());
            jsonLayer.addProperty("scaling", ((PiechartMapLayer) layer).getScaling().toString());
        } else if (layer instanceof IconMapLayer) {
            jsonLayer.addProperty("layerType", layer.getTypeName());
            jsonLayer.add("activityIds", encodeIntegerList(((IconMapLayer) layer).getActivityIds()));
            jsonLayer.addProperty("icon", ((IconMapLayer) layer).getIcon());
        }
        jsonLayer.addProperty("isVisible", layer.isVisible());
        jsonLayer.add("indicatorIds", encodeIntegerList(layer.getIndicatorIds()));
        // jsonLayer.addProperty("labelSequence", layer.getLabelSequence()
        // .next());
        // jsonLayer.addProperty("cluster", (Boolean) layer.isClustered());
        jsonLayer.addProperty("name", layer.getName());
        jsonLayer.add("filter", encodeFilter(layer.getFilter()));
        jsonLayers.add(jsonLayer);
    }
    return jsonLayers;
}
Also used : JsonArray(com.google.gson.JsonArray) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) JsonObject(com.google.gson.JsonObject) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer)

Example 2 with IconMapLayer

use of org.activityinfo.shared.report.model.layers.IconMapLayer 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");
    renderToPpt(map, "iconMarker.ppt");
    renderToImage(map, "iconMarker.png");
}
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) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) Extents(org.activityinfo.shared.util.mapping.Extents) Test(org.junit.Test)

Example 3 with IconMapLayer

use of org.activityinfo.shared.report.model.layers.IconMapLayer 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.shared.report.model.MapReportElement) AdministrativeLevelClustering(org.activityinfo.shared.report.model.clustering.AdministrativeLevelClustering) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) MapContent(org.activityinfo.shared.report.content.MapContent) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) Test(org.junit.Test)

Example 4 with IconMapLayer

use of org.activityinfo.shared.report.model.layers.IconMapLayer in project activityinfo by bedatadriven.

the class ReportJsonFactory method decodeLayers.

public List<MapLayer> decodeLayers(JsonArray layers) {
    Iterator<JsonElement> it = layers.iterator();
    List<MapLayer> mapLayers = new ArrayList<MapLayer>();
    while (it.hasNext()) {
        JsonObject jsonLayer = it.next().getAsJsonObject();
        if ("Bubble".equals(jsonLayer.get("type"))) {
            BubbleMapLayer layer = new BubbleMapLayer();
            JsonArray colorDimensions = jsonLayer.get("colorDimensions").getAsJsonArray();
            if (colorDimensions.size() > 0) {
                layer.setColorDimensions(decodeDimensionList(colorDimensions));
            }
            JsonElement bubbleColor = jsonLayer.get("bubbleColor");
            if (bubbleColor != null) {
                layer.setBubbleColor(bubbleColor.getAsString());
            }
            JsonElement labelColor = jsonLayer.get("labelColor");
            if (labelColor != null) {
                layer.setLabelColor(labelColor.getAsString());
            }
            JsonElement minRadius = jsonLayer.get("minRadius");
            if (minRadius != null) {
                layer.setMinRadius(minRadius.getAsInt());
            }
            JsonElement maxRadius = jsonLayer.get("maxRadius");
            if (maxRadius != null) {
                layer.setMaxRadius(maxRadius.getAsInt());
            }
            JsonElement alpha = jsonLayer.get("alpha");
            if (alpha != null) {
                layer.setAlpha(alpha.getAsDouble());
            }
            JsonElement scaling = jsonLayer.get("scaling");
            if (scaling != null) {
                layer.setScaling(ScalingType.valueOf(scaling.getAsString()));
            }
            layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
            JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
            Iterator<JsonElement> itr = indicators.iterator();
            while (itr.hasNext()) {
                layer.addIndicator(itr.next().getAsInt());
            }
            if (jsonLayer.get("cluster").getAsBoolean()) {
                layer.setClustering(new AutomaticClustering());
            } else {
                layer.setClustering(new NoClustering());
            }
            layer.setName(jsonLayer.get("name").getAsString());
            layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
            mapLayers.add(layer);
        } else if ("Piechart".equals(jsonLayer.get("type"))) {
            PiechartMapLayer layer = new PiechartMapLayer();
            JsonElement minRadius = jsonLayer.get("minRadius");
            if (minRadius != null) {
                layer.setMinRadius(minRadius.getAsInt());
            }
            JsonElement maxRadius = jsonLayer.get("maxRadius");
            if (maxRadius != null) {
                layer.setMaxRadius(maxRadius.getAsInt());
            }
            JsonElement alpha = jsonLayer.get("alpha");
            if (alpha != null) {
                layer.setAlpha(alpha.getAsDouble());
            }
            JsonElement scaling = jsonLayer.get("scaling");
            if (scaling != null) {
                layer.setScaling(ScalingType.valueOf(scaling.getAsString()));
            }
            layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
            JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
            Iterator<JsonElement> itr = indicators.iterator();
            while (itr.hasNext()) {
                layer.addIndicatorId(itr.next().getAsInt());
            }
            if (jsonLayer.get("cluster").getAsBoolean()) {
                layer.setClustering(new AutomaticClustering());
            } else {
                layer.setClustering(new NoClustering());
            }
            layer.setName(jsonLayer.get("name").getAsString());
            layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
            mapLayers.add(layer);
        } else if ("Bubble".equals(jsonLayer.get("type"))) {
            IconMapLayer layer = new IconMapLayer();
            JsonArray activityIds = jsonLayer.get("activityIds").getAsJsonArray();
            Iterator<JsonElement> activityIrtator = activityIds.iterator();
            while (activityIrtator.hasNext()) {
                layer.addActivityId(activityIrtator.next().getAsInt());
            }
            JsonElement icon = jsonLayer.get("icon");
            if (icon != null) {
                layer.setIcon(icon.getAsString());
            }
            layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
            JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
            Iterator<JsonElement> itr = indicators.iterator();
            while (itr.hasNext()) {
                layer.addIndicatorId(itr.next().getAsInt());
            }
            if (jsonLayer.get("cluster").getAsBoolean()) {
                layer.setClustering(new AutomaticClustering());
            } else {
                layer.setClustering(new NoClustering());
            }
            layer.setName(jsonLayer.get("name").getAsString());
            layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
            mapLayers.add(layer);
        }
    }
    return mapLayers;
}
Also used : IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) NoClustering(org.activityinfo.shared.report.model.clustering.NoClustering) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) Iterator(java.util.Iterator) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) AutomaticClustering(org.activityinfo.shared.report.model.clustering.AutomaticClustering)

Example 5 with IconMapLayer

use of org.activityinfo.shared.report.model.layers.IconMapLayer 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");
    renderToPpt(map, "legend.ppt");
}
Also used : ReportContent(org.activityinfo.shared.report.content.ReportContent) BubbleLayerLegend(org.activityinfo.shared.report.content.BubbleLayerLegend) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) Extents(org.activityinfo.shared.util.mapping.Extents) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) PieChartLegend(org.activityinfo.shared.report.content.PieChartLegend) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) IconLayerLegend(org.activityinfo.shared.report.content.IconLayerLegend) Test(org.junit.Test)

Aggregations

IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)5 IconMapMarker (org.activityinfo.shared.report.content.IconMapMarker)3 MapContent (org.activityinfo.shared.report.content.MapContent)3 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)3 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)3 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)3 Test (org.junit.Test)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)2 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)2 MapMarker (org.activityinfo.shared.report.content.MapMarker)2 ReportContent (org.activityinfo.shared.report.content.ReportContent)2 Report (org.activityinfo.shared.report.model.Report)2 MapLayer (org.activityinfo.shared.report.model.layers.MapLayer)2 Extents (org.activityinfo.shared.util.mapping.Extents)2 JsonElement (com.google.gson.JsonElement)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)1