Interactive interface for browsing global, full-resolution satellite imagery
AB model updates #986
Benjamin King3513651d0004
diff --git a/web/js/compare/model.js b/web/js/compare/model.jsindex 7c7c6ae17..e24324a3b 100644--- a/web/js/compare/model.js+++ b/web/js/compare/model.js@@ -14,32 +14,36 @@ export function compareModel(models, config) {};self.toggleState = function() {self.isCompareA = !self.isCompareA;+ models.layers.updateLayerGroup(self.isCompareA ? 'active' : 'activeB');+ models.date.setActiveDate(self.isCompareA ? 'selected' : 'selectedB');self.events.trigger('toggle-state');self.events.trigger('change');};self.setMode = function(mode) {self.mode = mode;+ self.events.trigger('mode');self.events.trigger('change');};self.save = function(state) {- if (self.active !== state.c) {- state.c = self.active;- }- if (self.isCompareA !== state.ca) {- state.ca = self.isCompareA;- }- if (self.mode !== state.cm) {- state.cm = self.mode;+ if (!self.active) {+ if (state.ca) delete state.ca;+ if (state.cm) delete state.ca;+ } else {+ if (self.isCompareA !== state.ca) {+ state.ca = self.isCompareA;+ }+ if (self.mode !== state.cm) {+ state.cm = self.mode;+ }}};self.load = function(state) {- if (state.c) {- self.active = state.c === 'true';- }if (state.ca) {+ self.active = true;self.isCompareA = state.ca === 'true';}if (state.cm) {+ self.active = true;self.mode = state.cm;}};diff --git a/web/js/date/model.js b/web/js/date/model.jsindex 77f704356..be9570344 100644--- a/web/js/date/model.js+++ b/web/js/date/model.js@@ -6,46 +6,67 @@ export function dateModel(config, spec) {var self = {};self.events = util.events();self.selected = null;- self.selectedA = null;self.selectedB = null;self.activeDate = 'selected';- self.monthAbbr = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',- 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];+ self.monthAbbr = [+ 'JAN',+ 'FEB',+ 'MAR',+ 'APR',+ 'MAY',+ 'JUN',+ 'JUL',+ 'AUG',+ 'SEP',+ 'OCT',+ 'NOV',+ 'DEC'+ ];- var init = function () {+ var init = function() {var initial = spec.initial || util.now();self.select(initial);- if (config.features.compare) {- self.select(initial, 'selectedA');- self.select(util.dateAdd(initial, 'day', -5), 'selectedB');+ };+ self.initCompare = function() {+ if (!self.selectedB) {+ self.select(util.dateAdd(self.selected, 'day', -5), 'selectedB');}};-- self.string = function () {+ self.setActiveDate = function(dateString) {+ self.activeDate = dateString;+ self.events.trigger('state-update');+ };+ self.string = function() {return util.toISOStringDate(self.selected);};- self.select = function (date, selection) {- selection = selection || 'selected';+ self.select = function(date, selectionStr) {+ selectionStr = selectionStr || self.activeDate;date = self.clamp(date);var updated = false;- if (!self[selection] || date.getTime() !== self[selection].getTime()) {- self[selection] = date;- if (selection === self.activeDate) {- self.events.trigger('select', date);+ if (+ !self[selectionStr] ||+ date.getTime() !== self[selectionStr].getTime()+ ) {+ self[selectionStr] = date;+ if (selectionStr === self.activeDate) {+ self.events.trigger('select', date, selectionStr);}updated = true;}return updated;};- self.add = function (interval, amount, selection) {- selection = selection || self.selected;- self.select(util.dateAdd(selection, interval, amount), selection);+ self.add = function(interval, amount, selectionStr) {+ selectionStr = selectionStr || self.activeDate;+ self.select(+ util.dateAdd(self[selectionStr], interval, amount),+ selectionStr+ );};- self.clamp = function (date) {+ self.clamp = function(date) {if (self.maxZoom > 3) {if (date > util.now()) {date = util.now();@@ -64,7 +85,7 @@ export function dateModel(config, spec) {return date;};- self.isValid = function (date) {+ self.isValid = function(date) {if (self.maxZoom > 3) {if (date > util.now()) {return false;@@ -83,49 +104,57 @@ export function dateModel(config, spec) {return true;};- self.minDate = function () {+ self.minDate = function() {if (config.startDate) {return util.parseDateUTC(config.startDate);}return util.minDate();};- self.maxDate = function () {+ self.maxDate = function() {return util.now();};self.maxZoom = null;var dateToStringForUrl = function(date) {- return date.toISOString()- .split('T')[0] + '-' + 'T' + self.selected.toISOString()- .split('T')[1].slice(0, -5) + 'Z';+ return (+ date.toISOString().split('T')[0] ++ '-' ++ 'T' ++ self.selected+ .toISOString()+ .split('T')[1]+ .slice(0, -5) ++ 'Z'+ );};- self.save = function (state) {+ self.save = function(state) {state.t = dateToStringForUrl(self.selected);if (self.selectedZoom) {state.z = self.selectedZoom.toString();}if (config.features.compare) {- state.t1 = dateToStringForUrl(self.selectedA);- state.t2 = dateToStringForUrl(self.selectedB);+ if (self.selectedB) {+ state.t1 = dateToStringForUrl(self.selectedB);+ }}};- self.load = function (state) {+ self.load = function(state) {+ if (state.ca === 'false') {+ self.setActiveDate('selectedB');+ }if (state.t) {- self.select(state.t);+ self.select(state.t, 'selected');}if (state.z) {self.selectedZoom = Number(state.z);}if (state.t1) {- self.select(state.t1, 'selectedA');- }- if (state.t2) {- self.select(state.t2, 'selectedB');+ self.select(state.t1, 'selectedB');}};init();return self;-};+}diff --git a/web/js/layers/model.js b/web/js/layers/model.jsindex e71559301..28b9287d9 100644--- a/web/js/layers/model.js+++ b/web/js/layers/model.js@@ -5,14 +5,12 @@ import lodashFind from 'lodash/find';import lodashFindIndex from 'lodash/findIndex';import lodashIsUndefined from 'lodash/isUndefined';import lodashCloneDeep from 'lodash/cloneDeep';-import { getActiveDateString } from '../compare/util';import util from '../util/util';var loaded = false;-self.activeLayers = 'active';export function layersModel(models, config) {var self = {};-+ self.activeLayers = 'active';var split = { active: 0, activeB: 0 };self.events = util.events();@@ -22,7 +20,9 @@ export function layersModel(models, config) {var init = function() {self.reset();};-+ self.updateLayerGroup = function(newGroupStr) {+ self.activeLayers = newGroupStr;+ };self.reset = function() {self.clear();if (config.defaults && config.defaults.startingLayers) {@@ -60,8 +60,7 @@ export function layersModel(models, config) {return baselayers.concat(overlays);};-<<<<<<< HEAD- self.getTitles = function (layerId, proj) {+ self.getTitles = function(layerId, proj) {try {proj = proj || models.proj.selected.id;var title, subtitle, tags;@@ -82,32 +81,19 @@ export function layersModel(models, config) {};} catch (err) {throw new Error(`error in layer ${layerId}: ${err}`);-=======- self.getTitles = function(layerId, proj) {- proj = proj || models.proj.selected.id;- var title, subtitle, tags;- if (config.layers[layerId].projections[proj]) {- var forProj = config.layers[layerId].projections[proj];- title = forProj.title;- subtitle = forProj.subtitle;- tags = forProj.tags;->>>>>>> update Date and layer models #986}};- self.available = function(id, date, activeLayers) {- activeLayers = activeLayers || self.active;- var activeDateString = getActiveDateString(- models.compare.abIsActive,- models.compareisCompareA- );- date = date || models.date[activeDateString] || models.date.selected;+ self.available = function(id, date, activeLayers, activeLayersString) {+ activeLayers = activeLayers || self[activeLayersString] || self.active;+ date = date || models.date[models.date.activeDate];var range = self.dateRange({layer: id},activeLayers);+if (range) {if (date < range.start || date > range.end) {return false;@@ -129,7 +115,7 @@ export function layersModel(models, config) {};self.dateRange = function(spec, activeLayers) {- activeLayers = activeLayers || self.active;+ activeLayers = activeLayers || self[self.activeLayers];spec = spec || {};var layers = spec.layer? [@@ -185,7 +171,7 @@ export function layersModel(models, config) {};self.add = function(id, spec, activeLayerString) {- activeLayerString = activeLayerString || 'active';+ activeLayerString = activeLayerString || self.activeLayers;if (lodashFind(self[activeLayerString], {id: id@@ -217,7 +203,7 @@ export function layersModel(models, config) {};self.remove = function(id, activeLayerString) {- activeLayerString = activeLayerString || 'active';+ activeLayerString = activeLayerString || self.activeLayers;var index = lodashFindIndex(self[activeLayerString], {id: id});@@ -233,7 +219,7 @@ export function layersModel(models, config) {};self.replace = function(idOld, idNew, activeLayerString) {- activeLayerString = activeLayerString || 'active';+ activeLayerString = activeLayerString || self.activeLayers;var index = lodashFindIndex(self[activeLayerString], {id: idOld});@@ -247,9 +233,18 @@ export function layersModel(models, config) {self.events.trigger('update');self.events.trigger('change');};-+ self.replaceSubGroup = function(newSubGroup, activeLayerString, subGroup) {+ activeLayerString = activeLayerString || self.activeLayers;+ var layers = self.get({ group: 'all' }, self[activeLayerString]);+ var baseLayers =+ subGroup === 'baselayers' ? newSubGroup : layers.baselayers;+ var overlays = subGroup === 'overlays' ? newSubGroup : layers.overlays;+ self[activeLayerString] = baseLayers.concat(overlays);+ self.events.trigger('update');+ self.events.trigger('change');+ };self.clear = function(projId, activeLayerString) {- activeLayerString = activeLayerString || 'active';+ activeLayerString = activeLayerString || self.activeLayers;if (!self[activeLayerString]) self[activeLayerString] = [];projId = projId || models.proj.selected.id;var defs = self[activeLayerString].slice(0);@@ -261,7 +256,7 @@ export function layersModel(models, config) {};self.pushToBottom = function(id, activeLayersString) {- activeLayersString = activeLayersString || 'active';+ activeLayersString = activeLayersString || self.activeLayers;var oldIndex = lodashFindIndex(self[activeLayersString], {id: id});@@ -280,7 +275,7 @@ export function layersModel(models, config) {};self.moveBefore = function(sourceId, targetId, activeLayersString) {- activeLayersString = activeLayersString || 'active';+ activeLayersString = activeLayersString || self.activeLayers;var sourceIndex = lodashFindIndex(self[activeLayersString], {id: sourceId});@@ -306,7 +301,7 @@ export function layersModel(models, config) {};self.setVisibility = function(id, visible, activeLayersString) {- activeLayersString = activeLayersString || 'active';+ activeLayersString = activeLayersString || self.activeLayers;var def = lodashFind(self[activeLayersString], {id: id});@@ -321,7 +316,7 @@ export function layersModel(models, config) {}};self.toggleVisibility = function(id, activeLayersString) {- activeLayersString = activeLayersString || 'active';+ activeLayersString = activeLayersString || self.activeLayers;var index = lodashFindIndex(self[activeLayersString], {id: id});@@ -329,21 +324,22 @@ export function layersModel(models, config) {var visibility = !self[activeLayersString][index].visible;self[activeLayersString][index].visible = visibility;self.events.trigger('visibility', id, visibility, activeLayersString);+ self.events.trigger('change');};self.setOpacity = function(id, opacity, activeLayersString) {- activeLayersString = activeLayersString || 'active';+ activeLayersString = activeLayersString || self.activeLayers;var def = lodashFind(self[activeLayersString], {id: id});if (def.opacity !== opacity) {def.opacity = opacity;- self.events.trigger('opacity', def, opacity);+ self.events.trigger('opacity', def, opacity, activeLayersString);self.events.trigger('change');}};self.isRenderable = function(id, activeLayers, date) {- activeLayers = activeLayers || self.active;+ activeLayers = activeLayers || self[self.activeLayers];var def = lodashFind(activeLayers, {id: id});@@ -385,23 +381,28 @@ export function layersModel(models, config) {};self.save = function(state) {- var layers;state.l = state.l || [];- if (config.features.compare) {- state.l1 = state.l1 || [];- state.l2 = state.l2 || [];- layers = [- {- state: 'l',- str: 'active'- },- {- state: 'l1',- str: 'activeB'- }- ];- } else {- layers = [{ state: 'l', active: 'active' }];+ var layers = [{ state: 'l', str: 'active' }];+ if (models.compare) {+ if (models.compare.active) {+ state.l1 = state.l1 || [];+ layers = [+ {+ state: 'l',+ str: 'active'+ },+ {+ state: 'l1',+ str: 'activeB'+ }+ ];+ }+ if (!models.compare.active && !models.compare.isCompareA) {+ layers = [{ state: 'l', str: 'activeB' }];+ }+ if (!models.compare.active) {+ if (state.l1) delete state.l1;+ }}lodashEach(layers, obj => {lodashEach(self.get({}, self[obj.str]), function(def) {@@ -482,6 +483,9 @@ export function layersModel(models, config) {});}});+ if (state.ca && state.ca !== 'true') {+ self.activeLayers = 'activeB';+ }loaded = true;};var forGroup = function(group, spec, activeLayers) {diff --git a/web/js/natural-events/model.js b/web/js/natural-events/model.jsindex 5f9e239fa..f9cd7d294 100644--- a/web/js/natural-events/model.js+++ b/web/js/natural-events/model.js@@ -15,19 +15,19 @@ export default function naturalEventsModel(models, config, ui) {*/self.events = util.events();- self.save = function (state) {+ self.save = function(state) {if (self.active) {var id = ui.naturalEvents.selected.id;var date = ui.naturalEvents.selected.date;- var value = id ? date ? [id, date].join(',') : id : true;+ var value = id ? (date ? [id, date].join(',') : id) : true;state.e = value;}};- self.load = function (state) {+ self.load = function(state) {if (!state.e) return;- models.wv.events.on('startup', function () {- ui.sidebar.selectTab('events');+ models.wv.events.on('startup', function() {+ self.events.trigger('activate');});var values = state.e.split(',');var id = values[0] || '';@@ -35,11 +35,11 @@ export default function naturalEventsModel(models, config, ui) {id = id.match(/^EONET_[0-9]+/i) ? values[0] : null;date = date.match(/\d{4}-\d{2}-\d{2}/) ? values[1] : null;if (id) {- self.events.on('hasData', function () {+ self.events.on('hasData', function() {ui.naturalEvents.selectEvent(id, date);});}};return self;-};+}diff --git a/web/js/palettes/model.js b/web/js/palettes/model.jsindex a620afba9..8c37bb99c 100644--- a/web/js/palettes/model.js+++ b/web/js/palettes/model.js@@ -16,6 +16,7 @@ export function palettesModel(models, config) {var self = {};self.events = util.events();self.active = {};+ self.activeB = {};self.getRenderedPalette = function (layerId, index) {var name = config.layers[layerId].palette.id;@@ -36,9 +37,10 @@ export function palettesModel(models, config) {return palette;};- var prepare = function (layerId) {- self.active[layerId] = self.active[layerId] || {};- var active = self.active[layerId];+ var prepare = function(layerId, groupStr) {+ groupStr = groupStr || 'active';+ self[groupStr][layerId] = self[groupStr][layerId] || {};+ var active = self[groupStr][layerId];active.maps = active.maps || [];lodashEach(self.getRenderedPalette(layerId).maps,function (palette, index) {@@ -48,37 +50,35 @@ export function palettesModel(models, config) {});};- self.allowed = function (layerId) {+ self.allowed = function(layerId) {if (!palettes.supported) {return false;}- let palette = config.layers[layerId].palette;- if (!palette || palette.immutable) {- return false;- }- return palette;+ return config.layers[layerId].palette;};- self.setCustom = function (layerId, paletteId, index) {+ self.setCustom = function(layerId, paletteId, index, groupStr) {+ groupStr = groupStr || 'active';if (!config.layers[layerId]) {throw new Error('Invalid layer: ' + layerId);}- prepare(layerId);- index = (lodashIsUndefined(index)) ? 0 : index;- var active = self.active[layerId];+ prepare(layerId, groupStr);+ index = lodashIsUndefined(index) ? 0 : index;+ var active = self[groupStr][layerId];var palette = active.maps[index];if (palette.custom === paletteId) {return;}palette.custom = paletteId;- updateLookup(layerId);- self.events.trigger('set-custom', layerId, active);+ updateLookup(layerId, groupStr);+ self.events.trigger('set-custom', layerId, active, groupStr);self.events.trigger('change');};- self.clearCustom = function (layerId, index) {- index = (lodashIsUndefined(index)) ? 0 : index;- var active = self.active[layerId];+ self.clearCustom = function(layerId, index, groupStr) {+ groupStr = groupStr || 'active';+ index = lodashIsUndefined(index) ? 0 : index;+ var active = self[groupStr][layerId];if (!active) {return;}@@ -87,27 +87,27 @@ export function palettesModel(models, config) {return;}delete palette.custom;- updateLookup(layerId);- self.events.trigger('clear-custom', layerId);+ updateLookup(layerId, groupStr);+ self.events.trigger('clear-custom', layerId, groupStr);self.events.trigger('change');};- self.setRange = function (layerId, min, max, squash, index) {+ self.setRange = function(layerId, min, max, squash, index, groupStr) {+ groupStr = groupStr || 'active';prepare(layerId);- index = (lodashIsUndefined(index)) ? 0 : index;- var palette = self.active[layerId].maps[index];+ index = lodashIsUndefined(index) ? 0 : index;+ var palette = self[groupStr][layerId].maps[index];if (min === 0) {min = undefined;}- if (max === self.get(layerId, index)- .entries.values.length - 1) {+ if (max === self.get(layerId, index, groupStr).entries.values.length - 1) {max = undefined;}palette.min = min;palette.max = max;palette.squash = squash;- updateLookup(layerId);- self.events.trigger('range', layerId, palette.min, palette.max);+ updateLookup(layerId, groupStr);+ self.events.trigger('range', layerId, palette.min, palette.max, groupStr);self.events.trigger('change');};@@ -129,10 +129,11 @@ export function palettesModel(models, config) {* object.* @return {object} object including the entries and legend*/- self.get = function (layerId, index) {- index = (lodashIsUndefined(index)) ? 0 : index;- if (self.active[layerId]) {- return self.active[layerId].maps[index];+ self.get = function(layerId, index, groupStr) {+ groupStr = groupStr || 'active';+ index = lodashIsUndefined(index) ? 0 : index;+ if (self[groupStr][layerId]) {+ return self[groupStr][layerId].maps[index];}return self.getRenderedPalette(layerId, index);};@@ -147,8 +148,9 @@ export function palettesModel(models, config) {* object.* @return {object} object of the legend*/- self.getLegend = function (layerId, index) {- var value = self.get(layerId, index);+ self.getLegend = function(layerId, index, groupStr) {+ groupStr = groupStr || 'active';+ var value = self.get(layerId, index, groupStr);return value.legend || value.entries;};/**@@ -167,67 +169,82 @@ export function palettesModel(models, config) {return palette.legend || palette.entries;};- self.getLegends = function (layerId) {+ self.getLegends = function(layerId, groupStr) {+ groupStr = groupStr || 'active';var legends = [];var count = self.getCount(layerId);for (var i = 0; i < count; i++) {- legends.push(self.getLegend(layerId, i));+ legends.push(self.getLegend(layerId, i, groupStr));}return legends;};// Is a canvas required?- self.isActive = function (layerId) {- return self.active[layerId];+ self.isActive = function(layerId, group) {+ group = group || 'active';+ return self[group][layerId];};// Looks up options/colormaps/layer.xml colormap entry- self.getLookup = function (layerId) {- return self.active[layerId].lookup;+ self.getLookup = function(layerId, groupstr) {+ groupstr = groupstr || 'active';+ return self[groupstr][layerId].lookup;};- self.clear = function () {+ self.clear = function() {self.active = {};self.events.trigger('update');};- self.restore = function (active) {+ self.restore = function(active) {self.active = active;self.events.trigger('update');};- var getMinValue = function (v) {- return (v.length) ? v[0] : v;+ var getMinValue = function(v) {+ return v.length ? v[0] : v;};- var getMaxValue = function (v) {- return (v.length) ? v[v.length - 1] : v;+ var getMaxValue = function(v) {+ return v.length ? v[v.length - 1] : v;};- self.save = function (state) {+ self.save = function(state) {+ var groupArray = ['active'];if (self.inUse() && !state.l) {throw new Error('No layers in state');}- lodashEach(self.active, function (def, layerId) {- if (!lodashFind(models.layers.get(), {- id: layerId- })) {- return;- }- if (self.getCount(layerId) > 1) {- self.saveMulti(state, layerId);- } else {- self.saveSingle(state, layerId);- }+ if (models.compare && models.compare.active) {+ groupArray = ['active', 'activeB'];+ }+ lodashEach(groupArray, groupStr => {+ lodashEach(self[groupStr], function(def, layerId) {+ if (+ !lodashFind(models.layers.get({}, groupStr), {+ id: layerId+ })+ ) {+ return;+ }+ if (self.getCount(layerId) > 1) {+ self.saveMulti(state, layerId, groupStr);+ } else {+ self.saveSingle(state, layerId, groupStr);+ }+ });});};- self.saveSingle = function (state, layerId) {- var attr = lodashFind(state.l, {+ self.saveSingle = function(state, layerId, groupStr) {+ groupStr = groupStr || 'active';+ var stateStr = 'l';++ if (groupStr === 'activeB') stateStr = 'l1';++ var attr = lodashFind(state[stateStr], {id: layerId- })- .attributes;- var def = self.get(layerId);+ }).attributes;+ var def = self.get(layerId, undefined, groupStr);if (def.custom) {attr.push({id: 'palette',@@ -255,7 +272,9 @@ export function palettesModel(models, config) {}};- self.saveMulti = function (state, layerId) {+ self.saveMulti = function(state, layerId, groupStr) {+ groupStr = groupStr || 'active';+ var stateStr = 'l';var palettes = [];var hasPalettes = false;var min = [];@@ -264,9 +283,10 @@ export function palettesModel(models, config) {var hasMax = false;var squash = [];var hasSquash = false;+ if (groupStr === 'activeB') stateStr = 'l1';for (var i = 0; i < self.getCount(layerId); i++) {- var def = self.get(layerId, i);+ var def = self.get(layerId, i, groupStr);if (def.custom) {palettes.push(def.custom);hasPalettes = true;@@ -296,10 +316,9 @@ export function palettesModel(models, config) {}}- var attr = lodashFind(state.l, {+ var attr = lodashFind(state[stateStr], {id: layerId- })- .attributes;+ }).attributes;if (hasPalettes) {attr.push({id: 'palette',@@ -326,11 +345,12 @@ export function palettesModel(models, config) {}};- self.key = function (layerId) {- if (!self.isActive(layerId)) {+ self.key = function(layerId, groupStr) {+ groupStr = groupStr || 'active';+ if (!self.isActive(layerId, groupStr)) {return '';}- var def = self.get(layerId);+ var def = self.get(layerId, undefined, groupStr);var keys = [];if (def.custom) {keys.push('palette=' + def.custom);@@ -347,92 +367,104 @@ export function palettesModel(models, config) {return keys.join(',');};- self.load = function (state, errors) {+ self.load = function(state, errors) {+ var stateArray = [{ stateStr: 'l', groupStr: 'active' }];if (!palettes.supported) {return;}-- lodashEach(state.l, function (layerDef) {- var layerId = layerDef.id;- var minValue, maxValue;- var min = [];- var max = [];- var squash = [];- var count = 0;- lodashEach(layerDef.attributes, function (attr) {- var values;- if (attr.id === 'palette') {- count = self.getCount(layerId);- values = util.toArray(attr.value.split(';'));- lodashEach(values, function (value, index) {- try {- self.setCustom(layerId, value, index);- } catch (error) {- errors.push('Invalid palette: ' + value);- }- });- }- if (attr.id === 'min') {- count = self.getCount(layerId);- values = util.toArray(attr.value.split(';'));- lodashEach(values, function (value, index) {- if (value === '') {- min.push(undefined);- return;- }- minValue = parseFloat(value);- if (lodashIsNaN(minValue)) {- errors.push('Invalid min value: ' + value);- } else {- min.push(findIndex(layerId, 'min', minValue, index));- }- });- }- if (attr.id === 'max') {- count = self.getCount(layerId);- values = util.toArray(attr.value.split(';'));- lodashEach(values, function (value, index) {- if (value === '') {- max.push(undefined);- return;- }- maxValue = parseFloat(value);- if (lodashIsNaN(maxValue)) {- errors.push('Invalid max value: ' + value);- } else {- max.push(findIndex(layerId, 'max', maxValue, index));- }- });- }- if (attr.id === 'squash') {- count = self.getCount(layerId);- if (attr.value === true) {- squash[0] = true;- } else {+ if (state.l1) {+ stateArray = [+ { stateStr: 'l', groupStr: 'active' },+ { stateStr: 'l1', groupStr: 'activeB' }+ ];+ }+ lodashEach(stateArray, stateObj => {+ lodashEach(state[stateObj.stateStr], function(layerDef) {+ var layerId = layerDef.id;+ var minValue, maxValue;+ var min = [];+ var max = [];+ var squash = [];+ var count = 0;+ lodashEach(layerDef.attributes, function(attr) {+ var values;+ if (attr.id === 'palette') {+ count = self.getCount(layerId);+ values = util.toArray(attr.value.split(';'));+ lodashEach(values, function(value, index) {+ try {+ self.setCustom(layerId, value, index, stateObj.groupStr);+ } catch (error) {+ errors.push('Invalid palette: ' + value);+ }+ });+ }+ if (attr.id === 'min') {+ count = self.getCount(layerId);values = util.toArray(attr.value.split(';'));- lodashEach(values, function (value) {- squash.push(value === 'true');+ lodashEach(values, function(value, index) {+ if (value === '') {+ min.push(undefined);+ return;+ }+ minValue = parseFloat(value);+ if (lodashIsNaN(minValue)) {+ errors.push('Invalid min value: ' + value);+ } else {+ min.push(+ findIndex(layerId, 'min', minValue, index, stateObj.groupStr)+ );+ }});}+ if (attr.id === 'max') {+ count = self.getCount(layerId);+ values = util.toArray(attr.value.split(';'));+ lodashEach(values, function(value, index) {+ if (value === '') {+ max.push(undefined);+ return;+ }+ maxValue = parseFloat(value);+ if (lodashIsNaN(maxValue)) {+ errors.push('Invalid max value: ' + value);+ } else {+ max.push(+ findIndex(layerId, 'max', maxValue, index, stateObj.groupStr)+ );+ }+ });+ }+ if (attr.id === 'squash') {+ count = self.getCount(layerId);+ if (attr.value === true) {+ squash[0] = true;+ } else {+ values = util.toArray(attr.value.split(';'));+ lodashEach(values, function(value) {+ squash.push(value === 'true');+ });+ }+ }+ });+ if (min.length > 0 || max.length > 0) {+ for (var i = 0; i < count; i++) {+ var vmin = min.length > 0 ? min[i] : undefined;+ var vmax = max.length > 0 ? max[i] : undefined;+ var vsquash = squash.length > 0 ? squash[i] : undefined;+ self.setRange(layerId, vmin, vmax, vsquash, i, stateObj.groupStr);+ }}});- if (min.length > 0 || max.length > 0) {- for (var i = 0; i < count; i++) {- var vmin = (min.length > 0) ? min[i] : undefined;- var vmax = (max.length > 0) ? max[i] : undefined;- var vsquash = (squash.length > 0) ? squash[i] : undefined;- self.setRange(layerId, vmin, vmax, vsquash, i);- }- }});};- var findIndex = function (layerId, type, value, index) {+ var findIndex = function(layerId, type, value, index, groupStr) {+ groupStr = groupStr || 'active';index = index || 0;- var values = self.get(layerId, index)- .entries.values;+ var values = self.get(layerId, index, groupStr).entries.values;var result;- lodashEach(values, function (check, index) {+ lodashEach(values, function(check, index) {var min = getMinValue(check);var max = getMaxValue(check);if (type === 'min' && value === min) {@@ -449,11 +481,12 @@ export function palettesModel(models, config) {// If any custom rendering is being used, image download must turn it// off- self.inUse = function () {- var layers = models.layers.get();+ self.inUse = function(groupStr) {+ groupStr = groupStr || 'active';+ var layers = models.layers.get({}, groupStr);var found = false;- lodashEach(layers, function (layer) {- if (self.active[layer.id]) {+ lodashEach(layers, function(layer) {+ if (self[groupStr][layer.id]) {found = true;return false;}@@ -461,11 +494,12 @@ export function palettesModel(models, config) {return found;};- var useLookup = function (layerId) {+ var useLookup = function(layerId, groupStr) {+ groupStr = groupStr || 'active';var use = false;- var active = self.active[layerId].maps;+ var active = self[groupStr][layerId].maps;- lodashEach(active, function (palette, index) {+ lodashEach(active, function(palette, index) {if (palette.custom) {use = true;return false;@@ -478,7 +512,10 @@ export function palettesModel(models, config) {if (palette.max >= rendered.entries.values.length) {delete palette.max;}- if (!lodashIsUndefined(palette.min) || !lodashIsUndefined(palette.max)) {+ if (+ !lodashIsUndefined(palette.min) ||+ !lodashIsUndefined(palette.max)+ ) {use = true;return false;}@@ -487,14 +524,15 @@ export function palettesModel(models, config) {return use;};- var updateLookup = function (layerId) {- if (!useLookup(layerId)) {- delete self.active[layerId];+ var updateLookup = function(layerId, groupStr) {+ groupStr = groupStr || 'active';+ if (!useLookup(layerId, groupStr)) {+ delete self[groupStr][layerId];return;}var lookup = {};- var active = self.active[layerId].maps;- lodashEach(active, function (palette, index) {+ var active = self[groupStr][layerId].maps;+ lodashEach(active, function(palette, index) {var oldLegend = palette.legend;var entries = palette.entries;var legend = {@@ -508,9 +546,15 @@ export function palettesModel(models, config) {id: oldLegend.id};var source = entries.colors;+<<<<<<< HEADvar target = (palette.custom)? self.getCustomPalette(palette.custom).colors : source;+=======+ var target = palette.custom+ ? self.getCustom(palette.custom).colors+ : source;+>>>>>>> AB model updates #986var min = palette.min || 0;var max = palette.max || source.length;@@ -518,7 +562,7 @@ export function palettesModel(models, config) {var sourceCount = source.length;var targetCount = target.length;- lodashEach(source, function (color, index) {+ lodashEach(source, function(color, index) {var targetColor;if (index < min || index > max) {targetColor = '00000000';@@ -541,9 +585,12 @@ export function palettesModel(models, config) {}legend.colors.push(targetColor);var lookupSource =- lodashParseInt(color.substring(0, 2), 16) + ',' +- lodashParseInt(color.substring(2, 4), 16) + ',' +- lodashParseInt(color.substring(4, 6), 16) + ',' ++ lodashParseInt(color.substring(0, 2), 16) ++ ',' ++ lodashParseInt(color.substring(2, 4), 16) ++ ',' ++ lodashParseInt(color.substring(4, 6), 16) ++ ',' +lodashParseInt(color.substring(6, 8), 16);var lookupTarget = {r: lodashParseInt(targetColor.substring(0, 2), 16),@@ -555,8 +602,8 @@ export function palettesModel(models, config) {});palette.legend = legend;});- self.active[layerId].lookup = lookup;+ self[groupStr][layerId].lookup = lookup;};return self;-};+}