Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

remove old files, remove unused param

Jason Kent890ae1fb4465
diff --git a/web/js/map/natural-events/event-track.js b/web/js/map/natural-events/event-track.js
index 53144628d..28f554f2e 100644
--- a/web/js/map/natural-events/event-track.js
+++ b/web/js/map/natural-events/event-track.js
@@ -586,7 +586,7 @@ const addPoints = function(proj, clusters, map, selectedDate, callback) {
* @param {Function} callback
* @return {Object} Openlayers overlay object
*/
-function getClusterPointEl(proj, cluster, map, pointClusterObj, callback) {
+function getClusterPointEl(proj, cluster, map, pointClusterObj) {
const overlayEl = document.createElement('div');
const circleEl = document.createElement('div');
const innerCircleEl = document.createElement('div');
diff --git a/web/js/map/natural-events/markers.js b/web/js/map/natural-events/markers.js
deleted file mode 100644
index fd19f4300..000000000
--- a/web/js/map/natural-events/markers.js
+++ /dev/null
@@ -1,218 +0,0 @@
-import lodashFind from 'lodash/find';
-import lodashIsEmpty from 'lodash/isEmpty';
-import * as olExtent from 'ol/extent';
-import OlOverlay from 'ol/Overlay';
-import OlFeature from 'ol/Feature';
-import OlStyleStyle from 'ol/style/Style';
-import OlStyleStroke from 'ol/style/Stroke';
-import OlLayerVector from 'ol/layer/Vector';
-import OlSourceVector from 'ol/source/Vector';
-import OlGeomPolygon from 'ol/geom/Polygon';
-import * as olProj from 'ol/proj';
-import googleTagManager from 'googleTagManager';
-import { selectEvent as selectEventAction } from '../../modules/natural-events/actions';
-import { getDefaultEventDate } from './util';
-
-export default function markers(ui, store) {
- const self = {};
- const map = ui.map.selected;
-
- self.draw = function() {
- const { proj } = store.getState();
- const events = ui.naturalEvents.eventsData;
- if (!events || events.length < 1) return null;
- const markers = events.reduce((collection, event) => {
- const marker = {};
- const { selected } = ui.naturalEvents;
- const isSelected = event.id === selected.id;
- let date = getDefaultEventDate(event);
-
- if (isSelected && selected.date) {
- date = selected.date;
- }
-
- const geometry = lodashFind(event.geometry, (geom) => geom.date.split('T')[0] === date) || event.geometry[0];
- if (!geometry) return marker;
-
- let { coordinates } = geometry;
-
- // polar projections require transform of coordinates to crs
- if (proj.selected.id !== 'geographic') {
- // check for polygon geometries
- if (geometry.type === 'Polygon') {
- const coordinatesTransform = coordinates[0].map((coordinate) => olProj.transform(coordinate, 'EPSG:4326', proj.selected.crs));
- const extent = olExtent.boundingExtent(coordinatesTransform);
- coordinates = olExtent.getCenter(extent);
- if (isSelected) {
- marker.boundingBox = createBoundingBox(coordinatesTransform);
- map.addLayer(marker.boundingBox);
- }
- } else {
- // if normal geometries, transform given lon/lat array
- coordinates = olProj.transform(
- coordinates,
- 'EPSG:4326',
- proj.selected.crs,
- );
- }
- } else if (geometry.type === 'Polygon') {
- const extent = olExtent.boundingExtent(geometry.coordinates[0]);
- coordinates = olExtent.getCenter(extent);
- if (isSelected) {
- marker.boundingBox = createBoundingBox(geometry.coordinates);
- map.addLayer(marker.boundingBox);
- }
- }
-
- let category = event.categories[0];
- // Assign a default category if we don't have an icon
- const icons = [
- 'Dust and Haze',
- 'Icebergs',
- 'Manmade',
- 'Sea and Lake Ice',
- 'Severe Storms',
- 'Snow',
- 'Temperature Extremes',
- 'Volcanoes',
- 'Water Color',
- 'Wildfires',
- ];
- category = icons.includes(category.title)
- ? category
- : { title: 'Default', slug: 'default' };
-
- // get maxExtent of current projection and check if marker is within range
- const { maxExtent } = proj.selected;
- const maxExtentCheck = olExtent.containsCoordinate(maxExtent, coordinates);
- // only create marker if within projection extent range
- if (maxExtentCheck) {
- marker.pin = createPin(event.id, category, isSelected, event.title);
- marker.pin.setPosition(coordinates);
- map.addOverlay(marker.pin);
-
- // Add event listeners
- let willSelect = true;
- let moveCount = 0;
- // The pin element used to be on `element_` but now it looks like it
- // moved to `element`. Maybe this was a change to OpenLayers.
- const pinEl = marker.pin.element_ || marker.pin.element;
-
- // Use passiveSupport detect in ui. passive applied if supported, capture will be false either way.
- ['pointerdown', 'mousedown', 'touchstart'].forEach((type) => {
- pinEl.addEventListener(
- type,
- (e) => {
- willSelect = true;
- moveCount = 0;
- },
- ui.supportsPassive ? { passive: true } : false,
- );
- });
- ['pointermove', 'mousemove'].forEach((type) => {
- pinEl.addEventListener(
- type,
- (e) => {
- moveCount += 1;
- if (moveCount > 2) {
- willSelect = false;
- }
- },
- ui.supportsPassive ? { passive: true } : false,
- );
- });
- ['touchend', 'click'].forEach((type) => {
- pinEl.addEventListener(
- type,
- (e) => {
- if (willSelect && !isSelected) {
- e.stopPropagation();
- store.dispatch(selectEventAction(event.id, date));
- googleTagManager.pushEvent({
- event: 'natural_event_selected',
- natural_events: {
- category: category.title,
- },
- });
- }
- },
- ui.supportsPassive ? { passive: true } : false,
- );
- });
- }
- // empty objects (i.e., markers not within projection range) are not pushed to collection
- if (lodashIsEmpty(marker) !== true) {
- collection.push(marker);
- }
- return collection;
- }, []);
-
- map.renderSync(); // Marker position will be off until this is called
- return markers;
- };
-
- self.remove = function(markers) {
- markers = markers || [];
- if (markers.length < 1) return;
- markers.forEach((marker) => {
- if (marker.boundingBox) {
- // added setMap to null for marker to remove - may be scope related issue
- marker.boundingBox.setMap(null);
- map.removeLayer(marker.boundingBox);
- }
- if (marker.pin) {
- // added setMap to null for marker to remove - may be scope related issue
- marker.pin.setMap(null);
- map.removeOverlay(marker.pin);
- }
- });
- };
-
- const createPin = function(id, category, isSelected, title) {
- const overlayEl = document.createElement('div');
- const icon = document.createElement('i');
- overlayEl.className = 'marker';
- if (isSelected) overlayEl.classList.add('marker-selected');
- icon.className = `event-icon event-icon-${category.slug}`;
- icon.title = title || category.title;
- overlayEl.appendChild(icon);
- return new OlOverlay({
- element: overlayEl,
- positioning: 'bottom-center',
- stopEvent: false,
- id,
- });
- };
-
- const createBoundingBox = function(coordinates) {
- const lightStroke = new OlStyleStyle({
- stroke: new OlStyleStroke({
- color: [255, 255, 255, 0.6],
- width: 2,
- lineDash: [4, 8],
- lineDashOffset: 6,
- }),
- });
- const darkStroke = new OlStyleStyle({
- stroke: new OlStyleStroke({
- color: [0, 0, 0, 0.6],
- width: 2,
- lineDash: [4, 8],
- }),
- });
- return new OlLayerVector({
- source: new OlSourceVector({
- features: [
- new OlFeature({
- geometry: new OlGeomPolygon(coordinates),
- name: 'NaturalEvent',
- }),
- ],
- wrapX: false,
- }),
- style: [lightStroke, darkStroke],
- });
- };
-
- return self;
-}
diff --git a/web/js/map/natural-events/track.js b/web/js/map/natural-events/track.js
deleted file mode 100644
index 11c5fb13d..000000000
--- a/web/js/map/natural-events/track.js
+++ /dev/null
@@ -1,612 +0,0 @@
-import OlFeature from 'ol/Feature';
-import OlOverlay from 'ol/Overlay';
-import OlLayerVector from 'ol/layer/Vector';
-import OlSourceVector from 'ol/source/Vector';
-import OlStyleStroke from 'ol/style/Stroke';
-import OlStyleStyle from 'ol/style/Style';
-import * as olExtent from 'ol/extent';
-import OlGeomMultiLineString from 'ol/geom/MultiLineString';
-import * as olProj from 'ol/proj';
-import {
- find as lodashFind,
- each as lodashEach,
- debounce as lodashDebounce,
-} from 'lodash';
-
-import {
- naturalEventsClusterPointToGeoJSON,
- naturalEventsClusterGetPoints,
- naturalEventsClusterCreateObject,
- naturalEventsClusterSort,
-} from './cluster';
-import { mapUtilZoomAction } from '../util';
-import { selectEvent as selectEventAction } from '../../modules/natural-events/actions';
-
-const firstClusterObj = naturalEventsClusterCreateObject(); // Cluster before selected event
-const secondClusterObj = naturalEventsClusterCreateObject(); // Cluster after selected event
-
-export default function naturalEventsTrack(ui, store, selectedMap) {
- const self = {};
- self.trackDetails = {};
- self.active = false;
-
- /**
- * @return {void}
- */
- const init = function() {
- selectedMap.on('moveend', (e) => {
- if (self.active && store.getState().events.active) {
- if (self.trackDetails.id) {
- addPointOverlays(selectedMap, self.trackDetails.pointArray);
- } else {
- debounceTrackUpdate();
- }
- }
- });
- // reset track on change to resolution or rotation
- selectedMap.getView().on('propertychange', (e) => {
- if (e.key === 'resolution' || e.key === 'rotation') {
- self.trackDetails = self.trackDetails.id
- ? self.removeTrack(selectedMap, self.trackDetails)
- : {};
- } else if (e.key === 'center') {
- if (self.active) {
- // if old values equal target, map is not moving
- // restricts track/cluster points from disappearing on min/max zoom
- let isNewTarget = true;
- if (e.target) {
- const valueCheck = (val) => (typeof val === 'number' ? val.toFixed(6) : 0);
- const oldValues = e.oldValue.map((val) => valueCheck(val));
- const targetValues = e.target.values_.center.map((val) => valueCheck(val));
-
- const oldLon = oldValues[0];
- const oldLat = oldValues[1];
- const targetLon = targetValues[0];
- const targetLat = targetValues[1];
-
- // compare oldValues and target values
- isNewTarget = oldLon !== targetLon || oldLat !== targetLat;
- }
- if (isNewTarget) {
- removeOldPoints(selectedMap, self.trackDetails.pointArray);
- }
- }
- }
- });
- };
-
- self.onSidebarChange = function(tab) {
- if (tab === 'events') {
- debounceTrackUpdate();
- } else if (self.trackDetails.id) self.update(null);
- };
-
- /**
- * Remove track
- *
- * @param {Object} map Openlayers map object
- * @param {Object} trackObj Object containig info related
- * to track
- * @return {Object} Empty object
- */
- self.removeTrack = function(map, trackObj) {
- map.removeLayer(trackObj.track);
- removeOldPoints(map, trackObj.pointArray);
- return {};
- };
-
- /**
- * Update track
- *
- * @param {Object} event EONET event object
- * @param {Object} map Ol map object
- * @param {String} selectedDate
- * @param {Function} callback event change callback
- * @return {[type]}
- */
- self.update = function(event, selectedDate, callback) {
- const { proj } = store.getState();
- let newTrackDetails;
- const { trackDetails } = self;
- const createAndAddTrack = () => {
- newTrackDetails = createTrack(
- proj,
- event,
- selectedMap,
- selectedDate,
- callback,
- );
- selectedMap.addLayer(newTrackDetails.track);
- };
-
- if (!event || event.geometry.length < 2) {
- newTrackDetails = trackDetails.id
- ? self.removeTrack(selectedMap, trackDetails)
- : {};
- self.active = false;
- } else if (trackDetails.id) {
- if (trackDetails.id === event.id) {
- // If same Track but different selection
- // Just update classNames
- if (trackDetails.selectedDate !== selectedDate) {
- const isClusteredSelection = !document.getElementById(
- `track-marker-${selectedDate}`,
- );
- // If New Date is in cluster build new track
- if (isClusteredSelection) {
- newTrackDetails = self.removeTrack(selectedMap, trackDetails);
- createAndAddTrack();
- } else {
- newTrackDetails = trackDetails;
- updateSelection(selectedDate);
- newTrackDetails.selectedDate = selectedDate;
- }
- } else {
- // If the date and event are the same
- // Return the same Object and do nothing
- return self.trackDetails;
- }
- } else {
- // Remove old DOM Elements
- newTrackDetails = self.removeTrack(selectedMap, trackDetails);
- createAndAddTrack();
- }
- } else {
- // If no track element currenlty exists,
- // but there is a multiday event, build a new track
- createAndAddTrack();
- }
- self.active = true;
- self.trackDetails = newTrackDetails;
- };
-
- const debounceTrackUpdate = lodashDebounce(() => {
- const { eventsData, selected } = ui.naturalEvents;
-
- if (!selected.id || !selected.date) {
- return;
- }
- const event = eventsData.find((e) => e.id === selected.id);
- self.update(event, selected.date, (id, date) => {
- store.dispatch(selectEventAction(id, date));
- });
- }, 250);
-
- init();
- return self;
-}
-
-/**
- * Determine if track point is across the date line from the
- * selected point
- * @param {Array} activeCoord Coordinate array of selected track point
- * @param {Array} nextCoord Coordinate to test against active coord
- * @return {Boolean}
- */
-const crossesDateLine = function(activeCoord, nextCoord) {
- return Math.abs(activeCoord[0] - nextCoord[0]) > 180;
-};
-
-/**
- * Convert coordinates to be over date line
- * in geographic projections
- *
- * @param {Array} coordinates Coordinate array
- * @return {Array}
- */
-const getOverDateLineCoordinates = function(coordinates) {
- const long = coordinates[0];
- const lat = coordinates[1];
- return long < 0
- ? [Math.abs(180 + 180 - Math.abs(long)), lat]
- : [-Math.abs(180 + 180 - Math.abs(long)), lat];
-};
-
-/**
- * Create vector layer
- *
- * @param {Array} featuresArray Array of linstring
- * points
- * @return {Object} OpenLayers Vector Layer
- */
-const naturalEventsTrackLayer = function(proj, featuresArray) {
- return new OlLayerVector({
- source: new OlSourceVector({
- features: featuresArray,
- }),
- extent:
- proj.selected.id === 'geographic'
- ? [-250, -90, 250, 90]
- : proj.selected.maxExtent,
- style: [getLineStyle('black', 2), getLineStyle('white', 1)],
- });
-};
-
-/**
- * Create event point
- *
- * @param {Object} clusterPoint
- * @param {Boolean} isSelected
- * @param {Function} callback
- * @return {Object} Openlayers overlay object
- */
-const naturalEventsTrackPoint = function(
- proj,
- clusterPoint,
- isSelected,
- map,
- callback,
-) {
- const overlayEl = document.createElement('div');
- const circleEl = document.createElement('div');
- const textEl = document.createElement('span');
- const { properties } = clusterPoint;
- const content = document.createTextNode(properties.date);
- const { date } = properties;
- const eventID = properties.event_id;
- let { coordinates } = clusterPoint.geometry;
- if (proj.selected.id !== 'geographic') {
- coordinates = olProj.transform(coordinates, 'EPSG:4326', proj.selected.crs);
- }
- overlayEl.className = isSelected
- ? 'track-marker-case track-marker-case-selected'
- : 'track-marker-case';
- overlayEl.dataset.id = eventID;
- overlayEl.id = `track-marker-case-${date}`;
- overlayEl.onclick = function() {
- callback(eventID, date);
- };
- textEl.appendChild(content);
- textEl.className = 'track-marker-date';
- circleEl.className = `track-marker track-marker-${date}`;
- circleEl.id = `track-marker-${date}`;
- overlayEl.appendChild(circleEl);
- overlayEl.appendChild(textEl);
- return new OlOverlay({
- position: coordinates,
- positioning: 'center-center',
- element: overlayEl,
- stopEvent: false,
- id: eventID + date.toString(),
- });
-};
-
-/**
- * @param {Array} coordinateArray
- * @return {Object} Openlayers Feature
- */
-const naturalEventsTrackLine = function(coordinateArray) {
- return new OlFeature({
- geometry: new OlGeomMultiLineString(coordinateArray),
- });
-};
-
-/**
- * @param {String} color
- * @param {Number} Width
- * @return {Object} OpenLayers Style Object
- */
-const getLineStyle = function(color, width) {
- return new OlStyleStyle({
- stroke: new OlStyleStroke({
- color,
- width,
- }),
- });
-};
-
-/**
- * Loop through event geometries and create
- * track points and line
- *
- * @param {Object} proj
- * @param {Object} eventObj EONET event Object
- * @param {Object} map Openlayers map Object
- * @param {String} selectedDate
- * @param {Function} callback date-change callback
- * @return {Object} Object with Track elements and info
- */
-const createTrack = function(proj, eventObj, map, selectedDate, callback) {
- const olTrackLineFeatures = [];
- let pointObject = {};
- const geoJSONPointsBeforeSelected = [];
- const geoJSONPointsAfterSelected = [];
- let selectedPoint;
- let clusters;
- let afterSelected = false;
- const zoom = map.getView().getZoom();
- const extent = proj.selected.id === 'geographic'
- ? [-250, -90, 250, 90]
- : [-180, -90, 180, 90];
-
- const selectedCoords = lodashFind(eventObj.geometry, (geometry) => geometry.date.split('T')[0] === selectedDate).coordinates;
- lodashEach(eventObj.geometry, (geometry, index) => {
- let { coordinates } = geometry;
- const date = geometry.date.split('T')[0];
- const isSelected = selectedDate === date;
- const isOverDateline = proj.selected.id === 'geographic'
- ? crossesDateLine(selectedCoords, coordinates)
- : false;
- if (isOverDateline) {
- // replace coordinates
- coordinates = getOverDateLineCoordinates(coordinates);
- }
- // Cluster in three groups
- if (isSelected) {
- selectedPoint = naturalEventsClusterPointToGeoJSON(
- eventObj.id,
- coordinates,
- date,
- );
- afterSelected = true;
- } else if (!afterSelected) {
- geoJSONPointsBeforeSelected.push(
- naturalEventsClusterPointToGeoJSON(eventObj.id, coordinates, date),
- );
- } else {
- geoJSONPointsAfterSelected.push(
- naturalEventsClusterPointToGeoJSON(eventObj.id, coordinates, date),
- );
- }
- });
-
- // set radius and maxZoom of superCluster object for polar vs geographic projections
- if (proj.selected.id !== 'geographic') {
- firstClusterObj.options.setPolar();
- secondClusterObj.options.setPolar();
- } else {
- firstClusterObj.options.setGeo();
- secondClusterObj.options.setGeo();
- }
-
- const clustersBeforeSelected = naturalEventsClusterGetPoints(
- firstClusterObj,
- geoJSONPointsBeforeSelected,
- zoom,
- extent,
- );
- const clustersAfterSelected = naturalEventsClusterGetPoints(
- secondClusterObj,
- geoJSONPointsAfterSelected,
- zoom,
- extent,
- );
- clusters = clustersBeforeSelected.concat(
- [selectedPoint],
- clustersAfterSelected,
- );
- clusters = naturalEventsClusterSort(clusters);
-
- pointObject = addPoints(proj, clusters, map, selectedDate, callback);
- olTrackLineFeatures.push(naturalEventsTrackLine(pointObject.trackArray));
-
- return {
- id: eventObj.id,
- track: naturalEventsTrackLayer(proj, olTrackLineFeatures, map),
- pointArray: pointObject.overlayArray,
- selectedDate,
- hidden: false,
- };
-};
-
-/**
- * Remove Point overlays to DOM
- *
- * @param {Object} map OpenLayers Map Object
- * @param {Array} pointOverlayArray
- * @return {void}
- */
-const removeOldPoints = function(map, pointOverlayArray) {
- lodashEach(pointOverlayArray, (pointOverlay) => {
- if (map.getOverlayById(pointOverlay.getId())) {
- map.removeOverlay(pointOverlay);
- }
- });
-};
-
-/**
- * Add Point overlays to DOM
- *
- * @param {Object} map OpenLayers Map Object
- * @param {Array} pointOverlayArray
- * @return {void}
- */
-const addPointOverlays = function(map, pointOverlayArray) {
- lodashEach(pointOverlayArray, (pointOverlay) => {
- addOverlayIfIsVisible(map, pointOverlay);
- });
-};
-
-/**
- * Change selected point
- *
- * @param {String} newDate
- * @return {void}
- */
-const updateSelection = function(newDate) {
- const oldSelectedPoint = document.getElementsByClassName(
- 'track-marker-case-selected',
- )[0];
- const newSelectedPoint = document.getElementById(
- `track-marker-case-${newDate}`,
- );
- if (oldSelectedPoint) oldSelectedPoint.className = 'track-marker-case';
- newSelectedPoint.className = 'track-marker-case track-marker-case-selected';
-};
-
-/**
- * Create rotated element that displays arrows between points
- * as repeated css background image
- *
- * @param {Array} lineSegmentCoords Start and end points of
- * line in Lat/long
- * @param {Object} map OpenLayers map Object
- * @return {Object} Openlayers overlay Object
- */
-const createArrows = function(lineSegmentCoords, map) {
- const currentRotation = map.getView().getRotation();
- const overlayEl = document.createElement('div');
- const innerEl = document.createElement('div');
-
- const clusterPadding = 20; // 10px on each side
- const end = lineSegmentCoords[0];
- const start = lineSegmentCoords[1];
- const dxCoord = end[0] - start[0];
- const dyCoord = end[1] - start[1];
- const pixel1 = map.getPixelFromCoordinate(start);
- const pixel2 = map.getPixelFromCoordinate(end);
- const dx = pixel2[0] - pixel1[0];
- const dy = pixel2[1] - pixel1[1];
- const pixelMidPoint = [0.5 * dx + pixel1[0], 0.5 * dy + pixel1[1]];
- const distanceInPixels = Math.sqrt((dx ** 2) + (dy ** 2));
- const angleRadians = Math.atan2(dyCoord, dxCoord) - currentRotation;
- const angleDegrees = -angleRadians * (180 / Math.PI);
- const lengthOfArrowDiv = distanceInPixels - clusterPadding;
-
- innerEl.className = 'event-track-arrows';
- overlayEl.appendChild(innerEl);
- overlayEl.style.width = '1px';
- overlayEl.style.height = '1px';
- innerEl.style.width = `${lengthOfArrowDiv}px`;
- innerEl.style.height = '16px';
- innerEl.style.transform = `translate(${-(lengthOfArrowDiv / 2)}px, -8px)`;
- overlayEl.style.transform = `rotate(${angleDegrees}deg)`;
- return new OlOverlay({
- position: map.getCoordinateFromPixel(pixelMidPoint),
- positioning: 'center-center',
- stopEvent: true,
- element: overlayEl,
- id: `arrow${pixelMidPoint[0].toString()}${pixelMidPoint[1].toString()}`,
- });
-};
-
-/**
- * Loop through clustered point array and create elements
- *
- * @param {Array} clusters Array of cluster objects
- * @param {Object} map OpenLayers map Object
- * @param {String} selectedDate
- * @param {Function} callback
- * @return {Object} Object Containing track info and elements
- */
-const addPoints = function(proj, clusters, map, selectedDate, callback) {
- const overlays = [];
- const trackArray = [];
- lodashEach(clusters, (clusterPoint, index) => {
- let point;
- const date = clusterPoint.properties.date || clusterPoint.properties.startDate;
- const isSelected = selectedDate === date;
- const pointClusterObj = new Date(date) > new Date(selectedDate)
- ? firstClusterObj
- : secondClusterObj;
- if (index !== 0) {
- let prevCoordinates = clusters[index - 1].geometry.coordinates;
- let nextCoordinates = clusterPoint.geometry.coordinates;
-
- // polar projections require transform of coordinates to crs
- if (proj.selected.id !== 'geographic') {
- prevCoordinates = olProj.transform(
- prevCoordinates,
- 'EPSG:4326',
- proj.selected.crs,
- );
- nextCoordinates = olProj.transform(
- nextCoordinates,
- 'EPSG:4326',
- proj.selected.crs,
- );
- }
-
- const lineSegmentArray = [prevCoordinates, nextCoordinates];
- const arrowOverlay = createArrows(lineSegmentArray, map);
- overlays.push(arrowOverlay);
- trackArray.push(lineSegmentArray);
- addOverlayIfIsVisible(map, arrowOverlay);
- }
- if (clusterPoint.properties.cluster) {
- point = getClusterPointEl(
- proj,
- clusterPoint,
- map,
- pointClusterObj,
- callback,
- );
- overlays.push(point);
- } else {
- point = naturalEventsTrackPoint(
- proj,
- clusterPoint,
- isSelected,
- map,
- callback,
- );
- overlays.push(point);
- }
- addOverlayIfIsVisible(map, point);
- });
- return { trackArray, overlayArray: overlays };
-};
-
-/**
- * Create cluster point
- *
- * @param {Object} clusterPoint
- * @param {Object} map Openlayers map object
- * @param {Object} pointClusterObj supercluster object
- * @param {Function} callback
- * @return {Object} Openlayers overlay object
- */
-function getClusterPointEl(proj, cluster, map, pointClusterObj, callback) {
- const overlayEl = document.createElement('div');
- const circleEl = document.createElement('div');
- const innerCircleEl = document.createElement('div');
-
- const textEl = document.createElement('span');
- const { properties } = cluster;
- const clusterId = properties.cluster_id;
- const number = properties.point_count_abbreviated;
- const numberEl = document.createTextNode(number);
- const dateRangeTextEl = document.createTextNode(
- `${properties.startDate} to ${properties.endDate}`,
- );
- let { coordinates } = cluster.geometry;
- const mapView = map.getView();
- if (proj.selected.id !== 'geographic') {
- coordinates = olProj.transform(coordinates, 'EPSG:4326', proj.selected.crs);
- }
- const sizeClass = number < 10 ? 'small' : number < 20 ? 'medium' : 'large';
-
- overlayEl.className = 'cluster-track-marker-case track-marker-case';
- textEl.className = 'cluster-track-marker-date track-marker-date';
- textEl.appendChild(dateRangeTextEl);
- circleEl.className = `cluster-marker cluster-marker-${sizeClass}`;
- innerCircleEl.className = 'cluster-marker-inner';
- innerCircleEl.appendChild(numberEl);
- circleEl.appendChild(innerCircleEl);
- circleEl.onclick = () => {
- const zoomTo = pointClusterObj.getClusterExpansionZoom(clusterId);
- const mapZoom = mapView.getZoom();
- mapUtilZoomAction(map, zoomTo - mapZoom, 450, coordinates);
- };
- overlayEl.appendChild(circleEl);
- overlayEl.appendChild(textEl);
-
- return new OlOverlay({
- position: coordinates,
- positioning: 'center-center',
- element: overlayEl,
- stopEvent: false,
- id: clusterId + properties.startDate + properties.endDate,
- });
-}
-
-function addOverlayIfIsVisible(map, overlay) {
- if (
- olExtent.containsCoordinate(
- map.getView().calculateExtent(),
- overlay.getPosition(),
- )
- ) {
- map.addOverlay(overlay);
- }
-}
diff --git a/web/js/map/natural-events/ui.js b/web/js/map/natural-events/ui.js
deleted file mode 100644
index bf98460cf..000000000
--- a/web/js/map/natural-events/ui.js
+++ /dev/null
@@ -1,430 +0,0 @@
-import * as olExtent from 'ol/extent';
-import * as olProj from 'ol/proj';
-import { forOwn as lodashForOwn, find as lodashFind } from 'lodash';
-import markers from './markers';
-import track from './track';
-import util from '../../util/util';
-import { CHANGE_TAB as CHANGE_SIDEBAR_TAB } from '../../modules/sidebar/constants';
-import * as EVENT_CONSTANTS from '../../modules/natural-events/constants';
-import { activateLayersForEventCategory } from '../../modules/layers/actions';
-import { selected as selectedAction } from '../../modules/natural-events/actions';
-import { getDefaultEventDate } from './util';
-import { selectDate } from '../../modules/date/actions';
-import { UPDATE_MAP_UI } from '../../modules/map/constants';
-import { LOCATION_POP_ACTION } from '../../redux-location-state-customs';
-
-const { events } = util;
-
-const zoomLevelReference = {
- Wildfires: 8,
- Volcanoes: 6,
-};
-
-// ui.map = state.map.ui
-
-export default function naturalEventsUI(ui, config, store) {
- const self = {};
- let map;
- let view;
- let isLoading = true;
- self.eventsData = [];
- self.layers = config.naturalEvents.layers;
- self.markers = [];
- self.selected = {};
- self.selecting = false;
- let naturalEventMarkers = markers(ui, store);
- const naturalEventsTracks = {};
- let naturalEventsTrack;
-
- /**
- * Suscribe to redux store and listen for
- * specific action types
- */
- const subscribeToStore = function(action) {
- const state = store.getState();
- const { events } = state;
- const {
- requestedEvents,
- requestedEventSources,
- } = state;
- switch (action.type) {
- case LOCATION_POP_ACTION: {
- const newState = util.fromQueryString(action.payload.search);
- if ((self.active && !newState.e) || (!self.active && newState.e)) {
- return onSidebarChange(newState.e);
- }
- return;
- }
- case CHANGE_SIDEBAR_TAB:
- return onSidebarChange(action.activeTab);
- case EVENT_CONSTANTS.SELECT_EVENT:
- return selectEvent(action.id, action.date);
- case EVENT_CONSTANTS.DESELECT_EVENT:
- return deselectEvent();
- case UPDATE_MAP_UI:
- if (map.proj !== action.ui.selected.proj) {
- onProjChange(action.ui.selected.proj);
- }
- return;
- case EVENT_CONSTANTS.REQUEST_EVENTS_SUCCESS:
- case EVENT_CONSTANTS.REQUEST_SOURCES_SUCCESS:
- if (!isLoading) return;
- isLoading = requestedEvents.isLoading
- || requestedEventSources.isLoading;
- if (!isLoading) {
- self.eventsData = requestedEvents.response;
- }
- if (!isLoading && state.sidebar.activeTab === 'events') {
- onQueryResults();
-
- const { selected } = events;
-
- if (selected.id) {
- return selectEvent(selected.id, selected.date, null, true);
- }
- }
- break;
- default:
- break;
- }
- };
-
- /**
- * Handle when switching to/from the 'Events' tab in the sidebar
- * @param {*} tab
- */
- const onSidebarChange = function(tab) {
- const { proj } = store.getState();
- if (tab === 'events') {
- self.active = true;
- // Remove previously stored markers
- naturalEventMarkers.remove(self.markers);
- // Store markers so the can be referenced later
- self.markers = naturalEventMarkers.draw();
-
- const isZoomed = Math.floor(view.getZoom()) >= 3;
- if (isZoomed || proj.selected.id !== 'geographic') {
- filterEventList();
- }
- // check if selected event is in changed projection
- if (self.selected.id) {
- const findSelectedInProjection = lodashFind(
- self.markers,
- (marker) => marker.pin && marker.pin.id === self.selected.id,
- );
- // remove selected event if not in changed projection
- if (!findSelectedInProjection) {
- deselectEvent();
- filterEventList();
- }
- }
- } else {
- naturalEventMarkers.remove(self.markers);
- self.active = false;
- }
- naturalEventsTrack.onSidebarChange(tab);
- };
-
- /**
- * Handle when the projection changes
- * @param {*} id
- */
- const onProjChange = function(id) {
- const state = store.getState();
- map = ui.map.selected;
- view = map.getView();
- naturalEventMarkers = markers(ui, store, map);
- if (naturalEventsTrack.trackDetails.id) naturalEventsTrack.update(null);
- naturalEventsTrack = naturalEventsTracks[id];
- // filter events within projection view extent
- filterEventList();
-
- // handle list filter on map move
- map.on('moveend', (e) => {
- filterEventList();
- });
-
- if (state.sidebar.activeTab === 'events') {
- // Remove previously stored markers
- naturalEventMarkers.remove(self.markers);
- // Store markers so the can be referenced later
- self.markers = naturalEventMarkers.draw();
- filterEventList();
- // check if selected event is in changed projection
- if (self.selected.id) {
- const findSelectedInProjection = lodashFind(
- self.markers,
- (marker) => marker.pin && marker.pin.id === self.selected.id,
- );
- // remove selected event if not in changed projection
- if (!findSelectedInProjection) {
- deselectEvent();
- filterEventList();
- }
- if (self.selected.date) {
- const event = self.eventsData.find((e) => e.id === self.selected.id);
- setTimeout(() => {
- naturalEventsTrack.update(event, self.selected.date);
- zoomToEvent(event, self.selected.date, null, false);
- });
- }
- }
- }
- };
-
- const onQueryResults = function() {
- const state = store.getState();
-
- if (state.sidebar.activeTab === 'events') {
- // Remove previously stored markers
- naturalEventMarkers.remove(self.markers);
- // Store markers so the can be referenced later
- self.markers = naturalEventMarkers.draw();
- }
-
- const isZoomed = Math.floor(view.getZoom()) >= 3;
- if (isZoomed || state.proj.selected.id !== 'geographic') {
- filterEventList();
- }
-
- map.on('moveend', (e) => {
- const isZoomed = Math.floor(view.getZoom()) >= 3;
- if (isZoomed || state.proj.selected.id !== 'geographic') {
- filterEventList();
- }
- });
-
- // Reselect previously selected event
- if (self.selected.id) {
- selectEvent(
- self.selected.id,
- self.selected.date || null,
- null,
- true,
- );
- }
- };
-
- const init = function() {
- map = ui.map.selected;
- lodashForOwn(ui.map.proj, (projMap, key) => {
- naturalEventsTracks[key] = track(ui, store, projMap);
- });
- naturalEventsTrack = naturalEventsTracks[store.getState().proj.id];
- // Display loading information for user feedback on slow network
- view = map.getView();
- events.on('redux:action-dispatched', subscribeToStore);
- };
-
- const getZoomPromise = function(
- event,
- date,
- rotation,
- isIdChange,
- isInitialLoad,
- ) {
- return isInitialLoad
- ? new Promise((resolve, reject) => {
- resolve();
- })
- : zoomToEvent(event, date, rotation, isIdChange);
- };
-
- /**
- * Select an event
- * @param {*} id
- * @param {*} date
- * @param {*} rotation
- * @param {*} isInitialLoad
- */
- const selectEvent = function(id, date, rotation, isInitialLoad) {
- const isIdChange = !self.selected || self.selected.id !== id;
- const prevId = self.selected.id ? self.selected.id : false;
- const prevEvent = prevId && self.eventsData.find((e) => e.id === prevId);
- const prevCategory = prevEvent ? prevEvent.categories[0].title : false;
- const event = self.eventsData.find((e) => e.id === id);
- const category = event && event.categories[0].title;
- const isSameCategory = category === prevCategory;
- if (!event) {
- return;
- }
- date = date || getDefaultEventDate(event);
- self.selected = {
- id,
- date,
- };
-
- const zoomPromise = getZoomPromise(
- event,
- date,
- rotation,
- !isIdChange,
- isInitialLoad,
- );
-
- // Remove previously stored markers
- naturalEventMarkers.remove(self.markers);
- // Store markers so the can be referenced later
- self.markers = naturalEventMarkers.draw();
- zoomPromise.then(() => {
- self.selecting = true;
-
- /* For Wildfires that didn't happen today, move the timeline forward a day
- * to improve the chance that the fire is visible.
- * NOTE: If the fire happened yesterday and the imagery isn't yet available
- * for today, this may not help.
- */
- if (event.categories[0].title === 'Wildfires' && !isInitialLoad) {
- const now = new Date();
- const today = now.toISOString().split('T')[0];
- const yesterday = new Date(now.setDate(now.getDate() - 1))
- .toISOString()
- .split('T')[0];
- if (date !== today || date !== yesterday) {
- store.dispatch(
- selectDate(util.dateAdd(util.parseDateUTC(date), 'day', 1)),
- );
- }
- } else if (!isInitialLoad) {
- store.dispatch(selectDate(util.parseDateUTC(date)));
- }
- self.selecting = false;
- if (isIdChange && !isSameCategory && !isInitialLoad) {
- activateLayersForCategory(event.categories[0].title);
- }
- // hack to update layers
- if (isIdChange) {
- ui.map.reloadLayers();
- } else {
- ui.map.updateDate();
- }
- naturalEventsTrack.update(event, date, selectEvent);
- store.dispatch(selectedAction());
- });
- };
-
- const deselectEvent = function() {
- self.selected = {};
- naturalEventMarkers.remove(self.markers);
- const state = store.getState();
- if (state.events.active) {
- self.markers = naturalEventMarkers.draw();
- naturalEventsTrack.update(null);
- }
- };
-
- /**
- * Filter event list in sidebar based on projection/view extents
- *
- * @param {Boolean} showAll - show all available points in projection
- */
- const filterEventList = function() {
- const state = store.getState();
- const { proj } = state;
- const { showAll } = state.events;
- if (isLoading || !state.sidebar.activeTab === 'events') return;
- const extent = view.calculateExtent();
- const { maxExtent } = proj.selected;
- const visibleListEvents = {};
-
- self.eventsData.forEach((naturalEvent) => {
- const isSelectedEvent = self.selected.id === naturalEvent.id;
- let date = getDefaultEventDate(naturalEvent);
- if (self.selected && self.selected.date) {
- date = self.selected.date;
- }
- const geometry = lodashFind(naturalEvent.geometry, (geometry) => geometry.date.split('T')[0] === date) || naturalEvent.geometry[0];
-
- let { coordinates } = geometry;
-
- if (proj.selected.id !== 'geographic') {
- // check for polygon geometries for targeted projection coordinate transform
- if (geometry.type === 'Polygon') {
- const coordinatesTransform = coordinates[0].map((coordinate) => olProj.transform(coordinate, 'EPSG:4326', proj.selected.crs));
- const geomExtent = olExtent.boundingExtent(coordinatesTransform);
- coordinates = olExtent.getCenter(geomExtent);
- } else {
- // if normal geometries, transform given lon/lat array
- coordinates = olProj.transform(
- coordinates,
- 'EPSG:4326',
- proj.selected.crs,
- );
- }
- } else if (geometry.type === 'Polygon') {
- const geomExtent = olExtent.boundingExtent(geometry.coordinates[0]);
- coordinates = olExtent.getCenter(geomExtent);
- }
-
- // limit to maxExtent while allowing zoom and filter 'out of extent' events
- let isVisible = olExtent.containsCoordinate(extent, coordinates)
- && olExtent.containsCoordinate(maxExtent, coordinates);
- // boolean showAll events limited to maxExtent of current projection
- if (showAll) {
- isVisible = olExtent.containsCoordinate(maxExtent, coordinates);
- }
- if (isVisible || isSelectedEvent) {
- visibleListEvents[naturalEvent.id] = true;
- }
- });
- };
-
- /**
- *
- * @param {*} category
- */
- const activateLayersForCategory = function(category) {
- const state = store.getState();
- const { proj } = state;
- category = category || 'Default';
- const currentProjection = proj.selected.id;
- // Turn on the relevant layers for the event type based on projection and category
- let activeLayers = self.layers[currentProjection][category];
- if (!activeLayers) activeLayers = self.layers[currentProjection].Default;
- store.dispatch(activateLayersForEventCategory(activeLayers));
- };
-
- /**
- *
- * @param {*} event
- * @param {*} date
- * @param {*} rotation
- * @param {*} isSameEventID
- */
- const zoomToEvent = function(event, date, rotation, isSameEventID) {
- const { proj } = store.getState();
- const category = event.categories[0].title;
- const zoom = isSameEventID
- ? ui.map.selected.getView().getZoom()
- : zoomLevelReference[category];
- const geometry = lodashFind(event.geometry, (geom) => geom.date.split('T')[0] === date);
-
- // check for polygon geometries and/or perform projection coordinate transform
- let coordinates = geometry.type === 'Polygon'
- ? olExtent.boundingExtent(
- olProj.transform(
- geometry.coordinates[0],
- 'EPSG:4326',
- proj.selected.crs,
- ),
- )
- : olProj.transform(
- geometry.coordinates,
- 'EPSG:4326',
- proj.selected.crs,
- );
-
- // handle extent transform for polar
- if (geometry.type === 'Polygon' && proj.selected.id !== 'geographic') {
- coordinates = olProj.transformExtent(
- coordinates,
- 'EPSG:4326',
- proj.selected.crs,
- );
- }
- return ui.map.animate.fly(coordinates, zoom, rotation);
- };
-
- init();
- return self;
-}