Search in sources :

Example 1 with IntersectionCalculator

use of org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.IntersectionCalculator in project activityinfo by bedatadriven.

the class IconLayerGenerator method generate.

@Override
public void generate(TiledMap map, MapContent content) {
    List<PointValue> points = new ArrayList<PointValue>();
    IconRectCalculator rectCalculator = new IconRectCalculator(icon);
    IntersectionCalculator intersectionCalculator = new IntersectionCalculator() {

        @Override
        public boolean intersects(Node a, Node b) {
            return a.getPointValue().getIconRect().intersects(b.getPointValue().getIconRect());
        }
    };
    Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), rectCalculator, intersectionCalculator);
    for (SiteDTO site : sites) {
        if (meetsCriteria(site)) {
            AiLatLng geoPoint = getPoint(site);
            if (geoPoint != null || clusterer.isMapped(site)) {
                Point point = null;
                if (geoPoint != null) {
                    point = map.fromLatLngToPixel(geoPoint);
                }
                points.add(new PointValue(site, point, point == null ? null : rectCalculator.iconRect(point), getValue(site, layer.getIndicatorIds())));
            } else {
                content.getUnmappedSites().add(site.getId());
            }
        }
    }
    List<Cluster> clusters = clusterer.cluster(map, points);
    createMarkersFrom(clusters, map, content);
    IconLayerLegend legend = new IconLayerLegend();
    legend.setDefinition(layer);
    content.addLegend(legend);
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) Node(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.Node) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) Point(org.activityinfo.legacy.shared.reports.content.Point) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) IntersectionCalculator(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.IntersectionCalculator) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) IconLayerLegend(org.activityinfo.legacy.shared.reports.content.IconLayerLegend)

Aggregations

ArrayList (java.util.ArrayList)1 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)1 IconLayerLegend (org.activityinfo.legacy.shared.reports.content.IconLayerLegend)1 Point (org.activityinfo.legacy.shared.reports.content.Point)1 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)1 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)1 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)1 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)1 IntersectionCalculator (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.IntersectionCalculator)1 Node (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.Node)1