Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Add arrows to track #818

Benjamin King97e9eabc954f
diff --git a/web/css/events.css b/web/css/events.css
index d54ae40b2..0f9b5f6d3 100644
--- a/web/css/events.css
+++ b/web/css/events.css
@@ -201,6 +201,14 @@
cursor: pointer;
}
+.event-track-arrows {
+ background-size: contain;
+ background-repeat: repeat-x;
+ background-image: url('../images/natural-events/track-arrow.svg');
+ position:absolute;
+ text-align: center;
+ pointer-events: none;
+}
.track-marker-case .track-marker:hover ~ .track-marker-date {
display: block;
}
diff --git a/web/images/natural-events/track-arrow.svg b/web/images/natural-events/track-arrow.svg
new file mode 100644
index 000000000..9aa75b617
--- /dev/null
+++ b/web/images/natural-events/track-arrow.svg
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="0 0 30 16" width="30" height="16"><defs><clipPath id="_clipPath_t58cCUiIBQwtDGKPsdRu0ZOu6CCMkAae"><rect width="30" height="16"/></clipPath></defs><g clip-path="url(#_clipPath_t58cCUiIBQwtDGKPsdRu0ZOu6CCMkAae)"><path d=" M 11.517 14 C 11.647 13.995 11.77 13.936 11.86 13.835 L 16.854 8.386 C 17.049 8.174 17.049 7.829 16.854 7.616 L 11.86 2.168 C 11.735 2.025 11.549 1.968 11.373 2.018 C 11.199 2.068 11.062 2.217 11.016 2.407 C 10.97 2.598 11.023 2.802 11.154 2.938 L 15.795 8.001 L 11.154 13.064 C 11.007 13.221 10.962 13.46 11.042 13.668 C 11.122 13.874 11.311 14.006 11.517 14 Z " fill="rgb(0,0,0)" vector-effect="non-scaling-stroke" stroke-width="1" stroke="rgb(0,0,0)" stroke-linejoin="miter" stroke-linecap="butt" stroke-miterlimit="4"/><path d=" M 11.517 14 C 11.647 13.995 11.77 13.936 11.86 13.835 L 16.854 8.386 C 17.049 8.174 17.049 7.829 16.854 7.616 L 11.86 2.168 C 11.735 2.025 11.549 1.968 11.373 2.018 C 11.199 2.068 11.062 2.217 11.016 2.407 C 10.97 2.598 11.023 2.802 11.154 2.938 L 15.795 8.001 L 11.154 13.064 C 11.007 13.221 10.962 13.46 11.042 13.668 C 11.122 13.874 11.311 14.006 11.517 14 Z " fill="rgb(255,255,255)"/></g></svg>
\ No newline at end of file
diff --git a/web/js/naturalEvents/track.js b/web/js/naturalEvents/track.js
index 801cd6a41..43d558569 100644
--- a/web/js/naturalEvents/track.js
+++ b/web/js/naturalEvents/track.js
@@ -2,14 +2,11 @@ import OlFeature from 'ol/feature';
import OlOverlay from 'ol/overlay';
import OlLayerVector from 'ol/layer/vector';
import OlSourceVector from 'ol/source/vector';
-import OlStyleFill from 'ol/style/fill';
import OlStyleStroke from 'ol/style/stroke';
-import OlStyleCircle from 'ol/style/circle';
import OlStyleStyle from 'ol/style/style';
import OlGeomMultiLineString from 'ol/geom/multilinestring';
import lodashEach from 'lodash/each';
import lodashDebounce from 'lodash/debounce';
-
import { getEventById } from './util';
import {
naturalEventsPointToGeoJSON,
@@ -17,18 +14,19 @@ import {
naturalEventsCreateClusterObject,
sortCluster
} from './cluster';
-import {
- mapUtilZoomAction
-} from '../map/util';
-const firstClusterObj = naturalEventsCreateClusterObject();
-const secondClusterObj = naturalEventsCreateClusterObject();
+import { mapUtilZoomAction } from '../map/util';
+const firstClusterObj = naturalEventsCreateClusterObject(); // Cluster before selected event
+const secondClusterObj = naturalEventsCreateClusterObject();// Cluster after selected event
export default function naturalEventsTrack (models, ui, config) {
var self = {};
var model = models.naturalEvents;
self.trackDetails = {};
self.active = false;
+ /**
+ * @return {void}
+ */
var init = function() {
const map = ui.map.selected;
map.on('moveend', function (e) {
@@ -57,6 +55,18 @@ export default function naturalEventsTrack (models, ui, config) {
}
});
};
+ /**
+ * @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);
+ naturalEventsRemoveOldPoints(map, trackObj.pointArray);
+ return {};
+ };
+
self.update = function(event, map, selectedDate, callback) {
var newTrackDetails;
var trackDetails = self.trackDetails;
@@ -105,24 +115,18 @@ export default function naturalEventsTrack (models, ui, config) {
var debounceTrackUpdate = lodashDebounce((event, selectedDate, map, selectEventCallback) => {
self.update(event, map, selectedDate, selectEventCallback);
}, 1000);
- self.removeTrack = function(map, trackObj) {
- map.removeLayer(trackObj.track);
- naturalEventsRemoveOldPoints(map, trackObj.pointArray);
- return {};
- };
+
init();
return self;
}
-var naturalEventsTrackLayer = function(featuresArray, styles) {
+
+var naturalEventsTrackLayer = function(featuresArray) {
return new OlLayerVector({
source: new OlSourceVector({
features: featuresArray
}),
extent: [-180, -90, 180, 90],
- style: function(feature) {
- return styles[feature.get('type')];
- }
-
+ style: [getLineStyle('black', 2), getLineStyle('white', 1)]
});
};
var naturalEventsTrackPoint = function(clusterPoint, isSelected, callback) {
@@ -155,42 +159,23 @@ var naturalEventsTrackPoint = function(clusterPoint, isSelected, callback) {
});
};
-var naturalEventsTrackLine = function(coordinateArray, type) {
+var naturalEventsTrackLine = function(coordinateArray) {
return new OlFeature({
- type: type,
geometry: new OlGeomMultiLineString(coordinateArray)
});
};
-var naturalEventsTrackStyle = function() {
- return {
- 'geoMarker': new OlStyleStyle({
- image: new OlStyleCircle({
- radius: 4,
- snapToPixel: false,
- fill: new OlStyleFill({ color: 'white' }),
- stroke: new OlStyleStroke({
- color: 'white',
- width: 2
- })
- })
- }),
- 'white-line': new OlStyleStyle({
- stroke: new OlStyleStroke({
- color: 'white',
- width: 1
- })
- }),
- 'black-line': new OlStyleStyle({
- stroke: new OlStyleStroke({
- color: 'black',
- width: 2
- })
+
+var getLineStyle = function(color, width) {
+ return new OlStyleStyle({
+ stroke: new OlStyleStroke({
+ color: color,
+ width: width
})
- };
+ });
};
+
var createTrack = function (eventObj, map, selectedDate, callback) {
var olPointCoordinates = [];
- var eventTrackStyles;
var olTrackLineFeatures = [];
var pointObject = {};
var geoJSONPointsBeforeSelected = [];
@@ -222,15 +207,13 @@ var createTrack = function (eventObj, map, selectedDate, callback) {
clustersAfterSelected = naturalEventsGetClusterPoints(secondClusterObj, geoJSONPointsAfterSelected, zoom);
clusters = clustersBeforeSelected.concat([selectedPoint], clustersAfterSelected);
sortCluster(clusters);
- eventTrackStyles = naturalEventsTrackStyle();
pointObject = addPoints(clusters, map, selectedDate, callback);
- olTrackLineFeatures.push(naturalEventsTrackLine(pointObject.trackArray, 'black-line'));
- olTrackLineFeatures.push(naturalEventsTrackLine(pointObject.trackArray, 'white-line'));
+ olTrackLineFeatures.push(naturalEventsTrackLine(pointObject.trackArray));
return {
'id': eventObj.id,
- 'track': naturalEventsTrackLayer(olTrackLineFeatures, eventTrackStyles),
+ 'track': naturalEventsTrackLayer(olTrackLineFeatures, map),
'pointArray': pointObject.overlayArray,
'selectedDate': selectedDate,
'hidden': false
@@ -248,17 +231,52 @@ var updateSelection = function (newDate) {
oldSelectedPoint.className = 'track-marker-case';
newSelectedPoint.className = 'track-marker-case track-marker-case-selected';
};
+var createArrows = function (lineSegmentCoords, map) {
+ var overlayEl = document.createElement('div');
+ var innerEl = document.createElement('div');
+
+ 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(Math.pow(dx, 2) + Math.pow(dy, 2));
+ const angleRadians = Math.atan2(dyCoord, dxCoord);
+ const angleDegrees = -angleRadians * (180 / Math.PI);
+
+ innerEl.className = 'event-track-arrows';
+ overlayEl.appendChild(innerEl);
+ overlayEl.style.width = '1px';
+ overlayEl.style.height = '1px';
+ innerEl.style.width = distanceInPixels + 'px';
+ innerEl.style.height = '16px';
+ innerEl.style.transform = 'translate(' + -(distanceInPixels / 2) + 'px' + ', -8px)';
+ overlayEl.style.transform = 'rotate(' + angleDegrees + 'deg)';
+ return new OlOverlay({
+ position: map.getCoordinateFromPixel(pixelMidPoint),
+ positioning: 'center-center',
+ stopEvent: true,
+ element: overlayEl
+ });
+};
var addPoints = function(clusters, map, selectedDate, callback) {
var overlays = [];
var trackArray = [];
-
lodashEach(clusters, function(clusterPoint, index) {
let point;
let date = clusterPoint.properties.date || clusterPoint.properties.startDate;
let isSelected = (selectedDate === date);
let pointClusterObj = (new Date(date) > new Date(selectedDate)) ? firstClusterObj : secondClusterObj;
if (index !== 0) {
- trackArray.push([clusters[index - 1].geometry.coordinates, clusterPoint.geometry.coordinates]);
+ let lineSegmentArray = [clusters[index - 1].geometry.coordinates, clusterPoint.geometry.coordinates];
+ let arrowOverlay = createArrows(lineSegmentArray, map);
+ overlays.push(arrowOverlay);
+ trackArray.push(lineSegmentArray);
+ map.addOverlay(arrowOverlay);
}
if (clusterPoint.properties.cluster) {
point = getClusterPointEl(clusterPoint, map, pointClusterObj, callback);