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.x
is longitude in degrees, andy
is latitude in degrees.holeIndices
(Array|TypedArray|null) - the indices inpositions
where each hole starts. Ifnull
, the polygon has no holes.options
(Object, optional)size
(Number) - the number of elements in each vertex. Size2
will interpretpositions
as[x0, y0, x1, y1, ...]
and size3
will interpretpositions
as[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,maxLatitude
will be used to represent the pole. Default85.051129
which 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 inpositions
where 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