Skip to content

GeoPositionFigure

roosit edited this page Oct 16, 2026 · 4 revisions

GeoPositionFigure

Up | Previous | Next | Русский

Full source with short explanations

Below is the full source of the class in documentation form. The comments inside the block explain the purpose of the parts of the class, but they are not stored in the working file GeoPositionFigure.java: the production code stays clean, and the explanations live in the wiki.

package com.velitask.plugin.official.geo;

import com.velitask.plugin.official.GeoMapIndicator;
import com.velitask.sdk.IndicatorContext;
import com.velitask.sdk.data.GeoSensorAtom;
import com.velitask.sdk.figures.Figure;
import com.velitask.sdk.properties.ColorProperty;
import com.velitask.sdk.properties.DisplayConfig;
import com.velitask.sdk.properties.DisplayHint;
import com.velitask.sdk.properties.GeoSensorProperty;
import com.velitask.sdk.properties.IProperty;
import com.velitask.sdk.properties.PropertyGroup;
import com.velitask.sdk.properties.SizeProperty;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;

/* The "Position marker" figure: a dot at the current position. */
public class GeoPositionFigure extends Figure<GeoFigureContext> {

    /* Figure name (the type field in the figure JSON). */
    public static final String NAME = "position";

    /* Prefix of the localization keys. */
    private static final String KEY = GeoMapIndicator.KEY + "." + NAME;

    /* Geo sensor of the figure; the current point is taken from it. */
    private final GeoSensorProperty mGeoSensor = new GeoSensorProperty();

    /* Name of the fill property. */
    private static final String FILL_COLOR = "fillColor";
    /* Marker fill, blue (0, 0, 200) by default. */
    private final ColorProperty mFillColor = new ColorProperty(
            new Color(0, 0, 200),
            FILL_COLOR,
            localized(KEY + "." + FILL_COLOR + ".title")
    );

    /* Name of the stroke property. */
    private static final String BORDER_COLOR = "borderColor";
    /* Marker stroke, white by default. */
    private final ColorProperty mBorderColor = new ColorProperty(
            Color.WHITE,
            BORDER_COLOR,
            localized(KEY + "." + BORDER_COLOR + ".title")
    );

    /* Marker diameter in pixels: 4..100, 30 by default. */
    private final SizeProperty mSize = new SizeProperty() {
        {
            setRange(4, 100);
        }

        @Override
        public Integer getDefault() {
            return 30;
        }
    };

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getTitle() {
        return localized(KEY + ".title");
    }

    @Override
    /* Geo, fillColor, borderColor, size are saved. */
    public IProperty[] defineProperties() {
        return new IProperty[]{mGeoSensor, mFillColor, mBorderColor, mSize};
    }

    @Override
    /* The size is shown as a counter with arrows. */
    public void configureDisplay(DisplayConfig config) {
        config.set(mFillColor, PropertyGroup.APPEARANCE);
        config.set(mBorderColor, PropertyGroup.APPEARANCE);
        config.set(mSize, PropertyGroup.APPEARANCE, DisplayHint.SPINNER);
    }

    @Override
    /* Takes the current point, converts it to screen coordinates and draws a circle with a stroke. */
    public void render(GeoFigureContext baseCtx) {
        PositionContext ctx = (PositionContext) baseCtx;
        if (ctx.zoom == null || ctx.position.sensorId == 0) {
            return;
        }

        GeoSensorAtom atom = ctx.position.queryAtom();
        if (atom == null) {
            return;
        }

        Point2D.Double pt = ctx.toScreen(atom.lat, atom.lon);
        int cx = (int) pt.x;
        int cy = (int) pt.y;

        /* The diameter is multiplied by the layer scale; the stroke is 2 wide, taking the scale into account. */
        int size = Math.max(1, (int) Math.round(ctx.size * ctx.scale));
        int x = cx - size / 2;
        int y = cy - size / 2;

        Graphics2D g = ctx.graphics;
        g.setColor(ctx.fill);
        g.fillOval(x, y, size, size);

        g.setColor(ctx.border);
        g.setStroke(new BasicStroke((float) Math.max(1, 2 * ctx.scale)));
        g.drawOval(x, y, size, size);
    }

    @Override
    /* Creation of the context from the indicator context. */
    public GeoFigureContext createContext(IndicatorContext indCtx) {
        PositionContext ctx = new PositionContext((GeoMapIndicator.GeoMapContext) indCtx);
        return ctx;
    }

    /* Figure context: property values for the frame. */
    public class PositionContext extends GeoFigureContext {

        public final GeoSensorProperty.GeoSensorContext position;
        public final Color fill;
        public final Color border;
        public final int size;

        public PositionContext(GeoMapIndicator.GeoMapContext indCtx) {
            super(indCtx);
            position = mGeoSensor.createContext(indCtx);
            fill = mFillColor.get(indCtx);
            border = mBorderColor.get(indCtx);
            size = mSize.get(indCtx);
        }
    }

}

Purpose

GeoPositionFigure draws a round marker of the current position on the map: a filled dot with a stroke. Together with GeoTrackFigure it is part of the default figure set of GeoMapIndicator. If the map center follows the carrier, the marker stands in the center of the frame (or in the bottom third, if that position is selected).

How it works

Data. From GeoSensorProperty, ctx.position.queryAtom() reads the GeoSensorAtom of the current moment. If the zoom of the indicator is null, sensorId == 0, or there is no atom, the figure draws nothing. Latitude and longitude are taken directly from atom.lat and atom.lon.

Settings. Four properties in the figure JSON: Geo, fillColor (blue (0, 0, 200)), borderColor (white) and size (SizeProperty, range 4..100, 30 by default). The colors are read as mFillColor.get(indCtx), the size as mSize.get(indCtx).

Drawing. toScreen(atom.lat, atom.lon) (GeoFigureContext) gives the center of the marker. The diameter equals size × scale (at least 1 pixel). First fillOval paints the circle, then drawOval draws the stroke with a thickness of max(1, 2 × scale).

Features and limitations

  • The marker is always a circle; the rotation of the map does not affect it, and it does not show the direction of movement.
  • The coordinates are taken from the atom without interpolation by rawTime, whereas the map center in GeoMapIndicator is calculated from calcLat / calcLon. If the track points are sparse, the marker may lag slightly behind the map center between points.
  • The marker is not clipped by the rounded corners of the map frame: it is drawn after the indicator, on top of the frame.
  • The Geo property is not declared in configureDisplay(), so it does not appear as a separate row in the list of figure settings.

Clone this wiki locally