mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
Move conversion of co-ordinates to run() instead of present()
This commit is contained in:
parent
237f792fb4
commit
b491b9d77d
1 changed files with 17 additions and 13 deletions
|
@ -59,7 +59,19 @@ class ShowOnMap extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
// Pass the input through, don't need to do anything to it here
|
if (input.replace(/\s+/g, "") !== "") {
|
||||||
|
const inFormat = args[1],
|
||||||
|
inDelim = args[2];
|
||||||
|
let latLong;
|
||||||
|
try {
|
||||||
|
latLong = convertCoordinates(input, inFormat, inDelim, "Decimal Degrees", "Comma", "None", 5);
|
||||||
|
} catch (error) {
|
||||||
|
throw new OperationError(error);
|
||||||
|
}
|
||||||
|
latLong = latLong.replace(/[,]$/, "");
|
||||||
|
latLong = latLong.replace(/°/g, "");
|
||||||
|
return latLong;
|
||||||
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,15 +82,7 @@ class ShowOnMap extends Operation {
|
||||||
*/
|
*/
|
||||||
async present(data, args) {
|
async present(data, args) {
|
||||||
if (data.replace(/\s+/g, "") !== "") {
|
if (data.replace(/\s+/g, "") !== "") {
|
||||||
const [zoomLevel, inFormat, inDelim] = args;
|
const zoomLevel = args[0];
|
||||||
let latLong;
|
|
||||||
try {
|
|
||||||
latLong = convertCoordinates(data, inFormat, inDelim, "Decimal Degrees", "Comma", "None", 5);
|
|
||||||
} catch (error) {
|
|
||||||
throw new OperationError(error);
|
|
||||||
}
|
|
||||||
latLong = latLong.replace(/[,]$/, "");
|
|
||||||
latLong = latLong.replace(/°/g, "");
|
|
||||||
const tileUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
const tileUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||||
tileAttribution = "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
|
tileAttribution = "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
|
||||||
leafletUrl = "https://unpkg.com/leaflet@1.4.0/dist/leaflet.js",
|
leafletUrl = "https://unpkg.com/leaflet@1.4.0/dist/leaflet.js",
|
||||||
|
@ -90,13 +94,13 @@ class ShowOnMap extends Operation {
|
||||||
var mapscript = document.createElement('script');
|
var mapscript = document.createElement('script');
|
||||||
document.body.appendChild(mapscript);
|
document.body.appendChild(mapscript);
|
||||||
mapscript.onload = function() {
|
mapscript.onload = function() {
|
||||||
var presentMap = L.map('presentedMap').setView([${latLong}], ${zoomLevel});
|
var presentMap = L.map('presentedMap').setView([${data}], ${zoomLevel});
|
||||||
L.tileLayer('${tileUrl}', {
|
L.tileLayer('${tileUrl}', {
|
||||||
attribution: '${tileAttribution}'
|
attribution: '${tileAttribution}'
|
||||||
}).addTo(presentMap);
|
}).addTo(presentMap);
|
||||||
|
|
||||||
L.marker([${latLong}]).addTo(presentMap)
|
L.marker([${data}]).addTo(presentMap)
|
||||||
.bindPopup('${latLong}')
|
.bindPopup('${data}')
|
||||||
.openPopup();
|
.openPopup();
|
||||||
};
|
};
|
||||||
mapscript.src = "${leafletUrl}";
|
mapscript.src = "${leafletUrl}";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue