mardi 8 janvier 2019

Ember 3.6 super-rentals tutorial LEAFLET_MAPS_API_KEY using environment.js

While going through the ember 3.6 super-rentals tutorial I ran into a few snags adding the ember-simple-leaflet-maps. I couldn't get the environment variable LEAFLET_MAPS_API_KEY to set. https://guides.emberjs.com/release/tutorial/service/

To my understanding, the tutorial has you set an environment variable on your operating system? Maybe I'm wrong in thinking that, but I wanted a way to just add the variable to my project /config/environment.js

After the addon was installed:

ember install ember-simple-leaflet-maps

I opened the geocode.js file to see how the service was injecting the api key. Path is: node_modules\ember-simple-leaflet-maps\addon\services\geocode.js

The line of code was:

let accessToken = getOwner(this).resolveRegistration('config:environment')['ember-simple-leaflet-maps'].apiKey;

From there I just added the lookup it was looking for to my file /config/environment.js

let ENV = {
    modulePrefix: 'super-rentals',
    environment,
    rootURL: '/',
    locationType: 'auto',
    'ember-simple-leaflet-maps': {
      apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    },
    EmberENV: {
      FEATURES: {
        // Here you can enable experimental features on an ember canary build
        // e.g. 'with-controller': true
      },
      EXTEND_PROTOTYPES: {
        // Prevent Ember Data from overriding Date.parse.
        Date: false
      }
    },

    APP: {
      // Here you can pass flags/options to your application instance
      // when it is created
    }
  };

Rebuild the project and serve, my maps are now showing up

ember build
ember serve




Aucun commentaire:

Enregistrer un commentaire