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

Commit

Permalink
HARP-11151: Force ring winding to follow Mapbox Vector Tile spec.
Browse files Browse the repository at this point in the history
Fix winding at OmvProtobufDataAdapter for XYZ spaces using protobuf.
  • Loading branch information
atomicsulfate committed Aug 4, 2020
1 parent 7010d87 commit 910282c
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions @here/harp-omv-datasource/lib/OmvData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { Env, MapEnv, Value, ValueMap } from "@here/harp-datasource-protocol/index-decoder";
import { TileKey } from "@here/harp-geoutils";
import { ILogger } from "@here/harp-utils";
import { assert, ILogger } from "@here/harp-utils";
import * as Long from "long";
import { Vector2 } from "three";
import { ShapeUtils, Vector2 } from "three";
import { DecodeInfo } from "./DecodeInfo";
import { IGeometryProcessor, ILineGeometry, IPolygonGeometry } from "./IGeometryProcessor";
import { OmvFeatureFilter } from "./OmvDataFilter";
Expand Down Expand Up @@ -357,6 +357,29 @@ function asGeometryType(feature: com.mapbox.pb.Tile.IFeature | undefined): OmvGe
} // switch
}

// Ensures ring winding follows Mapbox Vector Tile specification: outer rings must be clockwise,
// inner rings counter-clockwise.
function checkWinding(multipolygon: IPolygonGeometry[]) {
if (multipolygon.length === 0) {
return;
}

const firstPolygon = multipolygon[0];
assert(firstPolygon.rings.length > 0);

// Opposite sign to ShapeUtils.isClockWise, since webMercator tile space has top-left origin.
const isOuterRingClockWise = ShapeUtils.area(firstPolygon.rings[0]) > 0;
if (isOuterRingClockWise) {
return;
}

for (const polygon of multipolygon) {
for (const ring of polygon.rings) {
ring.reverse();
}
}
}

/**
* The class [[OmvProtobufDataAdapter]] converts OMV protobuf geo data
* to geometries for the given [[IGeometryProcessor]].
Expand Down Expand Up @@ -589,6 +612,8 @@ export class OmvProtobufDataAdapter implements OmvDataAdapter, OmvVisitor {
return;
}

checkWinding(geometry);

const env = createFeatureEnv(
this.m_layer,
feature,
Expand Down

0 comments on commit 910282c

Please sign in to comment.