ts-maps

API reference

On this page 12

What ts-maps exports, grouped by what it is for. The pages below document the larger pieces in full; the concepts pages explain how they fit together, with more examples.

Page
MapThe map: options, camera, style, queries, feature state, events, 3D, projection, export.
LayersMarkers, popups, tile layers, vector tiles, GeoJSON, heatmaps, overlays, shapes, 3D objects.
ExpressionsThe style expression operators, and how to evaluate one yourself.
GeometryLatLng, LatLngBounds, Point, Bounds, area, distance and polygon operations.
import { control, Map, Marker, styles } from 'ts-maps'
import 'ts-maps/styles.css'

const map = new Map('map', {
  center: [51.5072, -0.1276],
  zoom: 14,
  style: styles.light({ url: 'https://tiles.openfreemap.org/planet' }),
})

control.search().addTo(map)
new Marker([51.5072, -0.1276]).addTo(map).bindPopup('Trafalgar Square')

Everything is a named export. The default export, tsMap, gathers the common ones in one object; in a browser, importing ts-maps also sets it as window.tsMap.

Map

Export
Map, MapThe map class. See Map.
createMap(container, options), map(...)new Map(...) as a function.
MapOptionsThe options type.
DragHandler, ScrollWheelZoomHandler, PinchZoomHandler, BoxZoomHandler, DoubleClickZoomHandler, KeyboardHandler, TwoFingerRotateHandler, TwoFingerPitchHandler, TapHoldHandler, CooperativeGesturesHandlerThe interaction handlers, on every map as map.dragging, map.scrollWheelZoom and so on.
versionThe library's version string.

Layers

All in Layers.

Export
Layer, LayerGroup, FeatureGroupThe base class, and groups.
Marker, Icon, DivIcon, DefaultIcon, Popup, TooltipPoints and the cards on them.
TileLayer, WMSTileLayer, GridLayer, RasterDEMLayer (HillshadeLayer)Image tiles and hillshading.
VectorTileMapLayerVector tiles drawn with style layers.
GeoJSON, HeatmapLayer, GeoJSONClusterSource, GeoJSONTileSourceData.
ImageOverlay, VideoOverlay, SVGOverlayPictures over bounds.
Polyline, Polygon, Rectangle, Circle, CircleMarker, Path, SVG, CanvasShapes, and the renderers that draw them.
Landmark, Trees, loadModel, parseGLB, modelFromGltf, roofOf3D objects: glTF landmarks, trees and roof shapes.
TrafficLayer, trafficSources, TomTomIncidentsLive traffic.
TerritoryLayer, RunTrailLayer, RouteEditorFor territory-capture games.

Factories: marker, icon, divIcon, popup, tooltip, layerGroup, featureGroup, geoJSON (geoJson), gridLayer, tileLayer, tileLayer.wms, vectorTileLayer, heatmapLayer, rasterDEMLayer, imageOverlay, videoOverlay, svgOverlay, polyline, polygon, rectangle, circle, circleMarker, landmark, trees, trafficLayer, territoryLayer, runTrailLayer, routeEditor.

Controls

Each is a class, and control.* makes one. See Controls.

FactoryClass
control.zoom()ZoomControl+ and −. On by default (zoomControl: false to leave it off).
control.navigation()NavigationControlZoom buttons and a compass. Click the compass to turn back to north.
control.attribution()AttributionControlCredits from the layers. On by default.
control.scale()ScaleControlMetric and imperial scale bars.
control.layers(base, overlays)LayersControlA switcher between layers.
control.fullscreen()FullscreenControl
control.locate()LocateControlShow and follow the device's position.
control.geocoder()GeocoderControlA plain search box over a geocoder.
control.search()SearchControlSearch with suggestions, categories, place cards, directions and saved places.
control.mapType({ types })MapTypeControlExplore, Driving, Transit, Satellite. mapTypes(options) builds that set.
control.offlineMaps()OfflineMapsControlDownload areas for use with no connection.
control.lookAround(), lookAround()LookAroundStreet-level imagery.
indoorMap({ venue })IndoorMapIndoor floor plans from IMDF, with a level picker.
control(options)ControlThe base class, for your own.

Styles

styles holds the built-in styles. Each is a function that returns a style document for setStyle.

Export
styles.light(options), styles.dark(options)The basemap, over any OpenMapTiles source: { url } for a TileJSON, or { tiles }.
styles.transit(options)The basemap with transit lines and stations.
styles.satellite(options?), styles.hybrid(options)Esri World Imagery; hybrid adds the basemap's roads and labels.
styles.LIGHT, styles.DARKThe palettes, to override single colours with palette.
resolveTileJSON(urls), resolveStyleSources(style, fetch), tileJSONSources(style)Read TileJSON sources yourself.

See Styles and theming.

Search, directions and navigation

Export
servicesGeocoders, directions, isochrones and matrices — the same as ts-maps/services. See Services.
turnByTurn(map, options), TurnByTurnRoute choices, then guidance: banner, lanes, voice and a camera that follows.
SearchEngine, SearchHistory, StreetIndexThe search behind SearchControl, usable on its own.
savedPlaces(), SavedPlaces, LocalStorageSavedPlaces, MemorySavedPlacesFavourites and guides.
OverpassPlaceDetails, parseOpeningHours, openingStatusPlace details and opening hours.
SEARCH_CATEGORIES, categoryForQuery, clusterPinsCategories and result pins.

Offline

Export
offlineMaps(), OfflineMapsThe page's offline maps manager, also map.offline. Download areas, list them, search and route over them.
IndexedDBOfflineStore, MemoryOfflineStore, KeyValueOfflineStoreWhere downloads are kept.
OfflineGeocoder, OfflineDirections, withOfflineFallbackSearch and directions over downloaded data.
TileCache, cachedFetch, saveOfflineRegion, getDefaultCacheA tile cache, for offlineCache on a tile layer or source.

See Offline.

Indoor and street level

Export
loadIMDF, searchIndoorRead an IMDF venue and search it.
PanoramaxImagery, MapillaryImageryStreet-level imagery providers for LookAround. Panoramax is the default and needs no key.

Geography and geometry

All in Geometry: LatLng, LatLngBounds, Point, Bounds, Transformation, LineUtil, PolyUtil, RTree, earcut; polygonArea, haversine, formatArea, formatDistance; union, intersection, difference, xor; CRS, EPSG3857, EPSG4326, EPSG3395, SimpleCRS, Projection.

Tiles and formats

Export
VectorTile, VectorTileLayer, VectorTileFeature, PbfDecode a Mapbox Vector Tile by hand: new VectorTile(new Pbf(bytes)).
withPMTiles, setPMTilesArchive, pmtilesTileJSON, …pmtiles:// URLs: a PMTiles archive read in place, with no tile server.
renderStaticMap(options), staticMapSvg(map, w, h)A map drawn once as SVG, from the same tiles and style. For share cards and figures.
WebGLTileRendererThe WebGL renderer the tile layers use.

Localization

addMessages(locale, messages), message(locale, key), messageLocales(), resolveLocale(locale), translator(locale), formatNumber, formatDate. English and German are built in. See Localization.

Core

Class, Evented, Handler, Util, Browser, DomUtil, DomEvent, Draggable, Animation, PosAnimation, easing. The building blocks the rest is made of, for writing layers, controls and handlers of your own.

Entry points

ts-maps itself has everything above. These entry points carry one part each, and the server-side ones are only there:

Import
ts-maps/styles.css (or ts-maps/css)The stylesheet. Needed for controls, popups and markers.
ts-maps/servicesGeocoding, directions, isochrone, matrix and elevation providers.
ts-maps/style-specvalidateStyle, compileExpression, evaluateExpression, diffStyles, convertLegacyFilter, the style types.
ts-maps/storageTileCache, cachedFetch, saveOfflineRegion.
ts-maps/geoGeographic types, CRSs, area and polygon operations, elevation decoding.
ts-maps/geometryPoint, Bounds, Transformation, LineUtil, PolyUtil, RTree.
ts-maps/symbolsCollisionIndex, GlyphAtlas, IconAtlas, glyph and sprite loaders.
ts-maps/staticrenderStaticMap and staticMapSvg.
ts-maps/pmtilesRead and write PMTiles archives.
ts-maps/serverA vector tile server for Bun, from a PMTiles archive on disk, a URL or S3.
ts-maps/workerA tile server for Cloudflare Workers over R2.
ts-maps/gazetteerA self-hosted place search for Bun, from GeoNames.
ts-maps/offline-swA service worker that keeps the page itself available offline.

See Running a tile server for the server-side ones.