Search in sources :

Example 16 with GeoLocation

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

the class GeoMap method performOk.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
	 */
@Override
public boolean performOk() {
    try {
        GeoLocation center = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
        config.setLatitude(center.getLatitude());
        config.setLongitude(center.getLongitude());
    } catch (GeoLocationFormatException e) {
        MessageDialogHelper.openError(getShell(), Messages.get().GeoMap_Error, Messages.get().GeoMap_ErrorText);
    }
    config.setTitle(title.getText());
    config.setZoom(zoom.getSelection());
    config.setRootObjectId(objectSelector.getObjectId());
    return true;
}
Also used : GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation)

Example 17 with GeoLocation

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

the class MapBackground method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    final IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
    // $NON-NLS-1$
    disableGeolocationBackground = ps.getBoolean("DISABLE_GEOLOCATION_BACKGROUND");
    object = (NetworkMap) getElement().getAdapter(NetworkMap.class);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 1;
    dialogArea.setLayout(layout);
    Group typeGroup = new Group(dialogArea, SWT.NONE);
    typeGroup.setText(Messages.get().MapBackground_BkgndType);
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    typeGroup.setLayoutData(gd);
    layout = new GridLayout();
    typeGroup.setLayout(layout);
    final SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            enableControls(radioTypeImage.getSelection(), disableGeolocationBackground ? false : radioTypeGeoMap.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    };
    radioTypeNone = new Button(typeGroup, SWT.RADIO);
    radioTypeNone.setText(Messages.get().MapBackground_None);
    radioTypeNone.setSelection(object.getBackground().equals(NXCommon.EMPTY_GUID));
    radioTypeNone.addSelectionListener(listener);
    radioTypeImage = new Button(typeGroup, SWT.RADIO);
    radioTypeImage.setText(Messages.get().MapBackground_Image);
    radioTypeImage.setSelection(!object.getBackground().equals(NXCommon.EMPTY_GUID) && !object.getBackground().equals(NetworkMap.GEOMAP_BACKGROUND));
    radioTypeImage.addSelectionListener(listener);
    if (!disableGeolocationBackground) {
        radioTypeGeoMap = new Button(typeGroup, SWT.RADIO);
        radioTypeGeoMap.setText(Messages.get().MapBackground_GeoMap);
        radioTypeGeoMap.setSelection(object.getBackground().equals(NetworkMap.GEOMAP_BACKGROUND));
        radioTypeGeoMap.addSelectionListener(listener);
    } else {
        if (object.getBackground().equals(NetworkMap.GEOMAP_BACKGROUND))
            radioTypeNone.setSelection(true);
    }
    image = new ImageSelector(dialogArea, SWT.NONE);
    image.setLabel(Messages.get().MapBackground_BkgndImage);
    if (radioTypeImage.getSelection())
        image.setImageGuid(object.getBackground(), true);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    image.setLayoutData(gd);
    if (!disableGeolocationBackground) {
        Group geomapGroup = new Group(dialogArea, SWT.NONE);
        geomapGroup.setText(Messages.get().MapBackground_GroupGeoMap);
        gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        geomapGroup.setLayoutData(gd);
        layout = new GridLayout();
        geomapGroup.setLayout(layout);
        GeoLocation gl = object.getBackgroundLocation();
        latitude = new LabeledText(geomapGroup, SWT.NONE);
        latitude.setLabel(Messages.get().MapBackground_Lat);
        latitude.setText(gl.getLatitudeAsString());
        gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        latitude.setLayoutData(gd);
        longitude = new LabeledText(geomapGroup, SWT.NONE);
        longitude.setLabel(Messages.get().MapBackground_Lon);
        longitude.setText(gl.getLongitudeAsString());
        gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        longitude.setLayoutData(gd);
        Composite zoomGroup = new Composite(geomapGroup, SWT.NONE);
        layout = new GridLayout();
        layout.numColumns = 2;
        layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.marginTop = WidgetHelper.OUTER_SPACING;
        zoomGroup.setLayout(layout);
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        zoomGroup.setLayoutData(gd);
        zoomLabel = new Label(zoomGroup, SWT.NONE);
        zoomLabel.setText(Messages.get().MapBackground_ZoomLevel);
        gd = new GridData();
        gd.horizontalAlignment = SWT.LEFT;
        gd.horizontalSpan = 2;
        zoomLabel.setLayoutData(gd);
        zoomScale = new Scale(zoomGroup, SWT.HORIZONTAL);
        zoomScale.setMinimum(1);
        zoomScale.setMaximum(18);
        zoomScale.setSelection(object.getBackgroundZoom());
        gd = new GridData();
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessHorizontalSpace = true;
        zoomScale.setLayoutData(gd);
        zoomScale.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                zoomSpinner.setSelection(zoomScale.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        zoomSpinner = new Spinner(zoomGroup, SWT.BORDER);
        zoomSpinner.setMinimum(1);
        zoomSpinner.setMaximum(18);
        zoomSpinner.setSelection(object.getBackgroundZoom());
        zoomSpinner.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                zoomScale.setSelection(zoomSpinner.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
    }
    Composite colorArea = new Composite(dialogArea, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    colorArea.setLayout(layout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    colorArea.setLayoutData(gd);
    Label label = new Label(colorArea, SWT.NONE);
    label.setText(Messages.get().MapBackground_BkgndColor);
    backgroundColor = new ColorSelector(colorArea);
    backgroundColor.setColorValue(ColorConverter.rgbFromInt(object.getBackgroundColor()));
    enableControls(radioTypeImage.getSelection(), disableGeolocationBackground ? false : radioTypeGeoMap.getSelection());
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) Scale(org.eclipse.swt.widgets.Scale) ImageSelector(org.netxms.ui.eclipse.imagelibrary.widgets.ImageSelector) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GeoLocation(org.netxms.base.GeoLocation) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ColorSelector(org.eclipse.jface.preference.ColorSelector) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 18 with GeoLocation

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

the class MapLoader method getAllTiles.

/**
 * @param mapSize
 * @param basePoint
 * @param zoom
 * @param cachedOnly if true, only locally cached tiles will be returned (missing tiles will be replaced by placeholder image)
 * @return
 */
public TileSet getAllTiles(Point mapSize, GeoLocation basePoint, int pointLocation, int zoom, boolean cachedOnly) {
    if ((mapSize.x < 32) || (mapSize.y < 32) || (basePoint == null))
        return null;
    Area coverage = GeoLocationCache.calculateCoverage(mapSize, basePoint, pointLocation, zoom);
    Point bottomLeft = tileFromLocation(coverage.getxLow(), coverage.getyLow(), zoom);
    Point topRight = tileFromLocation(coverage.getxHigh(), coverage.getyHigh(), zoom);
    Tile[][] tiles = new Tile[bottomLeft.y - topRight.y + 1][topRight.x - bottomLeft.x + 1];
    int x = bottomLeft.x;
    int y = topRight.y;
    int l = (bottomLeft.y - topRight.y + 1) * (topRight.x - bottomLeft.x + 1);
    for (int i = 0; i < l; i++) {
        tiles[y - topRight.y][x - bottomLeft.x] = getTile(zoom, x, y, cachedOnly);
        x++;
        if (x > topRight.x) {
            x = bottomLeft.x;
            y++;
        }
    }
    double lat = latitudeFromTile(topRight.y, zoom);
    double lon = longitudeFromTile(bottomLeft.x, zoom);
    Point realTopLeft = GeoLocationCache.coordinateToDisplay(new GeoLocation(lat, lon), zoom);
    Point reqTopLeft = GeoLocationCache.coordinateToDisplay(new GeoLocation(coverage.getxHigh(), coverage.getyLow()), zoom);
    return new TileSet(tiles, realTopLeft.x - reqTopLeft.x, realTopLeft.y - reqTopLeft.y, zoom);
}
Also used : Point(org.eclipse.swt.graphics.Point) GeoLocation(org.netxms.base.GeoLocation) Point(org.eclipse.swt.graphics.Point)

Example 19 with GeoLocation

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

the class AbstractGeolocationView 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 = createMapViewer(parent, SWT.BORDER);
    map.setViewPart(this);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    activateContext();
    // 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) {
            AbstractGeolocationView.this.zoomLevel = zoomLevel;
            mapAccessor.setZoom(zoomLevel);
            actionZoomIn.setEnabled(zoomLevel < MapAccessor.MAX_MAP_ZOOM);
            actionZoomOut.setEnabled(zoomLevel > MapAccessor.MIN_MAP_ZOOM);
        }

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

Example 20 with GeoLocation

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

the class AbstractGeoMapViewer method mouseDoubleClick.

/* (non-Javadoc)
	 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
	 */
@Override
public void mouseDoubleClick(MouseEvent e) {
    int zoom = accessor.getZoom();
    if (zoom < MapAccessor.MAX_MAP_ZOOM) {
        int step = ((e.stateMask & SWT.SHIFT) != 0) ? 4 : 1;
        zoom = (zoom + step > MapAccessor.MAX_MAP_ZOOM) ? MapAccessor.MAX_MAP_ZOOM : zoom + step;
        final GeoLocation geoLocation = getLocationAtPoint(new Point(e.x, e.y));
        accessor.setZoom(zoom);
        accessor.setLatitude(geoLocation.getLatitude());
        accessor.setLongitude(geoLocation.getLongitude());
        reloadMap();
        notifyOnZoomChange();
        notifyOnPositionChange();
    }
}
Also used : GeoLocation(org.netxms.base.GeoLocation) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

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