Interactive interface for browsing global, full-resolution satellite imagery
Add labels and inverse-clipping to compare modes #1118
Benjamin Kingd1d739b27024
diff --git a/web/css/compare.css b/web/css/compare.cssindex 4f78f420a..f940143d9 100644--- a/web/css/compare.css+++ b/web/css/compare.css@@ -11,7 +11,8 @@top: 50%;width: 30px;height: 30px;- left: -12px;+ margin-top: -15px;+ left: -13px;border-radius: 50%;color: black;background: white;@@ -32,7 +33,48 @@left: 0;right: 0;bottom: 25%;- width: 150px;+ width: 160px;text-align: center;background: rgba(40, 40, 40, 0.85);+ color: white;+}+.ab-slider-case span {+ position: absolute;+ top: 5px;+ font-size: 14px;+}+.ab-swipe-line .ab-swipe-span {+ position: absolute;+ top: 50%;+ padding: 2px;+ background: white;+ color: black;+ display: block;+ font-size: 14px;+ margin-top: -7px;+ border-radius: 3px;+ border: 1px solid black;+}+.ab-swipe-line .left-label {+ left: -35px;+}+.ab-swipe-line .right-label {+ left: 24px;+}+.ab-spy-span {+ position: absolute;+ background: white;+ color: black;+ display: block;+ font-size: 14px;+ border-radius: 3px;+ border: 1px solid black;+ padding: 2px;+ margin-left: -4px;+}+.ab-slider-case .left-label {+ left: 3px;+}+.ab-slider-case .right-label {+ right: 3px;}diff --git a/web/js/map/compare/compare.js b/web/js/map/compare/compare.jsindex a1e12a4df..2873d6637 100644--- a/web/js/map/compare/compare.js+++ b/web/js/map/compare/compare.js@@ -13,14 +13,14 @@ export function mapCompare(models, config) {self.create = function(map, compareMode) {if (compareMode === mode && comparison && proj === models.proj.selected) {- comparison.update();+ comparison.update(models.compare.isCompareA);} else if (comparison) {mode = compareMode;self.destroy();- comparison = new self[compareMode](map); // e.g. new self.swipe()+ comparison = new self[compareMode](map, models.compare.isCompareA); // e.g. new self.swipe()} else {mode = compareMode;- comparison = new self[compareMode](map); // e.g. new self.swipe()+ comparison = new self[compareMode](map, models.compare.isCompareA); // e.g. new self.swipe()}self.active = true;proj = models.proj.selected;diff --git a/web/js/map/compare/opacity.js b/web/js/map/compare/opacity.jsindex 151c0f2fd..91b5aa025 100644--- a/web/js/map/compare/opacity.js+++ b/web/js/map/compare/opacity.js@@ -19,16 +19,27 @@ export class Opacity {createSlider(map, secondLayer) {var sliderCaseEl = document.createElement('div');var sliderInputEl = document.createElement('input');+ var firstLabel = document.createElement('span');+ var secondLabel = document.createElement('span');+ firstLabel.className = 'ab-opacity-span left-label';+ secondLabel.className = 'ab-opacity-span right-label';var mapCase = document.getElementById('wv-map');+ firstLabel.appendChild(document.createTextNode('A'));+ secondLabel.appendChild(document.createTextNode('B'));+sliderCaseEl.className = 'ab-slider-case';sliderInputEl.className = 'slider ab-slider-input';sliderInputEl.type = 'range';sliderInputEl.min = '0';sliderInputEl.max = '100';sliderInputEl.value = value;+ secondLayer.setOpacity(value / 100);+ sliderCaseEl.appendChild(firstLabel);sliderCaseEl.appendChild(sliderInputEl);+ sliderCaseEl.appendChild(secondLabel);mapCase.appendChild(sliderCaseEl);+sliderInputEl.oninput = function() {value = this.value;secondLayer.setOpacity(this.value / 100);diff --git a/web/js/map/compare/spy.js b/web/js/map/compare/spy.jsindex 53c0a2d9b..722ce1424 100644--- a/web/js/map/compare/spy.js+++ b/web/js/map/compare/spy.js@@ -2,41 +2,107 @@ import lodashEach from 'lodash/each';var mousePosition = null;var spy = null;-var layers = [];+var topLayers = [];+var bottomLayers = [];var map;-var radius = 70;+const DEFAULT_RADIUS = 70;+var radius = DEFAULT_RADIUS;+var firstLabel = null;+var secondLabel = null;export class Spy {- constructor(olMap) {+ constructor(olMap, isBInside) {map = olMap;- this.create();+ this.create(isBInside);}- create() {- spy = this.addSpy(map);- this.update();+ create(isBInside) {+ spy = this.addSpy(map, isBInside);+ this.isBInside = isBInside;+ this.update(isBInside);}- update() {- var mapLayers = map.getLayers().getArray();- applyEventsToBaseLayers(mapLayers[1], map, applyLayerListeners);+ update(isBInside) {+ if (this.isBInside !== isBInside) {+ this.destroy();+ this.create(isBInside);+ } else {+ var mapLayers = map.getLayers().getArray();+ applyEventsToBaseLayers(mapLayers[0], map, applyreverseLayerListeners);+ applyEventsToBaseLayers(mapLayers[1], map, applyLayerListeners);+ }}destroy() {spy.removeEventListener('mousemove', this.updateSpy);- removeListenersFromLayers(layers);+ firstLabel.remove();+ secondLabel.remove();+ removeListenersFromLayers(topLayers);+ removeInverseListenersFromLayers(bottomLayers);}updateSpy(e) {mousePosition = map.getEventPixel(e);+ radius = DEFAULT_RADIUS;map.render();}- addSpy(map) {+ hideSpy(e) {+ radius = 0;+ firstLabel.style.display = 'none';+ secondLabel.style.display = 'none';+ map.render();+ }+ showSpy() {+ radius = DEFAULT_RADIUS;+ firstLabel.style.display = 'block';+ secondLabel.style.display = 'block';+ map.render();+ }+ addSpy(map, isBInside) {var mapCase = document.getElementById('wv-map');+ var insideText = !isBInside ? 'A' : 'B';+ var outsideText = !isBInside ? 'B' : 'A';+ firstLabel = document.createElement('span');+ secondLabel = document.createElement('span');+ firstLabel.className = 'ab-spy-span inside-label';+ secondLabel.className = 'ab-spy-span outside-label';+ firstLabel.appendChild(document.createTextNode(insideText));+ secondLabel.appendChild(document.createTextNode(outsideText));++ mapCase.appendChild(firstLabel);+ mapCase.appendChild(secondLabel);+mapCase.addEventListener('mousemove', this.updateSpy);+ mapCase.addEventListener('mouseleave', this.hideSpy);+ mapCase.addEventListener('mouseenter', this.showSpy);+return mapCase;}}-+var applyreverseLayerListeners = function(layer) {+ layer.on('precompose', inverseClip);+ layer.on('postcompose', restore);+ bottomLayers.push(layer);+};var applyLayerListeners = function(layer) {layer.on('precompose', clip);layer.on('postcompose', restore);- layers.push(layer);+ topLayers.push(layer);+};+var inverseClip = function(event) {+ var ctx = event.context;+ var pixelRatio = event.frameState.pixelRatio;+ ctx.save();+ ctx.beginPath();+ if (mousePosition) {+ // only show a circle around the mouse+ let x = mousePosition[0];+ let y = mousePosition[1];+ ctx.arc(+ x * pixelRatio,+ y * pixelRatio,+ radius * pixelRatio,+ 0,+ 2 * Math.PI+ );+ ctx.rect(ctx.canvas.width, ctx.canvas.height, -ctx.canvas.width, 0);+ ctx.fill();+ }};var clip = function(event) {var ctx = event.context;@@ -45,13 +111,19 @@ var clip = function(event) {ctx.beginPath();if (mousePosition) {// only show a circle around the mouse+ let x = mousePosition[0];+ let y = mousePosition[1];ctx.arc(- mousePosition[0] * pixelRatio,- mousePosition[1] * pixelRatio,+ x * pixelRatio,+ y * pixelRatio,radius * pixelRatio,0,2 * Math.PI);+ firstLabel.style.top = y + 45 + 'px';+ firstLabel.style.left = x + 'px';+ secondLabel.style.top = y + 80 + 'px';+ secondLabel.style.left = x + 'px';ctx.lineWidth = 5 * pixelRatio;ctx.strokeStyle = 'rgba(0,0,0,0.5)';ctx.stroke();@@ -68,6 +140,12 @@ var removeListenersFromLayers = function(layers) {layer.un('postcompose', restore);});};+var removeInverseListenersFromLayers = function(layers) {+ lodashEach(layers, layer => {+ layer.un('precompose', inverseClip);+ layer.un('postcompose', restore);+ });+};var applyEventsToBaseLayers = function(layer, map, callback) {var layers = layer.get('layers');