CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ol

OpenLayers is a high-performance, feature-packed library for creating interactive maps on the web.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

data-sources.mddocs/

Data Sources

Comprehensive data source system supporting multiple formats, tile services, and vector data with optimized loading strategies.

Capabilities

Base Source Classes

Foundation classes providing common source functionality.

/**
 * Base class for all data sources
 */
abstract class Source {
  constructor(options: SourceOptions);
  
  /** Get source attributions */
  getAttributions(): Attribution[] | null;
  /** Set source attributions */
  setAttributions(attributions: Attribution[] | null): void;
  
  /** Get source projection */
  getProjection(): Projection | null;
  
  /** Get source state */
  getState(): SourceState;
  
  /** Refresh the source */
  refresh(): void;
  
  /** Get custom properties */
  get(key: string): any;
  /** Set custom properties */
  set(key: string, value: any): void;
}

interface SourceOptions {
  /** Attribution information */
  attributions?: Attribution[] | null;
  /** Interpolate linearly between pixels */
  interpolate?: boolean;
  /** Source projection */
  projection?: ProjectionLike;
  /** Source state */
  state?: SourceState;
  /** Wrap the world horizontally */
  wrapX?: boolean;
}

type SourceState = 'undefined' | 'loading' | 'ready' | 'error';

Tile Sources

Sources providing tiled data for efficient map rendering.

/**
 * Base class for tile sources
 */
abstract class TileSource extends Source {
  constructor(options: TileSourceOptions);
  
  /** Get the tile grid */
  getTileGrid(): TileGrid | null;
  /** Set the tile grid */
  setTileGrid(tileGrid: TileGrid): void;
  
  /** Get tile loading function */
  getTileLoadFunction(): TileLoadFunction;
  /** Set tile loading function */
  setTileLoadFunction(tileLoadFunction: TileLoadFunction): void;
  
  /** Get tile URL function */
  getTileUrlFunction(): TileUrlFunction | null;
  /** Set tile URL function */
  setTileUrlFunction(tileUrlFunction: TileUrlFunction): void;
  
  /** Get tile at coordinates */
  getTile(z: number, x: number, y: number, pixelRatio: number, projection: Projection): Tile;
  
  /** Refresh tiles */
  refresh(): void;
}

interface TileSourceOptions extends SourceOptions {
  /** Cache size for tiles */
  cacheSize?: number;
  /** Transition duration for tile opacity */
  transition?: number;
  /** Tile grid defining the tile coordinate system */
  tileGrid?: TileGrid;
  /** Tile loading function */
  tileLoadFunction?: TileLoadFunction;
  /** Tile URL function */
  tileUrlFunction?: TileUrlFunction;
  /** Key for tile cache */
  key?: string;
}

/**
 * XYZ tile source for standard tiled web maps
 */
class XYZ extends TileImage {
  constructor(options?: XYZOptions);
  
  /** Get tile URLs */
  getUrls(): string[] | null;
  /** Set tile URLs */
  setUrls(urls: string[]): void;
  
  /** Set single tile URL */
  setUrl(url: string): void;
}

interface XYZOptions extends TileImageOptions {
  /** Tile URL template or array of templates */
  url?: string;
  urls?: string[];
  /** Maximum zoom level */
  maxZoom?: number;
  /** Minimum zoom level */
  minZoom?: number;
  /** Maximum allowed resolution */
  maxResolution?: number;
  /** Tile size */
  tileSize?: number | Size;
  /** Reprojection error threshold */
  reprojectionErrorThreshold?: number;
}

/**
 * OpenStreetMap tile source
 */
class OSM extends XYZ {
  constructor(options?: OSMOptions);
}

interface OSMOptions extends XYZOptions {
  /** Use retina/high DPI tiles */
  hidpi?: boolean;
  /** OpenStreetMap layer type */
  layer?: 'osm' | 'cycle' | 'transport';
  /** Custom OpenStreetMap server URL */
  url?: string;
}

Usage Examples:

import XYZ from 'ol/source/XYZ';
import OSM from 'ol/source/OSM';
import TileLayer from 'ol/layer/Tile';

// Create a custom XYZ tile source
const xyzSource = new XYZ({
  url: 'https://tile.stamen.com/toner/{z}/{x}/{y}.png',
  maxZoom: 18,
  attributions: ['Map tiles by Stamen Design']
});

