-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Source and layer ownership is inconsistent (from style versus from developer) #6254
Comments
To expand on #6269 (comment), objects wrapping
This is the approach that the Android bindings follow. |
Note that after a source or layer is removed from the style, you don't get ownership of that object back, and any raw pointers you retained are invalid. This has implications for documentation of the SDK bindings for the removal methods. |
By the way, a somewhat orthogonal idea: for MGLStyleLayers obtained from the MGLStyle, the only state MGLStyleLayer maintains would be the layer identifier, and it always uses that identifier to obtain the |
Textbook example of what developers face with the current inconsistency: #6460. |
MGLSource and the MGLStyleLayer classes manage their underlying C++ objects inconsistently depending on the task. For example, when getting an MGLSource object from an MGLStyle, the MGLSource object holds a strong reference to an
mbgl::style::Source
object in itssource
property. On the other hand, when the developer initializes an MGLSource object from scratch in order to add it to an MGLMapView,-[MGLSource mbglSource]
creates thembgl::style::Source
object lazily when adding it to the style and never holds a reference to it. If the developer attempts to get an MGLSource from the style and add it back to the style, a brand-newmbgl::style::Source
object is created and added to the map, discarding any modifications that the developer may have made on the MGLSource object.We should remove
-[MGLSource mbglSource]
. MGLSource should create thembgl::style::Source
upfront in its initializers. (There should be an additional private initializer that accepts anmbgl::style::Source
.) This means all the source options need to be immutable. Currently, the only mutable source option is thesourceIdentifier
property, but I think that should be read-only anyways.The catch is that a source added to the map really shouldn’t be owned by the MGLSource object. Could we treat the
source
property as holding only a “pending” source and always access thembgl::style::Source
object viambgl::Map::getSource()
? What happens if the developer attempts to add the same MGLSource to the MGLStyles of two different MGLMapViews?/cc @frederoni @boundsj
The text was updated successfully, but these errors were encountered: