Search in sources :

Example 1 with Extents

use of org.activityinfo.shared.util.mapping.Extents in project activityinfo by bedatadriven.

the class LeafletReportOverlays method addMarkers.

public Extents addMarkers(List<MapMarker> markers) {
    Extents extents = Extents.emptyExtents();
    for (MapMarker marker : markers) {
        markerLayer.addLayer(LeafletMarkerFactory.create(marker));
        extents.grow(marker.getLat(), marker.getLng());
    }
    return extents;
}
Also used : MapMarker(org.activityinfo.shared.report.content.MapMarker) Extents(org.activityinfo.shared.util.mapping.Extents)

Example 2 with Extents

use of org.activityinfo.shared.util.mapping.Extents in project activityinfo by bedatadriven.

the class AdminFieldSetPresenter method updateBounds.

private void updateBounds() {
    Extents oldBounds = bounds;
    bounds = AdminBoundsHelper.calculate(country, levels, new HasAdminEntityValues() {

        @Override
        public AdminEntityDTO getAdminEntity(int levelId) {
            return level(levelId).getSelection();
        }
    });
    if (!bounds.equals(oldBounds)) {
        boundsName = AdminBoundsHelper.name(bounds, levels, this);
        fireEvent(new BoundsChangedEvent(bounds, boundsName));
    }
}
Also used : HasAdminEntityValues(org.activityinfo.shared.dto.HasAdminEntityValues) Extents(org.activityinfo.shared.util.mapping.Extents)

Example 3 with Extents

use of org.activityinfo.shared.util.mapping.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);
    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 4 with Extents

use of org.activityinfo.shared.util.mapping.Extents in project activityinfo by bedatadriven.

the class GetAdminEntitiesHandler method toEntity.

public static AdminEntityDTO toEntity(SqlResultSetRow row) {
    AdminEntityDTO entity = new AdminEntityDTO();
    entity.setId(row.getInt("adminEntityId"));
    entity.setName(row.getString("name"));
    entity.setLevelId(row.getInt("adminLevelId"));
    if (!row.isNull("adminEntityParentId")) {
        entity.setParentId(row.getInt("adminEntityParentId"));
    }
    Extents bounds = Extents.empty();
    if (!row.isNull("x1")) {
        bounds.setMinLon(row.getDouble("x1"));
        bounds.setMinLat(row.getDouble("y1"));
        bounds.setMaxLon(row.getDouble("x2"));
        bounds.setMaxLat(row.getDouble("y2"));
        entity.setBounds(bounds);
    }
    return entity;
}
Also used : AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) Extents(org.activityinfo.shared.util.mapping.Extents)

Example 5 with Extents

use of org.activityinfo.shared.util.mapping.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");
    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)

Aggregations

Extents (org.activityinfo.shared.util.mapping.Extents)11 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)5 MapContent (org.activityinfo.shared.report.content.MapContent)5 MapMarker (org.activityinfo.shared.report.content.MapMarker)5 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)4 IconMapMarker (org.activityinfo.shared.report.content.IconMapMarker)4 ReportContent (org.activityinfo.shared.report.content.ReportContent)4 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)4 Report (org.activityinfo.shared.report.model.Report)4 IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 TiledMap (org.activityinfo.server.report.generator.map.TiledMap)2 BaseMap (org.activityinfo.shared.map.BaseMap)2 GoogleBaseMap (org.activityinfo.shared.map.GoogleBaseMap)2 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)2 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)2 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)2 BasicStroke (com.google.code.appengine.awt.BasicStroke)1 Font (com.google.code.appengine.awt.Font)1