Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Red color palette

Mike McGannfba947309ebe
diff --git a/web/js/map/wv.map.ui.js b/web/js/map/wv.map.ui.js
index 3f632e001..1aa675b39 100644
--- a/web/js/map/wv.map.ui.js
+++ b/web/js/map/wv.map.ui.js
@@ -42,6 +42,10 @@ wv.map.ui = wv.map.ui || function(models, config) {
.on("opacity", updateOpacity)
.on("update", updateLayerOrder);
models.date.events.on("select", updateDate);
+ models.palettes.events
+ .on("set-custom", updateLookup)
+ .on("clear-custom", updateLookup)
+ .on("range", updateLookup);
updateProjection(true);
};
@@ -170,6 +174,23 @@ wv.map.ui = wv.map.ui || function(models, config) {
updateLayerVisibilities();
};
+ var updateLookup = function(layerId) {
+ // If the lookup changes, all layers in the cache are now stale
+ // since the tiles need to be rerendered. Remove from cache.
+ var selectedDate = wv.util.toISOStringDate(models.date.selected);
+ var selectedProj = models.proj.selected.id;
+ cache.removeWhere(function(key, mapLayer) {
+ if ( mapLayer.wvid === layerId &&
+ mapLayer.wvproj === selectedProj &&
+ mapLayer.wvdate !== selectedDate &&
+ mapLayer.lookupTable ) {
+ return true;
+ }
+ return false;
+ });
+ reloadLayers();
+ };
+
// FIXME: OL3
// Don't call directly, use an event instead
self.preload = function() {
@@ -247,7 +268,8 @@ wv.map.ui = wv.map.ui || function(models, config) {
resolutions: matrixSet.resolutions,
matrixIds: matrixIds,
tileSize: matrixSet.tileSize[0]
- })
+ }),
+ tileClass: wv.map.ui.lookupTileClass
})
});
return layer;
@@ -459,3 +481,51 @@ wv.map.ui = wv.map.ui || function(models, config) {
return self;
};
+
+wv.map.ui.lookupTileClass = function(tileCoord, tileState, src, crossOrigin,
+ tileLoadFunction) {
+
+ var image = new Image();
+ var canvas = document.createElement("canvas");
+
+ var self = new ol.ImageTile(tileCoord, tileState, null, "anonymous",
+ tileLoadFunction);
+
+ self.getImage = function(opt_context) {
+ return canvas;
+ };
+
+ self.getKey = function() {
+ return image.src;
+ };
+
+ self.load = function() {
+ if ( self.state == ol.TileState.IDLE ) {
+ self.state = ol.TileState.LOADING;
+ image.addEventListener("load", function() {
+ canvas = document.createElement("canvas");
+ w = image.width;
+ h = image.height;
+ canvas.width = w;
+ canvas.height = h;
+ var g = canvas.getContext("2d");
+ g.drawImage(image, 0, 0);
+ var imageData = g.getImageData(0, 0, canvas.width,
+ canvas.height);
+ var pixelData = imageData.data;
+ for ( var i = 0; i < w * h * 4; i += 4 ) {
+ pixelData[i+1] = 0;
+ pixelData[i+2] = 0;
+ }
+ g.putImageData(imageData, 0, 0);
+ self.state = ol.TileState.LOADED;
+ self.changed();
+ });
+ image.crossOrigin = "anonymous";
+ image.src = src;
+ }
+ };
+
+ return self;
+
+};