Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Finished refactoring for now

Mike McGann223a74ef9366
diff --git a/Gruntfile.js b/Gruntfile.js
index 7eefee18f..82a27e292 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -82,7 +82,7 @@ module.exports = function(grunt) {
src: [
"css/pages.css",
"css/bulkDownload.css",
- "js/Worldview/Map/TileWorker.js"
+ "js/map/wv.map.tileworker.js"
],
dest: "build/worldview/web" }
]
@@ -393,7 +393,7 @@ module.exports = function(grunt) {
"!build/worldview-debug/web/js/wv.js",
"!build/worldview-debug/web/css/pages.css",
"!build/worldview-debug/web/css/bulkDownload.css",
- "!build/worldview-debug/web/js/Worldview/Map/TileWorker.js",
+ "!build/worldview-debug/web/js/map/wv.map.tileworker.js",
"!build/worldview-debug/web/ext/**/*"
],
conf_src: [
diff --git a/buster.js b/buster.js
index 86e732496..8785eeb45 100644
--- a/buster.js
+++ b/buster.js
@@ -18,7 +18,8 @@ config["wv"] = {
"src/ext/main/lodash-2.4.1/lodash.js",
"src/ext/main/jquery-1.6.4/jquery.js",
"src/ext/main/jscache-gitba01cdc/cache.js",
- "src/ext/ui/yui-2.9.0/yui.js"
+ "src/ext/ui/yui-2.9.0/yui.js",
+ "src/ext/map/openlayers-2.13.1-wv1/OpenLayers.js"
],
src: [
"src/js/wv.*.js",
@@ -32,6 +33,8 @@ config["wv"] = {
"src/js/palettes/wv.*.js",
"src/js/proj/wv.*.js",
"src/js/data/wv.*.js",
+ "src/js/map/wv.*.js",
+ "!src/js/map/wv.map.tileworker.js"
],
tests: [
"test/**/*.js"
diff --git a/etc/deploy/wv.css.json b/etc/deploy/wv.css.json
index 575b55db2..f61153207 100644
--- a/etc/deploy/wv.css.json
+++ b/etc/deploy/wv.css.json
@@ -10,7 +10,6 @@
"src/css/accordionPicker.css",
"src/css/bank.css",
"src/css/selector.css",
- "src/css/sote.css",
"src/css/splash.css",
"src/css/products.css",
"src/css/projection.css",
diff --git a/etc/deploy/wv.js.json b/etc/deploy/wv.js.json
index df2a77dad..ed88040e5 100644
--- a/etc/deploy/wv.js.json
+++ b/etc/deploy/wv.js.json
@@ -1,10 +1,4 @@
[
- "src/js/component.js",
- "src/js/registry.js",
- "src/js/rubberBand.js",
- "src/js/imageDownload.js",
- "src/js/events.js",
-
"src/js/wv.brand.js",
"src/js/util/wv.util.js",
@@ -15,73 +9,48 @@
"src/js/ui/wv.ui.about.js",
"src/js/ui/wv.ui.indicator.js",
+ "src/js/proj/wv.proj.js",
"src/js/proj/wv.proj.change.js",
"src/js/proj/wv.proj.model.js",
"src/js/proj/wv.proj.ui.js",
+ "src/js/date/wv.date.js",
"src/js/date/wv.date.model.js",
"src/js/date/wv.date.sliders.js",
"src/js/date/wv.date.label.js",
"src/js/date/wv.date.wheels.js",
+ "src/js/layers/wv.layers.js",
"src/js/layers/wv.layers.model.js",
"src/js/layers/wv.layers.sidebar.js",
"src/js/layers/wv.layers.active.js",
"src/js/layers/wv.layers.add.js",
+ "src/js/image/wv.image.rubberband.js",
+ "src/js/image/wv.image.panel.js",
+
"src/js/palettes/wv.palettes.js",
"src/js/palettes/wv.palettes.custom.js",
"src/js/palettes/wv.palettes.legend.js",
"src/js/palettes/wv.palettes.model.js",
- "src/js/link/wv.link.model.js",
- "src/js/link/wv.link.ui.js",
-
+ "src/js/data/wv.data.js",
+ "src/js/data/wv.data.echo.js",
"src/js/data/wv.data.handler.js",
+ "src/js/data/wv.data.layers.js",
+ "src/js/data/wv.data.map.js",
"src/js/data/wv.data.model.js",
"src/js/data/wv.data.results.js",
"src/js/data/wv.data.ui.js",
- "src/js/legacy/wv.legacy.switch_.js",
- "src/js/legacy/wv.legacy.bank.js",
- "src/js/legacy/wv.legacy.date.js",
- "src/js/legacy/wv.legacy.palettes.js",
-
- "src/js/Worldview.js",
- "src/js/Worldview/Support.js",
- "src/js/Worldview/Scheduler.js",
- "src/js/Worldview/Indicator.js",
- "src/js/Worldview/AjaxJoin.js",
+ "src/js/map/wv.map.js",
+ "src/js/map/wv.map.layers.js",
+ "src/js/map/wv.map.model.js",
+ "src/js/map/wv.map.set.js",
+ "src/js/map/wv.map.palette.js",
- "src/js/Worldview/Map.js",
- "src/js/Worldview/Map/CanvasTile.js",
- "src/js/Worldview/Map/MapSet.js",
- "src/js/Worldview/Map/LayerSet.js",
- "src/js/Worldview/Map/StaticLayerSet.js",
- "src/js/Worldview/Map/DailyLayerSet.js",
- "src/js/Worldview/Map/GraticuleLayer.js",
- "src/js/Worldview/Map/TWMSLayer.js",
- "src/js/Worldview/Map/HoverControl.js",
- "src/js/Worldview/Map/MockLayerSet.js",
-
- "src/js/Worldview/DataDownload/ECHO.js",
- "src/js/Worldview/DataDownload/ECHO/Client.js",
- "src/js/Worldview/DataDownload/ECHO/Geometry.js",
- "src/js/Worldview/DataDownload/ECHO/MockClient.js",
-
- "src/js/Worldview/DataDownload/Layers/Button.js",
- "src/js/Worldview/DataDownload/Layers/Grid.js",
- "src/js/Worldview/DataDownload/Layers/Hover.js",
- "src/js/Worldview/DataDownload/Layers/Selection.js",
- "src/js/Worldview/DataDownload/Layers/Swath.js",
-
- "src/js/Worldview/DataDownload/MapController.js",
- "src/js/Worldview/DataDownload/SelectionListPanel.js",
- "src/js/Worldview/DataDownload/DownloadListPanel.js",
- "src/js/Worldview/DataDownload/BulkDownloadPage.js",
-
- "src/js/Worldview/Widget/Map.js",
- "src/js/Worldview/Widget/WorldviewMap.js",
+ "src/js/link/wv.link.model.js",
+ "src/js/link/wv.link.ui.js",
"src/js/wv.debug.js",
"src/js/wv.tour.js",
diff --git a/src/css/sote.css b/src/css/sote.css
deleted file mode 100644
index 6eaf6a3ac..000000000
--- a/src/css/sote.css
+++ /dev/null
@@ -1,210 +0,0 @@
-html,body, div, ul, li, p, h1, h2, h3, h4, h5, h6 {display:block; margin:0; padding:0; font: 100 12.8px/16px "helvetica",sans-serif;}
-body {min-width:320px; width:100%;}
-div {display:block;}
-h1, h2, h3, h4, h5, h6 { font-weight:400; }
-
-.yui-skin-sam .yui-panel {background: transparent; width:700px; font: 13px "Gill Sans", sans-serif; font-weight:100;}
-#selector_c .yui-panel {background: transparent; width:210px; font: 13px "Gill Sans", sans-serif; font-weight:100;}
-#selector_c .yui-panel .bd {padding:0 !important;}
-
-.yui-skin-sam .yui-panel-container .hd{ background:rgba(38, 43, 49, 0.65); color:#ffffff; border-bottom: none; padding:0; padding-left: 10px;}
-.yui-skin-sam .yui-panel-container .bd{ background:rgb(25, 28, 32); color:#d7d7d7;}
-.yui-skin-sam .yui-panel-container .ft{ background:rgba(18, 18, 18, 0.75); color:#d7d7d7;}
-.yui-skin-sam .yui-panel-container .bd h3{ color:#FFFFFF; font: 18px "Gill Sans", sans-serif; font-weight:400; text-decoration:none; }
-.yui-skin-sam .yui-panel-container .bd h4{ color:#000000; font: 18px "Gill Sans", sans-serif; font-weight:400; text-decoration:none; }
-.yui-skin-sam .yui-panel-container .bd a {color: #82CDFA; }
-#splash_c.yui-overlay-hidden, #conclusionPanel_c.yui-overlay-hidden {display:none;}
-
-.jspVerticalBar {width:10px !important; background:transparent;}
-.jspTrack {
- background: #555555;
-} /* or just remove the background property*/
-
-.jspDrag {
- background: #cccccc;
- padding:2px 0;
-}
-
-
-
-#info_drop { border:none; margin:0px;}
-#info_drop div.hidden a {display:block; color:#fff; font-weight:100; line-height:1em; font-size: 11px; width:70px; padding: 2px 5px; text-align:right; text-decoration:none;}
-#info_drop div.hidden a:hover {background: rgba(38,43,49,0.45); }
-#info_drop:hover div.hidden {display:block; background: rgba(38,43,49,0.45); width:80px; margin-left:-40px; margin-top:2px;}
-#info {display:block; width:40px; height:40px; border:none;}
-
-
-#permpanel h3 {color:#FFFFFF; font: 12px "Gill Sans", sans-serif; font-weight:100; text-decoration:none;}
-#permpanel input[type='text']{width:280px;}
-
-div.horizontalContainer {width:100%; display:block; float:left; position:absolute; bottom:10px; overflow:hidden; z-index:200; padding: 0;}
-
-#permalink_content {margin-top:10px;}
-
-.hidden {display:none;}
-
-#products {display:block; float:left; position:relative; left:0; }
-
-
-
-#banner {
- display:block;
- z-index:294;
- float:left;
- position:relative;
- width:100%;
- height:45px;
- background: rgba(65,65,65,0.5);
- border-bottom: 1px solid #000;
-}
-
-
-@media
-#banner img.logo {padding:11px 5px;}
-#banner ul {float:right; }
-#banner ul li {display:block; float:right; margin:3px 3px; line-height:0; }
-#banner ul li div {line-height:0;}
-#banner .toolbar-link {display:inline-block; line-height:0; }
-
-#hazard, #transition {z-index:1007; clear:both; float:left; display:block; position:relative; }
-
-#transition {width:22%; height:100px; text-shadow:none; color: #262626; margin-top:55px;}
-#hazard {top:-13px; }
-
-/* #map {position:absolute !important; left:0; top:0;} */
-
-#dlMap {position:absolute !important; left:0; top:0; background-color:#0000FF; opacity:0; width:100%; height:100%;z-index:-1; overflow:hidden;
-}
-
-#rubberband {position:absolute !important; left:0; top:0; width:100%; height:100%; z-index:-3; display:none; overflow:hidden; }
-#imagedownload {z-index:1005; width:180px; min-height:100px; position:absolute; display:none; background: rgba(38, 43, 49, 0.45);
- text-shadow:none; color:white; float:left; font-size:11px; text-align: left; top:44px; padding:5px; border-radius: 0 0 5px 5px;}
-#imgFileSize {color:#D99694;}
-
-#hazard ul {
- padding: 0;
- margin-left: 0;
- font: 13px "Gill Sans", sans-serif;
- text-align: center;
- text-shadow:none;
-}
-
-#hazard ul li {
- margin: 0;
- float: left;
- border-width: 1.5pt;
- padding: 0 5px 0 5px;
-}
-
-#hazard ul li.disabled {
- color: rgb(156,156,156);
-}
-
-#hazard ul.collapsible li div {
- position: absolute;
- left: -999em;
-}
-
-#hazard ul.collapsible:hover li div {
- position: relative;
- left: 0;
-}
-
-#hazard ul li:hover {
- border-color: yellow;
-}
-
-#hazard_item0 {
- background-color: rgb(149,55,53);
- border-color: rgb(217,150,148);
-}
-
-#hazard_item0.disabled, #hazard_item0.disabled:hover {
- background-color: rgb(92,76,77);
- border-color: rgb(113,95,96);
-}
-
-#hazard_item1 {
- background-color: rgb(23,55,94);
- border-color: rgb(85,142,213);
-}
-
-#hazard_item1.disabled, #hazard_item1.disabled:hover {
- background-color: rgb(54,66,76);
- border-color: rgb(78,100,119);
-}
-
-#hazard_item2 {
- background-color: rgb(74,69,42);
- border-color: rgb(148,138,84);
-}
-
-#hazard_item2.disabled, #hazard_item2.disabled:hover {
- background-color: rgb(58,56,52);
- border-color: rgb(105,99,78);
-}
-
-#hazard_item3 {
- background-color: rgb(160,162,108);
- border-color: rgb(209,212,111);
-}
-
-#hazard_item3.disabled, #hazard_item3.disabled:hover {
- background-color: rgb(101,103,86);
- border-color: rgb(127,128,97);
-}
-
-#hazard_item4 {
- background-color: rgb(127,127,127);
- border-color: rgb(166,166,166);
-}
-
-#hazard_item4.disabled, #hazard_item4.disabled:hover {
- background-color: rgb(63,63,63);
- border-color: rgb(97,97,97);
-}
-
-#hazard_item5 {
- background-color: rgb(79,98,40);
- border-color: rgb(101,117,79);
-}
-
-#hazard_item5.disabled, #hazard_item5.disabled:hover {
- background-color: rgb(83,83,67);
- border-color: rgb(101,117,79);
-}
-
-#hazard_item6 {
- background-color: rgb(64,49,82);
- border-color: rgb(179,162,199);
-}
-
-#transition ul {
- font: 10px "Gill Sans", sans-serif;
- text-align: center;
-}
-
-#transition ul li, #transition ul li.disabled, #transition ul li.disabled:hover {
- background-color: rgb(76,89,92);
- border-color: rgb(112,135,136);
- border-width: .75pt;
-}
-
-#transition ul li.selected {
- background-color: rgb(152,72,7);
- border-color: rgb(250,192,144);
-}
-
-#transition ul li:hover {
- border-color: yellow;
-}
-
-@media screen and (max-width: 440px){
- #wvlogo { width:54px; background-position: 0 center;}
-}
-
-.toolbar-icon {
- width: 40px;
- height: 40px;
-}
-
diff --git a/src/css/wv.main.css b/src/css/wv.main.css
index fa7e46de0..f76be3c78 100644
--- a/src/css/wv.main.css
+++ b/src/css/wv.main.css
@@ -9,6 +9,216 @@
* All Rights Reserved.
*/
+html,body, div, ul, li, p, h1, h2, h3, h4, h5, h6 {display:block; margin:0; padding:0; font: 100 12.8px/16px "helvetica",sans-serif;}
+body {min-width:320px; width:100%;}
+div {display:block;}
+h1, h2, h3, h4, h5, h6 { font-weight:400; }
+
+.yui-skin-sam .yui-panel {background: transparent; width:700px; font: 13px "Gill Sans", sans-serif; font-weight:100;}
+#selector_c .yui-panel {background: transparent; width:210px; font: 13px "Gill Sans", sans-serif; font-weight:100;}
+#selector_c .yui-panel .bd {padding:0 !important;}
+
+.yui-skin-sam .yui-panel-container .hd{ background:rgba(38, 43, 49, 0.65); color:#ffffff; border-bottom: none; padding:0; padding-left: 10px;}
+.yui-skin-sam .yui-panel-container .bd{ background:rgb(25, 28, 32); color:#d7d7d7;}
+.yui-skin-sam .yui-panel-container .ft{ background:rgba(18, 18, 18, 0.75); color:#d7d7d7;}
+.yui-skin-sam .yui-panel-container .bd h3{ color:#FFFFFF; font: 18px "Gill Sans", sans-serif; font-weight:400; text-decoration:none; }
+.yui-skin-sam .yui-panel-container .bd h4{ color:#000000; font: 18px "Gill Sans", sans-serif; font-weight:400; text-decoration:none; }
+.yui-skin-sam .yui-panel-container .bd a {color: #82CDFA; }
+#splash_c.yui-overlay-hidden, #conclusionPanel_c.yui-overlay-hidden {display:none;}
+
+.jspVerticalBar {width:10px !important; background:transparent;}
+.jspTrack {
+ background: #555555;
+} /* or just remove the background property*/
+
+.jspDrag {
+ background: #cccccc;
+ padding:2px 0;
+}
+
+
+
+#info_drop { border:none; margin:0px;}
+#info_drop div.hidden a {display:block; color:#fff; font-weight:100; line-height:1em; font-size: 11px; width:70px; padding: 2px 5px; text-align:right; text-decoration:none;}
+#info_drop div.hidden a:hover {background: rgba(38,43,49,0.45); }
+#info_drop:hover div.hidden {display:block; background: rgba(38,43,49,0.45); width:80px; margin-left:-40px; margin-top:2px;}
+#info {display:block; width:40px; height:40px; border:none;}
+
+
+#permpanel h3 {color:#FFFFFF; font: 12px "Gill Sans", sans-serif; font-weight:100; text-decoration:none;}
+#permpanel input[type='text']{width:280px;}
+
+div.horizontalContainer {width:100%; display:block; float:left; position:absolute; bottom:10px; overflow:hidden; z-index:200; padding: 0;}
+
+#permalink_content {margin-top:10px;}
+
+.hidden {display:none;}
+
+#products {display:block; float:left; position:relative; left:0; }
+
+
+
+#banner {
+ display:block;
+ z-index:294;
+ float:left;
+ position:relative;
+ width:100%;
+ height:45px;
+ background: rgba(65,65,65,0.5);
+ border-bottom: 1px solid #000;
+}
+
+
+@media
+#banner img.logo {padding:11px 5px;}
+#banner ul {float:right; }
+#banner ul li {display:block; float:right; margin:3px 3px; line-height:0; }
+#banner ul li div {line-height:0;}
+#banner .toolbar-link {display:inline-block; line-height:0; }
+
+#hazard, #transition {z-index:1007; clear:both; float:left; display:block; position:relative; }
+
+#transition {width:22%; height:100px; text-shadow:none; color: #262626; margin-top:55px;}
+#hazard {top:-13px; }
+
+/* #map {position:absolute !important; left:0; top:0;} */
+
+#dlMap {position:absolute !important; left:0; top:0; background-color:#0000FF; opacity:0; width:100%; height:100%;z-index:-1; overflow:hidden;
+}
+
+#rubberband {position:absolute !important; left:0; top:0; width:100%; height:100%; z-index:-3; display:none; overflow:hidden; }
+#imagedownload {z-index:1005; width:180px; min-height:100px; position:absolute; display:none; background: rgba(38, 43, 49, 0.45);
+ text-shadow:none; color:white; float:left; font-size:11px; text-align: left; top:44px; padding:5px; border-radius: 0 0 5px 5px;}
+#imgFileSize {color:#D99694;}
+
+#hazard ul {
+ padding: 0;
+ margin-left: 0;
+ font: 13px "Gill Sans", sans-serif;
+ text-align: center;
+ text-shadow:none;
+}
+
+#hazard ul li {
+ margin: 0;
+ float: left;
+ border-width: 1.5pt;
+ padding: 0 5px 0 5px;
+}
+
+#hazard ul li.disabled {
+ color: rgb(156,156,156);
+}
+
+#hazard ul.collapsible li div {
+ position: absolute;
+ left: -999em;
+}
+
+#hazard ul.collapsible:hover li div {
+ position: relative;
+ left: 0;
+}
+
+#hazard ul li:hover {
+ border-color: yellow;
+}
+
+#hazard_item0 {
+ background-color: rgb(149,55,53);
+ border-color: rgb(217,150,148);
+}
+
+#hazard_item0.disabled, #hazard_item0.disabled:hover {
+ background-color: rgb(92,76,77);
+ border-color: rgb(113,95,96);
+}
+
+#hazard_item1 {
+ background-color: rgb(23,55,94);
+ border-color: rgb(85,142,213);
+}
+
+#hazard_item1.disabled, #hazard_item1.disabled:hover {
+ background-color: rgb(54,66,76);
+ border-color: rgb(78,100,119);
+}
+
+#hazard_item2 {
+ background-color: rgb(74,69,42);
+ border-color: rgb(148,138,84);
+}
+
+#hazard_item2.disabled, #hazard_item2.disabled:hover {
+ background-color: rgb(58,56,52);
+ border-color: rgb(105,99,78);
+}
+
+#hazard_item3 {
+ background-color: rgb(160,162,108);
+ border-color: rgb(209,212,111);
+}
+
+#hazard_item3.disabled, #hazard_item3.disabled:hover {
+ background-color: rgb(101,103,86);
+ border-color: rgb(127,128,97);
+}
+
+#hazard_item4 {
+ background-color: rgb(127,127,127);
+ border-color: rgb(166,166,166);
+}
+
+#hazard_item4.disabled, #hazard_item4.disabled:hover {
+ background-color: rgb(63,63,63);
+ border-color: rgb(97,97,97);
+}
+
+#hazard_item5 {
+ background-color: rgb(79,98,40);
+ border-color: rgb(101,117,79);
+}
+
+#hazard_item5.disabled, #hazard_item5.disabled:hover {
+ background-color: rgb(83,83,67);
+ border-color: rgb(101,117,79);
+}
+
+#hazard_item6 {
+ background-color: rgb(64,49,82);
+ border-color: rgb(179,162,199);
+}
+
+#transition ul {
+ font: 10px "Gill Sans", sans-serif;
+ text-align: center;
+}
+
+#transition ul li, #transition ul li.disabled, #transition ul li.disabled:hover {
+ background-color: rgb(76,89,92);
+ border-color: rgb(112,135,136);
+ border-width: .75pt;
+}
+
+#transition ul li.selected {
+ background-color: rgb(152,72,7);
+ border-color: rgb(250,192,144);
+}
+
+#transition ul li:hover {
+ border-color: yellow;
+}
+
+@media screen and (max-width: 440px){
+ #wvlogo { width:54px; background-position: 0 center;}
+}
+
+.toolbar-icon {
+ width: 40px;
+ height: 40px;
+}
+
#wv-logo {
background: url('../images/wv-logo.svg') no-repeat center;
width: 247px;
diff --git a/src/index.html b/src/index.html
index 230570cff..5b3e314c9 100644
--- a/src/index.html
+++ b/src/index.html
@@ -56,7 +56,6 @@
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/wv.palettes.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/wv.debug.css">
- <!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/sote.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/projection.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/pages.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/map.css">
@@ -115,12 +114,6 @@
<!-- link.prod --> <!-- <script type="text/javascript" src="js/wv.js?v=20131218215115174&mobile"></script> -->
- <!-- link.dev --> <script type="text/javascript" src="js/component.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/registry.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/rubberBand.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/imageDownload.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/events.js"></script>
-
<!-- link.dev --> <script type="text/javascript" src="js/wv.brand.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/util/wv.util.js"></script>
@@ -131,71 +124,48 @@
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.about.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.indicator.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.change.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.ui.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.sliders.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.label.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.wheels.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.sidebar.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.active.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.add.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/image/wv.image.rubberband.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/image/wv.image.panel.js"></script>
+
<!-- link.dev --> <script type="text/javascript" src="js/palettes/wv.palettes.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/palettes/wv.palettes.custom.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/palettes/wv.palettes.legend.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/palettes/wv.palettes.model.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.model.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.ui.js"></script>
-
+ <!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.echo.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.handler.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.layers.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.map.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.results.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.ui.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.switch_.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.bank.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.date.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.palettes.js"></script>
-
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Scheduler.js"></script>
-
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/CanvasTile.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/MapSet.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/LayerSet.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/StaticLayerSet.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/DailyLayerSet.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/GraticuleLayer.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/TWMSLayer.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/HoverControl.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Map/MockLayerSet.js"></script>
-
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ECHO.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ECHO/Client.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ECHO/Geometry.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ECHO/MockClient.js"></script>
-
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/Layers/Button.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/Layers/Grid.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/Layers/Hover.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/Layers/Selection.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/Layers/Swath.js"></script>
-
-
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/MapController.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/SelectionListPanel.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/DownloadListPanel.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/BulkDownloadPage.js"></script>
-
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/Map.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/WorldviewMap.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.layers.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.set.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.palette.js"></script>
+
+ <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.ui.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/wv.debug.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/wv.tour.js"></script>
diff --git a/src/js/Worldview.js b/src/js/Worldview.js
deleted file mode 100644
index 99b2e70a9..000000000
--- a/src/js/Worldview.js
+++ /dev/null
@@ -1,329 +0,0 @@
-
-(function(ns) {
-
- // June 6, 2013
- ns.ARCTIC_PROJECTION_CHANGE_DATE = new Date(Date.UTC(2013, 05, 06));
-
- // Width boundary in pixels where desktop mode switches to mobile.
- ns.TRANSITION_WIDTH = 720;
-
-
-
- /**
- * Defines a namespace under Worldview. Each argument is an object path
- * delimited by periods. For each path item, an empty object is created if
- * one does not yet exist. For example:
- *
- * Worldview.namespace("foo.bar");
- *
- * If Worldview.foo does not exist, it wil be created with an empty object.
- * If Worldview.foo.bar does not exist, it will be created with an empty
- * object.
- *
- * @method namespace
- * @static
- *
- * @param [arguments]* {String} Object path, delimited by periods
- *
- * @return {Object} The newly created namespace object.
- */
- ns.namespace = function() {
- var obj;
- for ( var i = 0; i < arguments.length; i++ ) {
- var list=(""+arguments[i]).split(".");
- obj = Worldview;
- for ( var j = 0; j < list.length; j++ ) {
- obj[list[j]] = obj[list[j]] || {};
- obj = obj[list[j]];
- }
- }
- return obj;
- };
-
- /**
- * Worldview general error handler. The error is reported to the browser
- * console and, if the JavaScript library with YAHOO.widget.Panel is
- * found, opens a notification panel for the end user.
- *
- * @method error
- * @static
- *
- * @param message {string} Error message to display to the user.
- *
- * @param cause {exception|string} Description of the error that does not
- * need to be shown to the user, usually the exception that was caught.
- */
- ns.error = function(message, cause) {
- if ( cause ) {
- console.error(cause);
- } else {
- console.error(message);
- }
-
- if ( window.YAHOO && window.YAHOO.widget &&
- window.YAHOO.widget.Panel ) {
- o = new YAHOO.widget.Panel("WVerror", {
- width: "300px",
- zIndex: 1020,
- visible: false,
- constraintoviewport: true
- });
- o.setHeader('Warning');
- o.setBody("An unexpected error has occurred.<br/><br/>" + message +
- "<br/><br/>Please reload the page and try again. If you " +
- "continue to have problems, contact us at " +
- "<a href='mailto:[email protected]'>" +
- o.render(document.body);
- o.show();
- o.center();
- o.hideEvent.subscribe(function(i) {
- setTimeout(function() {o.destroy();}, 25);
- });
- }
- };
-
- /**
- * Asks the end user a yes or no question in a dialog box.
- *
- * @method ask
- * @static
- *
- * @param [spec.header="Notice"] {string} Header text to be displayed in
- * the dialog box.
- *
- * @param [spec.message="Are you sure?"] {string} Message text to be
- * displayed in the dialog box.
- *
- * @param [spec.okButton="OK"] {string} Text to be used in the no button.
- *
- * @param [spec.cancelButton="Cancel"] {string} Text to be used in the yes
- * button.
- *
- * @param [spec.onOk] {function} Function to execute when the OK button is
- * pressed. If not specified, the dialog box simply closes.
- *
- * @parma [spec.onCancel] {function} Function to execute when the Cancel
- * button is pressed. If not specified, the dialog box simply closes.
- */
- ns.ask = function(spec) {
- var dialog = new YAHOO.widget.SimpleDialog("dialog", {
- width: "20em",
- effect: {
- effect: YAHOO.widget.ContainerEffect.FADE,
- duration: 0.25
- },
- fixedcenter: true,
- modal: true,
- visible: false,
- draggable: false
- });
-
- var header = spec.header || "Notice";
- dialog.setHeader(header);
- dialog.setBody(spec.message || "Are you sure?");
-
- var handleOk = function() {
- try {
- this.hide();
- if ( spec.onOk) {
- spec.onOk();
- }
- } catch ( error ) {
- Worldview.error("Internal error", error);
- }
- };
- var handleCancel = function() {
- try {
- this.hide();
- if ( spec.onCancel ) {
- spec.onCancel();
- }
- } catch ( error ) {
- Worldview.error("Internal error", error);
- }
- };
-
- var buttons = [
- { text: spec.cancelButton || "Cancel", handler: handleCancel },
- { text: spec.okButton || "OK", handler: handleOk }
- ];
- dialog.cfg.queueProperty("buttons", buttons);
- dialog.render(document.body);
- dialog.show();
- };
-
- /**
- * Gets the number of properties in an object.
- *
- * @method size
- * @static
- *
- * @param size {object} Object to count the number of properties
- *
- * @return {integer} The number of properites where hasOwnPropery returns
- * true.
- */
- ns.size = function(object) {
- var size = 0;
- for ( key in object ) {
- if ( object.hasOwnProperty(key) ) {
- size++;
- }
- }
- return size;
- };
-
- /**
- * Returns the object specified by a string path.
- *
- * @method getObjectByPath
- * @static
- *
- * @param path {string} The path to the object, delimited by periods.
- *
- * @return {object} The object or undefined. Throws an exception
- * if any object leading up the leaf object is undefined.
- */
- ns.getObjectByPath = function(path) {
- var nodes = path.split(".");
- var parent = window;
- $.each(nodes, function(index, node) {
- if ( parent[node] === undefined ) {
- throw new Error("In " + path + ", " + node + " is undefined");
- }
- parent = parent[node];
- });
- return parent;
- };
-
- /**
- * Converts a query string into an object.
- *
- * @method queryStringToObject
- * @static
- *
- * @param queryString {string} The query string to convert
- *
- * @return An object where each property is one of the parameters found in
- * the query string.
- */
- ns.queryStringToObject = function(queryString) {
- if ( !queryString ) {
- return "";
- }
- if ( queryString[0] === "?" ) {
- queryString = queryString.substring(1);
- }
- var parameters = queryString.split("&");
- result = {};
- for ( var i = 0; i < parameters.length; i++ ) {
- var fields = parameters[i].split("=");
- result[fields[0]] = fields[1];
- }
- return result;
- };
-
- /**
- * Extracts the value of the given key from the querystring.
- *
- * @method extractFromQuery
- * @static
- *
- * @param key {string} Item to be extracted
- * @param qs {string} Query string to extract from
- *
- * @return {object} The value associated with the given key in the
- * querystring, or an empty string if not found.
- */
- ns.extractFromQuery = function(key, qs) {
- var regex = new RegExp("[\\?&#]*"+key+"=([^&#]*)");
- var val = regex.exec(qs);
- if(val == null)
- return "";
- else
- return val[1];
- };
-
- /**
- * Wrapper for handling AJAX errors when the XHR and status code is not
- * necessary.
- *
- * @method ajaxError
- * @static
- *
- * @param hanadler {function} Callback to be invoked on error that accepts
- * one argument, the error that was thrown.
- *
- * @return {function} The function wrapper.
- */
- ns.ajaxError = function(handler) {
- return function(jqXHR, textStatus, errorThrown) {
- handler(errorThrown);
- };
- };
-
- /**
- * Ensures a value is between an minimum and a maximum.
- *
- * @method clamp
- * @static
- *
- * @param min {number} Lower bound of the clamp range
- * @param max {number} Upper bound of the clamp range
- * @param value {number} The value to check.
- *
- * @return {number} min if the value is below min, max if the value is
- * above max, othewise returns value. Throws an exception if min is
- * greater than max.
- */
- ns.clamp = function(min, max, value) {
- if ( min > max ) {
- throw new Error("Invalid clamp range (" + min + " - " + max + ")");
- }
- if ( value < min ) { return min; }
- if ( value > max ) { return max; }
- return value;
- };
-
- /**
- * Clamps a value to a valid array index.
- *
- * @method clampIndex
- * @static
- *
- * @param array {Array} Clamp the index to this array
- * @param index {integer} Index value
- *
- * @return {number} Zero if the index is below zero, array.length - 1 if
- * the index is greater than the maximum array index, otherwise returns
- * index.
- */
- ns.clampIndex = function(array, index) {
- return ns.clamp(0, array.length - 1, index);
- };
-
- /**
- * Determines if the values of an array are equal to those of another
- * array. This was copied from Stack Overflow.
- *
- * @method arrayEquals
- * @static
- *
- * @param {Object} arr1 Array to compare
- * @param {Object} arr2 Array to compare
- *
- * @return {boolean} true if arr1 and arr2 have the same length, and all
- * values in arr1 are equal to those in arr2, otherwise returns false.
- */
- ns.arrayEquals = function(arr1, arr2) {
- return $(arr1).not(arr2).length == 0 && $(arr2).not(arr1).length == 0;
- };
-
- ns.id = function(value) {
- return value.replace(/:/g,"colon");
- };
-
-})(window.Worldview = window.Worldview || {});
-
-
diff --git a/src/js/Worldview/DataDownload/BulkDownloadPage.js b/src/js/Worldview/DataDownload/BulkDownloadPage.js
deleted file mode 100644
index 71dec1e62..000000000
--- a/src/js/Worldview/DataDownload/BulkDownloadPage.js
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload");
-
-Worldview.DataDownload.BulkDownloadPage = (function() {
-
- var ns = {};
-
- var pages = {
- wget: "pages/wget.html",
- curl: "pages/curl.html"
- };
-
- ns.show = function(selection, type) {
- var nonce = Date.now();
- var page = window.open(pages[type] + "?v=" + nonce,
- 'Worldview_' + nonce);
-
- var loaded = false;
- page.onload = function() {
- if ( !loaded ) {
- fillPage(page, selection, type);
- loaded = true;
- }
- };
- var checkCount = 0;
- var timer = setInterval(function() {
- checkCount++;
- if ( loaded ) {
- clearInterval(timer);
- return;
- }
- if ( checkCount > 20 ) {
- clearInterval(timer);
- return;
- }
- if ( fillPage(page, selection, type) ) {
- loaded = true;
- clearInterval(timer);
- }
- }, 100);
- };
-
- var fillPage = function(page, selection, type) {
- var downloadLinks = [];
- var hosts = {};
- var indirectLinks = [];
- $.each(selection, function(index, product) {
- $.each(product.list, function(index2, granule) {
- var netrc = "";
- if ( granule.urs ) {
- netrc = "--netrc ";
- }
- $.each(granule.links, function(index2, link) {
- if ( !link.data ) {
- return;
- }
- if ( product.noBulkDownload ) {
- indirectLinks.push("<li><a href='" + link.href + "'>" +
- link.href + "</a></li>");
- return;
- }
- if ( type === "curl" ) {
- downloadLinks.push("curl --remote-name " + netrc +
- link.href);
- } else {
- downloadLinks.push(link.href);
- }
- if ( granule.urs ) {
- // Get the hostname from the URL, the text between
- // the double slash and the first slash after that
- var host = /\/\/([^\/]*)\//.exec(link.href);
- if ( host ) {
- hosts[host[1]] = true;
- }
- }
- });
- });
- });
- var links = page.document.getElementById("links");
- if ( !links ) {
- // Page is not ready
- return false;
- }
- links.innerHTML = "<pre>" + downloadLinks.join("\n") + "</pre>";
-
- var netrcEntries = [];
- var hostnames = [];
- $.each(hosts, function(host, value) {
- netrcEntries.push("machine " + host + " login URS_USER " +
- "password URS_PASSWORD");
- hostnames.push(host);
- });
- if ( netrcEntries.length > 0 ) {
- page.document.getElementById("netrc").innerHTML =
- "<pre>" + netrcEntries.join("\n") + "</pre>";
- page.document.getElementById("bulk-password-notice")
- .style.display = "block";
- page.document.getElementById("netrc-instructions")
- .style.display = "block";
- var instructions =
- page.document.getElementById("fdm-password-instructions");
- if ( instructions ) {
- instructions.style.display = "block";
- }
- var machineNames =
- page.document.getElementById("fdm-machine-names");
- if ( machineNames ) {
- machineNames.innerHTML = "<pre>" + hostnames.join("\n") +
- "</pre>";
- }
- }
- if ( indirectLinks.length > 0 ) {
- page.document.getElementById("indirect-instructions")
- .style.display = "block";
- page.document.getElementById("indirect").innerHTML =
- "<ul>" + indirectLinks.join("\n") + "</ul>";
- }
- return true;
- };
-
- return ns;
-
-})();
\ No newline at end of file
diff --git a/src/js/Worldview/DataDownload/DownloadListPanel.js b/src/js/Worldview/DataDownload/DownloadListPanel.js
deleted file mode 100644
index dede2750f..000000000
--- a/src/js/Worldview/DataDownload/DownloadListPanel.js
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload");
-
-Worldview.DataDownload.DownloadListPanel = function(config, model) {
-
- var echo = Worldview.DataDownload.ECHO;
-
- var NOTICE =
- "<div id='DataDownload_Notice'>" +
- "<img class='icon' src='images/info-icon-blue.svg'>" +
- "<p class='text'>" +
- "Some items you have selected require an account with the " +
- "EOSDIS User Registration System (URS) to download. " +
- "It is simple and free to sign up! " +
- "<a href='https://urs.eosdis.nasa.gov/users/new' target='urs'>" +
- "Click to register for an account.</a>" +
- "</p>" +
- "</div>";
-
- var panel = null;
- var selection;
- var self = {};
- var urs = false;
-
- self.events = wv.util.events();
-
- self.show = function() {
- $("#DataDownload_DownloadListPanel .remove").off("click", removeGranule);
- $("#DataDownload_DownloadListPanel a.wget").off("click", showWgetPage);
- $("#DataDownload_DownloadListPanel a.curl").off("click", showCurlPage);
- $("#DataDownload_DownloadListPanel tr").off("mouseenter", onHoverOver);
- $("#DataDownload_DownloadListPanel tr").off("mouseleave", onHoverOut);
-
- selection = reformatSelection();
- var newPanel = false;
- if ( !panel ) {
- newPanel = true;
- panel = new YAHOO.widget.Panel("DataDownload_DownloadListPanel", {
- width: "650px",
- height: "500px",
- zIndex: 1020,
- visible: false,
- constraintoviewport: true
- });
- panel.setHeader("Download Links");
- }
- panel.setBody(bodyText(selection));
- panel.setFooter(bulkDownloadText());
-
- if ( newPanel ) {
- panel.render(document.body);
- panel.show();
- panel.center();
- panel.hideEvent.subscribe(function() {
- setTimeout(dispose, 25);
- });
- }
-
- $("#DataDownload_DownloadListPanel a.wget").click(showWgetPage);
- $("#DataDownload_DownloadListPanel a.curl").click(showCurlPage);
- $("#DataDownload_DownloadListPanel .remove").click(removeGranule);
- $("#DataDownload_DownloadListPanel tr").on("mouseenter", onHoverOver);
- $("#DataDownload_DownloadListPanel tr").on("mouseleave", onHoverOut);
-
- var bulkVisible = isBulkDownloadable() &&
- Worldview.size(model.selectedGranules) !== 0;
- if ( bulkVisible ) {
- $("#DataDownload_DownloadListPanel .ft .bulk")
- .css("visibility", "visible");
- } else {
- $("#DataDownload_DownloadListPanel .ft .bulk")
- .css("visibility", "hidden");
- }
- };
-
- self.hide = function() {
- if ( panel ) {
- panel.hide();
- }
- };
-
- self.visible = function() {
- return panel !== null;
- };
-
- var dispose = function() {
- $("#DataDownload_DownloadListPanel .remove").off("click", removeGranule);
- $("#DataDownload_DownloadListPanel a.wget").off("click", showWgetPage);
- $("#DataDownload_DownloadListPanel a.curl").off("click", showCurlPage);
- $("#DataDownload_DownloadListPanel tr").off("mouseenter", onHoverOver);
- $("#DataDownload_DownloadListPanel tr").off("mouseleave", onHoverOut);
-
- self.events.trigger("close");
- panel.destroy();
- panel = null;
- };
-
- var reformatSelection = function() {
- var selection = {};
-
- urs = false;
- $.each(model.selectedGranules, function(key, granule) {
- if ( granule.urs ) {
- urs = true;
- }
- if ( !selection[granule.product] ) {
- productConfig = config.products[granule.product];
- selection[granule.product] = {
- name: productConfig.name,
- granules: [granule],
- counts: {},
- noBulkDownload: productConfig.noBulkDownload || false,
- };
- } else {
- selection[granule.product].granules.push(granule);
- }
-
- var product = selection[granule.product];
- var id = granule.product;
-
- // For each link that looks like metadata, see if that link is
- // repeated in all granules for that product. If so, we want to
- // bump that up to product level instead of at the granule level.
- $.each(granule.links, function(index, link) {
- if ( link.rel !== echo.REL_DATA && link.rel !== echo.REL_BROWSE ) {
- if ( !product.counts[link.href] ) {
- product.counts[link.href] = 1;
- } else {
- product.counts[link.href]++;
- }
- }
- });
- });
-
- $.each(selection, function(key, product) {
- product.links = [];
- product.list = [];
-
- // Check the first granule, and populate product level links
- // where the count equals the number of granules
- var granule = product.granules[0];
- $.each(granule.links, function(index, link) {
- var count = product.counts[link.href];
- if ( count % product.granules.length === 0 ) {
- product.links.push(reformatLink(link));
- }
- });
-
- $.each(product.granules, function(index, granule) {
- var item = {
- id: granule.id,
- label: granule.downloadLabel || granule.label,
- links: [],
- urs: granule.urs
- };
- $.each(granule.links, function(index, link) {
- // Skip this link if now at the product level
- var count = product.counts[link.href];
- if ( count % product.granules.length === 0 ) {
- return;
- }
- // Skip browse images per Kevin's request
- if ( link.rel === echo.REL_BROWSE ) {
- return;
- }
- item.links.push(reformatLink(link));
- });
- product.list.push(item);
- });
- product.list.sort(function(a, b) {
- if ( a.label > b.label ) {
- return 1;
- }
- if ( a.label < b.label ) {
- return -1;
- }
- return 0;
- });
- });
-
- return selection;
- };
-
- var isBulkDownloadable = function() {
- var result = false;
- $.each(selection, function(index, product) {
- if ( !product.noBulkDownload ) {
- result = true;
- }
- });
- return result;
- };
-
- var reformatLink = function(link) {
- // For title, take it if found, otherwise, use the basename of the
- // URI
- return {
- href: link.href,
- title: ( link.title ) ? link.title : link.href.split("/").slice(-1),
- data: ( link.rel === echo.REL_DATA )
- };
- };
-
- var linksText = function(links) {
- var elements = [];
- elements.push("<ul>");
- $.each(links, function(index, link) {
- elements.push(
- "<li><a href='" + link.href + "' target='_blank'>" +
- link.title + "</a></li>");
- });
- elements.push("</ul>");
- return elements.join("\n");
- };
-
- var granuleText = function(product, granule) {
- if ( product.name !== granule.label ) {
- var elements = [
- "<tr data-granule='" + granule.id + "'>",
- "<td><input type='button' class='remove' " +
- "data-granule='" + granule.id + "' " +
- "value='X'></input></td>",
- "<td><nobr><ul><li>" + granule.label + "</li></ul></nobr></td>",
- "<td>" + linksText(granule.links) + "</td>",
- "</tr>"
- ];
- } else {
- var elements = [
- "<tr data-granule='" + granule.id + "'>",
- "<td><input type='button' class='remove' " +
- "data-granule='" + granule.id + "' " +
- "value='X'></input></td>",
- "<td colspan='2'>" + linksText(granule.links) + "</td>",
- "</tr>"
- ];
- }
- return elements.join("\n");
- };
-
- var productText = function(product) {
- var elements = [
- "<h3>" + product.name + "</h3>"
- ];
-
- elements.push("<h5>Selected Data</h5>");
- elements.push("<table>");
-
- $.each(product.list, function(index, item) {
- elements.push(granuleText(product, item));
- });
- elements.push("</table>");
-
- if ( product.links && product.links.length > 0 ) {
- elements.push("<h5>Data Collection Information</h5>");
- elements.push("<div class='product'>");
- elements.push(linksText(product.links));
- elements.push("</div>");
- }
-
- return elements.join("\n");
- };
-
- var bodyText = function() {
- if ( Worldview.size(model.selectedGranules) === 0 ) {
- return "<br/><h3>Selection Empty</h3>";
- }
- var elements = [];
- if ( urs ) {
- elements.push(NOTICE);
- }
- $.each(selection, function(key, product) {
- elements.push("\n<br/>\n" + productText(product));
- });
-
- var text = elements.join("\n<br/>\n") + "<br/>";
- return text;
- };
-
- var bulkDownloadText = function() {
- var bulk =
- "<div class='bulk'>" +
- "<h4>Bulk Download</h4>" +
- "<ul class='BulkDownload'>" +
- "<li><a class='wget' href='#'>List of Links:</a> " +
- "for wget or download managers that accept a list of " +
- "URLs</li>" +
- "<li><a class='curl' href='#'>List of cURL Commands:</a> " +
- "can be copied and pasted to " +
- "a terminal window to download using cURL.</li>" +
- "</ul>" +
- "</div>";
- return bulk;
- };
-
- var showWgetPage = function() {
- Worldview.DataDownload.BulkDownloadPage.show(selection, "wget");
- };
-
- var showCurlPage = function() {
- Worldview.DataDownload.BulkDownloadPage.show(selection, "curl");
- };
-
- var removeGranule = function() {
- var id = $(this).attr("data-granule");
- model.unselectGranule(model.selectedGranules[id]);
- onHoverOut.apply(this);
- };
-
- var onHoverOver = function() {
- model.events.trigger("hoverOver",
- model.selectedGranules[$(this).attr("data-granule")]);
- };
-
- var onHoverOut = function() {
- model.events.trigger("hoverOut",
- model.selectedGranules[$(this).attr("data-granule")]);
- };
-
- return self;
-
-};
diff --git a/src/js/Worldview/DataDownload/ECHO.js b/src/js/Worldview/DataDownload/ECHO.js
deleted file mode 100644
index e2b0ce3de..000000000
--- a/src/js/Worldview/DataDownload/ECHO.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("DataDownload");
-
-Worldview.DataDownload.ECHO = function() {
-
- var ns = {};
-
- ns.REL_DATA = "http://esipfed.org/ns/fedsearch/1.1/data#";
- ns.REL_BROWSE = "http://esipfed.org/ns/fedsearch/1.1/browse#";
-
- ns.roundTime = function(timeString) {
- var time = wv.util.parseTimestampUTC(timeString);
- if ( time.getUTCMilliseconds() >= 500 ) {
- time.setUTCSeconds(time.getUTCSeconds() + 1);
- }
- time.setUTCMilliseconds(0);
- return time.toISOString();
- };
-
- return ns;
-
-}();
diff --git a/src/js/Worldview/DataDownload/ECHO/Client.js b/src/js/Worldview/DataDownload/ECHO/Client.js
deleted file mode 100644
index 7bee641a4..000000000
--- a/src/js/Worldview/DataDownload/ECHO/Client.js
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module Worldview.DataDownload.ECHO
- */
-Worldview.namespace("DataDownload.ECHO");
-
-Worldview.DataDownload.ECHO.Client = function(spec) {
-
- // Abort query after 45 seconds
- var QUERY_TIMEOUT = spec.timeout || 45 * 1000;
-
- var ns = Worldview.DataDownload.ECHO.Client;
-
- var ajaxOptions = {
- url: "service/echo.cgi",
- traditional: true,
- dataType: "json",
- timeout: QUERY_TIMEOUT
- };
-
- var self = {};
-
- var init = function() {
- ns.ajax = wv.util.ajaxCache();
- };
-
- self.submit = function(parameters) {
- var queryParameters = $.extend(true, {}, ajaxOptions, parameters);
- var startTimeDelta = parameters.startTimeDelta || 0;
- var endTimeDelta = parameters.endTimeDelta || 0;
-
- var t = parameters.time;
- if ( t ) {
- var startTime = new Date(Date.UTC(
- t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate(),
- 0, 0 + startTimeDelta, 0
- ));
- var endTime = new Date(Date.UTC(
- t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate(),
- 23, 59 + endTimeDelta, 59
- ));
-
- queryParameters.data.startTime =
- wv.util.toCompactTimestamp(startTime);
- queryParameters.data.endTime = wv.util.toCompactTimestamp(endTime);
- }
-
- var deferred = $.Deferred();
- ns.ajax.submit(queryParameters).done(function(data) {
- deferred.resolve(data.feed.entry);
- }).fail(function(jqXHR, textStatus, errorThrown) {
- deferred.reject(jqXHR, textStatus, errorThrown);
- });
- return deferred.promise();
- };
-
- init();
- return self;
-};
diff --git a/src/js/Worldview/DataDownload/ECHO/Geometry.js b/src/js/Worldview/DataDownload/ECHO/Geometry.js
deleted file mode 100644
index 3fded1187..000000000
--- a/src/js/Worldview/DataDownload/ECHO/Geometry.js
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module Worldview.DataDownload
- */
-Worldview.namespace("DataDownload");
-
-Worldview.DataDownload.ECHO.Geometry = function(result) {
-
- var self = {};
- self.polygons = [];
-
- var init = function() {
- if ( result.polygons ) {
- initFromPolygons(result.polygons);
- } else if ( result.boxes ) {
- initFromBoxes(result.boxes);
- } else {
- throw new Error("Unable to find spatial field");
- }
- };
-
- self.toOpenLayers = function() {
- 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);
- olPoints.push(p);
- });
- olRings.push(new OpenLayers.Geometry.LinearRing(olPoints));
- });
- olPolygons.push(new OpenLayers.Geometry.Polygon(olRings));
- });
- return olPolygons[0];
- };
-
- var initFromPolygons = function(echoPolygons) {
- $.each(echoPolygons, function(index, echoPolygon) {
- var rings = [];
- $.each(echoPolygon, function(index, echoRing) {
- var ring = [];
- var parts = echoRing.split(" ");
- for ( var i = 0; i < parts.length; i+= 2 ) {
- var y = parseFloat(parts[i]);
- var x = parseFloat(parts[i + 1]);
- ring.push({x: x, y: y});
- }
- rings.push(ring);
- });
- self.polygons.push(rings);
- });
- };
-
- var initFromBoxes = function(echoBoxes) {
- $.each(echoBoxes, function(index, echoBox) {
- var ring = [];
- var fields = echoBox.split(" ");
- var ymin = parseFloat(fields[0]);
- var xmin = parseFloat(fields[1]);
- var ymax = parseFloat(fields[2]);
- var xmax = parseFloat(fields[3]);
- ring.push({x: xmin, y: ymin});
- ring.push({x: xmax, y: ymin});
- ring.push({x: xmax, y: ymax});
- ring.push({x: xmin, y: ymax});
- ring.push({x: xmin, y: ymin});
-
- self.polygons.push([ring]);
- });
- };
-
- init();
- return self;
-};
diff --git a/src/js/Worldview/DataDownload/ECHO/MockClient.js b/src/js/Worldview/DataDownload/ECHO/MockClient.js
deleted file mode 100644
index ef5c73274..000000000
--- a/src/js/Worldview/DataDownload/ECHO/MockClient.js
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module Worldview.DataDownload
- */
-Worldview.namespace("DataDownload");
-
-Worldview.DataDownload.ECHO.MockClient = function(suffix) {
-
- var endpoint;
- var results;
-
- var self = {};
-
- var init = function() {
- if ( !suffix ) {
- throw new Error("No mock ECHO suffix specified");
- }
- endpoint = "mock/echo.cgi-" + suffix;
- };
-
- self.submit = function(parameters) {
- console.warn("Mocking ECHO query", endpoint);
- var deferred = $.Deferred();
- if ( !results ) {
- $.getJSON(endpoint, function(data) {
- try {
- results = adjustResults(parameters, data);
- deferred.resolve(results.feed.entry);
- } catch ( error ) {
- Worldview.error("Internal error", error);
- }
- })
- .fail(function(jqXHR, textStatus, errorThrown) {
- deferred.reject(jqXHR, textStatus, errorThrown);
- });
- } else {
- deferred.resolve(results.feed.entry);
- }
- return deferred.promise();
- };
-
- var adjustResults = function(parameters, data) {
- var day = REGISTRY.getState().time;
- // Mock data was retrieved for Aug 6, 2013
- var resultsDay = new Date(Date.UTC(2013, 7, 6));
- var diffDays = (day - resultsDay) / (1000 * 60 * 60 * 24);
-
- $.each(data.feed.entry, function(index, entry) {
- var timeStart = wv.util.parseTimestampUTC(entry.time_start);
- timeStart.setUTCDate(timeStart.getUTCDate() + diffDays);
- entry.time_start = timeStart.toISOString();
-
- var timeEnd = wv.util.parseTimestampUTC(entry.time_end);
- timeEnd.setUTCDate(timeEnd.getUTCDate() + diffDays);
- entry.time_end = timeEnd.toISOString();
- });
-
- return data;
- };
-
- init();
-
- return self;
-};
-
diff --git a/src/js/Worldview/DataDownload/Handler.js b/src/js/Worldview/DataDownload/Handler.js
deleted file mode 100644
index c9b9de8a4..000000000
--- a/src/js/Worldview/DataDownload/Handler.js
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module Worldview.DataDownload.Handler
- */
-Worldview.namespace("DataDownload");
-
-Worldview.DataDownload.Handler = function() {
-
- var ns = {};
-
- // FIXME: Make these static
- ns.getByName = function(name) {
- var map = {
- "AquaSwathMultiDay": Worldview.DataDownload.Handler.AquaSwathMultiDay,
- "CollectionList": Worldview.DataDownload.Handler.CollectionList,
- "List": Worldview.DataDownload.Handler.List,
- "MODISGrid": Worldview.DataDownload.Handler.MODISGrid,
- "MODISMix": Worldview.DataDownload.Handler.MODISMix,
- "MODISSwath": Worldview.DataDownload.Handler.MODISSwath,
- "TerraSwathMultiDay": Worldview.DataDownload.Handler.TerraSwathMultiDay,
- };
- var handler = map[name];
- if ( !handler ) {
- throw new Error("No such handler: " + name);
- }
- return handler;
- };
-
- return ns;
-}();
diff --git a/src/js/Worldview/DataDownload/Layers/Button.js b/src/js/Worldview/DataDownload/Layers/Button.js
deleted file mode 100644
index 973eaed88..000000000
--- a/src/js/Worldview/DataDownload/Layers/Button.js
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload.Layers");
-
-Worldview.DataDownload.Layers.Button = function(model, maps, config) {
-
- var LAYER_NAME = "DataDownload_Button";
-
- var IMAGE_SELECT = "images/data-download-plus-button-orange.svg";
- var IMAGE_UNSELECT = "images/data-download-minus-button-red.svg";
-
- var STYLE = {
- "default": {
- externalGraphic: IMAGE_SELECT,
- fontFamily: "helvetica, sans-serif",
- fontColor: "#ffffff",
- fontWeight: "bold",
- labelOutlineColor: "black",
- labelOutlineWidth: 2,
- labelOutlineOpacity: 0.7,
- label: "${label}",
- cursor: "pointer"
- },
- "select": {
- externalGraphic: IMAGE_UNSELECT,
- fontFamily: "helvetica, sans-serif",
- fontColor: "#ffffff",
- fontWeight: "bold",
- labelOutlineColor: "black",
- labelOutlineWidth: 2,
- labelOutlineOpacity: 0.7,
- label: "${label}",
- cursor: "pointer"
- }
- };
-
- var features = {};
- var splitFeature = null;
- var self = {};
-
- self.EVENT_HOVER_OVER = "hoverover";
- self.EVENT_HOVER_OUT = "hoverout";
-
- self.events = wv.util.events();
-
- var init = function() {
- $.each(maps.projections, function(index, map) {
- map.events.register("zoomend", self, resize);
- });
- model.events.on("granuleUnselect", onUnselect);
- };
-
- self.update = function(results) {
- var layer = getLayer();
- layer.removeAllFeatures();
- features = {};
- var featureList = [];
- var selectedFeatures = [];
- $.each(results.granules, function(index, granule) {
- if ( !granule.centroid ) {
- return;
- }
- var centroid = granule.centroid[model.crs];
- if ( centroid ) {
- var feature = new OpenLayers.Feature.Vector(centroid, {
- granule: granule,
- label: ""
- });
- featureList.push(feature);
- features[granule.id] = feature;
- if ( model.selectedGranules[granule.id] ) {
- selectedFeatures.push(feature);
- }
- }
- });
- layer.addFeatures(featureList);
- var selectionControl = layer.selectionControl;
- $.each(selectedFeatures, function(index, selectedFeature) {
- selectionControl.select(selectedFeature);
- });
- };
-
- self.clear = function() {
- var layer = Worldview.Map.getLayerByName(maps.map, LAYER_NAME);
- if ( layer ) {
- features = {};
- layer.removeAllFeatures();
- }
- };
-
- self.dispose = function() {
- $.each(maps.projections, function(index, map) {
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( layer ) {
- map.removeControl(layer.hoverControl);
- map.removeControl(layer.selectionControl);
- map.removeLayer(layer);
- }
- });
- };
-
- var createLayer = function() {
- size = getSize();
-
- layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
- styleMap: new OpenLayers.StyleMap(getStyle())
- });
-
- layer.div.setAttribute("data-layer-name", LAYER_NAME);
- maps.map.addLayer(layer);
-
- layer.events.on({
- 'featureselected': function(event) {
- model.selectGranule(event.feature.attributes.granule);
- },
- 'featureunselected': function(event) {
- model.unselectGranule(event.feature.attributes.granule);
- }
- });
-
- var hoverControl = new Worldview.Map.HoverControl(layer);
- hoverControl.events.on({
- "hoverover": function(event) {
- self.events.trigger(self.EVENT_HOVER_OVER, event);
- onHoverOver(event);
- },
- "hoverout": function(event) {
- self.events.trigger(self.EVENT_HOVER_OUT, event);
- onHoverOut(event);
- }
- });
- maps.map.addControl(hoverControl);
- hoverControl.activate();
- layer.hoverControl = hoverControl;
-
- var selectionControl = new OpenLayers.Control.SelectFeature(layer, {
- autoActivate: true,
- toggle: true,
- multiple: true,
- clickout: false
- });
- maps.map.addControl(selectionControl);
- layer.selectionControl = selectionControl;
-
- return layer;
- };
-
- var getLayer = function(map) {
- map = map || maps.map;
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( !layer ) {
- layer = createLayer();
- }
- return layer;
- };
-
- var getSize = function() {
- var zoom = maps.map.getZoom();
- // Minimum size of the button is 15 pixels
- var base = 15;
- // Double the size for each zoom level
- var add = Math.pow(2, zoom);
- // But 47 pixels is the maximum size
- var size = Math.min(base + add, base + 32);
- return new OpenLayers.Size(size, size);
- };
-
- var getStyle = function(intent) {
- var size = getSize();
- var newStyle = $.extend(true, {}, STYLE);
-
- newStyle["default"].graphicWidth = size.w;
- newStyle["default"].graphicHeight = size.h;
- newStyle["default"].labelYOffset = getLabelOffset();
-
- newStyle.select.graphicWidth = size.w;
- newStyle.select.graphicHeight = size.h;
- newStyle.select.labelYOffset = getLabelOffset();
-
- if ( intent ) {
- return newStyle[intent];
- } else {
- return newStyle;
- }
- };
-
- var resize = function() {
- if ( !model.active ) {
- return;
- }
- var styleMap = new OpenLayers.StyleMap(getStyle());
- getLayer().styleMap = styleMap;
- layer.redraw();
- };
-
- var onUnselect = function(granule) {
- var feature = features[granule.id];
- if ( feature ) {
- getLayer().selectionControl.unselect(feature);
- }
- };
-
- var onHoverOver = function(event) {
- var feature = event.feature;
- var granule = feature.attributes.granule;
- feature.attributes.label = granule.label;
- getLayer().drawFeature(feature);
- if ( feature.geometry.CLASS_NAME ===
- "OpenLayers.Geometry.MultiPoint" ) {
- var newStyle = $.extend(true, {}, getStyle("default"));
- delete newStyle.externalGraphic;
- newStyle.strokeOpacity = 1;
- newStyle.fillOpacity = 1;
- newStyle.label = granule.label;
- splitFeature = new OpenLayers.Feature.Vector(
- feature.geometry.components[1].clone(),
- feature.attributes,
- newStyle
- );
- getLayer().addFeatures([splitFeature]);
- }
- };
-
- var onHoverOut = function(event) {
- var feature = event.feature;
- feature.attributes.label = "";
- getLayer().drawFeature(feature);
- if ( splitFeature ) {
- getLayer().removeFeatures([splitFeature]);
- splitFeature = null;
- }
- };
-
- var getLabelOffset = function() {
- var buttonHeight = getSize().h;
- return ( buttonHeight / 2.0 ) + 10;
- };
-
- init();
- return self;
-
-};
\ No newline at end of file
diff --git a/src/js/Worldview/DataDownload/Layers/Grid.js b/src/js/Worldview/DataDownload/Layers/Grid.js
deleted file mode 100644
index 79c4259cd..000000000
--- a/src/js/Worldview/DataDownload/Layers/Grid.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload.Layers");
-
-Worldview.DataDownload.Layers.Grid = function(model, maps, config) {
-
- var LAYER_NAME = "DataDownload_Grid";
- var STYLE = {
- strokeColor: "#bab498",
- strokeOpacity: 0.6,
- fillOpacity: 0,
- strokeWidth: 1.5
- };
-
- var parser = new OpenLayers.Format.GeoJSON();
-
- var self = {};
-
- self.update = function(results) {
- self.clear();
- var grid = results.meta.grid;
- if ( !grid ) {
- return;
- }
- var layer = getLayer();
-
- var features = [];
- $.each(grid, function(index, cell) {
- var geom = parser.read(cell.geometry, "Geometry");
- var feature = new OpenLayers.Feature.Vector(geom);
- features.push(feature);
- });
- layer.addFeatures(features);
- };
-
- self.clear = function() {
- var layer = Worldview.Map.getLayerByName(maps.map, LAYER_NAME);
- if ( layer ) {
- layer.removeAllFeatures();
- }
- };
-
- self.dispose = function() {
- $.each(maps.projections, function(index, map) {
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( layer ) {
- map.removeLayer(layer);
- }
- });
- };
-
- var createLayer = function() {
- var layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
- styleMap: new OpenLayers.StyleMap(STYLE)
- });
- layer.div.setAttribute("data-layer-name", LAYER_NAME);
- maps.map.addLayer(layer);
- return layer;
- };
-
- var getLayer = function(map) {
- map = map || maps.map;
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( !layer ) {
- layer = createLayer();
- }
- return layer;
- };
-
- return self;
-
-};
diff --git a/src/js/Worldview/DataDownload/Layers/Hover.js b/src/js/Worldview/DataDownload/Layers/Hover.js
deleted file mode 100644
index 5ad91f530..000000000
--- a/src/js/Worldview/DataDownload/Layers/Hover.js
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload.Hover");
-
-Worldview.DataDownload.Layers.Hover = function(model, maps, config) {
-
- var LAYER_NAME = "DataDownload_Hover";
-
- var STYLE_HOVER_UNSELECTED = {
- strokeColor: "#fbe26d",
- fillColor: "#b59e32",
- fillOpacity: 0.25
- };
-
- var STYLE_HOVER_SELECTED = {
- strokeColor: "#ff0600",
- fillColor: "#f20c0c",
- fillOpacity: 0.25,
- };
-
- var self = {};
-
- var init = function() {
- model.events
- .on("granuleSelect", refresh)
- .on("granuleUnselect", refresh);
- };
-
- self.hoverOver = function(granule) {
- if ( !granule.geometry ) {
- return;
- }
- var geom = granule.geometry[model.crs];
- var extent =
- config.projections[model.projection].maxExtent.toGeometry();
- if ( geom && extent.intersects(geom) ) {
- var hoverFeature = new OpenLayers.Feature.Vector(
- granule.geometry[model.crs], {
- granule: granule
- }
- );
- applyStyle(hoverFeature);
- getLayer().addFeatures([hoverFeature]);
- }
- };
-
- self.hoverOut = function() {
- self.clear();
- };
-
- self.clear = function() {
- var layer = Worldview.Map.getLayerByName(maps.map, LAYER_NAME);
- if ( layer ) {
- layer.removeAllFeatures();
- }
- };
-
- self.dispose = function() {
- $.each(maps.projections, function(index, map) {
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( layer ) {
- map.removeLayer(layer);
- }
- });
- };
-
- var refresh = function(granule) {
- var layer = getLayer();
- if ( layer.features.length === 0 ) {
- return;
- }
- var feature = layer.features[0];
- var hoverGranule = feature.attributes.granule;
- if ( hoverGranule.id === granule.id ) {
- applyStyle(feature);
- layer.drawFeature(feature);
- }
- };
-
- var applyStyle = function(feature) {
- var granule = feature.attributes.granule;
- var selected = model.selectedGranules[granule.id];
- var style = ( selected ) ? STYLE_HOVER_SELECTED: STYLE_HOVER_UNSELECTED;
- feature.style = style;
- };
-
- var createLayer = function() {
- var layer = new OpenLayers.Layer.Vector(LAYER_NAME);
- layer.div.setAttribute("data-layer-name", LAYER_NAME);
- maps.map.addLayer(layer);
- return layer;
- };
-
- var getLayer = function(map) {
- map = map || maps.map;
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( !layer ) {
- layer = createLayer();
- }
- return layer;
- };
-
- init();
- return self;
-
-};
-
-
diff --git a/src/js/Worldview/DataDownload/Layers/Selection.js b/src/js/Worldview/DataDownload/Layers/Selection.js
deleted file mode 100644
index f2f8ffa16..000000000
--- a/src/js/Worldview/DataDownload/Layers/Selection.js
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload.Layers");
-
-Worldview.DataDownload.Layers.Selection = function(model, maps, config) {
-
- var LAYER_NAME = "DataDownload_Selection";
-
- var OPACITY = 0.6;
- var STYLE = {
- strokeColor: "#808080",
- fillColor: "#808080",
- };
-
- var self = {};
- var features = {};
-
- var init = function() {
- model.events
- .on("granuleSelect", onGranuleSelect)
- .on("granuleUnselect", onGranuleUnselect);
- };
-
- self.clear = function() {
- var layer = Worldview.Map.getLayerByName(maps.map, LAYER_NAME);
- if ( layer ) {
- layer.removeAllFeatures();
- }
- };
-
- self.dispose = function() {
- $.each(maps.projections, function(index, map) {
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( layer ) {
- map.removeLayer(layer);
- }
- });
- features = {};
- };
-
- self.select = function(granule) {
- onGranuleSelect(granule);
- };
-
- var onGranuleSelect = function(granule) {
- if ( !granule.geometry ) {
- return;
- }
- var geom = granule.geometry[model.crs];
- var extent =
- config.projections[model.projection].maxExtent.toGeometry();
- if ( geom && extent.intersects(geom) ) {
- // Exit if already selected
- if ( features[granule.id] ) {
- return;
- }
- var feature = new OpenLayers.Feature.Vector(geom.clone());
- features[granule.id] = feature;
- getLayer().addFeatures([feature]);
- }
- };
-
-
- var onGranuleUnselect = function(granule) {
- if ( !granule.geometry ) {
- return;
- }
- var feature = features[granule.id];
- if ( !feature ) {
- return;
- }
- getLayer().removeFeatures([feature]);
- getLayer().redraw();
- delete features[granule.id];
- };
-
- self.refresh = function() {
- self.clear();
- features = {};
- $.each(model.selectedGranules, function(index, granule) {
- self.select(granule);
- });
- };
-
- var createLayer = function() {
- layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
- styleMap: new OpenLayers.StyleMap(STYLE)
- });
- layer.div.setAttribute("data-layer-name", LAYER_NAME);
- layer.setOpacity(OPACITY);
- maps.map.addLayer(layer);
-
- return layer;
- };
-
- var getLayer = function(map) {
- map = map || maps.map;
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( !layer ) {
- layer = createLayer();
- }
- return layer;
- };
-
- init();
- return self;
-
-};
\ No newline at end of file
diff --git a/src/js/Worldview/DataDownload/Layers/Swath.js b/src/js/Worldview/DataDownload/Layers/Swath.js
deleted file mode 100644
index d9fd62721..000000000
--- a/src/js/Worldview/DataDownload/Layers/Swath.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload.Layers");
-
-Worldview.DataDownload.Layers.Swath = function(model, maps, config) {
-
- var LAYER_NAME = "DataDownload_Swaths";
- var STYLE = {
- strokeColor: "#c3bd7b",
- strokeOpacity: 0.75,
- strokeWidth: 2
- };
- var MAX_DISTANCE_GEO = 270;
-
- var self = {};
-
- self.update = function(results) {
- self.clear();
- var swaths = results.meta.swaths;
- if ( !swaths ) {
- return;
- }
- var layer = getLayer();
-
- var maxDistance = ( model.crs === Worldview.Map.CRS_WGS_84 )
- ? MAX_DISTANCE_GEO : Number.POSITIVE_INFINITY;
-
- var features = [];
- $.each(swaths, function(index, swath) {
- var lastGranule = null;
- // Main granules or west side granuels
- $.each(swath, function(index, granule) {
- if ( !lastGranule ) {
- lastGranule = granule;
- return;
- }
- var polys1 = Worldview.Map.toPolys(lastGranule.geometry[model.crs]);
- var polys2 = Worldview.Map.toPolys(granule.geometry[model.crs]);
- $.each(polys1, function(index1, poly1) {
- $.each(polys2, function(index2, poly2) {
- var c1 = poly1.getCentroid();
- var c2 = poly2.getCentroid();
- var distanceX = Worldview.Map.distanceX(c1, c2);
- if ( distanceX < maxDistance ) {
- features.push(new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.LineString([c1, c2])
- ));
- }
- });
- });
- lastGranule = granule;
- });
-
- });
- layer.addFeatures(features);
- };
-
- self.clear = function() {
- var layer = Worldview.Map.getLayerByName(maps.map, LAYER_NAME);
- if ( layer ) {
- layer.removeAllFeatures();
- }
- };
-
- self.dispose = function() {
- $.each(maps.projections, function(index, map) {
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( layer ) {
- map.removeLayer(layer);
- }
- });
- };
-
- var createLayer = function() {
- var layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
- styleMap: new OpenLayers.StyleMap(STYLE)
- });
- layer.div.setAttribute("data-layer-name", LAYER_NAME);
- maps.map.addLayer(layer);
- return layer;
- };
-
- var getLayer = function(map) {
- map = map || maps.map;
- var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);
- if ( !layer ) {
- layer = createLayer();
- }
- return layer;
- };
-
- return self;
-};
diff --git a/src/js/Worldview/DataDownload/SelectionListPanel.js b/src/js/Worldview/DataDownload/SelectionListPanel.js
deleted file mode 100644
index 3faa27053..000000000
--- a/src/js/Worldview/DataDownload/SelectionListPanel.js
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-Worldview.namespace("DataDownload");
-
-Worldview.DataDownload.SelectionListPanel = function(model, results) {
-
- var panel = null;
- var self = {};
- var granules = {};
-
- var init = function() {
- model.events.on("granuleUnselect", onGranuleUnselect);
- };
-
- self.show = function() {
- panel = new YAHOO.widget.Panel("DataDownload_SelectionListPanel", {
- width: "400px",
- height: "400px",
- zIndex: 1020,
- visible: false,
- close: false,
- constraintoviewport: true
- });
- panel.setHeader("Select data");
-
- panel.setBody(bodyText());
- panel.render(document.body);
- panel.show();
- panel.center();
- panel.hideEvent.subscribe(function() {
- setTimeout(dispose, 25);
- });
-
- $.each(results.granules, function(index, granule) {
- granules[granule.id] = granule;
- });
-
- $("#DataDownload_GranuleList input").on("click", toggleSelection);
- };
-
- self.hide = function() {
- if ( panel ) {
- panel.hide();
- }
- };
-
- self.visible = function() {
- return panel !== null;
- };
-
- self.setVisible = function(value) {
- if ( !value ) {
- $("#DataDownload_SelectionListPanel").hide();
- } else {
- $("#DataDownload_SelectionListPanel").show();
- }
- };
-
- var dispose = function() {
- panel.destroy();
- panel = null;
- $("#DataDownload_GranuleList input").off("click", toggleSelection);
- };
-
- var resultsText = function() {
- var elements = [];
- $.each(results.granules, function(index, granule) {
- var selected = model.isSelected(granule) ? "checked='true'" : "";
- elements.push(
- "<tr>" +
- "<td>" +
- "<input type='checkbox' value='" + granule.id + "' " +
- selected + ">" +
- "</td>" +
- "<td class='label'>" + granule.label + "</td>" +
- "</tr>"
- );
- });
- var text = elements.join("\n");
- return text;
- };
-
- var bodyText = function() {
- var elements = [
- "<div id='DataDownload_GranuleList'>",
- "<table>",
- resultsText(),
- "</table>",
- "</div>"
- ];
- var text = elements.join("\n") + "<br/>";
- return text;
- };
-
- var toggleSelection = function(event, ui) {
- var granule = granules[$(this).attr("value")];
- var selected = $(this).prop("checked");
- if ( selected ) {
- model.selectGranule(granule);
- } else {
- model.unselectGranule(granule);
- }
- };
-
- var onGranuleUnselect = function(granule) {
- $("#DataDownload_GranuleList input[value='" + granule.id + "']")
- .removeAttr("checked");
- };
-
-
- init();
- return self;
-
-};
diff --git a/src/js/Worldview/DataDownload/module.js b/src/js/Worldview/DataDownload/module.js
deleted file mode 100644
index 5c36289a1..000000000
--- a/src/js/Worldview/DataDownload/module.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * Browsing and selecting data granules for download.
- *
- * @module Worldview.DataDownload
- * @main Worldview.DataDownload
- */
\ No newline at end of file
diff --git a/src/js/Worldview/Map/CanvasTile.js b/src/js/Worldview/Map/CanvasTile.js
deleted file mode 100644
index 7d63f8e78..000000000
--- a/src/js/Worldview/Map/CanvasTile.js
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Map");
-
-/**
- * Class: Worldview.Map.CanvasTile
- *
- * Cavas based tile generator. The default tile generator,
- * OpenLayers.Tile.Image renders each tile in an image element. This generator
- * is simiar except that it uses canvas elements instead. This can be used in a
- * layer by providing an instance at instantiation:
- *
- * (start code)
- * var myLayer = new OpenLayers.Layer.WMTS({
- * name: "My Layer",
- * tileClass: Worldview.Map.CanvasTile,
- * ...
- * });
- * (end code)
- *
- * To apply a lookup table to dynamically change the colors of the tile,
- * set a lookupTable property in OpenLayers.Layer with a <ColorLookup> object.
- * Example:
- *
- * (start code)
- * var red = { r: 255, g: 0x00, b: 0x00, a: 255 };
- *
- * // Map green to blue
- * myLayer.lookupTable = {
- * "0,255,0,255": redInt
- * };
- * (end code)
- */
-Worldview.Map.CanvasTile = OpenLayers.Class(OpenLayers.Tile.Image, {
-
- // Element that contains the canvas to draw the tile. Initially set to
- // null and created after the tile has been loaded. Set back to null
- // when clear() is invoked.
- canvas: null,
-
- // Canvas that contains the pixels of the original tile. This allows
- // lookups to be applied multiple times without reloading the layer.
- canvasOriginal: null,
-
- // Graphics context for the canvas
- graphics: null,
-
- // Graphics context for the canvas containing the original image
- graphicsOriginal: null,
-
- // The ID of the last job submitted to the scheduler. If a response
- // comes back that is not this ID, the tile is stale and can be thrown
- // out
- latestJobId: null,
-
- initialize: function(layer, position, bounds, url, size, options) {
- // This is required or the browser will throw security exceptions
- this.crossOriginKeyword = "anonymous";
- OpenLayers.Tile.Image.prototype.initialize.apply(this, arguments);
- },
-
- /*
- * Discards the canvas.
- */
- destroy: function() {
- OpenLayers.Tile.Image.prototype.destroy.apply(this, arguments);
- this.clear();
- if ( this.canvas ) {
- this.graphics = null;
- this.canvas = null;
- this.graphicsOriginal = null;
- this.canvasOriginal = null;
- }
- },
-
- /*
- * Hides the canvas element and clears the image load error class if
- * set.
- */
- clear: function() {
- OpenLayers.Tile.Image.prototype.clear.apply(this, arguments);
- if ( this.canvas ) {
- this.canvas.style.visibility = "hidden";
- this.canvas.style.opacity = 0;
- OpenLayers.Element.removeClass(this.canvas, "olImageLoadError");
- }
- },
-
- /*
- * Returns the canvas element by creating one if necessary. Copy over the
- * style elements that OpenLayers.Tile.Image object applies to the image
- * element to the canvas element.
- */
- getCanvas: function() {
- var image = this.getImage();
- var style;
-
- if ( !this.canvas ) {
- this.canvas = document.createElement("canvas");
- this.graphics = this.canvas.getContext("2d");
- this.canvas.id = "OpenLayers.Tile.Canvas." + this.id;
- this.canvas.className = "olTileImage";
-
- style = this.canvas.style;
- if ( this.frame ) {
- style.left = image.style.left;
- style.top = image.style.top;
- style.width = image.style.width;
- style.height = image.style.height;
- }
- style.visibility = "hidden";
- style.opacity = 0;
- style.filter = image.style.filter;
- style.position = image.style.position;
- if ( this.frame ) {
- this.frame.appendChild(self.canvas);
- }
- }
- return this.canvas;
- },
-
- /*
- * Returns the element that contains the canvas.
- */
- getTile: function() {
- var canvas = this.getCanvas();
- return this.frame ? this.frame : canvas;
- },
-
- /*
- * Relods a tile from the server.
- */
- setImgSrc: function() {
- // If the tile is being reloaded, hide the canvas so that stale
- // tiles are not visible
- if ( this.canvas ) {
- this.canvas.visibility = "hidden";
- this.canvas.opacity = 0;
- this.latestJobId = 0;
- }
- if ( this.imgDiv ) {
- OpenLayers.Tile.Image.prototype.setImgSrc.apply(this, arguments);
- }
- },
-
- /*
- * Takes the loaded image and submits it to the scheduler to render the
- * color lookup table.
- */
- onImageLoad: function() {
- OpenLayers.Event.stopObservingElement(this.imgDiv);
-
- // Draw the image that was loaded and save it for anytime a color
- // lookup needs to be applied
- this.canvasOriginal = document.createElement("canvas");
- this.graphicsOriginal = this.canvasOriginal.getContext("2d");
- this.canvasOriginal.width = this.imgDiv.width;
- this.canvasOriginal.height = this.imgDiv.height;
- this.graphicsOriginal.drawImage(this.imgDiv, 0, 0);
-
- // Ensure the canvas object has been created
- var canvas = this.getCanvas();
- canvas.width = this.canvasOriginal.width;
- canvas.height = this.canvasOriginal.height;
-
- this.scheduleTile();
- },
-
- /**
- * Function: applyLookup
- * Changes the lookup table for the tile and repaints the canvas.
- */
- applyLookup: function() {
- if ( !this.canvas ) {
- return;
- }
- this.isLoading = true;
- this.events.triggerEvent("loadstart");
- this.scheduleTile();
- },
-
- /*
- * Submit the render operation to the scheduler.
- */
- scheduleTile: function() {
- var lookupTable = this.layer.lookupTable;
- if ( this.graphicsOriginal === null ) {
- return;
- }
- var source = this.graphicsOriginal.getImageData(0, 0, this.canvas.width,
- this.canvas.height);
- var destination = this.graphics.getImageData(0, 0, this.canvas.width,
- this.canvas.height);
-
- this.latestJobId = Worldview.Map.TILE_SCHEDULER.submit({
- message: {
- lookupTable: lookupTable,
- source: source,
- destination: destination
- },
- callback: this.onTileRendered,
- self: this
- });
- },
-
- /*
- * Callback for when the tile has finished rendering.
- */
- onTileRendered: function(results) {
- var self = results.self;
- var canvas = self.canvas;
-
- // If there is no longer a canvas (a zoom operation cleared it out
- // for use in the back buffer) or this render is not the last tile
- // submitted, this data is now stale and can be thrown away.
- if ( !canvas || results.id !== self.latestJobId ) {
- // Nothing
- // If the operation was cancelled during execution, ignore the result.
- } else if ( results.status === "cancelled" ) {
- // Nothing
- // If there was an error during processing, report it here
- } else if ( results.status === "error" ) {
- // Nothing
- // Draw the tile
- } else if ( results.status === "success" ){
- var imageData = results.message.destination;
- self.graphics.putImageData(imageData, 0, 0);
- canvas.style.visibility = "inherit";
- canvas.style.opacity = self.layer.opacity;
- self.canvasContext = null;
- } else {
- throw new Error("Invalid status during tile rendering: " +
- results.status);
- }
- self.isLoading = false;
- self.events.triggerEvent("loadend");
- },
-
- /*
- * This is called during a zoom for the resize transition effect. It
- * steals away the canvas object for use in the scaled image shown before
- * tiles are loaded.
- */
- createBackBuffer: function() {
- if ( !this.canvas || this.isLoading ) {
- return;
- }
- var backBuffer = this.canvas;
- this.canvas = null;
- return backBuffer;
- },
-
- /*
- * Name of this class per OpenLayers convention.
- */
- CLASS_NAME: "Worldview.Map.CanvasTile"
-
-});
-
diff --git a/src/js/Worldview/Map/DailyLayerSet.js b/src/js/Worldview/Map/DailyLayerSet.js
deleted file mode 100644
index ccbdf86fb..000000000
--- a/src/js/Worldview/Map/DailyLayerSet.js
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Map");
-
-/**
- * Class: Worldview.Map.DailyProduct
- * Product that updates on a daily basis.
- *
- * A requirement in Worldview is to be able to slide between several dates
- * and quickly see the changes per day without redrawing the map. This trick is
- * performed by adding a new layer for each day selected and setting the
- * opacity for the other layers to zero. Once the map moves, the "cached"
- * layers are invalidated and eligbile for removal the next time the map
- * needs to be redrawn.
- *
- * Delegates to:
- * <Worldview.Map.Product>
- *
- * Constructor: DailyProduct
- * Creates a new instance.
- *
- * Parameters:
- * map - The map object that layers will be added and removed from.
- * config - Configuration for this layer as a <Worldview.JSON.MapConfig.Product>
- * object.
- */
-Worldview.Map.DailyLayerSet = function(map, config, projId, layerId) {
-
- var self = Worldview.Map.LayerSet(config, projId, layerId);
-
- // The current z-index for all layers.
- var zIndex = 0;
-
- // Layers from previous days are cached for quick display when moving
- // the time slider
- var cachedLayers = {};
-
- // Layers that are no longer valid because the map has moved. These
- // are removed using a timeout to prevent map flickering.
- var staleLayers = [];
-
- // The layer that is currently visible and seen by the user
- var currentLayer = null;
-
- // The day of the data displayed on the map
- var currentDay;
-
- // Active lookup table for all layers in the product, null if no table
- // is active
- var lookupTable = null;
-
- // Timeout identifier for the reaper that cleans out stale layers.
- var reaperId = null;
-
- // Time, in milliseconds, to wait before reaping stale layers.
- var reapDelay = 500;
-
- //-------------------------------------------------------------------------
- // Public
- //-------------------------------------------------------------------------
-
- var init = function() {
- self.setDay(wv.util.today());
-
- map.events.register("movestart", self, invalidate);
- map.events.register("zoomend", self, invalidate);
- $(window).resize(invalidate);
- };
-
- /**
- * Method: setDay
- * Changes the map to display the product for the given day.
- *
- * Parameters:
- * d - The day to display.
- */
- self.setDay = function(d) {
- // Don't do anything if nothing has changed or if there are no valid
- // layers
- if ( !d ) {
- return;
- }
- var ds = wv.util.toISOStringDate(d);
- if ( ds === currentDay ) {
- return;
- }
-
- // If there is a current layer, cache it
- if ( currentLayer ) {
- cachedLayers[currentDay] = currentLayer;
- }
- currentDay = ds;
-
- // If the layer is hidden, don't fetch anything
- if ( self.visible ) {
- fetchLayer();
- } else {
- currentLayer = null;
- }
- };
-
- self.setOpacity = function(opacity) {
- if ( self.opacity === opacity ) {
- return;
- }
- self.opacity = opacity;
- if ( currentLayer ) {
- Worldview.Map.setVisiblity(currentLayer, self.visible, self.opacity);
- }
- };
-
- self.setVisibility = function(visible) {
- if ( self.visible === visible ) {
- return;
- }
- self.visible = visible;
- if ( visible && !currentLayer ) {
- fetchLayer();
- }
- if ( currentLayer ) {
- Worldview.Map.setVisibility(currentLayer, self.visible,
- self.opacity);
- }
- };
-
- /**
- * Method: setLookup
- * Applies a lookup table to this product. If this product doesn't have
- * a lookup table already, all layers are discarded and a new layer is
- * created using <Worldview.Map.CanvasTile>.
- *
- * Parameters:
- * lookup - The <ColorLookup> to apply.
- */
- self.setLookup = function(lookup) {
- var resetRequired = (lookupTable === null);
- lookupTable = lookup;
- if ( currentLayer ) {
- if ( resetRequired ) {
- reset();
- fetchLayer();
- } else {
- invalidate();
- currentLayer.lookupTable = lookup;
- applyLookup(currentLayer);
- }
- }
- };
-
- /**
- * Method: clearLookup
- * Removes a lookup table from this product. If the product has a lookup
- * table, all layers are discarded and a new layer using the standard
- * tile renderer is created.
- */
- self.clearLookup = function() {
- if ( lookupTable !== null ) {
- lookupTable = null;
- if ( currentLayer ) {
- reset();
- fetchLayer();
- }
- }
- };
-
- /**
- * Method: setZIndex
- * Sets the z-index for all layers in this product.
- *
- * Parameters:
- * index - The z-index to set. All layers are set with this z-index
- * except for the visible layer which is set to index + 1.
- */
- self.setZIndex = function(index) {
- zIndex = index;
- refreshZOrder();
- };
-
- /**
- * Method: dispose
- * Remove all layers from the map.
- */
- self.dispose = function() {
- reset();
- if ( reaperId !== null ) {
- clearTimeout(reaperId);
- }
- map.events.unregister("movestart", self, invalidate);
- map.events.unregister("zoomend", self, invalidate);
- $(window).unbind("resize", invalidate);
- };
-
- //-------------------------------------------------------------------------
- // Private
- //-------------------------------------------------------------------------
-
- var fetchLayer = function() {
- var previousLayer = currentLayer;
-
- if ( currentDay in cachedLayers ) {
- currentLayer = cachedLayers[currentDay];
- Worldview.Map.setVisibility(currentLayer, self.visible,
- self.opacity);
- delete cachedLayers[currentDay];
- } else {
- var additionalOptions = {
- time: currentDay
- };
- if ( lookupTable !== null ) {
- additionalOptions.tileClass = Worldview.Map.CanvasTile;
- }
- currentLayer = self.createLayer(additionalOptions);
- if ( lookupTable !== null ) {
- currentLayer.lookupTable = lookupTable;
- }
- map.addLayer(currentLayer);
- }
-
- if ( previousLayer ) {
- previousLayer.setZIndex(zIndex);
- }
- currentLayer.setZIndex(zIndex + 1);
- Worldview.Map.setVisibility(currentLayer, self.visible, self.opacity);
-
- if ( previousLayer ) {
- Worldview.Map.setVisibility(previousLayer, false, 0);
- }
- };
-
- /*
- * Iterates through each tile in the layer and applies the lookup.
- */
- var applyLookup = function(layer) {
- $.each(layer.grid, function(index, row) {
- $.each(row, function(index, tile) {
- tile.applyLookup();
- });
- });
- };
-
- /*
- * Sets the z-index on all layers.
- */
- var refreshZOrder = function() {
- $.each(cachedLayers, function(i, layer) {
- layer.setZIndex(zIndex);
- });
- if ( currentLayer ) {
- currentLayer.setZIndex(zIndex + 1);
- }
- };
-
- /*
- * Clears the cache and removes the current layer. Called when switching
- * between a lookup and non-lookup based layer.
- */
- var reset = function() {
- invalidate();
- if ( currentLayer ) {
- map.removeLayer(currentLayer);
- }
- currentLayer = null;
- };
-
- /*
- * Hide all layers that are not currently being displayed and move them
- * to the stale set. Restart the reaper to remove those layers.
- */
- var invalidate = function() {
- if ( currentLayer ) {
- var opacity = currentLayer.div.style.opacity;
- if ( opacity !== "" && opacity < 0.001 ) {
- currentLayer.setVisibility(false);
- }
- }
- if ( $.isEmptyObject(cachedLayers) ) {
- return;
- }
- $.each(cachedLayers, function(day, layer) {
- layer.setVisibility(false);
- staleLayers.push(layer);
- });
- cachedLayers = {};
-
- if ( reaperId !== null ) {
- clearTimeout(reaperId);
- }
- reaperId = setTimeout(function() { reaper(); }, reapDelay);
- };
-
-
- /*
- * Remove all layers in the invalid set from the map.
- */
- var reaper = function(all) {
- $.each(staleLayers, function(index, layer) {
- if ( map.getLayerIndex(layer) >= 0 ) {
- map.removeLayer(layer);
- }
- });
- staleLayers = [];
- refreshZOrder();
- reaperId = null;
- };
-
- init();
- return self;
-};
diff --git a/src/js/Worldview/Map/GraticuleLayer.js b/src/js/Worldview/Map/GraticuleLayer.js
deleted file mode 100644
index 0471f0d44..000000000
--- a/src/js/Worldview/Map/GraticuleLayer.js
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Map");
-
-/**
- * Class: Worldview.Map.GraticleLayer
- * Standard OpenLayers graticle control that acts like a layer.
- */
-Worldview.Map.GraticuleLayer = OpenLayers.Class(OpenLayers.Layer, {
-
- graticuleLineStyle: null,
- graticuleLabelStyle: null,
- graticule: null,
- isControl: true,
-
- initialize: function(name, options) {
- OpenLayers.Layer.prototype.initialize.apply(this, arguments);
-
- this.graticuleLineStyle = new OpenLayers.Symbolizer.Line({
- strokeColor: '#AAAAAA',
- strokeOpacity: 0.95,
- strokeWidth: 1.35,
- strokeLinecap: 'square',
- strokeDashstyle: 'dot'
- });
-
- this.graticuleLabelStyle = new OpenLayers.Symbolizer.Text({
- fontFamily: 'Gill Sans',
- fontSize: '16',
- fontWeight: '550',
- fontColor: '#0000e1',
- fontOpacity: 1.0
- });
- },
-
- /*
- * Add the control when the layer is added to the map
- */
- setMap: function(map) {
- OpenLayers.Layer.prototype.setMap.apply(this, arguments);
-
- this.graticule = new OpenLayers.Control.Graticule({
- layerName: 'ol_graticule_control',
- numPoints: 2,
- labelled: true,
- lineSymbolizer: this.graticuleLineStyle,
- labelSymbolizer: this.graticuleLabelStyle
- });
-
- map.addControl(this.graticule);
- },
-
- /*
- * Remove the contorl when the layer is removed from the map
- */
- removeMap: function(map) {
- OpenLayers.Layer.prototype.removeMap.apply(this, arguments);
- map.removeControl(this.graticule);
- this.graticule.destroy();
- this.graticule = null;
- },
-
- setVisibility: function(value) {
- if ( !this.granule ) {
- return;
- }
- if ( value ) {
- this.graticule.activate();
- } else {
- this.graticule.deactivate();
- }
- },
-
- /*
- * Name of this class per OpenLayers convention.
- */
- CLASS_NAME: "Worldview.Map.GraticuleLayer"
-});
diff --git a/src/js/Worldview/Map/HoverControl.js b/src/js/Worldview/Map/HoverControl.js
deleted file mode 100644
index 0bfed9e8c..000000000
--- a/src/js/Worldview/Map/HoverControl.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Map");
-
-Worldview.Map.HoverControl = OpenLayers.Class(OpenLayers.Control, {
-
- layer: null,
-
- defaultHandlerOptions: {
- delay: 2000,
- pixelTolerance: 1,
- stopMove: false
- },
-
- featureHandler: null,
-
- initialize: function(layer, options) {
- this.layer = layer;
- this.handlerOptions = OpenLayers.Util.extend({},
- this.defaultHandlerOptions);
- OpenLayers.Control.prototype.initialize.apply(this, arguments);
-
- this.featureHandler = new OpenLayers.Handler.Feature(this, this.layer, {
- over: this.over,
- out: this.out
- }, {});
- this.handlers = {
- feature: this.featureHandler
- };
- },
-
- draw: function() {
- return false;
- },
-
- activate: function() {
- this.handlers.feature.activate();
- },
-
- deactivate: function() {
- this.handlers.feature.deactivate();
- },
-
- over: function(feature) {
- this.events.triggerEvent("hoverover", {feature: feature});
- },
-
- out: function(feature) {
- this.events.triggerEvent("hoverout", {feature: feature});
- }
-});
-
-
-
-
-
diff --git a/src/js/Worldview/Map/LayerSet.js b/src/js/Worldview/Map/LayerSet.js
deleted file mode 100644
index 663945861..000000000
--- a/src/js/Worldview/Map/LayerSet.js
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Map");
-
-/**
- * Class: Worldview.Map.Product
- * Provides common methods for all products.
- *
- * Constructor: Worldview.Map.Product
- * Creates a new instance.
- *
- * Parameters:
- * c - Configuration for this layer as a <Worldview.JSON.MapConfig.Product>
- * object.
- */
-Worldview.Map.LayerSet = function(config, projId, layerId) {
-
- var self = {};
- self.opacity = 1;
- self.visible = false;
-
- var init = function() {
- /*
- config = $.extend(true, {}, c);
-
- var prop = config.properties || {};
- if ( prop.style === undefined ) { prop.style = ""; }
- if ( prop.tileSize ) {
- prop.tileSize = new OpenLayers.Size(prop.tileSize[0],
- prop.tileSize[1]);
- }
- if ( prop.transitionEffect === undefined ) {
- prop.transitionEffect = "resize";
- }
-
- // HACK: For the moment, some projections use TWMS and others use
- // WMTS. Copy the type attribute to the correct location if required
- if ( config.properties.type ) {
- config.type = config.properties.type;
- delete config.properties.type;
- }
- // If this is a WMS layer, the urls are passed in directly and not
- // part of the parameters or properties
- if ( config.type === "wms" && config.properties.url ) {
- config.url = config.properties.url;
- delete config.properties.url;
- }
- // TWMS does not like the projection parameter, remove it
- if ( config.type === "wms" && config.parameters ) {
- delete config.parameters.projection;
- }
- */
- };
-
- var createWMTS = function(options) {
- var proj = config.projections[projId];
- var layer = config.layers[layerId];
- var matrixSet = config.matrixSets[layer.projections[projId].matrixSet];
- var source = config.sources[layer.projections[projId].source];
- var param = {
- url: source.url,
- layer: layer.id,
- style: "",
- format: layer.format,
- matrixSet: matrixSet.id,
- maxResolution: matrixSet.maxResolution,
- serverResolutions: matrixSet.serverResolutions,
- maxExtent: proj.maxExtent,
- tileSize: new OpenLayers.Size(layer.tileSize[0],
- layer.tileSize[1])
- };
- if ( layer.noTransition ) {
- param.transitionEffect = "none";
- } else {
- param.transitionEffect = "resize";
- }
- if ( options.tileClass ) {
- param.tileClass = options.tileClass;
- }
- var olLayer = new OpenLayers.Layer.WMTS(param);
- if ( options && options.time ) {
- olLayer.mergeNewParams({"time": options.time});
- }
- return olLayer;
- };
-
- var createWMS = function(options) {
- var proj = config.projections[projId];
- var layer = config.layers[layerId];
- var source = config.sources[layer.projections[projId].source];
- var layerParameter = layer.projections[projId].layer || layerId;
-
- var transparent = ( layer.format === "image/png" );
-
- var params = {
- layers: layerParameter,
- format: layer.format,
- transparent: transparent
- };
- if ( layer.period === "daily" ) {
- params.time = options.time;
- };
- var options = {
- tileSize: new OpenLayers.Size(layer.tileSize[0],
- layer.tileSize[1]),
- };
- if ( layer.opacity ) {
- options.opacity = layer.opacity;
- }
- if ( layer.transition ) {
- options.transitionEffect = "resize";
- } else {
- options.transitionEffect = "none";
- }
- var olLayer = new OpenLayers.Layer.WMS(layer.title, source.url,
- params, options);
- return olLayer;
- };
-
- /**
- * Function: createLayer
- * Creates a new layer based on the configuration provided.
- *
- * Parameters:
- * additionalProperties - If specified, these properites are merged into
- * the product configuration to create the layer.
- *
- * Return:
- * An OpenLayers Layer.
- */
- self.createLayer = function(options) {
- options = options || {};
- var type = config.layers[layerId].type;
- if ( type === "wmts" ) {
- return createWMTS(options);
- } else if ( type === "wms" ) {
- return createWMS(options);
- } else if ( type === "graticule" ) {
- return new Worldview.Map.GraticuleLayer("Graticule");
- } else {
- throw new Error("Invalid layer type: " + type);
- }
- /*
- var properties = config.properties;
- if ( additionalProperties ) {
- properties = $.extend(true, {}, config.properties,
- additionalProperties);
- }
- var parameters = config.parameters;
- if ( additionalParameters ) {
- parameters = $.extend(true, {}, config.parameters,
- additionalParameters);
- }
- var layer;
- if ( properties.opacity ) {
- self.opacity = properties.opacity;
- } else {
- properties.opacity = self.opacity;
- }
- //properties.visiblity = false;
- if ( config.type === "wms" ) {
- layer = new Worldview.Map.TWMSLayer(config.name, config.url,
- parameters, properties);
- } else if ( config.type === "wmts" ) {
- layer = new OpenLayers.Layer.WMTS(properties);
- if ( parameters && parameters.time ) {
- layer.mergeNewParams({"time": parameters.time});
- }
- } else if ( config.type === "graticule" ) {
- layer = new Worldview.Map.GraticuleLayer(config.name,
- properties);
- } else {
- throw new Error("Unsupported layer type: " + config.type);
- }
- layer.setVisibility(false);
- return layer;
- */
- };
-
- init();
- return self;
-};
diff --git a/src/js/Worldview/Map/MockLayerSet.js b/src/js/Worldview/Map/MockLayerSet.js
deleted file mode 100644
index 894af9cb0..000000000
--- a/src/js/Worldview/Map/MockLayerSet.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Map");
-
-Worldview.Map.MockLayerSet = function() {
-
- return {
- setDay: function() {},
- setOpacity: function() {},
- setVisibility: function() {},
- setZIndex: function() {},
- dispose: function() {},
- setLookup: function() {},
- clearLookup: function() {}
- };
-
-};
\ No newline at end of file
diff --git a/src/js/Worldview/Map/StaticLayerSet.js b/src/js/Worldview/Map/StaticLayerSet.js
deleted file mode 100644
index 9a6a4fdce..000000000
--- a/src/js/Worldview/Map/StaticLayerSet.js
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Map");
-
-/**
- * Class: Worldview.Map.StaticProduct
- * Product that is not based on the current date or time.
- *
- * Inherits from:
- * <Worldview.Map.Product>
- *
- * Constructor: StaticProduct
- * Creates a new instance.
- *
- * Parameters:
- * map - The map object that layers will be added and removed from.
- * config - Configuration for this layer as a <Worldview.JSON.MapConfig.Product>
- * object.
- */
-Worldview.Map.StaticLayerSet = function(map, config, projId, layerId) {
-
- var self = Worldview.Map.LayerSet(config, projId, layerId);
-
- // There is only one layer and this is it
- var layer = null;
-
- // Tue current z-index for the layer
- var zIndex = 0;
-
- //-------------------------------------------------------------------------
- // Public
- //-------------------------------------------------------------------------
- var init = function() {
- layer = self.createLayer();
- map.addLayer(layer);
- layer.setZIndex(zIndex);
-
- map.events.register("movestart", self, invalidate);
- map.events.register("zoomend", self, invalidate);
- };
-
- /**
- * Method: setDay
- * Does nothing.
- */
- self.setDay = function(d) {
- };
-
- self.setOpacity = function(opacity) {
- if ( self.opacity === opacity ) {
- return;
- }
- self.opacity = opacity;
- Worldview.Map.setVisibility(layer, self.visible, self.opacity);
- };
-
- self.setVisibility = function(visible) {
- if ( self.visible === visible ) {
- return;
- }
- self.visible = visible;
- Worldview.Map.setVisibility(layer, self.visible, self.opacity);
- };
-
- /**
- * Method: setZIndex
- * Sets the z-index for the product's layer.
- *
- * Parameters:
- * index - The z-index to set.
- */
- self.setZIndex = function(index) {
- zIndex = index;
- setZOrder();
- };
-
- /**
- * Method: dispose
- * Removes the layer from the map.
- */
- self.dispose = function() {
- map.removeLayer(layer);
- map.events.unregister("movestart", self, invalidate);
- map.events.unregister("zoomend", self, invalidate);
- };
-
- /**
- * Method: setLookup
- * Does nothing. This can be implemented once there is a static data
- * product that could be adjusted.
- */
- self.setLookup = function(lookup) {
- };
-
- /**
- * Method: clearLookup
- * Does nothing. This can be implemented once there is a static data
- * product that could be adjusted.
- */
- self.clearLookup = function() {
- };
-
- //-------------------------------------------------------------------------
- // Private
- //-------------------------------------------------------------------------
- var setZOrder = function() {
- layer.setZIndex(zIndex);
- };
-
- var invalidate = function() {
- if ( layer ) {
- var opacity = layer.div.style.opacity;
- if ( opacity !== "" && opacity < 0.001 ) {
- layer.setVisibility(false);
- }
- }
- setZOrder();
- };
-
- init();
- return self;
-};
diff --git a/src/js/Worldview/Map/TWMSLayer.js b/src/js/Worldview/Map/TWMSLayer.js
deleted file mode 100644
index 20f061910..000000000
--- a/src/js/Worldview/Map/TWMSLayer.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Worldview.Map");
-
-Worldview.Map.TWMSLayer = OpenLayers.Class(OpenLayers.Layer.WMS, {
-
- parameterOrder: [
- "time",
- "layers",
- "format"
- ],
-
- initialize: function(name, url, params, options) {
- var newArguments = [];
- var newParams = {};
-
- $.each(this.parameterOrder, function(index, name) {
- if ( params[name] ) {
- newParams[name] = params[name];
- }
- });
- $.each(params, function(name, value) {
- if ( $.inArray(name, this.parameterOrder) < 0 ) {
- newParams[name] = value;
- }
- });
-
- newArguments.push(name, url, newParams, options);
- OpenLayers.Layer.WMS.prototype.initialize.apply(this, newArguments);
- },
-
- CLASS_NAME: "Worldview.Map.TWMSLayer"
-
-});
diff --git a/src/js/Worldview/Widget/Map.js b/src/js/Worldview/Widget/Map.js
deleted file mode 100644
index 66beb18e9..000000000
--- a/src/js/Worldview/Widget/Map.js
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Widget");
-
-/**
- * Class: Worldview.Widget.Map
- * Widget that provides the map for displaying data layers.
- *
- * Constructor: Worldview.Widget.Map
- * Creates a new instance.
- *
- * Parameters:
- * containerId - The id of the div element to place the map into
- * spec.dataSourceUrl - The endpoint where configuration information should
- * be obtained from.
- * spec.onReady - function to be invoked once the map has read in the
- * configuration and is ready to be used.
- */
-Worldview.Widget.Map = function(containerId, config) {
-
- var self = {};
-
- /**
- * Property: maps
- * The <Worldview.Map.maps> that contains the map objects, one for
- * each projection.
- */
- self.maps = null;
-
- /**
- * Property: config
- * The <Worldview.JSON.MapConfig> object retrieved from the server that
- * defines the available projections and data products.
- */
- self.config = config;
-
- var init = function() {
- self.config = validateConfig(self.config);
- self.maps = Worldview.Map.MapSet(containerId,
- self.config, self);
-
- $.each(self.config.layers, function(name, config) {
- if ( config.defaultLayer === "true" ) {
- self.maps.append(name);
- }
- });
- };
-
- /**
- * Method: setValue
- * Zooms to the specified extent.
- *
- * Parameters:
- * value - String in the form of L_B_R_U where L is the left X value,
- * B is the bottom Y value, R is the right X value, and U is the upper
- * Y value. Commas instead of underscores are also accepted.
- */
- self.setValue = function(value) {
- if ( value === undefined ) {
- return;
- }
-
- var extent = OpenLayers.Bounds.fromString(value);
- var map = self.maps.map;
-
- // Verify that the viewport extent overlaps the valid extent, if
- // invalid, just zoom out the max extent
- if ( !Worldview.Map.isExtentValid(extent) ||
- !extent.intersectsBounds(map.getMaxExtent()) ) {
- console.warn("Extent is invalid: " + extent + "; using " +
- map.getExtent());
- extent = map.getExtent();
- }
- self.maps.map.zoomToExtent(extent, true);
- };
-
- /**
- * Method: getValue
- * Returns the current extent as a query string.
- *
- * Returns:
- * The value in the form of I=L_B_R_U where I is the container id, L is the
- * left X value, B is the bottom Y value, R is the right X value,
- * and U is the upper Y value.
- */
- self.getValue = function() {
- var queryString = containerId + "=" +
- self.maps.map.getExtent().toBBOX();
- return queryString;
- };
-
- /**
- * Method: loadFromQuery
- * Sets the projection and zooms to the extent given values in a query
- * string.
- *
- * Parameters:
- * queryString: If switch=X appears in the string, the projection is
- * set to X. If containerId=Y where containerId is the id that was used
- * to construct this object, the map is zoomed to extent Y as defined
- * in <setValue>
- */
- self.loadFromQuery = function(queryString) {
- var query = Worldview.queryStringToObject(queryString);
- if ( query.map ) {
- self.setValue(query.map);
- } else if ( query.center && query.zoom ) {
- try {
- var coordinate = query.center.split(",");
- var x = parseFloat(coordinate[0]);
- var y = parseFloat(coordinate[1]);
- center = [x, y];
- self.maps.map.setCenter(center, parseInt(query.zoom));
- } catch ( error ) {
- console.warn("Unable to set center and zoom: " + error);
- }
- }
- self.updateComponent(queryString);
- };
-
- /**
- * Method: validate
- * Always returns true.
- */
- self.validate = function() {
- return true;
- };
-
- /**
- * Method: setDataSourceUrl
- * Throws an unsupported exception.
- */
- self.setDataSourceUrl = function(url) {
- throw new Error("setDataSourceUrl: unsupported");
- };
-
- /**
- * Method: getDataSourceUrl
- * Gets the URL endpoint where configuration data is obtained.
- *
- * Returns:
- * The URL to the configuration endpoint.
- */
- self.getDataSourceUrl = function() {
- return spec.dataSourceUrl;
- };
-
- /**
- * Method: setStatus
- * Throws an unsupported exception as it seems this method is never
- * invoked.
- */
- self.setStatus = function(status) {
- throw new Error("setStatus: unsupported");
- };
-
- /**
- * Method: getStatus
- * Throws an unsupported exception as it seems this method is never
- * invoked.
- */
- self.getStatus = function() {
- throw new Error("getStatus: unsupported");
- };
-
- /*
- * Make sure that all the required parameters exist in the map
- * configuration.
- */
- var validateConfig = function(config) {
- var root = ["defaults", "projections", "layers"];
- $.each(root, function(index, key) {
- if ( !config.hasOwnProperty(key) ) {
- throw key + " is required in the map configuration";
- }
- });
- var _config = ["projection"];
- $.each(_config, function(index, key) {
- if ( !(key in config.defaults ) ) {
- throw new Error("defaults." + key + " is required for the " +
- "map configuraiton");
- }
- });
- return config;
- };
- init();
- return self;
-};
-
-
-
-
diff --git a/src/js/Worldview/Widget/WorldviewMap.js b/src/js/Worldview/Widget/WorldviewMap.js
deleted file mode 100644
index a48215f4b..000000000
--- a/src/js/Worldview/Widget/WorldviewMap.js
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Widget");
-
-/**
- * Class: Worldview.Widget.WorldviewMap
- * Map features that are specific to Worldview.
- *
- * Delegates to:
- * <Worldview.Widget.Map>
- *
- * Constructor: Worldview.Widget.WorldviewMap
- * Creates a new instance.
- *
- * Parameters:
- * containerId - The id of the div element to place the map into
- * spec.dataSourceUrl - The endpoint where configuration information should
- * be obtained from.
- * spec.onReady - function to be invoked once the map has read in the
- * configuration and is ready to be used.
- */
-Worldview.Widget.WorldviewMap = function(containerId, config) {
-
- var ns = Worldview.Widget;
-
- var self = ns.Map(containerId, config);
- var lastState = {};
- var last = null;
-
- var init = function() {
- //Logging.debug("Worldview.Map");
- if ( REGISTRY ) {
- REGISTRY.register(containerId, self);
- } else {
- throw new Error("Cannot register Map, REGISTRY not found");
- }
-
- REGISTRY.markComponentReady(containerId);
-
- setExtentToLeading();
- // FIXME: It should not be getting this value from global
- self.updateComponent(wv.models.link.get());
- };
-
- /**
- * Method: updateComponent
- * Updates the map when the state of the application changes.
- *
- * Parameters:
- * queryString - If products=X is defined, ensure that only the layers for
- * X are visible. If switch=Y is defined, changes the projection of the
- * map to Y if necessary.
- */
- self.updateComponent = function(queryString) {
- try {
- if ( !(self.maps.projection in lastState) ) {
- lastState[self.maps.projection] = {};
- }
- last = lastState[self.maps.projection];
-
- if ( last.queryString === queryString ) {
- return;
- }
- var state = REGISTRY.getState();
-
- if ( state.projection !== undefined &&
- state.projection !== last.projection ) {
- var projection = state.projection;
- if ( !(projection in self.maps.mapConfig.projections) ) {
- var defaultProjection =
- self.maps.mapConfig.defaults.projection;
- console.warn("Invalid projection: " + projection + ", using: " +
- defaultProjection);
- projection = defaultProjection;
- }
- self.maps.setProjection(projection);
- self.maps.set(state.layers, state.hiddenLayers);
- } else if ( state.layersString !== last.layersString ) {
- self.maps.set(state.layers, state.hiddenLayers);
- // If the layers changed, force setting the palettes
- // again
- if ( !Worldview.arrayEquals(state.layers, last.layers) ) {
- last.palettesString = "";
- }
- var topLayerSelected = false;
- $.each(state.baselayers, function(index, layer) {
- var alreadyHidden =
- $.inArray(layer, state.hiddenLayers) >= 0;
- var visible = !topLayerSelected && !alreadyHidden;
- if ( visible && !topLayerSelected ) {
- topLayerSelected = true;
- }
- self.maps.setVisibility(layer, visible);
- });
- }
- if ( state.time !== last.time ) {
- self.maps.setDay(state.time);
- }
- if ( state.palettesString !== last.palettesString ) {
- self.maps.setPalettes(state.palettes);
- }
- if ( state.opacityString !== last.opacityString) {
- $.each(state.opacity, function(layerName, opacity) {
- self.maps.setOpacity(layerName, opacity);
- });
- }
- last = state;
- last.queryString = queryString;
- lastState[self.maps.projection] = last;
- } catch ( cause ) {
- Worldview.error("Unable to update map", cause);
- }
- };
-
- self.parse = function(queryString, object) {
- parseProducts(queryString, object);
- return object;
- };
-
- // TODO: This should be moved to the product picker
- var parseProducts = function(queryString, object) {
- object.layers = [];
- object.visibleLayers = [];
- object.hiddenLayers = [];
- object.baselayers = [];
- object.overlays = [];
-
- var products = Worldview.extractFromQuery("products", queryString);
- object.layersString = products;
- if ( !products ) {
- return object;
- }
- var sets = products.split("~");
- for ( var i = 0; i < sets.length; i++ ) {
- var set = sets[i];
- var items = set.split(",");
- var values = [];
- var type = items[0];
- object[type] = [];
- for ( var j = 1; j < items.length; j++ ) {
- var name = items[j];
- if ( name.substring(0, 1) == "!" ) {
- name = name.substring(1);
- object.hiddenLayers.push(name);
- } else {
- object.visibleLayers.push(name);
- }
- values.push(name);
- object[type].push(name);
- }
- // Products are listed in the "opposite" order from what is
- // expected--the first layer is the layer to be drawn last.
- // Flip them.
- values.reverse();
- object.layers = object.layers.concat(values);
- }
- return object;
- };
-
- var setExtentToLeading = function() {
- // Polar projections don't need to be positioned
- if ( self.maps.projection !== "geographic" ) {
- return;
- }
-
- var map = self.maps.map;
-
- // Set default extent according to time of day:
- // at 00:00 UTC, start at far eastern edge of map: "20.6015625,-46.546875,179.9296875,53.015625"
- // at 23:00 UTC, start at far western edge of map: "-179.9296875,-46.546875,-20.6015625,53.015625"
- var curHour = wv.util.now().getUTCHours();
-
- // For earlier hours when data is still being filled in, force a far eastern perspective
- if (curHour < 3) {
- curHour = 23;
- }
- else if (curHour < 9) {
- curHour = 0;
- }
-
- // Compute east/west bounds
- var minLon = 20.6015625 + curHour * (-200.53125/23.0);
- var maxLon = minLon + 159.328125;
-
- var minLat = -46.546875;
- var maxLat = 53.015625;
-
- var lat = minLat + (Math.abs(maxLat - minLat) / 2.0);
- var lon = minLon + (Math.abs(maxLon - minLon) / 2.0);
- var zoomLevel = 2;
-
- map.setCenter(new OpenLayers.LonLat(lon, lat), zoomLevel);
- };
-
- init();
- return self;
-};
diff --git a/src/js/component.js b/src/js/component.js
deleted file mode 100644
index 52275de9f..000000000
--- a/src/js/component.js
+++ /dev/null
@@ -1,150 +0,0 @@
-if (typeof SOTE=="undefined") {
-
- var SOTE = new Object();
-}
-
-// Creates namespace(s) under SOTE
-SOTE.namespace = function()
-{
- var obj;
- for (var i=0; i<arguments.length; i++)
- {
- var list=(""+arguments[i]).split(".");
- obj = SOTE;
- for(var j=(list[0]=="SOTE")?1:0; j<list.length; j++)
- {
- obj[list[j]] = obj[list[j]] || {};
- obj = obj[list[j]];
- }
- }
- return obj;
-};
-
-SOTE.namespace("widget");
-
-SOTE.widget.Component = function(containerId, config){
- // Content
-};
-
-/**
- * Initializes component user interface (View). All callbacks should be set
- * The entire UI should be displayed with controllers to call the events
- *
- * @this {component}
- *
-*/
-SOTE.widget.Component.prototype.init = function(){
- // Content
-};
-
-/**
- * Sets the value (Model) of the component
- *
- * @this {component}
- * @param {String} value to set the component
- *
-*/
-SOTE.widget.Component.prototype.setValue = function(value){
- // Content
-};
-
-/**
- * Gets the value (Model) of the component
- *
- * @this {component}
- * @returns {String} the value of the component
- *
-*/
-SOTE.widget.Component.prototype.getValue = function(){
- // Content
-};
-
-/**
- * Change the component based on dependencies
- *
- * @this {component}
- * @param {String} querystring contains all values of dependencies (from registry)
- *
-*/
-SOTE.widget.Component.prototype.updateComponent = function(querystring){
- // Content
-};
-
-/**
- * Sets the value from the querystring
- *
- * @this {component}
- * @param {String} qs contains the querystring
- *
-*/
-SOTE.widget.Component.prototype.loadFromQuery = function(qs){
- // Content
-};
-
-/**
- * Validates the value of the component given the component constraints
- *
- * @this {component}
- * @returns {boolean} true or false depending on whether the value of the component is valid
-*/
-SOTE.widget.Component.prototype.validate = function(){
- // Content
-};
-
-/**
- * Sets the data accessor that provides state change instructions given dependencies
- *
- * @this {component}
- * @param {String} datasourceurl is the relative location of the data accessor
- *
-*/
-SOTE.widget.Component.prototype.setDataSourceUrl = function(datasourceurl){
- // Content
-};
-
-/**
- * Gets the data accessor
- *
- * @this {component}
- * @returns {String} the relative location of the accessor
- *
-*/
-SOTE.widget.Component.prototype.getDataSourceUrl = function(){
- // Content
-};
-
-/**
- * Sets the status of the component
- *
- * @this {component}
- * @param {String} s the current status of the component (user prompts, error messages)
- *
-*/
-SOTE.widget.Component.prototype.setStatus = function(s){
- // Content
-};
-
-/**
- * Gets the status of the component
- *
- * @this {component}
- * @returns {String} the current status of the component (user prompts, error messages)
- *
-*/
-SOTE.widget.Component.prototype.getStatus = function(){
- // Content
-};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/js/data/wv.data.echo.js b/src/js/data/wv.data.echo.js
new file mode 100644
index 000000000..04cd56464
--- /dev/null
+++ b/src/js/data/wv.data.echo.js
@@ -0,0 +1,217 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+/**
+ * @module wv.data
+ */
+var wv = wv || {};
+wv.data = wv.data || {};
+wv.data.echo = wv.data.echo || {};
+
+wv.data.echo.client = wv.data.echo.client || function(spec) {
+
+ // Abort query after 45 seconds
+ var QUERY_TIMEOUT = spec.timeout || 45 * 1000;
+
+ var ns = wv.data.echo.client;
+
+ var ajaxOptions = {
+ url: "service/echo.cgi",
+ traditional: true,
+ dataType: "json",
+ timeout: QUERY_TIMEOUT
+ };
+
+ var self = {};
+
+ var init = function() {
+ ns.ajax = wv.util.ajaxCache();
+ };
+
+ self.submit = function(parameters) {
+ var queryParameters = $.extend(true, {}, ajaxOptions, parameters);
+ var startTimeDelta = parameters.startTimeDelta || 0;
+ var endTimeDelta = parameters.endTimeDelta || 0;
+
+ var t = parameters.time;
+ if ( t ) {
+ var startTime = new Date(Date.UTC(
+ t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate(),
+ 0, 0 + startTimeDelta, 0
+ ));
+ var endTime = new Date(Date.UTC(
+ t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate(),
+ 23, 59 + endTimeDelta, 59
+ ));
+
+ queryParameters.data.startTime =
+ wv.util.toCompactTimestamp(startTime);
+ queryParameters.data.endTime = wv.util.toCompactTimestamp(endTime);
+ }
+
+ var deferred = $.Deferred();
+ ns.ajax.submit(queryParameters).done(function(data) {
+ deferred.resolve(data.feed.entry);
+ }).fail(function(jqXHR, textStatus, errorThrown) {
+ deferred.reject(jqXHR, textStatus, errorThrown);
+ });
+ return deferred.promise();
+ };
+
+ init();
+ return self;
+
+};
+
+
+wv.data.echo.geometry = function(result) {
+
+ var self = {};
+ self.polygons = [];
+
+ var init = function() {
+ if ( result.polygons ) {
+ initFromPolygons(result.polygons);
+ } else if ( result.boxes ) {
+ initFromBoxes(result.boxes);
+ } else {
+ throw new Error("Unable to find spatial field");
+ }
+ };
+
+ self.toOpenLayers = function() {
+ 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);
+ olPoints.push(p);
+ });
+ olRings.push(new OpenLayers.Geometry.LinearRing(olPoints));
+ });
+ olPolygons.push(new OpenLayers.Geometry.Polygon(olRings));
+ });
+ return olPolygons[0];
+ };
+
+ var initFromPolygons = function(echoPolygons) {
+ $.each(echoPolygons, function(index, echoPolygon) {
+ var rings = [];
+ $.each(echoPolygon, function(index, echoRing) {
+ var ring = [];
+ var parts = echoRing.split(" ");
+ for ( var i = 0; i < parts.length; i+= 2 ) {
+ var y = parseFloat(parts[i]);
+ var x = parseFloat(parts[i + 1]);
+ ring.push({x: x, y: y});
+ }
+ rings.push(ring);
+ });
+ self.polygons.push(rings);
+ });
+ };
+
+ var initFromBoxes = function(echoBoxes) {
+ $.each(echoBoxes, function(index, echoBox) {
+ var ring = [];
+ var fields = echoBox.split(" ");
+ var ymin = parseFloat(fields[0]);
+ var xmin = parseFloat(fields[1]);
+ var ymax = parseFloat(fields[2]);
+ var xmax = parseFloat(fields[3]);
+ ring.push({x: xmin, y: ymin});
+ ring.push({x: xmax, y: ymin});
+ ring.push({x: xmax, y: ymax});
+ ring.push({x: xmin, y: ymax});
+ ring.push({x: xmin, y: ymin});
+
+ self.polygons.push([ring]);
+ });
+ };
+
+ init();
+ return self;
+};
+
+
+wv.data.echo.mockClient = function(suffix) {
+
+ var endpoint;
+ var results;
+
+ var self = {};
+
+ var init = function() {
+ if ( !suffix ) {
+ throw new Error("No mock ECHO suffix specified");
+ }
+ endpoint = "mock/echo.cgi-" + suffix;
+ };
+
+ self.submit = function(parameters) {
+ console.warn("Mocking ECHO query", endpoint);
+ var deferred = $.Deferred();
+ if ( !results ) {
+ $.getJSON(endpoint, function(data) {
+ try {
+ results = adjustResults(parameters, data);
+ deferred.resolve(results.feed.entry);
+ } catch ( error ) {
+ wv.util.error(error);
+ }
+ })
+ .fail(function(jqXHR, textStatus, errorThrown) {
+ deferred.reject(jqXHR, textStatus, errorThrown);
+ });
+ } else {
+ deferred.resolve(results.feed.entry);
+ }
+ return deferred.promise();
+ };
+
+ var adjustResults = function(parameters, data) {
+ var day = REGISTRY.getState().time;
+ // Mock data was retrieved for Aug 6, 2013
+ var resultsDay = new Date(Date.UTC(2013, 7, 6));
+ var diffDays = (day - resultsDay) / (1000 * 60 * 60 * 24);
+
+ $.each(data.feed.entry, function(index, entry) {
+ var timeStart = wv.util.parseTimestampUTC(entry.time_start);
+ timeStart.setUTCDate(timeStart.getUTCDate() + diffDays);
+ entry.time_start = timeStart.toISOString();
+
+ var timeEnd = wv.util.parseTimestampUTC(entry.time_end);
+ timeEnd.setUTCDate(timeEnd.getUTCDate() + diffDays);
+ entry.time_end = timeEnd.toISOString();
+ });
+
+ return data;
+ };
+
+ init();
+
+ return self;
+};
+
+wv.data.echo.REL_DATA = "http://esipfed.org/ns/fedsearch/1.1/data#";
+wv.data.echo.REL_BROWSE = "http://esipfed.org/ns/fedsearch/1.1/browse#";
+
+wv.data.echo.roundTime = function(timeString) {
+ var time = wv.util.parseTimestampUTC(timeString);
+ if ( time.getUTCMilliseconds() >= 500 ) {
+ time.setUTCSeconds(time.getUTCSeconds() + 1);
+ }
+ time.setUTCMilliseconds(0);
+ return time.toISOString();
+};
+
diff --git a/src/js/data/wv.data.handler.js b/src/js/data/wv.data.handler.js
index 5c9879c9d..c9625f947 100644
--- a/src/js/data/wv.data.handler.js
+++ b/src/js/data/wv.data.handler.js
@@ -47,10 +47,10 @@ wv.data.handler.base = function(config, model) {
if ( !ns.echo ) {
if ( config.parameters.mockECHO ) {
- ns.echo = Worldview.DataDownload.ECHO.MockClient(
+ ns.echo = wv.data.echo.mockClient(
config.parameters.mockECHO);
} else {
- ns.echo = Worldview.DataDownload.ECHO.Client({
+ ns.echo = wv.data.echo.client({
timeout: config.parameters.timeoutECHO
});
}
@@ -110,8 +110,8 @@ wv.data.handler.modisSwathMultiDay = function(config, model, spec) {
var self = wv.data.handler.base(config, model);
var init = function() {
- self.extents[Worldview.Map.CRS_WGS_84] =
- Worldview.Map.CRS_WGS_84_QUERY_EXTENT;
+ self.extents[wv.map.CRS_WGS_84] =
+ wv.map.CRS_WGS_84_QUERY_EXTENT;
};
self._submit = function(queryData) {
@@ -130,8 +130,8 @@ wv.data.handler.modisSwathMultiDay = function(config, model, spec) {
meta: {},
granules: data
};
- if ( model.crs === Worldview.Map.CRS_WGS_84 ) {
- results.meta.queryMask = Worldview.Map.CRS_WGS_84_QUERY_MASK;
+ if ( model.crs === wv.map.CRS_WGS_84 ) {
+ results.meta.queryMask = wv.map.CRS_WGS_84_QUERY_MASK;
}
var ns = wv.data.results;
@@ -400,8 +400,8 @@ wv.data.handler.modisSwath = function(config, model, spec) {
var self = wv.data.handler.base(config, model);
var init = function() {
- self.extents[Worldview.Map.CRS_WGS_84] =
- Worldview.Map.CRS_WGS_84_QUERY_EXTENT;
+ self.extents[wv.map.CRS_WGS_84] =
+ wv.map.CRS_WGS_84_QUERY_EXTENT;
};
self._submit = function(queryData) {
@@ -418,8 +418,8 @@ wv.data.handler.modisSwath = function(config, model, spec) {
meta: {},
granules: data
};
- if ( model.crs === Worldview.Map.CRS_WGS_84 ) {
- results.meta.queryMask = Worldview.Map.CRS_WGS_84_QUERY_MASK;
+ if ( model.crs === wv.map.CRS_WGS_84 ) {
+ results.meta.queryMask = wv.map.CRS_WGS_84_QUERY_MASK;
}
var ns = wv.data.results;
diff --git a/src/js/data/wv.data.js b/src/js/data/wv.data.js
new file mode 100644
index 000000000..410ed431e
--- /dev/null
+++ b/src/js/data/wv.data.js
@@ -0,0 +1,29 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+
+wv.data = (function(self) {
+
+ self.parse = function(state, errors, config) {
+ var productId = state.dataDownload;
+ if ( productId ) {
+ if ( !config.products[productId] ) {
+ delete state.dataDownload;
+ errors.push({ message: "No such product: " + productId });
+ }
+ }
+ };
+
+ return self;
+
+})(wv.data || {});
+
diff --git a/src/js/data/wv.data.layers.js b/src/js/data/wv.data.layers.js
new file mode 100644
index 000000000..f1d01bb65
--- /dev/null
+++ b/src/js/data/wv.data.layers.js
@@ -0,0 +1,628 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+/**
+ * @module wv.data
+ */
+var wv = wv || {};
+wv.data = wv.data || {};
+
+wv.data.layers = wv.data.layers || {};
+
+wv.data.layers.button = wv.data.layers.button || function(model, maps, config) {
+
+ var LAYER_NAME = "DataDownload_Button";
+
+ var IMAGE_SELECT = "images/data-download-plus-button-orange.svg";
+ var IMAGE_UNSELECT = "images/data-download-minus-button-red.svg";
+
+ var STYLE = {
+ "default": {
+ externalGraphic: IMAGE_SELECT,
+ fontFamily: "helvetica, sans-serif",
+ fontColor: "#ffffff",
+ fontWeight: "bold",
+ labelOutlineColor: "black",
+ labelOutlineWidth: 2,
+ labelOutlineOpacity: 0.7,
+ label: "${label}",
+ cursor: "pointer"
+ },
+ "select": {
+ externalGraphic: IMAGE_UNSELECT,
+ fontFamily: "helvetica, sans-serif",
+ fontColor: "#ffffff",
+ fontWeight: "bold",
+ labelOutlineColor: "black",
+ labelOutlineWidth: 2,
+ labelOutlineOpacity: 0.7,
+ label: "${label}",
+ cursor: "pointer"
+ }
+ };
+
+ var features = {};
+ var splitFeature = null;
+ var self = {};
+
+ self.EVENT_HOVER_OVER = "hoverover";
+ self.EVENT_HOVER_OUT = "hoverout";
+
+ self.events = wv.util.events();
+
+ var init = function() {
+ $.each(maps.projections, function(index, map) {
+ map.events.register("zoomend", self, resize);
+ });
+ model.events.on("granuleUnselect", onUnselect);
+ };
+
+ self.update = function(results) {
+ var layer = getLayer();
+ layer.removeAllFeatures();
+ features = {};
+ var featureList = [];
+ var selectedFeatures = [];
+ $.each(results.granules, function(index, granule) {
+ if ( !granule.centroid ) {
+ return;
+ }
+ var centroid = granule.centroid[model.crs];
+ if ( centroid ) {
+ var feature = new OpenLayers.Feature.Vector(centroid, {
+ granule: granule,
+ label: ""
+ });
+ featureList.push(feature);
+ features[granule.id] = feature;
+ if ( model.selectedGranules[granule.id] ) {
+ selectedFeatures.push(feature);
+ }
+ }
+ });
+ layer.addFeatures(featureList);
+ var selectionControl = layer.selectionControl;
+ $.each(selectedFeatures, function(index, selectedFeature) {
+ selectionControl.select(selectedFeature);
+ });
+ };
+
+ self.clear = function() {
+ var layer = wv.map.getLayerByName(maps.map, LAYER_NAME);
+ if ( layer ) {
+ features = {};
+ layer.removeAllFeatures();
+ }
+ };
+
+ self.dispose = function() {
+ $.each(maps.projections, function(index, map) {
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( layer ) {
+ map.removeControl(layer.hoverControl);
+ map.removeControl(layer.selectionControl);
+ map.removeLayer(layer);
+ }
+ });
+ };
+
+ var createLayer = function() {
+ size = getSize();
+
+ layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
+ styleMap: new OpenLayers.StyleMap(getStyle())
+ });
+
+ layer.div.setAttribute("data-layer-name", LAYER_NAME);
+ maps.map.addLayer(layer);
+
+ layer.events.on({
+ 'featureselected': function(event) {
+ model.selectGranule(event.feature.attributes.granule);
+ },
+ 'featureunselected': function(event) {
+ model.unselectGranule(event.feature.attributes.granule);
+ }
+ });
+
+ var hoverControl = new wv.map.HoverControl(layer);
+ hoverControl.events.on({
+ "hoverover": function(event) {
+ self.events.trigger(self.EVENT_HOVER_OVER, event);
+ onHoverOver(event);
+ },
+ "hoverout": function(event) {
+ self.events.trigger(self.EVENT_HOVER_OUT, event);
+ onHoverOut(event);
+ }
+ });
+ maps.map.addControl(hoverControl);
+ hoverControl.activate();
+ layer.hoverControl = hoverControl;
+
+ var selectionControl = new OpenLayers.Control.SelectFeature(layer, {
+ autoActivate: true,
+ toggle: true,
+ multiple: true,
+ clickout: false
+ });
+ maps.map.addControl(selectionControl);
+ layer.selectionControl = selectionControl;
+
+ return layer;
+ };
+
+ var getLayer = function(map) {
+ map = map || maps.map;
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( !layer ) {
+ layer = createLayer();
+ }
+ return layer;
+ };
+
+ var getSize = function() {
+ var zoom = maps.map.getZoom();
+ // Minimum size of the button is 15 pixels
+ var base = 15;
+ // Double the size for each zoom level
+ var add = Math.pow(2, zoom);
+ // But 47 pixels is the maximum size
+ var size = Math.min(base + add, base + 32);
+ return new OpenLayers.Size(size, size);
+ };
+
+ var getStyle = function(intent) {
+ var size = getSize();
+ var newStyle = $.extend(true, {}, STYLE);
+
+ newStyle["default"].graphicWidth = size.w;
+ newStyle["default"].graphicHeight = size.h;
+ newStyle["default"].labelYOffset = getLabelOffset();
+
+ newStyle.select.graphicWidth = size.w;
+ newStyle.select.graphicHeight = size.h;
+ newStyle.select.labelYOffset = getLabelOffset();
+
+ if ( intent ) {
+ return newStyle[intent];
+ } else {
+ return newStyle;
+ }
+ };
+
+ var resize = function() {
+ if ( !model.active ) {
+ return;
+ }
+ var styleMap = new OpenLayers.StyleMap(getStyle());
+ getLayer().styleMap = styleMap;
+ layer.redraw();
+ };
+
+ var onUnselect = function(granule) {
+ var feature = features[granule.id];
+ if ( feature ) {
+ getLayer().selectionControl.unselect(feature);
+ }
+ };
+
+ var onHoverOver = function(event) {
+ var feature = event.feature;
+ var granule = feature.attributes.granule;
+ feature.attributes.label = granule.label;
+ getLayer().drawFeature(feature);
+ if ( feature.geometry.CLASS_NAME ===
+ "OpenLayers.Geometry.MultiPoint" ) {
+ var newStyle = $.extend(true, {}, getStyle("default"));
+ delete newStyle.externalGraphic;
+ newStyle.strokeOpacity = 1;
+ newStyle.fillOpacity = 1;
+ newStyle.label = granule.label;
+ splitFeature = new OpenLayers.Feature.Vector(
+ feature.geometry.components[1].clone(),
+ feature.attributes,
+ newStyle
+ );
+ getLayer().addFeatures([splitFeature]);
+ }
+ };
+
+ var onHoverOut = function(event) {
+ var feature = event.feature;
+ feature.attributes.label = "";
+ getLayer().drawFeature(feature);
+ if ( splitFeature ) {
+ getLayer().removeFeatures([splitFeature]);
+ splitFeature = null;
+ }
+ };
+
+ var getLabelOffset = function() {
+ var buttonHeight = getSize().h;
+ return ( buttonHeight / 2.0 ) + 10;
+ };
+
+ init();
+ return self;
+
+};
+
+
+wv.data.layers.grid = wv.data.layers.grid || function(model, maps, config) {
+
+ var LAYER_NAME = "DataDownload_Grid";
+ var STYLE = {
+ strokeColor: "#bab498",
+ strokeOpacity: 0.6,
+ fillOpacity: 0,
+ strokeWidth: 1.5
+ };
+
+ var parser = new OpenLayers.Format.GeoJSON();
+
+ var self = {};
+
+ self.update = function(results) {
+ self.clear();
+ var grid = results.meta.grid;
+ if ( !grid ) {
+ return;
+ }
+ var layer = getLayer();
+
+ var features = [];
+ $.each(grid, function(index, cell) {
+ var geom = parser.read(cell.geometry, "Geometry");
+ var feature = new OpenLayers.Feature.Vector(geom);
+ features.push(feature);
+ });
+ layer.addFeatures(features);
+ };
+
+ self.clear = function() {
+ var layer = wv.map.getLayerByName(maps.map, LAYER_NAME);
+ if ( layer ) {
+ layer.removeAllFeatures();
+ }
+ };
+
+ self.dispose = function() {
+ $.each(maps.projections, function(index, map) {
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( layer ) {
+ map.removeLayer(layer);
+ }
+ });
+ };
+
+ var createLayer = function() {
+ var layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
+ styleMap: new OpenLayers.StyleMap(STYLE)
+ });
+ layer.div.setAttribute("data-layer-name", LAYER_NAME);
+ maps.map.addLayer(layer);
+ return layer;
+ };
+
+ var getLayer = function(map) {
+ map = map || maps.map;
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( !layer ) {
+ layer = createLayer();
+ }
+ return layer;
+ };
+
+ return self;
+
+};
+
+
+wv.data.layers.hover = wv.data.layers.hover || function(model, maps, config) {
+
+ var LAYER_NAME = "DataDownload_Hover";
+
+ var STYLE_HOVER_UNSELECTED = {
+ strokeColor: "#fbe26d",
+ fillColor: "#b59e32",
+ fillOpacity: 0.25
+ };
+
+ var STYLE_HOVER_SELECTED = {
+ strokeColor: "#ff0600",
+ fillColor: "#f20c0c",
+ fillOpacity: 0.25,
+ };
+
+ var self = {};
+
+ var init = function() {
+ model.events
+ .on("granuleSelect", refresh)
+ .on("granuleUnselect", refresh);
+ };
+
+ self.hoverOver = function(granule) {
+ if ( !granule.geometry ) {
+ return;
+ }
+ var geom = granule.geometry[model.crs];
+ var extent =
+ config.projections[model.projection].maxExtent.toGeometry();
+ if ( geom && extent.intersects(geom) ) {
+ var hoverFeature = new OpenLayers.Feature.Vector(
+ granule.geometry[model.crs], {
+ granule: granule
+ }
+ );
+ applyStyle(hoverFeature);
+ getLayer().addFeatures([hoverFeature]);
+ }
+ };
+
+ self.hoverOut = function() {
+ self.clear();
+ };
+
+ self.clear = function() {
+ var layer = wv.map.getLayerByName(maps.map, LAYER_NAME);
+ if ( layer ) {
+ layer.removeAllFeatures();
+ }
+ };
+
+ self.dispose = function() {
+ $.each(maps.projections, function(index, map) {
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( layer ) {
+ map.removeLayer(layer);
+ }
+ });
+ };
+
+ var refresh = function(granule) {
+ var layer = getLayer();
+ if ( layer.features.length === 0 ) {
+ return;
+ }
+ var feature = layer.features[0];
+ var hoverGranule = feature.attributes.granule;
+ if ( hoverGranule.id === granule.id ) {
+ applyStyle(feature);
+ layer.drawFeature(feature);
+ }
+ };
+
+ var applyStyle = function(feature) {
+ var granule = feature.attributes.granule;
+ var selected = model.selectedGranules[granule.id];
+ var style = ( selected ) ? STYLE_HOVER_SELECTED: STYLE_HOVER_UNSELECTED;
+ feature.style = style;
+ };
+
+ var createLayer = function() {
+ var layer = new OpenLayers.Layer.Vector(LAYER_NAME);
+ layer.div.setAttribute("data-layer-name", LAYER_NAME);
+ maps.map.addLayer(layer);
+ return layer;
+ };
+
+ var getLayer = function(map) {
+ map = map || maps.map;
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( !layer ) {
+ layer = createLayer();
+ }
+ return layer;
+ };
+
+ init();
+ return self;
+
+};
+
+
+wv.data.layers.selection = wv.data.layers.selection || function(model, maps, config) {
+
+ var LAYER_NAME = "DataDownload_Selection";
+
+ var OPACITY = 0.6;
+ var STYLE = {
+ strokeColor: "#808080",
+ fillColor: "#808080",
+ };
+
+ var self = {};
+ var features = {};
+
+ var init = function() {
+ model.events
+ .on("granuleSelect", onGranuleSelect)
+ .on("granuleUnselect", onGranuleUnselect);
+ };
+
+ self.clear = function() {
+ var layer = wv.map.getLayerByName(maps.map, LAYER_NAME);
+ if ( layer ) {
+ layer.removeAllFeatures();
+ }
+ };
+
+ self.dispose = function() {
+ $.each(maps.projections, function(index, map) {
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( layer ) {
+ map.removeLayer(layer);
+ }
+ });
+ features = {};
+ };
+
+ self.select = function(granule) {
+ onGranuleSelect(granule);
+ };
+
+ var onGranuleSelect = function(granule) {
+ if ( !granule.geometry ) {
+ return;
+ }
+ var geom = granule.geometry[model.crs];
+ var extent =
+ config.projections[model.projection].maxExtent.toGeometry();
+ if ( geom && extent.intersects(geom) ) {
+ // Exit if already selected
+ if ( features[granule.id] ) {
+ return;
+ }
+ var feature = new OpenLayers.Feature.Vector(geom.clone());
+ features[granule.id] = feature;
+ getLayer().addFeatures([feature]);
+ }
+ };
+
+
+ var onGranuleUnselect = function(granule) {
+ if ( !granule.geometry ) {
+ return;
+ }
+ var feature = features[granule.id];
+ if ( !feature ) {
+ return;
+ }
+ getLayer().removeFeatures([feature]);
+ getLayer().redraw();
+ delete features[granule.id];
+ };
+
+ self.refresh = function() {
+ self.clear();
+ features = {};
+ $.each(model.selectedGranules, function(index, granule) {
+ self.select(granule);
+ });
+ };
+
+ var createLayer = function() {
+ layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
+ styleMap: new OpenLayers.StyleMap(STYLE)
+ });
+ layer.div.setAttribute("data-layer-name", LAYER_NAME);
+ layer.setOpacity(OPACITY);
+ maps.map.addLayer(layer);
+
+ return layer;
+ };
+
+ var getLayer = function(map) {
+ map = map || maps.map;
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( !layer ) {
+ layer = createLayer();
+ }
+ return layer;
+ };
+
+ init();
+ return self;
+
+};
+
+
+wv.data.layers.swath = function(model, maps, config) {
+
+ var LAYER_NAME = "DataDownload_Swaths";
+ var STYLE = {
+ strokeColor: "#c3bd7b",
+ strokeOpacity: 0.75,
+ strokeWidth: 2
+ };
+ var MAX_DISTANCE_GEO = 270;
+
+ var self = {};
+
+ self.update = function(results) {
+ self.clear();
+ var swaths = results.meta.swaths;
+ if ( !swaths ) {
+ return;
+ }
+ var layer = getLayer();
+
+ var maxDistance = ( model.crs === wv.map.CRS_WGS_84 ) ?
+ MAX_DISTANCE_GEO : Number.POSITIVE_INFINITY;
+
+ var features = [];
+ $.each(swaths, function(index, swath) {
+ var lastGranule = null;
+ // Main granules or west side granuels
+ $.each(swath, function(index, granule) {
+ if ( !lastGranule ) {
+ lastGranule = granule;
+ return;
+ }
+ var polys1 = wv.map.toPolys(lastGranule.geometry[model.crs]);
+ var polys2 = wv.map.toPolys(granule.geometry[model.crs]);
+ $.each(polys1, function(index1, poly1) {
+ $.each(polys2, function(index2, poly2) {
+ var c1 = poly1.getCentroid();
+ var c2 = poly2.getCentroid();
+ var distanceX = wv.map.distanceX(c1, c2);
+ if ( distanceX < maxDistance ) {
+ features.push(new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.LineString([c1, c2])
+ ));
+ }
+ });
+ });
+ lastGranule = granule;
+ });
+
+ });
+ layer.addFeatures(features);
+ };
+
+ self.clear = function() {
+ var layer = wv.map.getLayerByName(maps.map, LAYER_NAME);
+ if ( layer ) {
+ layer.removeAllFeatures();
+ }
+ };
+
+ self.dispose = function() {
+ $.each(maps.projections, function(index, map) {
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( layer ) {
+ map.removeLayer(layer);
+ }
+ });
+ };
+
+ var createLayer = function() {
+ var layer = new OpenLayers.Layer.Vector(LAYER_NAME, {
+ styleMap: new OpenLayers.StyleMap(STYLE)
+ });
+ layer.div.setAttribute("data-layer-name", LAYER_NAME);
+ maps.map.addLayer(layer);
+ return layer;
+ };
+
+ var getLayer = function(map) {
+ map = map || maps.map;
+ var layer = wv.map.getLayerByName(map, LAYER_NAME);
+ if ( !layer ) {
+ layer = createLayer();
+ }
+ return layer;
+ };
+
+ return self;
+};
diff --git a/src/js/Worldview/DataDownload/MapController.js b/src/js/data/wv.data.map.js
similarity index 80%
rename from src/js/Worldview/DataDownload/MapController.js
rename to src/js/data/wv.data.map.js
index 5a51b00c5..532307a0b 100644
--- a/src/js/Worldview/DataDownload/MapController.js
+++ b/src/js/data/wv.data.map.js
@@ -4,24 +4,29 @@
* This code was originally developed at NASA/Goddard Space Flight Center for
* the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-Worldview.namespace("DataDownload");
-Worldview.DataDownload.MapController = function(model, maps, config) {
+/**
+ * @module wv.data
+ */
+var wv = wv || {};
+wv.data = wv.data || {};
+
+wv.data.map = wv.data.map || function(model, maps, config) {
- var ns = Worldview.DataDownload;
+ var ns = wv.data;
var self = {};
var results = [];
- var selectionLayers = ns.Layers.Selection(model, maps, config);
- var swathLayers = ns.Layers.Swath(model, maps, config);
- var gridLayers = ns.Layers.Grid(model, maps, config);
- var hoverLayers = ns.Layers.Hover(model, maps, config);
- var buttonLayers = ns.Layers.Button(model, maps, config);
+ var selectionLayers = ns.layers.selection(model, maps, config);
+ var swathLayers = ns.layers.swath(model, maps, config);
+ var gridLayers = ns.layers.grid(model, maps, config);
+ var hoverLayers = ns.layers.hover(model, maps, config);
+ var buttonLayers = ns.layers.button(model, maps, config);
var init = function() {
model.events
diff --git a/src/js/data/wv.data.model.js b/src/js/data/wv.data.model.js
index 4be464bf3..8cbc83d08 100644
--- a/src/js/data/wv.data.model.js
+++ b/src/js/data/wv.data.model.js
@@ -276,23 +276,18 @@ wv.data.model = wv.data.model || function(models, config) {
query();
};
- self.toPermalink = function() {
+ self.save = function(state) {
if ( self.active ) {
- return "dataDownload=" + encodeURIComponent(self.selectedProduct);
+ state.dataDownload = self.selectedProduct;
}
};
- self.fromPermalink = function(queryString) {
- var query = wv.util.fromQueryString(queryString);
- var productId = query.dataDownload;
+ self.load = function(state) {
+ var productId = state.dataDownload;
if ( productId ) {
- if ( !config.products[productId] ) {
- wv.util.warn("No such product: " + productId);
- } else {
- models.wv.events.on("startup", function() {
- self.activate(productId);
- });
- }
+ models.wv.events.on("startup", function() {
+ self.activate(productId);
+ });
}
};
diff --git a/src/js/data/wv.data.results.js b/src/js/data/wv.data.results.js
index a47c8c1d3..46339b7dd 100644
--- a/src/js/data/wv.data.results.js
+++ b/src/js/data/wv.data.results.js
@@ -24,18 +24,18 @@ wv.data.results.antiMeridianMulti = function(maxDistance) {
self.name = "AntiMeridianMulti";
self.process = function(meta, granule) {
- var geom = granule.geometry[Worldview.Map.CRS_WGS_84];
- if ( !Worldview.Map.isPolygonValid(geom, maxDistance) ) {
- var geomEast = Worldview.Map.adjustAntiMeridian(geom, 1);
- var geomWest = Worldview.Map.adjustAntiMeridian(geom, -1);
+ var geom = granule.geometry[wv.map.CRS_WGS_84];
+ if ( !wv.util.map.isPolygonValid(geom, maxDistance) ) {
+ var geomEast = wv.util.map.adjustAntiMeridian(geom, 1);
+ var geomWest = wv.util.map.adjustAntiMeridian(geom, -1);
var centroidEast = geomEast.getCentroid();
var centroidWest = geomWest.getCentroid();
var newGeom =
new OpenLayers.Geometry.MultiPolygon([geomEast, geomWest]);
var newCentroid =
new OpenLayers.Geometry.MultiPoint([centroidEast, centroidWest]);
- granule.geometry[Worldview.Map.CRS_WGS_84] = newGeom;
- granule.centroid[Worldview.Map.CRS_WGS_84] = newCentroid;
+ granule.geometry[wv.map.CRS_WGS_84] = newGeom;
+ granule.centroid[wv.map.CRS_WGS_84] = newCentroid;
}
return granule;
};
@@ -97,7 +97,6 @@ wv.data.results.chain = function() {
wv.data.results.collectPreferred = function(prefer) {
var self = {};
- var ns = Worldview.DataDownload;
self.name = "CollectPreferred";
@@ -109,7 +108,7 @@ wv.data.results.collectPreferred = function(prefer) {
(prefer === "nrt" && granule.nrt) ||
(prefer === "science" && !granule.nrt);
if ( preferred ) {
- var timeStart = ns.ECHO.roundTime(granule.time_start);
+ var timeStart = wv.data.echo.roundTime(granule.time_start);
meta.preferred[timeStart] = granule;
}
return granule;
@@ -122,7 +121,6 @@ wv.data.results.collectPreferred = function(prefer) {
wv.data.results.collectVersions = function() {
var self = {};
- var ns = Worldview.DataDownload;
self.name = "CollectVersions";
@@ -131,7 +129,7 @@ wv.data.results.collectVersions = function() {
meta.versions = {};
}
if ( granule.version ) {
- var timeStart = ns.ECHO.roundTime(granule.time_start);
+ var timeStart = wv.data.echo.roundTime(granule.time_start);
var previousVersion = meta.versions[timeStart] || 0;
meta.versions[timeStart] = Math.max(previousVersion,
granule.version);
@@ -189,7 +187,7 @@ wv.data.results.connectSwaths = function(projection) {
var combineSwath = function(swath) {
var combined = false;
- var maxDistance = ( projection === Worldview.Map.CRS_WGS_84 ) ?
+ var maxDistance = ( projection === wv.map.CRS_WGS_84 ) ?
MAX_DISTANCE_GEO : Number.POSITIVE_INFINITY;
var thisTimeStart = roundTime(swath[0].time_start);
var thisTimeEnd = roundTime(swath[swath.length - 1].time_end);
@@ -233,8 +231,8 @@ wv.data.results.connectSwaths = function(projection) {
// Connection is allowed as long as there is at least one path between
// centroids that is less than the max distance
var connectionAllowed = function(g1, g2, maxDistance) {
- var polys1 = Worldview.Map.toPolys(g1.geometry[projection]);
- var polys2 = Worldview.Map.toPolys(g2.geometry[projection]);
+ var polys1 = wv.map.toPolys(g1.geometry[projection]);
+ var polys2 = wv.map.toPolys(g2.geometry[projection]);
var allowed = false;
$.each(polys1, function(index, poly1) {
@@ -252,7 +250,7 @@ wv.data.results.connectSwaths = function(projection) {
var roundTime = function(timeString) {
- return Worldview.DataDownload.ECHO.roundTime(timeString);
+ return wv.data.echo.roundTime(timeString);
};
return self;
@@ -296,7 +294,7 @@ wv.data.results.densify = function() {
self.name = "Densify";
self.process = function(meta, granule) {
- var geom = granule.geometry[Worldview.Map.CRS_WGS_84];
+ var geom = granule.geometry[wv.map.CRS_WGS_84];
var newGeom = null;
if ( geom.CLASS_NAME === "OpenLayers.Geometry.Polygon" ) {
newGeom = densifyPolygon(geom);
@@ -309,7 +307,7 @@ wv.data.results.densify = function() {
} else {
throw Error("Cannot handle geometry: " + geom.CLASS_NAME);
}
- granule.geometry[Worldview.Map.CRS_WGS_84] = newGeom;
+ granule.geometry[wv.map.CRS_WGS_84] = newGeom;
return granule;
};
@@ -321,13 +319,13 @@ wv.data.results.densify = function() {
for ( var i = 0; i < ring.length - 2; i++ ) {
var start = ring[i];
end = ring[i + 1];
- var distance = Worldview.Map.distance2D(start, end);
+ var distance = wv.map.distance2D(start, end);
var numPoints = Math.floor(distance / MAX_DISTANCE);
points.push(start);
for ( var j = 1; j < numPoints - 1; j++ ) {
var d = j / numPoints;
// This is what REVERB does, so we will do the same
- var p = Worldview.Map.interpolate2D(start, end, d);
+ var p = wv.map.interpolate2D(start, end, d);
points.push(p);
}
}
@@ -378,12 +376,12 @@ wv.data.results.geometryFromECHO = function(densify) {
granule.centroid = {};
}
- if ( !granule.geometry[Worldview.Map.CRS_WGS_84] ) {
- var echoGeom = Worldview.DataDownload.ECHO.Geometry(granule, densify);
+ if ( !granule.geometry[wv.map.CRS_WGS_84] ) {
+ var echoGeom = wv.data.echo.geometry(granule, densify);
var geom = echoGeom.toOpenLayers();
var centroid = geom.getCentroid();
- granule.geometry[Worldview.Map.CRS_WGS_84] = geom;
- granule.centroid[Worldview.Map.CRS_WGS_84] = centroid;
+ granule.geometry[wv.map.CRS_WGS_84] = geom;
+ granule.centroid[wv.map.CRS_WGS_84] = centroid;
}
return granule;
};
@@ -479,12 +477,11 @@ wv.data.results.modisGridLabel = function() {
wv.data.results.preferredFilter = function(prefer) {
var self = {};
- var ns = Worldview.DataDownload;
self.name = "PreferredFilter";
self.process = function(meta, granule) {
- var timeStart = ns.ECHO.roundTime(granule.time_start);
+ var timeStart = wv.data.echo.roundTime(granule.time_start);
if ( meta.preferred[timeStart] ) {
if ( prefer === "nrt" && !granule.nrt ) {
return;
@@ -659,18 +656,18 @@ wv.data.results.timeFilter = function(spec) {
};
self.process = function(meta, granule) {
- var geom = granule.geometry[Worldview.Map.CRS_WGS_84];
+ var geom = granule.geometry[wv.map.CRS_WGS_84];
var time = wv.util.parseTimestampUTC(granule.time_start);
time.setUTCMinutes(time.getUTCMinutes() + timeOffset);
- if ( !Worldview.Map.isPolygonValid(geom, maxDistance) ) {
+ if ( !wv.map.isPolygonValid(geom, maxDistance) ) {
var adjustSign = ( time < eastZone ) ? 1 : -1;
geom =
- Worldview.Map.adjustAntiMeridian(geom, adjustSign);
- granule.geometry[Worldview.Map.CRS_WGS_84] = geom;
- granule.centroid[Worldview.Map.CRS_WGS_84] = geom.getCentroid();
+ wv.map.adjustAntiMeridian(geom, adjustSign);
+ granule.geometry[wv.map.CRS_WGS_84] = geom;
+ granule.centroid[wv.map.CRS_WGS_84] = geom.getCentroid();
}
- var x = granule.centroid[Worldview.Map.CRS_WGS_84].x;
+ var x = granule.centroid[wv.map.CRS_WGS_84].x;
if ( time < eastZone && x < 0 ) {
return;
}
@@ -741,9 +738,9 @@ wv.data.results.transform = function(projection) {
if ( granule.geometry[projection] ) {
return granule;
}
- var geom = granule.geometry[Worldview.Map.CRS_WGS_84];
+ var geom = granule.geometry[wv.map.CRS_WGS_84];
var projGeom = geom.clone()
- .transform(Worldview.Map.CRS_WGS_84, projection);
+ .transform(wv.map.CRS_WGS_84, projection);
granule.geometry[projection] = projGeom;
granule.centroid[projection] = projGeom.getCentroid();
return granule;
@@ -756,13 +753,12 @@ wv.data.results.transform = function(projection) {
wv.data.results.versionFilter = function() {
var self = {};
- var ns = Worldview.DataDownload;
self.name = "VersionFilter";
self.process = function(meta, granule) {
if ( granule.version ) {
- var timeStart = ns.ECHO.roundTime(granule.time_start);
+ var timeStart = wv.data.echo.roundTime(granule.time_start);
if ( meta.versions[timeStart] ) {
if ( meta.versions[timeStart] !== granule.version ) {
return;
diff --git a/src/js/data/wv.data.ui.js b/src/js/data/wv.data.ui.js
index 76bb4f1df..aeb2c455e 100644
--- a/src/js/data/wv.data.ui.js
+++ b/src/js/data/wv.data.ui.js
@@ -12,7 +12,7 @@
var wv = wv || {};
wv.data = wv.data || {};
-wv.data.ui = wv.data.ui || function(models, config, maps) {
+wv.data.ui = wv.data.ui || function(models, config) {
var HTML_WIDGET_INACTIVE = "<img src='images/camera.png'></img>";
var HTML_WIDGET_ACTIVE = "<img src='images/cameraon.png'></img>";
@@ -24,6 +24,7 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
var selectionListPanel = null;
var downloadListPanel = null;
var lastResults = null;
+ var maps = models.map.maps;
var self = {};
self.selector = "#DataDownload";
@@ -42,51 +43,9 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
.on("queryTimeout", onQueryTimeout)
.on("granuleSelect", updateSelection)
.on("granuleUnselect", updateSelection);
-
- REGISTRY.register(self.id, self);
- REGISTRY.markComponentReady(self.id);
- self.updateComponent();
-
$(window).resize(resize);
};
- self.updateComponent = function(queryString) {
- /*
- try {
- model.update(REGISTRY.getState());
- } catch ( error ) {
- Worldview.error("Internal error", error);
- }
- */
- };
-
- self.getValue = function() {
- if ( model.active ) {
- return "dataDownload=" + model.selectedProduct;
- } else {
- return "";
- }
- };
-
- self.setValue = function(value) {
- throw new Error("Unsupported: setValue");
- };
-
- self.loadFromQuery = function(queryString) {
- /*
- var query = Worldview.queryStringToObject(queryString);
- if ( query.dataDownload ) {
- try {
- var state = REGISTRY.getState(queryString);
- model.activate(query.dataDownload);
- } catch ( error ) {
- console.warn("Invalid data download parameter: " + error);
- model.activate();
- }
- }
- */
- };
-
self.render = function() {
var $container = $(self.selector).empty()
.addClass(self.id + "list")
@@ -180,7 +139,7 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
var refreshLayers = function($container, key, value, layer) {
var $item = $("<li></li>")
- .attr("id", self.id + key + Worldview.id(layer.value))
+ .attr("id", self.id + key + encodeURIComponent(layer.value))
.addClass("item")
.addClass("item-static");
$item.append("<h4>" + layer.label + "</h4>");
@@ -197,7 +156,7 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
var $pane = $(self.selector + "content");
var api = $pane.data("jsp");
- if ( $(window).width() > Worldview.TRANSITION_WIDTH ) {
+ if ( !wv.util.browser.small ) {
if ( api ) {
api.reinitialise();
} else {
@@ -242,8 +201,7 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
var onActivate = function() {
if ( !mapController ) {
- mapController =
- Worldview.DataDownload.MapController(model, maps, config);
+ mapController = wv.data.map(model, maps, config);
}
onLayerUpdate();
updateSelection();
@@ -291,7 +249,7 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
} else {
if ( results.meta.showList ) {
selectionListPanel =
- Worldview.DataDownload.SelectionListPanel(model, results);
+ wv.data.ui.selectionListPanel(model, results);
selectionListPanel.show();
} else {
if ( selectionListPanel ) {
@@ -328,7 +286,7 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
var updateSelection = function() {
$button = $("#DataDownload_Button");
- var selected = Worldview.size(model.selectedGranules);
+ var selected = _.size(model.selectedGranules);
if ( selected > 0 ) {
$button.removeAttr("disabled");
var totalSize = model.getSelectionSize();
@@ -358,7 +316,7 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
}
if ( !downloadListPanel ) {
downloadListPanel =
- Worldview.DataDownload.DownloadListPanel(config, model);
+ wv.data.ui.downloadListPanel(config, model);
downloadListPanel.events.on("close", function() {
if ( selectionListPanel ) {
selectionListPanel.setVisible(true);
@@ -397,3 +355,561 @@ wv.data.ui = wv.data.ui || function(models, config, maps) {
};
+
+wv.data.ui.bulkDownloadPage = wv.data.ui.bulkDownloadPage ||
+ (function() {
+
+ var ns = {};
+
+ var pages = {
+ wget: "pages/wget.html",
+ curl: "pages/curl.html"
+ };
+
+ ns.show = function(selection, type) {
+ var nonce = Date.now();
+ var page = window.open(pages[type] + "?v=" + nonce,
+ 'Worldview_' + nonce);
+
+ var loaded = false;
+ page.onload = function() {
+ if ( !loaded ) {
+ fillPage(page, selection, type);
+ loaded = true;
+ }
+ };
+ var checkCount = 0;
+ var timer = setInterval(function() {
+ checkCount++;
+ if ( loaded ) {
+ clearInterval(timer);
+ return;
+ }
+ if ( checkCount > 20 ) {
+ clearInterval(timer);
+ return;
+ }
+ if ( fillPage(page, selection, type) ) {
+ loaded = true;
+ clearInterval(timer);
+ }
+ }, 100);
+ };
+
+ var fillPage = function(page, selection, type) {
+ var downloadLinks = [];
+ var hosts = {};
+ var indirectLinks = [];
+ $.each(selection, function(index, product) {
+ $.each(product.list, function(index2, granule) {
+ var netrc = "";
+ if ( granule.urs ) {
+ netrc = "--netrc ";
+ }
+ $.each(granule.links, function(index2, link) {
+ if ( !link.data ) {
+ return;
+ }
+ if ( product.noBulkDownload ) {
+ indirectLinks.push("<li><a href='" + link.href + "'>" +
+ link.href + "</a></li>");
+ return;
+ }
+ if ( type === "curl" ) {
+ downloadLinks.push("curl --remote-name " + netrc +
+ link.href);
+ } else {
+ downloadLinks.push(link.href);
+ }
+ if ( granule.urs ) {
+ // Get the hostname from the URL, the text between
+ // the double slash and the first slash after that
+ var host = /\/\/([^\/]*)\//.exec(link.href);
+ if ( host ) {
+ hosts[host[1]] = true;
+ }
+ }
+ });
+ });
+ });
+ var links = page.document.getElementById("links");
+ if ( !links ) {
+ // Page is not ready
+ return false;
+ }
+ links.innerHTML = "<pre>" + downloadLinks.join("\n") + "</pre>";
+
+ var netrcEntries = [];
+ var hostnames = [];
+ $.each(hosts, function(host, value) {
+ netrcEntries.push("machine " + host + " login URS_USER " +
+ "password URS_PASSWORD");
+ hostnames.push(host);
+ });
+ if ( netrcEntries.length > 0 ) {
+ page.document.getElementById("netrc").innerHTML =
+ "<pre>" + netrcEntries.join("\n") + "</pre>";
+ page.document.getElementById("bulk-password-notice")
+ .style.display = "block";
+ page.document.getElementById("netrc-instructions")
+ .style.display = "block";
+ var instructions =
+ page.document.getElementById("fdm-password-instructions");
+ if ( instructions ) {
+ instructions.style.display = "block";
+ }
+ var machineNames =
+ page.document.getElementById("fdm-machine-names");
+ if ( machineNames ) {
+ machineNames.innerHTML = "<pre>" + hostnames.join("\n") +
+ "</pre>";
+ }
+ }
+ if ( indirectLinks.length > 0 ) {
+ page.document.getElementById("indirect-instructions")
+ .style.display = "block";
+ page.document.getElementById("indirect").innerHTML =
+ "<ul>" + indirectLinks.join("\n") + "</ul>";
+ }
+ return true;
+ };
+
+ return ns;
+
+})();
+
+
+wv.data.ui.downloadListPanel = function(config, model) {
+
+ var echo = wv.data.echo;
+
+ var NOTICE =
+ "<div id='DataDownload_Notice'>" +
+ "<img class='icon' src='images/info-icon-blue.svg'>" +
+ "<p class='text'>" +
+ "Some items you have selected require an account with the " +
+ "EOSDIS User Registration System (URS) to download. " +
+ "It is simple and free to sign up! " +
+ "<a href='https://urs.eosdis.nasa.gov/users/new' target='urs'>" +
+ "Click to register for an account.</a>" +
+ "</p>" +
+ "</div>";
+
+ var panel = null;
+ var selection;
+ var self = {};
+ var urs = false;
+
+ self.events = wv.util.events();
+
+ self.show = function() {
+ $("#DataDownload_DownloadListPanel .remove").off("click", removeGranule);
+ $("#DataDownload_DownloadListPanel a.wget").off("click", showWgetPage);
+ $("#DataDownload_DownloadListPanel a.curl").off("click", showCurlPage);
+ $("#DataDownload_DownloadListPanel tr").off("mouseenter", onHoverOver);
+ $("#DataDownload_DownloadListPanel tr").off("mouseleave", onHoverOut);
+
+ selection = reformatSelection();
+ var newPanel = false;
+ if ( !panel ) {
+ newPanel = true;
+ panel = new YAHOO.widget.Panel("DataDownload_DownloadListPanel", {
+ width: "650px",
+ height: "500px",
+ zIndex: 1020,
+ visible: false,
+ constraintoviewport: true
+ });
+ panel.setHeader("Download Links");
+ }
+ panel.setBody(bodyText(selection));
+ panel.setFooter(bulkDownloadText());
+
+ if ( newPanel ) {
+ panel.render(document.body);
+ panel.show();
+ panel.center();
+ panel.hideEvent.subscribe(function() {
+ setTimeout(dispose, 25);
+ });
+ }
+
+ $("#DataDownload_DownloadListPanel a.wget").click(showWgetPage);
+ $("#DataDownload_DownloadListPanel a.curl").click(showCurlPage);
+ $("#DataDownload_DownloadListPanel .remove").click(removeGranule);
+ $("#DataDownload_DownloadListPanel tr").on("mouseenter", onHoverOver);
+ $("#DataDownload_DownloadListPanel tr").on("mouseleave", onHoverOut);
+
+ var bulkVisible = isBulkDownloadable() &&
+ _.size(model.selectedGranules) !== 0;
+ if ( bulkVisible ) {
+ $("#DataDownload_DownloadListPanel .ft .bulk")
+ .css("visibility", "visible");
+ } else {
+ $("#DataDownload_DownloadListPanel .ft .bulk")
+ .css("visibility", "hidden");
+ }
+ };
+
+ self.hide = function() {
+ if ( panel ) {
+ panel.hide();
+ }
+ };
+
+ self.visible = function() {
+ return panel !== null;
+ };
+
+ var dispose = function() {
+ $("#DataDownload_DownloadListPanel .remove").off("click", removeGranule);
+ $("#DataDownload_DownloadListPanel a.wget").off("click", showWgetPage);
+ $("#DataDownload_DownloadListPanel a.curl").off("click", showCurlPage);
+ $("#DataDownload_DownloadListPanel tr").off("mouseenter", onHoverOver);
+ $("#DataDownload_DownloadListPanel tr").off("mouseleave", onHoverOut);
+
+ self.events.trigger("close");
+ panel.destroy();
+ panel = null;
+ };
+
+ var reformatSelection = function() {
+ var selection = {};
+
+ urs = false;
+ $.each(model.selectedGranules, function(key, granule) {
+ if ( granule.urs ) {
+ urs = true;
+ }
+ if ( !selection[granule.product] ) {
+ productConfig = config.products[granule.product];
+ selection[granule.product] = {
+ name: productConfig.name,
+ granules: [granule],
+ counts: {},
+ noBulkDownload: productConfig.noBulkDownload || false,
+ };
+ } else {
+ selection[granule.product].granules.push(granule);
+ }
+
+ var product = selection[granule.product];
+ var id = granule.product;
+
+ // For each link that looks like metadata, see if that link is
+ // repeated in all granules for that product. If so, we want to
+ // bump that up to product level instead of at the granule level.
+ $.each(granule.links, function(index, link) {
+ if ( link.rel !== echo.REL_DATA && link.rel !== echo.REL_BROWSE ) {
+ if ( !product.counts[link.href] ) {
+ product.counts[link.href] = 1;
+ } else {
+ product.counts[link.href]++;
+ }
+ }
+ });
+ });
+
+ $.each(selection, function(key, product) {
+ product.links = [];
+ product.list = [];
+
+ // Check the first granule, and populate product level links
+ // where the count equals the number of granules
+ var granule = product.granules[0];
+ $.each(granule.links, function(index, link) {
+ var count = product.counts[link.href];
+ if ( count % product.granules.length === 0 ) {
+ product.links.push(reformatLink(link));
+ }
+ });
+
+ $.each(product.granules, function(index, granule) {
+ var item = {
+ id: granule.id,
+ label: granule.downloadLabel || granule.label,
+ links: [],
+ urs: granule.urs
+ };
+ $.each(granule.links, function(index, link) {
+ // Skip this link if now at the product level
+ var count = product.counts[link.href];
+ if ( count % product.granules.length === 0 ) {
+ return;
+ }
+ // Skip browse images per Kevin's request
+ if ( link.rel === echo.REL_BROWSE ) {
+ return;
+ }
+ item.links.push(reformatLink(link));
+ });
+ product.list.push(item);
+ });
+ product.list.sort(function(a, b) {
+ if ( a.label > b.label ) {
+ return 1;
+ }
+ if ( a.label < b.label ) {
+ return -1;
+ }
+ return 0;
+ });
+ });
+
+ return selection;
+ };
+
+ var isBulkDownloadable = function() {
+ var result = false;
+ $.each(selection, function(index, product) {
+ if ( !product.noBulkDownload ) {
+ result = true;
+ }
+ });
+ return result;
+ };
+
+ var reformatLink = function(link) {
+ // For title, take it if found, otherwise, use the basename of the
+ // URI
+ return {
+ href: link.href,
+ title: ( link.title ) ? link.title : link.href.split("/").slice(-1),
+ data: ( link.rel === echo.REL_DATA )
+ };
+ };
+
+ var linksText = function(links) {
+ var elements = [];
+ elements.push("<ul>");
+ $.each(links, function(index, link) {
+ elements.push(
+ "<li><a href='" + link.href + "' target='_blank'>" +
+ link.title + "</a></li>");
+ });
+ elements.push("</ul>");
+ return elements.join("\n");
+ };
+
+ var granuleText = function(product, granule) {
+ var elements;
+ if ( product.name !== granule.label ) {
+ elements = [
+ "<tr data-granule='" + granule.id + "'>",
+ "<td><input type='button' class='remove' " +
+ "data-granule='" + granule.id + "' " +
+ "value='X'></input></td>",
+ "<td><nobr><ul><li>" + granule.label + "</li></ul></nobr></td>",
+ "<td>" + linksText(granule.links) + "</td>",
+ "</tr>"
+ ];
+ } else {
+ elements = [
+ "<tr data-granule='" + granule.id + "'>",
+ "<td><input type='button' class='remove' " +
+ "data-granule='" + granule.id + "' " +
+ "value='X'></input></td>",
+ "<td colspan='2'>" + linksText(granule.links) + "</td>",
+ "</tr>"
+ ];
+ }
+ return elements.join("\n");
+ };
+
+ var productText = function(product) {
+ var elements = [
+ "<h3>" + product.name + "</h3>"
+ ];
+
+ elements.push("<h5>Selected Data</h5>");
+ elements.push("<table>");
+
+ $.each(product.list, function(index, item) {
+ elements.push(granuleText(product, item));
+ });
+ elements.push("</table>");
+
+ if ( product.links && product.links.length > 0 ) {
+ elements.push("<h5>Data Collection Information</h5>");
+ elements.push("<div class='product'>");
+ elements.push(linksText(product.links));
+ elements.push("</div>");
+ }
+
+ return elements.join("\n");
+ };
+
+ var bodyText = function() {
+ if ( _.size(model.selectedGranules) === 0 ) {
+ return "<br/><h3>Selection Empty</h3>";
+ }
+ var elements = [];
+ if ( urs ) {
+ elements.push(NOTICE);
+ }
+ $.each(selection, function(key, product) {
+ elements.push("\n<br/>\n" + productText(product));
+ });
+
+ var text = elements.join("\n<br/>\n") + "<br/>";
+ return text;
+ };
+
+ var bulkDownloadText = function() {
+ var bulk =
+ "<div class='bulk'>" +
+ "<h4>Bulk Download</h4>" +
+ "<ul class='BulkDownload'>" +
+ "<li><a class='wget' href='#'>List of Links:</a> " +
+ "for wget or download managers that accept a list of " +
+ "URLs</li>" +
+ "<li><a class='curl' href='#'>List of cURL Commands:</a> " +
+ "can be copied and pasted to " +
+ "a terminal window to download using cURL.</li>" +
+ "</ul>" +
+ "</div>";
+ return bulk;
+ };
+
+ var showWgetPage = function() {
+ wv.data.ui.bulkDownloadPage.show(selection, "wget");
+ };
+
+ var showCurlPage = function() {
+ wv.data.ui.bulkDownloadPage.show(selection, "curl");
+ };
+
+ var removeGranule = function() {
+ var id = $(this).attr("data-granule");
+ model.unselectGranule(model.selectedGranules[id]);
+ onHoverOut.apply(this);
+ };
+
+ var onHoverOver = function() {
+ model.events.trigger("hoverOver",
+ model.selectedGranules[$(this).attr("data-granule")]);
+ };
+
+ var onHoverOut = function() {
+ model.events.trigger("hoverOut",
+ model.selectedGranules[$(this).attr("data-granule")]);
+ };
+
+ return self;
+
+};
+
+
+wv.data.ui.selectionListPanel = function(model, results) {
+
+ var panel = null;
+ var self = {};
+ var granules = {};
+
+ var init = function() {
+ model.events.on("granuleUnselect", onGranuleUnselect);
+ };
+
+ self.show = function() {
+ panel = new YAHOO.widget.Panel("DataDownload_SelectionListPanel", {
+ width: "400px",
+ height: "400px",
+ zIndex: 1020,
+ visible: false,
+ close: false,
+ constraintoviewport: true
+ });
+ panel.setHeader("Select data");
+
+ panel.setBody(bodyText());
+ panel.render(document.body);
+ panel.show();
+ panel.center();
+ panel.hideEvent.subscribe(function() {
+ setTimeout(dispose, 25);
+ });
+
+ $.each(results.granules, function(index, granule) {
+ granules[granule.id] = granule;
+ });
+
+ $("#DataDownload_GranuleList input").on("click", toggleSelection);
+ };
+
+ self.hide = function() {
+ if ( panel ) {
+ panel.hide();
+ }
+ };
+
+ self.visible = function() {
+ return panel !== null;
+ };
+
+ self.setVisible = function(value) {
+ if ( !value ) {
+ $("#DataDownload_SelectionListPanel").hide();
+ } else {
+ $("#DataDownload_SelectionListPanel").show();
+ }
+ };
+
+ var dispose = function() {
+ panel.destroy();
+ panel = null;
+ $("#DataDownload_GranuleList input").off("click", toggleSelection);
+ };
+
+ var resultsText = function() {
+ var elements = [];
+ $.each(results.granules, function(index, granule) {
+ var selected = model.isSelected(granule) ? "checked='true'" : "";
+ elements.push(
+ "<tr>" +
+ "<td>" +
+ "<input type='checkbox' value='" + granule.id + "' " +
+ selected + ">" +
+ "</td>" +
+ "<td class='label'>" + granule.label + "</td>" +
+ "</tr>"
+ );
+ });
+ var text = elements.join("\n");
+ return text;
+ };
+
+ var bodyText = function() {
+ var elements = [
+ "<div id='DataDownload_GranuleList'>",
+ "<table>",
+ resultsText(),
+ "</table>",
+ "</div>"
+ ];
+ var text = elements.join("\n") + "<br/>";
+ return text;
+ };
+
+ var toggleSelection = function(event, ui) {
+ var granule = granules[$(this).attr("value")];
+ var selected = $(this).prop("checked");
+ if ( selected ) {
+ model.selectGranule(granule);
+ } else {
+ model.unselectGranule(granule);
+ }
+ };
+
+ var onGranuleUnselect = function(granule) {
+ $("#DataDownload_GranuleList input[value='" + granule.id + "']")
+ .removeAttr("checked");
+ };
+
+
+ init();
+ return self;
+
+};
+
+
+
diff --git a/src/js/date/wv.date.js b/src/js/date/wv.date.js
new file mode 100644
index 000000000..1cf309e1d
--- /dev/null
+++ b/src/js/date/wv.date.js
@@ -0,0 +1,34 @@
+
+var wv = wv || {};
+
+wv.date = (function(self) {
+
+ self.parse = function(state, errors) {
+ if ( state.time ) {
+ try {
+ state.time = wv.util.parseDateUTC(state.time);
+ } catch ( error ) {
+ delete state.time;
+ errors.push({
+ message: "Invalid date: " + state.time,
+ cause: error
+ });
+ }
+ }
+
+ if ( state.now ) {
+ try {
+ state.now = wv.util.parseDateUTC(state.now);
+ } catch ( error ) {
+ delete state.now;
+ errors.push({
+ message: "Invalid now: " + state.now,
+ cause: error
+ });
+ }
+ }
+ };
+
+ return self;
+
+})(wv.date || {});
diff --git a/src/js/date/wv.date.model.js b/src/js/date/wv.date.model.js
index 85a34ed2c..9a324e4de 100644
--- a/src/js/date/wv.date.model.js
+++ b/src/js/date/wv.date.model.js
@@ -83,50 +83,6 @@ wv.date.model = wv.date.model || function(spec) {
return updated;
};
- /**
- * Representation of this model as a permalink.
- *
- * @method toPermalink
- * @return {String} current day in the form of ``time=YYYY-MM-DD``
- */
- self.toPermalink = function() {
- return "time=" + self.selected.toISOString().split("T")[0];
- };
-
- /**
- * Selects a day based on a value from a permalink.
- *
- * @method fromPermalink
- * @param {Object} queryString the query string used to select the day
- * with a parameter in the form of ``time=YYYY-MM-DD``. If the parameter
- * does not exist, this method does nothing. If the value of the day
- * is invalid, the value is not changed and a warning is emitted to
- * the console.
- */
- self.fromPermalink = function(queryString) {
- var query = wv.util.fromQueryString(queryString);
- if ( query.time ) {
- try {
- var value = wv.util.parseDateUTC(query.time);
- self.select(value);
- } catch ( error ) {
- wv.util.warn("Invalid date: " + query.time + ": " + error);
- }
- }
- if ( query.now ) {
- try {
- var now = wv.util.parseDateUTC(query.now);
- wv.util.now = function() {
- return now;
- };
- wv.util.warn("Overriding now: " + now.toISOString());
- self.range({ start: self.start, end: self.end });
- } catch ( error ) {
- console.error("Invalid now: " + query.now, error);
- }
- }
- };
-
self.range = function(range) {
if ( range ) {
self.start = range.start;
@@ -144,6 +100,23 @@ wv.date.model = wv.date.model || function(spec) {
self.events.trigger("range");
};
+ self.save = function(state) {
+ state.time = self.selected.toISOString().split("T")[0];
+ };
+
+ self.load = function(state) {
+ if ( state.time ) {
+ self.select(state.time);
+ }
+ if ( state.now ) {
+ wv.util.now = function() {
+ return state.now;
+ };
+ wv.util.warn("Overriding now: " + now.toISOString());
+ self.range({ start: self.start, end: self.end });
+ }
+ };
+
init();
return self;
diff --git a/src/js/image/wv.image.panel.js b/src/js/image/wv.image.panel.js
new file mode 100644
index 000000000..c68dcaca3
--- /dev/null
+++ b/src/js/image/wv.image.panel.js
@@ -0,0 +1,153 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+wv.image = wv.image || {};
+
+wv.image.panel = wv.image.panel || function(models, ui, config) {
+
+ var self = {};
+
+ var BASE_URL = "http://map2.vis.earthdata.nasa.gov/imagegen/index";
+ var container;
+ var alignTo = config.alignTo;
+ var containerId = "imagedownload";
+ var id = containerId;
+
+ if ( config.parameters.imagegen ) {
+ wv.util.warn("Redirecting image download to: " + BASE_URL +
+ "-" + config.parameters.imagegen + ".php");
+ }
+
+ /**
+ * Initialize a map object in Lat/Long projection, and add a "fake" layer to compute the map math.
+ * Display the HTML UI with UI options. *
+ * @this {Download}
+ */
+ var init = function(){
+
+ alignTo = { id: "camera" };
+ container=document.getElementById(containerId);
+
+ if (container===null){
+ throw new Error("Error: element '"+containerId+"' not found!");
+ }
+
+ container.setAttribute("class","imagedownload");
+
+ setPosition();
+ $(window).resize(setPosition);
+
+ var htmlElements = "<div>Resolution (per pixel): <select id='selImgResolution'><option value='1'>250m</option><option value='2'>500m</option><option value='4'>1km</option><option value='20'>5km</option><option value='40'>10km</option></select>";
+ htmlElements +="<br />Format: <select id='selImgFormat'><option value='image/jpeg'>JPEG</option><option value='image/png'>PNG</option><option value='image/geotiff'>GeoTIFF</option></select>";
+ htmlElements +="<br />Raw Image Size: ~ <span id='imgFileSize'> </span> MB <br />(<span id='imgWidth''></span> x <span id='imgHeight'></span> pixels)";
+ htmlElements += "<br /><span style='font-size:10px; color:#aaa; font-style:italic;'>(Max Size: 250 MB)</span> ";//(<span id='imgWidth''></span> x <span id='imgHeight'></span> pixels)
+ htmlElements += "<br /><input type='button' id='btnImgDownload' value='Download'/>";
+ htmlElements +="</div>";
+
+ $("#"+id).html(htmlElements);
+
+ ui.rubberband.events.on("update", update);
+
+ };
+
+ var setPosition = function(){
+ var offset = $("#"+alignTo.id).offset();
+ var left = offset.left + parseInt($("#"+alignTo.id).css("width")) - parseInt($("#"+id).css("width"));
+ $("#"+id).css("left",left+"px");
+ };
+
+
+ var update = function(coords){
+ try {
+ var map = models.map.selected;
+ var bbox = map.getExtent();
+ var time = models.date.selected;
+ var pixels = coords;
+ var s = models.proj.selected.id;
+ var products = models.layers.get({
+ visibleOnly: true,
+ reverse: true
+ });
+ var epsg = models.proj.selected.epsg;
+
+ //console.log("EPSG: " + epsg);
+
+ var px = pixels;
+ var x1 = px.x; var y1= px.y; var x2 = px.x2; var y2=px.y2;
+ var lonlat1 = map.getLonLatFromViewPortPx(new OpenLayers.Pixel(Math.floor(x1), Math.floor(y2)));
+ var lonlat2 = map.getLonLatFromViewPortPx(new OpenLayers.Pixel(Math.floor(x2), Math.floor(y1)));
+
+ var dlURL = null;
+ var imagegen = config.parameters.imagegen;
+ if ( imagegen ) {
+ dlURL = BASE_URL + "-" + imagegen + ".php?";
+ } else {
+ dlURL= BASE_URL + ".php?";
+ }
+
+ var conversionFactor = 256;
+ if (s=="geographic") {
+ if( 0 === $('#selImgFormat option[value=KMZ]').length) {
+ $('#selImgFormat').append( $('<option></option>').val("KMZ").text("KMZ"));
+ }
+ conversionFactor = 0.002197;
+ }
+ else { //polar
+ if( 0 !== $('#selImgFormat option[value=KMZ]').length) {
+ $('#selImgFormat option[value=KMZ]').remove();
+ }
+ }
+ var dTime = time;
+ //Julian date, padded with two zeros (to ensure the julian date is always in DDD format).
+ var jStart = wv.util.parseDateUTC(dTime.getUTCFullYear() + "-01-01");
+ var jDate = "00" + (1+Math.ceil((dTime.getTime() - jStart) / 86400000));
+ dlURL += "TIME="+dTime.getUTCFullYear()+(jDate).substr((jDate.length)-3);
+
+
+
+ dlURL += "&extent="+lonlat1.lon+","+lonlat1.lat+","+lonlat2.lon+","+lonlat2.lat;
+
+ //dlURL += "&switch="+s;
+ dlURL += "&epsg="+epsg;
+ dlURL +="&layers=" + _.pluck(products, "id").join(",");
+
+ var imgWidth=0; var imgHeight=0;
+
+
+ $("select#selImgResolution").change(function () {
+ imgRes = $("#selImgResolution option:selected").val();
+ imgWidth = Math.round((Math.abs(lonlat2.lon - lonlat1.lon) / conversionFactor) / Number(imgRes));
+ imgHeight = Math.round((Math.abs(lonlat2.lat - lonlat1.lat) / conversionFactor) / Number(imgRes));
+ imgFilesize = (( imgWidth * imgHeight * 24) / 8388608).toFixed(2);
+
+ $("#imgWidth").text((imgWidth));
+ $("#imgHeight").text((imgHeight));
+ $("#imgFileSize").text(imgFilesize);
+ if(imgFilesize>250) { $("#imgFileSize").css("color", "#D99694"); $("#btnImgDownload").attr("disabled", "disabled"); }
+ else { $("#imgFileSize").css("color", "white"); $("#btnImgDownload").removeAttr("disabled"); }
+ })
+ .change();
+
+
+ $("#btnImgDownload").unbind('click').click(function(){
+ ntptEventTag('lc='+encodeURIComponent(dlURL+"&format="+$("#selImgFormat option:selected").val()+"&width="+$("#imgWidth").text()+"&height="+$("#imgHeight").text() ) );
+ window.open(dlURL+"&format="+$("#selImgFormat option:selected").val()+"&width="+$("#imgWidth").text()+"&height="+$("#imgHeight").text(),"_blank");
+ });
+ } catch ( cause ) {
+ wv.util.error(cause);
+ }
+ };
+
+ init();
+ return self;
+
+};
\ No newline at end of file
diff --git a/src/js/image/wv.image.rubberband.js b/src/js/image/wv.image.rubberband.js
new file mode 100644
index 000000000..e6522d3ab
--- /dev/null
+++ b/src/js/image/wv.image.rubberband.js
@@ -0,0 +1,159 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+wv.image = wv.image || {};
+
+wv.image.rubberband = wv.image.rubberband || function(models, config) {
+
+ var self = {};
+
+ var PALETTE_WARNING =
+ "Image download does not yet support the custom palette(s) that you " +
+ "have applied. Would you like to continue with the default color palette(s)?";
+
+ var containerId = "camera";
+ var container;
+ var coords = null;
+ var previousCoords = null;
+ var icon = "images/camera.png";
+ var onicon = "images/cameraon.png";
+ var cropee = "map";
+ var id = containerId;
+ var state = "off";
+ var jcropAPI = null;
+ var previousPalettes = "";
+ var currentPalettes = "";
+ self.events = wv.util.events();
+
+ /**
+ * Initializes the RubberBand component.
+ *
+ * @this {RubberBand}
+ */
+ var init = function(){
+ container=document.getElementById(containerId);
+ if (container===null){
+ throw new Error("Error: element '"+containerId+"' not found!");
+ }
+ container.setAttribute("class","rubberband");
+
+ container.innerHTML = "<a id='"+id+"camera_link' class='toolbar-link' title='Take a snapshot'><img src='"+icon+"' /></a>";
+ $('#'+id+"camera_link").on('click', toggle);
+ };
+
+ var toggle = function(){
+ var toggleOn = function() {
+ state = "on";
+ $("#"+id+"camera_link img").attr("src",onicon);
+ $("#imagedownload").show('slide', {direction: 'up'}, 1000);
+ draw();
+ };
+
+ // When disabling the palettes, we need to wait for the map to reload all
+ // the tiles before enabling the crop box. The crop box copies all
+ // elements in the map to do its background effect and if the map isn't
+ // ready yet, it will copy blank images.
+ var disablePalettes = function() {
+ var map = models.map.maps.map;
+ var handler = function() {
+ map.events.unregister("maploadend", map, handler);
+ toggleOn();
+ };
+ map.events.register("maploadend", map, handler);
+
+ // Save the previous state to be restored later
+ previousPalettes = models.palettes.active;
+ // FIXME: What is this for?
+ // self.paletteWidget.noRestore = true;
+ models.palettes.clear();
+ };
+
+ if(state == "off") {
+ // Confirm with the user they want to continue, and if so, disable
+ // the palettes before bringing up the crop box.
+ if (_.size(models.palettes.active) > 0) {
+ wv.ui.ask({
+ header: "Notice",
+ message: PALETTE_WARNING,
+ onOk: disablePalettes
+ });
+ } else {
+ toggleOn();
+ }
+ }
+ else {
+ state = "off";
+ $("#"+id+"camera_link img").attr("src",icon);
+ jcropAPI.destroy();
+ $("#imagedownload").hide('slide', {direction: 'up'}, 1000);
+ if (previousPalettes) {
+ // FIXME: What is this for?
+ //self.paletteWidget.noResture = false;
+ _.each(previousPalettes, function(paletteId, layerId) {
+ model.palettes.add(layerId, paletteId);
+ });
+ }
+ }
+ };
+
+ /**
+ * Sets the values for the rubberband (x1, y1, x2, y2, width, height) from the passed "coordinates" object of JCrop *
+ * @this {RBand}
+ * @param {String} coordinates object of JCrop
+ *
+ */
+ var setCoords = function(c) {
+ previousCoords = coords;
+ coords = c;
+ self.events.trigger("update", coords);
+ };
+
+ /**
+ * Activates the drawing on the map.
+ *
+ * @this {RBand}
+ *
+ *
+ */
+ var draw = function() {
+
+ $("#"+cropee).Jcrop({
+ bgColor: 'black',
+ bgOpacity: 0.3,
+ onSelect: function(c){previousCoords=coords;handleChange(c);},
+ onChange: function(c){handleChange(c);},
+ onRelease: function(c){ coords=previousCoords; toggle(); },
+ fullScreen: true
+ });
+
+ jcropAPI = $('#'+cropee).data('Jcrop');
+
+ if(coords) {
+ jcropAPI.setSelect([coords.x, coords.y,coords.x2,coords.y2]);
+ }
+ else {
+ jcropAPI.setSelect([($(window).width()/2)-100,($(window).height()/2)-100,($(window).width()/2)+100,($(window).height()/2)+100]);
+ }
+
+ };
+
+
+ var handleChange = function(c){
+
+ setCoords(c);
+
+ };
+
+ init();
+ return self;
+};
+
diff --git a/src/js/imageDownload.js b/src/js/imageDownload.js
deleted file mode 100644
index 082d89113..000000000
--- a/src/js/imageDownload.js
+++ /dev/null
@@ -1,294 +0,0 @@
-SOTE.namespace("SOTE.widget.ImageDownload");
-
-/**
- * The ImageDownload object that provides a UI to users for image download.
- * Provides a list of available resolutions, image formats, along with calculated image dimensions and size per users' area selection.
- *
- */
-SOTE.widget.ImageDownload = function(containerId, config){
- this.BASE_URL = "http://map2.vis.earthdata.nasa.gov/imagegen/index";
-
- this.container=document.getElementById(containerId);
-
- if (this.container==null){
- this.setStatus("Error: element '"+containerId+"' not found!",true);
- return;
- }
-
- if(config===undefined) {
- config={};
- }
-
- this.alignTo = config.alignTo;
- this.id = containerId;
- this.m = config.m;
-
-
- if (config.baselayer === undefined)
- {
- config.baselayer = null;
- }
- this.baseLayer = config.baselayer;
- this.config = config.config;
- this.value = "";
-
- if ( this.config.parameters.imagegen ) {
- console.warn("Redirecting image download to: " + this.BASE_URL +
- "-" + this.config.parameters.imagegen + ".php");
- }
- this.init();
-};
-
-SOTE.widget.ImageDownload.prototype = new SOTE.widget.Component;
-
-
-/**
- * Initialize a map object in Lat/Long projection, and add a "fake" layer to compute the map math.
- * Display the HTML UI with UI options. *
- * @this {Download}
- * @requires SOTE.widget.Map
-*/
-SOTE.widget.ImageDownload.prototype.init = function(){
- this.container.setAttribute("class","imagedownload");
-
- var self = this;
-
- SOTE.widget.ImageDownload.setPosition(this);
- $(window).resize(function() {
- SOTE.widget.ImageDownload.setPosition(self);
- });
-
- if(REGISTRY){
- REGISTRY.register(this.id,this);
- REGISTRY.markComponentReady(this.id);
- }
- else{
- alert("No REGISTRY found! Cannot register Download!");
- }
-
- var htmlElements = "<div>Resolution (per pixel): <select id='selImgResolution'><option value='1'>250m</option><option value='2'>500m</option><option value='4'>1km</option><option value='20'>5km</option><option value='40'>10km</option></select>";
- htmlElements +="<br />Format: <select id='selImgFormat'><option value='image/jpeg'>JPEG</option><option value='image/png'>PNG</option><option value='image/geotiff'>GeoTIFF</option></select>";
- htmlElements +="<br />Raw Image Size: ~ <span id='imgFileSize'> </span> MB <br />(<span id='imgWidth''></span> x <span id='imgHeight'></span> pixels)";
- htmlElements += "<br /><span style='font-size:10px; color:#aaa; font-style:italic;'>(Max Size: 250 MB)</span> ";//(<span id='imgWidth''></span> x <span id='imgHeight'></span> pixels)
- htmlElements += "<br /><input type='button' id='btnImgDownload' value='Download'/>";
- htmlElements +="</div>";
-
- $("#"+this.id).html(htmlElements);
-
-
-};
-
-SOTE.widget.ImageDownload.setPosition = function(self){
- var offset = $("#"+self.alignTo.id).offset();
- var left = offset.left + parseInt($("#"+self.alignTo.id).css("width")) - parseInt($("#"+self.id).css("width"));
- $("#"+self.id).css("left",left+"px");
-};
-
-/**
- * Sets the passed HTML string as the component's value
- *
- * @this {Download}
- * @param {String} value is the URL for download image
- *
-*/
-SOTE.widget.ImageDownload.prototype.setValue = function(value){
-
- this.value=value;
-
-};
-
-/**
- * Gets the currently HTML value of the component.
- *
- * @this {Download}
- * @returns {String} a string representing the currently configured download URL
- *
-*/
-SOTE.widget.ImageDownload.prototype.getValue = function(){
- return this.id+"="+this.value;
-};
-
-/**
- * Modify the component based on dependencies. Speficially, update the image dimensions and image size based on the size of rubberband box the user draws. *
- * @this {Download}
- * @param {String} querystring contains all values of dependencies (from registry)
- *
-*/
-
-
-SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
-
- try {
- var query = wv.util.fromQueryString(qs);
- var bbox = query.map || "";
- var time = query.time || "";
- var pixels = query.camera || "";
- var s = query["switch"] || "";
- var products = query.products || "";
- var epsg = query.epsg || "";
-
- //console.log("EPSG: " + epsg);
-
- var px = pixels.split(",");
- var x1 = px[0]; var y1= px[1]; var x2 = px[2]; var y2=px[3];
- var lonlat1 = this.m.maps.map.getLonLatFromViewPortPx(new OpenLayers.Pixel(Math.floor(x1), Math.floor(y2)));
- var lonlat2 = this.m.maps.map.getLonLatFromViewPortPx(new OpenLayers.Pixel(Math.floor(x2), Math.floor(y1)));
-
- var dlURL = null;
- var imagegen = this.config.parameters.imagegen;
- if ( imagegen ) {
- dlURL = this.BASE_URL + "-" + imagegen + ".php?";
- } else {
- dlURL= this.BASE_URL + ".php?";
- }
-
- var conversionFactor = 256;
- if (s=="geographic") {
- if( !(0 != $('#selImgFormat option[value=KMZ]').length)) {
- $('#selImgFormat').append( $('<option></option>').val("KMZ").text("KMZ"));
- }
- conversionFactor = 0.002197;
- }
- else { //polar
- if( 0 != $('#selImgFormat option[value=KMZ]').length) {
- $('#selImgFormat option[value=KMZ]').remove();
- }
- }
- var dTime = wv.util.parseDateUTC(time);
- //Julian date, padded with two zeros (to ensure the julian date is always in DDD format).
- var jStart = wv.util.parseDateUTC(dTime.getUTCFullYear() + "-01-01");
- var jDate = "00" + (1+Math.ceil((dTime.getTime() - jStart) / 86400000));
- dlURL += "TIME="+dTime.getUTCFullYear()+(jDate).substr((jDate.length)-3);
-
-
-
- dlURL += "&extent="+lonlat1.lon+","+lonlat1.lat+","+lonlat2.lon+","+lonlat2.lat;
-
- //dlURL += "&switch="+s;
- dlURL += "&epsg="+epsg;
- dlURL +="&layers=";
- if (products != ""){
- var a = products.split("~");
-
- //Add the first (top most) visible baselayer.
- var base = a[0].split(",");
- //base.reverse(); base.pop();
- for(var i=1; i<base.length; i++){
- if(base[i].charAt(0)!="!") {
- dlURL += base[i]+",";
- break;
- }
- }
-
- var overlays = a[1].split(/[\.,]/);
- overlays.reverse(); overlays.pop();
-
- for(var i=0; i<overlays.length; i++){
- if(overlays[i].charAt(0)!="!") {
- dlURL+= overlays[i]+",";
- }
- }
-
- //remove the extra ","
- dlURL = dlURL.slice(0,-1);
-
- }
-
-
- var imgWidth=0; var imgHeight=0;
-
-
- $("select#selImgResolution").change(function () {
- imgRes = $("#selImgResolution option:selected").val();
- imgWidth = Math.round((Math.abs(lonlat2.lon - lonlat1.lon) / conversionFactor) / Number(imgRes));
- imgHeight = Math.round((Math.abs(lonlat2.lat - lonlat1.lat) / conversionFactor) / Number(imgRes));
- imgFilesize = (( imgWidth * imgHeight * 24) / 8388608).toFixed(2);
-
- $("#imgWidth").text((imgWidth));
- $("#imgHeight").text((imgHeight));
- $("#imgFileSize").text(imgFilesize);
- if(imgFilesize>250) { $("#imgFileSize").css("color", "#D99694"); $("#btnImgDownload").attr("disabled", "disabled"); }
- else { $("#imgFileSize").css("color", "white"); $("#btnImgDownload").removeAttr("disabled"); }
- })
- .change();
-
-
- $("#btnImgDownload").unbind('click').click(function(){
- ntptEventTag('lc='+encodeURIComponent(dlURL+"&format="+$("#selImgFormat option:selected").val()+"&width="+$("#imgWidth").text()+"&height="+$("#imgHeight").text() ) );
- window.open(dlURL+"&format="+$("#selImgFormat option:selected").val()+"&width="+$("#imgWidth").text()+"&height="+$("#imgHeight").text(),"_blank");
- });
-
- this.setValue(dlURL);
- } catch ( cause ) {
- Worldview.error("Unable to update download box", cause);
- }
-};
-
-
-
-/**
- * Sets the URL from the querystring
- *
- * @this {Download}
- * @param {String} qs contains the querystring (must contain [containerId]=[selectedDate] in the string)
- * @returns {boolean} true or false depending on if the extracted date validates
- *
-*/
-SOTE.widget.ImageDownload.prototype.loadFromQuery = function(qs){
-};
-
-/**
- * Validates that the selected URL is valid
- * @this {Download}
- * @returns {boolean} true or false depending on whether the date is not null and within bounds
-*/
-SOTE.widget.ImageDownload.prototype.validate = function(){
- // Content
-};
-
-/**
- * Sets the accessor that provides state change instructions given dependencies
- *
- * @this {Download}
- * @param {String} sourceurl is the relative location of the accessor
- *
-*/
-SOTE.widget.ImageDownload.prototype.setSourceUrl = function(sourceurl){
- // Content
-};
-
-/**
- * Gets the accessor
- *
- * @this {Download}
- * @returns {String} the relative location of the accessor
- *
-*/
-SOTE.widget.ImageDownload.prototype.getSourceUrl = function(){
- // Content
-};
-
-/**
- * Sets the status of the component
- *
- * @this {Download}
- * @param {String} s the current status of the component (user prompts, error messages)
- *
-*/
-SOTE.widget.ImageDownload.prototype.setStatus = function(s){
- // Content
-};
-
-/**
- * Gets the status of the component
- *
- * @this {Download}
- * @returns {String} the current status of the component (user prompts, error messages)
- *
-*/
-SOTE.widget.ImageDownload.prototype.getStatus = function(){
- // Content
-};
-
-
-
diff --git a/src/js/layers/wv.layers.active.js b/src/js/layers/wv.layers.active.js
index b3cd595cb..388279b3b 100644
--- a/src/js/layers/wv.layers.active.js
+++ b/src/js/layers/wv.layers.active.js
@@ -109,14 +109,14 @@ wv.layers.active = wv.layers.active || function(models, config) {
var renderLayer = function($parent, group, layer, top) {
var $layer = $("<li></li>")
- .attr("id", group.id + "-" + Worldview.id(layer.id))
+ .attr("id", group.id + "-" + encodeURIComponent(layer.id))
.addClass(self.id + "item")
.addClass("item")
.attr("data-layer", layer.id);
var $removeButton = $("<a></a>");
var $removeImage = $("<img></img>")
- .attr("id", "close" + group.id + Worldview.id(layer.id))
+ .attr("id", "close" + group.id + encodeURIComponent(layer.id))
.addClass("close")
.addClass("bank-item-img")
.attr("data-layer", layer.id)
@@ -128,7 +128,7 @@ wv.layers.active = wv.layers.active || function(models, config) {
var $visibleButton = $("<a></a>")
.addClass("hdanchor");
var $visibleImage = $("<img></img>")
- .attr("id", "hide" + Worldview.id(layer.id))
+ .attr("id", "hide" + encodeURIComponent(layer.id))
.attr("data-layer", layer.id)
.addClass("hide")
.addClass("hideReg")
@@ -225,7 +225,7 @@ wv.layers.active = wv.layers.active || function(models, config) {
var resize = function() {
// If on a mobile device, use the native scroll bars
- if ( $(window).width() > Worldview.TRANSITION_WIDTH ) {
+ if ( !wv.util.browser.small ) {
if ( jsp ) {
var api = jsp.data('jsp');
if ( api ) {
@@ -249,7 +249,7 @@ wv.layers.active = wv.layers.active || function(models, config) {
};
var onLayerRemoved = function(layer) {
- var layerSelector = "#" + layer.group + "-" + Worldview.id(layer.id);
+ var layerSelector = "#" + layer.group + "-" + encodeURIComponent(layer.id);
$(layerSelector).remove();
adjustCategoryHeights();
};
diff --git a/src/js/layers/wv.layers.add.js b/src/js/layers/wv.layers.add.js
index 60c88665d..2face7825 100644
--- a/src/js/layers/wv.layers.add.js
+++ b/src/js/layers/wv.layers.add.js
@@ -132,7 +132,7 @@ wv.layers.add = wv.layers.add || function(models, config) {
.html(layer.subtitle);
var $checkbox = $("<input></input>")
- .attr("id", Worldview.id(layer.id))
+ .attr("id", encodeURIComponent(layer.id))
.attr("value", layer.id)
.attr("type", "checkbox")
.attr("data-layer", layer.id);
@@ -206,7 +206,7 @@ wv.layers.add = wv.layers.add || function(models, config) {
$(self.selector)
.height($(self.selector).parent().outerHeight() - tabs_height);
- if ( $(window).width() > Worldview.TRANSITION_WIDTH ) {
+ if ( !wv.util.browser.small ) {
if ( jsp ) {
var api = jsp.data('jsp');
if ( api ) {
@@ -241,12 +241,12 @@ wv.layers.add = wv.layers.add || function(models, config) {
};
var onLayerAdded = function(layer) {
- var $element = $("#" + Worldview.id(layer.id));
+ var $element = $("#" + encodeURIComponent(layer.id));
$element.attr("checked", "checked");
};
var onLayerRemoved = function(layer) {
- var $element = $("#" + Worldview.id(layer.id));
+ var $element = $("#" + encodeURIComponent(layer.id));
$element.removeAttr("checked");
};
@@ -335,7 +335,7 @@ wv.layers.add = wv.layers.add || function(models, config) {
filterProjection(layer) ||
filterSearch(layer, search);
var display = filtered ? "none": "block";
- $("#" + Worldview.id(layerId)).parent().css("display", display);
+ $("#" + encodeURIComponent(layerId)).parent().css("display", display);
});
adjustCategoryHeights();
};
diff --git a/src/js/layers/wv.layers.js b/src/js/layers/wv.layers.js
new file mode 100644
index 000000000..386c822e7
--- /dev/null
+++ b/src/js/layers/wv.layers.js
@@ -0,0 +1,57 @@
+/*
+ * 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 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+
+wv.layers = (function(self) {
+
+ self.parse = function(state, errors, config) {
+ var str = state.products;
+ if ( str ) {
+ var layers = [];
+ var hidden = {};
+ var ids = str.split(/[~,]/);
+ _.each(ids, function(id) {
+ if ( id === "baselayers" || id == "overlays" ) {
+ return;
+ }
+ var visible = true;
+ if ( id.startsWith("!") ) {
+ visible = false;
+ id = id.substring(1);
+ }
+ if ( config.redirects && config.redirects.layers ) {
+ id = config.redirects.layers[id] || id;
+ }
+ if ( !config.layers[id] ) {
+ errors.push({message: "No such layer: " + id});
+ return;
+ }
+ // Layers have to be added in reverse
+ layers.unshift(id);
+ if ( !visible ) {
+ hidden[id] = true;
+ }
+ });
+ if ( layers.length > 0 ) {
+ state.products = layers;
+ if ( _.size(hidden) > 0 ) {
+ state.hidden = hidden;
+ }
+ } else {
+ delete state.products;
+ }
+ }
+ };
+
+ return self;
+
+})(wv.layers || {});
diff --git a/src/js/layers/wv.layers.model.js b/src/js/layers/wv.layers.model.js
index 21f64e4db..9001c2aac 100644
--- a/src/js/layers/wv.layers.model.js
+++ b/src/js/layers/wv.layers.model.js
@@ -49,6 +49,7 @@ wv.layers.model = wv.layers.model || function(models, config) {
}
};
+ // Deprecated
self.forProjection = function(proj) {
proj = proj || models.proj.selected.id;
var results = {
@@ -65,6 +66,27 @@ wv.layers.model = wv.layers.model || function(models, config) {
return results;
};
+ self.forGroup = function(group, spec) {
+ var results = [];
+ var groups = self.forProjection();
+ _.each(groups[group], function(layer) {
+ if ( spec.visibleOnly && !self.visible[layer.id] ) {
+ return;
+ }
+ results.push(layer);
+ });
+ if ( spec.reverse ) {
+ results = results.reverse();
+ }
+ return results;
+ };
+
+ self.get = function(spec) {
+ var baselayers = self.forGroup("baselayers", spec);
+ var overlays = self.forGroup("overlays", spec);
+ return Array.concat(baselayers, overlays);
+ };
+
self.dateRange = function(proj) {
proj = proj || models.proj.selected.id;
if ( config.parameters && config.parameters.debugGIBS ) {
@@ -214,6 +236,7 @@ wv.layers.model = wv.layers.model || function(models, config) {
if ( self.visible[id] !== visible ) {
self.visible[id] = visible;
self.events.trigger("visibility", layer, visible);
+ self.events.trigger("change");
}
};
@@ -229,59 +252,28 @@ wv.layers.model = wv.layers.model || function(models, config) {
return answer;
};
- self.toPermalink = function() {
- var types = [];
- $.each(self.forProjection(), function(type, layers) {
- type = [type];
- $.each(layers, function(index, layer) {
+ self.save = function(state) {
+ var groups = [];
+ _.each(self.forProjection(), function(layers, group) {
+ group = [group];
+ _.each(layers, function(layer) {
prefix = ( !self.visible[layer.id] ) ? "!": "";
- type.push(prefix + layer.id);
+ group.push(prefix + layer.id);
});
- types.push(type.join(","));
+ // Only list group if there are layers to save
+ if ( group.length > 1 ) {
+ groups.push(group.join(","));
+ }
});
- return "products=" + types.join("~");
+ state.products = groups.join("~");
};
- self.fromPermalink = function(queryString) {
- var query = wv.util.fromQueryString(queryString);
- var values = query.layers || query.products;
- if ( values ) {
+ self.load = function(state) {
+ if ( state.products ) {
self.clear(models.proj.selected.id);
- // Base layers / overlays
- var sections = values.split("~");
- $.each(sections, function(i, section) {
- var group = null;
- $.each(sections, function(i, section) {
- var items = section.split(/[,\.]/);
- var layers = [];
- $.each(items, function(index, item) {
- if ( index === 0 ) {
- group = item;
- if ( !wv.util.LAYER_GROUPS[group] ) {
- wv.util.warn("Invalid layer group: " + group);
- return false;
- }
- } else {
- var hidden = item.startsWith("!");
- if ( hidden ) {
- item = item.substring(1);
- }
- // Layers have to be added in reverse
- layers.unshift({id: item, hidden: hidden});
- }
- });
- $.each(layers, function(index, layer) {
- var redirect = config.redirects.layers[layer.id];
- if ( redirect ) {
- layer.id = redirect;
- }
- try {
- self.add(layer.id, layer.hidden);
- } catch ( error ) {
- wv.util.warn("Invalid layer: " + layer.id);
- }
- });
- });
+ _.each(state.products, function(layerId) {
+ var hidden = state.hidden && state.hidden[layerId];
+ self.add(layerId, hidden);
});
}
};
diff --git a/src/js/layers/wv.layers.sidebar.js b/src/js/layers/wv.layers.sidebar.js
index a8505dacf..13a764463 100644
--- a/src/js/layers/wv.layers.sidebar.js
+++ b/src/js/layers/wv.layers.sidebar.js
@@ -52,7 +52,7 @@ wv.layers.sidebar = wv.layers.sidebar || function(models) {
var init = function() {
render();
- if ( $(window).width() < Worldview.TRANSITION_WIDTH ) {
+ if ( wv.util.browser.small ) {
slide();
}
$(window).resize(adjustAlignment);
@@ -205,7 +205,7 @@ wv.layers.sidebar = wv.layers.sidebar || function(models) {
};
var adjustAlignment = function() {
- if ( $(window).width() < Worldview.TRANSITION_WITH && collapsed ) {
+ if ( wv.util.browser.small && collapsed ) {
var w = $('.products').outerWidth();
$('.products').css("left", "-" + w + "px");
}
diff --git a/src/js/legacy/wv.legacy.bank.js b/src/js/legacy/wv.legacy.bank.js
deleted file mode 100644
index 37b72e539..000000000
--- a/src/js/legacy/wv.legacy.bank.js
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module wv.legacy
- */
-var wv = wv || {};
-wv.legacy = wv.legacy || {};
-
-/**
- * Undocumented.
- *
- * @class wv.legacy.bank
- */
-wv.legacy.bank = wv.legacy.bank || function(model) {
-
- var self = {};
-
- self.id = "products";
-
- var init = function() {
- REGISTRY.register(self.id, self);
- REGISTRY.markComponentReady(self.id);
-
- model.events.on("add", fire);
- model.events.on("remove", fire);
- model.events.on("update", fire);
- model.events.on("visibility", fire);
- fire();
- };
-
- self.setValue = function(value) {
- model.fromPermalink(self.id + "=" + value);
- };
-
- self.getValue = function() {
- return decodeURIComponent(model.toPermalink());
- };
-
- self.updateComponent = function() {};
-
- self.loadFromQuery = function(queryString) {
- model.fromPermalink(queryString);
- fire();
- };
-
- self.parse = function(queryString, object) {
- var projection = Worldview.extractFromQuery("switch", queryString);
- object.projection = projection;
- return object;
- };
-
- var fire = function() {
- REGISTRY.fire(self);
- };
-
- init();
- return self;
-};
\ No newline at end of file
diff --git a/src/js/legacy/wv.legacy.date.js b/src/js/legacy/wv.legacy.date.js
deleted file mode 100644
index 132321781..000000000
--- a/src/js/legacy/wv.legacy.date.js
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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 - 2014 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module wv.legacy
- */
-var wv = wv || {};
-wv.legacy = wv.legacy || {};
-
-/**
- * Undocumented.
- *
- * @class wv.legacy.date
- */
-wv.legacy.date = wv.legacy.date || function(model) {
-
- var self = {};
-
- self.id = "time";
-
- var init = function() {
- REGISTRY.register(self.id, self);
- REGISTRY.markComponentReady(self.id);
-
- model.events.on("select", fire);
- fire();
- };
-
- self.setValue = function(value) {
- model.set(self.id + "=" + model.selected.toISOString().split("T")[0]);
- };
-
- self.getValue = function() {
- return decodeURIComponent(model.toPermalink());
- };
-
- self.updateComponent = function() {};
-
- self.loadFromQuery = function(queryString) {
- model.fromPermalink(queryString);
- fire();
- };
-
- self.parse = function(queryString, object) {
- var timeString = Worldview.extractFromQuery("time", queryString);
- if ( !timeString ) {
- object.time = wv.util.today();
- } else {
- try {
- object.time = wv.util.parseDateUTC(timeString);
- } catch ( error ) {
- console.warn("Invalid time: " + timeString + ", reason: " +
- error);
- object.time = wv.util.today();
- }
- }
- };
-
- var fire = function() {
- REGISTRY.fire(self);
- };
-
- init();
- return self;
-};
\ No newline at end of file
diff --git a/src/js/legacy/wv.legacy.palettes.js b/src/js/legacy/wv.legacy.palettes.js
deleted file mode 100644
index ad933d79b..000000000
--- a/src/js/legacy/wv.legacy.palettes.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module wv.legacy
- */
-var wv = wv || {};
-wv.legacy = wv.legacy || {};
-
-/**
- * Undocumented.
- *
- * @class wv.legacy.palettes
- */
-wv.legacy.palettes = wv.legacy.palettes || function(model) {
-
- var self = {};
-
- self.id = "palettes";
-
- var init = function() {
- REGISTRY.register(self.id, self);
- REGISTRY.markComponentReady(self.id);
-
- model.events.on("add", fire);
- model.events.on("remove", fire);
- fire();
- };
-
- self.setValue = function(value) {
- model.fromPermalink(self.id + "=" + value);
- };
-
- self.getValue = function() {
- return decodeURIComponent(model.toPermalink());
- };
-
- self.updateComponent = function() {};
-
- self.loadFromQuery = function(queryString) {
- model.fromPermalink(queryString);
- fire();
- };
-
- self.parse = function(queryString, object) {
- object.palettes = {};
- palettes = Worldview.extractFromQuery("palettes", queryString);
- object.palettesString = palettes;
-
- if ( !palettes ) {
- return object;
- }
- var definitions = palettes.split("~");
- $.each(definitions, function(index, definition) {
- var items = definition.split(",");
- var layer = items[0];
- var palette = items[1];
- object.palettes[layer] = palette;
- });
- return object;
- };
-
- var fire = function() {
- REGISTRY.fire(self);
- };
-
- init();
- return self;
-};
\ No newline at end of file
diff --git a/src/js/legacy/wv.legacy.switch_.js b/src/js/legacy/wv.legacy.switch_.js
deleted file mode 100644
index 05cee9b96..000000000
--- a/src/js/legacy/wv.legacy.switch_.js
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module wv.legacy
- */
-var wv = wv || {};
-wv.legacy = wv.legacy || {};
-
-/**
- * Undocumented.
- *
- * @class wv.legacy.switch
- */
-wv.legacy.switch_ = wv.legacy.switch_ || function(model) {
-
- var self = {};
-
- self.id = "switch";
-
- var init = function() {
- REGISTRY.register(self.id, self);
- REGISTRY.markComponentReady(self.id);
-
- model.events.on("select", fire);
- fire();
- };
-
- self.setValue = function(value) {
- model.set(self.id + "=" + model.selected.id);
- };
-
- self.getValue = function() {
- return decodeURIComponent(model.toPermalink()) +
- "&epsg=" + model.selected.epsg +
- "&crs=" + model.selected.crs;
- };
-
- self.updateComponent = function() {};
-
- self.loadFromQuery = function(queryString) {
- model.fromPermalink(queryString);
- fire();
- };
-
- var fire = function() {
- REGISTRY.fire(self);
- };
-
- init();
- return self;
-};
\ No newline at end of file
diff --git a/src/js/link/wv.link.model.js b/src/js/link/wv.link.model.js
index e58cc284f..eda15efde 100644
--- a/src/js/link/wv.link.model.js
+++ b/src/js/link/wv.link.model.js
@@ -26,6 +26,10 @@ wv.link.model = wv.link.model || function(config) {
var self = {};
var DEBUG_SHORTEN_LINK = "https://earthdata.nasa.gov/worldview?a=1&b=2";
+ var ENCODING_EXCEPTIONS = [
+ { match: new RegExp("%2C", "g"), replace: "," }
+ ];
+
var shortenCache = new Cache(10);
var mock = "";
var components = [];
@@ -49,14 +53,14 @@ wv.link.model = wv.link.model || function(config) {
* characters escaped.
*/
self.toQueryString = function() {
- var parts = [];
+ var state = {};
_.each(components, function(component) {
- var value = component.toPermalink();
- if ( value && value.length > 0 ) {
- parts.push(component.toPermalink());
- }
+ var value = component.save(state);
+ });
+ state = _.map(state, function(value, key) {
+ return key + "=" + encode(value);
});
- return parts.join("&");
+ return state.join("&");
};
/**
@@ -101,18 +105,19 @@ wv.link.model = wv.link.model || function(config) {
return promise;
};
- /**
- * Sets the state of all registered models from a query string.
- *
- * @method load
- * @param {Object} [queryString] the query string to use, if not specified
- * ``window.location.search`` is used.
- */
- self.load = function(queryString) {
- queryString = queryString || window.location.search;
+ self.load = function(state, errors) {
+ errors = errors || [];
_.each(components, function(component) {
- component.fromPermalink(queryString);
+ component.load(state, errors);
+ });
+ };
+
+ var encode = function(value) {
+ var encoded = encodeURIComponent(value);
+ _.each(ENCODING_EXCEPTIONS, function(exception) {
+ encoded = encoded.replace(exception.match, exception.replace);
});
+ return encoded;
};
init();
diff --git a/src/js/Worldview/Map.js b/src/js/map/wv.map.js
similarity index 69%
rename from src/js/Worldview/Map.js
rename to src/js/map/wv.map.js
index 5e8769744..0fcb9babf 100644
--- a/src/js/Worldview/Map.js
+++ b/src/js/map/wv.map.js
@@ -4,23 +4,21 @@
* This code was originally developed at NASA/Goddard Space Flight Center for
* the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-/**
- * @module Worldview
- */
-Worldview.namespace("Map");
+var wv = wv || {};
+wv.map = wv.map || {};
-$(function(ns) {
+wv.map = (function(self) {
- ns.CRS_WGS_84 = "EPSG:4326";
+ self.CRS_WGS_84 = "EPSG:4326";
- ns.CRS_WGS_84_QUERY_EXTENT = new OpenLayers.Bounds(-180, -60, 180, 60);
+ self.CRS_WGS_84_QUERY_EXTENT = new OpenLayers.Bounds(-180, -60, 180, 60);
- ns.CRS_WGS_84_QUERY_MASK =
+ self.CRS_WGS_84_QUERY_MASK =
new OpenLayers.Geometry.MultiPolygon([
new OpenLayers.Bounds(-180, -90, 180, -60).toGeometry(),
new OpenLayers.Bounds(-180, 60, 180, 90).toGeometry()
@@ -33,13 +31,11 @@ $(function(ns) {
* or "antarctic".
*
* Example:
- *
- * var control = Worldview.Map.COORDINATE_CONTROLS["geographic"];
- *
+ * *
* @attribute COORDINATE_CONTROLS
* @final
*/
- ns.COORDINATE_CONTROLS = {
+ self.COORDINATE_CONTROLS = {
"geographic": new OpenLayers.Control.MousePosition({
formatOutput: function(mouseLonLat) {
return mouseLonLat.lon.toFixed(3) + "&#176;, " +
@@ -63,6 +59,19 @@ $(function(ns) {
})
};
+ self.parse = function(state, errors) {
+ if ( state.map ) {
+ var extent = OpenLayers.Bounds.fromString(state.map);
+ var valid = wv.map.isExtentValid(extent);
+ if ( !valid ) {
+ errors.push({message: "Invalid extent: " + state.map});
+ delete state.map;
+ } else {
+ state.map = extent;
+ }
+ }
+ };
+
/**
* Determines if an exent object contains valid values.
*
@@ -74,7 +83,7 @@ $(function(ns) {
* @return {boolean} False if any of the values is NaN, otherwise returns
* true.
*/
- ns.isExtentValid = function(extent) {
+ self.isExtentValid = function(extent) {
if ( extent === undefined ) {
return false;
}
@@ -94,12 +103,14 @@ $(function(ns) {
* @static
* @readOnly
*/
- ns.TILE_SCHEDULER = Worldview.Scheduler.isSupported()
- ? Worldview.Scheduler({
- script: "js/Worldview/Map/TileWorker.js?v=" + wv.brand.BUILD_NONCE,
- max: 4
- })
- : null;
+ self.tileScheduler = _.once(function() {
+ if ( wv.util.browser.webWorkers ) {
+ return wv.map.palette.scheduler({
+ script: "js/map/wv.map.tileworker.js?v=" + wv.brand.BUILD_NONCE,
+ max: 4
+ });
+ }
+ });
/**
* Sets the opacity of a layer. Since the backbuffer can interfere with
@@ -112,7 +123,7 @@ $(function(ns) {
* @param layer {OpenLayers.Layer} The layer to set the opacity
* @param opacity {float} A value from 0 (transparent) to 1 (opaque).
*/
- ns.setOpacity = function(layer, opacity) {
+ self.setOpacity = function(layer, opacity) {
layer.setOpacity(opacity);
if ( opacity === 1 ) {
var effect = layer.originalTransitionEffect || "resize";
@@ -139,7 +150,7 @@ $(function(ns) {
* @param opacity {float} The opacity that this layer should be if it
* is visible. A value from 0 (transparent) to 1 (opaque).
*/
- ns.setVisibility = function(layer, visible, opacity) {
+ self.setVisibility = function(layer, visible, opacity) {
if ( layer.isControl ) {
layer.setVisibility(visible);
} else {
@@ -151,7 +162,7 @@ $(function(ns) {
}
};
- ns.getLayerByName = function(map, name) {
+ self.getLayerByName = function(map, name) {
var layers = map.getLayersByName(name);
if ( layers && layers.length > 1 ) {
throw new Error("Multiple layers found for: " + name);
@@ -161,7 +172,7 @@ $(function(ns) {
}
};
- ns.isPolygonValid = function(polygon, maxDistance) {
+ self.isPolygonValid = function(polygon, maxDistance) {
var outerRing = polygon.components[0];
for ( var i = 0; i < outerRing.components.length - 1; i++ ) {
var p1 = outerRing.components[i];
@@ -173,7 +184,7 @@ $(function(ns) {
return true;
};
- ns.adjustAntiMeridian = function(polygon, adjustSign) {
+ self.adjustAntiMeridian = function(polygon, adjustSign) {
var outerRing = polygon.components[0];
var points = outerRing.components.slice();
@@ -192,16 +203,16 @@ $(function(ns) {
);
};
- ns.distance2D = function(p1, p2) {
+ self.distance2D = function(p1, p2) {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) +
(Math.pow(p1.y - p2.y, 2)));
};
- ns.distanceX = function(p1, p2) {
+ self.distanceX = function(p1, p2) {
return Math.abs(p2.x - p1.x);
};
- ns.interpolate2D = function(p1, p2, amount) {
+ self.interpolate2D = function(p1, p2, amount) {
var distX = p2.x - p1.x;
var distY = p2.y - p1.y;
@@ -213,7 +224,7 @@ $(function(ns) {
// If multipolygon, return a list of the polygons. If polygon, return
// the single item in a list
- ns.toPolys = function(geom) {
+ self.toPolys = function(geom) {
var polys = [];
if ( geom.CLASS_NAME === "OpenLayers.Geometry.MultiPolygon" ) {
polys = geom.components;
@@ -223,5 +234,54 @@ $(function(ns) {
return polys;
};
+ return self;
+
+})(wv.map || {});
+
+wv.map.HoverControl = OpenLayers.Class(OpenLayers.Control, {
+
+ layer: null,
+
+ defaultHandlerOptions: {
+ delay: 2000,
+ pixelTolerance: 1,
+ stopMove: false
+ },
+
+ featureHandler: null,
+
+ initialize: function(layer, options) {
+ this.layer = layer;
+ this.handlerOptions = OpenLayers.Util.extend({},
+ this.defaultHandlerOptions);
+ OpenLayers.Control.prototype.initialize.apply(this, arguments);
+
+ this.featureHandler = new OpenLayers.Handler.Feature(this, this.layer, {
+ over: this.over,
+ out: this.out
+ }, {});
+ this.handlers = {
+ feature: this.featureHandler
+ };
+ },
+
+ draw: function() {
+ return false;
+ },
+
+ activate: function() {
+ this.handlers.feature.activate();
+ },
+
+ deactivate: function() {
+ this.handlers.feature.deactivate();
+ },
+
+ over: function(feature) {
+ this.events.triggerEvent("hoverover", {feature: feature});
+ },
-}(Worldview.Map));
+ out: function(feature) {
+ this.events.triggerEvent("hoverout", {feature: feature});
+ }
+});
diff --git a/src/js/map/wv.map.layers.js b/src/js/map/wv.map.layers.js
new file mode 100644
index 000000000..b2d0df64e
--- /dev/null
+++ b/src/js/map/wv.map.layers.js
@@ -0,0 +1,595 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+wv.map = wv.map || {};
+
+wv.map.layers = wv.map.layers || {};
+
+wv.map.layers.set = function(config, projId, layerId) {
+
+ var self = {};
+ self.opacity = 1;
+ self.visible = false;
+
+ var init = function() {
+ };
+
+ var createWMTS = function(options) {
+ var proj = config.projections[projId];
+ var layer = config.layers[layerId];
+ var matrixSet = config.matrixSets[layer.projections[projId].matrixSet];
+ var source = config.sources[layer.projections[projId].source];
+ var param = {
+ url: source.url,
+ layer: layer.id,
+ style: "",
+ format: layer.format,
+ matrixSet: matrixSet.id,
+ maxResolution: matrixSet.maxResolution,
+ serverResolutions: matrixSet.serverResolutions,
+ maxExtent: proj.maxExtent,
+ tileSize: new OpenLayers.Size(layer.tileSize[0],
+ layer.tileSize[1])
+ };
+ if ( layer.noTransition ) {
+ param.transitionEffect = "none";
+ } else {
+ param.transitionEffect = "resize";
+ }
+ if ( options.tileClass ) {
+ param.tileClass = options.tileClass;
+ }
+ var olLayer = new OpenLayers.Layer.WMTS(param);
+ if ( options && options.time ) {
+ olLayer.mergeNewParams({"time": options.time});
+ }
+ return olLayer;
+ };
+
+ var createWMS = function(add) {
+ var proj = config.projections[projId];
+ var layer = config.layers[layerId];
+ var source = config.sources[layer.projections[projId].source];
+ var layerParameter = layer.projections[projId].layer || layerId;
+
+ var transparent = ( layer.format === "image/png" );
+
+ var params = {
+ layers: layerParameter,
+ format: layer.format,
+ transparent: transparent
+ };
+ if ( layer.period === "daily" ) {
+ params.time = add.time;
+ }
+ var options = {
+ tileSize: new OpenLayers.Size(layer.tileSize[0],
+ layer.tileSize[1]),
+ };
+ if ( layer.opacity ) {
+ options.opacity = layer.opacity;
+ }
+ if ( layer.transition ) {
+ options.transitionEffect = "resize";
+ } else {
+ options.transitionEffect = "none";
+ }
+ var olLayer = new OpenLayers.Layer.WMS(layer.title, source.url,
+ params, options);
+ return olLayer;
+ };
+
+ /**
+ * Function: createLayer
+ * Creates a new layer based on the configuration provided.
+ *
+ * Parameters:
+ * additionalProperties - If specified, these properites are merged into
+ * the product configuration to create the layer.
+ *
+ * Return:
+ * An OpenLayers Layer.
+ */
+ self.createLayer = function(options) {
+ options = options || {};
+ var type = config.layers[layerId].type;
+ if ( type === "wmts" ) {
+ return createWMTS(options);
+ } else if ( type === "wms" ) {
+ return createWMS(options);
+ } else if ( type === "graticule" ) {
+ return new wv.map.layers.graticule("Graticule");
+ } else {
+ throw new Error("Invalid layer type: " + type);
+ }
+ };
+
+ init();
+ return self;
+};
+
+
+wv.map.layers.daily = function(map, config, projId, layerId) {
+
+ var self = wv.map.layers.set(config, projId, layerId);
+
+ // The current z-index for all layers.
+ var zIndex = 0;
+
+ // Layers from previous days are cached for quick display when moving
+ // the time slider
+ var cachedLayers = {};
+
+ // Layers that are no longer valid because the map has moved. These
+ // are removed using a timeout to prevent map flickering.
+ var staleLayers = [];
+
+ // The layer that is currently visible and seen by the user
+ var currentLayer = null;
+
+ // The day of the data displayed on the map
+ var currentDay;
+
+ // Active lookup table for all layers in the product, null if no table
+ // is active
+ var lookupTable = null;
+
+ // Timeout identifier for the reaper that cleans out stale layers.
+ var reaperId = null;
+
+ // Time, in milliseconds, to wait before reaping stale layers.
+ var reapDelay = 500;
+
+ //-------------------------------------------------------------------------
+ // Public
+ //-------------------------------------------------------------------------
+
+ var init = function() {
+ self.setDay(wv.util.today());
+
+ map.events.register("movestart", self, invalidate);
+ map.events.register("zoomend", self, invalidate);
+ $(window).resize(invalidate);
+ };
+
+ /**
+ * Method: setDay
+ * Changes the map to display the product for the given day.
+ *
+ * Parameters:
+ * d - The day to display.
+ */
+ self.setDay = function(d) {
+ // Don't do anything if nothing has changed or if there are no valid
+ // layers
+ if ( !d ) {
+ return;
+ }
+ var ds = wv.util.toISOStringDate(d);
+ if ( ds === currentDay ) {
+ return;
+ }
+
+ // If there is a current layer, cache it
+ if ( currentLayer ) {
+ cachedLayers[currentDay] = currentLayer;
+ }
+ currentDay = ds;
+
+ // If the layer is hidden, don't fetch anything
+ if ( self.visible ) {
+ fetchLayer();
+ } else {
+ currentLayer = null;
+ }
+ };
+
+ self.setOpacity = function(opacity) {
+ if ( self.opacity === opacity ) {
+ return;
+ }
+ self.opacity = opacity;
+ if ( currentLayer ) {
+ wv.map.setVisibility(currentLayer, self.visible, self.opacity);
+ }
+ };
+
+ self.setVisibility = function(visible) {
+ if ( self.visible === visible ) {
+ return;
+ }
+ self.visible = visible;
+ if ( visible && !currentLayer ) {
+ fetchLayer();
+ }
+ if ( currentLayer ) {
+ wv.map.setVisibility(currentLayer, self.visible,
+ self.opacity);
+ }
+ };
+
+ /**
+ * Method: setLookup
+ * Applies a lookup table to this product. If this product doesn't have
+ * a lookup table already, all layers are discarded and a new layer is
+ * created using canvas tile
+ *
+ * Parameters:
+ * lookup - The <ColorLookup> to apply.
+ */
+ self.setLookup = function(lookup) {
+ var resetRequired = (lookupTable === null);
+ lookupTable = lookup;
+ if ( currentLayer ) {
+ if ( resetRequired ) {
+ reset();
+ fetchLayer();
+ } else {
+ invalidate();
+ currentLayer.lookupTable = lookup;
+ applyLookup(currentLayer);
+ }
+ }
+ };
+
+ /**
+ * Method: clearLookup
+ * Removes a lookup table from this product. If the product has a lookup
+ * table, all layers are discarded and a new layer using the standard
+ * tile renderer is created.
+ */
+ self.clearLookup = function() {
+ if ( lookupTable !== null ) {
+ lookupTable = null;
+ if ( currentLayer ) {
+ reset();
+ fetchLayer();
+ }
+ }
+ };
+
+ /**
+ * Method: setZIndex
+ * Sets the z-index for all layers in this product.
+ *
+ * Parameters:
+ * index - The z-index to set. All layers are set with this z-index
+ * except for the visible layer which is set to index + 1.
+ */
+ self.setZIndex = function(index) {
+ zIndex = index;
+ refreshZOrder();
+ };
+
+ /**
+ * Method: dispose
+ * Remove all layers from the map.
+ */
+ self.dispose = function() {
+ reset();
+ if ( reaperId !== null ) {
+ clearTimeout(reaperId);
+ }
+ map.events.unregister("movestart", self, invalidate);
+ map.events.unregister("zoomend", self, invalidate);
+ $(window).unbind("resize", invalidate);
+ };
+
+ //-------------------------------------------------------------------------
+ // Private
+ //-------------------------------------------------------------------------
+
+ var fetchLayer = function() {
+ var previousLayer = currentLayer;
+
+ if ( currentDay in cachedLayers ) {
+ currentLayer = cachedLayers[currentDay];
+ wv.map.setVisibility(currentLayer, self.visible,
+ self.opacity);
+ delete cachedLayers[currentDay];
+ } else {
+ var additionalOptions = {
+ time: currentDay
+ };
+ if ( lookupTable !== null ) {
+ additionalOptions.tileClass = wv.map.palette.canvasTile;
+ }
+ currentLayer = self.createLayer(additionalOptions);
+ if ( lookupTable !== null ) {
+ currentLayer.lookupTable = lookupTable;
+ }
+ map.addLayer(currentLayer);
+ }
+
+ if ( previousLayer ) {
+ previousLayer.setZIndex(zIndex);
+ }
+ currentLayer.setZIndex(zIndex + 1);
+ wv.map.setVisibility(currentLayer, self.visible, self.opacity);
+
+ if ( previousLayer ) {
+ wv.map.setVisibility(previousLayer, false, 0);
+ }
+ };
+
+ /*
+ * Iterates through each tile in the layer and applies the lookup.
+ */
+ var applyLookup = function(layer) {
+ $.each(layer.grid, function(index, row) {
+ $.each(row, function(index, tile) {
+ tile.applyLookup();
+ });
+ });
+ };
+
+ /*
+ * Sets the z-index on all layers.
+ */
+ var refreshZOrder = function() {
+ $.each(cachedLayers, function(i, layer) {
+ layer.setZIndex(zIndex);
+ });
+ if ( currentLayer ) {
+ currentLayer.setZIndex(zIndex + 1);
+ }
+ };
+
+ /*
+ * Clears the cache and removes the current layer. Called when switching
+ * between a lookup and non-lookup based layer.
+ */
+ var reset = function() {
+ invalidate();
+ if ( currentLayer ) {
+ map.removeLayer(currentLayer);
+ }
+ currentLayer = null;
+ };
+
+ /*
+ * Hide all layers that are not currently being displayed and move them
+ * to the stale set. Restart the reaper to remove those layers.
+ */
+ var invalidate = function() {
+ if ( currentLayer ) {
+ var opacity = currentLayer.div.style.opacity;
+ if ( opacity !== "" && opacity < 0.001 ) {
+ currentLayer.setVisibility(false);
+ }
+ }
+ if ( $.isEmptyObject(cachedLayers) ) {
+ return;
+ }
+ $.each(cachedLayers, function(day, layer) {
+ layer.setVisibility(false);
+ staleLayers.push(layer);
+ });
+ cachedLayers = {};
+
+ if ( reaperId !== null ) {
+ clearTimeout(reaperId);
+ }
+ reaperId = setTimeout(function() { reaper(); }, reapDelay);
+ };
+
+
+ /*
+ * Remove all layers in the invalid set from the map.
+ */
+ var reaper = function(all) {
+ $.each(staleLayers, function(index, layer) {
+ if ( map.getLayerIndex(layer) >= 0 ) {
+ map.removeLayer(layer);
+ }
+ });
+ staleLayers = [];
+ refreshZOrder();
+ reaperId = null;
+ };
+
+ init();
+ return self;
+};
+
+
+wv.map.layers.static = function(map, config, projId, layerId) {
+
+ var self = wv.map.layers.set(config, projId, layerId);
+
+ // There is only one layer and this is it
+ var layer = null;
+
+ // Tue current z-index for the layer
+ var zIndex = 0;
+
+ //-------------------------------------------------------------------------
+ // Public
+ //-------------------------------------------------------------------------
+ var init = function() {
+ layer = self.createLayer();
+ map.addLayer(layer);
+ layer.setZIndex(zIndex);
+
+ map.events.register("movestart", self, invalidate);
+ map.events.register("zoomend", self, invalidate);
+ };
+
+ /**
+ * Method: setDay
+ * Does nothing.
+ */
+ self.setDay = function(d) {
+ };
+
+ self.setOpacity = function(opacity) {
+ if ( self.opacity === opacity ) {
+ return;
+ }
+ self.opacity = opacity;
+ wv.map.setVisibility(layer, self.visible, self.opacity);
+ };
+
+ self.setVisibility = function(visible) {
+ if ( self.visible === visible ) {
+ return;
+ }
+ self.visible = visible;
+ wv.map.setVisibility(layer, self.visible, self.opacity);
+ };
+
+ /**
+ * Method: setZIndex
+ * Sets the z-index for the product's layer.
+ *
+ * Parameters:
+ * index - The z-index to set.
+ */
+ self.setZIndex = function(index) {
+ zIndex = index;
+ setZOrder();
+ };
+
+ /**
+ * Method: dispose
+ * Removes the layer from the map.
+ */
+ self.dispose = function() {
+ map.removeLayer(layer);
+ map.events.unregister("movestart", self, invalidate);
+ map.events.unregister("zoomend", self, invalidate);
+ };
+
+ /**
+ * Method: setLookup
+ * Does nothing. This can be implemented once there is a static data
+ * product that could be adjusted.
+ */
+ self.setLookup = function(lookup) {
+ };
+
+ /**
+ * Method: clearLookup
+ * Does nothing. This can be implemented once there is a static data
+ * product that could be adjusted.
+ */
+ self.clearLookup = function() {
+ };
+
+ //-------------------------------------------------------------------------
+ // Private
+ //-------------------------------------------------------------------------
+ var setZOrder = function() {
+ layer.setZIndex(zIndex);
+ };
+
+ var invalidate = function() {
+ if ( layer ) {
+ var opacity = layer.div.style.opacity;
+ if ( opacity !== "" && opacity < 0.001 ) {
+ layer.setVisibility(false);
+ }
+ }
+ setZOrder();
+ };
+
+ init();
+ return self;
+};
+
+
+wv.map.layers.mock = function() {
+
+ return {
+ setDay: function() {},
+ setOpacity: function() {},
+ setVisibility: function() {},
+ setZIndex: function() {},
+ dispose: function() {},
+ setLookup: function() {},
+ clearLookup: function() {}
+ };
+
+};
+
+
+wv.map.layers.graticule = OpenLayers.Class(OpenLayers.Layer, {
+
+ graticuleLineStyle: null,
+ graticuleLabelStyle: null,
+ graticule: null,
+ isControl: true,
+
+ initialize: function(name, options) {
+ OpenLayers.Layer.prototype.initialize.apply(this, arguments);
+
+ this.graticuleLineStyle = new OpenLayers.Symbolizer.Line({
+ strokeColor: '#AAAAAA',
+ strokeOpacity: 0.95,
+ strokeWidth: 1.35,
+ strokeLinecap: 'square',
+ strokeDashstyle: 'dot'
+ });
+
+ this.graticuleLabelStyle = new OpenLayers.Symbolizer.Text({
+ fontFamily: 'Gill Sans',
+ fontSize: '16',
+ fontWeight: '550',
+ fontColor: '#0000e1',
+ fontOpacity: 1.0
+ });
+ },
+
+ /*
+ * Add the control when the layer is added to the map
+ */
+ setMap: function(map) {
+ OpenLayers.Layer.prototype.setMap.apply(this, arguments);
+
+ this.graticule = new OpenLayers.Control.Graticule({
+ layerName: 'ol_graticule_control',
+ numPoints: 2,
+ labelled: true,
+ lineSymbolizer: this.graticuleLineStyle,
+ labelSymbolizer: this.graticuleLabelStyle
+ });
+
+ map.addControl(this.graticule);
+ },
+
+ /*
+ * Remove the contorl when the layer is removed from the map
+ */
+ removeMap: function(map) {
+ OpenLayers.Layer.prototype.removeMap.apply(this, arguments);
+ map.removeControl(this.graticule);
+ this.graticule.destroy();
+ this.graticule = null;
+ },
+
+ setVisibility: function(value) {
+ if ( !this.granule ) {
+ return;
+ }
+ if ( value ) {
+ this.graticule.activate();
+ } else {
+ this.graticule.deactivate();
+ }
+ },
+
+ /*
+ * Name of this class per OpenLayers convention.
+ */
+ CLASS_NAME: "wv.map.layers.graticule"
+});
+
diff --git a/src/js/map/wv.map.model.js b/src/js/map/wv.map.model.js
new file mode 100644
index 000000000..702b5e82d
--- /dev/null
+++ b/src/js/map/wv.map.model.js
@@ -0,0 +1,159 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+wv.map = wv.map || {};
+
+wv.map.model = wv.map.model || function(models, config) {
+
+ var containerId = "map";
+ var self = {};
+
+ /**
+ * Property: maps
+ * The <maps> that contains the map objects, one for
+ * each projection.
+ */
+ self.maps = null;
+
+ self.selected = null;
+
+ /**
+ * Property: config
+ * The map config object retrieved from the server that
+ * defines the available projections and data products.
+ */
+ self.config = config;
+
+ var init = function() {
+ self.config = validateConfig(self.config);
+ self.maps = wv.map.set(containerId, self.config, self);
+
+ $.each(self.config.layers, function(name, config) {
+ if ( config.defaultLayer === "true" ) {
+ self.maps.append(name);
+ }
+ });
+ setExtentToLeading();
+
+ models.proj.events.on("select", onProjectionSelect);
+ models.layers.events.on("change", onLayersChange);
+ models.date.events.on("select", onDateSelect);
+ models.palettes.events.on("change", onPalettesChange);
+
+ onDateSelect();
+ onProjectionSelect();
+ onLayersChange();
+ onPalettesChange();
+ };
+
+ self.load = function(state, errors) {
+ if ( state.map ) {
+ var map = self.maps.map;
+ // Verify that the viewport extent overlaps the valid extent, if
+ // invalid, just zoom out the max extent
+ var extent = state.map;
+ var intersects = extent.intersectsBounds(map.getExtent());
+ if ( !intersects ) {
+ errors.push({message: "Extent outside of range"});
+ extent = map.getExtent();
+ }
+ self.maps.map.zoomToExtent(extent, true);
+ }
+ };
+
+ self.save = function(state) {
+ state.map = self.maps.map.getExtent().toBBOX();
+ };
+
+ var setExtentToLeading = function() {
+ // Polar projections don't need to be positioned
+ if ( self.maps.projection !== "geographic" ) {
+ return;
+ }
+
+ var map = self.maps.map;
+
+ // Set default extent according to time of day:
+ // at 00:00 UTC, start at far eastern edge of map: "20.6015625,-46.546875,179.9296875,53.015625"
+ // at 23:00 UTC, start at far western edge of map: "-179.9296875,-46.546875,-20.6015625,53.015625"
+ var curHour = wv.util.now().getUTCHours();
+
+ // For earlier hours when data is still being filled in, force a far eastern perspective
+ if (curHour < 3) {
+ curHour = 23;
+ }
+ else if (curHour < 9) {
+ curHour = 0;
+ }
+
+ // Compute east/west bounds
+ var minLon = 20.6015625 + curHour * (-200.53125/23.0);
+ var maxLon = minLon + 159.328125;
+
+ var minLat = -46.546875;
+ var maxLat = 53.015625;
+
+ var lat = minLat + (Math.abs(maxLat - minLat) / 2.0);
+ var lon = minLon + (Math.abs(maxLon - minLon) / 2.0);
+ var zoomLevel = 2;
+
+ map.setCenter(new OpenLayers.LonLat(lon, lat), zoomLevel);
+ };
+
+ var onProjectionSelect = function() {
+ self.maps.setProjection(models.proj.selected.id);
+ self.selected = self.maps.map;
+ onLayersChange();
+ };
+
+ var onLayersChange = function() {
+ var active = models.layers.forProjection();
+ var layers = Array.concat(
+ _.pluck(active.baselayers, "id"),
+ _.pluck(active.overlays, "id")
+ );
+ var visible = models.layers.visible;
+ self.maps.set(layers, visible);
+ };
+
+ var onDateSelect = function() {
+ self.maps.setDay(models.date.selected);
+ };
+
+ var onPalettesChange = function() {
+ self.maps.setPalettes(models.palettes.active);
+ };
+
+ /*
+ * Make sure that all the required parameters exist in the map
+ * configuration.
+ */
+ var validateConfig = function(config) {
+ var root = ["defaults", "projections", "layers"];
+ $.each(root, function(index, key) {
+ if ( !config.hasOwnProperty(key) ) {
+ throw key + " is required in the map configuration";
+ }
+ });
+ var _config = ["projection"];
+ $.each(_config, function(index, key) {
+ if ( !(key in config.defaults ) ) {
+ throw new Error("defaults." + key + " is required for the " +
+ "map configuraiton");
+ }
+ });
+ return config;
+ };
+ init();
+ return self;
+};
+
diff --git a/src/js/Worldview/Scheduler.js b/src/js/map/wv.map.palette.js
similarity index 55%
rename from src/js/Worldview/Scheduler.js
rename to src/js/map/wv.map.palette.js
index f12d4d722..5d3763da6 100644
--- a/src/js/Worldview/Scheduler.js
+++ b/src/js/map/wv.map.palette.js
@@ -4,32 +4,243 @@
* This code was originally developed at NASA/Goddard Space Flight Center for
* the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-/**
- * Class: Worldview.Scheduler
- * Executes jobs in web workers and queues requests if busy.
- *
- * Logger:
- * Worldview.Scheduler
- *
- * Constructor: Scheduler
- * Creates a new instance.
- *
- * Parameters:
- * config.script - The path to the script that contains the code for the
- * web worker. This path should be relative to the application
- * root.
- * config.max - Number of workers to start. Requests up to this number can
- * run concurrently--after this jobs are queued.
- * config.factory - Use this function to create web workers instead of invoking
- * new directly.
- *
- */
-Worldview.Scheduler = function(config) {
+var wv = wv || {};
+wv.map = wv.map || {};
+wv.map.palette = wv.map.palette || {};
+
+wv.map.palette.canvasTile = OpenLayers.Class(OpenLayers.Tile.Image, {
+
+ // Element that contains the canvas to draw the tile. Initially set to
+ // null and created after the tile has been loaded. Set back to null
+ // when clear() is invoked.
+ canvas: null,
+
+ // Canvas that contains the pixels of the original tile. This allows
+ // lookups to be applied multiple times without reloading the layer.
+ canvasOriginal: null,
+
+ // Graphics context for the canvas
+ graphics: null,
+
+ // Graphics context for the canvas containing the original image
+ graphicsOriginal: null,
+
+ // The ID of the last job submitted to the scheduler. If a response
+ // comes back that is not this ID, the tile is stale and can be thrown
+ // out
+ latestJobId: null,
+
+ initialize: function(layer, position, bounds, url, size, options) {
+ // This is required or the browser will throw security exceptions
+ this.crossOriginKeyword = "anonymous";
+ OpenLayers.Tile.Image.prototype.initialize.apply(this, arguments);
+ },
+
+ /*
+ * Discards the canvas.
+ */
+ destroy: function() {
+ OpenLayers.Tile.Image.prototype.destroy.apply(this, arguments);
+ this.clear();
+ if ( this.canvas ) {
+ this.graphics = null;
+ this.canvas = null;
+ this.graphicsOriginal = null;
+ this.canvasOriginal = null;
+ }
+ },
+
+ /*
+ * Hides the canvas element and clears the image load error class if
+ * set.
+ */
+ clear: function() {
+ OpenLayers.Tile.Image.prototype.clear.apply(this, arguments);
+ if ( this.canvas ) {
+ this.canvas.style.visibility = "hidden";
+ this.canvas.style.opacity = 0;
+ OpenLayers.Element.removeClass(this.canvas, "olImageLoadError");
+ }
+ },
+
+ /*
+ * Returns the canvas element by creating one if necessary. Copy over the
+ * style elements that OpenLayers.Tile.Image object applies to the image
+ * element to the canvas element.
+ */
+ getCanvas: function() {
+ var image = this.getImage();
+ var style;
+
+ if ( !this.canvas ) {
+ this.canvas = document.createElement("canvas");
+ this.graphics = this.canvas.getContext("2d");
+ this.canvas.id = "OpenLayers.Tile.Canvas." + this.id;
+ this.canvas.className = "olTileImage";
+
+ style = this.canvas.style;
+ if ( this.frame ) {
+ style.left = image.style.left;
+ style.top = image.style.top;
+ style.width = image.style.width;
+ style.height = image.style.height;
+ }
+ style.visibility = "hidden";
+ style.opacity = 0;
+ style.filter = image.style.filter;
+ style.position = image.style.position;
+ if ( this.frame ) {
+ this.frame.appendChild(self.canvas);
+ }
+ }
+ return this.canvas;
+ },
+
+ /*
+ * Returns the element that contains the canvas.
+ */
+ getTile: function() {
+ var canvas = this.getCanvas();
+ return this.frame ? this.frame : canvas;
+ },
+
+ /*
+ * Relods a tile from the server.
+ */
+ setImgSrc: function() {
+ // If the tile is being reloaded, hide the canvas so that stale
+ // tiles are not visible
+ if ( this.canvas ) {
+ this.canvas.visibility = "hidden";
+ this.canvas.opacity = 0;
+ this.latestJobId = 0;
+ }
+ if ( this.imgDiv ) {
+ OpenLayers.Tile.Image.prototype.setImgSrc.apply(this, arguments);
+ }
+ },
+
+ /*
+ * Takes the loaded image and submits it to the scheduler to render the
+ * color lookup table.
+ */
+ onImageLoad: function() {
+ OpenLayers.Event.stopObservingElement(this.imgDiv);
+
+ // Draw the image that was loaded and save it for anytime a color
+ // lookup needs to be applied
+ this.canvasOriginal = document.createElement("canvas");
+ this.graphicsOriginal = this.canvasOriginal.getContext("2d");
+ this.canvasOriginal.width = this.imgDiv.width;
+ this.canvasOriginal.height = this.imgDiv.height;
+ this.graphicsOriginal.drawImage(this.imgDiv, 0, 0);
+
+ // Ensure the canvas object has been created
+ var canvas = this.getCanvas();
+ canvas.width = this.canvasOriginal.width;
+ canvas.height = this.canvasOriginal.height;
+
+ this.scheduleTile();
+ },
+
+ /**
+ * Function: applyLookup
+ * Changes the lookup table for the tile and repaints the canvas.
+ */
+ applyLookup: function() {
+ if ( !this.canvas ) {
+ return;
+ }
+ this.isLoading = true;
+ this.events.triggerEvent("loadstart");
+ this.scheduleTile();
+ },
+
+ /*
+ * Submit the render operation to the scheduler.
+ */
+ scheduleTile: function() {
+ var lookupTable = this.layer.lookupTable;
+ if ( this.graphicsOriginal === null ) {
+ return;
+ }
+ var source = this.graphicsOriginal.getImageData(0, 0, this.canvas.width,
+ this.canvas.height);
+ var destination = this.graphics.getImageData(0, 0, this.canvas.width,
+ this.canvas.height);
+
+ this.latestJobId = wv.map.tileScheduler().submit({
+ message: {
+ lookupTable: lookupTable,
+ source: source,
+ destination: destination
+ },
+ callback: this.onTileRendered,
+ self: this
+ });
+ },
+
+ /*
+ * Callback for when the tile has finished rendering.
+ */
+ onTileRendered: function(results) {
+ var self = results.self;
+ var canvas = self.canvas;
+
+ // If there is no longer a canvas (a zoom operation cleared it out
+ // for use in the back buffer) or this render is not the last tile
+ // submitted, this data is now stale and can be thrown away.
+ if ( !canvas || results.id !== self.latestJobId ) {
+ // Nothing
+ // If the operation was cancelled during execution, ignore the result.
+ } else if ( results.status === "cancelled" ) {
+ // Nothing
+ // If there was an error during processing, report it here
+ } else if ( results.status === "error" ) {
+ // Nothing
+ // Draw the tile
+ } else if ( results.status === "success" ){
+ var imageData = results.message.destination;
+ self.graphics.putImageData(imageData, 0, 0);
+ canvas.style.visibility = "inherit";
+ canvas.style.opacity = self.layer.opacity;
+ self.canvasContext = null;
+ } else {
+ throw new Error("Invalid status during tile rendering: " +
+ results.status);
+ }
+ self.isLoading = false;
+ self.events.triggerEvent("loadend");
+ },
+
+ /*
+ * This is called during a zoom for the resize transition effect. It
+ * steals away the canvas object for use in the scaled image shown before
+ * tiles are loaded.
+ */
+ createBackBuffer: function() {
+ if ( !this.canvas || this.isLoading ) {
+ return;
+ }
+ var backBuffer = this.canvas;
+ this.canvas = null;
+ return backBuffer;
+ },
+
+ /*
+ * Name of this class per OpenLayers convention.
+ */
+ CLASS_NAME: "wv.map.palette.canvasTile"
+
+});
+
+
+wv.map.palette.scheduler = function(config) {
var self = {};
@@ -300,17 +511,7 @@ Worldview.Scheduler = function(config) {
};
/**
- * Section: Static Functions
- *
- * Function: isSupported
- * Returns true if Worker is defined in the window object.
- */
-Worldview.Scheduler.isSupported = function() {
- return window.Worker !== undefined;
-};
-
-/**
- * Class: Worldview.Scheduler.Stats
+ * Stats
* Contains statistics gathered from the <Scheduler> when <Scheduler.profile>
* is set to true.
*
@@ -343,7 +544,7 @@ Worldview.Scheduler.isSupported = function() {
*/
/**
- * Class: Worldview.Scheduler.Results
+ * Results
* Object that contains information on a completed job.
*
* Property: id
diff --git a/src/js/Worldview/Map/MapSet.js b/src/js/map/wv.map.set.js
similarity index 94%
rename from src/js/Worldview/Map/MapSet.js
rename to src/js/map/wv.map.set.js
index 36d779b3c..dce774702 100644
--- a/src/js/Worldview/Map/MapSet.js
+++ b/src/js/map/wv.map.set.js
@@ -4,30 +4,15 @@
* This code was originally developed at NASA/Goddard Space Flight Center for
* the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-Worldview.namespace("Map");
+var wv = wv || {};
+wv.map = wv.map || {};
-/**
- * Class: Worldview.Map.MapSet
- * Map object that handles GIBS products.
- *
- * Constructor: MapSet
- * Creates a new instance
- *
- * Parameters:
- * containerId - The identifier of the HTML DOM element to add the map objects
- * to.
- * mapConfig - Configuration for the maps and products of type
- * <MapConfig>.
- *
- * Throws:
- * An exception if no DOM element exists with the provided containerId.
- */
-Worldview.Map.MapSet = function(containerId, mapConfig, component) {
+wv.map.set = wv.map.set || function(containerId, mapConfig, component) {
var self = {};
@@ -86,7 +71,7 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
var init = function() {
var $container = $("#" + containerId);
if ( $container.length === 0 ) {
- throw new Error("No container for MapSet: " + containerId);
+ throw new Error("No container for map set: " + containerId);
}
// Create map objects, one for each projection.
@@ -242,10 +227,11 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
* Throws:
* An exception if the product for the given name is not defined.
*/
- self.set = function(requestedLayers, hiddenLayers) {
+ self.set = function(requestedLayers, visibleLayers) {
var newLayers = [];
$.each(requestedLayers, function(index, layer) {
+ var added = false;
if ( $.inArray(layer, self.layers) < 0 ) {
if ( add(layer) ) {
newLayers.push(layer);
@@ -254,7 +240,7 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
newLayers.push(layer);
}
if ( self.map.layerSets[layer] ) {
- if ( $.inArray(layer, hiddenLayers) >= 0 ) {
+ if ( !visibleLayers[layer] ) {
self.setVisibility(layer, false);
} else {
self.setVisibility(layer, true);
@@ -268,6 +254,20 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
});
activeLayers[self.projection] = newLayers;
self.layers = activeLayers[self.projection];
+
+ var seenBaseLayer = false;
+ _.each(self.layers, function(layerId) {
+ if ( !visibleLayers[layerId] ) {
+ return;
+ }
+ var layer = config.layers[layerId];
+ if ( !seenBaseLayer && layer.group === "baselayers" ) {
+ seenBaseLayer = true;
+ } else if ( seenBaseLayer && layer.group === "baselayers" ) {
+ self.setVisibility(layerId, false);
+ }
+ });
+
refreshZOrder();
};
@@ -338,7 +338,6 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
//-------------------------------------------------------------------------
var fireEvent = function() {
- REGISTRY.fire(component);
};
/*
@@ -470,7 +469,7 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
}));
var coordinateControl =
- Worldview.Map.COORDINATE_CONTROLS[projection];
+ wv.map.COORDINATE_CONTROLS[projection];
if ( coordinateControl ) {
controls.push(coordinateControl);
} else {
@@ -493,7 +492,7 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
* any missing defaults, and does any object conversions as needed.
*/
var validateMapConfig = function(config) {
- var config = $.extend(true, config, {});
+ config = $.extend(true, config, {});
config.maxExtent = new OpenLayers.Bounds(config.maxExtent);
config.allOverlays = true;
config.fractionalZoom = false;
@@ -505,14 +504,14 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
*/
var createLayer = function(map, projId, layerId) {
if ( self.mapConfig.parameters.mockMap ) {
- return Worldview.Map.MockLayerSet();
+ return wv.map.layers.mock();
}
config = $.extend(true, {}, mapConfig);
var period = config.layers[layerId].period;
if ( period === "daily" ) {
- return Worldview.Map.DailyLayerSet(map, mapConfig, projId, layerId);
+ return wv.map.layers.daily(map, mapConfig, projId, layerId);
}
- return Worldview.Map.StaticLayerSet(map, mapConfig, projId, layerId);
+ return wv.map.layers.static(map, mapConfig, projId, layerId);
};
var onZoomEnd = function(evt) {
@@ -578,4 +577,4 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
init();
return self;
-};
+};
\ No newline at end of file
diff --git a/src/js/Worldview/Map/TileWorker.js b/src/js/map/wv.map.tileworker.js
similarity index 94%
rename from src/js/Worldview/Map/TileWorker.js
rename to src/js/map/wv.map.tileworker.js
index a1ef7cb19..8aa3f4ede 100644
--- a/src/js/Worldview/Map/TileWorker.js
+++ b/src/js/map/wv.map.tileworker.js
@@ -4,13 +4,12 @@
* This code was originally developed at NASA/Goddard Space Flight Center for
* the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
/**
- * Namespace: Worldview.Map.TileWorker
* Performs the task of applying a color lookup table from a source tile
* to a destination tile.
*
@@ -24,7 +23,6 @@
* - cancel: Cancelles any outstanding work as soon as possible. No message
* object is required.
*
- * Class: Worldview.Map.TileWorker.Execute
* The execute command requires the following object to be found in
* event.data.message
*
@@ -38,6 +36,7 @@
* The taget canvs image data pixels that the new color will be applied ot.
*
*/
+
var cancelled = false;
var execute = function(event) {
@@ -84,4 +83,3 @@ self.addEventListener("message", function(event) {
throw new Error("Invalid command: " + event.data.commmand);
}
}, false);
-
diff --git a/src/js/palettes/wv.palettes.js b/src/js/palettes/wv.palettes.js
index b962bf21f..b1e87d489 100644
--- a/src/js/palettes/wv.palettes.js
+++ b/src/js/palettes/wv.palettes.js
@@ -122,16 +122,50 @@ wv.palettes = (function(self) {
"conf/palettes/" + layer.palette.id + ".json");
};
- self.startup = function(config) {
+ self.parse = function(state, errors, config) {
+ if ( state.palettes ) {
+ var results = {};
+ var parts = state.palettes.split("~");
+ _.each(parts, function(part) {
+ var items = part.split(",");
+ var layerId = items[0];
+ var paletteId = items[1];
+ if ( !config.layers[layerId] ) {
+ errors.push({message: "Invalid layer for palette " +
+ paletteId + ": " + layerId});
+ } else {
+ results[layerId] = paletteId;
+ }
+ });
+ if ( _.size(results) > 0 ) {
+ state.palettes = results;
+ } else {
+ delete state.palettes;
+ }
+ }
+ };
+
+ self.requirements = function(state, config) {
+ var promises = [];
config.palettes = {
rendered: {},
custom: {}
};
- var promise = {};
if ( config.parameters.palettes ) {
- promise = self.loadCustom(config);
+ promises.push(self.loadCustom(config));
+ }
+ _.each(state.products, function(layerId) {
+ if ( config.layers[layerId].palette ) {
+ promises.push(self.loadRendered(config, layerId));
+ }
+ });
+ if ( promises.length > 0 ) {
+ var promise = $.Deferred();
+ $.when.apply(null, promises)
+ .then(promise.resolve)
+ .fail(promise.reject);
+ return promise;
}
- return promise;
};
init();
diff --git a/src/js/palettes/wv.palettes.model.js b/src/js/palettes/wv.palettes.model.js
index 851f7711f..a47cb0e50 100644
--- a/src/js/palettes/wv.palettes.model.js
+++ b/src/js/palettes/wv.palettes.model.js
@@ -39,12 +39,14 @@ wv.palettes.model = wv.palettes.model || function(models, config) {
}
self.active[layerId] = paletteId;
self.events.trigger("add", layerId, self.active[layerId]);
+ self.events.trigger("change");
};
self.remove = function(layerId) {
if ( self.active[layerId] ) {
delete self.active[layerId];
self.events.trigger("remove", layerId);
+ self.events.trigger("change");
}
};
@@ -60,24 +62,24 @@ wv.palettes.model = wv.palettes.model || function(models, config) {
}
};
- self.toPermalink = function() {
+ self.save = function(state) {
var parts = [];
_.each(self.active, function(paletteId, layerId) {
parts.push(layerId + "," + paletteId);
});
- return ( parts.length > 0 ) ? "palettes=" + parts.join("~") : "";
+ if ( parts.length > 0 ) {
+ state.palettes = parts.join("~");
+ }
};
- self.fromPermalink = function(queryString) {
- var query = wv.util.fromQueryString(queryString);
- if ( query.palettes ) {
- var parts = query.palettes.split("~");
- _.each(parts, function(part) {
- var items = part.split(",");
- try {
- self.add(items[0], items[1]);
- } catch ( error ) {
- wv.util.warn(error);
+ self.load = function(state, errors) {
+ if ( state.palettes ) {
+ _.each(state.palettes, function(paletteId, layerId) {
+ if ( !config.palettes.custom[paletteId] ) {
+ errors.push({message: "Invalid palette for layer" +
+ layerId + ": " + paletteId});
+ } else {
+ self.add(layerId, paletteId);
}
});
}
diff --git a/src/js/proj/wv.proj.change.js b/src/js/proj/wv.proj.change.js
index f39212184..c442a081f 100644
--- a/src/js/proj/wv.proj.change.js
+++ b/src/js/proj/wv.proj.change.js
@@ -68,7 +68,7 @@ wv.proj.change = wv.proj.change || function(models) {
self.events.trigger("select", self);
if ( !wasVisited && wasOld !== self.old ) {
checkNotify();
- Worldview.Map.COORDINATE_CONTROLS.arctic.projection = self.crs;
+ wv.map.COORDINATE_CONTROLS.arctic.projection = self.crs;
}
if ( wasOld !== self.old && self.old ) {
diff --git a/src/js/proj/wv.proj.js b/src/js/proj/wv.proj.js
new file mode 100644
index 000000000..098e28c85
--- /dev/null
+++ b/src/js/proj/wv.proj.js
@@ -0,0 +1,29 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+var wv = wv || {};
+
+wv.proj = (function(self) {
+
+ self.parse = function(state, errors, config) {
+ var projId = state["switch"];
+ if ( state["switch"] ) {
+ if ( !config.projections[projId] ) {
+ delete state["switch"];
+ errors.push({message: "Unsupported projection: " + projId});
+ }
+ }
+ };
+
+ return self;
+
+})(wv.proj || {});
+
diff --git a/src/js/proj/wv.proj.model.js b/src/js/proj/wv.proj.model.js
index 3874e8bee..6f07cffbd 100644
--- a/src/js/proj/wv.proj.model.js
+++ b/src/js/proj/wv.proj.model.js
@@ -46,19 +46,14 @@ wv.proj.model = wv.proj.model || function(config) {
return updated;
};
- self.toPermalink = function() {
- return "switch=" + self.selected.id;
+ self.save = function(state) {
+ state["switch"] = self.selected.id;
};
- self.fromPermalink = function(queryString) {
- var query = wv.util.fromQueryString(queryString);
- var id = query.projection || query["switch"];
- if ( id ) {
- if ( !config.projections[id] ) {
- wv.util.warn("Unsupported projection: " + id);
- } else {
- self.select(id);
- }
+ self.load = function(state) {
+ var projId = state["switch"];
+ if ( projId ) {
+ self.select(projId);
}
};
diff --git a/src/js/registry.js b/src/js/registry.js
deleted file mode 100644
index 534be1fe4..000000000
--- a/src/js/registry.js
+++ /dev/null
@@ -1,384 +0,0 @@
-// establish the component namespace
-SOTE.namespace("util");
-// component constructor
-SOTE.util.Registry = function () {
- // holds the components that have registered
- this.compRegistry = new Array();
- // holds events that have been registered
- this.evtRegistry = new Array();
- // holds consumers
- this.consumers = new Array();
- // holds list of component ids that have marked themselves as ready
- this.readyRegistry = new Array();
- // holds array of callbacks for when all components are ready
- this.allReadyCallbacks = new Array();
- // HACK: Components can check this value to ignore bogus state on startup
- this.isLoadingQuery = false;
-
- // Components that have a function to parse query string state.
- this.parsableComponents = {};
-
- // register a component
- this.register = function register(id,component){
- var compObj = new ComponentObj(id,component);
- this.storeComponent( id, compObj );
- if ( typeof component.parse === "function" ) {
- this.parsableComponents[id] = component;
- }
- }
-
- // registry component object - this is what is actually held in compRegistry
- function ComponentObj(id,obj){
- this.name = id;
- this.obj = obj;
- return this;
- }
-
- function ConsumerProducerPair(cid,pid){
- this.consumerId = cid;
- this.producerId = pid;
- return this;
- }
-
- // add a listener pair - producer and consumer; can have multiple consumers
- this.addEventListener = function addEventListener(producerId, consumerId){
- if(consumerId != null || consumerId != 'undefined' || consumerId != ""){
- for(var i=1;i<arguments.length;i++){
- var evtObj = new ComponentUpdateObj(producerId,arguments[i]);
- var consObj = new Consumer(arguments[i], evtObj);
- //alert("Registry: storing: producer: "+producerId+", event object name: "+evtObj.name+", consumer: "+arguments[i]);
- this.storeEvent(producerId,evtObj);
-
- this.consumers.push(new ConsumerProducerPair(arguments[i],producerId));
- }
- }
- }
- // store an event in evtRegistry
- this.storeEvent = function storeEvent(name,evtObj){
- //var eo;
- //for(var i=0;i<this.evtRegistry.length;i++){
- // eo = this.evtRegistry[i];
- // if( name == eo.name ){
- // this.evtRegistry.splice(i,1);
- // break;
- // }
- //}
- this.evtRegistry.push(evtObj);
- }
- // get an event from evtRegistry given a producer id
- this.getEvents = function getEvents(id){
- var eoA = new Array();
- for(var i=0;i<this.evtRegistry.length;i++){
- if( id == this.evtRegistry[i].name ){
- //alert("Registry: getEvent: id: "+id+" eo.name: "+this.evtRegistry[i].name);
- eoA.push( this.evtRegistry[i] );
- }
- }
- return eoA;
- }
- // fire an event
- this.fire = function fire(comp,noFireVal){
- if(noFireVal == null){
- noFireVal = "xxx";
- }
- if(comp != null){
- var evtObjA = this.getEvents(this.getComponentId(comp));
- if(evtObjA.length > 0){
- //alert("Registry: fire: comp val: "+comp.getValue());
- var consumers = new Array();
- for(var i=0;i<evtObjA.length;i++){
- consumers = this.getConsumers( evtObjA[i].consumerId );
- //if(i==0){ alert("consumer: "+evtObjA[i].consumerId+", consumers len: "+consumers.length); }
- var recursive = "";
- for(var j=0;j<consumers.length;j++){
- //if(i==0){ alert("consumer "+j+": "+consumers[j]); }
- if(consumers[j] == this.getComponentId(comp)){
- recursive = consumers[j];
- //delete consumers[j];
- break;
- }
- }
- if(evtObjA[i].consumerId != noFireVal && evtObjA[i].consumerId != recursive){
- if(recursive.length > 0){
- evtObjA[i].componentUpdate.fire(comp.getValue()+"&norecurse="+recursive);
- }else{
- evtObjA[i].componentUpdate.fire(comp.getValue());
- }
- }
- }
- }
- }else{
- alert("Registry: fire: comp is null");
- }
- }
-
- this.syncComponents = function() {
- // get the components
- var comps = this.getComponents();
- // determine which are producers
- var producers = new Array();
- var tmpA;
- for(var i=0;i<comps.length;i++){
- tmpA = this.getProducers(comps[i].id);
- if(tmpA.length > 0){
- producers = producers.concat(tmpA);
- }
- }
- //SOTE.util.uniqueArray(producers);
- for(var i=0;i<producers.length;i++){
- this.fire(this.getComponent(producers[i]));
- }
- }
-
- // given a consumer, find it's dependencies, gather the components that are supposed to update
- // and pass back their 'getValue's to the fire event
- this.getDependentValues = function (consumerId,producerId){
- // foreach consumerid, find it's producerids, get the components and get their values
- //alert("Registry: getDependentValues: consumerId: "+consumerId+", producerId: "+producerId);
- var val = "";
- for(var i=0;i<this.consumers.length;i++){
- if(this.consumers[i].consumerId == consumerId && this.consumers[i].producerId != producerId){
- val += this.getComponent(this.consumers[i].producerId).getValue() + "&";
- }
- }
- val = val.substring(0,val.length - 1);
- //alert("getDependenValues: cid: "+consumerId+", pid: "+producerId+", values: "+val);
- return val;
- }
-
- // custom event object
- function ComponentUpdateObj(name,consumerId) {
- // producer id/name
- this.name = name;
- // consumer id
- this.consumerId = consumerId;
- // define a custom event
- this.componentUpdate = new YAHOO.util.CustomEvent("componentUpdate", this);
- return this;
- }
-
- // an object that consumes "componentUpdate" events
- function Consumer(name, evtObj) {
- // consumer id/name
- this.name = name;
- // evtObj associated with producer
- this.evtObj = evtObj;
- this.evtObj.componentUpdate.subscribe(this.onComponentUpdate, this);
- return this;
- }
-
- // the callback of the 'fire' (componentUpdate, really) method
- Consumer.prototype.onComponentUpdate = function(type, args, me) {
-
- //alert(" "+
- // "\n this: " + this.name +
- // "\n producer event name (type): " + type +
- // "\n data: " + args +
- // "\n event obj name: "+ me.evtObj.name +
- // "\n me.name: " + me.name.id);
-
- //alert("Registry: onComponentUpdate: producer: "+this.name+" consumer: "+me.name+", args for the update: "+args);
-
- // are there other producers for this consumer?
- var additionalValues = getRegistryDependentValues(me.name, this.name);
- if(additionalValues != ""){
- args = args + "&" + additionalValues;
- } else {
- // HACK: args here is actually an array. The line above converts to
- // string if there are additionalValues. If not, follow the same
- // trick.
- args = args + "";
- }
- // get physical comp and do the update
- var comp = getGComponent(me.name);
- if(comp != null){
- comp.updateComponent(args);
- }
- }
-
- // add a consumer to consumers
- this.addConsumer = function addConsumer(consumer){
- var co;
- for(var i=0;i<this.consumers.length;i++){
- co = this.consumers[i];
- if( consumer.id == co.id ){
- this.consumers.splice(i,1);
- break;
- }
- }
- this.consumers.push(consumer);
- }
- // get a consumer object from consumers
- this.getConsumer = function getConsumer(id){
- var co;
- for(var i=0;i<this.consumers.length;i++){
- co = this.consumers[i];
- if( id == co.id ){
- break;
- }
- }
- return co;
- }
-
-
- // store a registry component object in compRegistry
- this.storeComponent = function storeComponent(name,comp) {
- var co;
- for(var i=0;i<this.compRegistry.length;i++){
- co = this.compRegistry[i];
- if( name == co.name ){
- this.compRegistry.splice(i,1);
- break;
- }
- }
- this.compRegistry.push(comp);
- }
-
- // get a registry component object from compRegistry given an id
- this.getComponent = function getComponent(id) {
- var co;
- for(var i=0;i<this.compRegistry.length;i++){
- co = this.compRegistry[i];
- if( id == co.name ){
- break;
- }
- }
- return co.obj;
- }
-
- // get the component id for the component registered in compRegistry
- this.getComponentId = function getComponentId(obj) {
- var co;
- for(var i=0;i<this.compRegistry.length;i++){
- co = this.compRegistry[i];
- if( obj == co.obj ){
- break;
- }
- }
- return co.name;
- }
-
- // get all of the components in compRegistry
- this.getComponents = function getComponents() {
- var coA = new Array();
- for(var i=0;i<this.compRegistry.length;i++){
- coA.push(this.compRegistry[i]);
- }
- return coA;
- }
-
-// Checks that all components are ready and fires off the callbacks if the are.
- this.checkComponentsReady = function checkComponentsReady() {
- // Determine if every registered components has marked themselves as ready
- // Essentially, see if relevant components are a subset of readyRegistry.
- var allReady = true;
- var comps = this.getComponents();
- for (var i=0; i < comps.length; i++) {
- if (comps[i].obj.loadFromQuery == undefined)
- continue; // not considered
-
- // see if comps[i].name is in readyRegistry.
- var found = false;
- for (var j=0; j < this.readyRegistry.length; j++) {
- if (this.readyRegistry[j] == comps[i].name) {
- found = true;
- }
- }
-
- if (!found) {
- allReady = false;
- break;
- }
- }
-
- // Call all callbacks if all components ready
- if (allReady) {
- for (var i=0; i < this.allReadyCallbacks.length; i++) {
- var callback = this.allReadyCallbacks[i];
- callback();
- }
- }
- }
-
- // Adds a callback function to be called once all components are ready.
- this.addAllReadyCallback = function addAllReadyCallback(callback) {
- this.allReadyCallbacks.push(callback);
- this.checkComponentsReady(); // just in case all were marked before callback added
- }
-
- // Method for registered components to call when they are ready.
- this.markComponentReady = function markComponentReady(id) {
- this.readyRegistry.push(id);
- this.checkComponentsReady(); // will check make necessary action if so
- }
-
- // get all of the user interface (selection) components in compRegistry
- this.getUIComponents = function getUIComponents() {
- var rawA = this.getComponents();
- var coA = new Array();
- for(var i=0;i<rawA.length;i++){
- if(rawA[i].obj.loadFromQuery){
- coA.push(rawA[i].obj);
- }
- }
- return coA;
- }
-
- this.getProducers = function getProducers(consumerId) {
- var producers = new Array();
- for(var i=0;i<this.consumers.length;i++){
- if(this.consumers[i].consumerId == consumerId){
- producers.push(this.consumers[i].producerId);
- }
- }
- return producers;
- }
-
- this.getConsumers = function getConsumers(producerId) {
- var consumers = new Array();
- for(var i=0;i<this.consumers.length;i++){
- if(this.consumers[i].producerId == producerId){
- consumers.push(this.consumers[i].consumerId);
- }
- }
- return consumers;
- }
-
- this.getState = function(queryString) {
- if ( !queryString ) {
- var queryParts = [];
- $.each(this.getComponents(), function(index, component) {
- var part = component.obj.getValue();
- if ( part ) {
- queryParts.push(part);
- }
- });
- queryString = queryParts.join("&");
- }
-
- var state = {
- components: {}
- };
- $.each(this.parsableComponents, function(name, component) {
- state.components[name] = component;
- component.parse(queryString, state);
- });
- return state;
- };
-
-};
-
-// globally exposed instance of this class
-var REGISTRY = new SOTE.util.Registry();
-
-// an external function for getting components; useful in event methods
-function getGComponent(id){
- return REGISTRY.getComponent(id);
-}
-
-function getRegistryDependentValues(cid,pid){
- // get the producers for the given consumer (except for the one passed in)
- // and get the values
- return REGISTRY.getDependentValues(cid,pid);
-}
-
diff --git a/src/js/rubberBand.js b/src/js/rubberBand.js
deleted file mode 100644
index d259881ff..000000000
--- a/src/js/rubberBand.js
+++ /dev/null
@@ -1,284 +0,0 @@
-SOTE.namespace("SOTE.widget.RubberBand");
-
-
-/**
- * A "rubberband" tool class. Uses the JCrop library.
- */
-
-SOTE.widget.RubberBand = function (containerId, config){
- this.PALETTE_WARNING =
- "Image download does not yet support the custom palette(s) that you " +
- "have applied. Would you like to continue with the default color palette(s)?";
-
- this.container=document.getElementById(containerId);
- this.coords = null;
- this.previousCoords = null;
-
- if (this.container==null){
- this.setStatus("Error: element '"+containerId+"' not found!",true);
- return;
- }
-
- if(config===undefined) {
- config={};
- }
- this.icon = config.icon;
- this.onicon = config.onicon;
- this.cropee = config.cropee;
- this.projectionSwitch="geographic";
- this.id = containerId;
- this.state = "off";
- this.jcropAPI = null;
- this.mapWidget = config.mapWidget;
- this.paletteWidget = config.paletteWidget;
- this.previousPalettes = "";
- this.currentPalettes = "";
- //this.windowURL = "";
-
- this.init();
-};
-
-
-SOTE.widget.RubberBand.prototype = new SOTE.widget.Component;
-
-/**
- * Initializes the RubberBand component.
- *
- * @this {RubberBand}
- * @requires SOTE.widget.Map
-*/
-SOTE.widget.RubberBand.prototype.init = function(){
- this.container.setAttribute("class","rubberband");
-
- this.container.innerHTML = "<a id='"+this.id+"camera_link' class='toolbar-link' title='Take a snapshot'><img src='"+this.icon+"' /></a>";
- $('#'+this.id+"camera_link").bind('click',{self:this},SOTE.widget.RubberBand.toggle);
-
- if(REGISTRY){
- REGISTRY.register(this.id,this);
- REGISTRY.markComponentReady(this.id);
- }
- else{
- alert("No REGISTRY found! Cannot register Rubber Band!");
- }
-};
-
-SOTE.widget.RubberBand.toggle = function(o){
- var self = o.data.self;
- var toggleOn = function() {
- self.state = "on";
- $("#"+self.id+"camera_link img").attr("src",self.onicon);
- $("#imagedownload").show('slide', {direction: 'up'}, 1000);
- self.draw();
- };
-
- // When disabling the palettes, we need to wait for the map to reload all
- // the tiles before enabling the crop box. The crop box copies all
- // elements in the map to do its background effect and if the map isn't
- // ready yet, it will copy blank images.
- var disablePalettes = function() {
- var map = self.mapWidget.maps.map;
- var handler = function() {
- map.events.unregister("maploadend", map, handler);
- toggleOn();
- };
- map.events.register("maploadend", map, handler);
-
- // Save the previous state to be restored later
- self.previousPalettes = self.currentPalettes;
- self.paletteWidget.noRestore = true;
- self.paletteWidget.setValue("");
- };
-
- if(self.state == "off") { // && self.projectionSwitch == "geographic"){
- // Confirm with the user they want to continue, and if so, disable
- // the palettes before bringing up the crop box.
- if (self.currentPalettes) {
- Worldview.ask({
- header: "Notice",
- message: self.PALETTE_WARNING,
- onOk: disablePalettes
- });
- } else {
- toggleOn();
- }
- }
- else { //}(self.projectionSwitch == "geographic"){
- self.state = "off";
- $("#"+self.id+"camera_link img").attr("src",self.icon);
- self.jcropAPI.destroy();
- $("#imagedownload").hide('slide', {direction: 'up'}, 1000);
- if (self.previousPalettes) {
- self.paletteWidget.noResture = false;
- self.paletteWidget.setValue(self.previousPalettes);
- }
- }
- /*else {
- SOTE.util.throwError("The download feature is currently available for geographic projection only.");
- }*/
-};
-
-/**
- * Sets the values for the rubberband (x1, y1, x2, y2, width, height) from the passed "coordinates" object of JCrop *
- * @this {RBand}
- * @param {String} coordinates object of JCrop
- *
-*/
-SOTE.widget.RubberBand.prototype.setValue = function(c) {
- this.previousCoords = this.coords;
- this.coords = c;
- this.fire();
-};
-
-/**
- * Gets the JCrop coordinates object, which holds the current rubberband box's x,y,x2,y2,height, width values.
- * @this {RBand}
- * @returns {String} an object containing the x,y,x2,y2, width, and height values for the rubberband.
- *
-*/
-SOTE.widget.RubberBand.prototype.getValue = function() {
- if(this.coords){
- var returnVal = this.id + "=" + this.coords.x+","+this.coords.y+","+this.coords.x2+","+this.coords.y2+","+this.coords.w+","+this.coords.h;
- return returnVal;
- }
- else {
- return;
- }
-};
-
-/**
- * Modify the component based on dependencies
- *
- * @this {RBand}
- * @param {String} querystring contains all values of dependencies (from registry)
- * @returns {boolean} true or false depending on if the selected date validates against the updated criteria
- *
-*/
-SOTE.widget.RubberBand.prototype.updateComponent = function(qs){
- var query = wv.util.fromQueryString(qs);
- this.projectionSwitch = query["switch"];
- this.currentPalettes = query.palettes || "";
-};
-
-/**
- * Sets the selected date from the querystring, [containerId]=[selectedDate]
- *
- * @this {RBand}
- * @param {String} qs contains the querystring (must contain [containerId]=[selectedDate] in the string)
- * @returns {boolean} true or false depending on if the extracted date validates
- *
-*/
-SOTE.widget.RubberBand.prototype.loadFromQuery = function(qs){
-};
-
-/**
- * Validates
- *
- * @this {RBand}
- * @returns {boolean} true or false depending on whether the date is not null and within bounds
-*/
-SOTE.widget.RubberBand.prototype.validate = function(){
- // Content
-};
-
-/**
- * Sets the accessor that provides state change instructions given dependencies
- *
- * @this {RBand}
- * @param {String} sourceurl is the relative location of the accessor
- *
-*/
-SOTE.widget.RubberBand.prototype.setSourceUrl = function(sourceurl){
- // Content
-};
-
-/**
- * Gets the accessor
- *
- * @this {RBand}
- * @returns {String} the relative location of the accessor
- *
-*/
-SOTE.widget.RubberBand.prototype.getSourceUrl = function(){
- // Content
-};
-
-/**
- * Sets the status of the component
- *
- * @this {RBand}
- * @param {String} s the current status of the component (user prompts, error messages)
- *
-*/
-SOTE.widget.RubberBand.prototype.setStatus = function(s){
- // Content
-};
-
-/**
- * Gets the status of the component
- *
- * @this {RBand}
- * @returns {String} the current status of the component (user prompts, error messages)
- *
-*/
-SOTE.widget.RubberBand.prototype.getStatus = function(){
-
-};
-
-/**
- * Activates the drawing on the map.
- *
- * @this {RBand}
- *
- *
-*/
-SOTE.widget.RubberBand.prototype.draw = function() {
-
- var self = this;
-
- $("#"+this.cropee).Jcrop({
- bgColor: 'black',
- bgOpacity: 0.3,
- onSelect: function(c){self.previousCoords=self.coords;SOTE.widget.RubberBand.handleChange(c, self);},
- onChange: function(c){SOTE.widget.RubberBand.handleChange(c, self);},
- onRelease: function(c){ self.coords=self.previousCoords; SOTE.widget.RubberBand.toggle({data: {self:self} }); },
- fullScreen: true
- });
-
- this.jcropAPI = $('#'+this.cropee).data('Jcrop');
-
- if(this.coords) {
- this.jcropAPI.setSelect([this.coords.x, this.coords.y,this.coords.x2,this.coords.y2]);
- }
- else {
- this.jcropAPI.setSelect([($(window).width()/2)-100,($(window).height()/2)-100,($(window).width()/2)+100,($(window).height()/2)+100]);
- }
-
-};
-
-
-SOTE.widget.RubberBand.handleChange = function(c, self){
-
- self.setValue(c);
-
-
-};
-
-
-/**
- * Fires an event in the registry when the component value is changed
- */
-
-SOTE.widget.RubberBand.prototype.fire = function(){
-
- if(REGISTRY){
- REGISTRY.fire(this);
- }
- else{
- alert("No REGISTRY found! Cannot fire to REGISTRY from Map!");
- }
-
-};
-
-
-
-
diff --git a/src/js/ui/wv.ui.js b/src/js/ui/wv.ui.js
index 906592a74..41fb5aef2 100644
--- a/src/js/ui/wv.ui.js
+++ b/src/js/ui/wv.ui.js
@@ -92,6 +92,76 @@ wv.ui = (function(self) {
}
};
+ /**
+ * Asks the end user a yes or no question in a dialog box.
+ *
+ * @method ask
+ * @static
+ *
+ * @param [spec.header="Notice"] {string} Header text to be displayed in
+ * the dialog box.
+ *
+ * @param [spec.message="Are you sure?"] {string} Message text to be
+ * displayed in the dialog box.
+ *
+ * @param [spec.okButton="OK"] {string} Text to be used in the no button.
+ *
+ * @param [spec.cancelButton="Cancel"] {string} Text to be used in the yes
+ * button.
+ *
+ * @param [spec.onOk] {function} Function to execute when the OK button is
+ * pressed. If not specified, the dialog box simply closes.
+ *
+ * @parma [spec.onCancel] {function} Function to execute when the Cancel
+ * button is pressed. If not specified, the dialog box simply closes.
+ */
+ self.ask = function(spec) {
+ var dialog = new YAHOO.widget.SimpleDialog("dialog", {
+ width: "20em",
+ effect: {
+ effect: YAHOO.widget.ContainerEffect.FADE,
+ duration: 0.25
+ },
+ fixedcenter: true,
+ modal: true,
+ visible: false,
+ draggable: false
+ });
+
+ var header = spec.header || "Notice";
+ dialog.setHeader(header);
+ dialog.setBody(spec.message || "Are you sure?");
+
+ var handleOk = function() {
+ try {
+ this.hide();
+ if ( spec.onOk) {
+ spec.onOk();
+ }
+ } catch ( error ) {
+ wv.util.error(error);
+ }
+ };
+ var handleCancel = function() {
+ try {
+ this.hide();
+ if ( spec.onCancel ) {
+ spec.onCancel();
+ }
+ } catch ( error ) {
+ wv.util.error(error);
+ }
+ };
+
+ var buttons = [
+ { text: spec.cancelButton || "Cancel", handler: handleCancel },
+ { text: spec.okButton || "OK", handler: handleOk }
+ ];
+ dialog.cfg.queueProperty("buttons", buttons);
+ dialog.render(document.body);
+ dialog.show();
+ };
+
/**
* Displays a message to the end user that the feature is not supported
* in this web browser.
diff --git a/src/js/wv.main.js b/src/js/wv.main.js
index 344df1f67..44bd52ce9 100644
--- a/src/js/wv.main.js
+++ b/src/js/wv.main.js
@@ -12,24 +12,43 @@
$(function() {
var config;
+ var state = wv.util.fromQueryString(location.search);
var parameters = wv.util.fromQueryString(location.search);
+ var errors = [];
var main = function() {
var configURI = wv.brand.url("conf/wv.json");
var promise = $.getJSON(configURI)
- .done(wv.util.wrap(load))
+ .done(wv.util.wrap(onConfigLoaded))
.error(wv.util.error);
wv.ui.indicator.delayed(promise, 2000);
};
- var load = function(c) {
- config = c;
+ var onConfigLoaded = function(data) {
+ config = data;
config.parameters = parameters;
// Export for debugging
wv.config = config;
- $.when(wv.palettes.startup(config))
+ parsers = [
+ wv.proj.parse,
+ wv.layers.parse,
+ wv.date.parse,
+ wv.palettes.parse,
+ wv.data.parse,
+ wv.map.parse
+ ];
+
+ _.each(parsers, function(parser) {
+ parser(state, errors, config);
+ });
+
+ requirements = [
+ wv.palettes.requirements(state, config)
+ ];
+
+ $.when.apply(null, requirements)
.then(wv.util.wrap(init))
.fail(wv.util.error);
};
@@ -69,70 +88,34 @@ $(function() {
.on("update", updateDateRange);
updateDateRange();
- // Legacy REGISTRY based widgets
- var legacySwitch = wv.legacy.switch_(models.proj);
- var legacyBank = wv.legacy.bank(models.layers);
- var legacyDate = wv.legacy.date(models.date);
- var legacyPalettes = wv.legacy.palettes(models.palettes);
- var map = Worldview.Widget.WorldviewMap("map", config);
-
- var mapBridge = {
- fromPermalink: function(queryString) {
- map.loadFromQuery(queryString);
- },
- toPermalink: function() {
- return map.getValue();
- }
- };
models.link
.register(models.proj)
.register(models.layers)
.register(models.date)
- .register(mapBridge)
.register(models.palettes)
.register(models.data);
- models.link.load();
+ models.link.load(state);
models.proj.change = wv.proj.change(models);
+ // Map is special as it actually creates UI components.
+ models.map = wv.map.model(models, config);
+ models.link.register(models.map);
+ models.map.load(state, errors);
+
// Create widgets
var ui = {};
- ui.proj = wv.proj.ui(models);
+ ui.proj = wv.proj.ui(models);
ui.sidebar = wv.layers.sidebar(models);
ui.activeLayers = wv.layers.active(models, config);
ui.addLayers = wv.layers.add(models, config);
ui.dateSliders = wv.date.sliders(models, config);
ui.dateLabel = wv.date.label(models);
ui.dateWheels = wv.date.wheels(models, config);
- var rubberBand = new SOTE.widget.RubberBand("camera", {
- icon: "images/camera.png",
- onicon: "images/cameraon.png",
- cropee: "map",
- mapWidget: map
- });
- var imageDownload = new SOTE.widget.ImageDownload("imagedownload", {
- baseLayer: "MODIS_Terra_CorrectedReflectance_TrueColor",
- alignTo: rubberBand,
- m: map,
- config: config
- });
-
- // collapse events if worldview is being loaded via permalink
- if(window.location.search) {
- eventsCollapsed = true;
- }
- /*
- var events = new SOTE.widget.Events("eventsHolder", {
- config: config,
- models: models,
- maps: map.maps,
- shouldCollapse: eventsCollapsed,
- lastVisit: lastVisitObj
- });
- */
+ ui.rubberband = wv.image.rubberband(models, config);
+ ui.image = wv.image.panel(models, ui, config);
ui.data = wv.data.ui(models, config, map.maps);
ui.data.render();
-
ui.link = wv.link.ui(models);
$(window).resize(function() {
@@ -155,9 +138,9 @@ $(function() {
ui.sidebar.selectTab("download");
})
.on("queryResults", function() {
- ui.data.onViewChange(map.maps.map);
+ ui.data.onViewChange(models.map.selected);
});
- map.maps.events
+ models.map.maps.events
.on("moveEnd", function(map) {
ui.data.onViewChange(map);
})
@@ -165,21 +148,6 @@ $(function() {
ui.data.onViewChange(map);
});
- // Register event listeners
- REGISTRY.addEventListener("map", "imagedownload");
- REGISTRY.addEventListener("time",
- "map", "imagedownload",
- ui.data.containerId);
- REGISTRY.addEventListener("switch",
- "map", "products", "selectorbox", "imagedownload", "camera",
- ui.data.containerId);
- REGISTRY.addEventListener("products",
- "map", "selectorbox", "imagedownload", "palettes",
- ui.data.containerId);
- REGISTRY.addEventListener("selectorbox","products");
- REGISTRY.addEventListener("camera","imagedownload");
- REGISTRY.addEventListener("palettes","map","camera","products");
-
// Console notifications
if ( wv.brand.release() ) {
console.info(wv.brand.NAME + " - Version " + wv.brand.VERSION +
@@ -190,6 +158,10 @@ $(function() {
wv.debug.gibs(ui, models, config);
wv.tour.introduction();
+ _.each(errors, function(error) {
+ var cause = ( error.cause ) ? ": " + error.cause : "";
+ wv.util.warn(error.message + cause);
+ });
models.wv.events.trigger("startup");
};
@@ -209,7 +181,7 @@ $(function() {
// Test error dialog
if ( config.parameters.showError ) {
- Worldview.error("No error -- this is a test");
+ *** SHOW ERROR
}
};
*/
diff --git a/test/data/wv.data-test.js b/test/data/wv.data-test.js
new file mode 100644
index 000000000..3360271a0
--- /dev/null
+++ b/test/data/wv.data-test.js
@@ -0,0 +1,39 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+buster.testCase("wv.data", {
+
+ config: null,
+ errors: null,
+
+ setUp: function() {
+ this.config = {
+ products: {
+ "product1": {}
+ }
+ };
+ this.errors = [];
+ },
+
+ "Parses state": function() {
+ var state = { dataDownload: "product1" };
+ wv.data.parse(state, this.errors, this.config);
+ buster.assert.equals(state.dataDownload, "product1");
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Error on an invalid product": function() {
+ var state = { dataDownload: "productX" };
+ wv.data.parse(state, this.errors, this.config);
+ buster.refute(state.dataDownload);
+ buster.assert.equals(this.errors.length, 1);
+ }
+});
diff --git a/test/data/wv.data.model-test.js b/test/data/wv.data.model-test.js
index b5ed2fe49..8f40f05eb 100644
--- a/test/data/wv.data.model-test.js
+++ b/test/data/wv.data.model-test.js
@@ -31,15 +31,19 @@ buster.testCase("wv.data.model", {
this.model = wv.data.model(this.models, this.config);
},
- "No permalink when not active": function() {
- buster.refute(this.model.toPermalink());
+ "Doesn't save state when not active": function() {
+ this.model.selectProduct("product1");
+ var state = {};
+ this.model.save(state);
+ buster.refute(state.dataDownload);
},
- "To permalink": function() {
+ "Saves state": function() {
this.model.active = true;
this.model.selectedProduct = "product1";
- buster.assert.equals(this.model.toPermalink(),
- "dataDownload=product1");
+ var state = {};
+ this.model.save(state);
+ buster.assert.equals(state.dataDownload, "product1");
},
"Subscribed for startup event when data download in permalink": function() {
@@ -48,7 +52,8 @@ buster.testCase("wv.data.model", {
on: this.stub()
}
};
- this.model.fromPermalink("dataDownload=product1");
+ var state = { dataDownload: "product1" };
+ this.model.load(state);
buster.assert.calledWith(this.models.wv.events.on, "startup");
}
diff --git a/test/date/wv.date-test.js b/test/date/wv.date-test.js
new file mode 100644
index 000000000..6eebed25b
--- /dev/null
+++ b/test/date/wv.date-test.js
@@ -0,0 +1,49 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+buster.testCase("wv.date", {
+
+ "Parses valid date": function() {
+ var d = new Date(Date.UTC(2013, 0, 5));
+ var state = { time: "2013-01-05" };
+ var errors = [];
+ wv.date.parse(state, errors);
+ buster.assert.equals(state.time, d);
+ buster.assert.equals(errors.length, 0);
+ },
+
+ "Error added if date is invalid": function() {
+ var state = { time: "X" };
+ var errors = [];
+ wv.date.parse(state, errors);
+ buster.assert.equals(errors.length, 1);
+ buster.refute(state.time);
+ },
+
+ "Parses valid now": function() {
+ var d = new Date(Date.UTC(2013, 0, 5));
+ var state = { now: "2013-01-05" };
+ var errors = [];
+ wv.date.parse(state, errors);
+ buster.assert.equals(state.now, d);
+ buster.assert.equals(errors.length, 0);
+ },
+
+ "Error added if now is invalid": function() {
+ var state = { now: "X" };
+ var errors = [];
+ wv.date.parse(state, errors);
+ buster.assert.equals(errors.length, 1);
+ buster.refute(state.now);
+ }
+
+});
+
diff --git a/test/date/wv.date.model-test.js b/test/date/wv.date.model-test.js
index beaca279b..a88eb0c3f 100644
--- a/test/date/wv.date.model-test.js
+++ b/test/date/wv.date.model-test.js
@@ -64,32 +64,27 @@ buster.testCase("wv.date.model", {
"2012-01-31");
},
- "To permalink": function() {
+ "Saves state": function() {
var d = new Date(Date.UTC(2013, 0, 5));
var date = wv.date.model(this.config);
date.select(d);
- buster.assert.equals(date.toPermalink(), "time=2013-01-05");
+ var state = {};
+ date.save(state);
+ buster.assert.equals(state.time, "2013-01-05");
},
- "From valid permalink": function() {
- var d = new Date(Date.UTC(2013, 0, 5));
- var date = wv.date.model(this.config);
- date.fromPermalink("time=2013-01-05");
- buster.assert.equals(date.selected, d);
- },
-
- "Not selected when time is not in permalink": function() {
- var date = wv.date.model(this.config);
- date.fromPermalink("foo=2013-01-05");
- buster.assert.equals(date.selected, this.now);
+ "Loads state": function() {
+ var date = new Date(Date.UTC(2013, 0, 5));
+ var model = wv.date.model(this.config);
+ var state = { time: date };
+ model.load(state);
+ buster.assert.equals(model.selected, date);
},
- "Warning emitted when time is invalid": function() {
- var date = wv.date.model(this.config);
- this.stub(wv.util, "warn");
- date.fromPermalink("time=X");
- buster.assert.equals(date.selected, this.now);
- buster.assert.calledOnce(wv.util.warn);
+ "Nothing selected when missing in state": function() {
+ var model = wv.date.model(this.config);
+ model.load({});
+ buster.assert.equals(model.selected, this.now);
},
"Start/End times set to null if range is null": function() {
diff --git a/test/layers/wv.layers-test.js b/test/layers/wv.layers-test.js
new file mode 100644
index 000000000..c79c3ba59
--- /dev/null
+++ b/test/layers/wv.layers-test.js
@@ -0,0 +1,88 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+buster.testCase("wv.layers", {
+
+ config: null,
+ errors: null,
+
+ setUp: function() {
+ this.config = {
+ layers: {
+ "layer1": {},
+ "layer2": {},
+ "layer3": {}
+ }
+ };
+ this.errors = [];
+ },
+
+ "Parses only one baselayer": function() {
+ var state = { products: "baselayers,layer1" };
+ wv.layers.parse(state, this.errors, this.config);
+ buster.assert.equals(state.products[0], "layer1");
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Parses only one overlay": function() {
+ var state = { products: "overlays,layer1" };
+ wv.layers.parse(state, this.errors, this.config);
+ buster.assert.equals(state.products[0], "layer1");
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Parses multiple layers": function() {
+ var state = { products: "baselayers,layer1~overlays,layer2,layer3" };
+ wv.layers.parse(state, this.errors, this.config);
+ // Reverse order
+ buster.assert.equals(state.products[0], "layer3");
+ buster.assert.equals(state.products[1], "layer2");
+ buster.assert.equals(state.products[2], "layer1");
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Skips invalid layers and records an error": function () {
+ var state = { products: "baselayers,layer1~overlays,layerx,layer3" };
+ wv.layers.parse(state, this.errors, this.config);
+ // Reverse order
+ buster.assert.equals(state.products[0], "layer3");
+ buster.assert.equals(state.products[1], "layer1");
+ buster.assert.equals(this.errors.length, 1);
+ },
+
+ "No layers if all invalid": function() {
+ var state = { products: "layerx" };
+ wv.layers.parse(state, this.errors, this.config);
+ buster.refute(state.products);
+ },
+
+ "Hidden layers": function() {
+ var state = { products: "!layer1" };
+ wv.layers.parse(state, this.errors, this.config);
+ // Reverse order
+ buster.assert.equals(state.products[0], "layer1");
+ buster.assert(state.hidden.layer1);
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Layer redirects": function() {
+ this.config.redirects = {
+ layers: {
+ layer1: "layer3"
+ }
+ };
+ var state = { products: "layer1" };
+ wv.layers.parse(state, this.errors, this.config);
+ buster.assert.equals(state.products[0], "layer3");
+ buster.assert.equals(this.errors.length, 0);
+ }
+
+});
diff --git a/test/layers/wv.layers.model-test.js b/test/layers/wv.layers.model-test.js
index 51d5bb7ed..8c9edf7c0 100644
--- a/test/layers/wv.layers.model-test.js
+++ b/test/layers/wv.layers.model-test.js
@@ -21,31 +21,35 @@ buster.testCase("wv.layers.model", {
projection: "geographic"
},
projections: {
- "arctic": {},
- "geographic": {}
+ "arctic": { id: "arctic" },
+ "geographic": { id: "geographic" }
},
layers: {
"historical_1": {
id: "historical_1",
startDate: "2000-01-01",
endDate: "2002-01-01",
- group: "overlays"
+ group: "baselayers",
+ projections: { geographic: {} }
},
"historical_2": {
id: "historical_2",
startDate: "2001-01-01",
endDate: "2003-01-01",
- group: "overlays"
+ group: "overlays",
+ projections: { geographic: {} }
},
"active_1": {
id: "active_1",
startDate: "2005-01-01",
- group: "overlays"
+ group: "overlays",
+ projections: { geographic: {} }
},
"static": {
id: "static",
- group: "overlays"
- }
+ group: "overlays",
+ projections: { geographic: {} }
+ },
}
};
this.models = {};
@@ -86,6 +90,47 @@ buster.testCase("wv.layers.model", {
"No date range with static": function() {
this.model.add("static");
buster.refute(this.model.dateRange());
+ },
+
+ "Saves state": function() {
+ this.model.add("historical_1");
+ this.model.add("historical_2");
+ var state = {};
+ this.model.save(state);
+ buster.assert.equals(state.products,
+ "baselayers,historical_1~overlays,historical_2");
+ },
+
+ "Saves state with hidden layer": function() {
+ this.model.add("historical_1");
+ delete this.model.visible.historical_1;
+ var state = {};
+ this.model.save(state);
+ buster.assert.equals(state.products, "baselayers,!historical_1");
+ },
+
+ "Loads state": function() {
+ var state = {
+ products: ["historical_1", "historical_2"]
+ };
+ var errors = [];
+ this.model.load(state, errors);
+ buster.assert.equals(this.model.active.baselayers[0].id, "historical_1");
+ buster.assert.equals(this.model.active.overlays[0].id, "historical_2");
+ buster.assert.equals(errors.length, 0);
+ },
+
+ "Loads state with hidden layer": function() {
+ var state = {
+ products: ["historical_1"],
+ hidden: {"historical_1": true}
+ };
+ var errors = [];
+ this.model.load(state, errors);
+ buster.assert.equals(this.model.active.baselayers[0].id, "historical_1");
+ buster.refute(this.model.visible.historical_1);
+ buster.assert.equals(errors.length, 0);
}
+
});
diff --git a/test/link/wv.link.model-test.js b/test/link/wv.link.model-test.js
index bd9305606..2e401d17e 100644
--- a/test/link/wv.link.model-test.js
+++ b/test/link/wv.link.model-test.js
@@ -12,32 +12,25 @@
buster.testCase("wv.link.model", {
"Query string from registered components": function() {
- var c1 = { toPermalink: this.stub().returns("foo=1") };
- var c2 = { toPermalink: this.stub().returns("bar=2") };
+ var c1 = { save: function(state) { state.foo = 1; } };
+ var c2 = { save: function(state) { state.bar = 2; } };
var model = wv.link.model();
model.register(c1).register(c2);
buster.assert.equals(model.toQueryString(), "foo=1&bar=2");
},
- "Components without state are skipped": function() {
- var c1 = { toPermalink: this.stub().returns("foo=1") };
- var cx = { toPermalink: this.stub().returns("") };
- var c2 = { toPermalink: this.stub().returns("bar=2") };
+ "Values encoded": function() {
+ var c1 = { save: function(state) { state.foo = "?"; } };
var model = wv.link.model();
- model.register(c1).register(cx).register(c2);
- buster.assert.equals(model.toQueryString(), "foo=1&bar=2");
+ model.register(c1);
+ buster.assert.equals(model.toQueryString(), "foo=%3F");
},
- "Registered components called to parse query string": function() {
- var fp1 = this.stub();
- var fp2 = this.stub();
- var c1 = { fromPermalink: fp1 };
- var c2 = { fromPermalink: fp2 };
+ "Exceptions not encoded": function() {
+ var c1 = { save: function(state) { state.foo = ","; } };
var model = wv.link.model();
- model.register(c1).register(c2);
- model.load("foo=1&bar=2");
- buster.assert.calledWith(fp1, "foo=1&bar=2");
- buster.assert.calledWith(fp2, "foo=1&bar=2");
+ model.register(c1);
+ buster.assert.equals(model.toQueryString(), "foo=,");
},
"Shorten calls cgi script": function(done) {
@@ -71,7 +64,6 @@ buster.testCase("wv.link.model", {
buster.assert.calledOnce(call);
done();
});
-
}
});
diff --git a/test/map/wv.map-test.js b/test/map/wv.map-test.js
new file mode 100644
index 000000000..37160661f
--- /dev/null
+++ b/test/map/wv.map-test.js
@@ -0,0 +1,37 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+buster.testCase("wv.map", {
+
+ errors: null,
+
+ setUp: function() {
+ this.errors = [];
+ },
+
+ "Parses state": function() {
+ var state = { map: "0,1,2,3" };
+ wv.map.parse(state, this.errors);
+ buster.assert.equals(state.map.left, 0);
+ buster.assert.equals(state.map.bottom, 1);
+ buster.assert.equals(state.map.right, 2);
+ buster.assert.equals(state.map.top, 3);
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Error on invalid extent": function() {
+ var state = { map: "0,1,x,3" };
+ wv.map.parse(state, this.errors);
+ buster.refute(state.map);
+ buster.assert.equals(this.errors.length, 1);
+ }
+
+});
diff --git a/test/palettes/wv.palettes-test.js b/test/palettes/wv.palettes-test.js
index 142f9f9f0..4ce77b267 100644
--- a/test/palettes/wv.palettes-test.js
+++ b/test/palettes/wv.palettes-test.js
@@ -11,6 +11,49 @@
buster.testCase("wv.palettes", {
+ config: null,
+ errors: null,
+
+ setUp: function() {
+ this.config = {
+ layers: {
+ "layer1": {},
+ "layer2": {}
+ }
+ };
+ this.errors = [];
+ },
+
+ "Parses palette for valid layer": function() {
+ var state = { palettes: "layer1,palette1" };
+ wv.palettes.parse(state, this.errors, this.config);
+ buster.assert.equals(state.palettes.layer1, "palette1");
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Parses two palettes for valid layers": function() {
+ var state = { palettes: "layer1,palette1~layer2,palette2" };
+ wv.palettes.parse(state, this.errors, this.config);
+ buster.assert.equals(state.palettes.layer1, "palette1");
+ buster.assert.equals(state.palettes.layer2, "palette2");
+ buster.assert.equals(this.errors.length, 0);
+ },
+
+ "Rejects palette for invalid layer": function() {
+ var state = { palettes: "layerX,paletteX~layer2,palette2" };
+ wv.palettes.parse(state, this.errors, this.config);
+ buster.refute(state.palettes.layerX);
+ buster.assert.equals(state.palettes.layer2, "palette2");
+ buster.assert.equals(this.errors.length, 1);
+ },
+
+ "Rejects all palettes for invalid layers": function() {
+ var state = { palettes: "layerX,paletteX~layerY,paletteY" };
+ wv.palettes.parse(state, this.errors, this.config);
+ buster.refute(state.palettes);
+ buster.assert.equals(this.errors.length, 2);
+ },
+
"Translate one to one with custom palette": function() {
var source = {
colors: ["a", "b", "c"]
diff --git a/test/palettes/wv.palettes.model-test.js b/test/palettes/wv.palettes.model-test.js
index a138044f2..935f4e3a0 100644
--- a/test/palettes/wv.palettes.model-test.js
+++ b/test/palettes/wv.palettes.model-test.js
@@ -88,49 +88,60 @@ buster.testCase("wv.palettes.model", {
this.model.remove("layer1");
},
- "To permalink": function() {
+ "Saves state": function() {
this.model.active = {
"layer1": "custom1",
"layer2": "custom2"
};
- buster.assert.equals(this.model.toPermalink(),
- "palettes=layer1,custom1~layer2,custom2");
+ var state = {};
+ this.model.save(state);
+ buster.assert.equals(state.palettes, "layer1,custom1~layer2,custom2");
},
- "Empty permalink when no palettes are active": function() {
- buster.assert.equals(this.model.toPermalink(), "");
+ "Empty state no palettes are active": function() {
+ var state = {};
+ this.model.save(state);
+ buster.refute(state.palettes);
},
- "From permalink": function() {
+ "Loads state": function() {
this.stub(this.model, "add");
- this.model.fromPermalink("palettes=layer1,custom1~layer2,custom2");
+ var state = {
+ palettes: {
+ layer1: "custom1",
+ layer3: "custom3"
+ }
+ };
+ this.config.palettes.custom = {
+ custom1: {},
+ custom3: {}
+ };
+ var errors = [];
+ this.model.load(state, errors);
buster.assert.calledWith(this.model.add, "layer1", "custom1");
- buster.assert.calledWith(this.model.add, "layer2", "custom2");
+ buster.assert.calledWith(this.model.add, "layer3", "custom3");
+ buster.assert.equals(errors.length, 0);
},
+ /*
"From permalink, encoded ~": function() {
this.stub(this.model, "add");
this.model.fromPermalink("palettes=layer1,custom1%7Elayer2,custom2");
buster.assert.calledWith(this.model.add, "layer1", "custom1");
buster.assert.calledWith(this.model.add, "layer2", "custom2");
},
+ */
- "Warning from permalink when layer doesn't support palettes": function() {
+ "Error during load when layer doesn't support palettes": function() {
this.stub(wv.util, "warn");
- this.model.fromPermalink("palettes=layer3,customx");
- buster.assert.called(wv.util.warn);
- },
-
- "Warning from permalink when layer doesn't exist": function() {
- this.config.palettes.custom = {
- "custom1": {
- id: "custom1",
- colors: ["x1"]
+ var state = {
+ palettes: {
+ layer1: "customx"
}
};
- this.stub(wv.util, "warn");
- this.model.fromPermalink("palettes=layerx,custom1");
- buster.assert.called(wv.util.warn);
+ var errors = [];
+ this.model.load(state, errors);
+ buster.assert.equals(errors.length, 1);
}
});
\ No newline at end of file
diff --git a/test/proj/wv.proj-test.js b/test/proj/wv.proj-test.js
new file mode 100644
index 000000000..0adeb7dc7
--- /dev/null
+++ b/test/proj/wv.proj-test.js
@@ -0,0 +1,41 @@
+/*
+ * 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 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+buster.testCase("wv.proj", {
+
+ config: null,
+
+ setUp: function() {
+ this.config = {
+ projections: {
+ geographic: {}
+ }
+ };
+ },
+
+ "Parses valid projection": function() {
+ var state = { "switch": "geographic" };
+ var errors = [];
+ wv.proj.parse(state, errors, this.config);
+ buster.assert.equals(state["switch"], "geographic");
+ buster.assert.equals(errors.length, 0);
+ },
+
+ "Rejects unsupported projection": function() {
+ var state = { "switch": "albers" };
+ var errors = [];
+ wv.proj.parse(state, errors, this.config);
+ buster.refute(state["switch"]);
+ buster.assert.equals(errors.length, 1);
+ }
+
+});
+
diff --git a/test/proj/wv.proj.model-test.js b/test/proj/wv.proj.model-test.js
index 2e7c5ef1a..9073e5e15 100644
--- a/test/proj/wv.proj.model-test.js
+++ b/test/proj/wv.proj.model-test.js
@@ -74,29 +74,18 @@ buster.testCase("wv.proj.model", {
buster.refute.called(listener);
},
- "To permalink": function() {
+ "Saves state": function() {
var model = wv.proj.model(this.config);
- buster.assert.equals(model.toPermalink(), "switch=geographic");
+ var state = {};
+ model.save(state);
+ buster.assert.equals(state["switch"], "geographic");
},
- "From permalink": function() {
+ "Loads state": function() {
var model = wv.proj.model(this.config);
- model.fromPermalink("switch=arctic");
+ var state = {"switch": "arctic"};
+ model.load(state);
buster.assert.equals(model.selected.id, "arctic");
- },
-
- "Ignores query string without projection": function() {
- var model = wv.proj.model(this.config);
- model.fromPermalink("x=arctic");
- buster.assert.equals(model.selected.id, "geographic");
- },
-
- "Emits warning on invalid projection in query string": function() {
- this.stub(wv.util, "warn");
- var model = wv.proj.model(this.config);
- model.fromPermalink("switch=foo");
- buster.assert.equals(model.selected.id, "geographic");
- buster.assert.calledOnce(wv.util.warn);
}
});
\ No newline at end of file
diff --git a/test/util/wv.util.events-test.js b/test/util/wv.util.events-test.js
index 834777589..c82310d71 100644
--- a/test/util/wv.util.events-test.js
+++ b/test/util/wv.util.events-test.js
@@ -28,8 +28,9 @@ buster.testCase("wv.util.events", {
},
"Exception thrown when trying to register a null listener": function() {
+ var self = this;
buster.assert.exception(function() {
- this.events.on("foo");
+ self.events.on("foo");
});
},