summaryrefslogtreecommitdiffstats
path: root/src/assets/javascripts/helpers/google-maps.js
diff options
context:
space:
mode:
authorSimonBrazell <simon@brazell.com.au>2021-01-11 12:39:26 +1100
committerSimonBrazell <simon@brazell.com.au>2021-01-11 12:39:26 +1100
commitf56fc681886450e68fe3597fbcba870436c05ba4 (patch)
treed253aa87ab30e8f1d02e4f71d273a2d0d418cad9 /src/assets/javascripts/helpers/google-maps.js
parent20a2713a5688de89b15e9bddc578f998ee28b447 (diff)
downloadprivacy-redirect-f56fc681886450e68fe3597fbcba870436c05ba4.tar.gz
privacy-redirect-f56fc681886450e68fe3597fbcba870436c05ba4.tar.bz2
privacy-redirect-f56fc681886450e68fe3597fbcba870436c05ba4.zip
Fix for https://github.com/mozilla/addons-linter/issues/3541#issue-782801439
Diffstat (limited to 'src/assets/javascripts/helpers/google-maps.js')
-rw-r--r--src/assets/javascripts/helpers/google-maps.js89
1 files changed, 49 insertions, 40 deletions
diff --git a/src/assets/javascripts/helpers/google-maps.js b/src/assets/javascripts/helpers/google-maps.js
index 3a041c6..2ba924b 100644
--- a/src/assets/javascripts/helpers/google-maps.js
+++ b/src/assets/javascripts/helpers/google-maps.js
@@ -1,43 +1,52 @@
-export default class {
- static targets = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/;
- static redirects = ["https://openstreetmap.org"];
- static mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
- static dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g;
- static placeRegex = /\/place\/(.*)\//;
- static travelModes = {
- driving: "fossgis_osrm_car",
- walking: "fossgis_osrm_foot",
- bicycling: "fossgis_osrm_bike",
- transit: "fossgis_osrm_car", // not implemented on OSM, default to car.
- };
- static layers = {
- none: "S",
- transit: "T",
- traffic: "S", // not implemented on OSM, default to standard.
- bicycling: "C",
- };
- static addressToLatLng(address, callback) {
- const xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = () => {
- if (xmlhttp.readyState === XMLHttpRequest.DONE) {
- if (xmlhttp.status === 200) {
- const json = JSON.parse(xmlhttp.responseText)[0];
- if (json) {
- callback(
- `${json.lat}%2C${json.lon}`,
- `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`
- );
- }
- } else {
- console.info("Error: Status is " + xmlhttp.status);
+const targets = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/;
+const redirects = ["https://openstreetmap.org"];
+const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
+const dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g;
+const placeRegex = /\/place\/(.*)\//;
+const travelModes = {
+ driving: "fossgis_osrm_car",
+ walking: "fossgis_osrm_foot",
+ bicycling: "fossgis_osrm_bike",
+ transit: "fossgis_osrm_car", // not implemented on OSM, default to car.
+};
+const layers = {
+ none: "S",
+ transit: "T",
+ traffic: "S", // not implemented on OSM, default to standard.
+ bicycling: "C",
+};
+function addressToLatLng(address, callback) {
+ const xmlhttp = new XMLHttpRequest();
+ xmlhttp.onreadystatechange = () => {
+ if (xmlhttp.readyState === XMLHttpRequest.DONE) {
+ if (xmlhttp.status === 200) {
+ const json = JSON.parse(xmlhttp.responseText)[0];
+ if (json) {
+ callback(
+ `${json.lat}%2C${json.lon}`,
+ `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`
+ );
}
+ } else {
+ console.info("Error: Status is " + xmlhttp.status);
}
- };
- xmlhttp.open(
- "GET",
- `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`,
- false
- );
- xmlhttp.send();
- }
+ }
+ };
+ xmlhttp.open(
+ "GET",
+ `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`,
+ false
+ );
+ xmlhttp.send();
}
+
+export default {
+ targets,
+ redirects,
+ mapCentreRegex,
+ dataLatLngRegex,
+ placeRegex,
+ travelModes,
+ layers,
+ addressToLatLng,
+};