Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-12145: Fix gaps along the antimeridian.
Browse files Browse the repository at this point in the history
This change introduces the flag `roundUpCoordinatesIfNeeded` to
the `VectorTileDataSource`. When the flag is enabled the decoder
is allowed to adjust the coordinates of liens and polygons close
to the antimeridian to avoid gaps.

Currently the flag is enabled only when using the HERE vector service.

Signed-off-by: Roberto Raggi <roberto.raggi@here.com>
  • Loading branch information
robertoraggi committed Sep 24, 2020
1 parent b72e23d commit bf4e8a5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
2 changes: 2 additions & 0 deletions @here/harp-vectortile-datasource/lib/OmvDecoderDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export interface OmvDecoderOptions {
politicalView?: string;

enableElevationOverlay?: boolean;

roundUpCoordinatesIfNeeded?: boolean;
}

/**
Expand Down
22 changes: 21 additions & 1 deletion @here/harp-vectortile-datasource/lib/VectorTileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ export interface VectorTileDataSourceParameters extends DataSourceOptions {
* Default is true (i.e. if not defined it is taken to be true)
*/
addGroundPlane?: boolean;

/**
* Indicates whether the decoder is allowed to adjust the coordinates to
* avoid possible glitches at the 180th meridian.
*
* @defaultValue `true` if the data service is
* `https://vector.hereapi.com/v2/vectortiles/base/mc`,
* `false` otherwise.
*/
roundUpCoordinatesIfNeeded?: boolean;
}

/**
Expand Down Expand Up @@ -287,6 +297,15 @@ export class VectorTileDataSource extends TileDataSource {
this.addGroundPlane =
m_params.addGroundPlane === undefined || m_params.addGroundPlane === true;

let roundUpCoordinatesIfNeeded = m_params.roundUpCoordinatesIfNeeded;

if (
roundUpCoordinatesIfNeeded === undefined &&
(m_params as Partial<OmvWithRestClientParams>)?.baseUrl === hereVectorTileBaseUrl
) {
roundUpCoordinatesIfNeeded = true;
}

this.m_decoderOptions = {
showMissingTechniques: this.m_params.showMissingTechniques === true,
filterDescription: this.m_params.filterDescr,
Expand All @@ -297,7 +316,8 @@ export class VectorTileDataSource extends TileDataSource {
politicalView: this.m_params.politicalView,
skipShortLabels: this.m_params.skipShortLabels,
storageLevelOffset: m_params.storageLevelOffset ?? -1,
enableElevationOverlay: this.m_params.enableElevationOverlay === true
enableElevationOverlay: this.m_params.enableElevationOverlay === true,
roundUpCoordinatesIfNeeded
};

this.maxGeometryHeight = getOptionValue(
Expand Down
13 changes: 12 additions & 1 deletion @here/harp-vectortile-datasource/lib/VectorTileDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ export class VectorTileDataProcessor implements IGeometryProcessor {
private readonly m_skipShortLabels = true,
private readonly m_storageLevelOffset = 0,
private readonly m_enableElevationOverlay = false,
private readonly m_roundUpCoordinatesIfNeeded = false,
private readonly m_languages?: string[]
) {
const styleSetDataFilter = new StyleSetDataFilter(m_styleSetEvaluator);
const dataPreFilter = m_dataFilter
? new ComposedDataFilter([styleSetDataFilter, m_dataFilter])
: styleSetDataFilter;

// Register the default adapters.
this.m_dataAdapters.push(new OmvDataAdapter(this, dataPreFilter, logger));

const omvDataAdapter = new OmvDataAdapter(this, dataPreFilter, logger);
omvDataAdapter.roundUpCoordinatesIfNeeded = m_roundUpCoordinatesIfNeeded;
this.m_dataAdapters.push(omvDataAdapter);

this.m_dataAdapters.push(new GeoJsonVtDataAdapter(this, dataPreFilter, logger));
this.m_dataAdapters.push(new GeoJsonDataAdapter(this, dataPreFilter, logger));
}
Expand Down Expand Up @@ -301,6 +307,7 @@ export class VectorTileDecoder extends ThemedTileDecoder {
private m_gatherFeatureAttributes: boolean = false;
private m_skipShortLabels: boolean = true;
private m_enableElevationOverlay: boolean = false;
private m_roundUpCoordinatesIfNeeded: boolean = false;

/** @override */
connect(): Promise<void> {
Expand All @@ -326,6 +333,7 @@ export class VectorTileDecoder extends ThemedTileDecoder {
this.m_skipShortLabels,
this.m_storageLevelOffset,
this.m_enableElevationOverlay,
this.m_roundUpCoordinatesIfNeeded,
this.languages
);

Expand Down Expand Up @@ -420,6 +428,9 @@ export class VectorTileDecoder extends ThemedTileDecoder {
if (omvOptions.enableElevationOverlay !== undefined) {
this.m_enableElevationOverlay = omvOptions.enableElevationOverlay;
}
if (omvOptions.roundUpCoordinatesIfNeeded !== undefined) {
this.m_roundUpCoordinatesIfNeeded = omvOptions.roundUpCoordinatesIfNeeded;
}
}
if (languages !== undefined) {
this.languages = languages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ function checkWinding(multipolygon: IPolygonGeometry[]) {
}
}

function roundUpCoordinates(coordinates: Vector2[], layerExtents: number) {
coordinates.forEach(p => {
if (p.x === layerExtents - 1) {
p.x = layerExtents;
}
});
}

function roundUpPolygonCoordinates(geometry: IPolygonGeometry[], layerExtents: number) {
geometry.forEach(polygon => polygon.rings.forEach(r => roundUpCoordinates(r, layerExtents)));
}

function roundUpLineCoordinates(geometry: ILineGeometry[], layerExtents: number) {
geometry.forEach(line => roundUpCoordinates(line.positions, layerExtents));
}

/**
* The class `OmvDataAdapter` converts OMV protobuf geo data
* to geometries for the given `IGeometryProcessor`.
Expand All @@ -193,6 +209,8 @@ export class OmvDataAdapter implements DataAdapter, OmvVisitor {
private m_tileKey!: TileKey;
private m_layer!: com.mapbox.pb.Tile.ILayer;

public roundUpCoordinatesIfNeeded: boolean = false;

/**
* Constructs a new [[OmvProtobufDataAdapter]].
*
Expand Down Expand Up @@ -350,6 +368,10 @@ export class OmvDataAdapter implements DataAdapter, OmvVisitor {
return;
}

if (this.mustRoundUpCoordinates) {
roundUpLineCoordinates(geometry, layerExtents);
}

const env = createFeatureEnv(
this.m_layer,
feature,
Expand Down Expand Up @@ -410,6 +432,10 @@ export class OmvDataAdapter implements DataAdapter, OmvVisitor {
return;
}

if (this.mustRoundUpCoordinates) {
roundUpPolygonCoordinates(geometry, layerExtents);
}

checkWinding(geometry);

const env = createFeatureEnv(
Expand All @@ -429,4 +455,12 @@ export class OmvDataAdapter implements DataAdapter, OmvVisitor {
storageLevel
);
}

private get mustRoundUpCoordinates(): boolean {
return (
this.roundUpCoordinatesIfNeeded &&
this.m_tileKey.level < 5 &&
this.m_tileKey.column === this.m_tileKey.columnCount() - 1
);
}
}

0 comments on commit bf4e8a5

Please sign in to comment.