Skip to content

Instantly share code, notes, and snippets.

@liskin
Created June 4, 2022 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liskin/86b6ab31a45fed2e276504760d0b62f7 to your computer and use it in GitHub Desktop.
Save liskin/86b6ab31a45fed2e276504760d0b62f7 to your computer and use it in GitHub Desktop.
From e12a2de6ca017a33cb5a4f8973da71f9c8fab148 Mon Sep 17 00:00:00 2001
From: Tomas Janousek <tomi@nomi.cz>
Date: Sat, 4 Jun 2022 13:14:33 +0100
Subject: [PATCH] Add support for Locus Map Web
---
manifest.json | 1 +
statshuntersRouteOverlay.js | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/manifest.json b/manifest.json
index 36c3a39..69f50dc 100644
--- a/manifest.json
+++ b/manifest.json
@@ -35,6 +35,7 @@
"https://connect.garmin.com/modern/course/*",
"https://cycle.travel/map",
"https://*.mapy.cz/*",
+ "https://web.locusmap.app/*",
"https://dashboard.hammerhead.io/*"
]
}
diff --git a/statshuntersRouteOverlay.js b/statshuntersRouteOverlay.js
index d8b6c35..4bab8f6 100644
--- a/statshuntersRouteOverlay.js
+++ b/statshuntersRouteOverlay.js
@@ -110,6 +110,7 @@ var addRouteEventListeners = function() {
window.routeMap.on('layeradd', getNewTiles);
break;
case 'garmin':
+ case 'locusmap':
window.routeMap.on('moveend', drawGrid);
window.routeMap.on('layeradd', getNewTiles);
window.routeMap.on('layerremove', getNewTiles);
@@ -186,6 +187,8 @@ var getRouteType = function() {
return 'cycle';
} else if (window.location.host == "dashboard.hammerhead.io") {
return 'hammerhead'
+ } else if (window.location.host == "web.locusmap.app") {
+ return 'locusmap'
} else {
return 'strava';
}
@@ -289,6 +292,23 @@ var getMapForType = function() {
throw 'route map is null try again'
}
break;
+ case 'locusmap':
+ const origFireDOMEvent = L.Map.prototype._fireDOMEvent;
+ L.Map.prototype._fireDOMEvent = function (e, type) {
+ if (type == 'getRouteMap') {
+ window.routeMap = this;
+ } else {
+ origFireDOMEvent.call(this, ...arguments);
+ }
+ }
+
+ for (const [ev, _handleDOMEvent] of Object.entries(document.getElementById('leaflet-map')._leaflet_events)) {
+ if (ev.startsWith('click')) {
+ _handleDOMEvent(new Event('getRouteMap'));
+ break;
+ }
+ }
+ break;
}
}
@@ -494,6 +514,7 @@ var addLayerToMap = function(data, type) {
case 'cycle':
case 'brouter':
case 'garmin':
+ case 'locusmap':
return addLayerToMapLeaflet(data, type)
case 'ridewithgps':
return addLayerToMapGmap(data, type)
@@ -611,6 +632,7 @@ var removeLayerFromMap = function(type) {
case 'cycle':
case 'brouter':
case 'garmin':
+ case 'locusmap':
removeLayerFromLeaflet(type);
break;
case 'ridewithgps':
@@ -932,6 +954,7 @@ var getNewTiles = function() {
switch(window.routeType) {
case 'brouter':
case 'cycle':
+ case 'locusmap':
tiles = getNewTilesForLeaflet();
break;
case 'mapy':
--
2.36.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment