-
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
API for mutating style properties #755
Conversation
How would an imaginary API for this look like? We probably want to refactor style implementation in a way that makes it possible to do small atomic changes quickly. Like, changing one constant or adding one layer rule doesn't need to force reinterpretation of the whole style. |
One potential imaginary API would be for updates to properties in the original object passed to |
For my use cases, I really really do not want to use the stylesheet object in the map object as the point of truth. A good API would provide a CSSOM-esque API like |
For clarity, the API I was imagining is:
But since In any case this seems like it's going to be a difficult/complex implementation, with lots of corner cases. |
Hm, yeah - that isn't the kind of API that would fit my use case, though I guess it could, if it had as part of its design that the map object does not mutate the |
@jfirebaugh's idea of an API is what I was envisioning over here: cutting-room-floor/mapbox-gl-cocoa#31 (comment)
Precisely. Though this has been off my radar for a while, it's especially important on mobile, so the style of modification will likely percolate back over here. |
Does it still do that? I would consider that a bug. |
Yeah, it shouldn't. |
We could do something like http://vuejs.org/ (and some other MVC framework) does, — preprocess the given style object, replacing every property with a getter/setter with |
I'm much more in favor of an explicit setter/getter implementation than using defineProperty or Object.observe |
Yeah, I think I'm in favor of
|
Also, map.style.setIn(['layerId', 'paint', 'fill-color', '#f00']) // cascades
map.style.setIn(['layerId', 'layout', 'text-font', 'New Font']) // reloads
map.style.setIn(['layerId', 'filter', ['==', 'scalerank', 2]) // reloads — or should it be limited to nice cascading |
Some questions about how y'all would like this API to behave. So far, I have added Would you expect/require this to be perfectly symmetrical? I.e., if you call Which of the following are needed:
|
Are we going to support getting and setting non-default paint properties, like I would expect the getter to return the set value ( |
Yes, the last argument, |
I'm cool with normalization but mostly because I don't see a good way that an alternate path could be implemented without kludge. Fwiw browsers do a little bit of normalization in CSS properties, especially complex ones like matrix transforms that are reformatted and mushed internally. |
Yeah, the alternatives are to normalize at a later step (during cascade or recalculate, making them slower) or to store both the normalized and original values. Neither is very appealing. |
@jfirebaugh is there a rationale for separate methods for layout and paint, instead of general The catch-alls could avoid accidental mismatches, like |
Yes, it's essentially the same rationale as having "paint" and "layout" sections in styles -- they are different things in the features they support, how they behave, and in their performance characteristics. Changes to paint properties will transition, changes to layout properties will result in reparsing all tiles and will not transition. Also, |
@jfirebaugh lets not normalize, I don't see it as a problem in practice. |
e2b1c2c
to
c4e436e
Compare
eb00344
to
5ce426f
Compare
I see that you added an API to set layout and paint properties, that's very handy, thank you. But, as far as I can tell, filter settings are neither paint nor layout properties, they're layer properties. Do you intend to have a similar API for updating filters? |
@robschley Correct, we'll followup in future releases with more APIs. I've opened a ticket for filters: #985. Could you elaborate on your use case there, so I can make sure it's covered by the API we design? Thanks! |
So, it appears that it's only possible to cascade style changes made from an external tool if you change the stylesheet passed into mapbox-gl-js by reference, which is yucky.
Either let's have an API to do this, or maybe it'll be necessary to hack this in by using
_.assign
withmap.style.stylesheet