use of org.netxms.base.GeoLocation in project netxms by netxms.
the class WorldMap method createPartControl.
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.osm.views.AbstractGeolocationView#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
IDialogSettings settings = Activator.getDefault().getDialogSettings();
initialZoom = settings.get(ID + "zoom") != null ? settings.getInt(ID + "zoom") : 2;
if (settings.get(ID + "latitude") != null && settings.get(ID + "longitude") != null)
initialLocation = new GeoLocation(settings.getDouble(ID + "latitude"), settings.getDouble(ID + "longitude"));
filterEnabled = settings.get(ID + "filterEnabled") != null ? settings.getBoolean(ID + "filterEnabled") : true;
super.createPartControl(parent);
parent.setLayout(new FormLayout());
// Create filter area
filterControl = new FilterText(parent, SWT.NONE);
filterControl.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterControl.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterControl);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
map.setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterControl.setLayoutData(fd);
// Set initial focus to filter input line
if (filterEnabled)
filterControl.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
}
use of org.netxms.base.GeoLocation 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;
}
use of org.netxms.base.GeoLocation in project netxms by netxms.
the class GeoLocationHistoryViewer method updateHistory.
/**
* Updates points for historical view
*/
private void updateHistory() {
final NXCSession session = ConsoleSharedData.getSession();
ConsoleJob job = new ConsoleJob(Messages.get().GeoMapViewer_DownloadJob_Title, viewPart, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<GeoLocation> pl = session.getLocationHistory(historyObject.getObjectId(), timePeriod.getPeriodStart(), timePeriod.getPeriodEnd());
runInUIThread(new Runnable() {
@Override
public void run() {
points = pl;
locationTree.removeAll();
for (int i = 0; i < points.size(); i++) locationTree.insert(points.get(i).getLatitude(), points.get(i).getLongitude(), points.get(i));
redraw();
}
});
}
@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 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();
}
}
use of org.netxms.base.GeoLocation in project netxms by netxms.
the class AbstractGeoMapViewer method paintControl.
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
*/
@Override
public void paintControl(PaintEvent e) {
final GC gc = e.gc;
gc.setAntialias(SWT.ON);
gc.setTextAntialias(SWT.ON);
if (currentTileSet != null)
drawTiles(gc, currentTileSet);
GeoLocation currentLocation;
// and map is not currently loading
if (dragStartPoint == null) {
currentLocation = accessor.getCenterPoint();
Rectangle rect = getClientArea();
drawContent(gc, currentLocation, rect.width, rect.height);
} else {
Point cp = GeoLocationCache.coordinateToDisplay(accessor.getCenterPoint(), accessor.getZoom());
cp.x += offsetX;
cp.y += offsetY;
currentLocation = GeoLocationCache.displayToCoordinates(cp, accessor.getZoom());
}
// Draw selection rectangle
if ((selectionStartPoint != null) && (selectionEndPoint != null)) {
int x = Math.min(selectionStartPoint.x, selectionEndPoint.x);
int y = Math.min(selectionStartPoint.y, selectionEndPoint.y);
int w = Math.abs(selectionStartPoint.x - selectionEndPoint.x);
int h = Math.abs(selectionStartPoint.y - selectionEndPoint.y);
gc.setBackground(SELECTION_COLOR);
gc.setForeground(SELECTION_COLOR);
gc.setAlpha(64);
gc.fillRectangle(x, y, w, h);
gc.setAlpha(255);
gc.setLineWidth(2);
gc.drawRectangle(x, y, w, h);
}
// Draw current location info
String text = currentLocation.toString();
Point textSize = gc.textExtent(text);
Rectangle rect = getClientArea();
rect.x = rect.width - textSize.x - 20;
rect.y += 10;
rect.width = textSize.x + 10;
rect.height = textSize.y + 8;
gc.setBackground(INFO_BLOCK_BACKGROUND);
gc.setAlpha(128);
gc.fillRoundRectangle(rect.x, rect.y, rect.width, rect.height, 8, 8);
gc.setAlpha(255);
gc.setForeground(INFO_BLOCK_TEXT);
gc.drawText(text, rect.x + 5, rect.y + 4, true);
// Draw title
if ((title != null) && !title.isEmpty()) {
gc.setFont(mapTitleFont);
rect = getClientArea();
int x = (rect.width - gc.textExtent(title).x) / 2;
gc.setForeground(SharedColors.getColor(SharedColors.GEOMAP_TITLE, getDisplay()));
gc.drawText(title, x, 10, true);
}
// Draw zoom control
gc.setFont(JFaceResources.getHeaderFont());
text = Integer.toString(accessor.getZoom());
textSize = gc.textExtent(text);
rect = getClientArea();
rect.x = 10;
rect.y = 10;
rect.width = 80;
rect.height = 47 + textSize.y;
gc.setBackground(INFO_BLOCK_BACKGROUND);
gc.setForeground(INFO_BLOCK_TEXT);
gc.setAlpha(128);
gc.fillRoundRectangle(rect.x, rect.y, rect.width, rect.height, 8, 8);
gc.setAlpha(255);
gc.drawText(text, rect.x + rect.width / 2 - textSize.x / 2, rect.y + 5, true);
gc.drawImage(imageZoomIn, rect.x + 5, rect.y + rect.height - 37);
gc.drawImage(imageZoomOut, rect.x + 42, rect.y + rect.height - 37);
zoomControlRect = rect;
}
Aggregations