1
votes

I'm working on learning how to build an application into a single js file (or close to) using the Dojo Build System. I have followed the instructions to the best of my knowledge and have it working with a basic example. I am now trying to add additional js resources and widgets.

One of my widgets requires the Proj4js projection library to convert between coordinates. Unfortunately this is causing issues when I try to build the app.

error(311) Missing dependency.
module: app/widgets/MapInfo; dependency: proj4/proj4

I have my dojo config for that package set up as follows:

            packages: [
                // Using a string as a package is shorthand for `{ name: 'app', location: 'app' }`
                'app',
                'dgrid',
                'dijit',
                'dojo',
                'dojox', {
                    name: 'put-selector',
                    location: 'put-selector',
                    main: 'put'
                },
                'xstyle',
                'esri',
                {
                    name: 'proj4',
                    location: '//cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/'
                }
            ],

Here is the top of the widget:

define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'dojo/_base/lang',
'dojo/html',
'dojo/dom-style',
'dojo/number',
'dojo/topic',
'proj4/proj4',
'xstyle/css!./MapInfo/css/MapInfo.css'
], function (
declare,
WidgetBase,
TemplatedMixin,
lang,
html,
style,
number,
topic,
proj4
  ) {

Option 1: ignore it I had thought first to try and tell dojo to ignore it, however, after reading some posts this isn't really an option.

Option 2: Use a plugin? My next thought is to try and use a dojo plugin like dojo/text! to include the file, however, I haven't been able to get this to work either.

Option 3: Embed script in page Finally, as a last resort I could simply embed the script using a script tag and reference proj4 via window.proj4 in the widget, but this isn't very portable so I am looking for better solutions.

Thanks!

1
Do you have a typo in your build profile? It says esri but probably should say proj4... - Ken Franqueiro
There's two ways to list packages, one is to simply list the string but another is to list the name of the package and the string. esri is just the name of another dojo package. - twoLeftFeet
Whoops, I misread your build configuration, hence the confusion, sorry about that. (My brain mixed up the esri and proj4 entries.) - Ken Franqueiro
No worries :) It really confused me at first. As it currently is, Dojo's amd require loader seems to have no problem finding the proj4 package, but the builder build tool seems to have an issue. - twoLeftFeet

1 Answers

0
votes

I ended up getting this working by using a local copy of the proj4 library. Then I used the dojo's map property to map proj4 to its correct location:

  map: {
    '*': {
      'viewer': 'cmv/viewer/js/viewer',
      'gis': 'cmv/viewer/js/gis',
      'proj4js': 'app/vendor'
    }
 },

proj4 can now be used by widgets using the path 'proj4js/proj4'.