Skip to content

Maplibre Map

The Map object represents the map on your page. It exposes methods and properties that enable you to programmatically change the map, and fires events as users interact with it.

You create a Map by specifying a container and other options. Then MapLibre GL JS initializes the map on the page and returns your Map object.

Props

  • options
    NameDescription
    options.container
    HTMLElement string
    The HTML element in which MapLibre GL JS will render the map,
    or the element's string id . The specified element must have no children.
    options.minZoom
    number
    default: 0
    The minimum zoom level of the map (0-24).
    options.maxZoom number
    default: 22
    The maximum zoom level of the map (0-24).
    options.minPitch number
    default: 0
    The minimum pitch of the map (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
    options.maxPitch number
    default: 60
    The minimum pitch of the map (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
    options.maxPitch number
    default: 60
    The map's MapLibre style. This must be an a JSON object conforming to the schema described in the MapLibre Style Specification , or a URL to such JSON.
    options.hash boolean string
    default: false
    The map's MapLibre style. This must be an a If true , the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL.
    options.interactive boolean
    default: true
    If false , no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to interaction.
    options.bearingSnap number
    default: 7
    The threshold, measured in degrees, that determines when the map's bearing will snap to north. For example, with a bearingSnap of 7, if the user rotates the map within 7 degrees of north, the map will automatically snap to exact north.
    options.pitchWithRotate boolean
    default: true
    If false , the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
    options.clickTolerance number
    default: 3
    The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag).
    options.attributionControl boolean
    default: true
    If true , an AttributionControl will be added to the map.
    options.attributionControl string Array<string>String or strings to show in an AttributionControl . Only applicable if options.attributionControl is true .
    options.maplibreLogo boolean
    default: false
    If true , the MapLibre logo will be shown.
    options.logoPosition string
    default: bottom-left
    A string representing the position of the MapLibre wordmark on the map. Valid options are top-left , top-right , bottom-left , bottom-right .
    options.failIfMajorPerformanceCaveat boolean
    default: false
    If true , map creation will fail if the performance of MapLibre GL JS would be dramatically worse than expected (i.e. a software renderer would be used).
    options.preserveDrawingBuffer boolean
    default: false
    If true , the map's canvas can be exported to a PNG using map.getCanvas().toDataURL() . This is false by default as a performance optimization.
    options.antialias
    boolean
    If true , the gl context will be created with MSAA antialiasing, which can be useful for antialiasing custom layers. this is false by default as a performance optimization.
    options.refreshExpiredTiles
    boolean
    default: true
    If false , the map won't attempt to re-request tiles once they expire per their HTTP cacheControl / expires headers.
    options.maxBounds
    LngLatBoundsLike
    If set, the map will be constrained to the given bounds.
    options.scrollZoom
    boolean Object
    default: true
    If true , the "scroll to zoom" interaction is enabled. An Object value is passed as options to ScrollZoomHandler#enable .
    options.boxZoom
    boolean
    default: true
    If true , the "box zoom" interaction is enabled (see BoxZoomHandler ).
    options.dragRotate
    boolean
    default: true
    If true , the "drag to rotate" interaction is enabled (see DragRotateHandler ).
    options.dragPan
    boolean Object
    default: true
    If true , the "drag to pan" interaction is enabled. An Object value is passed as options to DragPanHandler#enable .
    options.keyboard
    boolean
    default: true
    If true , keyboard shortcuts are enabled (see KeyboardHandler ).
    options.doubleClickZoom
    boolean
    default: true
    If true , the "double click to zoom" interaction is enabled (see DoubleClickZoomHandler ).
    options.touchZoomRotate
    boolean Object
    default: true
    If true , the "pinch to rotate and zoom" interaction is enabled. An Object value is passed as options to TouchZoomRotateHandler#enable .

Full list of options you can see on API page

Events

@initialized, @error, @load, @idle, @remove, @render, @resize, @webglcontextlost, @webglcontextrestored, @dataloading, @data, @tiledataloading, @sourcedataloading, @styledataloading, @sourcedata, @styledata, @boxzoomcancel, @boxzoomstart, @boxzoomend, @touchcancel, @touchmove, @touchend, @touchstart, @click, @contextmenu, @dblclick, @mousemove, @mouseup, @mousedown, @mouseout, @mouseover, @movestart, @move, @moveend, @zoomstart, @zoom, @zoomend, @rotatestart, @rotate, @rotateend, @dragstart, @drag, @dragend, @pitchstart, @pitch, @pitchend, @wheel,

Full list of events you can see on API page