From 02261c96e0353fff7595dc40fb047ca1477d4566 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Tue, 18 Dec 2018 12:01:22 -0500 Subject: [PATCH] adding svg layer... ref #5587 --- modules/svg/geolocate.js | 91 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 modules/svg/geolocate.js diff --git a/modules/svg/geolocate.js b/modules/svg/geolocate.js new file mode 100644 index 000000000..8a06d769d --- /dev/null +++ b/modules/svg/geolocate.js @@ -0,0 +1,91 @@ + +export function svgGeolocate(projection, context, dispatch) { + var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000); + var minZoom = 12; + var layer = d3_select(null); + var _mapillary; + + + function init() { + if (svgGeolocate.initialized) return; // run once + svgGeolocate.enabled = false; + svgGeolocate.initialized = true; + } + + function showLayer() { + layer.attr('display', 'block'); + layerOn(); + } + + + function hideLayer() { + throttledRedraw.cancel(); + layer + .transition() + .duration(250) + .style('opacity', 0) + .on('end', function() {}); + } + + function layerOn() { + layer + .style('opacity', 0) + .transition() + .duration(250) + .style('opacity', 1) + .on('end', function () { dispatch.call('change'); }); + + } + + function layerOff() { + // layer.selectAll('.viewfield-group').remove(); + layer.style('display', 'none'); + } + + function update(location) { + + var groups = layer.selectAll('.markers').selectAll('.viewfield-group') + .data([location]); + + } + + function drawLocation(selection) { + var enabled = svgGeolocate.enabled; + + layer = selection.selectAll('.layer-mapillary-signs') + .data([]); + + layer.exit() + .remove(); + + layer = layer.enter() + .append('g') + .attr('class', 'layer-geolocate-point') + .style('display', enabled ? 'block' : 'none') + .merge(layer); + + if (enabled) { + layerOn(); + update(); + } else { + layerOff(); + } + } + + drawLocation.enabled = function(_) { + if (!arguments.length) return svgGeolocate.enabled; + svgGeolocate.enabled = _; + if (svgGeolocate.enabled) { + showLayer(); + } else { + hideLayer(); + } + dispatch.call('change'); + return this; + }; + + + + init(); + return drawLocation; +}