Search in sources :

Example 21 with GeoLocation

use of org.netxms.base.GeoLocation in project netxms by netxms.

the class AbstractGeoMapViewer method reloadMap.

/**
 * Reload current map
 */
public void reloadMap() {
    Rectangle rect = this.getClientArea();
    accessor.setMapWidth(rect.width);
    accessor.setMapHeight(rect.height);
    if (!accessor.isValid())
        return;
    final Point mapSize = new Point(accessor.getMapWidth(), accessor.getMapHeight());
    final GeoLocation centerPoint = accessor.getCenterPoint();
    ConsoleJob job = new ConsoleJob(Messages.get().GeoMapViewer_DownloadJob_Title, viewPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final TileSet tiles = mapLoader.getAllTiles(mapSize, centerPoint, MapLoader.CENTER, accessor.getZoom(), true);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (isDisposed())
                        return;
                    if (currentTileSet != null)
                        currentTileSet.dispose();
                    currentTileSet = tiles;
                    if ((tiles != null) && (tiles.missingTiles > 0))
                        loadMissingTiles(tiles);
                    Rectangle clientArea = getClientArea();
                    Point mapSize = new Point(clientArea.width, clientArea.height);
                    coverage = GeoLocationCache.calculateCoverage(mapSize, accessor.getCenterPoint(), GeoLocationCache.CENTER, accessor.getZoom());
                    onMapLoad();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().GeoMapViewer_DownloadError;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GeoLocation(org.netxms.base.GeoLocation) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TileSet(org.netxms.ui.eclipse.osm.tools.TileSet)

Example 22 with GeoLocation

use of org.netxms.base.GeoLocation in project netxms by netxms.

the class ObjectGeoLocationViewer method onCacheChange.

/* (non-Javadoc)
    * @see org.netxms.ui.eclipse.osm.widgets.AbstractGeoMapViewer#onCacheChange(org.netxms.client.objects.AbstractObject, org.netxms.base.GeoLocation)
    */
@Override
protected void onCacheChange(AbstractObject object, GeoLocation prevLocation) {
    GeoLocation currLocation = object.getGeolocation();
    if (((currLocation.getType() != GeoLocation.UNSET) && coverage.contains(currLocation.getLatitude(), currLocation.getLongitude())) || ((prevLocation != null) && (prevLocation.getType() != GeoLocation.UNSET) && coverage.contains(prevLocation.getLatitude(), prevLocation.getLongitude()))) {
        objects = GeoLocationCache.getInstance().getObjectsInArea(coverage, rootObjectId, filterString);
        redraw();
    }
}
Also used : GeoLocation(org.netxms.base.GeoLocation)

Example 23 with GeoLocation

use of org.netxms.base.GeoLocation 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)

Example 24 with GeoLocation

use of org.netxms.base.GeoLocation in project netxms by netxms.

the class GeoLocationCache method internalInitialize.

/**
 * (Re)initialize location cache - actual initialization
 */
private void internalInitialize() {
    synchronized (locationTree) {
        locationTree.removeAll();
        objects.clear();
        for (AbstractObject object : session.getAllObjects()) {
            if ((object.getObjectClass() == AbstractObject.OBJECT_NODE) || (object.getObjectClass() == AbstractObject.OBJECT_MOBILEDEVICE) || (object.getObjectClass() == AbstractObject.OBJECT_CLUSTER) || (object.getObjectClass() == AbstractObject.OBJECT_CONTAINER) || (object.getObjectClass() == AbstractObject.OBJECT_RACK) || (object.getObjectClass() == AbstractObject.OBJECT_SENSOR)) {
                GeoLocation gl = object.getGeolocation();
                if (gl.getType() != GeoLocation.UNSET) {
                    objects.put(object.getObjectId(), object);
                    locationTree.insert(gl.getLatitude(), gl.getLongitude(), object.getObjectId());
                }
            }
        }
    }
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) GeoLocation(org.netxms.base.GeoLocation)

Example 25 with GeoLocation

use of org.netxms.base.GeoLocation in project netxms by netxms.

the class HistoryView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    // Map control
    map = new GeoLocationHistoryViewer(parent, SWT.BORDER, object);
    map.setViewPart(this);
    createActions(parent);
    contributeToActionBars();
    createPopupMenu();
    // Initial map view
    mapAccessor = new MapAccessor(getInitialCenterPoint());
    zoomLevel = getInitialZoomLevel();
    mapAccessor.setZoom(zoomLevel);
    map.showMap(mapAccessor);
    map.addMapListener(new GeoMapListener() {

        @Override
        public void onZoom(int zoomLevel) {
            HistoryView.this.zoomLevel = zoomLevel;
            mapAccessor.setZoom(zoomLevel);
            actionZoomIn.setEnabled(zoomLevel < 18);
            actionZoomOut.setEnabled(zoomLevel > 0);
        }

        @Override
        public void onPan(GeoLocation centerPoint) {
            mapAccessor.setLatitude(centerPoint.getLatitude());
            mapAccessor.setLongitude(centerPoint.getLongitude());
        }
    });
}
Also used : MapAccessor(org.netxms.ui.eclipse.osm.tools.MapAccessor) GeoLocation(org.netxms.base.GeoLocation) GeoLocationHistoryViewer(org.netxms.ui.eclipse.osm.widgets.GeoLocationHistoryViewer) GeoMapListener(org.netxms.ui.eclipse.osm.widgets.helpers.GeoMapListener)

Aggregations

GeoLocation (org.netxms.base.GeoLocation)26 Point (org.eclipse.swt.graphics.Point)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 GeoLocationFormatException (org.netxms.base.GeoLocationFormatException)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 NXCSession (org.netxms.client.NXCSession)3 Area (org.netxms.ui.eclipse.osm.tools.Area)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Group (org.eclipse.swt.widgets.Group)2 NXCPMessage (org.netxms.base.NXCPMessage)2 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 Node (org.netxms.client.objects.Node)2