Interactive interface for browsing global, full-resolution satellite imagery
Caching trick simplified
Mike McGann7b6053d8e6ba
diff --git a/etc/deploy/wv.js.json b/etc/deploy/wv.js.jsonindex 8d2a6dfc8..085f5ad2d 100644--- a/etc/deploy/wv.js.json+++ b/etc/deploy/wv.js.json@@ -44,11 +44,10 @@"src/js/data/wv.data.ui.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/map/wv.map.ui.js",+"src/js/link/wv.link.model.js","src/js/link/wv.link.ui.js",diff --git a/src/css/map-ol2.css b/src/css/map-ol2.cssindex 50325f9ee..838fbb0f5 100644--- a/src/css/map-ol2.css+++ b/src/css/map-ol2.css@@ -103,4 +103,3 @@ div.olControlScaleLineCustom {-ms-user-select: none; /* IE10+ */user-select: none;}-diff --git a/src/css/map.css b/src/css/map.cssindex 2c0b50393..b35731fd5 100644--- a/src/css/map.css+++ b/src/css/map.css@@ -8,6 +8,3 @@* Administrator of the National Aeronautics and Space Administration.* All Rights Reserved.*/---diff --git a/src/index.html b/src/index.htmlindex 2d57fa9af..2d4bc66b6 100644--- a/src/index.html+++ b/src/index.html@@ -176,10 +176,9 @@<!-- link.dev --> <script type="text/javascript" src="js/data/wv.data.ui.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/map/wv.map.ui.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>@@ -225,4 +224,4 @@<li id="toolbarPanel" class="toolbarTip" data-id="toolbarlist" data-button="Finish" data-options="tipLocation:bottom;nubPosition:top;tipAnimation:fade;prevButton:true;bordered:true;class:toolbar"></li></ol></body>-</html>\ No newline at end of file+</html>diff --git a/src/js/date/wv.date.model.js b/src/js/date/wv.date.model.jsindex 4b5507c99..63619d84d 100644--- a/src/js/date/wv.date.model.js+++ b/src/js/date/wv.date.model.js@@ -57,6 +57,10 @@ wv.date.model = wv.date.model || function(spec) {self.select(initial);};+ self.string = function() {+ return wv.util.toISOStringDate(self.selected);+ };+/*** Select a day to display on the map. If the selected date differs* from the current selection, a "selected" event is triggered.@@ -124,4 +128,3 @@ wv.date.model = wv.date.model || function(spec) {* @event selected* @param {Date} date the newly selected day.*/-diff --git a/src/js/layers/wv.layers.model.js b/src/js/layers/wv.layers.model.jsindex 092c5f3b1..e563d2340 100644--- a/src/js/layers/wv.layers.model.js+++ b/src/js/layers/wv.layers.model.js@@ -331,4 +331,4 @@ wv.layers.model = wv.layers.model || function(models, config) {init();return self;-};\ No newline at end of file+};diff --git a/src/js/layers/wv.layers.options.js b/src/js/layers/wv.layers.options.jsindex e0e0b4344..a37e171be 100644--- a/src/js/layers/wv.layers.options.js+++ b/src/js/layers/wv.layers.options.js@@ -64,7 +64,7 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {var $slider = $("<div></div>").noUiSlider({start: models.layers.getOpacity(layer.id),- step: 0.1,+ step: 0.01,range: {min: 0,max: 1@@ -176,4 +176,3 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {return self;};-diff --git a/src/js/layers/wv.layers.sidebar.js b/src/js/layers/wv.layers.sidebar.jsindex 90e0fbb67..efdd8daa7 100644--- a/src/js/layers/wv.layers.sidebar.js+++ b/src/js/layers/wv.layers.sidebar.js@@ -18,7 +18,7 @@ wv.layers = wv.layers || {};/*** @class wv.layers.sidebar*/-wv.layers.sidebar = wv.layers.sidebar || function(models) {+wv.layers.sidebar = wv.layers.sidebar || function(models, config) {var HTML_TAB_ACTIVE_SELECTED ="<i class='productsIcon selected icon-layers'></i>" +@@ -256,4 +256,4 @@ wv.layers.sidebar = wv.layers.sidebar || function(models) {init();return self;-};\ No newline at end of file+};diff --git a/src/js/link/wv.link.ui.js b/src/js/link/wv.link.ui.jsindex 52393a940..9572f1b95 100644--- a/src/js/link/wv.link.ui.js+++ b/src/js/link/wv.link.ui.js@@ -20,7 +20,7 @@ wv.link = wv.link || {};** @class wv.link.ui*/-wv.link.ui = wv.link.ui || function(models) {+wv.link.ui = wv.link.ui || function(models, config) {var self = {};var id = "wv-link-button";diff --git a/src/js/map/wv.map.js b/src/js/map/wv.map.jsindex 90d51fd39..629e083e7 100644--- a/src/js/map/wv.map.js+++ b/src/js/map/wv.map.js@@ -24,48 +24,6 @@ wv.map = (function(self) {new OpenLayers.Bounds(-180, 60, 180, 90).toGeometry()]);- /**- * An object that contains OpenLayers.Control.MousePosition objects- * that update the current latitude/longitude values on the map as the- * mouse moves. Keyed by projection name, either "geographic", "arctic",- * or "antarctic".- *- * Example:- * *- * @attribute COORDINATE_CONTROLS- * @final- */- self.COORDINATE_CONTROLS = {- "geographic": new OpenLayers.Control.MousePosition({- formatOutput: function(mouseLonLat) {- return mouseLonLat.lon.toFixed(3) + "°, " +- mouseLonLat.lat.toFixed(3) + "°";- }- }),- "arctic": new OpenLayers.Control.MousePosition({- projection: "EPSG:3413",- formatOutput: function(mouseLonLat) {- return this.projection + " " +- Math.round(mouseLonLat.lon) + "m, " +- Math.round(mouseLonLat.lat) + "m";- }- }),- "antarctic": new OpenLayers.Control.MousePosition({- formatOutput: function(mouseLonLat) {- return "EPSG:3031 " +- Math.round(mouseLonLat.lon) + "m, " +- Math.round(mouseLonLat.lat) + "m";- },- }),- "webmerc": new OpenLayers.Control.MousePosition({- formatOutput: function(mouseXY) {- var mouseLonLat = mouseXY.transform("EPSG:3857", "EPSG:4326");- return mouseLonLat.lon.toFixed(3) + "°, " +- mouseLonLat.lat.toFixed(3) + "°";- }- })- };-self.parse = function(state, errors) {if ( state.map ) {var extent = OpenLayers.Bounds.fromString(state.map);@@ -292,3 +250,89 @@ wv.map.HoverControl = OpenLayers.Class(OpenLayers.Control, {this.events.triggerEvent("hoverout", {feature: feature});}});++wv.map.mock = function() {++ return {+ setDay: function() {},+ setOpacity: function() {},+ setVisibility: function() {},+ setZIndex: function() {},+ dispose: function() {},+ setLookup: function() {},+ clearLookup: function() {}+ };++};+++wv.map.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.layers.js b/src/js/map/wv.map.layers.jsdeleted file mode 100644index 1b9f47f2a..000000000--- a/src/js/map/wv.map.layers.js+++ /dev/null@@ -1,600 +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.- */--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(matrixSet.tileSize[0],- matrixSet.tileSize[1]),- visibility: false- };- 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});- }- olLayer.wvid = layerId;- 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(512, 512),- visiblity: false- };- 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);- olLayer.wvid = layerId;- 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;- fetchLayer();- /*- // 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.jsindex a2338dbfd..77cdb3fa0 100644--- a/src/js/map/wv.map.model.js+++ b/src/js/map/wv.map.model.js@@ -12,86 +12,31 @@var wv = wv || {};wv.map = wv.map || {};-// FIXME: This needs to be split out into model/ui sections+// FIXME: The code is like this for historical reasons and should be refactored+// at some point.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.extent = [];- self.selected = null;-- /**- * Property: config- * The map config object retrieved from the server that- * defines the available projections and data products.- */- self.config = config;-- self.events = wv.util.events();-- 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);- }- });-- models.proj.events.on("select", onProjectionSelect);- models.layers.events.on("add", onLayersChange);- models.layers.events.on("remove", onLayersChange);- models.layers.events.on("update", onLayersChange);- models.layers.events.on("visibility", onLayersChange);- models.layers.events.on("opacity", onOpacityChange);- models.date.events.on("select", onDateSelect);- models.palettes.events.on("change", onPalettesChange);- };-- self.load = function(state, errors) {- onProjectionSelect();+ self.load = function(state) {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.getMaxExtent());- if ( !intersects ) {- errors.push({message: "Extent outside of range"});- extent = map.getExtent();- }- self.maps.map.zoomToExtent(extent, true);+ self.extent = state.map;} else {self.setExtentToLeading();}-- // Initial state needs to be loaded here or the transition effect- // does not work when a palette is assigned via permalink- onDateSelect();- onLayersChange();- onPalettesChange();};self.save = function(state) {- state.map = self.maps.map.getExtent().toBBOX();+ state.map = self.extent.slice(0);};self.setExtentToLeading = function() {- // Polar projections don't need to be positioned- if ( self.maps.projection !== "geographic" && self.maps.projection !== "webmerc" ) {+ if ( models.proj.selected.id !== "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"@@ -112,69 +57,8 @@ wv.map.model = wv.map.model || function(models, config) {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;-- var center = new OpenLayers.LonLat(lon, lat);- if ( self.maps.projection === "webmerc" ) {- center = center.transform("EPSG:4326", "EPSG:3857");- zoomLevel = 3;- }- map.setCenter(center, zoomLevel);+ self.extent = [minLon, minLat, maxLon, maxLat];};- 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 =- _.pluck(active.overlays, "id")- .concat(_.pluck(active.baselayers, "id"));- layers.reverse();- var visible = models.layers.visible;- self.maps.set(layers, visible);- self.maps.setPalettes(models.palettes.active);- self.events.trigger("projection");- };-- var onOpacityChange = function(layer, opacity) {- self.maps.setOpacity(layer.id, opacity);- };-- 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/map/wv.map.palette.js b/src/js/map/wv.map.palette.jsindex 5d3763da6..6954a135f 100644--- a/src/js/map/wv.map.palette.js+++ b/src/js/map/wv.map.palette.js@@ -558,4 +558,4 @@ wv.map.palette.scheduler = function(config) {** Property: self* If provided, the "this" context of the caller.- */\ No newline at end of file+ */diff --git a/src/js/map/wv.map.set.js b/src/js/map/wv.map.set.jsdeleted file mode 100644index c0dd20e97..000000000--- a/src/js/map/wv.map.set.js+++ /dev/null@@ -1,580 +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.- */--var wv = wv || {};-wv.map = wv.map || {};--wv.map.set = wv.map.set || function(containerId, mapConfig, component) {-- var self = {};-- // Configurations for each available product- var productConfigs = {};-- // Current set of layers that have been added to the map, one set- // for each supported projection.- var activeLayers = {};-- // Display layers on the map for this day- var currentDay = wv.util.today();-- // The number of layers in the processing of loading. This is used- // to fire maploadstart and maploadend events.- self.layersLoading = {};-- //-------------------------------------------------------------------------- // Public- //--------------------------------------------------------------------------- self.mapConfig = mapConfig;-- // Map objects, one for each supported projection- self.projections = {};-- /**- * Property: map- * OpenLayers.Map object used for the currently selected projection- * (read only).- */- self.map = null;-- /**- * Property: layers- * Array containing the name of each layer that is visible on the map for- * the currently selected projection (read only).- */- self.layers = null;-- /**- * Property: projection- * Current map projection (read only). Set via <setProjection>.- */- self.projection = null;-- self.EVENT_ZOOM_END = "zoomEnd";- self.EVENT_MOVE_END = "zoomEnd";-- self.events = wv.util.events();-- var init = function() {- var $container = $("#" + containerId);- if ( $container.length === 0 ) {- throw new Error("No container for map set: " + containerId);- }-- // Create map objects, one for each projection.- $.each(mapConfig.projections, function(projection, config) {- config = validateMapConfig(config);- if ( config.virtual ) {- return;- }- var id = "map-" + projection;-- var newMap = createMap($container, id, projection, config);-- // Put in a bogus layer to act as the base layer to make the- // map happy for setting up the starting location- var options = {- isBaseLayer: true,- projection: config.projection,- maxExtent: config.maxExtent,- maxResolution: 0.5625,- units: config.units || "dd"- };- var blankLayer = new OpenLayers.Layer("Blank", options);- blankLayer.wvid = "__BLANK";- newMap.addLayer(blankLayer);-- // If a starting location is provided, go there otherwise- // zoom to max extent- if ( config.startCenter || config.startZoom ) {- var startCenter = config.startCenter || [0, 0];- var startZoom = config.startZoom || 0;- newMap.setCenter(startCenter, startZoom);- } else {- newMap.zoomToMaxExtent();- }-- newMap.layerSets = {};- self.projections[projection] = newMap;- activeLayers[projection] = [];-- newMap.events.register("addlayer", self, onAddLayer);- newMap.events.register("removelayer", self, onRemoveLayer);- newMap.events.register("moveend", self, fireEvent);- newMap.events.register("moveend", self, function() {- self.events.trigger(self.EVENT_MOVE_END, newMap);- });- newMap.events.register("zoomend", self, function() {- self.events.trigger(self.EVENT_ZOOM_END, newMap);- });-- // Keep track of center point on projection switch- newMap.previousCenter = newMap.getCenter();- });- layerConfigs = mapConfig.layers;-- self.setProjection(mapConfig.defaultProjection || "geographic");-- $(document.body).mousemove(function(event) {- /* FIXME: This code breaks other components, see WV-150- newEvent = $.extend(true, {}, event);- newEvent.xy = {- x: event.clientX,- y: event.clientY- };- self.map.events.triggerEvent("mousemove", newEvent);- */- });- };-- /**- * Method: setProjection- * Changes the projection of the map.- *- * Parameters:- * projection - The name of the projection to use (e.g., "geographic",- * "arctic", "antarctic").- *- * Throws:- * An exception if the specified projection is not supported.- */- self.setProjection = function(projection) {- if ( !(projection in self.projections) ) {- throw new Error("Unsupported projection: " + projection);- }-- // Hide all map elements and then display only the ones for this- // projection- $(".map-projection").css("display", "none");- $(".map-" + projection).css("display", "block");-- // Keep track of center point on projection switch- if ( self.map ) {- self.map.previousCenter = self.map.getCenter();- }-- // Update convenience variables- self.map = self.projections[projection];- self.layers = activeLayers[projection];- self.projection = projection;-- // If the browser was resized, the inactive map was not notified of- // the event. Force the update no matter what and reposition the center- // using the previous value.- self.map.updateSize();- self.map.setCenter(self.map.previousCenter);-- // Ensure the current layers are using the current day if this was- // changed in the last projection- self.setDay(currentDay);- };-- /**- * Method: setDay- * Display product data for the specified ay.- *- * Parameters:- * day - Day to display as a Date object. If this is undefined or null,- * this method does nothing.- */- self.setDay = function(day) {- if ( day ) {- currentDay = day;- $.each(self.map.layerSets, function(name, layer) {- layer.setDay(day);- });- refreshZOrder();- }- };-- self.setOpacity = function(layerName, opacity) {- $.each(self.map.layerSets, function(name, layer) {- if ( name == layerName ) {- var value = parseFloat(opacity);- if ( isNaN(value) ) {- console.warn("Invalid opacity for layer " + layerName + ": " +- opacity);- } else {- layer.setOpacity(value);- }- }- });- };-- /**- * Method: set- * Set the layers that should be displayed on the map.- *- * Parameters:- * requestedLayers - Array of product names to show on the map. If a- * product is currently displayed, but is not in the array, it will be- * removed from the map. If a product is not currently displayed, but it- * is in the array, it will be added to the map.- *- * Throws:- * An exception if the product for the given name is not defined.- */- // FIXME: This awkwardness of this function is for historical reasons- // and can be cleaned up now.- 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);- }- } else {- newLayers.push(layer);- }- if ( self.map.layerSets[layer] ) {- if ( !visibleLayers[layer] ) {- self.setVisibility(layer, false);- } else {- self.setVisibility(layer, true);- }- }- });- $.each(self.layers, function(index, layer) {- if ( $.inArray(layer, requestedLayers) < 0 ) {- remove(layer);- }- });- activeLayers[self.projection] = newLayers;- self.layers = activeLayers[self.projection];-- var seenBaseLayer = false;- _.eachRight(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();- };-- self.setVisibility = function(layer, value, options) {- self.map.layerSets[layer].setVisibility(value, options);- };-- /**- * Method: append- * Appends a layer to the map which is displayed on top.- *- * Parameters:- * product - Name of the product to append to the map. If the product- * already exsits, this method does nothing.- */- self.append = function(layer) {- if ( $.inArray(layer, self.layers) >= 0 ) {- return;- }- var newLayers = $.extend([], self.layers);- newLayers.push(layer);- self.set(newLayers);- refreshZOrder();- };-- /**- * Method: setPalettes- * Sets which products should have custom palettes applied.- *- * Parameters:- * activePalettes - An object which has product names as properties- * and palette names as values.- */- self.setPalettes = function(activePalettes) {- $.each(self.projections, function(projection, map) {- $.each(map.layerSets, function(layerName, layer) {- var paletteName = activePalettes[layerName];- if ( paletteName ) {- // Find the rendered palette for this product- var layerConfig = self.mapConfig.layers[layerName];- var renderedName = layerConfig.palette.id;- var renderedPalette = self.mapConfig.palettes.rendered[renderedName];-- if ( !renderedPalette ) {- console.warn(layerName + " does not support palettes");- return;- }- // Find the palette that should be used instead- var palette = wv.palettes.translate(renderedPalette,- self.mapConfig.palettes.custom[paletteName]);-- if ( !palette ) {- console.warn("No such palette: " + paletteName);- return;- }- var lookup = wv.palettes.lookup(renderedPalette, palette);- // Apply- layer.setLookup(lookup);- } else {- layer.clearLookup();- }- });- });- };-- //-------------------------------------------------------------------------- // Private- //--------------------------------------------------------------------------- var fireEvent = function() {- };-- /*- * Adds a product of the given name to map. Returns true if the product- * was added or already exists, false if the product is not supported- * by the projection.- */- var add = function(name) {- if ( name === "NON_EXISTENT_LAYER" ) {- return;- }-- var layerConfig = layerConfigs[name];- if ( !layerConfig ) {- console.warn("No such layer: " + name);- return false;- }- if ( $.inArray(name, self.layers) >= 0 ) {- console.warn("Layer already added: " + name);- return true;- }-- var supported = false;- if ( self.projection in layerConfig.projections ) {- var layer = createLayer(self.map, self.projection, name);- layer.setDay(currentDay);- self.map.layerSets[name] = layer;- supported = true;- } else {- console.warn(name + " does not support " + self.projection);- supported = false;- }- return supported;- };-- /*- * Removes the given product from the map.- */- var remove = function(name) {- if ( $.inArray(name, self.layers) < 0 ) {- console.warn("Layer has not been added: " + name);- return;- }- var layer = self.map.layerSets[name];- if ( layer ) {- layer.dispose();- delete self.map.layerSets[name];- } else {- console.warn("Layer does not exist: " + name);- }- };-- /*- * The order of the layers in the OpenLayers.Map object is not used- * to determine the z-index but is done manually instead since this- * is much easier. Change the z-index for for each product based on- * its positition in the products array.- */- var refreshZOrder = function() {- $.each(self.layers, function(index, name) {- var layer = self.map.layerSets[name];- if ( layer ) {- layer.setZIndex(index * 2);- }- });- };-- /*- * Creates the OpenLayers.Map object and all associated controls.- */- var createMap = function($div, id, projection, spec) {-- var config = $.extend(true, {}, spec);- // OpenLayers uses "projection" for the map object. We use "crs"- // instead- config.projection = config.crs;-- // Zooming feature is not as fluid as advertised- config.zoomMethod = null;-- // Don't let OpenLayers fetch the stylesheet -- that is included- // manually.- config.theme = null;-- // Let events propagate up- config.fallThrough = true;-- // Force OL to get the latest tiles without caching- config.tileManager = null;-- var controls = [];-- var $map = $("<div></div>")- .appendTo($div)- .attr("id", id)- .addClass("map-projection")- .addClass("map")- .addClass(id);-- var mapClass = "map-projection " + id + " ";-- var $zoomOut = $("<button></button>")- .addClass("wv-map-zoom-out")- .addClass("wv-map-zoom");- var $outIcon = $("<i></i>")- .addClass("fa")- .addClass("fa-minus")- .addClass("fa-1x");- $zoomOut.append($outIcon);- $map.append($zoomOut);- $zoomOut.button({- text: false- });-- var $zoomIn = $("<button></button>")- .addClass("wv-map-zoom-in")- .addClass("wv-map-zoom");- var $inIcon = $("<i></i>")- .addClass("fa")- .addClass("fa-plus")- .addClass("fa-1x");- $zoomIn.append($inIcon);- $map.append($zoomIn);- $zoomIn.button({- text: false- });-- $zoomIn.click(function() {- self.map.zoomIn();- });-- $zoomOut.click(function() {- self.map.zoomOut();- });-- // Add navigation controls- controls.push(new OpenLayers.Control.Navigation({- dragPanOptions: {- enableKinetic: true- }- }));-- // While these aren't controls, per se, they are extra decorations- controls.push(new OpenLayers.Control.Attribution());- controls.push(new OpenLayers.Control.ScaleLine({- displayClass: mapClass + "olControlScaleLineCustom",- maxWidth: 175,- }));-- var coordinateControl =- wv.map.COORDINATE_CONTROLS[projection];- if ( coordinateControl ) {- controls.push(coordinateControl);- } else {- console.warn("No coordinate control for projection " + projection);- }-- config.controls = controls;- var m = new OpenLayers.Map(id, config);-- var navControl =- m.getControlsByClass("OpenLayers.Control.Navigation")[0];- navControl.handlers.wheel.interval = 100;- navControl.handlers.wheel.cumulative = false;-- m.events.register("zoomend", null, function() {- if ( m.zoom === m.numZoomLevels - 1 ) {- $zoomIn.button("disable");- $zoomOut.button("enable");- } else if ( m.zoom === 0 ) {- $zoomIn.button("enable");- $zoomOut.button("disable");- } else {- $zoomIn.button("enable");- $zoomOut.button("enable");- }- });-- return m;- };-- /*- * Validates the configuraiton for the OpenLayers.Map object, provides- * any missing defaults, and does any object conversions as needed.- */- var validateMapConfig = function(config) {- config = $.extend(true, config, {});- config.maxExtent = new OpenLayers.Bounds(config.maxExtent);- config.allOverlays = true;- config.fractionalZoom = false;- return config;- };-- /*- * Merges in any projection specific properties.- */- var createLayer = function(map, projId, layerId) {- if ( self.mapConfig.parameters.mockMap ) {- return wv.map.layers.mock();- }- config = $.extend(true, {}, mapConfig);- var period = config.layers[layerId].period;- if ( period === "daily" ) {- return wv.map.layers.daily(map, mapConfig, projId, layerId);- }- return wv.map.layers.static(map, mapConfig, projId, layerId);- };--- // This has gotten really awkward, but seems to work- var onAddLayer = function(event) {- var layer = event.layer;-- var onLoadStart = function() {- if ( _.size(self.layersLoading) === 0 ) {- self.map.events.triggerEvent("maploadstart");- }- self.layersLoading[layer.wvid] = true;- };-- var onLoadEnd = function() {- if ( _.size(self.layersLoading) === 1 && self.layersLoading[layer.wvid] ) {- self.map.events.triggerEvent("maploadend");- }- delete self.layersLoading[layer.wvid];- };-- layer.events.register("loadstart", layer, onLoadStart);- layer.events.register("loadend", layer, onLoadEnd);- //onLoadStart();-- refreshZOrder();- };-- var onRemoveLayer = function(event) {- delete self.layersLoading[event.layer.wvid];- refreshZOrder();- };-- init();- return self;-};\ No newline at end of filediff --git a/src/js/map/wv.map.ui.js b/src/js/map/wv.map.ui.jsnew file mode 100644index 000000000..5a6375d10--- /dev/null+++ b/src/js/map/wv.map.ui.js@@ -0,0 +1,468 @@+/*+ * 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.ui = wv.map.ui || function(models, config) {++ var self = {};++ var id = "map";+ var selector = "#" + id;++ // When the date changes, save the layer so that the tiles remain+ // cached.+ var layerCache = new Cache(50);+ var $proj = {};++ // One map for each projection+ self.proj = {};++ // The map for the selected projection+ self.selected = null;++ var init = function() {+ _.each(config.projections, function(proj) {+ var map = createMap(proj);+ self.proj[proj.id] = map;+ });++ models.proj.events.on("select", updateProjection);+ models.layers.events.on("add", addLayer);+ models.layers.events.on("remove", removeLayer);+ models.layers.events.on("visibility", updateVisibility);+ models.layers.events.on("opacity", updateOpacity);+ models.layers.events.on("update", updateOrder);+ models.date.events.on("select", updateDate);+ models.palettes.events.on("add", addPalette);+ models.palettes.events.on("remove", removePalette);++ updateProjection();+ };++ var updateProjection = function() {+ if ( self.selected ) {+ hideMap(self.selected);+ }+ self.selected = self.proj[models.proj.selected.id];+ refreshLayers();+ showMap(self.selected);+ };++ var hideMap = function(map) {+ $(map.div).hide();+ };++ var showMap = function(map) {+ $(map.div).show();+ };++ var addLayer = function(layer) {+ var map = self.selected;+ var mapLayer = createLayer(layer, models.proj.selected);++ // If this is a base layer, it should be added after the last+ // base layer but before the first overlay+ var lastLayer = 0;+ _.each(map.layers, function(activeLayer, index) {+ if ( layer.group === activeLayer.wvgroup ) {+ lastLayer = index;+ }+ });+ self.selected.addLayer(mapLayer);+ map.setLayerIndex(mapLayer, lastLayer + 1);+ adjustLayers();+ };++ var removeLayer = function(layer) {+ var map = self.selected;+ var activeLayers = map.layers.slice(0);+ _.each(activeLayers, function(mapLayer) {+ if ( mapLayer.wvid === layer.id ) {+ map.removeLayer(mapLayer);+ }+ });+ adjustLayers();+ };++ var updateVisibility = function(layer, visible) {+ findLayer(layer.id).setVisibility(visible);+ adjustLayers();+ };++ var updateOpacity = function(layer, opacity) {+ findLayer(layer.id).setOpacity(opacity);+ adjustLayers();+ };++ var updateDate = function() {+ /*+ _.each(self.selected.layers, function(mapLayer) {+ var layer = config.layers[mapLayer.wvid];+ if ( layer.period === "daily" ) {+ var newMapLayer = createLayer(layer, map.worldview.proj);+ if ( models.layers.visible[layer.id] ) {+ newMapLayer.setVisible(true);+ }+ var oldMapLayer = mapLayers.getAt(index);+ mapLayers.insertAt(index, newMapLayer);+ map.removeLayer(oldMapLayer);+ }+ });*/+ refreshLayers();+ };++ var clearLayers = function(map) {+ var activeLayers = map.layers.slice(0);+ for ( var i = 0; i < activeLayers.length; i++ ) {+ map.removeLayer(activeLayers[i]);+ }+ };++ var refreshLayers = function(map) {+ map = map || self.selected;+ var proj = models.proj.selected;+ clearLayers(map);++ map.addLayer(createLayerBlank(proj));+ var layers = models.layers.get({proj: proj.id, reverse: true});+ _.each(layers, function(layer) {+ map.addLayer(createLayer(layer, proj));+ });+ adjustLayers();+ };++ var updateOrder = function() {+ var map = self.selected;+ var proj = models.proj.selected;+ var layers = models.layers.get({proj: proj.id, reverse: true});+ _.each(layers, function(layer, index) {+ // Plus one because of the bogus base layer+ map.setLayerIndex(findLayer(layer.id), index + 1);+ });+ adjustLayers();+ };++ var getLookupTable = function(layerId) {+ var layer = config.layers[layerId];+ var source = config.palettes.rendered[layer.palette.id];+ var custom = config.palettes.custom[models.palettes.active[layerId]];+ var target = wv.palettes.translate(source, custom);+ return wv.palettes.lookup(source, target);+ };++ var addPalette = function(layerId, paletteId) {+ var layer = config.layers[layerId];+ var mapLayer = findLayer(layer.id);+ var redraw = false;+ if ( !mapLayer.lookupTable ) {+ layerCache.clear();+ removeLayer(layer);+ addLayer(layer);+ updateOrder();+ } else {+ mapLayer.lookupTable = getLookupTable(layerId);+ _.each(mapLayer.grid, function(row) {+ _.each(row, function(tile) {+ tile.applyLookup();+ });+ });+ }+ };++ var removePalette = function(layerId) {+ var layer = config.layers[layerId];+ layerCache.clear();+ removeLayer(layer);+ addLayer(layer);+ updateOrder();+ };++ // After changes to the layer list, make sure that any layers underneath+ // an opaque layer are hidden to prevent tiles being fetched from the+ // server. Any layers that are semi-transparent must have transitions+ // turned off or the back buffer will interfere.+ var adjustLayers = function() {+ var bottom = false;+ _.eachRight(self.selected.layers, function(mapLayer) {+ if ( !mapLayer.wvid) {+ return;+ }+ if ( bottom ) {+ mapLayer.setVisibility(false);+ return;+ }+ var layer = config.layers[mapLayer.wvid];+ var visible = models.layers.visible[layer.id];+ var opacity = models.layers.getOpacity(layer.id);+ if ( layer.group === "baselayer" && visible && opacity === 1.0 ) {+ bottom = true;+ }+ if ( opacity > 0.0 && opacity < 1.0 ) {+ mapLayer.transitionEffect = "none";+ } else {+ mapLayer.transitionEffect = getTransition(layer);+ }+ });+ };++ var getTransition = function(layer) {+ if ( layer.type === "wmts" ) {+ return ( layer.noTransition ) ? "none" : "resize";+ } else if ( layer.type === "wms" ) {+ return ( layer.transition ) ? "resize": "none";+ }+ throw new Error("Invalid layer type: " + layer.type);+ };++ var updateExtent = function() {+ models.map.extent = self.selected.getExtent().toArray();+ };++ var createLayer = function(layer, proj) {+ var key = layerKey(proj, layer, models.date.selected);+ var mapLayer = layerCache.getItem(key);+ if ( !mapLayer ) {+ if ( layer.type === "wmts" ) {+ mapLayer = createLayerWMTS(layer, proj);+ } else if ( layer.type === "wms" ) {+ mapLayer = createLayerWMS(layer, proj);+ } else {+ throw new Error("Unknown layer type: " + layer.type);+ }+ layerCache.setItem(key, mapLayer);+ }+ mapLayer.wvid = layer.id;+ mapLayer.wvgroup = layer.group;+ if ( models.layers.visible[layer.id] ) {+ mapLayer.setVisibility(true);+ }+ mapLayer.setOpacity(models.layers.getOpacity(layer.id));+ return mapLayer;+ };++ var createLayerBlank = function(proj) {+ // Put in a bogus layer to act as the base layer to make the+ // map happy for setting up the starting location+ var options = {+ isBaseLayer: true,+ projection: proj.crs,+ maxExtent: proj.maxExtent,+ maxResolution: proj.maxResolution,+ units: proj.units || "dd"+ };+ return new OpenLayers.Layer("Blank", options);+ };++ var createLayerWMTS = function(layer, proj) {+ var matrixSet = config.matrixSets[layer.projections[proj.id].matrixSet];+ var source = config.sources[layer.projections[proj.id].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(matrixSet.tileSize[0],+ matrixSet.tileSize[1]),+ visibility: false+ };+ if ( layer.noTransition ) {+ param.transitionEffect = "none";+ } else {+ param.transitionEffect = "resize";+ }+ if ( models.palettes.active[layer.id] ) {+ param.tileClass = wv.map.palette.canvasTile;+ param.lookupTable = getLookupTable(layer.id);+ }++ var olLayer = new OpenLayers.Layer.WMTS(param);+ if ( layer.period === "daily" ) {+ olLayer.mergeNewParams({"time": models.date.string()});+ }+ return olLayer;+ };++ var createLayerWMS = function(layer, proj) {+ 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 = models.date.string();+ }+ var options = {+ tileSize: new OpenLayers.Size(512, 512),+ visiblity: false+ };+ 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;+ };++ var createMap = function(proj) {+ var target = id + "-" + proj.id;+ var $map = $("<div></div>")+ .attr("id", target)+ .attr("data-projection", proj.id)+ .addClass("map");+ $proj[proj.id] = $map;+ $(selector).append($map);++ var options = _.extend({}, proj);+ // OpenLayers uses "projection" for the map object. We use "crs"+ // instead+ options.projection = new OpenLayers.Projection(options.crs);++ // Zooming feature is not as fluid as advertised+ options.zoomMethod = null;++ // Don't let OpenLayers fetch the stylesheet -- that is included+ // manually.+ options.theme = null;++ // Let events propagate up+ options.fallThrough = true;++ // Force OL to get the latest tiles without caching+ options.tileManager = null;++ options.extent = options.maxExtent;+ options.allOverlays = true;+ options.fractionalZoom = false;++ var controls = [];++ // Add navigation controls+ controls.push(new OpenLayers.Control.Navigation({+ dragPanOptions: {+ enableKinetic: true+ }+ }));++ // While these aren't controls, per se, they are extra decorations+ controls.push(new OpenLayers.Control.Attribution());+ controls.push(new OpenLayers.Control.ScaleLine({+ displayClass: "olControlScaleLineCustom",+ maxWidth: 175+ }));++ var coordinateControl = new OpenLayers.Control.MousePosition({+ formatOutput: function(mouseXY) {+ var mouseLonLat = mouseXY.transform(proj.crs, "EPSG:4326");+ return mouseLonLat.lon.toFixed(3) + "°, " ++ mouseLonLat.lat.toFixed(3) + "°";+ }+ });+ controls.push(coordinateControl);++ options.controls = controls;+ var map = new OpenLayers.Map(target, options);++ var navControl =+ map.getControlsByClass("OpenLayers.Control.Navigation")[0];+ navControl.handlers.wheel.interval = 100;+ navControl.handlers.wheel.cumulative = false;++ var $zoomOut = $("<button></button>")+ .addClass("wv-map-zoom-out")+ .addClass("wv-map-zoom");+ var $outIcon = $("<i></i>")+ .addClass("fa")+ .addClass("fa-minus")+ .addClass("fa-1x");+ $zoomOut.append($outIcon);+ $map.append($zoomOut);+ $zoomOut.button({+ text: false+ });++ var $zoomIn = $("<button></button>")+ .addClass("wv-map-zoom-in")+ .addClass("wv-map-zoom");+ var $inIcon = $("<i></i>")+ .addClass("fa")+ .addClass("fa-plus")+ .addClass("fa-1x");+ $zoomIn.append($inIcon);+ $map.append($zoomIn);+ $zoomIn.button({+ text: false+ });++ $zoomIn.click(function() {+ map.zoomIn();+ });++ $zoomOut.click(function() {+ map.zoomOut();+ });++ map.addLayer(createLayerBlank(proj));+ map.setCenter(proj.startCenter, proj.startZoom);++ map.events.register("zoomend", null, function() {+ if ( map.zoom === map.numZoomLevels - 1 ) {+ $zoomIn.button("disable");+ $zoomOut.button("enable");+ } else if ( map.zoom === 0 ) {+ $zoomIn.button("enable");+ $zoomOut.button("disable");+ } else {+ $zoomIn.button("enable");+ $zoomOut.button("enable");+ }+ });+ map.events.register("move", null, updateExtent);++ $map.hide();++ return map;+ };++ var findLayer = function(id) {+ var found;+ _.each(self.selected.layers, function(mapLayer) {+ if ( mapLayer.wvid === id ) {+ found = mapLayer;+ return false;+ }+ });+ return found;+ };++ var layerKey = function(proj, layer, date) {+ return proj.id + ":" + layer.id + ":" + date.getTime();+ };++ init();+ return self;++};diff --git a/src/js/palettes/wv.palettes.model.js b/src/js/palettes/wv.palettes.model.jsindex 903b2e8f0..9e7175b56 100644--- a/src/js/palettes/wv.palettes.model.js+++ b/src/js/palettes/wv.palettes.model.js@@ -108,4 +108,4 @@ wv.palettes.model = wv.palettes.model || function(models, config) {return self;-};\ No newline at end of file+};diff --git a/src/js/proj/wv.proj.change.js b/src/js/proj/wv.proj.change.jsindex 9275864ae..97119c516 100644--- a/src/js/proj/wv.proj.change.js+++ b/src/js/proj/wv.proj.change.js@@ -67,7 +67,6 @@ wv.proj.change = wv.proj.change || function(models) {self.events.trigger("select", self);if ( polarVisited > 1 && wasOld !== self.old ) {checkNotify();- wv.map.COORDINATE_CONTROLS.arctic.projection = self.crs;}if ( wasOld !== self.old && self.old ) {@@ -142,4 +141,3 @@ wv.proj.change = wv.proj.change || function(models) {init();return self;};-diff --git a/src/js/wv.main.js b/src/js/wv.main.jsindex 8fe0f98ed..5e09f8e95 100644--- a/src/js/wv.main.js+++ b/src/js/wv.main.js@@ -88,12 +88,12 @@ $(function() {if ( config.features.dataDownload ) {models.data = wv.data.model(models, config);}+ models.map = wv.map.model(models, config);models.link = wv.link.model(config);// Export for debuggingwv.models = models;-var updateDateRange = function() {models.date.range(models.layers.dateRange());};@@ -107,23 +107,20 @@ $(function() {.register(models.proj).register(models.layers).register(models.date)- .register(models.palettes);+ .register(models.palettes)+ .register(models.map);if ( config.features.dataDownload) {models.link.register(models.data);}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 widgetsvar ui = {};+ ui.map = wv.map.ui(models, config);ui.proj = wv.proj.ui(models, config);- ui.sidebar = wv.layers.sidebar(models);+ ui.sidebar = wv.layers.sidebar(models, config);ui.activeLayers = wv.layers.active(models, ui, config);ui.addLayers = wv.layers.add(models, ui, config);//ui.dateSliders = wv.date.sliders(models, config);@@ -136,7 +133,7 @@ $(function() {// FIXME: Why is this here?ui.data.render();}- ui.link = wv.link.ui(models);+ ui.link = wv.link.ui(models, config);ui.tour = wv.tour(models, ui);_.merge(wv.ui, ui);@@ -168,10 +165,12 @@ $(function() {ui.data.onViewChange(map);});*/+ /*if ( config.features.dataDownload ) {// FIXME: This is a hackmodels.map.events.on("projection", models.data.updateProjection);}+ */// Console notificationsif ( wv.brand.release() ) {@@ -235,4 +234,3 @@ $(function() {wv.util.wrap(main)();});-