API
-
Map
- boxZoom
- doubleClickZoom
- dragPan
- dragRotate
- keyboard
- repaint
- scrollZoom
- showCollisionBoxes
- showTileBoundaries
- touchZoomRotate
- addControl
- addImage
- addLayer
- addSource
- areTilesLoaded
- easeTo
- fitBounds
- flyTo
- getBearing
- getBounds
- getCanvas
- getCanvasContainer
- getCenter
- getContainer
- getFilter
- getLayer
- getLayoutProperty
- getLight
- getMaxBounds
- getMaxZoom
- getMinZoom
- getPaintProperty
- getPitch
- getRenderWorldCopies
- getSource
- getStyle
- getZoom
- hasImage
- isMoving
- isRotating
- isSourceLoaded
- isStyleLoaded
- isZooming
- jumpTo
- loaded
- loadImage
- moveLayer
- off
- on
- panBy
- panTo
- project
- queryRenderedFeatures
- querySourceFeatures
- remove
- removeControl
- removeImage
- removeLayer
- removeSource
- resetNorth
- resize
- rotateTo
- setBearing
- setCenter
- setFilter
- setLayerZoomRange
- setLayoutProperty
- setLight
- setMaxBounds
- setMaxZoom
- setMinZoom
- setPaintProperty
- setPitch
- setRenderWorldCopies
- setStyle
- setZoom
- snapToNorth
- stop
- unproject
- zoomIn
- zoomOut
- zoomTo
- ⓔ boxzoomcancel
- ⓔ boxzoomend
- ⓔ boxzoomstart
- ⓔ click
- ⓔ contextmenu
- ⓔ data
- ⓔ dataloading
- ⓔ dblclick
- ⓔ drag
- ⓔ dragend
- ⓔ dragstart
- ⓔ error
- ⓔ load
- ⓔ mousedown
- ⓔ mouseenter
- ⓔ mouseleave
- ⓔ mousemove
- ⓔ mouseout
- ⓔ mouseover
- ⓔ mouseup
- ⓔ move
- ⓔ moveend
- ⓔ movestart
- ⓔ pitch
- ⓔ pitchend
- ⓔ pitchstart
- ⓔ remove
- ⓔ render
- ⓔ resize
- ⓔ rotate
- ⓔ rotateend
- ⓔ rotatestart
- ⓔ sourcedata
- ⓔ sourcedataloading
- ⓔ styledata
- ⓔ styledataloading
- ⓔ touchcancel
- ⓔ touchend
- ⓔ touchmove
- ⓔ touchstart
- ⓔ webglcontextlost
- ⓔ webglcontextrestored
- ⓔ wheel
- ⓔ zoom
- ⓔ zoomend
- ⓔ zoomstart
- supported
- version
- AnimationOptions
- CameraOptions
- PaddingOptions
- Geography & Geometry
- LngLat
- LngLatLike
- LngLatBounds
- LngLatBoundsLike
- Point
- PointLike
- User Interaction Handlers
- BoxZoomHandler
- ScrollZoomHandler
- DragPanHandler
- DragRotateHandler
- KeyboardHandler
- DoubleClickZoomHandler
- TouchZoomRotateHandler
- Sources
- GeoJSONSource
- VideoSource
- ImageSource
- CanvasSource
- CanvasSourceOptions
- Events
- Evented
- MapMouseEvent
- MapTouchEvent
- MapBoxZoomEvent
- MapDataEvent
- MapWheelEvent
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 Dragonfly initializes the map on the page and returns your Map object. Extends Evented.
new Map(options: Object)
Parameters
options (Object)-
container HTMLElement | stringThe HTML element in which Dragonfly will render the map, or the element's string id . The specified element must have no children.
-
minZoom number default:The minimum zoom level of the map (0-24).
0
-
maxZoom number default:The maximum zoom level of the map (0-24).
22
-
style Object | stringThis must be an a JSON object conforming to the schema described in the Dragonfly Style Specification , or a URL to such JSON.
-
hash boolean default:If
false
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. For example, http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60 . -
interactive boolean default:If
true
false
, no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to interaction. -
bearingSnap number default: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.
7
-
pitchWithRotate boolean default:If
true
false
, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled. -
logoPosition string default:A string representing the position of the Dragonfly wordmark on the map. Valid options are
'bottom-left'
top-left
,top-right
,bottom-left
,bottom-right
. -
failIfMajorPerformanceCaveat boolean default:If
false
true
, map creation will fail if the performance of Dragonfly would be dramatically worse than expected (i.e. a software renderer would be used). -
preserveDrawingBuffer boolean default:If
false
true
, the map's canvas can be exported to a PNG using map.getCanvas().toDataURL() . This isfalse
by default as a performance optimization. -
refreshExpiredTiles boolean default:If
true
false
, the map won't attempt to re-request tiles once they expire per their HTTP cacheControl / expires headers. -
maxBounds LangLatLikeIf set, the map will be constrained to the given bounds.
-
scrollZoom boolean | Object default:If
true
true
, the "scroll to zoom" interaction is enabled. An Object value is passed as options to ScrollZoomHandler#enable . -
boxZoom boolean default:If
true
true
, the "box zoom" interaction is enabled (see BoxZoomHandler ). -
dragRotate boolean default:If
true
true
, the "drag to rotate" interaction is enabled (see DragRotateHandler ). -
dragPan boolean default:If
true
true
, the "drag to pan" interaction is enabled (see DragPanHandler ). -
keyboard boolean default:If
true
true
, keyboard shortcuts are enabled (see KeyboardHandler ). -
doubleClickZoom boolean default:If
true
true
, the "double click to zoom" interaction is enabled (see DoubleClickZoomHandler ). -
touchZoomRotate boolean | Object default:If
true
true
, the "pinch to rotate and zoom" interaction is enabled. An Object value is passed as options to TouchZoomRotateHandler#enable . -
trackResize boolean default:If true, the map will automatically resize when the browser window resizes.
true
-
center LngLatLike default:The inital geographical centerpoint of the map. If center is not specified in the constructor options, Dragonfly will look for it in the map's style object. If it is not specified in the style, either, it will default to [0, 0] Note: Dragonfly uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
[0,0]
-
zoom number default:The initial zoom level of the map. If zoom is not specified in the constructor options, Dragonfly will look for it in the map's style object. If it is not specified in the style, either, it will default to 0 .
0
-
bearing number default:The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If bearing is not specified in the constructor options, Dragonfly will look for it in the map's style object. If it is not specified in the style, either, it will default to 0 .
0
-
pitch number default:The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-60). If pitch is not specified in the constructor options, Dragonfly will look for it in the map's style object. If it is not specified in the style, either, it will default to 0 .
0
-
renderWorldCopies boolean default:If
true
true
, multiple copies of the world will be rendered, when zoomed out. -
maxTileCacheSize number default:The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
null
-
localIdeographFontFamily string default:If specified, defines a CSS font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables' ranges. In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold). The purpose of this option is to avoid bandwidth-intensive glyph server requests.
null
-
transformRequest RequestTransformFunction default:A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests. Expected to return an object with a url property and optionally headers and credentials properties.
null
-
collectResourceTiming boolean default:If
false
true
, Resource Timing API information will be collected for requests made by GeoJSON and Vector Tile web workers (this information is normally inaccessible from the main Javascript thread). Information will be returned in a resourceTiming property of relevant data events.
Example
var map = new dragonfly.Map({ container: 'map', center: [-122.420679, 37.772537], zoom: 13, style: style_object, hash: true, transformRequest: (url, resourceType)=> { if(resourceType == 'Source' && url.startsWith('http://myHost')) { return { url: url.replace('http', 'https'), headers: { 'my-custom-header': true}, credentials: 'include' // Include cookies for cross-origin requests } } } });
Map Instance Properties
-
map.boxZoom: BoxZoomHandler
The map's BoxZoomHandler, which implements zooming using a drag gesture with the Shift key pressed.
-
map.doubleClickZoom: DoubleClickZoomHandler
The map's DoubleClickZoomHandler, which allows the user to zoom by double clicking.
-
map.dragPan: DragPanHandler
The map's DragPanHandler, which implements dragging the map with a mouse or touch gesture.
-
map.dragRotate: DragRotateHandler
The map's DragRotateHandler, which implements rotating the map while dragging with the right mouse button or with the Control key pressed.
-
map.keyboard: KeyboardHandler
The map's KeyboardHandler, which allows the user to zoom, rotate, and pan the map using keyboard shortcuts.
-
map.repaint: boolean
Gets and sets a Boolean indicating whether the map will continuously repaint. This information is useful for analyzing performance.
-
map.scrollZoom: ScrollZoomHandler
The map's ScrollZoomHandler, which implements zooming in and out with a scroll wheel or trackpad.
-
map.showCollisionBoxes: boolean
Gets and sets a Boolean indicating whether the map will render boxes around all symbols in the data source, revealing which symbols were rendered or which were hidden due to collisions. This information is useful for debugging.
-
map.showTileBoundaries: boolean
Gets and sets a Boolean indicating whether the map will render an outline around each tile. These tile boundaries are useful for debugging.
-
map.touchZoomRotate: TouchZoomRotateHandler
The map's TouchZoomRotateHandler,, which allows the user to zoom or rotate the map with touch gestures.
Map Instance Methods
-
map.addControl(control, position?): Mapcontrol(IControl)The IControl to add.position(string?)position on the map to which the control will be added. Valid values are
'top-left'
,'top-right'
,'bottom-left'
, and'bottom-right'
. Defaults to'top-right'
.Adds a IControl to the map.
-
map.addImage(id, image, options)id(string) The ID of the image.image(((HTMLImageElement | ImageData | {width: number, height: number, data: (Uint8Array | Uint8ClampedArray)}))) The image as an HTMLImageElement , ImageData , or object with width , height , and data properties with the same format as ImageData.options(Object)
-
pixelRatio number default:The amount of padding in pixels to add to the given bounds.
1
-
sdf boolean default:Whether the image should be interpreted as an SDF image
false
Add an image to the style. This image can be used in icon-image, background-pattern, fill-pattern, and line-pattern. An Map.error event will be fired if there is not enough space in the sprite to add this image.
-
-
map.addLayer(layer, before?): Maplayer(Object) The style layer to add, conforming to the Dragonfly Style Specification's layer definition.before(string?). The ID of an existing layer to insert the new layer before. If this argument is omitted, the layer will be appended to the end of the layers array.
Adds a Dragonfly style layer to the map's style.
-
map.addSource(id, source): Maplayer(string) The ID of the source to add. Must not conflict with existing sources.before(Object). The source object, conforming to the Dragonfly Style Specification's source definition or CanvasSourceOptions.
Adds a source to the map's style.
-
map.areTilesLoaded(): boolean
Returns a Boolean indicating whether all tiles in the viewport from all sources on the style are loaded.
-
map.easeTo(options, eventData): Mapoptions(any) Options describing the destination and animation of the transition. Accepts CameraOptions and AnimationOptions.eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Changes any combination of center, zoom, bearing, and pitch, with an animated transition between old and new values. The map will retain its current values for any details not specified in options.
-
map.fitBounds(bounds, options, eventData): Mapbounds(LngLatBoundsLike). Center these bounds in the viewport and use the highest zoom level up to and including Map.getMaxZoom that fits them in the viewport.options(Object)
-
padding number | PaddingOptionsThe amount of padding in pixels to add to the given bounds.
-
linear boolean default:If
false
true
, the map transitions using Map.easeTo. Iffalse
, the map transitions using Map.flyTo. See those functions and AnimationOptions for information about options available. -
easing Function?An easing function for the animated transition. See AnimationOptions.
-
offset PointLike default:The center of the given bounds relative to the map's center, measured in pixels.
[0,0]
-
maxZoom number?The maximum zoom level to allow when the map view transitions to the specified bounds.
eventData(Object). Additional properties to be added to event objects of events triggered by this method.Pans and zooms the map to contain its visible area within the specified geographical bounds. This function will also reset the map's bearing to 0 if bearing is nonzero.
var bbox = [[-79, 43], [-73, 45]]; map.fitBounds(bbox, { padding: {top: 10, bottom:25, left: 15, right: 5} });
-
-
map.flyTo(options, eventData): Mapoptions(Object) Options describing the destination and animation of the transition. Accepts CameraOptions , AnimationOptions , and the following additional options.
-
curve number default:The amount of padding in pixels to add to the given bounds.
1.42
-
minZoom number?The zero-based zoom level at the peak of the flight path. If
curve
is specified, this option is ignored. -
speed number default:The average speed of the animation defined in relation to options.curve . A speed of 1.2 means that the map appears to move along the flight path by 1.2 times options.curve screenfuls every second. A screenful is the map's visible span. It does not correspond to a fixed physical distance, but varies by zoom level.
1.2
-
screenSpeed number?The average speed of the animation measured in screenfuls per second, assuming a linear timing curve. If
speed
is specified, this option is ignored. -
maxDuration number?The animation's maximum duration, measured in milliseconds. If duration exceeds maximum duration, it resets to 0.
eventData(Object). Additional properties to be added to event objects of events triggered by this method.Changes any combination of center, zoom, bearing, and pitch, animating the transition along a curve that evokes flight. The animation seamlessly incorporates zooming and panning to help the user maintain her bearings even after traversing a great distance.
// fly with default options to null island map.flyTo({center: [0, 0], zoom: 9}); // using flyTo options map.flyTo({ center: [0, 0], zoom: 9, speed: 0.2, curve: 1, easing(t) { return t; } });
-
-
map.getBearing(): number
Returns the map's current bearing. The bearing is the compass direction that is \"up\"; for example, a bearing of 90° orients the map so that east is up.
-
map.getBounds(): LngLatBounds
Returns the map's geographical bounds.
-
map.getCanvas(): HTMLCanvasElement
Returns the map's
<canvas>
element. -
map.getCanvasContainer(): HTMLCanvasElement
Returns the HTML element containing the map's
<canvas>
element. If you want to add non-GL overlays to the map, you should append them to this element. This is the element to which event bindings for map interactivity (such as panning and zooming) are attached. It will receive bubbled events from child elements such as the<canvas>
, but not from map controls. -
map.getCenter(): LngLat
Returns the map's geographical centerpoint.
-
map.getContainer(): HTMLElement
Returns the map's containing HTML element.
-
map.getFilter(layer): Arraylayer(string) The ID of the style layer whose filter to get.
Returns the filter applied to the specified style layer.
-
map.getLayer(id): Object?id(string) The ID of the layer to get.
Returns the layer with the specified ID in the map's style,or
undefined
if the ID corresponds to no existing layers. -
map.getLayoutProperty(layer, name): anylayer(string) The ID of the layer to get the layout property from.name(string) The name of the layout property to get.
Returns the value of a layout property in the specified style layer.
-
map.getLight(): Object
Returns the value of the light object.
-
map.getMaxBounds(): LngLatBounds | null
Returns the maximum bounds the map is constrained to, or null if none set.
-
map.getMaxZoom(): number
Returns the map's maximum allowable zoom level.
-
map.getMinZoom(): number
Returns the map's minimum allowable zoom level.
-
map.getPaintProperty(layer, name): anylayer(string) The ID of the layer to get the paint property from.name(string) The name of the paint property to get.
Returns the value of a paint property in the specified style layer.
-
map.getPitch(): number
Returns map's current pitch, measured in degrees away from the plane of the screen.
-
map.getRenderWorldCopies(): boolean
Returns the state of renderWorldCopies.
-
map.getSource(id): Objectid(string) The ID of the source to get.
Returns the source with the specified ID,or
undefined
if the ID corresponds to no existing sources. -
map.getStyle(): Object
Returns the map's Dragonfly style object, which can be used to recreate the map's style.
-
map.getZoom(): number
Returns the map's current zoom level.
-
map.hasImage(id): booleanid(string) The ID of the image.
Returns whether the image with that id has been added or not.
-
map.isMoving(): boolean
Returns
true
if the map is panning, zooming, rotating, or pitching due to a camera animation or user gesture. -
map.isRotating(): boolean
Returns
true
if the map is rotating due to a camera animation or user gesture. -
map.isSourceLoaded(id): booleanid(string) The ID of the source to be checked.
Returns a Boolean indicating whether the source is loaded.
-
map.isStyleLoaded(id): boolean
Returns a Boolean indicating whether the map's style is fully loaded.
-
map.isZooming(): boolean
Returns
true
if the map is zooming due to a camera animation or user gesture. -
map.jumpTo(options, eventData): Mapoptions(CameraOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Changes any combination of center, zoom, bearing, and pitch, without an animated transition. The map will retain its current values for any details not specified in
options
. -
map.loaded(): boolean
Returns a Boolean indicating whether the map is fully loaded. Returns
false
if the style is not yet fully loaded, or if there has been a change to the sources or style that has not yet fully loaded. -
map.loadImage(layer, before?): Mapurl(string) The URL of the image file. Image file must be in png, webp, or jpg format.callback(Function) Expecting
callback(error, data)
. Called when the image has loaded or with an error argument if there is an error.Load an image from an external URL for use with Map.addImage. External domains must support CORS.
-
map.moveLayer(layer, before?): Maplayer(Object) The style layer to move.before(string?) The ID of an existing layer to insert the new layer before. If this argument is omitted, the layer will be appended to the end of the layers array.
Moves a layer to a different z-position.
-
map.off(type, listener): Mapmap.off(type, layer, listener): Maptype(string) The event type previously used to install the listener.layer(string) The layer ID previously used to install the listener.listener(Function) The function previously installed as a listener.
Removes an event listener for events previously added with Map.on. Use layer parameter if the listener was added to a specific layer.
-
map.on(type, listener): Mapmap.on(type, layer, listener): Maptype(string) The event type to listen for. One of
'mousedown'
,'mouseup'
,'click'
,'dblclick'
,'mousemove'
,'mouseenter'
,'mouseleave'
,'mouseover'
,'mouseout'
,'contextmenu'
,'touchstart'
,'touchend'
, or'touchcancel'
.mouseenter
andmouseover
events are triggered when the cursor enters a visible portion of the specified layer from outside that layer or outside the map canvas.mouseleave
andmouseout
events are triggered when the cursor leaves a visible portion of the specified layer, or leaves the map canvas.layer(string) The ID of a style layer. Only events whose location is within a visible feature in this layer will trigger the listener. The event will have a features property containing an array of the matching features.listener(Function) The function to be called when the event is fired.Adds a listener for events of a specified type. If layer parameter is present only events occurring on features in a specified style layer are processed.
-
map.panBy(offset, options, eventData): Mapoptions(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Pans the map by the specified
offest
. -
map.panTo(lnglat, options, eventData): Maplnglat(LngLatLike) The location to pan the mapt to.options(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Pans the map to the specified location, with an animated transition.
-
map.project(lnglat): Pointlnglat(LngLatLike) The geographical location to project.
Returns a Point representing pixel coordinates, relative to the map's
container
, that correspond to the specified geographical location. -
map.queryRenderedFeatures( geometry?, options?):Array<Object>geometry(PointLike | Array<PointLike>) he geometry of the query region: either a single point or southwest and northeast points describing a bounding box. Omitting this parameter (i.e. calling Map.queryRenderedFeatures with zero arguments, or with only a options argument) is equivalent to passing a bounding box encompassing the entire map viewport.options(Object)
-
layers Array<string>?An array of style layer IDs for the query to inspect. Only features within these layers will be returned. If this parameter is undefined, all layers will be checked.
-
filter Array?A filter to limit query results.
Returns an array of GeoJSON Feature objects representing visible features that satisfy the query parameters.
The properties value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only string and numeric property values are supported (i.e. null, Array, and Object values are not supported).
Each feature includes a top-level layer property whose value is an object representing the style layer to which the feature belongs. Layout and paint properties in this object contain values which are fully evaluated for the given zoom level and feature.
Features from layers whose
visibility
property is"none"
, or from layers whose zoom range excludes the current zoom level are not included. Symbol features that have been hidden due to text or icon collision are not included. Features from all other layers are included, including features that may have no visible contribution to the rendered result; for example, because the layer's opacity or color alpha component is set to 0.The topmost rendered feature appears first in the returned array, and subsequent features are sorted by descending z-order. Features that are rendered multiple times (due to wrapping across the antimeridian at low zoom levels) are returned only once (though subject to the following caveat).
Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering.
// Find all features at a point var features = map.queryRenderedFeatures( [20, 35], { layers: ['my-layer-name'] } ); // Find all features within a static bounding box var features = map.queryRenderedFeatures( [[10, 20], [30, 50]], { layers: ['my-layer-name'] } ); // Find all features within a bounding box around a point var width = 10; var height = 20; var features = map.queryRenderedFeatures([ [point.x - width / 2, point.y - height / 2], [point.x + width / 2, point.y + height / 2] ], { layers: ['my-layer-name'] }); // Query all rendered features from a single layer var features = map.queryRenderedFeatures({ layers: ['my-layer-name'] }
-
-
map.querySourceFeatures(sourceID, parameters?):Array<Object>sourceIDThe ID of the vector tile or GeoJSON source to query.parameters(Object?)
-
sourceLayers stringThe name of the vector tile layer to query. For vector tile sources, this parameter is required. For GeoJSON sources, it is ignored.
-
filter Array?A filter to limit query results.
Returns an array of GeoJSON Feature objects.
In contrast to Map.queryRenderedFeatures, this function returns all features matching the query parameters, whether or not they are rendered by the current style (i.e. visible). The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport.
Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering.
-
-
map.remove()
Clean up and release all internal resources associated with this map. This includes DOM elements, event bindings, web workers, and WebGL resources. Use this method when you are done using the map and wish to ensure that it no longer consumes browser resources. Afterwards, you must not call any other methods on the map.
-
map.removeControl(control): Mapcontrol(IControl)The IControl to remove.
Remove the control to the map.
-
map.removeImage(id)id(string) The ID of the image.
Remove an image from the style (such as one used by
icon-image
orbackground-pattern
). -
map.removeLayer(id)id(string) The ID of the layer to remove.
Removes the layer with the given id from the map's style. If no such layer exists, an error
event
is fired. -
map.removeSource(id)id(string) The ID of the source to remove.
Removes the source with the given id from the map's style.
-
map.resetNorth(options, eventData): Mapoptions(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Rotates the map so that north is up (0° bearing), with an animated transition.
-
map.resize( eventData): MapeventData(Object). Additional properties to be added to event objects of events triggered by this method.
Resizes the map according to the dimensions of its
container
element. This method must be called after the map'scontainer
is resized by another script, or when the map is shown after being initially hidden with CSS. -
map.rotateto(bearing, options, eventData): Mapbearing(number)options(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Rotates the map to the specified bearing, with an animated transition. The bearing is the compass direction that is \"up\"; for example, a bearing of 90° orients the map so that east is up.
-
map.setBearing(bearing, eventData): Mapbearing(number) The desired bearing.eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Sets the map's bearing (rotation). The bearing is the compass direction that is \"up\"; for example, a bearing of 90° orients the map so that east is up. Equivalent to
jumpTo({bearing: bearing})
.map.setBearing(90);
-
map.setCenter(center, eventData): Mapcenter(LngLatLike) The desired bearing.eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Sets the map's geographical centerpoint. Equivalent to
jumpTo({center: center})
.map.setBearing(90);
-
map.setFilter(layer, filter): Maplayer(string) The ID of the layer to which the filter will be applied.filter(Array | null | undefined) The filter, conforming to the Dragonfly Style Specification's filter definition. If
null
orundefined
, the function removes any existing filter from the layer.Sets the zoom extent for the specified style layer.
map.setLayerZoomRange('my-layer', 2, 5);
-
map.setLayerZoomRange(layer, minzoom, maxzoom): Maplayer(string) The ID of the layer to which the zoom extent will be applied.minzoom(number) The minimum zoom to set (0-24).maxzoom(number) The maximum zoom to set (0-24).
Sets the value of a layout property in the specified style layer.
map.setLayoutProperty('my-layer', 'visibility', 'none');
-
map.setLayoutProperty(layer, name, value): Maplayer(string) The ID of the layer to set the layout property in.name(string) The name of the layout property to set.value(any) The value of the layout propery to set. Must be of a type appropriate for the property, as defined in the Dragonfly Style Specification.
Sets the value of a layout property in the specified style layer.
map.setLayoutProperty('my-layer', 'visibility', 'none');
-
map.setLight(light): Maplight(LightSpecification) Light properties to set. Must conform to the Dragonfly Style Specification.
Sets the any combination of light values.
-
map.setMaxBounds(lnglatbounds): Maplnglatbounds(LngLatLike | null | undefined) The maximum bounds to set. If
null
orundefined
is provided, the function removes map's maximum bounds.Sets or clears the map's geographical bounds. Pan and zoom operations are constrained within these bounds. If a pan or zoom is performed that would display regions outside these bounds, the map will instead display a position and zoom level as close as possible to the operation's request while still remaining within the bounds.
-
map.setMaxZoom(maxZoom): MapmaxZoom(number | null |undefined) The maximum zoom level to set. If
null
orundefined
is provided, the function removes the current maximum zoom (sets it to 22).Sets or clears the map's maximum zoom level. If the map's current zoom level is higher than the new maximum, the map will zoom to the new maximum.
-
map.setMinZoom(minZoom): MapminZoom(number | null |undefined) The minimum zoom level to set (0-24). If
null
orundefined
is provided, the function removes the current minimum zoom (i.e. sets it to 0).Sets or clears the map's minimum zoom level. If the map's current zoom level is lower than the new minimum, the map will zoom to the new minimum.
-
map.setPaintProperty(layer, name, value): Maplayer(string) The ID of the layer to set the paint property in.name(string) The name of the paint property to set.value(any) The value of the paint propery to set. Must be of a type appropriate for the property, as defined in the Dragonfly Style Specification .
Sets the value of a paint property in the specified style layer.
map.setPaintProperty('my-layer', 'fill-color', '#faafee');
-
map.setPitch(pitch, eventData): Mappitch(number) The pitch to set, measured in degrees away from the plane of the screen (0-60).eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Sets the map's pitch (tilt). Equivalent to
jumpTo({pitch: pitch})
. -
map.setRenderWorldCopies( renderWorldCopies ): MapeventData(boolean). If
true
, multiple copies of the world will be rendered, when zoomed out.undefined
is treated astrue
,null
is treated asfalse
.Sets the state of renderWorldCopies
-
map.setStyle(style, options): Mapstyle((StyleSpecification | string | null). A JSON object conforming to the schema described in the Dragonfly Style Specification , or a URL to such JSON.options(Object)
-
diff booleanIf false, force a 'full' update, removing the current style and adding building the given one instead of attempting a diff-based update.
-
localIdeographFontFamily stringIf non-null, defines a css font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables' ranges. Forces a full update.
Updates the map's Dragonfly style object with a new value. If the given value is style JSON object, compares it against the the map's current state and perform only the changes necessary to make the map style match the desired state.
-
-
map.setZoom(zoom, eventData): Mapzoom(number) The zoom level to set (0-20).eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Sets the map's zoom level. Equivalent to
jumpTo({zoom: zoom})
.map.setZoom(5);
-
map.snapToNorth(options, eventData): Mapoptions(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Snaps the map so that north is up (0° bearing), if the current bearing is close enough to it (i.e. within the
bearingSnap
threshold). -
map.stop(): Map
Stops any animated transition underway.
-
map.unproject(point): LngLatpoint(Point) The pixel coordinates to unproject.
Returns a LngLat representing geographical coordinates that correspond to the specified pixel coordinates.
-
map.zoomIn(options, eventData): Mapoptions(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Increases the map's zoom level by 1.
-
map.zoomOut(options, eventData): Mapoptions(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Decreases the map's zoom level by 1.
-
map.zoomTo(zoom, options, eventData): Mapzoom(number) The zoom level to transition to.options(AnimationOptions)eventData(Object). Additional properties to be added to event objects of events triggered by this method.
Decreases the map's zoom level by 1.
Map Events
-
boxzoomcanceldata(ZoomEvent)
Fired when the user cancels a "box zoom" interaction, or when the bounding box does not meet the minimum size threshold. See BoxZoomHandler.
-
boxzoomenddata(ZoomEvent)
Fired when a "box zoom" interaction ends. See BoxZoomHandler.
-
boxzoomstartdata(ZoomEvent)
Fired when a "box zoom" interaction starts. See BoxZoomHandler.
-
clickdata(MapMouseEvent)
Fired when a pointing device (usually a mouse) is pressed and released at the same point on the map.
-
contextmenudata(MapMouseEvent)
Fired when the right button of the mouse is clicked or the context menu key is pressed within the map.
-
datadata(MapDataEvent)
Fired when any map data loads or changes. See MapDataEvent for more information.
-
dataloadingdata(MapDataEvent)
Fired when any map data (style, source, tile, etc) begins loading or changing asyncronously. All
dataloading
events are followed by adata
orerror
event. See MapDataEvent for more information. -
dblclickdata(MapMouseEvent)
Fired when a pointing device (usually a mouse) is clicked twice at the same point on the map.
-
drag
Fired repeatedly during a "drag to pan" interaction. See DragPanHandler.
-
dragenddata(
{originalEvent: DragEvent}
)Fired when a "drag to pan" interaction ends. See DragPanHandler.
-
dragstartdata(
{originalEvent: DragEvent}
)Fired when a "drag to pan" interaction starts. See DragPanHandler.
-
errordata(
{error: {message: string}}
)Fired when an error occurs. This is GL JS's primary error reporting mechanism. We use an event instead of
throw
to better accommodate asyncronous operations. If no listeners are bound to the error event, theerror
will be printed to the console. -
load
Fired immediately after all necessary resources have been downloaded and the first visually complete rendering of the map has occurred.
-
mousedowndata(MapMouseEvent)
Fired when a pointing device (usually a mouse) is pressed within the map.
-
mouseenterdata(MapMouseEvent)
Fired when a pointing device (usually a mouse) enters a visible portion of a specified layer from outside that layer or outside the map canvas. This event can only be listened for via the three-argument version of Map.on, where the second argument specifies the desired layer.
-
mouseleavedata(MapMouseEvent)
Fired when a pointing device (usually a mouse) leaves a visible portion of a specified layer, or leaves the map canvas. This event can only be listened for via the three-argument version of Map.on, where the second argument specifies the desired layer.
-
mousemovedata(MapMouseEvent)
Fired when a pointing device (usually a mouse) is moved within the map.
-
mouseoutdata(MapMouseEvent)
Fired when a point device (usually a mouse) leaves the map's canvas.
-
mouseoverdata(MapMouseEvent)
Fired when a pointing device (usually a mouse) is moved within the map.
-
mouseupdata(MapMouseEvent)
Fired when a pointing device (usually a mouse) is released within the map.
-
move
Fired repeatedly during an animated transition from one view to another, as the result of either user interaction or methods such as Map.flyTo.
-
moveenddata((
{originalEvent: DragEvent}
)Fired just after the map completes a transition from one view to another, as the result of either user interaction or methods such as Map.flyTo.
-
movestartdata((
{originalEvent: DragEvent}
)Fired just before the map begins a transition from one view to another, as the result of either user interaction or methods such as Map.flyTo.
-
pitchdata(MapEventData)
Fired whenever the map's pitch (tilt) changes as. the result of either user interaction or methods such as Map.flyTo.
-
pitchenddata(MapEventData)
Fired immediately after the map's pitch (tilt) finishes changing as the result of either user interaction or methods such as Map.flyTo.
-
pitchstartdata(MapEventData)
Fired whenever the map's pitch (tilt) begins a change as the result of either user interaction or methods such as Map.flyTo.
-
remove
Fired immediately after the map has been removed with Map.remove().
-
render
Fired whenever the map is drawn to the screen, as the result of:
- a change to the map's position, zoom, pitch, or bearing
- a change to the map's style
- a change to a GeoJSON source
- the loading of a vector tile, GeoJSON file, glyph, or sprite
-
resize
Fired immediately after the map has been resized.
-
rotate
Fired repeatedly during a "drag to rotate" interaction. See DragPanHandler.
-
rotateend
Fired when a "drag to rotate" interaction ends. See DragPanHandler.
-
rotatestart
Fired when a "drag to rotate" interaction starts. See DragPanHandler.
-
sourcedatadata(MapDataEvent)
Fired when one of the map's sources loads or changes, including if a tile belonging to a source loads or changes. See MapDataEvent for more information.
-
sourcedataloadingdata(MapDataEvent)
Fired when any map's sources begins loading or changing asyncronously. All
sourcedataloading
events are followed by asourcedata
orerror
event. See MapDataEvent for more information. -
styledatadata(MapDataEvent)
Fired when any map's style loads or changes. See MapDataEvent for more information.
-
styledataloadingdata(MapDataEvent)
Fired when any map style begins loading or changing asyncronously. All
styledataloading
events are followed by astyledata
orerror
event. See MapDataEvent for more information. -
touchcanceldata(MapTouchEvent)
Fired when a
touchcancel
event occurs within the map. -
touchenddata(MapTouchEvent)
Fired when a
touchend
event occurs within the map. -
touchmovedata(MapTouchEvent)
Fired when a
touchmove
event occurs within the map. -
touchstartdata(MapTouchEvent)
Fired when a
touchstart
event occurs within the map. -
webglcontextlost
Fired when the WebGL context is lost.
-
webglcontextrestored
Fired when the WebGL context is restored.
-
wheeldata(MapWheelEvent)
Fired when a
wheel
event occurs within the map. -
zoom
Fired repeatedly during an animated transition from one zoom level to another, as the result of either user interaction or methods such asMap.flyTo.
-
zoomend
Fired repeatedly during an animated transition from one zoom level to another, as the result of either user interaction or methods such asMap.flyTo.
-
zoomstart
Fired just before the map begins a transition from one zoom level to another, as the result of either user interaction or methods such as Map.flyTo.
supported
Test whether the browser supports Dragondfly.
version
The version of Dragonfly in use as specified in package.json, CHANGELOG.md, and the GitHub release.
AnimationOptions
Options common to map movement methods that involve animation, such as Map.panBy and Map.easeTo, controlling the duration and easing function of the animation. All properties are optional.
false
, no animation will occur.
CameraOptions
Options common to Map.jumpTo, Map.easeTo, Map.flyTo, controlling the desired location, zoom, bearing, and pitch of the camera. All properties are optional, and when a property is omitted, the current camera value for that property will remain unchanged.
PaddingOptions
Options for setting padding on a call to Map.fitBounds. All properties of this object must be non-negative integers.
Geography & Geometry
LngLat
and LngLatBounds
represent points and rectanges in geographic coordinates. Point represents points in screen coordinates.
LngLat
A LngLat
object represents a given longitude and latitude coordinate, measured in degrees.
Dragonfly uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
Note that any Dragondly method that accepts a LngLat object as an argument or option can also accept an Array of two numbers and will perform an implicit conversion. This flexible type is documented as LngLatLike.
new LngLat(lng: number, lat: number)
var ll = new dragonfly.LngLat(-73.9749, 40.7736)
Instance Methods
-
LngLat.convert(item): LngLatinput(LngLatLike) An array of two numbers to convert, or a LngLat object to return.
Converts an array of two numbers to a
LngLat
object. If aLngLat
object is passed in, the function returns it unchanged.var arr = [-73.9749, 40.7736]; var ll = dragonfly.LngLat.convert(arr); ll; // = LngLat {lng: -73.9749, lat: 40.7736}
-
toArray(): Array<number>
Returns the coordinates represented as an array of two numbers.
var ll = new dragonfly.LngLat(-73.9749, 40.7736); ll.toArray(); // = [-73.9749, 40.7736]
-
toBounds(radius): LngLatBoundsradius(number) Distance in meters from the coordinates to extend the bounds.
Returns a
LngLatBounds
from the coordinates extended by a givenradius
.var ll = new dragonfly.LngLat(-73.9749, 40.7736); ll.toBounds(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
-
toString(): string
Returns the coordinates represented as a string of the format
'LngLat(lng, lat)'
.var ll = new dragonfly.LngLat(-73.9749, 40.7736); ll.toString(); // = "LngLat(-73.9749, 40.7736)"
-
wrap(): LngLat
Returns a new
LngLat
object whose longitude is wrapped to the range (-180, 180).var ll = new dragonfly.LngLat(286.0251, 40.7736); var wrapped = ll.wrap(); wrapped.lng; // = -73.9749
LngLatLike
A LngLat
an array of two numbers representing longitude and latitude, or an object with lng and lat properties.
var v1 = new dragonfly.LngLat(-122.420679, 37.772537); var v2 = [-122.420679, 37.772537];
LngLatBounds
A LngLatBounds
object represents a geographical bounding box, defined by its southwest and northeast points in longitude and latitude.
If no arguments are provided to the constructor, a null bounding box is created.
Note that any Dragonfly method that accepts a LngLatBounds object as an argument or option can also accept an Array of two LngLatLike constructs and will perform an implicit conversion. This flexible type is documented as LngLatBoundsLike.
new LngLatBounds(sw: LngLatLike?, ne: LngLatLike?)
var sw = new dragonfly.LngLat(-73.9876, 40.7661); var ne = new dragonfly.LngLat(-73.9397, 40.8002); var llb = new dragonfly.LngLatBounds(sw, ne);
Instance Methods
-
LngLatBounds.convert(item): LngLatBoundsinput(LngLatBoundsLike) An array of two numbers to convert, or a LngLatBounds object to return.
Converts an array to a
LngLatBounds
object. If aLngLatBounds
object is passed in, the function returns it unchanged. Internally, the function calls LngLat.convert to convert arrays toLngLat
values.ar arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]]; var llb = dragonfly.LngLatBounds.convert(arr); llb; // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
-
extend(obj): LngLatBounds
Extend the bounds to include a given LngLat or LngLatBounds.
-
getCenter(): LngLat
Returns the geographical coordinate equidistant from the bounding box's corners.
var llb = new dragonfly.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]); llb.getCenter(); // = LngLat {lng: -73.96365, lat: 40.78315}
-
getEast(): number
Returns the east edge of the bounding box.
-
getNorth(): number
Returns the north edge of the bounding box.
-
getNorthEast(): LngLat
Returns the northeast corner of the bounding box.
-
getNorthWest(): LngLat
Returns the northwest corner of the bounding box.
-
getSouth(): number
Returns the south edge of the bounding box.
-
getSouthEast(): LngLat
Returns the southeast corner of the bounding box.
-
getSouthWest(): LngLat
Returns the southwest corner of the bounding box.
-
getWest(): number
Returns the west edge of the bounding box.
-
isEmpty(): boolean
Check if the bounding box is an empty/null-type box. True if bounds have been defined, otherwise false.
-
setNorthEast(ne): LngLatBoundsne(LngLatLike)
Set the northeast corner of the bounding box.
-
setsouthwest(sw): LngLatBoundssw(LngLatLike)
Set the southwest corner of the bounding box.
-
toArray(): Array<Array<number>>
Returns the bounding box represented as an array, consisting of the southwest and northeast coordinates of the bounding represented as arrays of numbers.
var llb = new dragonfly.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]); llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
-
toString(): string
Returns the bounding box represents as a string of the format
'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'
.var llb = new dragonfly.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]); llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
LngLatBoundsLike
A LngLatBounds object, an array of LngLatLike objects in [sw, ne] order, or an array of numbers in [west, south, east, north] order.
var v1 = new dragonfly.LngLatBounds( new dragonfly.LngLat(-73.9876, 40.7661), new dragonfly.LngLat(-73.9397, 40.8002) ); var v2 = new dragonfly.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]) var v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
Point
A Point
geometry object, which has x and y properties representing screen coordinates in pixels.
PointLike
A Point
or an array of two numbers representing x and y screen coordinates in pixels.
User Interaction Handlers Handlers add different kinds of interactivity to the map - mouse interactivity, touch interactions, and other gestures.
BoxZoomHandler
The BoxZoomHandler
allows the user to zoom the map to fit within a bounding box. The bounding box is defined by clicking and holding shift while dragging the cursor.
Instance Methods
-
disable()
Disables the "box zoom" interaction.
map.boxZoom.disable();
-
enable()
Enables the "box zoom" interaction.
map.boxZoom.enable();
-
isactive(): boolean
Returns a Boolean indicating whether the "box zoom" interaction is active, i.e. currently being used.
-
isEnabled(): boolean
Returns a Boolean indicating whether the "box zoom" interaction is enabled.
ScrollZoomHandler
The ScrollZoomHandler
allows the user to zoom the map by scrolling.
Instance Methods
-
disable()
Disables the "scroll to zoom" interaction.
map.scrollZoom.disable();
-
enable(options?)options(Object?)
-
around stringIf "center" is passed, map will zoom around center of map.
Enables the "scroll to zoom" interaction.
map.scrollZoom.enable(); map.scrollZoom.enable({ around: 'center' })
-
-
isEnabled(): boolean
Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
DragPanHandler
The DragPanHandler
allows the user to zoom the map to fit within a bounding box. The bounding box is defined by clicking and holding shift while dragging the cursor.
Instance Methods
-
disable()
Disables the "drag to pan" interaction.
map.dragPan.disable();
-
enable()
Enables the "drag to pan" interaction.
map.dragPan.enable();
-
isactive(): boolean
Returns a Boolean indicating whether the "drag to pan" interaction is active, i.e. currently being used.
-
isEnabled(): boolean
Returns a Boolean indicating whether the "drag to pan" interaction is enabled.
DragRotateHandler
The DragRotateHandler
allows the user to zoom the map to fit within a bounding box. The bounding box is defined by clicking and holding shift while dragging the cursor.
Instance Methods
-
disable()
Disables the "drag to rotate" interaction.
map.dragPan.disable();
-
enable()
Enables the "drag to rotate" interaction.
map.dragPan.enable();
-
isactive(): boolean
Returns a Boolean indicating whether the "drag to rotate" interaction is active, i.e. currently being used.
-
isEnabled(): boolean
Returns a Boolean indicating whether the "drag to rotate" interaction is enabled.
KeyboardHandler
The KeyboardHandler
allows the user to zoom, rotate, and pan the map using the following keyboard shortcuts:
= / +
: Increase the zoom level by 1.Shift-= / Shift-+
: Increase the zoom level by 2.-:
Decrease the zoom level by 1.Shift--
: Decrease the zoom level by 2.Arrow keys
: Pan by 100 pixels.Shift+⇢
: Increase the rotation by 15 degrees.Shift+⇠
: Decrease the rotation by 15 degrees.Shift+⇡
: Increase the pitch by 10 degrees.Shift+⇣
: Decrease the pitch by 10 degrees.
Instance Methods
-
disable()
Disables keyboard interaction.
map.keyboard.disable();
-
enable()
Enables the keyboard interaction.
map.keyboard.enable();
-
isEnabled(): boolean
Returns a Boolean indicating whether the keyboard interaction is enabled.
DoubleClickZoomHandler
The DoubleClickZoomHandler
allows the user to zoom the map at a point by double clicking or double tapping.
Instance Methods
-
disable()
Disables the "double click to zoom" interaction.
map.doubleClickZoom.disable();
-
enable()
Enables the "double click to zoom" interaction.
map.doubleClickZoom.enable();
-
isactive(): boolean
Returns a Boolean indicating whether the "double click to zoom" interaction is active, i.e. currently being used.
-
isEnabled(): boolean
Returns a Boolean indicating whether the "double click to zoom" interaction is enabled.
TouchZoomRotateHandler
The TouchZoomRotateHandler
allows the user to zoom and rotate the map by pinching on a touchscreen.
Instance Methods
-
disable()
Disables the "pinch to rotate and zoom" interaction.
map.touchZoomRotate.disable();
-
disableRotation()
Disables the "pinch to rotate" interaction, leaving the "pinch to zoom" interaction enabled.
map.touchZoomRotate.disableRotation();
-
enable(options?)options(Object?)
-
around stringIf "center" is passed, map will zoom around center of map.
Enables the "pinch to rotate and zoom" interaction.
map.touchZoomRotate.enable(); map.touchZoomRotate.enable({ around: 'center' });
-
-
enableRotation()
Enables the "pinch to rotate" interaction.
map.touchZoomRotate.enableRotation();
-
isEnabled(): boolean
Returns a Boolean indicating whether the "pinch to rotate and zoom" interaction is enabled.
Sources Sources specify the geographic features to be rendered on the map. Source objects may be obtained from Map.getSource.
GeoJSONSource
A source containing GeoJSON. (See the Dragonfly Style Specification for detailed documentation of options.) Extends Evented.
Instance Methods
-
setData(data): GeoJSONSourceoptions(Object | string) A GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files.
Sets the GeoJSON data and re-renders the map.
map.addSource('some id', { type: 'geojson', data: 'url_to_geojson' }); map.addSource('some id', { type: 'geojson', data: { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [ -76.53063297271729, 39.18174077994108 ] } }] } }); map.getSource('some id').setData({ "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "name": "Null Island" }, "geometry": { "type": "Point", "coordinates": [ 0, 0 ] } }] });
VideoSource
A data source containing video. (See the Dragonfly Style Specification for detailed documentation of options.) Extends ImageSource.
Instance Methods
-
getVideo(): HTMLVideoElement
Returns the HTML
video
element. -
setCoordinates(coordinates): VideoSourcecoordinates(Array<Array<number>>) Four geographical coordinates, represented as arrays of longitude and latitude numbers, which define the corners of the video. The coordinates start at the top left corner of the video and proceed in clockwise order. They do not have to represent a rectangle.
Sets the video's coordinates and re-renders the map.
// add to map map.addSource('some id', { type: 'video', url: [ 'assets/videos/SocialExplorerDemo.webm' ], coordinates: [ [-76.54, 39.18], [-76.52, 39.18], [-76.52, 39.17], [-76.54, 39.17] ] }); // update var mySource = map.getSource('some id'); mySource.setCoordinates([ [-76.54335737228394, 39.18579907229748], [-76.52803659439087, 39.1838364847587], [-76.5295386314392, 39.17683392507606], [-76.54520273208618, 39.17876344106642] ]); map.removeSource('some id'); // remove
ImageSource
A data source containing an image. (See the Dragonfly Style Specification for detailed documentation of options.) Extends Evented.
Instance Methods
-
setCoordinates(coordinates): ImageSourcecoordinates(Array<Array<number>>) Four geographical coordinates, represented as arrays of longitude and latitude numbers, which define the corners of the image. The coordinates start at the top left corner of the image and proceed in clockwise order. They do not have to represent a rectangle.
Sets the image's coordinates and re-renders the map.
// add to map map.addSource('some id', { type: 'image', url: 'assets/images/map.jpg', coordinates: [ [-76.54, 39.18], [-76.52, 39.18], [-76.52, 39.17], [-76.54, 39.17] ] }); // update var mySource = map.getSource('some id'); mySource.setCoordinates([ [-76.54335737228394, 39.18579907229748], [-76.52803659439087, 39.1838364847587], [-76.5295386314392, 39.17683392507606], [-76.54520273208618, 39.17876344106642] ]); map.removeSource('some id'); // remove
CanvasSource
A data source containing the contents of an HTML canvas. See CanvasSourceOptions for detailed documentation of options. Extends ImageSource.
Instance Methods
-
getCanvas(): HTMLCanvasElement
Returns the HTML
canvas
element. -
pause()
Disables animation. The map will display a static copy of the canvas image.
-
play()
Enables animation. The image will be copied from the canvas to the map on each frame.
-
setCoordinates(coordinates): CanvasSourcecoordinates(Array<Array<number>>) Four geographical coordinates, represented as arrays of longitude and latitude numbers, which define the corners of the canvas. The coordinates start at the top left corner of the canvas and proceed in clockwise order. They do not have to represent a rectangle.
Sets the canvas's coordinates and re-renders the map.
// add to map map.addSource('some id', { type: 'canvas', canvas: 'idOfMyHTMLCanvas', animate: true, coordinates: [ [-76.54, 39.18], [-76.52, 39.18], [-76.52, 39.17], [-76.54, 39.17] ] }); // update var mySource = map.getSource('some id'); mySource.setCoordinates([ [-76.54335737228394, 39.18579907229748], [-76.52803659439087, 39.1838364847587], [-76.5295386314392, 39.17683392507606], [-76.54520273208618, 39.17876344106642] ]); map.removeSource('some id'); // remove
CanvasSourceOptions
Options to add a canvas source type to the map.
"canvas"
.
HTMLCanvasElement
itself.
[longitude, latitude]
pairs.
animate
should be set to false
to improve performance.
Events Map (and some other classes) emit events in response to user interactions or changes in state. Evented is the interface used to bind and unbind listeners for these events.
Evented
Methods mixed in to other classes for event capabilities.
Instance Methods
-
off(type, listener): Maptype(string) The event type to remove listeners for.listener(Function) The listener function to remove.
Removes a previously registered event listener.
-
on(type, listener): Maptype(string) The event type to add a listener for.listener(Function) The function to be called when the event is fired. The listener function is called with the data object passed to
fire
, extended withtarget
andtype
properties.Adds a listener to a specified event type.
-
once(type, listener): Maptype(string) The event type to listen for.listener(Function) The function to be called when the event is fired the first time.
Adds a listener to a specified event type.
MapMouseEvent
MapMouseEvent
is the event type for mouse-related map events.
Extends Object.
Instance Properties
-
defaultPrevented : boolean
true
ifpreventDefault()
has been called -
lnglat
The geographic location on the map of the mouse cursor.
-
originalEvent
The DOM event which caused the map event.
-
point
The pixel coordinates of the mouse cursor, relative to the map and measured from the top left corner.
-
target
The
Map
object that fired the event. -
type
The event type.
Instance Methods
-
preventDefault()
Prevents subsequent default processing of the event by the map. Calling this method will prevent the following default map behaviors:
- On
mousedown
events, the behavior of DragPanHandler - On
mousedown
events, the behavior of DragRotateHandler - On
mousedown
events, the behavior of BoxZoomHandler - On
dblclick
events, the behavior of DoubleClickZoomHandler
- On
MapTouchEvent
MapTouchEvent
is the event type for touch-related map events.
Extends Object.
Instance Properties
-
defaultPrevented : boolean
true
ifpreventDefault()
has been called -
lnglat
The geographic location on the map of the center of the touch event points.
-
lnglats
The geographical locations on the map corresponding to a touch event's
touches
property. -
map
The
Map
object that fired the event. -
originalEvent
The DOM event which caused the map event.
-
point
The pixel coordinates of the center of the touch event points, relative to the map and measured from the top left corner.
-
points
The array of pixel coordinates corresponding to a touch event's
touches
property. -
type
The event type.
Instance Methods
-
preventDefault()
Prevents subsequent default processing of the event by the map. Calling this method will prevent the following default map behaviors:
- On
touchstart
events, the behavior of DragPanHandler - On
touchstart
events, the behavior of TouchZoomRotateHandler
- On
MapBoxZoomEvent
MapDataEvent
A MapDataEvent
object is emitted with the Map.event:data and Map.event:dataloading events. Possible values for dataTypes
are:
'source'
: The non-tile data associated with any source'style'
: The style used by the map
'source'
, 'style'
.
dataType
of source
and the source has no outstanding network requests.
source
.
dataType
of source
and the event signals that internal data has been received or changed. Possible values are metadata and content .
dataType
of source and the event is related to loading of a tile.
Coordinate?
):The coordinate of the tile if the event has a dataType
of source
and the event is related to loading of a tile.
MapWheelEvent
MapWheelEvent
is the event type for the wheel map event.
Extends Object.
Instance Properties
-
defaultPrevented : boolean
true
ifpreventDefault()
has been called -
map
The
Map
object that fired the event. -
originalEvent
The DOM event which caused the map event.
-
type
The event type.
Instance Methods
-
preventDefault()
Prevents subsequent default processing of the event by the map. Calling this method will prevent the following default map behaviors:
- On
touchstart
events, the behavior of DragPanHandler - On
touchstart
events, the behavior of TouchZoomRotateHandler
- On