You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Relative URLs in sources don't work anymore (0.27.0) #3636
in my style definition, because I wanted it to work in all environments. Now with 0.27.0, the function parseUrl throws an error because the URL doesn't match the expected syntax (protocol missing):
I guess the protocol could be retrieved, if missing, with location.protocol ; but I'm not good enough with regexs to fix it myself... :) Here, if the regex doesn't match, it returns null.
I mean that each environment retrieves its own glyphs and fonts: local from local, staging from staging, prod from prod... So I didn't need to hard code each URLs for each environment.
then in the js code:
jQuery.get('/myfolder/tweakedstyle.json', function(theTweakedJson) {
var theStringifiedTweakedJson = JSON.stringify(theTweakedJson);
theStringifiedTweakedJson = theStringifiedTweakedJson.replace(/replacemewiththehostnameplease/g, window.location.hostname);
theTweakedJson = JSON.parse(theStringifiedTweakedJon);
...
then I feed it to the map constructor thingy:
map = new mapboxgl.Map({
container: 'map',
style: theTweakedJson,
@nicooprat pretty hacky for sure. I don't know about there being a performance issue. I don't see it being much worse than going to mapbox for the files. Also, I think this is only done when the page is loaded so once it's up and running it should be fine. But I'm no expert on js or mapbox.
It just seems silly because I can't preview my map before uploading the first time, since I'm pushing the whole thing to master anyway, therefore validating the hosted URL.
Activity
jfirebaugh commentedon Nov 16, 2016
It wasn't intended for
spriteandglyphsproperties to support relative URLs; if it worked in past versions, it was an accident.Can you say what specifically you mean by this?
nicooprat commentedon Nov 16, 2016
I mean that each environment retrieves its own glyphs and fonts: local from local, staging from staging, prod from prod... So I didn't need to hard code each URLs for each environment.
lucaswoj commentedon Nov 17, 2016
It is a reasonable expectation that relative URLs would work.
jfirebaugh commentedon Nov 17, 2016
I don't think it's something we should support.
Use cases where relative URLs are desired can be satisfied by preprocessing the style to produce the desired absolute URL.
lucaswoj commentedon Nov 17, 2016
Those are good points. 👍 Let's close this ticket and open another to consider adding this rule to the validator.
brianssheldon commentedon Feb 23, 2017
Since my production environment is not connected to the internet, this was keeping me from upgrading mapbox-gl.js...
My fix for this turned out to be the same one I used for the tiles.
from the json file in my project-
"sprite": "https://replacemewiththehostnameplease:4567/myfolder/style/bright/sprite",
then in the js code:
jQuery.get('/myfolder/tweakedstyle.json', function(theTweakedJson) {
var theStringifiedTweakedJson = JSON.stringify(theTweakedJson);
theStringifiedTweakedJson = theStringifiedTweakedJson.replace(/replacemewiththehostnameplease/g, window.location.hostname);
theTweakedJson = JSON.parse(theStringifiedTweakedJon);
...
then I feed it to the map constructor thingy:
....
seems to work like a champ.
nicooprat commentedon Mar 4, 2017
Thanks @brianssheldon I can confirm it works. A bit hacky, but, meh :) Could there be any performance issue with this way of loading the styles?
brianssheldon commentedon Mar 6, 2017
@nicooprat pretty hacky for sure. I don't know about there being a performance issue. I don't see it being much worse than going to mapbox for the files. Also, I think this is only done when the page is loaded so once it's up and running it should be fine. But I'm no expert on js or mapbox.
cbeddow commentedon Jun 20, 2018
I had to just push my project to master first, so instead of setting:
I have set:
It just seems silly because I can't preview my map before uploading the first time, since I'm pushing the whole thing to master anyway, therefore validating the hosted URL.
stevage commentedon Jul 12, 2019
For others running into this issue, a workaround like this may be helpful, if you're constructing your style file on the fly:
kkaefer commentedon Jan 24, 2020
For a cleaner solution than altering style JSON files, you can also use
transformRequestas outlined in the comment in #9225 (comment).