Skip to content

GeoPreviewGenerator

roosit edited this page Nov 15, 2026 · 1 revision

GeoPreviewGenerator

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 GeoPreviewGenerator.java: the production code stays clean and the explanations live in the wiki.

package com.velitask.plugin.official.previews;

import com.velitask.plugin.official.GeoMapIndicator;
import com.velitask.plugin.official.VelitaskPlagin;
import com.velitask.sdk.ISource;
import com.velitask.sdk.SourceType;
import com.velitask.sdk.preview.PreviewGenerator;
import com.velitask.sdk.preview.PreviewRequest;
import com.velitask.sdk.preview.PreviewTemplate;

/* Track preview generator: a "Map" indicator layer with the track fitted into the frame. */
public final class GeoPreviewGenerator extends PreviewGenerator {

    @Override
    /* Generator name, unique within the plugin. */
    public String getName() {
        return "geo";
    }

    @Override
    /* Cheap check by source type: a GPX/FIT/TCX track or a TMG recording. */
    public boolean supports(ISource source) {
        return source.getType() == SourceType.GPX || source.getType() == SourceType.TELEMIGER;
    }

    @Override
    /* Map layer over the whole frame; fitTrack = true fits the whole track into the frame. */
    public PreviewTemplate generate(PreviewRequest request) {
        PreviewTemplate template = PreviewTemplate.create();
        template.layer(VelitaskPlagin.UID + "." + GeoMapIndicator.NAME).fill().value("fitTrack", true);
        return template;
    }

    @Override
    /* Baseline solution: another plugin can replace it with its own preview. */
    public boolean isBaseline() {
        return true;
    }
}

Purpose

Preview generator for geodata. For track sources it builds a thumbnail from a single layer of the "Map" indicator with the "Fit track" property turned on: the frame shows the whole route, not the surroundings of the current position.

How it works

Data. The generator does not read the source data. The supports(...) condition looks only at the type: SourceType.GPX (this type is reported by GPX, FIT and TCX files) or SourceType.TELEMIGER (TMG recordings). The check is cheap, as the PreviewGenerator contract requires.

Settings. The generator has no settings of its own, only the name "geo". The generate(...) method does not use the PreviewRequest. One value is passed to the layer: the indicator property fitTrack ("Fit track") equals true; the other map properties are not set.

Drawing. generate(...) creates a PreviewTemplate, adds the layer VelitaskPlagin.UID + "." + GeoMapIndicator.NAME, calls fill() (the layer takes the whole frame) and value("fitTrack", true). The map itself (OSM tiles, track) is drawn by the "Map" indicator when the preview is rendered.

The generator is registered in VelitaskPlagin.definePreviewGenerators() last: video, image, audio, geo. The application polls the generators of all plugins by the priority getPriority() (here the default value) and draws the first non-empty template.

Features and limitations

  • isBaseline() returns true: other plugins can replace this preview with their own.
  • generate(...) never returns null, so when a source is supported, the chain of generators goes no further.
  • GoPro and DJI sources with geotelemetry inside a video have the type VIDEO and get the VideoPreviewGenerator preview, not a map.
  • The property name fitTrack is passed as a string: if it changes in the SDK, the preview will stop fitting the track, and the compiler will not notice.
  • The class is final and public; no constructor is declared.

Clone this wiki locally