Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

adding dependency naming convention to map files

Benjamin Kingb6bc2eb75353
diff --git a/web/js/map/wv.map.animate.js b/web/js/map/wv.map.animate.js
index ec7439695..08d99ded0 100644
--- a/web/js/map/wv.map.animate.js
+++ b/web/js/map/wv.map.animate.js
@@ -1,5 +1,5 @@
-import ol from 'openlayers';
-
+import olExtent from 'ol/extent';
+import OlGeomLineString from 'ol/geom/linestring';
export function mapAnimate(models, config, ui) {
var self = {};
@@ -16,10 +16,10 @@ export function mapAnimate(models, config, ui) {
var startPoint = view.getCenter();
var startZoom = Math.floor(view.getZoom());
endZoom = endZoom || 5;
- if (endPoint.length > 2) endPoint = ol.extent.getCenter(endPoint);
+ if (endPoint.length > 2) endPoint = olExtent.getCenter(endPoint);
var extent = view.calculateExtent();
- var hasEndInView = ol.extent.containsCoordinate(extent, endPoint);
- var line = new ol.geom.LineString([startPoint, endPoint]);
+ var hasEndInView = olExtent.containsCoordinate(extent, endPoint);
+ var line = new OlGeomLineString([startPoint, endPoint]);
var distance = line.getLength(); // In map units, which is usually degrees
var duration = (distance * 20) + 1000; // 4.6 seconds to go 360 degrees
var animationPromise = function () {
diff --git a/web/js/map/wv.map.datelinebuilder.js b/web/js/map/wv.map.datelinebuilder.js
index ccad52b57..68b2e98da 100644
--- a/web/js/map/wv.map.datelinebuilder.js
+++ b/web/js/map/wv.map.datelinebuilder.js
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'React-dom';
import WVC from 'worldview-components';
-import ol from 'openlayers';
+import OlOverlay from 'ol/overlay';
import util from '../util/util';
@@ -311,7 +311,7 @@ export function mapDateLineBuilder(models, config) {
* @returns {void}
*/
var drawOverlay = function(coordinate, el) {
- var overlay = new ol.Overlay({
+ var overlay = new OlOverlay({
element: el,
stopEvent: false
});
diff --git a/web/js/map/wv.map.js b/web/js/map/wv.map.js
index 23a4e9238..61c2ebc91 100644
--- a/web/js/map/wv.map.js
+++ b/web/js/map/wv.map.js
@@ -1,8 +1,9 @@
-import map from 'lodash/map';
-import each from 'lodash/each';
-import isUndefined from 'lodash/isUndefined';
-import find from 'lodash/find';
-import ol from 'openlayers';
+import loMap from 'lodash/map';
+import loEach from 'lodash/each';
+import loIsUndefined from 'lodash/isUndefined';
+import loFind from 'lodash/find';
+import OlGeomPolygon from 'ol/geom/polygon';
+
/*
* Checks to see if an extents string is found. If it exist
* then it is changed from a string to an array which is then
@@ -26,7 +27,7 @@ export function parse(state, errors) {
delete state.map;
}
if (state.v) {
- var extent = map(state.v.split(','), function (str) {
+ var extent = loMap(state.v.split(','), function (str) {
return parseFloat(str);
});
var valid = isExtentValid(extent);
@@ -53,14 +54,14 @@ export function parse(state, errors) {
* true.
*/
var isExtentValid = function(extent) {
- if (isUndefined(extent)) {
+ if (loIsUndefined(extent)) {
return false;
}
var valid = true;
if (extent.toArray) {
extent = extent.toArray();
}
- each(extent, function (value) {
+ loEach(extent, function (value) {
if (isNaN(value)) {
valid = false;
return false;
@@ -135,7 +136,7 @@ export function setVisibility(layer, visible, opacity) {
export function getLayerByName(map, name) {
var layers = map.getLayers()
.getArray();
- return find(layers, {
+ return loFind(layers, {
'wvname': name
});
};
@@ -201,7 +202,7 @@ export function adjustAntiMeridian(polygon, adjustSign) {
points[i] = [points[i][0] - 360, points[i][1]];
}
}
- return new ol.geom.Polygon([points]);
+ return new OlGeomPolygon([points]);
};
/**
diff --git a/web/js/map/wv.map.layerbuilder.js b/web/js/map/wv.map.layerbuilder.js
index ba7087ed7..6c245b8b5 100644
--- a/web/js/map/wv.map.layerbuilder.js
+++ b/web/js/map/wv.map.layerbuilder.js
@@ -1,8 +1,13 @@
import util from '../util/util';
-import ol from 'openlayers';
-import cloneDeep from 'lodash/cloneDeep';
-import merge from 'lodash/merge';
-import each from 'lodash/each';
+import OlTileGridWMTS from 'ol/tilegrid/wmts';
+import OlSourceWMTS from 'ol/source/wmts';
+import OlSourceTileWMS from 'ol/source/tilewms';
+import OlLayerGroup from 'ol/layer/group';
+import OlLayerTile from 'ol/layer/tile';
+import OlTileGridTileGrid from 'ol/tilegrid/tilegrid';
+import loCloneDeep from 'lodash/cloneDeep';
+import loMerge from 'lodash/merge';
+import loEach from 'lodash/each';
import {lookupFactory} from '../ol/lookupimagetile';
export function mapLayerBuilder(models, config, cache, Parent) {
@@ -41,8 +46,8 @@ export function mapLayerBuilder(models, config, cache, Parent) {
proj: proj.id,
def: def
};
- def = cloneDeep(def);
- merge(def, def.projections[proj.id]);
+ def = loCloneDeep(def);
+ loMerge(def, def.projections[proj.id]);
if (def.type === 'wmts') {
layer = createLayerWMTS(def, options);
if (proj.id === 'geographic' && def.wrapadjacentdays === true) {
@@ -53,7 +58,7 @@ export function mapLayerBuilder(models, config, cache, Parent) {
layerPrior.wv = attributes;
layerNext.wv = attributes;
- layer = new ol.layer.Group({
+ layer = new OlLayerGroup({
layers: [layer, layerNext, layerPrior]
});
}
@@ -67,7 +72,7 @@ export function mapLayerBuilder(models, config, cache, Parent) {
layerPrior.wv = attributes;
layerNext.wv = attributes;
- layer = new ol.layer.Group({
+ layer = new OlLayerGroup({
layers: [layer, layerNext, layerPrior]
});
}
@@ -138,7 +143,7 @@ export function mapLayerBuilder(models, config, cache, Parent) {
}
if (typeof def.matrixIds === 'undefined') {
matrixIds = [];
- each(matrixSet.resolutions, function (resolution, index) {
+ loEach(matrixSet.resolutions, function (resolution, index) {
matrixIds.push(index);
});
} else {
@@ -170,7 +175,7 @@ export function mapLayerBuilder(models, config, cache, Parent) {
crossOrigin: 'anonymous',
format: def.format,
matrixSet: matrixSet.id,
- tileGrid: new ol.tilegrid.WMTS({
+ tileGrid: new OlTileGridWMTS({
origin: start,
resolutions: matrixSet.resolutions,
matrixIds: matrixIds,
@@ -183,9 +188,9 @@ export function mapLayerBuilder(models, config, cache, Parent) {
var lookup = models.palettes.getLookup(def.id);
sourceOptions.tileClass = lookupFactory(lookup);
}
- var layer = new ol.layer.Tile({
+ var layer = new OlLayerTile({
extent: extent,
- source: new ol.source.WMTS(sourceOptions)
+ source: new OlSourceWMTS(sourceOptions)
});
return layer;
};
@@ -250,7 +255,7 @@ export function mapLayerBuilder(models, config, cache, Parent) {
style: 'default',
crossOrigin: 'anonymous',
params: parameters,
- tileGrid: new ol.tilegrid.TileGrid({
+ tileGrid: new OlTileGridTileGrid({
origin: start,
resolutions: res
})
@@ -260,9 +265,9 @@ export function mapLayerBuilder(models, config, cache, Parent) {
var lookup = models.palettes.getLookup(def.id);
sourceOptions.tileClass = lookupFactory(lookup);
}
- var layer = new ol.layer.Tile({
+ var layer = new OlLayerTile({
extent: extent,
- source: new ol.source.TileWMS(sourceOptions)
+ source: new OlSourceTileWMS(sourceOptions)
});
return layer;
};
diff --git a/web/js/map/wv.map.model.js b/web/js/map/wv.map.model.js
index c9f932430..a66ad05a9 100644
--- a/web/js/map/wv.map.model.js
+++ b/web/js/map/wv.map.model.js
@@ -1,6 +1,6 @@
-import ol from 'openlayers';
import util from '../util/util';
-import clone from 'lodash/clone';
+import loClone from 'lodash/clone';
+import olExtent from 'ol/extent';
export function mapModel(models, config) {
var self = {};
@@ -44,10 +44,10 @@ export function mapModel(models, config) {
if (proj.id === 'geographic') {
proj.wrapExtent = maxExtent = [-250, -90, 250, 90];
}
- if (ol.extent.intersects(extent, maxExtent)) {
+ if (olExtent.intersects(extent, maxExtent)) {
self.extent = state.v;
} else {
- self.extent = clone(proj.maxExtent);
+ self.extent = loClone(proj.maxExtent);
errors.push({
message: 'Extent outside of range'
});
@@ -72,7 +72,7 @@ export function mapModel(models, config) {
* @returns {void}
*/
self.save = function (state) {
- state.v = clone(self.extent);
+ state.v = loClone(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);
diff --git a/web/js/map/wv.map.precachetile.js b/web/js/map/wv.map.precachetile.js
index d0edc066d..df0920787 100644
--- a/web/js/map/wv.map.precachetile.js
+++ b/web/js/map/wv.map.precachetile.js
@@ -1,5 +1,6 @@
-import _each from 'lodash/each';
-import ol from 'openlayers';
+import loEach from 'lodash/each';
+import olExtent from 'ol/extent';
+import OlRendererCanvasTileLayer from 'ol/renderer/canvas/tilelayer';
export function mapPrecacheTile(models, config, cache, parent) {
/*
@@ -56,7 +57,7 @@ export function mapPrecacheTile(models, config, cache, parent) {
var layers;
var arra = [];
layers = models.layers.get();
- _each(layers, function (layer) {
+ loEach(layers, function (layer) {
if (layer.visible && new Date(layer.startDate > date)) {
arra.push(layer);
}
@@ -82,7 +83,7 @@ export function mapPrecacheTile(models, config, cache, parent) {
return extent;
};
var getExtent = function (extent1, extent2) {
- return ol.extent.getIntersection(extent1, extent2);
+ return olExtent.getIntersection(extent1, extent2);
};
var promiseLayerGroup = function (layer, extent, viewState, pixelRatio, map) {
return new Promise(function (resolve, reject) {
@@ -114,7 +115,7 @@ export function mapPrecacheTile(models, config, cache, parent) {
}
projection = viewState.projection;
i = 0;
- renderer = new ol.renderer.canvas.TileLayer(layer);
+ renderer = new OlRendererCanvasTileLayer(layer);
tileSource = layer.getSource();
tileGrid = tileSource.getTileGridForProjection(projection);
currentZ = tileGrid.getZForResolution(viewState.resolution, renderer.zDirection);
diff --git a/web/js/map/wv.map.runningdata.js b/web/js/map/wv.map.runningdata.js
index dc8e478c4..9839bbd39 100644
--- a/web/js/map/wv.map.runningdata.js
+++ b/web/js/map/wv.map.runningdata.js
@@ -1,7 +1,7 @@
import $ from 'jquery';
import util from '../util/util';
-import difference from 'lodash/difference';
-import each from 'lodash/each';
+import loDifference from 'lodash/difference';
+import loEach from 'lodash/each';
export function mapRunningData(models) {
var self;
@@ -186,7 +186,7 @@ export function mapRunningData(models) {
*
*/
self.LayersToRemove = function (oldArray, newArray) {
- return difference(oldArray, newArray);
+ return loDifference(oldArray, newArray);
};
/*
@@ -220,7 +220,7 @@ export function mapRunningData(models) {
legends = models.palettes.getLegends(layerId);
hex = util.rgbaToHex(data[0], data[1], data[2], data[3]);
- each(legends, function (legend) {
+ loEach(legends, function (legend) {
if (legend) {
self.createRunnerFromLegend(legend, hex);
}
diff --git a/web/js/map/wv.map.ui.js b/web/js/map/wv.map.ui.js
index a36ee54b0..e39e58ee9 100644
--- a/web/js/map/wv.map.ui.js
+++ b/web/js/map/wv.map.ui.js
@@ -1,11 +1,26 @@
import $ from 'jquery';
-import ol from 'openlayers';
-import findIndex from 'lodash/findIndex';
-import each from 'lodash/each';
-import forOwn from 'lodash/forOwn';
-import throttle from 'lodash/throttle';
-import find from 'lodash/find';
+import loFindIndex from 'lodash/findIndex';
+import loEach from 'lodash/each';
+import loForOwn from 'lodash/forOwn';
+import loThrottle from 'lodash/throttle';
+import loFind from 'lodash/find';
import util from '../util/util';
+import OlMap from 'ol/map';
+import OlView from 'ol/view';
+import OlKinetic from 'ol/kinetic';
+import OlGraticule from 'ol/graticule';
+import OlStyleStroke from 'ol/style/stroke';
+import OlControlScaleLine from 'ol/control/scaleline';
+import olEventsCondition from 'ol/events/condition';
+import OlInteractionPinchRotate from 'ol/interaction/pinchrotate';
+import OlInteractionDragRotate from 'ol/interaction/dragrotate';
+import OlInteractionDoubleClickZoom from 'ol/interaction/doubleclickzoom';
+import OlInteractionPinchZoom from 'ol/interaction/pinchzoom';
+import OlInteractionDragPan from 'ol/interaction/dragpan';
+import OlInteractionMouseWheelZoom from 'ol/interaction/mousewheelzoom';
+import OlInteractionDragZoom from 'ol/interaction/dragzoom';
+import olExtent from 'ol/extent';
+import olProj from 'ol/proj';
export function mapui(models, config, components) {
var id = 'wv-map';
@@ -45,7 +60,7 @@ export function mapui(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) {
+ loForOwn(config.projections, function (proj) {
var map = createMap(proj);
self.proj[proj.id] = map;
});
@@ -187,7 +202,7 @@ export function mapui(models, config, components) {
var activeLayers = map.getLayers()
.getArray()
.slice(0);
- each(activeLayers, function (mapLayer) {
+ loEach(activeLayers, function (mapLayer) {
if (mapLayer.wv) {
map.removeLayer(mapLayer);
}
@@ -213,7 +228,7 @@ export function mapui(models, config, components) {
var defs = models.layers.get({
reverse: true
});
- each(defs, function (def) {
+ loEach(defs, function (def) {
if (isGraticule(def)) {
addGraticule();
} else {
@@ -240,7 +255,7 @@ export function mapui(models, config, components) {
}
});
var defs = models.layers.get();
- each(defs, function (def) {
+ loEach(defs, function (def) {
if (isGraticule(def)) {
var renderable = models.layers.isRenderable(def.id);
if (renderable) {
@@ -280,7 +295,7 @@ export function mapui(models, config, components) {
*/
var addLayer = function (def) {
- var mapIndex = findIndex(models.layers.get({
+ var mapIndex = loFindIndex(models.layers.get({
reverse: true
}), {
id: def.id
@@ -338,7 +353,7 @@ export function mapui(models, config, components) {
*/
var updateDate = function () {
var defs = models.layers.get();
- each(defs, function (def) {
+ loEach(defs, function (def) {
if (def.period !== 'daily') {
return;
}
@@ -395,7 +410,7 @@ export function mapui(models, config, components) {
var findLayer = function (def) {
var layers = self.selected.getLayers()
.getArray();
- var layer = find(layers, {
+ var layer = loFind(layers, {
wv: {
id: def.id
}
@@ -417,7 +432,7 @@ export function mapui(models, config, components) {
var findLayerIndex = function (def) {
var layers = self.selected.getLayers()
.getArray();
- var layer = findIndex(layers, {
+ var layer = loFindIndex(layers, {
wv: {
id: def.id
}
@@ -458,9 +473,9 @@ export function mapui(models, config, components) {
var addGraticule = function () {
if (self.selected.graticule) { return; }
- self.selected.graticule = new ol.Graticule({
+ self.selected.graticule = new OlGraticule({
map: self.selected,
- strokeStyle: new ol.style.Stroke({
+ strokeStyle: new OlStyleStroke({
color: 'rgba(255, 255, 255, 0.5)',
width: 2,
lineDash: [0.5, 4]
@@ -484,7 +499,7 @@ export function mapui(models, config, components) {
self.selected.graticule = null;
};
- var triggerExtent = throttle(function () {
+ var triggerExtent = loThrottle(function () {
self.events.trigger('extent');
}, 500, {
trailing: true
@@ -531,26 +546,26 @@ export function mapui(models, config, components) {
.append($map);
// Create two specific controls
- scaleMetric = new ol.control.ScaleLine({
+ scaleMetric = new OlControlScaleLine({
className: 'wv-map-scale-metric',
units: 'metric'
});
- scaleImperial = new ol.control.ScaleLine({
+ scaleImperial = new OlControlScaleLine({
className: 'wv-map-scale-imperial',
units: 'imperial'
});
- rotateInteraction = new ol.interaction.DragRotate({
- condition: ol.events.condition.altKeyOnly,
+ rotateInteraction = new OlInteractionDragRotate({
+ condition: olEventsCondition.altKeyOnly,
duration: animationDuration
});
- mobileRotation = new ol.interaction.PinchRotate({
+ mobileRotation = new OlInteractionPinchRotate({
duration: animationDuration
});
- map = new ol.Map({
- view: new ol.View({
+ map = new OlMap({
+ view: new OlView({
maxResolution: proj.resolutions[0],
- projection: ol.proj.get(proj.crs),
+ projection: olProj.get(proj.crs),
center: proj.startCenter,
rotation: proj.id === 'geographic' ? 0.0 : models.map.rotation,
zoom: proj.startZoom,
@@ -566,19 +581,19 @@ export function mapui(models, config, components) {
scaleImperial
],
interactions: [
- new ol.interaction.DoubleClickZoom({
+ new OlInteractionDoubleClickZoom({
duration: animationDuration
}),
- new ol.interaction.DragPan({
- kinetic: new ol.Kinetic(-0.005, 0.05, 100)
+ new OlInteractionDragPan({
+ kinetic: new OlKinetic(-0.005, 0.05, 100)
}),
- new ol.interaction.PinchZoom({
+ new OlInteractionPinchZoom({
duration: animationDuration
}),
- new ol.interaction.MouseWheelZoom({
+ new OlInteractionMouseWheelZoom({
duration: animationDuration
}),
- new ol.interaction.DragZoom({
+ new OlInteractionDragZoom({
duration: animationDuration
})
],
@@ -607,7 +622,7 @@ export function mapui(models, config, components) {
map.getView()
.on('change:resolution', updateExtent);
map.getView()
- .on('change:rotation', throttle(onRotate, 300));
+ .on('change:rotation', loThrottle(onRotate, 300));
map.on('pointerdrag', function () {
self.mapIsbeingDragged = true;
self.events.trigger('drag');
@@ -842,7 +857,7 @@ export function mapui(models, config, components) {
}
pixels = map.getEventPixel(e.originalEvent);
coords = map.getCoordinateFromPixel(pixels);
- if (!ol.extent.containsCoordinate(extent, coords)) {
+ if (!olExtent.containsCoordinate(extent, coords)) {
outside = true;
}
@@ -903,7 +918,7 @@ export function mapui(models, config, components) {
hoverThrottle.cancel();
dataRunner.clearAll();
})
- .mousemove(hoverThrottle = throttle(onMouseMove, 300));
+ .mousemove(hoverThrottle = loThrottle(onMouseMove, 300));
};
/*