-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more sources for markers #45
Add more sources for markers #45
Conversation
src/_js/map.js
Outdated
const urlParams = new URLSearchParams(window.location.search); | ||
// Possible markers sources | ||
// A) https://example.com?m=<base64-json-str>#32368,32198,7:0 | ||
// B) https://example.com?mf=https://example.com/pack.json#32368,32198,7:0 | ||
// C) <div id="map" data-marker-json="<json-str>" ...> | ||
// D) <div id="map" data-marker-pack="https://example.com/pack.json" ...> | ||
// E) fallback: https://tibiamaps.github.io/tibia-map-data/markers.json | ||
if (urlParams.get('m')) { | ||
buildMarkerLayers(atob(JSON.parse(urlParams.get('m')))); | ||
} else if (urlParams.get('mf')) { | ||
loadMarkersPack(urlParams.get('mf')); | ||
} else if (mapContainer.dataset.markerJson) { | ||
buildMarkerLayers(JSON.parse(mapContainer.dataset.markerJson)); | ||
} else if (mapContainer.dataset.markerPack) { | ||
loadMarkersPack(URL_PREFIX + mapContainer.dataset.markerPack); | ||
} else { | ||
loadMarkersPack(URL_PREFIX + 'markers.json'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to extract this logic to a separate function (called getMarkerPackUrl
or some such) that returns a URL to load, so we could have early return
s instead of all the else if
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this could be much cleaner given the hierarchy I proposed (A behavior overrides B, B overrides C, etc.), but I gave it a try on my latest changes. Lemme know if it looks better. We can also consider other hierarchy or removing some of the sources.
The marker data is now user-controlled (either by loading a third-party URL or embedding the data in the URL itself), so we have to be careful not to introduce XSS. |
9fa13fb
to
5ca9c0d
Compare
Do you have any suggestions in mind? Given that user input in being sent to |
It's not |
Addresses #43 with a few more ways to override sources for markers