Search in sources :

Example 1 with LayerGenerator

use of org.activityinfo.server.report.generator.map.LayerGenerator 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)

Aggregations

ArrayList (java.util.ArrayList)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)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 PolygonLayerGenerator (org.activityinfo.server.report.generator.map.PolygonLayerGenerator)1 TiledMap (org.activityinfo.server.report.generator.map.TiledMap)1 Filter (org.activityinfo.shared.command.Filter)1 BaseMap (org.activityinfo.shared.map.BaseMap)1 GoogleBaseMap (org.activityinfo.shared.map.GoogleBaseMap)1 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)1 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)1 MapContent (org.activityinfo.shared.report.content.MapContent)1 DimensionType (org.activityinfo.shared.report.model.DimensionType)1 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)1 IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)1 MapLayer (org.activityinfo.shared.report.model.layers.MapLayer)1 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)1