-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
.getStyle
is broken for Standard style
#13160
Comments
Adding a +1. This is a well-documented report. I agree that this new Standard Style introduces some breaking changes/inconsistencies. The workaround above was helpful and I'm good to go moving forward, but I expect this to cause more people some headaches. |
Hi everyone 👋 Thanks for reaching out and sorry for any confusion. I understand the frustration when things don't work as expected. With the new Mapbox Standard style, we're introducing a different approach to handling map styles. When you use this style in your application, we take care of updating the basemap with the latest features automatically, so your users always see the most up-to-date version without any extra effort from your side. For the Mapbox Standard style or any "fragment" style (those with I’ll update the related documentation to clarify this. We don't plan to add an API for accessing import internals directly. However, I'd love to understand more about your use case. @korywka, could you please share why you need to get the import's |
Hi. |
@stepankuzmin My use case is to be able to click on POIs on the map, and open details about them. This is impossible with the standard style at the moment because |
@stepankuzmin I have the same issue as @alexwohlbruck ... map.queryRenderedFeatures() now returns nothing, which means we can't detect clicks on POIs on the map. |
Exact same functionality I'm trying to achieve @alexwohlbruck and @TimBarham. Hoping for a fix. If I understand correctly, you can't really do anything with imported layers found in For example 👇
I was thinking I could hack a solution by taking the imported layer and doing a Still somewhat confused on "import layers", "composite sources" "sourceLayers" and "sources" through all of this... 😵 |
^this actually does work. you can add only the POI layer from the standard style after map loads, then it can be made clickable: map.addSource('composite', {
type: 'vector',
url: 'mapbox://mapbox.mapbox-bathymetry-v2,mapbox.mapbox-streets-v8,mapbox.mapbox-terrain-v2,mapbox.mapbox-models-v1',
})
map.addLayer({
"id": "poi-label",
"type": "symbol",
"source": "composite",
"source-layer": "poi_label",
"minzoom": 6,
"filter": [
{truncated for clarity, find the actual code in the mapbox standard style json or my edit history}
]
}
})
map.on('click', e => {
const selectedFeatures = map.queryRenderedFeatures(e.point)
if (selectedFeatures.length) {
alert(`You clicked ${selectedFeatures[0].properties?.name}`)
}
}) of course, this means any updates to that layer made by mapbox will have to be manually replaced. also, there will be two duplicate POI layers rendered, but visually you can't tell any difference another solution which is a one-liner, but breaks all the map config options such as POI toggling and dynamic lighting:
neither of these options are ideal, and I would really appreciate a proper API for accessing this data |
It does work (almost)! but all my custom icon's are missing. (you or someone else knows how to resolve 🤞) This is because even though I tried the following which loads the sprite images, but reloading the style like this just breaks other things in the standard style👇
Agreed. Love the new standard style features.(3d / lighting / shadows / trees / etc...) but it has made basic tasks challenging. |
Sprites might have to be loaded separately, I don't totally know how they work. Download the style.json from your network panel and you can see how it is all working |
Yea that's the plan, thank you! staying optimistic 😐 👍 Edit: solved it (or well "hacked it" into working) |
Solved it! (or well "hacked it" into working). Hoping for a better longterm solution from the Mapbox Team though To summarize for others Issue: When displaying a map using the new Standard Style (ie. why issue is happening: As I understand via my own project - this is because the new Standard Style Map relies on loading the standard style via Imports to reference all map layers. This is done for backend reasons (I believe keeping all data such as POIs and roads up to date). But because the the layers are not stored in hack solution to get
|
Here is another hack solution to control the Standard style's layers |
Nice! Yes! Your solution seems similar to my work-around for updating layers in the Standard style. =]
Not sure if there are benifits to method vs mine! 🤔 |
My method will not trigger |
Hi all, I was trying to make the labels on standard style map clickable and trying to follow the solution provided here. It was really frustrated that I can't get this simple queryRenderedFeatures function to work. Unfortunately, I got this error when copying your solution. May I have if you have encountered similar error? I tried to change composite but seems no luck. Any help is appreciated.
|
looks like there is some hope for those of us who are looking to add click interactions to the built in standard style layers! |
According to MapBox JS API docs,
getStyle
method returns Style JSON:There is not any mention or hint about
Standard
style, for which this method returns different:This makes harder to retrieve current style
name
orurl
property.Some developers even think that
Standard
style doesn't havename
at all: korywka/mapbox-controls#55.Current fix looks like this:
My proposal:
Standard
style.getStyle()
documentationlet it be
string
forurl
likemapbox://styles/mapbox/satellite-streets-v12
ormapbox://styles/mapbox/standard
andObject
for plain JSON style.Or suggest please another way to identify loaded style among others.
The text was updated successfully, but these errors were encountered: