How are you loading proj4js
?
If you're using AMD style then you'll need to wrap it up a bit like this:
require([
"//cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4.js"
], function(proj4) {
var url = 'http://epsg.io/2193.js';
window.proj4 = proj4; // add to global scope
require([url], function() {
// now you can use proj4 with NZTM loaded in this block.
);
});
That seems a little magical to me, because you're hoping that proj4
will always be the correct name and you're adding proj4
to the global scope, which is a little unclean. I'd be inclined to use the .proj4
extension with the dojo/text
AMD plugin:
require([
"//cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4.js"
"dojo/text!http://epsg.io/2193.proj4"
], function(proj4, epsg2193) {
proj4.defs(epsg2193);
// now you can use proj4 with NZTM loaded.
});
That means you can load both resources simultaneously.
Unfortunately it looks like that lack of Access-Control-Allow-Origin
headers on the response breaks that approach, but you could look at proxying it through your own domain if you need the performance.
BTW, you could cheat a bit on the first option by defining a fake proj
object:
var Proj4Proxy = function() {
this._defs = [];
}
Proj4Proxy.prototype.defs = function(crs) { this._defs.push(crs); };
var proj4 = new Proj4Proxy();
require([
"dojo/_base/array",
"//cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4.js",
"//epsg.io/2193.js"
], function(array, _proj4) {
array.forEach(proj4._defs, function(crs) { _proj4.defs(crs); });
proj4 = _proj4;
// now you can use proj4 with NZTM loaded.
});
Best of both worlds, if you don't mind the verbosity.