Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

First view of polar data download

Mike McGann308637659453
diff --git a/etc/ant/js.build.xml b/etc/ant/js.build.xml
index 26950f256..ec452d20f 100644
--- a/etc/ant/js.build.xml
+++ b/etc/ant/js.build.xml
@@ -41,7 +41,14 @@
<file name="ext/jcrop/jcrop.js"/>
<file name="ext/jquery.dd/jquery.dd.js"/>
<file name="ext/jscache/cache.js"/>
-
+
+ <file name="ext/proj4js/proj4js.js"/>
+ <file name="ext/proj4js/merc.js"/>
+ <file name="ext/proj4js/stere.js"/>
+ <file name="ext/proj4js/EPSG_3031.js"/>
+ <file name="ext/proj4js/EPSG_3413.js"/>
+ <file name="ext/proj4js/EPSG_3995.js"/>
+
<file name="js/Date.js"/>
<file name="js/Logging.js"/>
diff --git a/src/ext/proj4js/EPSG_3031.js b/src/ext/proj4js/EPSG_3031.js
new file mode 100644
index 000000000..1b276b81c
--- /dev/null
+++ b/src/ext/proj4js/EPSG_3031.js
@@ -0,0 +1,2 @@
+Proj4js.defs["EPSG:3031"] = "+title=WGS 84 / Antarctic Polar Stereographic +proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs";
+
diff --git a/src/ext/proj4js/EPSG_3413.js b/src/ext/proj4js/EPSG_3413.js
new file mode 100644
index 000000000..e36178903
--- /dev/null
+++ b/src/ext/proj4js/EPSG_3413.js
@@ -0,0 +1,4 @@
+Proj4js.defs["EPSG:3413"] = "+title=WGS 84 / NSIDC Sea Ice Polar Stereographic North +proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs";
+
+
+
diff --git a/src/ext/proj4js/EPSG_3995.js b/src/ext/proj4js/EPSG_3995.js
new file mode 100644
index 000000000..86e3669b3
--- /dev/null
+++ b/src/ext/proj4js/EPSG_3995.js
@@ -0,0 +1,5 @@
+Proj4js.defs["EPSG:3995"] = "+title=WGS 84 / Arctic Polar Stereographic +proj=stere +lat_0=90 +lat_ts=71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs";
+
+
+
+
diff --git a/src/ext/proj4js/merc.js b/src/ext/proj4js/merc.js
new file mode 100644
index 000000000..ebf55a77d
--- /dev/null
+++ b/src/ext/proj4js/merc.js
@@ -0,0 +1,115 @@
+/*******************************************************************************
+NAME MERCATOR
+
+PURPOSE: Transforms input longitude and latitude to Easting and
+ Northing for the Mercator projection. The
+ longitude and latitude must be in radians. The Easting
+ and Northing values will be returned in meters.
+
+PROGRAMMER DATE
+---------- ----
+D. Steinwand, EROS Nov, 1991
+T. Mittan Mar, 1993
+
+ALGORITHM REFERENCES
+
+1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
+ Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
+ State Government Printing Office, Washington D.C., 1987.
+
+2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
+ U.S. Geological Survey Professional Paper 1453 , United State Government
+ Printing Office, Washington D.C., 1989.
+*******************************************************************************/
+
+//static double r_major = a; /* major axis */
+//static double r_minor = b; /* minor axis */
+//static double lon_center = long0; /* Center longitude (projection center) */
+//static double lat_origin = lat0; /* center latitude */
+//static double e,es; /* eccentricity constants */
+//static double m1; /* small value m */
+//static double false_northing = y0; /* y offset in meters */
+//static double false_easting = x0; /* x offset in meters */
+//scale_fact = k0
+
+Proj4js.Proj.merc = {
+ init : function() {
+ //?this.temp = this.r_minor / this.r_major;
+ //this.temp = this.b / this.a;
+ //this.es = 1.0 - Math.sqrt(this.temp);
+ //this.e = Math.sqrt( this.es );
+ //?this.m1 = Math.cos(this.lat_origin) / (Math.sqrt( 1.0 - this.es * Math.sin(this.lat_origin) * Math.sin(this.lat_origin)));
+ //this.m1 = Math.cos(0.0) / (Math.sqrt( 1.0 - this.es * Math.sin(0.0) * Math.sin(0.0)));
+ if (this.lat_ts) {
+ if (this.sphere) {
+ this.k0 = Math.cos(this.lat_ts);
+ } else {
+ this.k0 = Proj4js.common.msfnz(this.es, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
+ }
+ }
+ },
+
+/* Mercator forward equations--mapping lat,long to x,y
+ --------------------------------------------------*/
+
+ forward : function(p) {
+ //alert("ll2m coords : "+coords);
+ var lon = p.x;
+ var lat = p.y;
+ // convert to radians
+ if ( lat*Proj4js.common.R2D > 90.0 &&
+ lat*Proj4js.common.R2D < -90.0 &&
+ lon*Proj4js.common.R2D > 180.0 &&
+ lon*Proj4js.common.R2D < -180.0) {
+ Proj4js.reportError("merc:forward: llInputOutOfRange: "+ lon +" : " + lat);
+ return null;
+ }
+
+ var x,y;
+ if(Math.abs( Math.abs(lat) - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN) {
+ Proj4js.reportError("merc:forward: ll2mAtPoles");
+ return null;
+ } else {
+ if (this.sphere) {
+ x = this.x0 + this.a * this.k0 * Proj4js.common.adjust_lon(lon - this.long0);
+ y = this.y0 + this.a * this.k0 * Math.log(Math.tan(Proj4js.common.FORTPI + 0.5*lat));
+ } else {
+ var sinphi = Math.sin(lat);
+ var ts = Proj4js.common.tsfnz(this.e,lat,sinphi);
+ x = this.x0 + this.a * this.k0 * Proj4js.common.adjust_lon(lon - this.long0);
+ y = this.y0 - this.a * this.k0 * Math.log(ts);
+ }
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+ },
+
+
+ /* Mercator inverse equations--mapping x,y to lat/long
+ --------------------------------------------------*/
+ inverse : function(p) {
+
+ var x = p.x - this.x0;
+ var y = p.y - this.y0;
+ var lon,lat;
+
+ if (this.sphere) {
+ lat = Proj4js.common.HALF_PI - 2.0 * Math.atan(Math.exp(-y / this.a * this.k0));
+ } else {
+ var ts = Math.exp(-y / (this.a * this.k0));
+ lat = Proj4js.common.phi2z(this.e,ts);
+ if(lat == -9999) {
+ Proj4js.reportError("merc:inverse: lat = -9999");
+ return null;
+ }
+ }
+ lon = Proj4js.common.adjust_lon(this.long0+ x / (this.a * this.k0));
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+};
+
+
diff --git a/src/ext/proj4js/stere.js b/src/ext/proj4js/stere.js
new file mode 100644
index 000000000..8575ffcd6
--- /dev/null
+++ b/src/ext/proj4js/stere.js
@@ -0,0 +1,247 @@
+
+// Initialize the Stereographic projection
+
+Proj4js.Proj.stere = {
+ ssfn_: function(phit, sinphi, eccen) {
+ sinphi *= eccen;
+ return (Math.tan (.5 * (Proj4js.common.HALF_PI + phit)) * Math.pow((1. - sinphi) / (1. + sinphi), .5 * eccen));
+ },
+ TOL: 1.e-8,
+ NITER: 8,
+ CONV: 1.e-10,
+ S_POLE: 0,
+ N_POLE: 1,
+ OBLIQ: 2,
+ EQUIT: 3,
+
+ init: function() {
+ this.phits = this.lat_ts ? this.lat_ts : Proj4js.common.HALF_PI;
+ var t = Math.abs(this.lat0);
+ if ((Math.abs(t) - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
+ this.mode = this.lat0 < 0. ? this.S_POLE : this.N_POLE;
+ } else {
+ this.mode = t > Proj4js.common.EPSLN ? this.OBLIQ : this.EQUIT;
+ }
+ this.phits = Math.abs(this.phits);
+ if (this.es) {
+ var X;
+
+ switch (this.mode) {
+ case this.N_POLE:
+ case this.S_POLE:
+ if (Math.abs(this.phits - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
+ this.akm1 = 2. * this.k0 / Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e));
+ } else {
+ t = Math.sin(this.phits);
+ this.akm1 = Math.cos(this.phits) / Proj4js.common.tsfnz(this.e, this.phits, t);
+ t *= this.e;
+ this.akm1 /= Math.sqrt(1. - t * t);
+ }
+ break;
+ case this.EQUIT:
+ this.akm1 = 2. * this.k0;
+ break;
+ case this.OBLIQ:
+ t = Math.sin(this.lat0);
+ X = 2. * Math.atan(this.ssfn_(this.lat0, t, this.e)) - Proj4js.common.HALF_PI;
+ t *= this.e;
+ this.akm1 = 2. * this.k0 * Math.cos(this.lat0) / Math.sqrt(1. - t * t);
+ this.sinX1 = Math.sin(X);
+ this.cosX1 = Math.cos(X);
+ break;
+ }
+ } else {
+ switch (this.mode) {
+ case this.OBLIQ:
+ this.sinph0 = Math.sin(this.lat0);
+ this.cosph0 = Math.cos(this.lat0);
+ case this.EQUIT:
+ this.akm1 = 2. * this.k0;
+ break;
+ case this.S_POLE:
+ case this.N_POLE:
+ this.akm1 = Math.abs(this.phits - Proj4js.common.HALF_PI) >= Proj4js.common.EPSLN ?
+ Math.cos(this.phits) / Math.tan(Proj4js.common.FORTPI - .5 * this.phits) :
+ 2. * this.k0 ;
+ break;
+ }
+ }
+ },
+
+// Stereographic forward equations--mapping lat,long to x,y
+ forward: function(p) {
+ var lon = p.x;
+ lon = Proj4js.common.adjust_lon(lon - this.long0);
+ var lat = p.y;
+ var x, y;
+
+ if (this.sphere) {
+ var sinphi, cosphi, coslam, sinlam;
+
+ sinphi = Math.sin(lat);
+ cosphi = Math.cos(lat);
+ coslam = Math.cos(lon);
+ sinlam = Math.sin(lon);
+ switch (this.mode) {
+ case this.EQUIT:
+ y = 1. + cosphi * coslam;
+ if (y <= Proj4js.common.EPSLN) {
+ Proj4js.reportError("stere:forward:Equit");
+ }
+ y = this.akm1 / y;
+ x = y * cosphi * sinlam;
+ y *= sinphi;
+ break;
+ case this.OBLIQ:
+ y = 1. + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
+ if (y <= Proj4js.common.EPSLN) {
+ Proj4js.reportError("stere:forward:Obliq");
+ }
+ y = this.akm1 / y;
+ x = y * cosphi * sinlam;
+ y *= this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
+ break;
+ case this.N_POLE:
+ coslam = -coslam;
+ lat = -lat;
+ //Note no break here so it conitnues through S_POLE
+ case this.S_POLE:
+ if (Math.abs(lat - Proj4js.common.HALF_PI) < this.TOL) {
+ Proj4js.reportError("stere:forward:S_POLE");
+ }
+ y = this.akm1 * Math.tan(Proj4js.common.FORTPI + .5 * lat);
+ x = sinlam * y;
+ y *= coslam;
+ break;
+ }
+ } else {
+ coslam = Math.cos(lon);
+ sinlam = Math.sin(lon);
+ sinphi = Math.sin(lat);
+ var sinX, cosX;
+ if (this.mode == this.OBLIQ || this.mode == this.EQUIT) {
+ var Xt = 2. * Math.atan(this.ssfn_(lat, sinphi, this.e));
+ sinX = Math.sin(Xt - Proj4js.common.HALF_PI);
+ cosX = Math.cos(Xt);
+ }
+ switch (this.mode) {
+ case this.OBLIQ:
+ var A = this.akm1 / (this.cosX1 * (1. + this.sinX1 * sinX + this.cosX1 * cosX * coslam));
+ y = A * (this.cosX1 * sinX - this.sinX1 * cosX * coslam);
+ x = A * cosX;
+ break;
+ case this.EQUIT:
+ var A = 2. * this.akm1 / (1. + cosX * coslam);
+ y = A * sinX;
+ x = A * cosX;
+ break;
+ case this.S_POLE:
+ lat = -lat;
+ coslam = - coslam;
+ sinphi = -sinphi;
+ case this.N_POLE:
+ x = this.akm1 * Proj4js.common.tsfnz(this.e, lat, sinphi);
+ y = - x * coslam;
+ break;
+ }
+ x = x * sinlam;
+ }
+ p.x = x*this.a + this.x0;
+ p.y = y*this.a + this.y0;
+ return p;
+ },
+
+
+//* Stereographic inverse equations--mapping x,y to lat/long
+ inverse: function(p) {
+ var x = (p.x - this.x0)/this.a; /* descale and de-offset */
+ var y = (p.y - this.y0)/this.a;
+ var lon, lat;
+
+ var cosphi, sinphi, tp=0.0, phi_l=0.0, rho, halfe=0.0, pi2=0.0;
+ var i;
+
+ if (this.sphere) {
+ var c, rh, sinc, cosc;
+
+ rh = Math.sqrt(x*x + y*y);
+ c = 2. * Math.atan(rh / this.akm1);
+ sinc = Math.sin(c);
+ cosc = Math.cos(c);
+ lon = 0.;
+ switch (this.mode) {
+ case this.EQUIT:
+ if (Math.abs(rh) <= Proj4js.common.EPSLN) {
+ lat = 0.;
+ } else {
+ lat = Math.asin(y * sinc / rh);
+ }
+ if (cosc != 0. || x != 0.) lon = Math.atan2(x * sinc, cosc * rh);
+ break;
+ case this.OBLIQ:
+ if (Math.abs(rh) <= Proj4js.common.EPSLN) {
+ lat = this.phi0;
+ } else {
+ lat = Math.asin(cosc * this.sinph0 + y * sinc * this.cosph0 / rh);
+ }
+ c = cosc - this.sinph0 * Math.sin(lat);
+ if (c != 0. || x != 0.) {
+ lon = Math.atan2(x * sinc * this.cosph0, c * rh);
+ }
+ break;
+ case this.N_POLE:
+ y = -y;
+ case this.S_POLE:
+ if (Math.abs(rh) <= Proj4js.common.EPSLN) {
+ lat = this.phi0;
+ } else {
+ lat = Math.asin(this.mode == this.S_POLE ? -cosc : cosc);
+ }
+ lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y);
+ break;
+ }
+ p.x = Proj4js.common.adjust_lon(lon + this.long0);
+ p.y = lat;
+ } else {
+ rho = Math.sqrt(x*x + y*y);
+ switch (this.mode) {
+ case this.OBLIQ:
+ case this.EQUIT:
+ tp = 2. * Math.atan2(rho * this.cosX1 , this.akm1);
+ cosphi = Math.cos(tp);
+ sinphi = Math.sin(tp);
+ if( rho == 0.0 ) {
+ phi_l = Math.asin(cosphi * this.sinX1);
+ } else {
+ phi_l = Math.asin(cosphi * this.sinX1 + (y * sinphi * this.cosX1 / rho));
+ }
+
+ tp = Math.tan(.5 * (Proj4js.common.HALF_PI + phi_l));
+ x *= sinphi;
+ y = rho * this.cosX1 * cosphi - y * this.sinX1* sinphi;
+ pi2 = Proj4js.common.HALF_PI;
+ halfe = .5 * this.e;
+ break;
+ case this.N_POLE:
+ y = -y;
+ case this.S_POLE:
+ tp = - rho / this.akm1;
+ phi_l = Proj4js.common.HALF_PI - 2. * Math.atan(tp);
+ pi2 = -Proj4js.common.HALF_PI;
+ halfe = -.5 * this.e;
+ break;
+ }
+ for (i = this.NITER; i--; phi_l = lat) { //check this
+ sinphi = this.e * Math.sin(phi_l);
+ lat = 2. * Math.atan(tp * Math.pow((1.+sinphi)/(1.-sinphi), halfe)) - pi2;
+ if (Math.abs(phi_l - lat) < this.CONV) {
+ if (this.mode == this.S_POLE) lat = -lat;
+ lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y);
+ p.x = Proj4js.common.adjust_lon(lon + this.long0);
+ p.y = lat;
+ return p;
+ }
+ }
+ }
+ }
+};
diff --git a/src/index.html b/src/index.html
index ec600dc65..c8649d8aa 100644
--- a/src/index.html
+++ b/src/index.html
@@ -99,6 +99,13 @@
<!-- link.dev --> <script type="text/javascript" src="ext/joyride/jquery.joyride.js"></script>
<!-- link.dev --> <script type="text/javascript" src="ext/joyride/modernizr.mq.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="ext/proj4js/proj4js.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="ext/proj4js/merc.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="ext/proj4js/stere.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="ext/proj4js/EPSG_3031.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="ext/proj4js/EPSG_3413.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="ext/proj4js/EPSG_3995.js"></script>
+
<!-- link.dev --> <script type="text/javascript" src="ext/openlayers/OpenLayers.debug.js?mobile"></script>
<!-- link.dev --> <script type="text/javascript" src="ext/jcrop/jcrop.js"></script>
<!-- link.dev --> <script type="text/javascript" src="ext/jquery.dd/jquery.dd.js"></script>
diff --git a/src/js/Worldview/DataDownload/ControlDialog.js b/src/js/Worldview/DataDownload/ControlDialog.js
index b4fa47181..9daa287f0 100644
--- a/src/js/Worldview/DataDownload/ControlDialog.js
+++ b/src/js/Worldview/DataDownload/ControlDialog.js
@@ -13,7 +13,7 @@ Worldview.namespace("DataDownload");
Worldview.DataDownload.ControlDialog = function(model) {
var WIDTH = 345;
- var HEIGHT = 265;
+ var HEIGHT = 65;
var X_OFFSET = 50;
var Y_OFFSET = 75;
var dialog;
diff --git a/src/js/Worldview/DataDownload/ECHOGeometry.js b/src/js/Worldview/DataDownload/ECHOGeometry.js
index 321e5ded5..d56477f9c 100644
--- a/src/js/Worldview/DataDownload/ECHOGeometry.js
+++ b/src/js/Worldview/DataDownload/ECHOGeometry.js
@@ -27,14 +27,15 @@ Worldview.DataDownload.ECHOGeometry = function(result) {
}
};
- self.toOpenLayers = function() {
+ self.toOpenLayers = function(sourceProjection, targetProjection) {
olPolygons = [];
$.each(self.polygons, function(index, polygon) {
var olRings = [];
$.each(polygon, function(index, ring) {
var olPoints = [];
$.each(ring, function(index, point) {
- var p = new OpenLayers.Geometry.Point(point.x, point.y);
+ var p = createPoint(point, sourceProjection,
+ targetProjection);
olPoints.push(p);
});
olRings.push(new OpenLayers.Geometry.LinearRing(olPoints));
@@ -44,6 +45,16 @@ Worldview.DataDownload.ECHOGeometry = function(result) {
return new OpenLayers.Geometry.MultiPolygon(olPolygons);
};
+ var createPoint = function(point, sourceProjection, targetProjection) {
+ var p = new OpenLayers.Geometry.Point(point.x, point.y);
+ if ( sourceProjection ) {
+ if ( sourceProjection !== targetProjection ) {
+ p = p.transform(sourceProjection, targetProjection);
+ }
+ }
+ return p;
+ };
+
var initFromPolygons = function(echoPolygons) {
$.each(echoPolygons, function(index, echoPolygon) {
var rings = [];
diff --git a/src/js/Worldview/DataDownload/MapView.js b/src/js/Worldview/DataDownload/MapView.js
index caf34f9ca..a37f70f8e 100644
--- a/src/js/Worldview/DataDownload/MapView.js
+++ b/src/js/Worldview/DataDownload/MapView.js
@@ -40,6 +40,7 @@ Worldview.DataDownload.MapView = function(model, maps, config) {
});
model.events
+ .on("query", clear)
.on("queryResults", onQueryResults)
.on("projectionUpdate", onProjectionUpdate)
.on("deactivate", onDeactivate)
@@ -67,13 +68,14 @@ Worldview.DataDownload.MapView = function(model, maps, config) {
result.geometry = {};
}
if ( !result.geometry[model.epsg] ) {
- g = Worldview.DataDownload.ECHOGeometry(result).toOpenLayers();
+ g = Worldview.DataDownload.ECHOGeometry(result)
+ .toOpenLayers("EPSG:4326", "EPSG:" + model.epsg);
result.geometry[model.epsg] = g;
}
var geometry = result.geometry[model.epsg];
var extent = bounds[model.projection];
var geoBounds = geometry.getBounds();
- if ( extent.containsBounds(geoBounds) ) {
+ if ( extent.intersectsBounds(geoBounds) ) {
var feature = new OpenLayers.Feature.Vector(
geometry.getCentroid(),
{ result: result }
@@ -120,6 +122,7 @@ Worldview.DataDownload.MapView = function(model, maps, config) {
var onProjectionUpdate = function() {
console.log("projection", model.projection, model.epsg);
+ updateGranules();
};
var onDeactivate = function() {
@@ -155,6 +158,17 @@ Worldview.DataDownload.MapView = function(model, maps, config) {
hoverLayer.removeAllFeatures();
};
+ var clear = function() {
+ var hoverLayer = maps.map.getLayersByName(HOVER_LAYER_NAME)[0];
+ if ( hoverLayer ) {
+ hoverLayer.removeAllFeatures();
+ }
+ var buttonLayer = maps.map.getLayersByName(BUTTON_LAYER_NAME)[0];
+ if ( buttonLayer ) {
+ buttonLayer.removeAllFeatures();
+ }
+ };
+
init();
return self;
}
diff --git a/src/js/Worldview/DataDownload/Model.js b/src/js/Worldview/DataDownload/Model.js
index 2a419488e..9a2cdc035 100644
--- a/src/js/Worldview/DataDownload/Model.js
+++ b/src/js/Worldview/DataDownload/Model.js
@@ -21,7 +21,13 @@ Worldview.namespace("DataDownload");
*/
Worldview.DataDownload.Model = function(config) {
- var state = {};
+ var state = {
+ productsString: null,
+ projection: null,
+ epsg: null,
+ time: null
+ };
+
var client = Worldview.DataDownload.ECHOClient();
var self = {};
@@ -149,17 +155,24 @@ Worldview.DataDownload.Model = function(config) {
};
self.update = function(newState) {
- if ( newState.productsString !== state.productsString ) {
- updateLayers(newState);
+ var oldState = state;
+ state = newState;
+ if ( oldState.productsString !== state.productsString ) {
+ updateLayers();
+ }
+ if ( oldState.projection !== state.projection ||
+ oldState.epsg !== state.epsg ) {
+ updateProjection();
}
- if ( newState.projection !== state.projection ||
- newState.epsg !== state.epsg ) {
- updateProjection(newState);
+ if ( oldState.time !== state.time ) {
+ query();
}
- state = newState;
};
var query = function() {
+ if ( !self.active ) {
+ return;
+ }
var layerConfig = config.products[self.selectedLayer];
if ( !layerConfig.echo ) {
self.events.trigger(self.EVENT_QUERY_RESULTS, []);
@@ -174,9 +187,12 @@ Worldview.DataDownload.Model = function(config) {
client.query(parameters);
};
- var updateLayers = function(newState) {
+ var updateLayers = function() {
+ if ( !state.products ) {
+ return;
+ }
self.layers = [];
- $.each(newState.products, function(index, layer) {
+ $.each(state.products, function(index, layer) {
var id = layer;
var layerName = config.products[layer].name;
var description = config.products[layer].description;
@@ -194,9 +210,12 @@ Worldview.DataDownload.Model = function(config) {
self.events.trigger(self.EVENT_LAYER_UPDATE);
};
- var updateProjection = function(newState) {
- self.projection = newState.projection;
- self.epsg = newState.epsg;
+ var updateProjection = function() {
+ if ( !state.projection || !state.epsg ) {
+ return;
+ }
+ self.projection = state.projection;
+ self.epsg = state.epsg;
self.events.trigger(self.EVENT_PROJECTION_UPDATE, self.projection,
self.epsg);
};
diff --git a/src/js/Worldview/Events.js b/src/js/Worldview/Events.js
index 481d7acd5..1b5ceee79 100644
--- a/src/js/Worldview/Events.js
+++ b/src/js/Worldview/Events.js
@@ -102,16 +102,24 @@ Worldview.Events = function() {
* @return {Events} this object useful for chaining.
*/
self.trigger = function(event) {
- var listeners = types[event];
- if ( !listeners ) {
- return;
- }
- var eventArguments = Array.prototype.slice.call(arguments, 1);
- $.each(types[event], function(index, listener) {
- listener.apply(self, eventArguments);
- });
+ try {
+ var listeners = types[event];
+ if ( !listeners ) {
+ return;
+ }
+ var eventArguments = Array.prototype.slice.call(arguments, 1);
+ $.each(types[event], function(index, listener) {
+ listener.apply(self, eventArguments);
+ });
+ } catch ( error ) {
+ Worldview.Events.errorHandler(error);
+ }
return self;
};
return self;
-}
+};
+
+Worldview.Events.errorHandler = function(error) {
+ Logging.getLogger("Worldview.Events").error("Error in listener", error);
+};
diff --git a/src/js/main.js b/src/js/main.js
index f0494d0c6..d124249e7 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -46,6 +46,10 @@ $(function() {// Initialize "static" vars
};
var entryPoint = function() {
+ Worldview.Events.errorHandler = function(error) {
+ Worldview.error("Internal error", error);
+ };
+
//console.log("entryPoint");
Worldview.Support.quirks();