How to load leaflet.js and leaflet plugins with dojo AMD

<script type="text/javascript">
var dojoConfig = {
  baseUrl: '/lib',
  async: true,
  packages: [
    {name: 'Leaflet', location: './Leaflet'}
  ],
  map: {
    // lets you switch between minified and source version of leaflet for development
    '*': {
      'Leaflet/leaflet': 'Leaflet/leaflet-src'
    }
  }
};
</script>
<script type="text/javascript" src="lib/dojo/dojo.js"></script>

<script type="text/javascript">
require([
  'require',
  'Leaflet/leaflet'
], function(require, L) {

  // load plugin after loading leaflet, because it's referenced by the draw plugin
  require(['Leaflet/plugins/draw/leaflet.draw'], function() {

    var drawControl = new L.Control.Draw({...}),
    map = L.map(...);
    ...

  }):
});

Leave a comment

Your email address will not be published. Required fields are marked *