Repository navigation
GeoPositionFigure
Up | Previous | Next | Русский
Below is the full source code of the class in documentation form. Comments inside the block explain the purpose of class parts, but they are not stored in the working file GeoPositionFigure.java: production code stays clean, and 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;
/*
* Figure for GeoMapIndicator: round "you are here" marker at the current geo position.
* Position is read from its own GeoSensorProperty (can be the same sensor as
* GeoMap's or another one).
*/
public class GeoPositionFigure extends Figure<GeoFigureContext> {
public static final String NAME = "position";
/* Base localization key in the GeoMap.position namespace. */
private static final String KEY = GeoMapIndicator.KEY + "." + NAME;
/* Own geo sensor for the marker (can differ from the map sensor). */
private final GeoSensorProperty mGeoSensor = new GeoSensorProperty();
/* Marker fill. Default is blue. */
private static final String FILL_COLOR = "fillColor";
private final ColorProperty mFillColor = new ColorProperty(
new Color(0, 0, 200), FILL_COLOR,
localized(KEY + "." + FILL_COLOR + ".title"));
/* Marker border color. */
private static final String BORDER_COLOR = "borderColor";
private final ColorProperty mBorderColor = new ColorProperty(
Color.WHITE, BORDER_COLOR,
localized(KEY + "." + BORDER_COLOR + ".title"));
/* Marker size in pixels, 4..100, default 30. */
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
public IProperty[] defineProperties() {
return new IProperty[]{mGeoSensor, mFillColor, mBorderColor, mSize};
}
@Override
public void configureDisplay(DisplayConfig config) {
config.set(mFillColor, PropertyGroup.APPEARANCE);
config.set(mBorderColor, PropertyGroup.APPEARANCE);
config.set(mSize, PropertyGroup.APPEARANCE, DisplayHint.SPINNER);
}
/*
* Render: requests the current geo atom, projects lat/lon into screen
* coordinates through GeoFigureContext, draws a filled circle + border.
*/
@Override
public void render(GeoFigureContext baseCtx) {
PositionContext ctx = (PositionContext) baseCtx;
/* Exit if the map is not initialized or the sensor is not bound. */
if (ctx.zoom == null || ctx.sensorId == 0) {
return;
}
/* Standard UTC → raw-time + preview clamp. */
long rawTime = mGeoSensor.convertToRawTime(ctx.indicator.player.time);
if (ctx.indicator.player.isPreview) {
rawTime = mGeoSensor.clampToSensorRange(rawTime);
}
GeoSensorAtom atom = mGeoSensor.queryAtom(rawTime);
if (atom == null) {
return;
}
/* lat/lon → screen pixel through the parent helper. */
int cx = ctx.toScreenX(atom.lon);
int cy = ctx.toScreenY(atom.lat);
/* Size accounting for canvas scale; min 1px protection. */
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);
/* Border with fixed thickness 2 (accounting for scale). */
g.setColor(ctx.border);
g.setStroke(new BasicStroke((float) Math.max(1, 2 * ctx.scale)));
g.drawOval(x, y, size, size);
}
@Override
public GeoFigureContext createContext(IndicatorContext indCtx) {
PositionContext ctx = new PositionContext((GeoMapIndicator.GeoMapContext) indCtx);
return ctx;
}
/* Context with snapshots of all properties at creation time. */
public class PositionContext extends GeoFigureContext {
public final long sensorId;
public final Color fill;
public final Color border;
public final int size;
public PositionContext(GeoMapIndicator.GeoMapContext indCtx) {
super(indCtx);
sensorId = mGeoSensor.getSensorId();
fill = mFillColor.createContext().value;
border = mBorderColor.createContext().value;
size = mSize.createContext().value;
}
}
}GeoPositionFigure is a figure for GeoMapIndicator that draws a round "you are here" marker at the current geo position on the map. Used as a real-time indication: the point moves along the map with playback.
Data. Own GeoSensorProperty (can match the map sensor or be another one — for example, main track on the map, marker from another recording). Requests a GeoSensorAtom at the current time with UTC→raw conversion and preview clamp.
Settings. Four properties: geo source, fill ColorProperty, border ColorProperty, SizeProperty (marker diameter, 4..100, default 30, rendered as SPINNER).
Drawing. lat/lon from the atom is projected through GeoFigureContext.toScreenX/Y → pixel center of the marker. fillOval for fill, drawOval for border with fixed thickness 2px (accounting for canvas scale). Marker is centered relative to (cx, cy).
- Own sensor independent of the map sensor — allows showing another point (for example, skaters on one map, each with their own marker).
- Without an atom → draws nothing. Marker disappears when player time is outside the sensor range.
-
Size in base pixels, scale is applied during render (
size * ctx.scale). This gives "honest" scaling when exporting to 4K, etc. -
Border
2 * scale— hardcoded. Not configurable; increase it if stronger contrast is needed.