Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

exported map files

Benjamin Kingeaa58723fba8
diff --git a/web/js/map/wv.map.datelinebuilder.js b/web/js/map/wv.map.datelinebuilder.js
index 04e2f91ce..8d9069523 100644
--- a/web/js/map/wv.map.datelinebuilder.js
+++ b/web/js/map/wv.map.datelinebuilder.js
@@ -8,7 +8,7 @@ import util from '../util/util';
var map, overlay1, overlay2, textFactory, lineFactory, textOverlay1, textOverlay2,
lineLeft, lineRight, textLeft, textRight, proj;
-export default function datelinebuilder(models, config) {
+export default function (models, config) {
var self = {};
/*
* Sets globals and event listeners
diff --git a/web/js/map/wv.map.model.js b/web/js/map/wv.map.model.js
index 3c73ff9f9..ca00e1e78 100644
--- a/web/js/map/wv.map.model.js
+++ b/web/js/map/wv.map.model.js
@@ -1,16 +1,12 @@
-var wv = wv || {};
-wv.map = wv.map || {};
+import ol from 'openlayers';
+import util from '../util/util';
+import { clone as _clone } from 'lodash';
-// FIXME: The code is like this for historical reasons and should be refactored
-// at some point.
-/*
- * @Class
- */
-wv.map.model = wv.map.model || function (models, config) {
+export default function(models, config) {
var self = {};
self.extent = null;
- self.events = wv.util.events();
+ self.events = util.events();
self.rotation = 0;
/*
* Emits update event
@@ -51,7 +47,7 @@ wv.map.model = wv.map.model || function (models, config) {
if (ol.extent.intersects(extent, maxExtent)) {
self.extent = state.v;
} else {
- self.extent = _.clone(proj.maxExtent);
+ self.extent = _clone(proj.maxExtent);
errors.push({
message: 'Extent outside of range'
});
@@ -76,7 +72,7 @@ wv.map.model = wv.map.model || function (models, config) {
* @returns {void}
*/
self.save = function (state) {
- state.v = _.clone(self.extent);
+ state.v = _clone(self.extent);
if (self.rotation !== 0.0 && self.rotation !== 0 && models.proj.selected.id !== 'geographic') {
state.r = (self.rotation * (180.0 / Math.PI))
.toPrecision(6);
@@ -99,7 +95,7 @@ wv.map.model = wv.map.model || function (models, config) {
* @returns {object} Extent Array
*/
self.getLeadingExtent = function () {
- var curHour = wv.util.now()
+ var curHour = util.now()
.getUTCHours();
// For earlier hours when data is still being filled in, force a far eastern perspective
diff --git a/web/js/map/wv.map.precachetile.js b/web/js/map/wv.map.precachetile.js
index 67904eed8..dddfad5e2 100644
--- a/web/js/map/wv.map.precachetile.js
+++ b/web/js/map/wv.map.precachetile.js
@@ -1,10 +1,7 @@
-var wv = wv || {};
-wv.map = wv.map || {};
+import {each as _each} from 'lodash';
+import ol from 'openlayers';
-/*
- * @Class
- */
-wv.map.precachetile = wv.map.precachetile || function (models, config, cache, parent) {
+export default function (models, config, cache, parent) {
/*
* Loaded the layers that are needed for any one date.
* Checks the cache to see if a layer has already
@@ -20,14 +17,12 @@ wv.map.precachetile = wv.map.precachetile || function (models, config, cache, pa
*/
self.promiseDay = function (date) {
var viewState;
- var currentZ;
var frameState;
var extent;
var pixelRatio;
var layers;
var map;
var promiseArray;
- var projExtent;
layers = getActiveLayersWithData(date);
map = parent.selected;
@@ -37,10 +32,7 @@ wv.map.precachetile = wv.map.precachetile || function (models, config, cache, pa
promiseArray = layers.map(function (def) {
var key;
var layer;
- var renderer;
- var i = 0;
- i = 0;
key = parent.layerKey(def, {
date: date
});
@@ -64,7 +56,7 @@ wv.map.precachetile = wv.map.precachetile || function (models, config, cache, pa
var layers;
var arra = [];
layers = models.layers.get();
- _.each(layers, function (layer) {
+ _each(layers, function (layer) {
if (layer.visible && new Date(layer.startDate > date)) {
arra.push(layer);
}
diff --git a/web/js/map/wv.map.rotate.js b/web/js/map/wv.map.rotate.js
index 5005c5620..e48cd87ee 100644
--- a/web/js/map/wv.map.rotate.js
+++ b/web/js/map/wv.map.rotate.js
@@ -1,12 +1,8 @@
-var wv = wv || {};
-
-wv.map = wv.map || {};
-/*
- * @Class
- */
-wv.map.rotate = wv.map.rotate || function (ui, models, map) {
- this.evts = wv.util.events();
- var model = models.map;
+import $ from 'jquery';
+import util from '../util/util';
+
+export default function(ui, models, map) {
+ this.evts = util.events();
this.intervalId = null;
var self = this;
@@ -153,8 +149,7 @@ wv.map.rotate = wv.map.rotate || function (ui, models, map) {
* @returns {void}
*/
this.updateRotation = function () {
- var deg,
- radians,
+ var radians,
currentView,
currentDeg;
diff --git a/web/js/map/wv.map.runningdata.js b/web/js/map/wv.map.runningdata.js
index e0b361526..2e95631a5 100644
--- a/web/js/map/wv.map.runningdata.js
+++ b/web/js/map/wv.map.runningdata.js
@@ -1,7 +1,11 @@
-var wv = wv || {};
+import $ from 'jquery';
+import util from '../util/util';
+import {
+ differenced as _difference,
+ each as _each
+} from 'lodash';
-wv.map = wv.map || {};
-wv.map.runningdata = wv.map.runningdata || function (models) {
+export default function(models) {
var self;
var $productsBox;
var productsBoxHeight;
@@ -67,7 +71,7 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
// }
for (var i = 0, len = legend.colors.length; i < len; i++) {
- if (wv.util.hexColorDelta(legend.colors[i], hex) < 5) { // If the two colors are close
+ if (util.hexColorDelta(legend.colors[i], hex) < 5) { // If the two colors are close
return {
label: legend.tooltips[i] + ' ' + units,
len: len,
@@ -184,7 +188,7 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
*
*/
self.LayersToRemove = function (oldArray, newArray) {
- return _.difference(oldArray, newArray);
+ return _difference(oldArray, newArray);
};
/*
@@ -204,8 +208,7 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
self.activeLayers = [];
map.forEachLayerAtPixel(coords, function (layer, data) {
var hex;
- var palette;
- var legend;
+ var legends;
var layerId;
if (!layer.wv) {
@@ -217,9 +220,9 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
return;
}
legends = models.palettes.getLegends(layerId);
- hex = wv.util.rgbaToHex(data[0], data[1], data[2], data[3]);
+ hex = util.rgbaToHex(data[0], data[1], data[2], data[3]);
- _.each(legends, function (legend) {
+ _each(legends, function (legend) {
if (legend) {
self.createRunnerFromLegend(legend, hex);
}
@@ -332,8 +335,6 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
*/
self.setCategoryValue = function (id, data) {
var $categoryPaletteCase;
- var $caseWidth;
- var $labelWidth;
var $colorSquare;
var $paletteLabel;
var location;
@@ -347,10 +348,7 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
$colorSquare = $categoryPaletteCase.find('[data-class-index=\'' + data.index + '\']');
$paletteLabel = $categoryPaletteCase.find('.wv-running-category-label');
- $caseWidth = $categoryPaletteCase.width();
-
$paletteLabel.text(data.label);
- $labelWidth = wv.util.getTextWidth(data.label, 'Lucida Sans');
location = ((marginLeft + squareWidth) * data.index);
if (location < 5) {
@@ -382,6 +380,9 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
var $palette;
var $paletteCase;
var $paletteWidth;
+ var $paletteCaseWidth;
+ var $paletteLabel;
+ var $paletteBar;
var labelWidth;
var percent;
var labelMargin;
@@ -400,7 +401,7 @@ wv.map.runningdata = wv.map.runningdata || function (models) {
location = ($paletteWidth * percent + margin);
$paletteLabel.text(data.label);
- labelWidth = wv.util.getTextWidth(data.label, 'Lucida Sans');
+ labelWidth = util.getTextWidth(data.label, 'Lucida Sans');
labelMargin = self.getLabelMarginLeft(labelWidth, $paletteWidth, location);
$paletteLabel.attr('style', 'left:' + Math.round(labelMargin) + 'px;');
diff --git a/web/js/map/wv.map.ui.js b/web/js/map/wv.map.ui.js
index bc9bddb8b..4500d0b46 100644
--- a/web/js/map/wv.map.ui.js
+++ b/web/js/map/wv.map.ui.js
@@ -1,10 +1,15 @@
-var wv = wv || {};
-wv.map = wv.map || {};
-
-/*
- * @Class
- */
-wv.map.ui = wv.map.ui || function (models, config, components) {
+import $ from 'jquery';
+import ol from 'openlayers';
+import {
+ forOwn as _forOwn,
+ each as _each,
+ findIndex as _findIndex,
+ find as _find,
+ throttle as _throttle
+} from 'lodash';
+import util from '../util/util';
+
+export default function(models, config, components) {
var id = 'wv-map';
var selector = '#' + id;
var cache = new Cache(400); // Save layers from days visited
@@ -13,21 +18,18 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
var rotation = new components.Rotation(self, models);
var layerBuilder;
var dateline = components.Dateline(models, config);
- var layerKey;
var createLayer;
var precache = components.Precache(models, config, cache, self);
var dataRunner = self.runningdata = new components.Runningdata(models);
- var hiDPI = ol.has.DEVICE_PIXEL_RATIO > 1;
- var pixelRatio = hiDPI ? 2 : 1;
self.mapIsbeingDragged = false;
self.mapIsbeingZoomed = false;
self.proj = {}; // One map for each projection
self.selected = null; // The map for the selected projection
- self.events = wv.util.events();
+ self.events = util.events();
layerBuilder = self.layerBuilder = components.Layerbuilder(models, config, cache, self);
- layerKey = self.layerKey = layerBuilder.layerKey;
+ self.layerKey = layerBuilder.layerKey;
createLayer = self.createLayer = layerBuilder.createLayer;
self.promiseDay = precache.promiseDay;
@@ -45,7 +47,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
}
// NOTE: iOS sometimes bombs if this is _.each instead. In that case,
// it is possible that config.projections somehow becomes array-like.
- _.forOwn(config.projections, function (proj) {
+ _forOwn(config.projections, function (proj) {
var map = createMap(proj);
self.proj[proj.id] = map;
});
@@ -131,8 +133,8 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
*/
var onResize = function () {
var map = self.selected;
- if (map.small !== wv.util.browser.small) {
- if (wv.util.browser.small) {
+ if (map.small !== util.browser.small) {
+ if (util.browser.small) {
map.removeControl(map.wv.scaleImperial);
map.removeControl(map.wv.scaleMetric);
$('#' + map.getTarget() + ' .select-wrapper')
@@ -187,7 +189,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
var activeLayers = map.getLayers()
.getArray()
.slice(0);
- _.each(activeLayers, function (mapLayer) {
+ _each(activeLayers, function (mapLayer) {
if (mapLayer.wv) {
map.removeLayer(mapLayer);
}
@@ -213,7 +215,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
var defs = models.layers.get({
reverse: true
});
- _.each(defs, function (def) {
+ _each(defs, function (def) {
if (isGraticule(def)) {
addGraticule();
} else {
@@ -240,7 +242,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
}
});
var defs = models.layers.get();
- _.each(defs, function (def) {
+ _each(defs, function (def) {
if (isGraticule(def)) {
var renderable = models.layers.isRenderable(def.id);
if (renderable) {
@@ -280,7 +282,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
*/
var addLayer = function (def) {
- var mapIndex = _.findIndex(models.layers.get({
+ var mapIndex = _findIndex(models.layers.get({
reverse: true
}), {
id: def.id
@@ -338,7 +340,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
*/
var updateDate = function () {
var defs = models.layers.get();
- _.each(defs, function (def) {
+ _each(defs, function (def) {
if (def.period !== 'daily') {
return;
}
@@ -362,7 +364,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
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 selectedDate = util.toISOStringDate(models.date.selected);
var selectedProj = models.proj.selected.id;
cache.removeWhere(function (key, mapLayer) {
if (mapLayer.wvid === layerId &&
@@ -395,7 +397,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
var findLayer = function (def) {
var layers = self.selected.getLayers()
.getArray();
- var layer = _.find(layers, {
+ var layer = _find(layers, {
wv: {
id: def.id
}
@@ -417,7 +419,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
var findLayerIndex = function (def) {
var layers = self.selected.getLayers()
.getArray();
- var layer = _.findIndex(layers, {
+ var layer = _findIndex(layers, {
wv: {
id: def.id
}
@@ -484,7 +486,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
self.selected.graticule = null;
};
- var triggerExtent = _.throttle(function () {
+ var triggerExtent = _throttle(function () {
self.events.trigger('extent');
}, 500, {
trailing: true
@@ -519,7 +521,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
*/
var createMap = function (proj) {
var id, $map, scaleMetric, scaleImperial, rotateInteraction,
- map, mobileRotation, lineSvgs, resolution;
+ map, mobileRotation;
id = 'wv-map-' + proj.id;
$map = $('<div></div>')
@@ -598,7 +600,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
map.addInteraction(rotateInteraction);
map.addInteraction(mobileRotation);
} else {
- lineSvgs = dateline.init(self, map, models.date.selected);
+ dateline.init(self, map, models.date.selected);
}
// Set event listeners for changes on the map view (when rotated, zoomed, panned)
@@ -607,7 +609,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
map.getView()
.on('change:resolution', updateExtent);
map.getView()
- .on('change:rotation', _.throttle(onRotate, 300));
+ .on('change:rotation', _throttle(onRotate, 300));
map.on('pointerdrag', function () {
self.mapIsbeingDragged = true;
self.events.trigger('drag');
@@ -770,7 +772,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
return crs;
}
target = ol.proj.transform(source, proj.crs, 'EPSG:4326');
- return wv.util.formatCoordinate(target, format) + ' ' + crs;
+ return util.formatCoordinate(target, format) + ' ' + crs;
};
$map.append($mousePosition);
@@ -784,7 +786,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
.attr('data-format', 'latlon-dms')
.addClass('map-coord');
- if (wv.util.getCoordinateFormat() === 'latlon-dd') {
+ if (util.getCoordinateFormat() === 'latlon-dd') {
$('div.map-coord')
.removeClass('latlon-selected');
$latlonDD.addClass('latlon-selected');
@@ -814,13 +816,13 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
.removeClass('latlon-selected');
$('span.map-coord[data-format="latlon-dms"]')
.addClass('latlon-selected');
- wv.util.setCoordinateFormat('latlon-dms');
+ util.setCoordinateFormat('latlon-dms');
} else {
$('span.map-coord')
.removeClass('latlon-selected');
$('span.map-coord[data-format="latlon-dd"]')
.addClass('latlon-selected');
- wv.util.setCoordinateFormat('latlon-dd');
+ util.setCoordinateFormat('latlon-dd');
}
});
@@ -830,7 +832,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
var outside;
// if mobile return
- if (wv.util.browser.small) {
+ if (util.browser.small) {
return;
}
// if over coords return
@@ -865,7 +867,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
});
// setting a limit on running-data retrievel
- if (self.mapIsbeingDragged || wv.util.browser.small) {
+ if (self.mapIsbeingDragged || util.browser.small) {
return;
}
if (typeof models.naturalEvents === 'undefined' ||
@@ -903,7 +905,7 @@ wv.map.ui = wv.map.ui || function (models, config, components) {
hoverThrottle.cancel();
dataRunner.clearAll();
})
- .mousemove(hoverThrottle = _.throttle(onMouseMove, 300));
+ .mousemove(hoverThrottle = _throttle(onMouseMove, 300));
};
/*
diff --git a/web/js/stub.js b/web/js/stub.js
index 7fb15826d..9ea427b65 100644
--- a/web/js/stub.js
+++ b/web/js/stub.js
@@ -5,9 +5,13 @@ import { parse as mapParser } from './map/wv.map';
import builder from './map/wv.map.datelinebuilder';
import layerBuilder from './map/wv.map.layerbuilder';
import animate from './map/wv.map.animate';
+import mapModel from './map/wv.map.model';
+import preCacheTile from './map/wv.map.precachetile';
+import runningData from './map/wv.map.runningdata';
+import mapUi from './map/wv.map.ui';
export default function () {
- console.log($, DateSelector, mapParser, builder, layerBuilder, animate);
+ console.log($, DateSelector, mapParser, builder, layerBuilder, animate, mapModel, preCacheTile, runningData, mapUi);
};
export const stub2 = (function() {