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
Comprehensive format reading and writing system supporting major geospatial data formats including GeoJSON, KML, GPX, and various OGC service formats.
Foundation classes for different types of format readers and writers.
/**
* Base feature format class
*/
abstract class Feature {
constructor();
/** Read features from source */
abstract readFeatures(source: Document | Element | Object | string, options?: ReadOptions): Feature[];
/** Read single feature from source */
abstract readFeature(source: Document | Element | Object | string, options?: ReadOptions): Feature | null;
/** Read geometry from source */
abstract readGeometry(source: Document | Element | Object | string, options?: ReadOptions): Geometry | null;
/** Read projection from source */
abstract readProjection(source: Document | Element | Object | string): Projection | null;
/** Write features to format */
abstract writeFeatures(features: Feature[], options?: WriteOptions): string;
/** Write single feature to format */
abstract writeFeature(feature: Feature, options?: WriteOptions): string;
/** Write geometry to format */
abstract writeGeometry(geometry: Geometry, options?: WriteOptions): string;
}
/**
* Base JSON feature format class
*/
abstract class JSONFeature extends Feature {
constructor();
/** Read features from JSON object or string */
readFeaturesFromObject(object: Object, options?: ReadOptions): Feature[];
/** Write features to JSON object */
writeFeaturesObject(features: Feature[], options?: WriteOptions): Object;
}
/**
* Base XML feature format class
*/
abstract class XMLFeature extends Feature {
constructor();
/** Read features from XML node */
readFeaturesFromNode(node: Element, options?: ReadOptions): Feature[];
/** Write features to XML node */
writeFeaturesNode(features: Feature[], options?: WriteOptions): Node;
}
interface ReadOptions {
/** Data projection */
dataProjection?: ProjectionLike;
/** Extent to limit reading */
extent?: Extent;
/** Feature projection */
featureProjection?: ProjectionLike;
}
interface WriteOptions {
/** Data projection */
dataProjection?: ProjectionLike;
/** Feature projection */
featureProjection?: ProjectionLike;
/** Decimal precision */
decimals?: number;
/** Right-hand rule for coordinates */
rightHanded?: boolean;
}Standard JSON format for geographic data with full feature support.
/**
* GeoJSON format reader/writer
* @param options - GeoJSON configuration options
*/
class GeoJSON extends JSONFeature {
constructor(options?: GeoJSONOptions);
/** Read features from GeoJSON */
readFeatures(source: GeoJSONObject | string, options?: ReadOptions): Feature[];
/** Read single feature from GeoJSON */
readFeature(source: GeoJSONObject | string, options?: ReadOptions): Feature | null;
/** Read geometry from GeoJSON */
readGeometry(source: GeoJSONObject | string, options?: ReadOptions): Geometry | null;
/** Read projection from GeoJSON */
readProjection(source: GeoJSONObject | string): Projection | null;
/** Write features to GeoJSON string */
writeFeatures(features: Feature[], options?: WriteOptions): string;
/** Write single feature to GeoJSON string */
writeFeature(feature: Feature, options?: WriteOptions): string;
/** Write geometry to GeoJSON string */
writeGeometry(geometry: Geometry, options?: WriteOptions): string;
/** Write features to GeoJSON object */
writeFeaturesObject(features: Feature[], options?: WriteOptions): GeoJSONFeatureCollection;
/** Write single feature to GeoJSON object */
writeFeatureObject(feature: Feature, options?: WriteOptions): GeoJSONFeature;
/** Write geometry to GeoJSON object */
writeGeometryObject(geometry: Geometry, options?: WriteOptions): GeoJSONGeometry;
}
interface GeoJSONOptions {
/** Data projection */
dataProjection?: ProjectionLike;
/** Feature projection */
featureProjection?: ProjectionLike;
/** Extract geometry name */
geometryName?: string;
}
interface GeoJSONFeatureCollection {
type: 'FeatureCollection';
features: GeoJSONFeature[];
}
interface GeoJSONFeature {
type: 'Feature';
geometry: GeoJSONGeometry | null;
properties: Object | null;
id?: string | number;
}
interface GeoJSONGeometry {
type: string;
coordinates: any[];
}Usage Examples:
import GeoJSON from 'ol/format/GeoJSON';
import VectorSource from 'ol/source/Vector';
// Create GeoJSON format
const geojsonFormat = new GeoJSON();
// Read features from GeoJSON
const geojsonString = `{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
},
"properties": {
"name": "Sample Point"
}
}
]
}`;
const features = geojsonFormat.readFeatures(geojsonString, {
featureProjection: 'EPSG:3857'
});
// Write features to GeoJSON
const geojsonOutput = geojsonFormat.writeFeatures(features, {
featureProjection: 'EPSG:3857',
dataProjection: 'EPSG:4326'
});
// Use with vector source
const vectorSource = new VectorSource({
format: new GeoJSON(),
url: 'data/features.geojson'
});Keyhole Markup Language format for geographic visualization.
/**
* KML format reader/writer
* @param options - KML configuration options
*/
class KML extends XMLFeature {
constructor(options?: KMLOptions);
/** Read features from KML */
readFeatures(source: Document | Element | string, options?: ReadOptions): Feature[];
/** Read single feature from KML */
readFeature(source: Document | Element | string, options?: ReadOptions): Feature | null;
/** Read name from KML document */
readName(source: Document | Element | string): string | undefined;
/** Read network links from KML */
readNetworkLinks(source: Document | Element | string, options?: ReadOptions): Object[];
/** Read regions from KML */
readRegion(source: Document | Element | string): Extent | null;
/** Write features to KML string */
writeFeatures(features: Feature[], options?: WriteOptions): string;
/** Write single feature to KML string */
writeFeature(feature: Feature, options?: WriteOptions): string;
}
interface KMLOptions {
/** Extract styles */
extractStyles?: boolean;
/** Show point names */
showPointNames?: boolean;
/** Default style */
defaultStyle?: Style[];
/** Write styles */
writeStyles?: boolean;
}Usage Examples:
import KML from 'ol/format/KML';
// Create KML format
const kmlFormat = new KML({
extractStyles: true,
showPointNames: true
});
// Read features from KML file
fetch('data/places.kml')
.then(response => response.text())
.then(kmlText => {
const features = kmlFormat.readFeatures(kmlText, {
featureProjection: 'EPSG:3857'
});
vectorSource.addFeatures(features);
});
// Write features to KML
const kmlOutput = kmlFormat.writeFeatures(features, {
featureProjection: 'EPSG:3857',
dataProjection: 'EPSG:4326'
});GPS Exchange Format for GPS track and waypoint data.
/**
* GPX format reader/writer for GPS data
* @param options - GPX configuration options
*/
class GPX extends XMLFeature {
constructor(options?: GPXOptions);
/** Read features from GPX */
readFeatures(source: Document | Element | string, options?: ReadOptions): Feature[];
/** Read projection from GPX (always EPSG:4326) */
readProjection(source: Document | Element | string): Projection;
/** Write features to GPX string */
writeFeatures(features: Feature[], options?: WriteOptions): string;
}
interface GPXOptions {
/** Read track extensions */
readExtensions?: (feature: Feature, node: Element) => void;
}Formats for handling vector tile data.
/**
* Mapbox Vector Tiles (MVT) format
* @param options - MVT configuration options
*/
class MVT extends Feature {
constructor(options?: MVTOptions);
/** Read features from MVT buffer */
readFeatures(source: ArrayBuffer, options?: ReadOptions): Feature[];
/** Read projection (always EPSG:3857) */
readProjection(): Projection;
/** Set layer names to read */
setLayers(layers: string[]): void;
}
interface MVTOptions {
/** Feature class to use */
featureClass?: typeof Feature;
/** Geometry name */
geometryName?: string;
/** Layer names to read */
layers?: string[];
/** ID property name */
idProperty?: string;
}Text-based geometry formats for data exchange.
/**
* Well-Known Text (WKT) format for geometries
* @param options - WKT configuration options
*/
class WKT extends TextFeature {
constructor(options?: WKTOptions);
/** Read geometry from WKT string */
readGeometry(source: string, options?: ReadOptions): Geometry;
/** Read feature from WKT string */
readFeature(source: string, options?: ReadOptions): Feature;
/** Read features from WKT string */
readFeatures(source: string, options?: ReadOptions): Feature[];
/** Write geometry to WKT string */
writeGeometry(geometry: Geometry, options?: WriteOptions): string;
/** Write feature to WKT string */
writeFeature(feature: Feature, options?: WriteOptions): string;
/** Write features to WKT string */
writeFeatures(features: Feature[], options?: WriteOptions): string;
}
/**
* Well-Known Binary (WKB) format for geometries
*/
class WKB extends Feature {
constructor();
/** Read geometry from WKB buffer */
readGeometry(source: ArrayBuffer, options?: ReadOptions): Geometry;
/** Read feature from WKB buffer */
readFeature(source: ArrayBuffer, options?: ReadOptions): Feature;
/** Write geometry to WKB buffer */
writeGeometry(geometry: Geometry, options?: WriteOptions): ArrayBuffer;
/** Write feature to WKB buffer */
writeFeature(feature: Feature, options?: WriteOptions): ArrayBuffer;
}Usage Examples:
import { WKT, WKB } from 'ol/format';
import Point from 'ol/geom/Point';
// WKT format
const wktFormat = new WKT();
// Read geometry from WKT
const wktString = 'POINT(0 0)';
const geometry = wktFormat.readGeometry(wktString);
// Write geometry to WKT
const point = new Point([100, 200]);
const wktOutput = wktFormat.writeGeometry(point);
// Output: "POINT(100 200)"
// WKB format
const wkbFormat = new WKB();
const wkbBuffer = wkbFormat.writeGeometry(point);
const geometryFromWkb = wkbFormat.readGeometry(wkbBuffer);Formats for OGC web service responses and capabilities.
/**
* WMS Capabilities format reader
*/
class WMSCapabilities extends XML {
constructor();
/** Read WMS capabilities */
read(source: Document | Element | string): Object;
}
/**
* WMTS Capabilities format reader
*/
class WMTSCapabilities extends XML {
constructor();
/** Read WMTS capabilities */
read(source: Document | Element | string): Object;
}
/**
* WFS (Web Feature Service) format
* @param options - WFS configuration options
*/
class WFS extends XMLFeature {
constructor(options?: WFSOptions);
/** Read features from WFS response */
readFeatures(source: Document | Element | string, options?: ReadOptions): Feature[];
/** Read transaction response */
readTransactionResponse(source: Document | Element | string): Object;
/** Write GetFeature request */
writeGetFeature(options: WFSWriteGetFeatureOptions): Node;
/** Write Transaction request */
writeTransaction(inserts: Feature[], updates: Feature[], deletes: Feature[], options: WFSWriteTransactionOptions): Node;
}
interface WFSOptions {
/** Feature namespace URI */
featureNS?: string;
/** Feature type */
featureType?: string | string[];
/** GML format */
gmlFormat?: GMLBase;
/** Schema location */
schemaLocation?: string;
}
/**
* ESRI JSON format for ArcGIS services
*/
class EsriJSON extends JSONFeature {
constructor();
/** Read features from ESRI JSON */
readFeatures(source: Object | string, options?: ReadOptions): Feature[];
/** Read geometry from ESRI JSON */
readGeometry(source: Object | string, options?: ReadOptions): Geometry;
/** Write features to ESRI JSON */
writeGeometry(geometry: Geometry, options?: WriteOptions): Object;
}Google Polyline Algorithm for encoding coordinate paths.
/**
* Google Polyline encoding format
* @param options - Polyline configuration options
*/
class Polyline extends TextFeature {
constructor(options?: PolylineOptions);
/** Read geometry from encoded polyline string */
readGeometry(source: string, options?: ReadOptions): LineString;
/** Read feature from encoded polyline string */
readFeature(source: string, options?: ReadOptions): Feature;
/** Write geometry to encoded polyline string */
writeGeometry(geometry: Geometry, options?: WriteOptions): string;
}
interface PolylineOptions {
/** Encoding factor (default: 1e5) */
factor?: number;
/** Geometry layout */
geometryLayout?: GeometryLayout;
}Usage Examples:
import Polyline from 'ol/format/Polyline';
import LineString from 'ol/geom/LineString';
// Create polyline format
const polylineFormat = new Polyline();
// Decode polyline string
const encodedPolyline = 'u{~vFvyys@fS]';
const lineString = polylineFormat.readGeometry(encodedPolyline, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
// Encode linestring to polyline
const coordinates = [[-120, 38], [-121, 39], [-122, 40]];
const geometry = new LineString(coordinates);
const encoded = polylineFormat.writeGeometry(geometry);Topological JSON format for efficient geographic data encoding.
/**
* TopoJSON format reader
* @param options - TopoJSON configuration options
*/
class TopoJSON extends JSONFeature {
constructor(options?: TopoJSONOptions);
/** Read features from TopoJSON */
readFeatures(source: Object | string, options?: ReadOptions): Feature[];
/** Read projection from TopoJSON */
readProjection(source: Object | string): Projection | null;
}
interface TopoJSONOptions {
/** Layer names to read */
layers?: string[];
}type GeoJSONObject = GeoJSONGeometry | GeoJSONFeature | GeoJSONFeatureCollection;
type GeometryLayout = 'XY' | 'XYZ' | 'XYM' | 'XYZM';