// Create an OpenStreetMap source
const osmSource = new OSM({
  layer: 'osm',
  hidpi: true
});

// Use in a tile layer
const layer = new TileLayer({
  source: osmSource
});

Map Service Sources

Sources for accessing standardized map services.

/**
 * Web Map Service (WMS) image source
 */
class ImageWMS extends ImageSource {
  constructor(options: ImageWMSOptions);
  
  /** Get WMS parameters */
  getParams(): {[key: string]: any};
  /** Update WMS parameters */
  updateParams(params: {[key: string]: any}): void;
  
  /** Set WMS server URL */
  setUrl(url: string): void;
  /** Get WMS server URL */
  getUrl(): string | undefined;
  
  /** Get feature info URL */
  getFeatureInfoUrl(coordinate: Coordinate, resolution: number, projection: ProjectionLike, params: {[key: string]: any}): string | undefined;
}

interface ImageWMSOptions extends ImageSourceOptions {
  /** WMS server URL */
  url?: string;
  /** WMS parameters */
  params?: {[key: string]: any};
  /** Server type for vendor-specific parameters */
  serverType?: ServerType;
  /** Hide layers in legend */
  hidpi?: boolean;
  /** Ratio for image requests */
  ratio?: number;
  /** Cross-origin setting */
  crossOrigin?: string | null;
}

/**
 * Web Map Tile Service (WMTS) source
 */
class WMTS extends TileImage {
  constructor(options: WMTSOptions);
  
  /** Get WMTS dimensions */
  getDimensions(): {[key: string]: string};
  /** Update WMTS dimensions */
  updateDimensions(dimensions: {[key: string]: string}): void;
}

interface WMTSOptions extends TileImageOptions {
  /** WMTS capabilities or configuration */
  source?: any;
  /** Layer name */
  layer: string;
  /** Style name */
  style: string;
  /** Tile matrix set */
  matrixSet: string;
  /** Image format */
  format?: string;
  /** Request encoding */
  requestEncoding?: WMTSRequestEncoding;
  /** Dimensions */
  dimensions?: {[key: string]: string};
}

type ServerType = 'carmentaserver' | 'geoserver' | 'mapserver' | 'qgis';
type WMTSRequestEncoding = 'KVP' | 'REST';

Vector Sources

Sources for vector feature data.

/**
 * Vector source for features
 */
class VectorSource extends Source {
  constructor(options?: VectorSourceOptions);
  
  /** Add a single feature */
  addFeature(feature: Feature): void;
  /** Add multiple features */
  addFeatures(features: Feature[]): void;
  
  /** Remove a feature */
  removeFeature(feature: Feature): void;
  /** Clear all features */
  clear(): void;
  
  /** Get all features */
  getFeatures(): Feature[];
  /** Get features in extent */
  getFeaturesInExtent(extent: Extent): Feature[];
  /** Get closest feature to coordinate */
  getClosestFeatureToCoordinate(coordinate: Coordinate, filter?: (feature: Feature) => boolean): Feature | null;
  
  /** Get feature by ID */
  getFeatureById(id: string | number): Feature | null;
  
  /** Force feature re-rendering */
  changed(): void;
  
  /** Get source extent */
  getExtent(): Extent;
  
  /** Set loader function for remote data */
  setLoader(loader: FeatureLoader): void;
  /** Get loader function */
  getLoader(): FeatureLoader;
}

interface VectorSourceOptions extends SourceOptions {
  /** Initial features */
  features?: Feature[] | Collection<Feature>;
  /** Feature format for parsing */
  format?: FeatureFormat;
  /** Data URL */
  url?: string | FeatureUrlFunction;
  /** Feature loader function */
  loader?: FeatureLoader;
  /** Loading strategy */
  strategy?: LoadingStrategy;
  /** Use spatial index for fast queries */
  useSpatialIndex?: boolean;
  /** Wrap features horizontally */
  wrapX?: boolean;
}

/**
 * Cluster source for grouping nearby features
 */
class Cluster extends VectorSource {
  constructor(options: ClusterOptions);
  
  /** Get clustering distance */
  getDistance(): number;
  /** Set clustering distance */
  setDistance(distance: number): void;
  
  /** Get minimum distance between clusters */
  getMinDistance(): number;
  /** Set minimum distance between clusters */
  setMinDistance(minDistance: number): void;
}

