OpenLayers is a high-performance, feature-packed library for creating interactive maps on the web.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Feature system with comprehensive geometry support including points, lines, polygons, and collections with spatial operations.
Features represent geographic objects with geometry and properties.
/**
* Vector feature with geometry and attributes
*/
class Feature {
constructor(geometry?: Geometry);
/** Get feature geometry */
getGeometry(): Geometry | undefined;
/** Set feature geometry */
setGeometry(geometry: Geometry | undefined): void;
/** Get feature ID */
getId(): string | number | undefined;
/** Set feature ID */
setId(id: string | number | undefined): void;
/** Get property value */
get(key: string): any;
/** Set property value */
set(key: string, value: any): void;
/** Get all properties */
getProperties(): {[key: string]: any};
/** Set all properties */
setProperties(values: {[key: string]: any}): void;
/** Get feature style */
getStyle(): StyleLike | undefined;
/** Set feature style */
setStyle(style: StyleLike): void;
/** Clone the feature */
clone(): Feature;
}Foundation classes for all geometry types.
/**
* Base class for all geometries
*/
abstract class Geometry {
constructor();
/** Get geometry type */
getType(): GeometryType;
/** Get geometry extent */
getExtent(): Extent;
/** Transform geometry to different projection */
transform(source: ProjectionLike, destination: ProjectionLike): Geometry;
/** Clone the geometry */
clone(): Geometry;
/** Get closest point on geometry to coordinate */
getClosestPoint(point: Coordinate): Coordinate;
/** Check if geometry intersects extent */
intersectsExtent(extent: Extent): boolean;
/** Apply transform function to coordinates */
applyTransform(transformFn: TransformFunction): void;
/** Rotate geometry around anchor point */
rotate(angle: number, anchor: Coordinate): void;
/** Scale geometry */
scale(sx: number, sy?: number, anchor?: Coordinate): void;
/** Translate geometry */
translate(deltaX: number, deltaY: number): void;
}
/**
* Base class for simple geometries with coordinate arrays
*/
abstract class SimpleGeometry extends Geometry {
constructor();
/** Get geometry coordinates */
getCoordinates(): any;
/** Set geometry coordinates */
setCoordinates(coordinates: any): void;
/** Get first coordinate */
getFirstCoordinate(): Coordinate;
/** Get last coordinate */
getLastCoordinate(): Coordinate;
/** Get geometry layout */
getLayout(): GeometryLayout;
/** Get stride (number of values per coordinate) */
getStride(): number;
/** Get flat coordinates array */
getFlatCoordinates(): number[];
}
type GeometryType = 'Point' | 'LineString' | 'LinearRing' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'Circle';
type GeometryLayout = 'XY' | 'XYZ' | 'XYM' | 'XYZM';/**
* Point geometry representing a single coordinate
*/
class Point extends SimpleGeometry {
constructor(coordinates: Coordinate, layout?: GeometryLayout);
/** Get point coordinates */
getCoordinates(): Coordinate;
/** Set point coordinates */
setCoordinates(coordinates: Coordinate): void;
}
/**
* Multi-point geometry for multiple points
*/
class MultiPoint extends SimpleGeometry {
constructor(coordinates: Coordinate[], layout?: GeometryLayout);
/** Get coordinates of all points */
getCoordinates(): Coordinate[];
/** Set coordinates of all points */
setCoordinates(coordinates: Coordinate[]): void;
/** Get specific point geometry */
getPoint(index: number): Point;
/** Get all point geometries */
getPoints(): Point[];
}/**
* Line string geometry
*/
class LineString extends SimpleGeometry {
constructor(coordinates: Coordinate[], layout?: GeometryLayout);
/** Get line coordinates */
getCoordinates(): Coordinate[];
/** Set line coordinates */
setCoordinates(coordinates: Coordinate[]): void;
/** Get coordinate at index */
getCoordinateAt(fraction: number): Coordinate;
/** Get line length */
getLength(): number;
/** Append coordinate to line */
appendCoordinate(coordinate: Coordinate): void;
}
/**
* Linear ring (closed line string)
*/
class LinearRing extends SimpleGeometry {
constructor(coordinates: Coordinate[], layout?: GeometryLayout);
/** Get ring coordinates */
getCoordinates(): Coordinate[];
/** Set ring coordinates */
setCoordinates(coordinates: Coordinate[]): void;
/** Get ring area */
getArea(): number;
}
/**
* Multi-line string geometry
*/
class MultiLineString extends SimpleGeometry {
constructor(coordinates: Coordinate[][], layout?: GeometryLayout);
/** Get coordinates of all lines */
getCoordinates(): Coordinate[][];
/** Set coordinates of all lines */
setCoordinates(coordinates: Coordinate[][]): void;
/** Get specific line string */
getLineString(index: number): LineString;
/** Get all line strings */
getLineStrings(): LineString[];
}/**
* Polygon geometry with optional holes
*/
class Polygon extends SimpleGeometry {
constructor(coordinates: Coordinate[][], layout?: GeometryLayout);
/** Get polygon coordinates [exterior, ...holes] */
getCoordinates(): Coordinate[][];
/** Set polygon coordinates */
setCoordinates(coordinates: Coordinate[][]): void;
/** Get exterior ring */
getLinearRing(index: number): LinearRing;
/** Get all linear rings */
getLinearRings(): LinearRing[];
/** Get polygon area */
getArea(): number;
/** Get polygon perimeter */
getPerimeter(): number;
/** Get interior point */
getInteriorPoint(): Point;
}
/**
* Multi-polygon geometry
*/
class MultiPolygon extends SimpleGeometry {
constructor(coordinates: Coordinate[][][], layout?: GeometryLayout);
/** Get coordinates of all polygons */
getCoordinates(): Coordinate[][][];
/** Set coordinates of all polygons */
setCoordinates(coordinates: Coordinate[][][]): void;
/** Get specific polygon */
getPolygon(index: number): Polygon;
/** Get all polygons */
getPolygons(): Polygon[];
/** Get interior points of all polygons */
getInteriorPoints(): MultiPoint;
}/**
* Circle geometry
*/
class Circle extends SimpleGeometry {
constructor(center: Coordinate, radius?: number, layout?: GeometryLayout);
/** Get circle center */
getCenter(): Coordinate;
/** Set circle center */
setCenter(center: Coordinate): void;
/** Get circle radius */
getRadius(): number;
/** Set circle radius */
setRadius(radius: number): void;
/** Set center and radius together */
setCenterAndRadius(center: Coordinate, radius: number): void;
}
/**
* Collection of multiple geometries
*/
class GeometryCollection extends Geometry {
constructor(geometries?: Geometry[]);
/** Get all geometries in collection */
getGeometries(): Geometry[];
/** Set geometries in collection */
setGeometries(geometries: Geometry[]): void;
/** Get specific geometry by index */
getGeometry(index: number): Geometry;
/** Set specific geometry by index */
setGeometry(index: number, geometry: Geometry): void;
}Usage Examples:
import Feature from 'ol/Feature';
import { Point, LineString, Polygon } from 'ol/geom';
// Create a point feature
const pointFeature = new Feature({
geometry: new Point([0, 0]),
name: 'My Point',
population: 1000
});
// Create a line feature
const lineFeature = new Feature({
geometry: new LineString([
[0, 0], [10, 10], [20, 0]
])
});
// Create a polygon feature
const polygonFeature = new Feature({
geometry: new Polygon([
// Exterior ring
[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
// Interior hole
[[2, 2], [8, 2], [8, 8], [2, 8], [2, 2]]
])
});
// Get geometry properties
const area = polygonFeature.getGeometry().getArea();
const center = polygonFeature.getGeometry().getInteriorPoint();type TransformFunction = (input: number[], output?: number[], dimension?: number) => number[];