ember-mapbox-gl
ember-mapbox-gl
configmapbox-gl
map-source
map-source-layer
map-on
eventmap-popup
map-image
mapbox-gl-js bindings to Ember. Aims to be a fairly thin wrapper around the mapbox API.
Using this addon will mostly consist of creating a map (or maps), adding sources of data to the map, adding layers to render the data from the sources, and calling functions on the map to manipulate the camera.
Add a mapbox-gl
entry to ENV.
Available properties are documented in the mapbox-gl-js#map API.
accessToken
: Required. Your mapbox token.map
: Optional. Default options for all map instances. Additional options are documented in the mapbox-gl Map docs.background
: Optional. Default options for all background layers.fill
: Optional. Default options for all fill layers.line
: Optional. Default options for all line layers.symbol
: Optional. Default options for all symbol layers.raster
: Optional. Default options for all raster layers.circle
: Optional. Default options for all circle layers.fill-extrusion
: Optional. Default options for all fill-extrusion layers.marker
: Optional. Default options for all markers.popup
: Optional. Default options for all popups.
module.exports = function(environment) {
const ENV = {
// other env properties
'mapbox-gl': {
accessToken: 'YOUR ACCESS TOKEN HERE',
map: {
minZoom: 2,
maxZoom: 14,
style: 'mapbox://styles/mapbox/basic-v9',
zoom: 13,
center: [ -96.7969879, 32.7766642 ]
},
marker: {
offset: [ -1, -1 ]
},
popup: {
offset: [ 0, -10 ]
}
}
};
};
Component that creates a new mapbox-gl-js instance.
initOptions
- An options hash to pass on to the mapbox constructor. This is only used during map construction, and updates will have no effect.
mapLoaded
- action function to call when the map has finished loading. Note that the component does not yield until the map has loaded, so this is the only way to listen for the mapbox load event.
Adds a data source to the map. The API matches the mapbox source docs.
options
- An options hash to set as the source.
options.type
- A string detailing the map source type. Typically
geojson
.
- A string detailing the map source type. Typically
options.data
- A data hash for the map, following the source.data API detailed by mapbox docs.
Adds a layer to the map. A map can have many layers. The API matches the mapbox layer docs.
layer
- A hash to pass on to the mapbox layer.
Adds an action to listen for mapbox events.
eventSource
- The first positional parameter. The event type to listen for.
action
- The second positional parameter. The action provided by the consumer to call when the event is triggered.
import Controller from '@ember/controller';
export default Controller.extend({
actions: {
mapClicked({ target: map, point }) {
console.log(map, point);
}
}
});
Adds a popup to the map.
lngLat
- The longitude and latitude to pin the popup at.
Adds an image for use in the map, see here.
name
- The unique name for the image. The name will be referenced in a source layer as the
icon-image
. Reference layers-symbol for more details. Property can also be used as the first positional parameter.
- The unique name for the image. The name will be referenced in a source layer as the
image
- The path to your image, typically
/assets/<some_image>
. Property can also be used as the second positional parameter.
- The path to your image, typically
width
- The width of the image in pixels.
height
- The height of the image in pixels.
import Controller from '@ember/controller';
export default Controller.extend({
marker: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: { type: 'Point', coordinates: [ -96.7969879, 32.7766642 ] }
}
]
}
});