-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change maps source to use Wikimedia maps.
Add link to Wikimedia maps ToS. If there's no data, show the map anyway.
- Loading branch information
Showing
1 changed file
with
22 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.<br><br>Co-ordinates will be converted to decimal degrees before being shown on the map.<br><br>Supported formats:<ul><li>Degrees Minutes Seconds (DMS)</li><li>Degrees Decimal Minutes (DDM)</li><li>Decimal Degrees (DD)</li><li>Geohash</li><li>Military Grid Reference System (MGRS)</li><li>Ordnance Survey National Grid (OSNG)</li><li>Universal Transverse Mercator (UTM)</li></ul><br>This operation will not work offline."; | ||
this.description = "Displays co-ordinates on a slippy map.<br><br>Co-ordinates will be converted to decimal degrees before being shown on the map.<br><br>Supported formats:<ul><li>Degrees Minutes Seconds (DMS)</li><li>Degrees Decimal Minutes (DDM)</li><li>Decimal Degrees (DD)</li><li>Geohash</li><li>Military Grid Reference System (MGRS)</li><li>Ordnance Survey National Grid (OSNG)</li><li>Universal Transverse Mercator (UTM)</li></ul><br>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 = "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors", | ||
leafletUrl = "https://unpkg.com/[email protected]/dist/leaflet.js", | ||
leafletCssUrl = "https://unpkg.com/[email protected]/dist/leaflet.css"; | ||
return `<link rel="stylesheet" href="${leafletCssUrl}" crossorigin=""/> | ||
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 = "<a href=\"https://wikimediafoundation.org/wiki/Maps_Terms_of_Use\">Wikimedia maps</a> | © <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors", | ||
leafletUrl = "https://unpkg.com/[email protected]/dist/leaflet.js", | ||
leafletCssUrl = "https://unpkg.com/[email protected]/dist/leaflet.css"; | ||
return `<link rel="stylesheet" href="${leafletCssUrl}" crossorigin=""/> | ||
<style>#output-html { white-space: normal; }</style> | ||
<div id="presentedMap" style="width: 100%; height: 100%;"></div> | ||
<script type="text/javascript"> | ||
var mapscript = document.createElement('script'); | ||
document.body.appendChild(mapscript); | ||
mapscript.onload = function() { | ||
var presentMap = L.map('presentedMap').setView([${data}], ${zoomLevel}); | ||
L.tileLayer('${tileUrl}', { | ||
attribution: '${tileAttribution}' | ||
}).addTo(presentMap); | ||
var mapscript = document.createElement('script'); | ||
document.body.appendChild(mapscript); | ||
mapscript.onload = function() { | ||
var presentMap = L.map('presentedMap').setView([${data}], ${zoomLevel}); | ||
L.tileLayer('${tileUrl}', { | ||
attribution: '${tileAttribution}' | ||
}).addTo(presentMap); | ||
L.marker([${data}]).addTo(presentMap) | ||
.bindPopup('${data}') | ||
.openPopup(); | ||
}; | ||
mapscript.src = "${leafletUrl}"; | ||
L.marker([${data}]).addTo(presentMap) | ||
.bindPopup('${data}') | ||
.openPopup(); | ||
}; | ||
mapscript.src = "${leafletUrl}"; | ||
</script>`; | ||
} else { | ||
// Don't do anything if there's no input | ||
return ""; | ||
} | ||
} | ||
} | ||
|
||
|