Search in sources :

Example 6 with Extents

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

the class ItextReportRendererTest method htmlImages.

@Test
public void htmlImages() throws IOException {
    DummyPivotTableData data = new DummyPivotTableData();
    PivotChartContent chartContent = new PivotChartContent();
    chartContent.setData(data.table);
    chartContent.setYMin(0);
    chartContent.setYStep(100);
    chartContent.setFilterDescriptions(Collections.EMPTY_LIST);
    PivotChartReportElement chart = new PivotChartReportElement(Type.Pie);
    chart.setTitle("My Pie Chart");
    chart.setCategoryDimensions(data.colDims);
    chart.setSeriesDimensions(data.rowDims);
    chart.setContent(chartContent);
    PivotContent tableContent = new PivotContent();
    tableContent.setFilterDescriptions(Collections.EMPTY_LIST);
    tableContent.setData(data.table);
    PivotTableReportElement table = new PivotTableReportElement();
    table.setColumnDimensions(data.colDims);
    table.setRowDimensions(data.rowDims);
    table.setTitle("My Table");
    table.setContent(tableContent);
    BubbleMapMarker marker1 = new BubbleMapMarker();
    marker1.setLat(-2.45);
    marker1.setLng(28.8);
    marker1.setX(100);
    marker1.setY(100);
    marker1.setRadius(25);
    TileBaseMap baseMap = new TileBaseMap();
    baseMap.setTileUrlPattern("http://mt{s}.aimaps.net/nordkivu.cd/v1/z{z}/{x}x{y}.png");
    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);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(chart);
    report.addElement(table);
    report.addElement(new TextReportElement("Testing 1..2.3.. français"));
    report.addElement(map);
    renderToPdf(report, "piechart.pdf");
    renderToHtml(report, "piechart.html");
    // renderToHtmlUsingWriter(report, "piechart2.html");
    renderToRtf(report, "piechart.rtf");
}
Also used : 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) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) Extents(org.activityinfo.shared.util.mapping.Extents) TextReportElement(org.activityinfo.shared.report.model.TextReportElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) PivotContent(org.activityinfo.shared.report.content.PivotContent) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotChartContent(org.activityinfo.shared.report.content.PivotChartContent) Test(org.junit.Test)

Example 7 with Extents

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

the class ItextReportRendererTest method googleMapsBaseMap.

@Test
public void googleMapsBaseMap() throws IOException {
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    TileBaseMap referenceBaseMap = new TileBaseMap();
    referenceBaseMap.setTileUrlPattern("http://www.activityinfo.org/resources/tile/admin.cd/{z}/{x}/{y}.png");
    referenceBaseMap.setName("Administrative Map");
    BaseMap[] baseMaps = new BaseMap[] { referenceBaseMap, GoogleBaseMap.HYBRID, GoogleBaseMap.ROADMAP, GoogleBaseMap.SATELLITE, GoogleBaseMap.TERRAIN };
    for (BaseMap baseMap : baseMaps) {
        BubbleMapMarker marker1 = new BubbleMapMarker();
        marker1.setLat(-2.45);
        marker1.setLng(28.8);
        marker1.setX(100);
        marker1.setY(100);
        marker1.setRadius(25);
        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 satelliteMap = new MapReportElement();
        satelliteMap.setTitle(baseMap.toString());
        satelliteMap.setContent(mapContent);
        report.addElement(satelliteMap);
    }
    // renderToPdf(report, "google map.pdf");
    // renderToHtml(report, "google map.html");
    renderToRtf(report, "google map.rtf");
}
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) Report(org.activityinfo.shared.report.model.Report) MapContent(org.activityinfo.shared.report.content.MapContent) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Extents(org.activityinfo.shared.util.mapping.Extents) GoogleBaseMap(org.activityinfo.shared.map.GoogleBaseMap) BaseMap(org.activityinfo.shared.map.BaseMap) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) Test(org.junit.Test)

Example 8 with Extents

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

the class LocationMap method afterRender.

@Override
protected void afterRender() {
    super.afterRender();
    Extents countryBounds = searchPresenter.getCountry().getBounds();
    MapOptions mapOptions = new MapOptions();
    mapOptions.setCenter(new LatLng(countryBounds.getCenterY(), countryBounds.getCenterX()));
    mapOptions.setZoom(6);
    mapOptions.setProperty("crs", new EPSG3857());
    TileLayer baseLayer = new TileLayer(MapboxLayers.MAPBOX_STREETS, new Options());
    markerLayer = new LayerGroup(new ILayer[0]);
    map = new Map(getElement().getElementsByTagName("div").getItem(0), mapOptions);
    map.addLayer(baseLayer);
    map.addLayer(markerLayer);
    bindEvents();
}
Also used : EPSG3857(org.discotools.gwt.leaflet.client.crs.epsg.EPSG3857) MapOptions(org.discotools.gwt.leaflet.client.map.MapOptions) Options(org.discotools.gwt.leaflet.client.Options) DivIconOptions(org.discotools.gwt.leaflet.client.types.DivIconOptions) TileLayer(org.discotools.gwt.leaflet.client.layers.raster.TileLayer) MapOptions(org.discotools.gwt.leaflet.client.map.MapOptions) ILayer(org.discotools.gwt.leaflet.client.layers.ILayer) LatLng(org.discotools.gwt.leaflet.client.types.LatLng) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) LayerGroup(org.discotools.gwt.leaflet.client.layers.others.LayerGroup) Extents(org.activityinfo.shared.util.mapping.Extents) Map(org.discotools.gwt.leaflet.client.map.Map)

