Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Import and export layers configuration #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
</head>
<body>
<input id="input-file" type="file" accept=".gpx" multiple style="display: none"/>
<input id="input-configuration-file" type="file" accept=".json" multiple style="display: none"/>
<div id="mapid"></div>
<div id="mly"><div id="mly-controls"><i id="mly-move" class="fas fa-arrows-alt custom-button"></i><i id="mly-close" class="fas fa-times custom-button"></i></div></div>
<div style="display: none">
Expand Down Expand Up @@ -462,6 +463,10 @@
<div id="layer-selection-area"></div>
<div id="layer-selection-ok" class="panels custom-button normal-button">Save</div>
</div>
<div id="importexport-configuration">
<div id="import-configuration-ok" class="panels custom-button normal-button">Import</div>
<div id="export-configuration-ok" class="panels custom-button normal-button">Export</div>
</div>
</div>
<div id="load-error-content" class="popup-content">
There was an error loading your GPX file.<br>
Expand Down
57 changes: 55 additions & 2 deletions js/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default class Buttons {

// BUTTONS
this.input = document.getElementById("input-file");
this.input_configuration = document.getElementById("input-configuration-file");
this.load = document.getElementById("load");
this.load2 = document.getElementById("load2");
this.load_drive = document.getElementById("load-drive");
Expand Down Expand Up @@ -108,6 +109,8 @@ export default class Buttons {
this.crop_cancel = document.getElementById("crop-cancel");
this.crop_keep = document.getElementById("crop-keep");
this.layer_selection_ok = document.getElementById("layer-selection-ok");
this.import_configuration_ok = document.getElementById("import-configuration-ok");
this.export_configuration_ok = document.getElementById("export-configuration-ok");
this.export = document.getElementById("export");
this.export2 = document.getElementById("export-2");
this.save_drive = document.getElementById("save-drive");
Expand Down Expand Up @@ -433,7 +436,7 @@ export default class Buttons {
else if (mapSource == 'satellite' && urlParams.has('token') && _this.supportsWebGL()) {
_this.mapboxMap.addTo(_this.map);
_this.mapboxMap.options.style = "mapbox://styles/mapbox/satellite-v9";
_this.mapboxMap.getMapboxMap().setStyle("mapbox://styles/mapbox/satellite-v9", {diff: false});
_this.mapboxMap.getMapboxMap().setStyle("mapbox://styles/mapbox/satellite-v9", { diff: false });
} else layers.openStreetMap.addTo(_this.map);
} else if (urlParams.has('token') && _this.supportsWebGL()) _this.mapboxMap.addTo(_this.map);
else layers.openStreetMap.addTo(_this.map);
Expand Down Expand Up @@ -912,6 +915,9 @@ export default class Buttons {
this.input.oninput = function() {
buttons.loadFiles(this.files)
};
this.input_configuration.oninput = function () {
buttons.loadConfigurationFiles(this.files)
};
this.load.addEventListener("click", function () {
if (buttons.window_open) buttons.window_open.hide();
buttons.window_open = buttons.load_window;
Expand Down Expand Up @@ -1709,6 +1715,28 @@ export default class Buttons {

buttons.controlLayers._layer_selection_button.click();
});
this.import_configuration_ok.addEventListener('click', function () {
buttons.input_configuration.click();
});
this.export_configuration_ok.addEventListener('click', function () {

const toExport = {
'custom-layers': localStorage.getItem('custom-layers'),
'baselayer-selection': localStorage.getItem('baselayer-selection'),
'overlay-selection': localStorage.getItem('overlay-selection'),
'lastbasemap': localStorage.getItem('lastbasemap'),
'beforelastbasemap': localStorage.getItem('beforelastbasemap'),
'lastoverlays': localStorage.getItem('lastoverlays')
}

var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(toExport));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", "gpxstudio-configuration.json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
});
this.about.addEventListener("click", function () {
window.open('./about.html');
});
Expand Down Expand Up @@ -2094,7 +2122,32 @@ export default class Buttons {
reader.readAsDataURL(file);
}
this.input.value = "";
gtag('event', 'button', {'event_category' : 'load'});
gtag('event', 'button', { 'event_category': 'load' });
}

loadConfigurationFiles(files) {
if (files.length > 0) {
const file = files[0];
if (file.name.split('.').pop().toLowerCase() != 'json') return;
var reader = new FileReader();
reader.onload = (function (f, name) {
return function (e) {
const configuration = JSON.parse(e.target.result);

localStorage.setItem('custom-layers', configuration['custom-layers']);
localStorage.setItem('baselayer-selection', configuration['baselayer-selection']);
localStorage.setItem('overlay-selection', configuration['overlay-selection']);
localStorage.setItem('lastbasemap', configuration['lastbasemap']);
localStorage.setItem('beforelastbasemap', configuration['beforelastbasemap']);
localStorage.setItem('lastoverlays', configuration['lastoverlays']);

window.location.reload();

};
})(file, file.name);
reader.readAsText(file);
this.input_configuration.value = "";
}
}

openURLs() {
Expand Down
4 changes: 4 additions & 0 deletions res/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ html, body {
padding-left: 10px;
}

#importexport-configuration {
display: inline-block;
}

.close-spacing {
margin-right: 16px;
}
Expand Down