API.md
December 2, 2025 ยท View on GitHub
Table of Contents
Compare
- See: Swipe between maps
Parameters
aObject The first Mapbox GL MapbObject The second Mapbox GL Mapcontainer(string | HTMLElement) An HTML Element, or an element selector string for the compare container. It should be a wrapper around the two map Elements.optionsObjectoptions.orientationstring The orientation of the compare slider.verticalcreates a vertical slider bar to compare one map on the left (map A) with another map on the right (map B).horizontalcreates a horizontal slider bar to compare on mop on the top (map A) and another map on the bottom (map B). (optional, defaultvertical)options.mousemoveboolean Iftruethe compare slider will move with the cursor, otherwise the slider will need to be dragged to move. (optional, defaultfalse)
Examples
var compare = new mapboxgl.Compare(beforeMap, afterMap, '#wrapper', {
orientation: 'vertical',
mousemove: true
});
setSlider
Set the position of the slider.
Parameters
xnumber Slider position in pixels from left/top.
on
Adds a listener for events of a specified type.
Parameters
typestring The event type to listen for; one ofslideend.fnlistenerFunction The function to be called when the event is fired.
Returns Compare this
fire
Fire an event of a specified type.
Parameters
Returns Compare this
off
Removes an event listener previously added with Compare#on.
Parameters
typestring The event type previously used to install the listener.fnlistenerFunction The function previously installed as a listener.
Returns Compare this
remove
Removes the control from the DOM and stop synchronizing the two maps.