cutPolygonByMercatorBounds
Splits a geospatial polygon at the 180th meridian and the top (latitude=90) and bottom (latitude=-90) edges of the Web Mercator map.
import {cutPolygonByMercatorBounds} from '@math.gl/polygon';
cutPolygonByMercatorBounds([-170, 0, 170, 0, 170, 20, -170, 20], {size: 2});
// returns [
// [170, 20, 180, 20, 180, 0, 170, 0],
// [-180, 20, -170, 20, -170, 0, -180, 0]
// ]
]
Usage
cutPolygonByMercatorBounds(positions, holeIndices, [options]);
Arguments:
positions(Array|TypedArray) - a flat array of the vertex positions that define the polygon's rings.xis longitude in degrees, andyis latitude in degrees.holeIndices(Array|TypedArray|null) - the indices inpositionswhere each hole starts. Ifnull, the polygon has no holes.options(Object, optional)size(Number) - the number of elements in each vertex. Size2will interpretpositionsas[x0, y0, x1, y1, ...]and size3will interpretpositionsas[x0, y0, z0, x1, y1, z1, ...]. Default2.normalize(Boolean) - make sure the output longitudes are within[-180, 180]. Defaulttrue.maxLatitude(Number) - since latitude=90 projects to infinity in Web Mercator projection,maxLatitudewill be used to represent the pole. Default85.051129which makes the map square.edgeTypes(Boolean) - iftrue, returns an additional array for each polygon that describes the nature of each vertex. See "returns" below.
Returns:
An array of polygons. Each polygons is represented by an object with the following fields:
positions(Array|TypedArray) - a flat array of the vertex positions that define the polygon's rings.holeIndices(Array|TypedArray) - the indices inpositionswhere each hole starts. Not present if the polygon has no holes.edgeTypes(Array) - describes the nature of each vertex inpositions:0- the segment connecting this vertex to the next is inside the original polygon1- the segment connecting this vertex to the next is on the border of the original polygon