roemhildtg roemhildtg - 3 months ago 34
Javascript Question

Dojo Build using Proj4 External JS File

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' }`
'dojox', {
name: 'put-selector',
location: 'put-selector',
main: 'put'
name: 'proj4',
location: '//'

Here is the top of the widget:

], function (
) {

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.



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'.