This guide will help you get started with Ember Mapbox Composer. After completion you will have a collection of layer-groups visible on a map.
- Install the addon:
ember install ember-mapbox-composer
- Install Mapbox GL:
yarn add mapbox-gl
- Add
mapbox-gl
to theENV
object inconfig/environment.js
:
'mapbox-gl': {
accessToken: '',
map: {
style: 'https://layers-api-staging.planninglabs.nyc/v1/base/style.json',
},
},
- Add the
labs-map
component toapplication.hbs
{{labs-map id="map"}}
This will render a map with the environment’s base style.
(Remember to give #map
a height in your CSS.)
- Add
host
to theENV
object, pointing to the Labs Layers API:
host: 'https://layers-api-staging.planninglabs.nyc',
- Generate an application adapter if it does not exist:
ember g adapter application
- Set up
adapters/application.js
to query to the Layers API:
import DS from 'ember-data';
import config from '../config/environment';
const { host } = config;
const { JSONAPIAdapter } = DS;
export default class ApplicationAdapter extends JSONAPIAdapter {
host = host;
namespace = 'v1';
async query(store, type, query = {}) {
const URL = this.buildURL(type.modelName);
return fetch(`${URL}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(query),
}).then(blob => blob.json());
}
}
- Generate an application route if it does not exist:
ember g route application
- In
routes/application.js
define which layer groups will be queried from the API:
async model() {
const layerGroups = await this.store.query('layer-group', {
'layer-groups': [
{ id: 'subway', visible: true },
{ id: 'floodplain-efirm2007', visible: true },
],
});
return {
layerGroups,
}
}
- Add
labs-layers
component to the map:
{{#labs-map id='map' as |map|}}
{{map.labs-layers layerGroups=model.layerGroups}}
{{/labs-map}}