Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Add compare picks #990

Benjamin King00094d139361
diff --git a/web/css/timeline.css b/web/css/timeline.css
index 3cb9b4a49..82780b572 100644
--- a/web/css/timeline.css
+++ b/web/css/timeline.css
@@ -22,7 +22,7 @@ button:focus {
}
#timeline-footer text {
- font: 400 12px/125% 'Roboto Mono', monospace;
+ font: 400 12px/125% "Roboto Mono", monospace;
text-align: start;
letter-spacing: 0;
word-spacing: 0;
@@ -204,7 +204,7 @@ g.plot rect.data-bar-invisible {
font-size: 24px;
background: transparent;
border: 0;
- font-family: 'Roboto Mono', monospace;
+ font-family: "Roboto Mono", monospace;
line-height: 1.2em;
vertical-align: baseline;
box-sizing: border-box;
@@ -235,10 +235,11 @@ g.plot rect.data-bar-invisible {
#timeline-header div {
display: inline-block;
+ vertical-align: top;
}
#timeline-header .input-time-divider {
- font-family: 'Roboto Mono', monospace;
+ font-family: "Roboto Mono", monospace;
color: #fff;
font-size: 24px;
vertical-align: middle;
@@ -248,7 +249,7 @@ g.plot rect.data-bar-invisible {
}
#timeline-header .input-time-zmark {
- font-family: 'Roboto Mono', monospace;
+ font-family: "Roboto Mono", monospace;
color: #fff;
font-size: 24px;
vertical-align: middle;
@@ -320,7 +321,10 @@ g.plot rect.data-bar-invisible {
}
#timeline-header > .button-action-group .button-disabled:hover,
-#timeline-header #zoom-buttons-group .button-action-group .button-disabled:hover {
+#timeline-header
+ #zoom-buttons-group
+ .button-action-group
+ .button-disabled:hover {
background-color: transparent;
cursor: default;
}
@@ -352,15 +356,26 @@ g.plot rect.data-bar-invisible {
}
#timeline-header > .button-action-group.button-disabled .arrow,
-#timeline-header #zoom-buttons-group .button-action-group.button-disabled .arrow {
+#timeline-header
+ #zoom-buttons-group
+ .button-action-group.button-disabled
+ .arrow {
fill: #333;
}
#timeline-header > .button-action-group.button-disabled:hover .arrow,
-#timeline-header #zoom-buttons-group .button-action-group.button-disabled:hover .arrow {
+#timeline-header
+ #zoom-buttons-group
+ .button-action-group.button-disabled:hover
+ .arrow {
fill: #333;
}
+#timeline-header .animate-button {
+ margin-top: 10px;
+ height: 40px;
+ width: 40px;
+}
#timeline-header .animate-button .wv-animate {
color: #fff;
font-size: 2.5em;
@@ -380,7 +395,8 @@ g.plot rect.data-bar-invisible {
color: #ccc;
}
-#timeline-header, #timeline-footer {
+#timeline-header,
+#timeline-footer {
float: left;
}
@@ -473,7 +489,7 @@ g.plot rect.data-bar-invisible {
cursor: pointer;
text-transform: uppercase;
text-align: center;
- font-family: 'Roboto Mono', monospace;
+ font-family: "Roboto Mono", monospace;
margin-top: -2px;
}
@@ -488,7 +504,7 @@ g.plot rect.data-bar-invisible {
cursor: pointer;
text-transform: uppercase;
text-align: center;
- font-family: 'Roboto Mono', monospace;
+ font-family: "Roboto Mono", monospace;
font-size: 14px;
line-height: 16px;
color: #ccc;
@@ -560,3 +576,30 @@ g.plot rect.data-bar-invisible {
#timeline-hide:hover .hamburger path {
fill: #1a1a1a;
}
+.ab-group-case {
+ display: none;
+}
+.ab-group-case-active {
+ fill: white;
+}
+.ab-group-case polygon,
+.ab-group-case rect {
+ fill: gray;
+ opacity: 0.7;
+ pointer-events: none;
+}
+.ab-group-case-active polygon,
+.ab-group-case-active rect {
+ fill: white;
+ opacity: 1;
+ pointer-events: initial;
+}
+.ab-active .ab-group-case {
+ display: block;
+}
+.ab-active #guitarpick {
+ display: none !important;
+}
+.ab-group-case text {
+ pointer-events: none;
+}
diff --git a/web/js/date/compare-picks.js b/web/js/date/compare-picks.js
new file mode 100644
index 000000000..f437c366c
--- /dev/null
+++ b/web/js/date/compare-picks.js
@@ -0,0 +1,114 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { TimelineDragger } from 'worldview-components';
+import $ from 'jquery';
+import lodashDebounce from 'lodash/debounce';
+import util from '../util/util';
+
+const DEBOUCE_TIME = 100;
+
+export function timelineCompare(models, config, ui) {
+ var self = {};
+ var xmlns = 'http://www.w3.org/2000/svg';
+
+ var timeline = ui.timeline;
+ var $footer = $('#timeline-footer');
+ var $header = $('#timeline-header');
+ var $timeline = $('#timeline');
+ var mountObjectA;
+ var mountObjectB;
+ if (models.compare.active) {
+ $timeline.addClass('ab-active');
+ }
+ var init = function() {
+ mountObjectA = document.createElementNS(xmlns, 'g');
+ mountObjectB = document.createElementNS(xmlns, 'g');
+ applyActiveClasses();
+
+ var svg = document.getElementById('timeline-footer-svg');
+ svg.appendChild(mountObjectA);
+ svg.appendChild(mountObjectB);
+ self.comparePickA = ReactDOM.render(
+ React.createElement(TimelineDragger, getInitialProps('', 'A')),
+ mountObjectA
+ );
+ self.comparePickB = ReactDOM.render(
+ React.createElement(TimelineDragger, getInitialProps('B', 'B')),
+ mountObjectB
+ );
+ models.compare.events.on('toggle', () => {
+ $timeline.toggleClass('ab-active');
+ updateState();
+ });
+ models.compare.events.on('toggle-state', applyActiveClasses);
+ models.date.events.on('timeline-change', updateState);
+ };
+ var applyActiveClasses = function() {
+ if (models.compare.isCompareA) {
+ mountObjectA.setAttribute('class', 'ab-group-case ab-group-case-active');
+ mountObjectB.setAttribute('class', 'ab-group-case');
+ } else {
+ mountObjectA.setAttribute('class', 'ab-group-case ');
+ mountObjectB.setAttribute('class', 'ab-group-case ab-group-case-active');
+ }
+ };
+ var getInitialProps = function(compareLetter, label) {
+ return {
+ id: 'selected' + compareLetter,
+ onDrag: lodashDebounce(onDrag, DEBOUCE_TIME),
+ yOffset: 15,
+ draggerID: 'compare-dragger-' + compareLetter,
+ position: getLocationFromStringDate(
+ models.date['selected' + compareLetter]
+ ),
+ text: label
+ };
+ };
+ var updateState = function() {
+ self.comparePickA.setState({
+ position: getLocationFromStringDate(models.date['selected'])
+ });
+ self.comparePickB.setState({
+ position: getLocationFromStringDate(models.date['selectedB'])
+ });
+ };
+ /*
+ * calculates offset of timeline
+ *
+ * @method getHeaderOffset
+ * @static
+ *
+ * @returns {number} OffsetX
+ *
+ */
+ self.getHeaderOffset = function() {
+ return (
+ $header.width() +
+ Number($timeline.css('left').replace('px', '')) +
+ Number($footer.css('margin-left').replace('px', ''))
+ );
+ };
+ var getLocationFromStringDate = function(date) {
+ return timeline.x(util.roundTimeTenMinute(date));
+ };
+ /*
+ * Handles click on widget:
+ * switches current date to
+ * date clicked
+ *
+ * @method onRangeClick
+ * @static
+ *
+ * @param e {object} native event object
+ *
+ * @returns {object} props
+ *
+ */
+ var onDrag = function(e, id, offsetX) {
+ var date = timeline.x.invert(offsetX);
+ models.date.select(date, id);
+ };
+
+ init();
+ return self;
+}
diff --git a/web/js/date/timeline.js b/web/js/date/timeline.js
index f4d380eaf..ba45d3374 100644
--- a/web/js/date/timeline.js
+++ b/web/js/date/timeline.js
@@ -15,19 +15,19 @@ export function timeline(models, config, ui) {
left: 30
};
- self.getPadding = function () {
+ self.getPadding = function() {
self.padding = self.width / 4;
return self.padding;
};
- self.getWidth = function () {
- self.width = $(window)
- .outerWidth(true) -
- $('#timeline-header')
- .outerWidth(true) -
- $('#timeline-hide')
- .outerWidth(true) -
- self.margin.left - self.margin.right + 28;
+ self.getWidth = function() {
+ self.width =
+ $(window).outerWidth(true) -
+ $('#timeline-header').outerWidth(true) -
+ $('#timeline-hide').outerWidth(true) -
+ self.margin.left -
+ self.margin.right +
+ 28;
return self.width;
};
@@ -35,12 +35,12 @@ export function timeline(models, config, ui) {
self.isCropped = true;
- self.toggle = function (now) {
+ self.toggle = function(now) {
var tl = $('#timeline-footer');
var tlg = self.boundary;
var gp = d3.select('#guitarpick');
if (tl.is(':hidden')) {
- var afterShow = function () {
+ var afterShow = function() {
tlg.attr('style', 'clip-path:url("#timeline-boundary")');
gp.attr('style', 'display:block;clip-path:url(#guitarpick-boundary);');
};
@@ -50,18 +50,16 @@ export function timeline(models, config, ui) {
} else {
tl.show('slow', afterShow);
}
- $('#timeline')
- .removeClass('closed');
+ $('#timeline').removeClass('closed');
} else {
tlg.attr('style', 'clip-path:none');
gp.attr('style', 'display:none;clip-path:none');
tl.hide('slow');
- $('#timeline')
- .addClass('closed');
+ $('#timeline').addClass('closed');
}
};
- self.expand = function (now) {
+ self.expand = function(now) {
now = now || false;
var tl = $('#timeline-footer');
if (tl.is(':hidden')) {
@@ -69,73 +67,87 @@ export function timeline(models, config, ui) {
}
};
- self.expandNow = function () {
+ self.expandNow = function() {
self.expand(true);
};
- self.collapse = function (now) {
+ self.collapse = function(now) {
var tl = $('#timeline-footer');
if (!tl.is(':hidden')) {
self.toggle(now);
}
};
- self.collapseNow = function () {
+ self.collapseNow = function() {
self.collapse(true);
};
- self.resize = function () {
+ self.resize = function() {
var small = util.browser.small || util.browser.constrained;
if (self.enabled && small) {
self.enabled = false;
- $('#timeline')
- .hide();
+ $('#timeline').hide();
} else if (!self.enabled && !small) {
self.enabled = true;
- $('#timeline')
- .show();
+ $('#timeline').show();
}
if (self.enabled) {
self.getWidth();
- self.svg.attr('width', self.width)
- .attr('viewBox', '0 1 ' + self.width + ' ' + (self.height + self.margin.top + self.margin.bottom + 26));
+ self.svg
+ .attr('width', self.width)
+ .attr(
+ 'viewBox',
+ '0 1 ' +
+ self.width +
+ ' ' +
+ (self.height + self.margin.top + self.margin.bottom + 26)
+ );
- d3.select('#timeline-boundary rect')
- .attr('width', self.width);
+ d3.select('#timeline-boundary rect').attr('width', self.width);
- d3.select('#guitarpick-boundary rect')
- .attr('width', self.width +
- self.margin.left +
- self.margin.right);
+ d3.select('#guitarpick-boundary rect').attr(
+ 'width',
+ self.width + self.margin.left + self.margin.right
+ );
- self.axis.select('line:first-child')
- .attr('x2', self.width);
+ self.axis.select('line:first-child').attr('x2', self.width);
}
};
- self.setClip = function () { // This is a hack until Firefox fixes their svg rendering problems
- d3.select('#timeline-footer svg > g:nth-child(2)')
- .attr('visibility', 'hidden');
- d3.select('#timeline-footer svg > g:nth-child(2)')
- .attr('style', '');
- setTimeout(function () {
- d3.select('#timeline-footer svg > g:nth-child(2)')
- .attr('style', 'clip-path:url("#timeline-boundary")');
- d3.select('#timeline-footer svg > g:nth-child(2)')
- .attr('visibility', '');
+ self.setClip = function() {
+ // This is a hack until Firefox fixes their svg rendering problems
+ d3.select('#timeline-footer svg > g:nth-child(2)').attr(
+ 'visibility',
+ 'hidden'
+ );
+ d3.select('#timeline-footer svg > g:nth-child(2)').attr('style', '');
+ setTimeout(function() {
+ d3.select('#timeline-footer svg > g:nth-child(2)').attr(
+ 'style',
+ 'clip-path:url("#timeline-boundary")'
+ );
+ d3.select('#timeline-footer svg > g:nth-child(2)').attr('visibility', '');
}, 50);
};
- var drawContainers = function () {
+ var drawContainers = function() {
self.getWidth();
- self.svg = d3.select('#timeline-footer')
+ self.svg = d3
+ .select('#timeline-footer')
.append('svg:svg')
.attr('width', self.width) // + margin.left + margin.right)
.attr('height', self.height + self.margin.top + self.margin.bottom + 42)
- .attr('viewBox', '0 1 ' + self.width + ' ' + (self.height + self.margin.top + self.margin.bottom + 26));
+ .attr('id', 'timeline-footer-svg')
+ .attr(
+ 'viewBox',
+ '0 1 ' +
+ self.width +
+ ' ' +
+ (self.height + self.margin.top + self.margin.bottom + 26)
+ );
self.svg
.append('svg:defs')
@@ -159,7 +171,8 @@ export function timeline(models, config, ui) {
.attr('style', 'clip-path:url(#timeline-boundary)')
.attr('transform', 'translate(0,16)');
- self.axis = self.boundary.append('svg:g')
+ self.axis = self.boundary
+ .append('svg:g')
.attr('class', 'x axis')
.attr('transform', 'translate(0,' + self.height + ')');
@@ -168,45 +181,50 @@ export function timeline(models, config, ui) {
.attr('x1', 0)
.attr('x2', self.width); // +margin.left+margin.right);
- self.dataBars = self.boundary.insert('svg:g', '.x.axis')
+ self.dataBars = self.boundary
+ .insert('svg:g', '.x.axis')
.attr('height', self.height)
.classed('plot', true);
- self.verticalAxis = self.boundary.append('svg:g')
+ self.verticalAxis = self.boundary
+ .append('svg:g')
.attr('class', 'y axis')
.attr('transform', 'translate(0,0)');
self.animboundary = self.svg
.append('svg:g')
.attr('clip-path', '#timeline-boundary')
.attr('transform', 'translate(0,16)');
- self.animboundary
- .append('g')
- .attr('id', 'wv-rangeselector-case');
+ self.animboundary.append('g').attr('id', 'wv-rangeselector-case');
};
- var init = function () {
+ var init = function() {
var $timelineFooter = $('#timeline-footer');
models.layers.events.trigger('toggle-subdaily');
drawContainers();
- if (!models.anim) { // Hack: margin if anim is present
- $('#animate-button')
- .hide();
+ if (!models.anim) {
+ // Hack: margin if anim is present
+ $('#animate-button').hide();
$timelineFooter.css('margin-left', self.margin.left - 1 + 'px');
$timelineFooter.css('margin-right', self.margin.right - 1 + 'px');
} else {
$timelineFooter.css('margin-left', '0');
- $timelineFooter.css('margin-right', (self.margin.right + self.margin.left) - 32 + 'px');
+ $timelineFooter.css(
+ 'margin-right',
+ self.margin.right + self.margin.left - 32 + 'px'
+ );
}
self.x = d3.time.scale.utc();
- self.xAxis = d3.svg.axis()
+ self.xAxis = d3.svg
+ .axis()
.orient('bottom')
.tickSize(-self.height)
.tickPadding(5);
- self.axisZoom = d3.behavior.zoom()
+ self.axisZoom = d3.behavior
+ .zoom()
.scale(1)
.scaleExtent([1, 1]);
@@ -218,30 +236,28 @@ export function timeline(models, config, ui) {
}
}
- $('#timeline-hide')
- .click(function () {
- self.toggle();
- });
+ $('#timeline-hide').click(function() {
+ self.toggle();
+ });
- $(window)
- .resize(function () {
- self.resize();
- self.zoom.refresh();
- self.setClip();
- });
+ $(window).resize(function() {
+ self.resize();
+ self.zoom.refresh();
+ self.setClip();
+ });
- model.events.on('select', function () {
+ model.events.on('select', function() {
self.input.update();
self.pick.shiftView();
});
- models.layers.events.on('change', function () {
+ models.layers.events.on('change', function() {
self.data.set();
self.resize();
self.setClip();
});
- models.proj.events.on('select', function () {
+ models.proj.events.on('select', function() {
self.resize();
self.setClip();
});
@@ -249,4 +265,4 @@ export function timeline(models, config, ui) {
init();
return self;
-};
+}