Search in sources :

Example 1 with AiLatLng

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

the class LocationForm method addCoordFields.

private void addCoordFields() {
    coordinateFields = new CoordinateFields();
    coordinateFields.setToolTip(I18N.CONSTANTS.coordinateToolTip());
    add(coordinateFields.getLatitudeField());
    add(coordinateFields.getLongitudeField());
    newLocationPresenter.addListener(NewLocationPresenter.POSITION_CHANGED, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {
            if (!newLocationPresenter.isProvisional()) {
                coordinateFields.setValue(newLocationPresenter.getLatLng());
            }
        }
    });
    coordinateFields.addChangeListener(new Listener<FieldEvent>() {

        @Override
        public void handleEvent(FieldEvent be) {
            AiLatLng value = coordinateFields.getValue();
            if (value != null) {
                newLocationPresenter.setLatLng(value);
            }
        }
    });
}
Also used : FieldEvent(com.extjs.gxt.ui.client.event.FieldEvent) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) CoordinateFields(org.activityinfo.client.widget.CoordinateFields)

Example 2 with AiLatLng

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

the class MapEditorMapView method updateModelFromMap.

private void updateModelFromMap() {
    model.setZoomLevel(map.getMap().getZoom());
    LatLng center = map.getMap().getBounds().getCenter();
    model.setCenter(new AiLatLng(center.lat(), center.lng()));
}
Also used : AiLatLng(org.activityinfo.shared.report.content.AiLatLng) LatLng(org.discotools.gwt.leaflet.client.types.LatLng) AiLatLng(org.activityinfo.shared.report.content.AiLatLng)

Example 3 with AiLatLng

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

the class GeometryProjecter method transformCoordinates.

@Override
protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) {
    int n = coords.size();
    Coordinate[] outCoords = new Coordinate[n];
    int outIndex = 0;
    for (int i = 0; i != n; ++i) {
        Point px = map.fromLatLngToPixel(new AiLatLng(coords.getY(i), coords.getX(i)));
        outCoords[outIndex] = new Coordinate(px.getDoubleX(), px.getDoubleY());
        outIndex++;
    }
    return new CoordinateArraySequence(Arrays.copyOf(outCoords, outIndex));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Point(org.activityinfo.shared.report.content.Point) Point(org.activityinfo.shared.report.content.Point) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence)

Example 4 with AiLatLng

use of org.activityinfo.shared.report.content.AiLatLng 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 5 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)

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