Interactive interface for browsing global, full-resolution satellite imagery
Custom color palettes now working
Mike McGann16876a4c4d05
diff --git a/src/js/layers/wv.layers.options.js b/src/js/layers/wv.layers.options.jsindex e6f3a93d2..395a2f2f1 100644--- a/src/js/layers/wv.layers.options.js+++ b/src/js/layers/wv.layers.options.js@@ -209,9 +209,9 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {setTimeout(function() {var id = $(that).attr("data-palette");if ( id === "__default" ) {- models.palettes.remove(layer.id);+ models.palettes.clearCustom(layer.id);} else {- models.palettes.add(layer.id, id);+ models.palettes.setCustom(layer.id, id);}}, 0);});diff --git a/src/js/map/wv.map.ui.js b/src/js/map/wv.map.ui.jsindex 8d78852a8..fbef4ea74 100644--- a/src/js/map/wv.map.ui.js+++ b/src/js/map/wv.map.ui.js@@ -210,23 +210,23 @@ wv.map.ui = wv.map.ui || function(models, config) {var def = config.layers[layerId];var key = layerKey(def);var mapLayer = _.find(self.selected.layers, { key: key });- if ( !mapLayer.lookupTable ) {+ if ( !mapLayer ) {updateLayer(def);- updateOrder();} else {- mapLayer.lookupTable = getLookupTable(layerId);+ mapLayer.lookupTable = models.palettes.get(layerId).lookup;_.each(mapLayer.grid, function(row) {_.each(row, function(tile) {tile.applyLookup();});});}+ updateMap();};var removePalette = function(layerId) {var layer = config.layers[layerId];updateLayer(layer);- updateOrder();+ updateMap();};var updatePalette = function(layerId) {diff --git a/src/js/palettes/wv.palettes.js b/src/js/palettes/wv.palettes.jsindex 202db89af..b45096712 100644--- a/src/js/palettes/wv.palettes.js+++ b/src/js/palettes/wv.palettes.js@@ -43,18 +43,13 @@ wv.palettes = (function(self) {if ( !palette ) {return;}- var info = palette.scale || palette.classes;- if ( info ) {- var colors = info.colors;- var bins = info.colors.length;+ var colors = palette.colors || palette.scale.colors;+ if ( colors ) {+ var bins = colors.length;var binWidth = canvas.width / bins;var drawWidth = Math.ceil(binWidth);- _.each(info.colors, function(color, i) {- g.fillStyle = "rgba(" +- parseInt(color.substring(0,2), 16) + "," +- parseInt(color.substring(2,4), 16) + "," +- parseInt(color.substring(4,6), 16) + "," +- parseInt(color.substring(6,8), 16) + ")";+ _.each(colors, function(color, i) {+ g.fillStyle = wv.util.hexToRGBA(color);g.fillRect(Math.floor(binWidth * i), 0, drawWidth,canvas.height);});diff --git a/src/js/palettes/wv.palettes.legend.js b/src/js/palettes/wv.palettes.legend.jsindex e76e18b73..554ba34eb 100644--- a/src/js/palettes/wv.palettes.legend.js+++ b/src/js/palettes/wv.palettes.legend.js@@ -181,11 +181,11 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {index = bins - 1;}- var color = info.colors[index].substring(0, 6);+ var color = info.colors[index];var label = info.labels[index];$colorbar.tooltip("option", "content",- "<span class='wv-palettes-color-box' style='background: #" +- color + "'>" + "</span>" + label);+ "<span class='wv-palettes-color-box' style='background: " ++ wv.util.hexToRGBA(color) + "'>" + "</span>" + label);};var highlightClass = function() {diff --git a/src/js/palettes/wv.palettes.model.js b/src/js/palettes/wv.palettes.model.jsindex 39bd3e131..6ae4ff55a 100644--- a/src/js/palettes/wv.palettes.model.js+++ b/src/js/palettes/wv.palettes.model.js@@ -40,7 +40,8 @@ wv.palettes.model = wv.palettes.model || function(models, config) {if ( active && active.custom === paletteId ) {return;}- var def = active || { custom: paletteId };+ var def = active || {};+ def.custom = paletteId;updateLookup(layerId, def);self.active[layerId] = def;self.events.trigger("set-custom", layerId, def);diff --git a/src/js/util/wv.util.browser.js b/src/js/util/wv.util.browser.jsindex 750ae153e..34a2de0f8 100644--- a/src/js/util/wv.util.browser.js+++ b/src/js/util/wv.util.browser.js@@ -421,4 +421,3 @@ if (!String.prototype.endsWith) {}})();-diff --git a/src/js/util/wv.util.events.js b/src/js/util/wv.util.events.jsindex f2a6a7314..00e255923 100644--- a/src/js/util/wv.util.events.js+++ b/src/js/util/wv.util.events.js@@ -113,4 +113,4 @@ wv.util.events = wv.util.events || function() {};return self;-};\ No newline at end of file+};diff --git a/src/js/util/wv.util.js b/src/js/util/wv.util.jsindex e3dfb3551..3a1c3af0d 100644--- a/src/js/util/wv.util.js+++ b/src/js/util/wv.util.js@@ -312,6 +312,14 @@ wv.util = (function(self) {parseInt(str.substring(4, 6), 16) + ")";};+ self.hexToRGBA = function(str) {+ return "rgba(" ++ parseInt(str.substring(0, 2), 16) + "," ++ parseInt(str.substring(2, 4), 16) + "," ++ parseInt(str.substring(4, 6), 16) + "," ++ parseInt(str.substring(6, 8), 16) + ")";+ };+/*** Submits an AJAX request or retreives the result from the cache.*