Search in sources :

Example 1 with Area

use of org.netxms.ui.eclipse.osm.tools.Area in project netxms by netxms.

the class GeoLocationHistoryViewer method getAdjacentLocations.

/**
 * Get geolocations adjacent to given screen coordinates ordered by distance from that point
 *
 * @param x
 * @param y
 * @return
 */
public List<GeoLocation> getAdjacentLocations(int x, int y) {
    Point p = new Point(x, y);
    final GeoLocation center = getLocationAtPoint(p);
    p.x -= 5;
    p.y -= 5;
    GeoLocation topLeft = getLocationAtPoint(p);
    p.x += 10;
    p.y += 10;
    GeoLocation bottomRight = getLocationAtPoint(p);
    Area area = new Area(topLeft.getLatitude(), topLeft.getLongitude(), bottomRight.getLatitude(), bottomRight.getLongitude());
    List<GeoLocation> locations = locationTree.query(area);
    Collections.sort(locations, new Comparator<GeoLocation>() {

        @Override
        public int compare(GeoLocation l1, GeoLocation l2) {
            double d1 = Math.pow(Math.pow(l1.getLatitude() - center.getLatitude(), 2) + Math.pow(l1.getLongitude() - center.getLongitude(), 2), 0.5);
            double d2 = Math.pow(Math.pow(l2.getLatitude() - center.getLatitude(), 2) + Math.pow(l2.getLongitude() - center.getLongitude(), 2), 0.5);
            return (int) Math.signum(d1 - d2);
        }
    });
    return locations;
}
Also used : Area(org.netxms.ui.eclipse.osm.tools.Area) Point(org.eclipse.swt.graphics.Point) GeoLocation(org.netxms.base.GeoLocation)

Example 2 with Area

use of org.netxms.ui.eclipse.osm.tools.Area in project netxms by netxms.

the class AbstractGeoMapViewer method mouseUp.

/* (non-Javadoc)
	 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
	 */
@Override
public void mouseUp(MouseEvent e) {
    if ((e.button == 1) && (dragStartPoint != null)) {
        if (Math.abs(offsetX) > DRAG_JITTER || Math.abs(offsetY) > DRAG_JITTER) {
            final Point centerXY = GeoLocationCache.coordinateToDisplay(accessor.getCenterPoint(), accessor.getZoom());
            centerXY.x += offsetX;
            centerXY.y += offsetY;
            final GeoLocation geoLocation = GeoLocationCache.displayToCoordinates(centerXY, accessor.getZoom());
            accessor.setLatitude(geoLocation.getLatitude());
            accessor.setLongitude(geoLocation.getLongitude());
            reloadMap();
            notifyOnPositionChange();
        }
        offsetX = 0;
        offsetY = 0;
        dragStartPoint = null;
        setCursor(null);
    }
    if ((e.button == 1) && (selectionStartPoint != null)) {
        if (selectionEndPoint != null) {
            int x1 = Math.min(selectionStartPoint.x, selectionEndPoint.x);
            int x2 = Math.max(selectionStartPoint.x, selectionEndPoint.x);
            int y1 = Math.min(selectionStartPoint.y, selectionEndPoint.y);
            int y2 = Math.max(selectionStartPoint.y, selectionEndPoint.y);
            final GeoLocation l1 = getLocationAtPoint(new Point(x1, y1));
            final GeoLocation l2 = getLocationAtPoint(new Point(x2, y2));
            final GeoLocation lc = getLocationAtPoint(new Point(x2 - (x2 - x1) / 2, y2 - (y2 - y1) / 2));
            int zoom = accessor.getZoom();
            while (zoom < MapAccessor.MAX_MAP_ZOOM) {
                zoom++;
                final Area area = GeoLocationCache.calculateCoverage(getSize(), lc, GeoLocationCache.CENTER, zoom);
                if (!area.contains(l1.getLatitude(), l1.getLongitude()) || !area.contains(l2.getLatitude(), l2.getLongitude())) {
                    zoom--;
                    break;
                }
            }
            if (zoom != accessor.getZoom()) {
                accessor.setZoom(zoom);
                accessor.setLatitude(lc.getLatitude());
                accessor.setLongitude(lc.getLongitude());
                reloadMap();
                notifyOnPositionChange();
                notifyOnZoomChange();
            }
        }
        selectionStartPoint = null;
        selectionEndPoint = null;
        redraw();
    }
}
Also used : Area(org.netxms.ui.eclipse.osm.tools.Area) Point(org.eclipse.swt.graphics.Point) GeoLocation(org.netxms.base.GeoLocation) Point(org.eclipse.swt.graphics.Point)

Example 3 with Area

use of org.netxms.ui.eclipse.osm.tools.Area in project netxms by netxms.

the class GeoLocationCache method calculateCoverage.

/**
 * Calculate map coverage.
 *
 * @param mapSize map size in pixels
 * @param point coordinates of map's base point
 * @param pointLocation location of base point: TOP-LEFT, BOTTOM-RIGHT, CENTER
 * @param zoom zoom level
 * @return area covered by map
 */
public static Area calculateCoverage(Point mapSize, GeoLocation basePoint, int pointLocation, int zoom) {
    Point bp = coordinateToDisplay(basePoint, zoom);
    GeoLocation topLeft = null;
    GeoLocation bottomRight = null;
    switch(pointLocation) {
        case CENTER:
            topLeft = displayToCoordinates(new Point(bp.x - mapSize.x / 2, bp.y - mapSize.y / 2), zoom);
            bottomRight = displayToCoordinates(new Point(bp.x + mapSize.x / 2, bp.y + mapSize.y / 2), zoom);
            break;
        case TOP_LEFT:
            topLeft = displayToCoordinates(new Point(bp.x, bp.y), zoom);
            bottomRight = displayToCoordinates(new Point(bp.x + mapSize.x, bp.y + mapSize.y), zoom);
            break;
        case BOTTOM_RIGHT:
            topLeft = displayToCoordinates(new Point(bp.x - mapSize.x, bp.y - mapSize.y), zoom);
            bottomRight = displayToCoordinates(new Point(bp.x, bp.y), zoom);
            break;
        default:
            // $NON-NLS-1$
            throw new IllegalArgumentException("pointLocation=" + pointLocation);
    }
    return new Area(topLeft.getLatitude(), topLeft.getLongitude(), bottomRight.getLatitude(), bottomRight.getLongitude());
}
Also used : Area(org.netxms.ui.eclipse.osm.tools.Area) Point(org.eclipse.swt.graphics.Point) GeoLocation(org.netxms.base.GeoLocation)

Aggregations

Point (org.eclipse.swt.graphics.Point)3 GeoLocation (org.netxms.base.GeoLocation)3 Area (org.netxms.ui.eclipse.osm.tools.Area)3