A ShapeProvider allows you to map Feature from a single model into different geometric representations. It is used by a FeatureLayer.

A common use case is to visualize a model on both a geographic map and a cartesian chart.

For example, a ShapeProvider helps you display trajectories on a geodetic map in one layer, and display same trajectories on a vertical chart in another layer.

class TrajectoryShapeProvider extends ShapeProvider {
constructor() {
super();
this.reference = createCartesianReference({
xUnitOfMeasure: meterUnit,
yUnitOfMeasure: meterUnit
});
}

provideShape(trajectoryFeature: Feature) {
const shape = trajectoryFeature.shape as any as Polyline;
if (!shape || !shape.reference) {
return null;
}

// Creates a cartesian shape for the passed trajectory feature,
// where the x-coordinates represent the distance along the trajectory, and the y-coordinate represents the altitude of the aircraft at that point.
const geodesy = createEllipsoidalGeodesy(shape.reference);
const points: Point[] = [];

// for each of the points in the original trajectory calculate the distance from the first point using
// the geodesy instance. This gives us the x-coordinate of the resulting shape
// The height is directly available in the z-coordinate of the points of the original trajectory
let distance = 0;
let point0 = shape.getPoint(0);
points[0] = createPoint(this.reference, [0, point0.z]);

for (let i = 0; i < shape.pointCount; i++) {
const nextPoint = shape.getPoint(i);
distance += geodesy.distance(point0, nextPoint, LineType.SHORTEST_DISTANCE);
points.push(createPoint(this.reference, [distance, nextPoint.z]))
point0 = nextPoint;
}
return createPolyline(this.reference, points);
}
}

Example for a ShapeProvider that provides shapes asynchronously.

class AsyncShapeProvider extends ShapeProvider {
private readonly shapeCache: Map<string|number, Shape>
private readonly shapePromise: Map<string|number, Promise<Shape>>;
constructor() {
super();
this.shapeCache = new Map();
this.shapePromise = new Map();
}

provideShape(feature: Feature) {
const shape = this.shapeCache.get(feature.id);
if (shape) {
// Shape was already resolved
return shape;
}

if (!this.shapePromise.get(feature.id)) {
// Invoke a function that provides shapes asynchronously
const promiseForShape = getAsyncShape(feature);
this.shapePromise.set(feature.id, promiseForShape);

// When the promise is resolved cache the shape and invalidate itself
promiseForShape.then((shape) => {
this.shapeCache.set(feature.id, shape);
this.shapePromise.delete(feature.id);
// Invalidate self to provide the resolved shape
this.invalidateById(feature.id);
});
}

// The feature will not be drawn till its shape is resolved
return null;
};
}

Hierarchy

  • ShapeProvider

Implements

Constructors

Accessors

  • get reference(): null | CoordinateReference
  • The reference of the shapes produced by the provideShape method.

    When the ShapeProvider instance is added to a FeatureLayer, and then the layer is attached to a map, LuciadRIA determines if it is possible to visualize shapes on the map by matching the shape provider reference to the map reference.

    This property is optional. When it is not set, the FeatureLayer expects all shape references to be the same as the reference of the FeatureModel.

    Returns null | CoordinateReference

  • set reference(reference): void
  • Parameters

    Returns void

Methods

  • Invalidates the shape for a specific object.

    Call this method when any state that determines the mapping for a feature to a shape has changed. Calling this method guarantees that the object will be repainted with a new shape during the next map render.

    Parameters

    Returns void

  • Invalidates shapes for all objects.

    Calling this method guarantees that all the objects will be repainted with new shapes during the next map render.

    Returns void

  • Invalidates this shape for a specific object by id.

    Call this method when any state that determines the mapping for a feature to a shape has changed. Calling this method guarantees that the object will be repainted with a new shape during the next map render.

    Parameters

    • featureId: FeatureId

      The id of the feature. It corresponds to luciad/model/feature/Feature#id.

    Returns void

  • Registers a callback function for a given event type.

    Parameters

    • event: string

      the event type to register on

    • callback: ((...args) => void)

      the callback function to register

        • (...args): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional scope: any

      the context in which the callback function should be invoked implementation dependent.

    Returns Handle

    a handle to the registered callback with a single function 'remove'. This function can be used to unregister the callback function.

  • Returns a shape for the given feature.

    Parameters

    Returns null | Shape

    the shape associated with the input feature.