Skip to content
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

[Bug] Fix custom map style input #2564

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

akre54
Copy link
Collaborator

@akre54 akre54 commented Apr 19, 2024

Fix for #2560 and #2458: custom map style urls aren't being loaded.

Quoting from #2560:

Looks like the issue (or one issue) is that the confirmButton in the AddMapStyle modal is always disabled. It's checking for mapStyle.inputStyle.style which is always null since the input onChange listener only sets a url and not a style property. Also addCustomMapStyleUpdater is checking for state.inputStyle.id which is also null. Setting any id from the onChange handler seems to fix the issue.

The icon is also broken. The getStyleImageIcon called from inputMapStyleUpdater is returning a Mapbox url even for non-mapbox basemaps. For instance, inputting the example url "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json" gives me "https://api.mapbox.com/styles/v1/https://basemaps.cartocdn.com/gl/positron-gl-style/style.json/static/-122.3391,37.7922,9,0,0/400x300?access_token={snip}&logo=false&attribution=false". I'm not sure what the best fix for that would be.

Copy link

netlify bot commented Apr 19, 2024

Deploy Preview for keplergl2 failed.

Name Link
🔨 Latest commit ff892b3
🔍 Latest deploy log https://app.netlify.com/sites/keplergl2/deploys/663303ff5a5e8a00087f1ce5

@akre54 akre54 changed the title Fix custom map style input [Bug] Fix custom map style input Apr 19, 2024
@@ -30,6 +30,7 @@
"umd"
],
"dependencies": {
"@auth0/auth0-spa-js": "^2.1.2",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to separate this PR from the dependency fix so we can discuss them each on their merits?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I had to branch off of the other one to get the fix

Signed-off-by: Adam Krebs <amk528@cs.nyu.edu>
@ibgreen
Copy link
Collaborator

ibgreen commented Apr 19, 2024

The icon is also broken. The getStyleImageIcon called from inputMapStyleUpdater is returning a Mapbox url even for non-mapbox basemaps. For instance, inputting the example url "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json" gives me "https://api.mapbox.com/styles/v1/https://basemaps.cartocdn.com/gl/positron-gl-style/style.json/static/-122.3391,37.7922,9,0,0/400x300?access_token={snip}&logo=false&attribution=false". I'm not sure what the best fix for that would be.

Looking at your URL it seems the style is expected to be a name not a URL (see the double https in https://api.mapbox.com/styles/v1/https://basemaps.cartocdn.com/gl/positron-gl).

So while this PR may unbreak some thing, it is probably not a complete solution.

@ilyabo @macrigiuseppe Any thoughts?

@akre54
Copy link
Collaborator Author

akre54 commented Apr 19, 2024

I can confirm that the main issue is still broken with just a mapbox url scheme:

Screen.Recording.2024-04-19.at.2.17.18.PM.mov

@akre54
Copy link
Collaborator Author

akre54 commented Apr 19, 2024

With this fix, the mapbox:// url scheme still doesn't work. Looks like the only two places that check for a mapbox url scheme are isStyleUsingMapboxTiles (called to determine attribution in map-container.tsx) and getStyleDownloadUrl (called from getLoadMapStyleTasks)

Mapbox.url.scheme.bug.mov

@ilyabo
Copy link
Collaborator

ilyabo commented Apr 24, 2024

Maplibre dropped the support for mapbox:// style URLs. To work around this we would probably have to load the basemap library dynamically. Maybe we can add a switch in this dialog to choose from Maplibre and Mapbox. Or revert to Mapbox. @ibgreen what do you think?

@ibgreen
Copy link
Collaborator

ibgreen commented Apr 24, 2024

I don't think that reverting to mapbox is what we want to do. Supporting both would be an option, though that is a feature that someone needs to implement.

One option is to remove the map style support and the dialog.

How important is this feature? Are we breaking a important workflows here?

@akre54
Copy link
Collaborator Author

akre54 commented Apr 24, 2024

Would it be possible to simply rewrite the urls? Either in Kepler or in Maplibre? This feels like a pretty useful feature

Or at the very least include a warning message if you try to use a mapbox:// url scheme? This feels unexpected

@ilyabo
Copy link
Collaborator

ilyabo commented Apr 24, 2024

I suspect that newer mapbox styles would not work correctly with maplibre. I have experienced issues when trying to use newer styles with mapbox@1.

@akre54
Copy link
Collaborator Author

akre54 commented Apr 29, 2024

I can look into the icon import. It feels odd that the importer would assume that all urls come from mapbox, but it's not clear to me that Carto, for instance, returns a unique icon for all of its styles, or that every other style provider is required to return one as well. It seems to me like this would be better if it just used a generic icon, or black square.

I do think it's fine for mapbox:// urls to be broken so long as basic style.jsons still work. What do you think?

@chrisgervang
Copy link
Collaborator

It doesn't really make sense to continue supporting Mapbox styles (or their URLs) unless the actual Mapbox library is added as an alternative option, right?

@akre54
Copy link
Collaborator Author

akre54 commented Apr 29, 2024

Maybe not the url protocol but it's the most commonly used map style format. What's the alternative?

And how have they diverged? The functionality to load mapbox V1 styles works after a bugfix. I don't feel like having a preview icon is enough reason to break this workflow. What do you think?

@ibgreen
Copy link
Collaborator

ibgreen commented Apr 29, 2024

Apologies that this is taking time, the basemap support in kepler clearly lacks a decisive owner right now. Together we all have parts of the answer, but the risk is that this thread could go on for a long time unless we decide on something. Following up in the issue.

@akre54
Copy link
Collaborator Author

akre54 commented Apr 29, 2024

Yeah totally agree. I don't want to bike shed this any more than necessary. I agree there needs to be a better default for the icon. If I come up a patch to make this black or a basic color or something would that be acceptable?

@ibgreen
Copy link
Collaborator

ibgreen commented Apr 29, 2024

come up a patch to make this black or a basic color or something would that be acceptable?

Yes let's land something reasonable.

@birkskyum
Copy link
Collaborator

birkskyum commented May 1, 2024

It doesn't really make sense to continue supporting Mapbox styles (or their URLs) unless the actual Mapbox library is added as an alternative option, right?

I think this is right. The reason mapbox:// was removed from maplibre was not only a matter of compatibility, but also a license compliance concern. This change in the mapbox style spec license saying:

The software and files in this repository (collectively, "Software") are
licensed under the Mapbox TOS for use only with the relevant Mapbox product(s)
listed at www.mapbox.com/pricing.

Looking at the www.mapbox.com/pricing etc. it seemed risky to interpret that in any other way than "mapbox styles coming from the mapbox api will be under latest version of this license, and are thus only allowed to be rendered with a mapbox renderer".

@akre54
Copy link
Collaborator Author

akre54 commented May 1, 2024

I added a temporary fix using the NO_BASEMAP_ICON for custom map styles and removing the logic for isValidStyleUrl which checked for mapbox styles. I'm sure this can be changed in the future but for now this fixes the major issues.

url: isValidStyleUrl(url)
? getStyleDownloadUrl(url, accessToken || mapboxApiAccessToken, mapboxApiUrl)
: url
url: getStyleDownloadUrl(url, accessToken || mapboxApiAccessToken, mapboxApiUrl)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ternary wasn't necessary because getStyleDownloadUrl already guards for urls.

@birkskyum
Copy link
Collaborator

seems like ci is failing on the "should set the inputStyle" test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants