Search in sources :

Example 6 with AiLatLng

use of org.activityinfo.shared.report.content.AiLatLng in project activityinfo by bedatadriven.

the class ImageMapRenderer method drawGoogleBaseMap.

@LogSlow(threshold = 100)
protected void drawGoogleBaseMap(TileHandler tileHandler, TiledMap map, GoogleBaseMap baseMap) throws IOException {
    for (int x = 0; x < map.getWidth(); x += GoogleStaticMapsApi.MAX_WIDTH) {
        for (int y = 0; y < map.getHeight(); y += GoogleStaticMapsApi.MAX_HEIGHT) {
            int sliceWidth = Math.min(GoogleStaticMapsApi.MAX_WIDTH, map.getWidth() - x);
            int sliceHeight = Math.min(GoogleStaticMapsApi.MAX_HEIGHT, map.getHeight() - y);
            AiLatLng sliceCenter = map.fromPixelToLatLng(x + (sliceWidth / 2), y + (sliceHeight / 2));
            String tileUrl = GoogleStaticMapsApi.buildRequest().setBaseMap(baseMap).setCenter(sliceCenter).setWidth(sliceWidth).setHeight(sliceHeight).setZoom(map.getZoom()).urlString();
            tileHandler.addTile(tileUrl, x, y, sliceWidth, sliceHeight);
        }
    }
}
Also used : AiLatLng(org.activityinfo.shared.report.content.AiLatLng) LogSlow(org.activityinfo.server.util.logging.LogSlow)

Example 7 with AiLatLng

use of org.activityinfo.shared.report.content.AiLatLng in project activityinfo by bedatadriven.

the class BubbleLayerGenerator method generate.

@Override
public void generate(TiledMap map, MapContent content) {
    // define our symbol scaling
    RadiiCalculator radiiCalculator;
    if (layer.getScaling() == ScalingType.None || layer.getMinRadius() == layer.getMaxRadius()) {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    } else if (layer.getScaling() == ScalingType.Graduated) {
        radiiCalculator = new GsLogCalculator(layer.getMinRadius(), layer.getMaxRadius());
    } else {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    }
    BubbleIntersectionCalculator intersectionCalculator = new BubbleIntersectionCalculator(layer.getMaxRadius());
    Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), radiiCalculator, intersectionCalculator);
    // create the list of input point values
    List<PointValue> points = new ArrayList<PointValue>();
    List<PointValue> unmapped = new ArrayList<PointValue>();
    generatePoints(sites, map, layer, clusterer, points, unmapped);
    // Cluster points by the clustering algorithm set in the layer
    List<Cluster> clusters = clusterer.cluster(map, points);
    // add unmapped sites
    for (PointValue pv : unmapped) {
        content.getUnmappedSites().add(pv.getSite().getId());
    }
    BubbleLayerLegend legend = new BubbleLayerLegend();
    legend.setDefinition(layer);
    // create the markers
    List<BubbleMapMarker> markers = new ArrayList<BubbleMapMarker>();
    for (Cluster cluster : clusters) {
        Point px = cluster.getPoint();
        AiLatLng latlng = map.fromPixelToLatLng(px);
        BubbleMapMarker marker = new BubbleMapMarker();
        for (PointValue pv : cluster.getPointValues()) {
            marker.getSiteIds().add(pv.getSite().getId());
        }
        marker.setX(px.getX());
        marker.setY(px.getY());
        marker.setValue(cluster.sumValues());
        marker.setRadius((int) cluster.getRadius());
        marker.setLat(latlng.getLat());
        marker.setLng(latlng.getLng());
        marker.setAlpha(layer.getAlpha());
        marker.setTitle(formatTitle(cluster));
        marker.setIndicatorIds(new HashSet<Integer>(layer.getIndicatorIds()));
        marker.setClusterAmount(cluster.getPointValues().size());
        marker.setClustering(layer.getClustering());
        marker.setColor(layer.getBubbleColor());
        if (marker.getValue() < legend.getMinValue()) {
            legend.setMinValue(marker.getValue());
        }
        if (marker.getValue() > legend.getMaxValue()) {
            legend.setMaxValue(marker.getValue());
        }
        markers.add(marker);
    }
    // sort order by symbol radius descending
    // (this assures that smaller symbols are drawn on
    // top of larger ones)
    Collections.sort(markers, new Comparator<MapMarker>() {

        @Override
        public int compare(MapMarker o1, MapMarker o2) {
            if (o1.getSize() > o2.getSize()) {
                return -1;
            } else if (o1.getSize() < o2.getSize()) {
                return 1;
            }
            return 0;
        }
    });
    // number markers if applicable
    if (layer.getLabelSequence() != null) {
        numberMarkers(markers);
    }
    content.addLegend(legend);
    content.getMarkers().addAll(markers);
}
Also used : BubbleLayerLegend(org.activityinfo.shared.report.content.BubbleLayerLegend) MapMarker(org.activityinfo.shared.report.content.MapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) PointValue(org.activityinfo.shared.report.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Point(org.activityinfo.shared.report.content.Point) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) AiLatLng(org.activityinfo.shared.report.content.AiLatLng)

Example 8 with AiLatLng

use of org.activityinfo.shared.report.content.AiLatLng in project activityinfo by bedatadriven.

the class IconLayerGenerator method createMarkersFrom.

private void createMarkersFrom(List<Cluster> clusters, TiledMap map, MapContent content) {
    for (Cluster cluster : clusters) {
        IconMapMarker marker = new IconMapMarker();
        marker.setX(cluster.getPoint().getX());
        marker.setY(cluster.getPoint().getY());
        AiLatLng latlng = map.fromPixelToLatLng(cluster.getPoint());
        marker.setLat(latlng.getLat());
        marker.setLng(latlng.getLng());
        marker.setTitle(formatTitle(cluster));
        marker.setIcon(icon);
        marker.setIndicatorId(layer.getIndicatorIds().get(0));
        for (PointValue pv : cluster.getPointValues()) {
            marker.getSiteIds().add(pv.getSite().getId());
        }
        content.getMarkers().add(marker);
    }
}
Also used : PointValue(org.activityinfo.shared.report.model.PointValue) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) AiLatLng(org.activityinfo.shared.report.content.AiLatLng)

Example 9 with AiLatLng

use of org.activityinfo.shared.report.content.AiLatLng in project activityinfo by bedatadriven.

the class PiechartLayerGenerator method generatePoints.

public void generatePoints(TiledMap map, PiechartMapLayer layer, Clusterer clusterer, List<PointValue> mapped, List<PointValue> unmapped) {
    for (SiteDTO site : sites) {
        if (hasValue(site, layer.getIndicatorIds())) {
            Point px = null;
            if (site.hasLatLong()) {
                px = map.fromLatLngToPixel(new AiLatLng(site.getLatitude(), site.getLongitude()));
            }
            Double value = getValue(site, layer.getIndicatorIds());
            if (value != null && value != 0) {
                PointValue pv = new PointValue(site, new MapSymbol(), value, px);
                calulateSlices(pv, site);
                if (clusterer.isMapped(site)) {
                    mapped.add(pv);
                } else {
                    unmapped.add(pv);
                }
            }
        }
    }
}
Also used : PointValue(org.activityinfo.shared.report.model.PointValue) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Point(org.activityinfo.shared.report.content.Point) MapSymbol(org.activityinfo.shared.report.model.MapSymbol)

Example 10 with AiLatLng

use of org.activityinfo.shared.report.content.AiLatLng in project activityinfo by bedatadriven.

the class PathUtils method addRingToPath.

private static void addRingToPath(TiledMap map, GeneralPath path, Coordinate[] coordinates) {
    System.out.println("--ring--");
    float lastX = Float.NaN;
    float lastY = Float.NaN;
    for (int j = 0; j != coordinates.length; ++j) {
        Point point = map.fromLatLngToPixel(new AiLatLng(coordinates[j].y, coordinates[j].x));
        float x = point.getX();
        float y = point.getY();
        if (x != lastX || y != lastY) {
            System.out.println(point.getX() + "," + point.getY());
            if (j == 0) {
                path.moveTo(x, y);
            } else {
                path.lineTo(x, y);
            }
        }
        lastX = x;
        lastY = y;
    }
    path.closePath();
}
Also used : AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Point(org.activityinfo.shared.report.content.Point) Point(org.activityinfo.shared.report.content.Point)

Aggregations

AiLatLng (org.activityinfo.shared.report.content.AiLatLng)22 Point (org.activityinfo.shared.report.content.Point)10 PointValue (org.activityinfo.shared.report.model.PointValue)7 ArrayList (java.util.ArrayList)6 SiteDTO (org.activityinfo.shared.dto.SiteDTO)6 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)5 MapContent (org.activityinfo.shared.report.content.MapContent)5 Test (org.junit.Test)5 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)3 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)3 PieMapMarker (org.activityinfo.shared.report.content.PieMapMarker)3 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)3 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)3 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)2 TiledMap (org.activityinfo.server.report.generator.map.TiledMap)2 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)2 MapSymbol (org.activityinfo.shared.report.model.MapSymbol)2 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 StoreEvent (com.extjs.gxt.ui.client.store.StoreEvent)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1