Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

added ol.wv component to worldview source #WV-1675

Benjamin2af80e89ff9b
diff --git a/deploy/wv.js.json b/deploy/wv.js.json
index 598fa842a..1988fd87f 100644
--- a/deploy/wv.js.json
+++ b/deploy/wv.js.json
@@ -1,5 +1,8 @@
{
"wv.js": [
+
+ "webjs/ol.wv/ol.wv.lookupimagetile.js",
+
"web/js/edsc.js",
"web/js/edsc/coordinate.js",
"web/js/edsc/arc.js",
diff --git a/web/index.html b/web/index.html
index 220bfce9e..792794677 100644
--- a/web/index.html
+++ b/web/index.html
@@ -145,6 +145,8 @@
<!-- link.prod --> <!-- <script type="text/javascript" src="js/wv.js?v=20131218215115174&mobile"></script> -->
+ <!-- link.dev --> <script type="text/javascript" src="js/ol.wv/ol.wv.lookupimagetile.js"></script>
+
<!-- link.dev --> <script type="text/javascript" src="js/edsc.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/edsc/coordinate.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/edsc/arc.js"></script>
diff --git a/web/js/ol.wv/ol.wv.lookupimagetile.js b/web/js/ol.wv/ol.wv.lookupimagetile.js
new file mode 100644
index 000000000..7f1d068fa
--- /dev/null
+++ b/web/js/ol.wv/ol.wv.lookupimagetile.js
@@ -0,0 +1,87 @@
+/*
+* NASA Worldview
+*
+* This code was originally developed at NASA/Goddard Space Flight Center for
+* the Earth Science Data and Information System (ESDIS) project.
+*
+* Copyright (C) 2013 - 2015 United States Government as represented by the
+* Administrator of the National Aeronautics and Space Administration.
+* All Rights Reserved.
+*/
+
+ol.wv = {};
+/**
+ * @constructor
+ * @extends {ol.ImageTile}
+ */
+ol.wv.LookupImageTile = function(lookup, tileCoord, state, src, crossOrigin, tileLoadFunction) {
+
+ goog.base(this, tileCoord, state, src, "anonymous", tileLoadFunction);
+
+ /**
+ * @private
+ */
+ this.lookup_ = lookup;
+
+ /**
+ * @private
+ */
+ this.canvas_ = null;
+};
+goog.inherits(ol.wv.LookupImageTile, ol.ImageTile);
+
+/**
+ * @return (HTMLCanvasElement|HTMLImageElement|HTMLVideoElement|null)
+ */
+ol.wv.LookupImageTile.prototype.getImage = function(opt_context) {
+ return this.canvas_;
+};
+
+ol.wv.LookupImageTile.prototype.load = function() {
+
+ if ( this.state === ol.TileState.IDLE ) {
+ this.state = ol.TileState.LOADING;
+ var that = this;
+ this.image_.addEventListener("load", function() {
+ that.canvas_ = document.createElement("canvas");
+ that.canvas_.width = that.image_.width;
+ that.canvas_.height = that.image_.height;
+ var octets = that.canvas_.width * that.canvas_.height * 4;
+ var g = that.canvas_.getContext("2d");
+ g.drawImage(that.image_, 0, 0);
+ var imageData = g.getImageData(0, 0, that.canvas_.width,
+ that.canvas_.height);
+ var pixels = imageData.data;
+
+ for ( var i = 0; i < octets; i += 4 ) {
+ var source = pixels[i + 0] + "," +
+ pixels[i + 1] + "," +
+ pixels[i + 2] + "," +
+ pixels[i + 3];
+ var target = that.lookup_[source];
+
+ if ( target ) {
+ pixels[i + 0] = target["r"];
+ pixels[i + 1] = target["g"];
+ pixels[i + 2] = target["b"];
+ pixels[i + 3] = target["a"];
+ }
+ }
+ g.putImageData(imageData, 0, 0);
+ that.state = ol.TileState.LOADED;
+ that.changed();
+ });
+ this.image_.src = this.src_;
+ };
+
+};
+
+/**
+ * @api
+ */
+ol.wv.LookupImageTile.factory = function(lookup) {
+ return function(tileCoord, state, src, crossOrigin, tileLoadFunction) {
+ return new ol.wv.LookupImageTile(lookup, tileCoord, state, src,
+ crossOrigin, tileLoadFunction);
+ };
+};
\ No newline at end of file