interface ClusterOptions extends VectorSourceOptions {
  /** Distance for clustering features */
  distance?: number;
  /** Minimum distance between clusters */
  minDistance?: number;
  /** Geometry function for clustering point */
  geometryFunction?: (feature: Feature) => Point;
  /** Create cluster function */
  createCluster?: (extent: Extent, features: Feature[]) => Feature;
}

Usage Examples:

import VectorSource from 'ol/source/Vector';
import Cluster from 'ol/source/Cluster';
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import GeoJSON from 'ol/format/GeoJSON';

// Create a vector source with features
const vectorSource = new VectorSource({
  features: [
    new Feature({
      geometry: new Point([0, 0]),
      name: 'Point 1'
    })
  ]
});

// Load GeoJSON data
const geoJsonSource = new VectorSource({
  url: 'data/features.geojson',
  format: new GeoJSON()
});

// Create a clustering source
const clusterSource = new Cluster({
  source: vectorSource,
  distance: 40,
  minDistance: 20
});

Vector Tile Sources

Sources for vector tile data.

/**
 * Vector tile source
 */
class VectorTile extends UrlTile {
  constructor(options?: VectorTileOptions);
  
  /** Get tile format */
  getFormat(): FeatureFormat | null;
  
  /** Clear tile cache */
  clear(): void;
}

interface VectorTileOptions extends UrlTileOptions {
  /** Vector tile format */
  format?: FeatureFormat;
  /** Tile class */
  tileClass?: typeof VectorTile;
  /** Tile loading function */
  tileLoadFunction?: TileLoadFunction;
}

/**
 * Mapbox Vector Tiles (MVT) source
 */
class MVTSource extends VectorTile {
  constructor(options?: MVTOptions);
}

Specialized Sources

Additional sources for specific data types and services.

/**
 * Bing Maps tile source
 */
class BingMaps extends TileImage {
  constructor(options: BingMapsOptions);
  
  /** Get Bing Maps API key */
  getApiKey(): string;
  /** Set Bing Maps API key */
  setApiKey(apiKey: string): void;
}

interface BingMapsOptions extends TileImageOptions {
  /** Bing Maps API key */
  apiKey: string;
  /** Imagery set (Road, Aerial, etc.) */
  imagerySet: string;
  /** Culture code */
  culture?: string;
  /** Maximum zoom level */
  maxZoom?: number;
}

/**
 * Static image source
 */
class ImageStatic extends ImageSource {
  constructor(options: ImageStaticOptions);
  
  /** Get image URL */
  getUrl(): string;
  /** Set image URL */
  setUrl(url: string): void;
}

interface ImageStaticOptions extends ImageSourceOptions {
  /** Image URL */
  url: string;
  /** Image extent in map coordinates */
  imageExtent: Extent;
  /** Image size in pixels */
  imageSize?: Size;
  /** Cross-origin setting */
  crossOrigin?: string | null;
}

/**
 * Raster operation source for image processing
 */
class RasterSource extends ImageSource {
  constructor(options: RasterOptions);
  
  /** Set raster operation */
  setOperation(operation: RasterOperation, lib?: {[key: string]: any}): void;
}

interface RasterOptions extends ImageSourceOptions {
  /** Input sources for raster operation */
  sources: Source[];
  /** Raster operation function */
  operation?: RasterOperation;
  /** External library for operation */
  lib?: {[key: string]: any};
  /** Number of worker threads */
  threads?: number;
  /** Operation type */
  operationType?: RasterOperationType;
}

type RasterOperation = (inputs: ImageData[], data: {[key: string]: any}) => ImageData;
type RasterOperationType = 'pixel' | 'image';

Types

type Attribution = string | {
  html: string;
  collapsible?: boolean;
};

type FeatureLoader = (extent: Extent, resolution: number, projection: Projection) => void;
type FeatureUrlFunction = (extent: Extent, resolution: number, projection: Projection) => string;
type LoadingStrategy = (extent: Extent, resolution: number) => Extent[];
type TileLoadFunction = (tile: Tile, src: string) => void;
type TileUrlFunction = (tileCoord: [number, number, number], pixelRatio: number, projection: Projection) => string;

Install with Tessl CLI

npx tessl i tessl/npm-ol

docs

controls-ui.md

coordinate-systems-projections.md

core-map-system.md

data-sources.md

events-system.md

format-support.md

index.md

layer-management.md

styling-system.md

user-interactions.md

vector-features-geometries.md

tile.json