From 961a79e4f2b6987eeb2580f15cf501befa3009b2 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Thu, 16 May 2019 14:52:41 -0400 Subject: [PATCH] Add photo overlays used during editing to the "source" changeset tag (close #6279) --- modules/core/history.js | 20 ++++++++++++++++++++ modules/renderer/background.js | 33 +++++++++++++++------------------ modules/ui/commit.js | 17 +++++++++++++++++ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/modules/core/history.js b/modules/core/history.js index deefb97cb..518cba0a6 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -18,6 +18,7 @@ export function coreHistory(context) { var lock = utilSessionMutex('lock'); var duration = 150; var _imageryUsed = []; + var _photoOverlaysUsed = []; var _checkpoints = {}; var _pausedGraph; var _stack; @@ -43,6 +44,7 @@ export function coreHistory(context) { graph: graph, annotation: annotation, imageryUsed: _imageryUsed, + photoOverlaysUsed: _photoOverlaysUsed, transform: context.projection.transform(), selectedIDs: context.selectedIDs() }; @@ -314,6 +316,22 @@ export function coreHistory(context) { }, + photoOverlaysUsed: function(sources) { + if (sources) { + _photoOverlaysUsed = sources; + return history; + } else { + var s = new Set(); + _stack.slice(1, _index + 1).forEach(function(state) { + state.photoOverlaysUsed.forEach(function(photoOverlay) { + s.add(photoOverlay); + }); + }); + return Array.from(s); + } + }, + + // save the current history state checkpoint: function(key) { _checkpoints[key] = { @@ -468,6 +486,7 @@ export function coreHistory(context) { if (modified.length) x.modified = modified; if (deleted.length) x.deleted = deleted; if (i.imageryUsed) x.imageryUsed = i.imageryUsed; + if (i.photoOverlaysUsed) x.photoOverlaysUsed = i.photoOverlaysUsed; if (i.annotation) x.annotation = i.annotation; if (i.transform) x.transform = i.transform; if (i.selectedIDs) x.selectedIDs = i.selectedIDs; @@ -580,6 +599,7 @@ export function coreHistory(context) { graph: coreGraph(_stack[0].graph).load(entities), annotation: d.annotation, imageryUsed: d.imageryUsed, + photoOverlaysUsed: d.photoOverlaysUsed, transform: d.transform, selectedIDs: d.selectedIDs }; diff --git a/modules/renderer/background.js b/modules/renderer/background.js index fe66af5ee..d3b91d5f7 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -175,6 +175,7 @@ export function rendererBackground(context) { } var imageryUsed = []; + var photoOverlaysUsed = []; var current = b.imageryUsed(); if (current && _isValid) { @@ -190,26 +191,22 @@ export function rendererBackground(context) { imageryUsed.push(data.getSrc()); } - var streetside = context.layers().layer('streetside'); - if (streetside && streetside.enabled()) { - imageryUsed.push('Bing Streetside'); - } - - var mapillary_images = context.layers().layer('mapillary'); - if (mapillary_images && mapillary_images.enabled()) { - imageryUsed.push('Mapillary Images'); - } - - var mapillary_signs = context.layers().layer('mapillary-signs'); - if (mapillary_signs && mapillary_signs.enabled()) { - imageryUsed.push('Mapillary Signs'); - } - - var openstreetcam_images = context.layers().layer('openstreetcam'); - if (openstreetcam_images && openstreetcam_images.enabled()) { - imageryUsed.push('OpenStreetCam Images'); + var photoOverlayLayers = { + streetside: 'Bing Streetside', + mapillary: 'Mapillary Images', + 'mapillary-signs': 'Mapillary Signs', + openstreetcam: 'OpenStreetCam Images' + }; + + for (var layerID in photoOverlayLayers) { + var layer = context.layers().layer(layerID); + if (layer && layer.enabled()) { + photoOverlaysUsed.push(layerID); + imageryUsed.push(photoOverlayLayers[layerID]); + } } + context.history().photoOverlaysUsed(photoOverlaysUsed); context.history().imageryUsed(imageryUsed); }; diff --git a/modules/ui/commit.js b/modules/ui/commit.js index c7817283a..6880a5258 100644 --- a/modules/ui/commit.js +++ b/modules/ui/commit.js @@ -86,6 +86,23 @@ export function uiCommit(context) { if (source) { tags.source = source; } + var existingSources = (tags.source || '').split(';'); + // add the photo overlays used during editing as sources + var photoOverlaysUsed = context.history().photoOverlaysUsed(); + if (photoOverlaysUsed.length) { + // include this tag for any photo layer + if (existingSources.indexOf('streetlevel imagery') === -1) { + existingSources.push('streetlevel imagery'); + } + } + photoOverlaysUsed.forEach(function(photoOverlay) { + if (existingSources.indexOf(photoOverlay) === -1) { + existingSources.push(photoOverlay); + } + }); + if (existingSources.length) { + tags.source = existingSources.join(';').substr(0, 255); + } _changeset = new osmChangeset({ tags: tags }); }