Search in sources :

Example 1 with Bounds

use of org.openlca.geo.calc.Bounds in project olca-app by GreenDelta.

the class ResultMap method bsize.

private double bsize(Pair<Location, Feature> pair) {
    return bsize.computeIfAbsent(pair.first, loc -> {
        Feature f = pair.second;
        Bounds bounds = Bounds.of(f);
        return Math.abs(bounds.maxX - bounds.minX) * Math.abs(bounds.maxY - bounds.minY);
    });
}
Also used : Bounds(org.openlca.geo.calc.Bounds) Feature(org.openlca.geo.geojson.Feature)

Example 2 with Bounds

use of org.openlca.geo.calc.Bounds in project olca-app by GreenDelta.

the class MapView method initProjection.

/**
 * Find an initial zoom and center and calculate the projections.
 */
private void initProjection() {
    projections.clear();
    if (layers.isEmpty()) {
        return;
    }
    // find the centered projection
    FeatureCollection ref = null;
    for (LayerConfig config : layers) {
        if (config.isCenter()) {
            ref = config.layer;
            break;
        }
    }
    // with the largest bounds
    if (ref == null) {
        ref = layers.get(0).layer;
    }
    // calculate the center
    Bounds bounds = Bounds.of(ref);
    Point center = bounds.center();
    translation.center.x = center.x;
    translation.center.y = center.y;
    // try to find a good initial zoom
    Rectangle canvSize = canvas.getBounds();
    zoom = 0;
    for (int z = 0; z < 21; z++) {
        Point topLeft = new Point(bounds.minX, bounds.minY);
        Point bottomRight = new Point(bounds.maxX, bounds.maxY);
        WebMercator.apply(topLeft, z);
        WebMercator.apply(bottomRight, z);
        if ((bottomRight.x - topLeft.x) > canvSize.width)
            break;
        if ((bottomRight.y - topLeft.y) > canvSize.height)
            break;
        zoom = z;
    }
    // finally, project the layers
    projectLayers();
}
Also used : FeatureCollection(org.openlca.geo.geojson.FeatureCollection) Bounds(org.openlca.geo.calc.Bounds) Rectangle(org.eclipse.swt.graphics.Rectangle) MultiPoint(org.openlca.geo.geojson.MultiPoint) Point(org.openlca.geo.geojson.Point) MultiPoint(org.openlca.geo.geojson.MultiPoint) Point(org.openlca.geo.geojson.Point)

Aggregations

Bounds (org.openlca.geo.calc.Bounds)2 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Feature (org.openlca.geo.geojson.Feature)1 FeatureCollection (org.openlca.geo.geojson.FeatureCollection)1 MultiPoint (org.openlca.geo.geojson.MultiPoint)1 Point (org.openlca.geo.geojson.Point)1