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
Map is 1342 lines of code and exposes about a hundred methods, properties, and events. We should simplify Map's interface and implementation by moving as much logic downstream as possible and maybe moving some interface components downstream.
moving as much logic downstream as possible
Having many methods, properties, and events on Map would be more manageable if Map did not have any logic or state of its own.
For example, we should endevour to rewrite setMaxBounds
i.e. change the public interface from map.setPaintProperty(...) to map.style.setPaintProperty(...) (or map.style.paint['circle-color'].set(...))
The core mbgl native equivalent is map.getLayer(id).setCircleColor(...) (modulo some downcasting from the base Layer type to CircleLayer).
The difficulty of pushing the setters down to below the map level is how do you trigger the subsequent style recalculations? When I was first implementing map.setPaintProperty, I considered several alternatives:
Require downstream code to manually trigger style recalculation. For native I'm going to see if the "downstream code" in the iOS SDK or Android SDK bindings can do this. I don't think we want this implementation detail to leak to actual user code.
Have every mutable object have a reference back to the containing Map, so that the setter can trigger the recalculation.
Implement the observer pattern and have the map register for notifications from each mutable object. If individual layers or properties have a set method, this becomes cumbersome.
In the end none of these seemed worthwhile when compared to the simplicity of map.setPaintProperty(...). But I agree it does bloat Map. I think map.style.setPaintProperty(...), and an observable Style, could be a good compromise.
Implement the observer pattern and have the map register for notifications from each mutable object. If individual layers or properties have a set method, this becomes cumbersome.
Looks like this is the route native is going to go, with style sources and layers being the lowest level of observable object, which isn't too cumbersome.
I addressed the first part of the original issue in #7060, but the issue of changing the API to call methods on layer instances directly is still open, so maybe let's make a new issue or reopen/edit this one.
Activity
jfirebaugh commentedon Jun 15, 2016
The core mbgl native equivalent is
map.getLayer(id).setCircleColor(...)(modulo some downcasting from the baseLayertype toCircleLayer).The difficulty of pushing the setters down to below the map level is how do you trigger the subsequent style recalculations? When I was first implementing
map.setPaintProperty, I considered several alternatives:Map, so that the setter can trigger the recalculation.setmethod, this becomes cumbersome.In the end none of these seemed worthwhile when compared to the simplicity of
map.setPaintProperty(...). But I agree it does bloatMap. I thinkmap.style.setPaintProperty(...), and an observableStyle, could be a good compromise.mourner commentedon Jun 16, 2016
It was like that before, why did we move it upstream in the first place? I don't remember exactly but there must have been a reason.
jfirebaugh commentedon Jun 16, 2016
@mourner
style.setPaintProperty(...)has existed, butmap.setPaintProperty(...)has always been the public API, starting withsetPaintProperty's introduction in a374e74#diff-274e90d38623e2e16a5e7d34414f33c7R250.jfirebaugh commentedon Aug 29, 2016
Looks like this is the route native is going to go, with style sources and layers being the lowest level of observable object, which isn't too cumbersome.
mourner commentedon Aug 1, 2018
I addressed the first part of the original issue in #7060, but the issue of changing the API to call methods on layer instances directly is still open, so maybe let's make a new issue or reopen/edit this one.