Search in sources :

Example 1 with MapLayer

use of org.activityinfo.shared.report.model.layers.MapLayer 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 MapLayer

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

the class MapEditor method createLayersOptionsPanel.

protected void createLayersOptionsPanel() {
    optionsPanel = new LayerOptionsPanel(dispatcher);
    optionsPanel.setVisible(false);
    optionsPanel.addListener(Events.Hide, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {
            mapPanel.setZoomControlOffsetX(ZOOM_CONTROL_LEFT_MARGIN);
        }
    });
    optionsPanel.addListener(Events.Show, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {
            mapPanel.setZoomControlOffsetX(LayerOptionsPanel.WIDTH + ZOOM_CONTROL_LEFT_MARGIN);
        }
    });
    optionsPanel.addValueChangeHandler(new ValueChangeHandler<MapLayer>() {

        @Override
        public void onValueChange(ValueChangeEvent<MapLayer> event) {
            reportEventBus.fireChange();
        }
    });
    add(optionsPanel, new AbsoluteData(0, CONTROL_TOP_MARGIN));
}
Also used : MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) AbsoluteData(com.extjs.gxt.ui.client.widget.layout.AbsoluteData) LayerOptionsPanel(org.activityinfo.client.report.editor.map.layerOptions.LayerOptionsPanel)

Example 3 with MapLayer

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

the class MapGenerator method queryIndicators.

private Map<Integer, Indicator> queryIndicators(MapReportElement element) {
    // Get relevant indicators for the map markers
    Set<Integer> indicatorIds = new HashSet<Integer>();
    for (MapLayer maplayer : element.getLayers()) {
        indicatorIds.addAll(maplayer.getIndicatorIds());
    }
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    for (Integer indicatorId : indicatorIds) {
        indicators.put(indicatorId, indicatorDAO.findById(indicatorId));
    }
    return indicators;
}
Also used : PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) PolygonMapLayer(org.activityinfo.shared.report.model.layers.PolygonMapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) HashSet(java.util.HashSet)

Example 4 with MapLayer

use of org.activityinfo.shared.report.model.layers.MapLayer 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);
    if (baseMap == null) {
        baseMap = TileBaseMap.createNullMap(element.getBaseMapId());
        LOGGER.log(Level.SEVERE, "Could not find base map id=" + element.getBaseMapId());
    }
    // 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.shared.report.model.DimensionType) MapContent(org.activityinfo.shared.report.content.MapContent) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) PolygonMapLayer(org.activityinfo.shared.report.model.layers.PolygonMapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) ArrayList(java.util.ArrayList) Extents(org.activityinfo.shared.util.mapping.Extents) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) GoogleBaseMap(org.activityinfo.shared.map.GoogleBaseMap) BaseMap(org.activityinfo.shared.map.BaseMap) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) BubbleLayerGenerator(org.activityinfo.server.report.generator.map.BubbleLayerGenerator) PolygonLayerGenerator(org.activityinfo.server.report.generator.map.PolygonLayerGenerator) PiechartLayerGenerator(org.activityinfo.server.report.generator.map.PiechartLayerGenerator) IconLayerGenerator(org.activityinfo.server.report.generator.map.IconLayerGenerator) LayerGenerator(org.activityinfo.server.report.generator.map.LayerGenerator) Filter(org.activityinfo.shared.command.Filter) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Margins(org.activityinfo.server.report.generator.map.Margins) TiledMap(org.activityinfo.server.report.generator.map.TiledMap)

Example 5 with MapLayer

use of org.activityinfo.shared.report.model.layers.MapLayer 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)

Aggregations

MapLayer (org.activityinfo.shared.report.model.layers.MapLayer)7 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)4 IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)4 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)4 ArrayList (java.util.ArrayList)3 PolygonMapLayer (org.activityinfo.shared.report.model.layers.PolygonMapLayer)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)2 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 AbsoluteData (com.extjs.gxt.ui.client.widget.layout.AbsoluteData)1 JsonElement (com.google.gson.JsonElement)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LayerOptionsPanel (org.activityinfo.client.report.editor.map.layerOptions.LayerOptionsPanel)1 BubbleLayerGenerator (org.activityinfo.server.report.generator.map.BubbleLayerGenerator)1 IconLayerGenerator (org.activityinfo.server.report.generator.map.IconLayerGenerator)1 LayerGenerator (org.activityinfo.server.report.generator.map.LayerGenerator)1 Margins (org.activityinfo.server.report.generator.map.Margins)1 PiechartLayerGenerator (org.activityinfo.server.report.generator.map.PiechartLayerGenerator)1