Search in sources :

Example 1 with InstanceWaypoint

use of eu.esdihumboldt.hale.ui.views.styledmap.painter.InstanceWaypoint in project hale by halestudio.

the class StyledMapUtil method zoomToSelection.

/**
 * Zoom to the selected instances. Does nothing if the selection is empty or
 * contains no {@link Instance}s or {@link InstanceReference}s.
 *
 * @param mapKit the map kit
 * @param selection the selection
 */
public static void zoomToSelection(BasicMapKit mapKit, IStructuredSelection selection) {
    BoundingBox bb = null;
    // determine bounding box for each reference and accumulate it
    for (AbstractInstancePainter painter : mapKit.getTilePainters(AbstractInstancePainter.class)) {
        for (Object element : selection.toList()) {
            InstanceReference ref = getReference(element);
            if (ref != null) {
                InstanceWaypoint wp = painter.findWaypoint(ref);
                if (wp != null) {
                    BoundingBox wpBB = wp.getBoundingBox();
                    if (wpBB.checkIntegrity() && !wpBB.isEmpty()) {
                        if (bb == null) {
                            bb = new BoundingBox(wpBB);
                        } else {
                            bb.add(wpBB);
                        }
                    }
                }
            }
        }
    }
    if (bb != null) {
        Set<GeoPosition> positions = new HashSet<GeoPosition>();
        positions.add(new GeoPosition(bb.getMinX(), bb.getMinY(), SelectableWaypoint.COMMON_EPSG));
        positions.add(new GeoPosition(bb.getMaxX(), bb.getMaxY(), SelectableWaypoint.COMMON_EPSG));
        mapKit.zoomToPositions(positions);
    }
}
Also used : InstanceWaypoint(eu.esdihumboldt.hale.ui.views.styledmap.painter.InstanceWaypoint) AbstractInstancePainter(eu.esdihumboldt.hale.ui.views.styledmap.painter.AbstractInstancePainter) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) BoundingBox(de.fhg.igd.geom.BoundingBox) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) HashSet(java.util.HashSet)

Example 2 with InstanceWaypoint

use of eu.esdihumboldt.hale.ui.views.styledmap.painter.InstanceWaypoint in project hale by halestudio.

the class InstanceMapTip method getTipText.

/**
 * @see de.fhg.igd.mapviewer.tip.HoverMapTip#getTipText(int, int,
 *      org.jdesktop.swingx.mapviewer.PixelConverter, int)
 */
@Override
protected String getTipText(int x, int y, PixelConverter converter, int zoom) {
    Point point = new Point(x, y);
    String sourceName = null;
    List<SourceInstancePainter> sourcePainters = mapKit.getTilePainters(SourceInstancePainter.class);
    if (!sourcePainters.isEmpty()) {
        InstanceWaypoint wp = sourcePainters.get(0).findWaypoint(point);
        if (wp != null) {
            sourceName = wp.getName();
        }
    }
    String transformedName = null;
    List<TransformedInstancePainter> transformedPainters = mapKit.getTilePainters(TransformedInstancePainter.class);
    if (!transformedPainters.isEmpty()) {
        InstanceWaypoint wp = transformedPainters.get(0).findWaypoint(point);
        if (wp != null) {
            transformedName = wp.getName();
        }
    }
    if (sourceName != null && sourceName.equals(transformedName)) {
        // if both are equal, return one name only
        return sourceName;
    }
    if (sourceName != null) {
        sourceName += " (source)";
    }
    if (transformedName != null) {
        transformedName += " (transformed)";
    }
    if (sourceName != null && transformedName != null) {
        return sourceName + "; " + transformedName;
    } else if (sourceName != null) {
        return sourceName;
    } else if (transformedName != null) {
        return transformedName;
    }
    return null;
}
Also used : InstanceWaypoint(eu.esdihumboldt.hale.ui.views.styledmap.painter.InstanceWaypoint) Point(java.awt.Point) SourceInstancePainter(eu.esdihumboldt.hale.ui.views.styledmap.painter.SourceInstancePainter) TransformedInstancePainter(eu.esdihumboldt.hale.ui.views.styledmap.painter.TransformedInstancePainter)

Aggregations

InstanceWaypoint (eu.esdihumboldt.hale.ui.views.styledmap.painter.InstanceWaypoint)2 BoundingBox (de.fhg.igd.geom.BoundingBox)1 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)1 AbstractInstancePainter (eu.esdihumboldt.hale.ui.views.styledmap.painter.AbstractInstancePainter)1 SourceInstancePainter (eu.esdihumboldt.hale.ui.views.styledmap.painter.SourceInstancePainter)1 TransformedInstancePainter (eu.esdihumboldt.hale.ui.views.styledmap.painter.TransformedInstancePainter)1 Point (java.awt.Point)1 HashSet (java.util.HashSet)1 GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)1