I am using Proj4js to transform between WGS84 and a local Swedish grid RT90 (EPSG:2400). It works in FF, but in IE the Proj objects often is not readyToUse when I need them to.
I use this code to initialize the transformation objects (part of a bigger object):
wp.js
tera.wp = {
reproject: {
referenceSystem2400: null,
referenceSystem4326: null,
initializeReferenceSystems: function() {
Proj4js.defs["EPSG:2400"] = "+proj=tmerc +lat_0=0 +lon_0=15.80827777777778 +k=1 +x_0=1500000 +y_0=0 +ellps=bessel +units=m +no_defs";
var self = this;
if (self.referenceSystem2400 == null) {
self.referenceSystem2400 = new Proj4js.Proj("EPSG:2400");
}
if (self.referenceSystem4326 == null) {
self.referenceSystem4326 = new Proj4js.Proj("WGS84");
}
var loaded2400 = self.referenceSystem2400.readyToUse;
var loaded4326 = self.referenceSystem4326.readyToUse;
alert("init: " + loaded2400 + ", " + loaded4326);
}
},
init: function() {
var self = this;
self.reproject.initializeReferenceSystems();
// In this call, the transformation is performed
this.repopulateFromSession(function() {
self.disableLoader();
});
},
the web page
<script src="http://maps.google.se/maps/api/js?v=3&sensor=false&language=sv®ion=SE" type="text/javascript"></script>
<script src="/scripts/proj4js/lib/proj4js.js" type="text/javascript"></script>
<script src="/scripts/proj4js/lib/defs/EPSG2400.js" type="text/javascript"></script>
<script src="/scripts/wp/wp.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
tera.wp.init();
});
The explicit declaration of the 2400 parameters is to really ensure that the parameters are ok, and does not have to be loaded from anywhere. (I've been at this a while now)
Although, when I load the page and run the initializeReferenceSystems
function, the alert shows init: false, true
indicating that the 2400 object has not loaded properly.
What can I do to ensure that both my transformation objects are ready to use like this?
Best Answer
It turns out to be the underlying
tmerc
definition that didn't load properly. It's supposed to be loaded dynamically when requesting the 2400 object, since it's based on that projection. But IE must somehow forget to load it, or be too slow or something. My problem disappeared when I included thetmerc
file manually in my html file: