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();
}
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();
}
}
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());
}
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());
}
}
}
}
}
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());
}
});
}
Aggregations