Example 9 with Extents

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

the class AdminTileRenderer method render.

public byte[] render(int zoom, int x, int y) throws IOException {
    Extents extents = TileMath.tileBounds(zoom, x, y);
    mapPixelBounds = new Envelope(0, TileMath.TILE_SIZE, 0, TileMath.TILE_SIZE);
    Envelope envelope = new Envelope(extents.getMinLon(), extents.getMaxLon(), extents.getMinLat(), extents.getMaxLat());
    Geometry filter = gf.toGeometry(envelope);
    LOGGER.info("Creating Buffered Image...");
    BufferedImage image = new BufferedImage(TileMath.TILE_SIZE, TileMath.TILE_SIZE, ColorSpace.TYPE_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.setPaint(Color.WHITE);
    g2d.fillRect(0, 0, TileMath.TILE_SIZE, TileMath.TILE_SIZE);
    LOGGER.info("Querying geometry...");
    Criteria criteria = session.createCriteria(AdminEntity.class);
    criteria.add(SpatialRestrictions.filter("geometry", filter));
    criteria.add(Restrictions.eq("level", level));
    TiledMap map = new TiledMap(zoom, new Tile(x, y));
    g2d.setColor(Color.BLACK);
    g2d.setStroke(new BasicStroke(1));
    g2d.setFont(new Font("Arial", 0, 10));
    List<AdminEntity> entities = criteria.list();
    /*
         * Project Geometry onto this tile
         */
    LOGGER.info("Projecting geometry...");
    GeometryProjecter projector = new GeometryProjecter(map);
    Map<Integer, Geometry> projected = Maps.newHashMap();
    for (AdminEntity entity : entities) {
        LOGGER.info(entity.getName());
        Geometry transformed = projector.transform(entity.getGeometry());
        Geometry simplified = DouglasPeuckerSimplifier.simplify(transformed, 1.25);
        projected.put(entity.getId(), simplified);
    }
    /*
         * Draw outlines
         */
    LOGGER.info("Drawing geometry...");
    for (AdminEntity entity : entities) {
        Geometry geom = projected.get(entity.getId());
        g2d.draw(toPath(geom));
    }
    /*
         * Draw labels
         */
    LOGGER.info("Drawing geometry...");
    for (AdminEntity entity : entities) {
        Geometry geom = projected.get(entity.getId());
    // Polygon polygon = largestPolygon(geom);
    // 
    // if (polygon != null) {
    // labelPolygon(g2d, polygon, entity.getName());
    // }
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "png", baos);
    return baos.toByteArray();
}
Also used : BasicStroke(com.google.code.appengine.awt.BasicStroke) AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Tile(org.activityinfo.shared.util.mapping.Tile) Criteria(org.hibernate.Criteria) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Extents(org.activityinfo.shared.util.mapping.Extents) Envelope(com.vividsolutions.jts.geom.Envelope) BufferedImage(com.google.code.appengine.awt.image.BufferedImage) Font(com.google.code.appengine.awt.Font) Graphics2D(com.google.code.appengine.awt.Graphics2D) Geometry(com.vividsolutions.jts.geom.Geometry) TiledMap(org.activityinfo.server.report.generator.map.TiledMap)

Example 10 with Extents

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

the class GetSitePointsHandler method toPointList.

protected SitePointList toPointList(List<SiteDTO> sites) {
    Extents bounds = Extents.empty();
    List<SitePointDTO> points = new ArrayList<SitePointDTO>(sites.size());
    for (SiteDTO site : sites) {
        if (site.hasLatLong()) {
            points.add(new SitePointDTO(site.getId(), site.getLongitude(), site.getLatitude()));
            bounds.grow(site.getLatitude(), site.getLongitude());
        }
    }
    return new SitePointList(bounds, points);
}
Also used : SitePointList(org.activityinfo.shared.command.result.SitePointList) ArrayList(java.util.ArrayList) SitePointDTO(org.activityinfo.shared.dto.SitePointDTO) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Extents(org.activityinfo.shared.util.mapping.Extents)

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