-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Use (shallow) merge semantics for map.setStyle()
#6701
Comments
Hmm... my first reaction is pretty strongly against this. I think a lot of the benefit of smart What if we want to introduce non-required top-level properties, where it would be important to be able to distinguish between an intent to omit the value so that it's restored to the default value, versus an intent to retain the existing value via shallow merge? (In fact, |
I agree that we'd lose the dead-simplicity here, and that that's a real loss. But IMO, the bulk of smart Worth noting that the proposed semantics here are what we chose to use for
Good point... I guess we'd have to do something like require an explicit |
Good thread. I have two primary projects: one uses a large amount of embedded GeoJSON data, and the other project has heavier data-driven expressions. For both of these, That being said, How do we balance the simplicity of Much of my code is written in React, and uses referential equality ( |
Thanks @andest01.
Can you say more about what makes
Yep, @jfirebaugh and I were discussing this yesterday and leaning towards such an approach. See also #4875 |
Hi @anandthakker. I'll talk a little more about Suppose that you have a large amount of Admin 2 geometries -- say fewer than 5000 of them, distributed across a large area. These geometries are served from a tile server. The geometries have only an identifier, perhaps a four or five digit string, in their In order to match up your data that you're receiving in real time (as short as 500 ms per update) that has an ID and a piece of data, you'll likely need to use a data driven expression. The Mapbox Style Expression documentation is a bit.... shall we say, laconic, so you elect to use the
Also, given advanced visual design requirements (selection, highlighting, inner and outer borders), you'll need to create multiple layers of data-driven So let's back up for a second and take stock. Because the tile-server only stores IDs and our data changes in real-time, we're forced to somehow transcribe that data into a mapbox You can probably see where this is going. :) The result is that The point is to help show you various ways that |
Motivation
Map#setStyle()
currently does a deep equality comparison when diffing sources:mapbox-gl-js/src/style-spec/diff.js
Line 153 in a5a8dfe
This is unnecessarily costly for styles using inline / dynamically-created GeoJSON data. And more generally, it's very common that the caller of
map.setStyle()
knows that the sources haven't changed.See also @averas's comment here: #3643 (comment)
Design Alternatives
#4006
#4000
Design
Per the title, I propose that we do a shallow merge from
map.setStyle()
. In practice, this means that a user could omit omit any top-level field (sources
,layers
, etc.) of the style they're passing tomap.setStyle()
, and we would just use the existing style state for that field.Mock-Up
The text was updated successfully, but these errors were encountered: