From 237f792fb4b1d7c414586665375df9f7d6fccf6f Mon Sep 17 00:00:00 2001 From: j433866 Date: Fri, 18 Jan 2019 11:19:06 +0000 Subject: [PATCH 1/3] Add new Show on map operation --- src/core/operations/ShowOnMap.mjs | 111 ++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/core/operations/ShowOnMap.mjs diff --git a/src/core/operations/ShowOnMap.mjs b/src/core/operations/ShowOnMap.mjs new file mode 100644 index 00000000..a30d59f5 --- /dev/null +++ b/src/core/operations/ShowOnMap.mjs @@ -0,0 +1,111 @@ +/** + * @author j433866 [j433866@gmail.com] + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import {FORMATS, convertCoordinates} from "../lib/ConvertCoordinates"; +import OperationError from "../errors/OperationError"; + +/** + * Show on map operation + */ +class ShowOnMap extends Operation { + + /** + * ShowOnMap constructor + */ + constructor() { + super(); + + this.name = "Show on map"; + this.module = "Hashing"; + this.description = "Displays co-ordinates on an OpenStreetMap slippy map.

Co-ordinates will be converted to decimal degrees before being shown on the map.

Supported formats:
This operation will not work offline."; + this.infoURL = ""; + this.inputType = "string"; + this.outputType = "string"; + this.presentType = "html"; + this.args = [ + { + name: "Zoom Level", + type: "number", + value: 13 + }, + { + name: "Input Format", + type: "option", + value: ["Auto"].concat(FORMATS) + }, + { + name: "Input Delimiter", + type: "option", + value: [ + "Auto", + "Direction Preceding", + "Direction Following", + "\\n", + "Comma", + "Semi-colon", + "Colon" + ] + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + // Pass the input through, don't need to do anything to it here + return input; + } + + /** + * @param {string} data + * @param {Object[]} args + * @returns {string} + */ + async present(data, args) { + if (data.replace(/\s+/g, "") !== "") { + const [zoomLevel, inFormat, inDelim] = args; + 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", + tileAttribution = "© OpenStreetMap contributors", + leafletUrl = "https://unpkg.com/leaflet@1.4.0/dist/leaflet.js", + leafletCssUrl = "https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"; + return ` + +
+`; + } else { + // Don't do anything if there's no input + return ""; + } + } +} + +export default ShowOnMap; From b491b9d77d98658375959dd328f7bd62023c3a4c Mon Sep 17 00:00:00 2001 From: j433866 Date: Fri, 18 Jan 2019 11:31:53 +0000 Subject: [PATCH 2/3] Move conversion of co-ordinates to run() instead of present() --- src/core/operations/ShowOnMap.mjs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/core/operations/ShowOnMap.mjs b/src/core/operations/ShowOnMap.mjs index a30d59f5..fe0e2484 100644 --- a/src/core/operations/ShowOnMap.mjs +++ b/src/core/operations/ShowOnMap.mjs @@ -59,7 +59,19 @@ class ShowOnMap extends Operation { * @returns {string} */ 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; } @@ -70,15 +82,7 @@ class ShowOnMap extends Operation { */ async present(data, args) { if (data.replace(/\s+/g, "") !== "") { - const [zoomLevel, inFormat, inDelim] = args; - 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 zoomLevel = args[0]; const tileUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", tileAttribution = "© OpenStreetMap contributors", leafletUrl = "https://unpkg.com/leaflet@1.4.0/dist/leaflet.js", @@ -90,13 +94,13 @@ class ShowOnMap extends Operation { var mapscript = document.createElement('script'); document.body.appendChild(mapscript); mapscript.onload = function() { - var presentMap = L.map('presentedMap').setView([${latLong}], ${zoomLevel}); + var presentMap = L.map('presentedMap').setView([${data}], ${zoomLevel}); L.tileLayer('${tileUrl}', { attribution: '${tileAttribution}' }).addTo(presentMap); - L.marker([${latLong}]).addTo(presentMap) - .bindPopup('${latLong}') + L.marker([${data}]).addTo(presentMap) + .bindPopup('${data}') .openPopup(); }; mapscript.src = "${leafletUrl}"; From 2628f17faecc628f28781b89186d05953110e925 Mon Sep 17 00:00:00 2001 From: j433866 Date: Thu, 29 Aug 2019 11:43:45 +0100 Subject: [PATCH 3/3] Change maps source to use Wikimedia maps. Add link to Wikimedia maps ToS. If there's no data, show the map anyway. --- src/core/operations/ShowOnMap.mjs | 46 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/core/operations/ShowOnMap.mjs b/src/core/operations/ShowOnMap.mjs index fe0e2484..4a362fec 100644 --- a/src/core/operations/ShowOnMap.mjs +++ b/src/core/operations/ShowOnMap.mjs @@ -21,7 +21,7 @@ class ShowOnMap extends Operation { this.name = "Show on map"; this.module = "Hashing"; - this.description = "Displays co-ordinates on an OpenStreetMap slippy map.

Co-ordinates will be converted to decimal degrees before being shown on the map.

Supported formats:
  • Degrees Minutes Seconds (DMS)
  • Degrees Decimal Minutes (DDM)
  • Decimal Degrees (DD)
  • Geohash
  • Military Grid Reference System (MGRS)
  • Ordnance Survey National Grid (OSNG)
  • Universal Transverse Mercator (UTM)

This operation will not work offline."; + this.description = "Displays co-ordinates on a slippy map.

Co-ordinates will be converted to decimal degrees before being shown on the map.

Supported formats:
  • Degrees Minutes Seconds (DMS)
  • Degrees Decimal Minutes (DDM)
  • Decimal Degrees (DD)
  • Geohash
  • Military Grid Reference System (MGRS)
  • Ordnance Survey National Grid (OSNG)
  • Universal Transverse Mercator (UTM)

This operation will not work offline."; this.infoURL = ""; this.inputType = "string"; this.outputType = "string"; @@ -81,34 +81,32 @@ class ShowOnMap extends Operation { * @returns {string} */ async present(data, args) { - if (data.replace(/\s+/g, "") !== "") { - const zoomLevel = args[0]; - const tileUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", - tileAttribution = "© OpenStreetMap contributors", - leafletUrl = "https://unpkg.com/leaflet@1.4.0/dist/leaflet.js", - leafletCssUrl = "https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"; - return ` + if (data.replace(/\s+/g, "") === "") { + data = "0, 0"; + } + const zoomLevel = args[0]; + const tileUrl = "https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png", + tileAttribution = "Wikimedia maps | © OpenStreetMap contributors", + leafletUrl = "https://unpkg.com/leaflet@1.5.0/dist/leaflet.js", + leafletCssUrl = "https://unpkg.com/leaflet@1.5.0/dist/leaflet.css"; + return `
`; - } else { - // Don't do anything if there's no input - return ""; - } } }