Navigation Menu

Skip to content

Commit

Permalink
Remember last custom tile layer (fixes #2094)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 7, 2014
1 parent fd0aba1 commit 1fee019
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
6 changes: 3 additions & 3 deletions css/app.css
Expand Up @@ -2017,19 +2017,19 @@ img.wiki-image {
height:18px;
}

.background-control .layer-toggle-gpx button {
.background-control .layer-list button {
float: right;
height: 100%;
width: 10%;
border-left: 1px solid #CCC;
border-radius: 0;
}

.background-control .layer-toggle-gpx button .icon {
.background-control .layer-list button .icon {
opacity: 0.5;
}

.background-control .layer-toggle-gpx button.layer-extent {
.background-control .layer-list button:first-of-type {
border-radius: 0 3px 3px 0;
}

Expand Down
3 changes: 2 additions & 1 deletion data/core.yaml
Expand Up @@ -222,7 +222,8 @@ en:
percent_brightness: "{opacity}% brightness"
none: None
custom: Custom
custom_prompt: "Enter a tile template. Valid tokens are {z}, {x}, {y} for Z/X/Y scheme and {u} for quadtile scheme."
custom_button: Edit custom background
custom_prompt: "Enter a tile URL template. Valid tokens are {z}, {x}, {y} for Z/X/Y scheme and {u} for quadtile scheme."
fix_misalignment: Fix alignment
reset: reset
restore:
Expand Down
3 changes: 2 additions & 1 deletion dist/locales/en.json
Expand Up @@ -271,7 +271,8 @@
"percent_brightness": "{opacity}% brightness",
"none": "None",
"custom": "Custom",
"custom_prompt": "Enter a tile template. Valid tokens are {z}, {x}, {y} for Z/X/Y scheme and {u} for quadtile scheme.",
"custom_button": "Edit custom background",
"custom_prompt": "Enter a tile URL template. Valid tokens are {z}, {x}, {y} for Z/X/Y scheme and {u} for quadtile scheme.",
"fix_misalignment": "Fix alignment",
"reset": "reset"
},
Expand Down
40 changes: 33 additions & 7 deletions js/id/ui/background.js
Expand Up @@ -7,7 +7,8 @@ iD.ui.Background = function(context) {
['right', [-1, 0]],
['bottom', [0, 1]]],
opacityDefault = (context.storage('background-opacity') !== null) ?
(+context.storage('background-opacity')) : 0.5;
(+context.storage('background-opacity')) : 0.5,
customTemplate;

// Can be 0 from <1.3.0 use or due to issue #1923.
if (opacityDefault === 0) opacityDefault = 0.5;
Expand Down Expand Up @@ -47,15 +48,20 @@ iD.ui.Background = function(context) {
selectLayer();
}

function clickCustom() {
function editCustom() {
d3.event.preventDefault();
var template = window.prompt(t('background.custom_prompt'));
if (!template || template.indexOf('google.com') !== -1 ||
template.indexOf('googleapis.com') !== -1 ||
template.indexOf('google.ru') !== -1) {
var template = window.prompt(t('background.custom_prompt'), customTemplate);
if (!template ||
template.indexOf('google.com') !== -1 ||
template.indexOf('googleapis.com') !== -1 ||
template.indexOf('google.ru') !== -1) {
selectLayer();
return;
}
setCustom(template);
}

function setCustom(template) {
context.background().baseLayerSource(iD.BackgroundSource.Custom(template));
selectLayer();
}
Expand Down Expand Up @@ -119,6 +125,11 @@ iD.ui.Background = function(context) {
.property('checked', showsGpx);

selectLayer();

var source = context.background().baseLayerSource();
if (source.id === 'custom') {
customTemplate = source.template;
}
}

function clickNudge(d) {
Expand Down Expand Up @@ -225,12 +236,27 @@ iD.ui.Background = function(context) {
.attr('class', 'custom_layer')
.datum(iD.BackgroundSource.Custom());

custom.append('button')
.attr('class', 'layer-browse')
.call(bootstrap.tooltip()
.title(t('background.custom_button'))
.placement('left'))
.on('click', editCustom)
.append('span')
.attr('class', 'icon geocode');

var label = custom.append('label');

label.append('input')
.attr('type', 'radio')
.attr('name', 'layers')
.on('change', clickCustom);
.on('change', function () {
if (customTemplate) {
setCustom(customTemplate);
} else {
editCustom();
}
});

label.append('span')
.text(t('background.custom'));
Expand Down

0 comments on commit 1fee019

Please sign in to comment.