MglMap

root map Component

Examples

basic map

MglMap will be width: 100%; height: 100%, U need to give a size to .map-container

expand code expand code

API

props

props type required default description
container String | HTMLElement The HTML element in which Mapbox GL JS will render the map, or the element's string id. The specified element must have no children.
minZoom Number 0 The minimum zoom level of the map (0-24).
maxZoom Number 22 The maximum zoom level of the map (0-24).
mapStyle String | Object null The map's Mapbox style. This must be an a JSON object conforming to
the schema described in the Mapbox Style Specification, or a URL to
such JSON.
To load a style from the Mapbox API, you can use a URL of the form mapbox://styles/:owner/:style,
where :owner is your Mapbox account name and :style is the style ID. Or you can use one of the following
the predefined Mapbox styles:
_ mapbox://styles/mapbox/streets-v11
_ mapbox://styles/mapbox/outdoors-v11
_ mapbox://styles/mapbox/light-v10
_ mapbox://styles/mapbox/dark-v10
_ mapbox://styles/mapbox/satellite-v9
_ mapbox://styles/mapbox/satellite-streets-v11
_ mapbox://styles/mapbox/navigation-preview-day-v4
_ mapbox://styles/mapbox/navigation-preview-night-v4
_ mapbox://styles/mapbox/navigation-guidance-day-v4
_ mapbox://styles/mapbox/navigation-guidance-night-v4
Tilesets hosted with Mapbox can be style-optimized if you append ?optimize=true to the end of your style URL, like mapbox://styles/mapbox/streets-v11?optimize=true.
Learn more about style-optimized vector tiles in our API documentation.
hash Boolean false 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.
For example, http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60.
An additional string may optionally be provided to indicate a parameter-styled hash,
e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo
is a custom parameter and bar is an arbitrary hash distinct from the map hash.
interactive Boolean true If false, no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to interaction.
bearingSnap Number 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.
pitchWithRotate Boolean true If false, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
clickTolerance Number 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).
attributionControl Boolean true If true, an {@link AttributionControl} will be added to the map.
customAttribution String | Array String or strings to show in an {@link AttributionControl}. Only applicable if options.attributionControl is true.
logoPosition String "bottom-left" A string representing the position of the Mapbox wordmark on the map. Valid options are top-left,top-right, bottom-left, bottom-right.
failIfMajorPerformanceCaveat Boolean false If true, map creation will fail if the performance of Mapbox
GL JS would be dramatically worse than expected (i.e. a software renderer would be used).
preserveDrawingBuffer Boolean 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.
refreshExpiredTiles Boolean true If false, the map won't attempt to re-request tiles once they expire per their HTTP cacheControl/expires headers.
maxBounds Array If set, the map will be constrained to the given bounds.
scrollZoom Boolean | Object true If true, the "scroll to zoom" interaction is enabled. An Object value is passed as options to {@link ScrollZoomHandler#enable}.
boxZoom Boolean true If true, the "box zoom" interaction is enabled (see {@link BoxZoomHandler}).
dragRotate Boolean true If true, the "drag to rotate" interaction is enabled (see {@link DragRotateHandler}).
dragPan Boolean true If true, the "drag to pan" interaction is enabled. An Object value is passed as options to {@link DragPanHandler#enable}.
keyboard Boolean true If true, keyboard shortcuts are enabled (see {@link KeyboardHandler}).
doubleClickZoom Boolean true If true, the "double click to zoom" interaction is enabled (see {@link DoubleClickZoomHandler}).
touchZoomRotate Boolean | Object true If true, the "pinch to rotate and zoom" interaction is enabled. An Object value is passed as options to {@link TouchZoomRotateHandler#enable}.
trackResize Boolean true If true, the map will automatically resize when the browser window resizes.
center Array | Object [0,0] The inital geographical centerpoint of the map. If center is not specified in the constructor options, Mapbox GL JS 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: Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
zoom Number 0 The initial zoom level of the map. If zoom is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to 0.
bearing Number 0 The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If bearing is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to 0.
pitch Number 0 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, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to 0.
bounds Array | Object The initial bounds of the map. If bounds is specified, it overrides center and zoom constructor options.
renderWorldCopies Boolean true If true, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to false:
- When the map is zoomed out far enough that a single representation of the world does not fill the map's entire
container, there will be blank space beyond 180 and -180 degrees longitude.
- Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
map and the other on the left edge of the map) at every zoom level.
maxTileCacheSize Number 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.
localIdeographFontFamily String Defines a CSS
font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs', 'Hiragana', 'Katakana' 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).
Set to false, to enable font settings from the map's style for these glyph ranges. Note that Mapbox Studio sets this value to false by default.
The purpose of this option is to avoid bandwidth-intensive glyph server requests. (See Use locally generated ideographs.)
transformRequest Function 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.
collectResourceTiming Boolean false If 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.
fadeDuration Number 300 Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
crossSourceCollisions Boolean true If true, symbols from multiple sources can collide with each other during collision detection. If false, collision detection is run separately for the symbols in each source.

events

event name description arguments remark
ready when map is ready no args
load map.on('load') ({ map, component }) map is the mapbox-gl.Map instance
component is the MglMap vue instance
error map.on('error') (err) https://docs.mapbox.com/mapbox-gl-js/api/#map.event:error
style-load when map load new style no args

events for viewport props sync

event name description arguments
update:center for :center.sync='center' (center: LngLatLike)
update:zoom for :zoom.sync='zoom' (zoom: Number)
update:bearing for :bearing.sync='bearing' (bearing: Number)
update:pitch for :pitch.sync='pitch' (pitch: Number)

when map viewport change, the viewport state can be synced from mapbox-gl internal to Application Code

About style-load

when mapStyle change AND mapbox can not do a style diff.
e.g You change map theme from light to dark.
New style will be loaded, this means all your custom layers will be lost, if you do not readd them.
MglSource & MglLayer will utilize this event to readd layers


See

  • https://github.com/mapbox/mapbox-gl-js/blob/v0.42.2/src/ui/map.js#L919
  • https://github.com/mapbox/mapbox-gl-js/blob/v0.42.2/src/style/style.js#L230
  • and style.load will buble to map, can be listened via map.on('style.load')
  MglComponentMixinMglAttributionControl