-
Notifications
You must be signed in to change notification settings - Fork 1.3k
MGLStyleLayer classes should conform to NSCopying #7600
Comments
The equivalent mbgl core method is |
Yes, Note that this paradigm isn’t necessarily mutually exclusive with the idea that layers must have unique IDs. A developer might reasonably want to use MGLSymbolStyleLayer *parkLayer = [[mainMapView.style layerWithIdentifier:@"parks"] copy];
[sideMapView.style addLayer:parkLayer]; Although that’s sort of awkward, since the SDK’s public interface halfheartedly pretends that a layer points to a source object as opposed to a source identifier. (MGLForegroundSource’s initializers require an MGLSource object, as a way to encourage the developer to create the layer after the source, but has only a In any event, the primary use case of duplicating a layer for use within the same map view would require a distinct identifier to be passed in. The typical way to express these semantics is with a “with” method: |
Great idea. Note that Studio just appends "copy" when duplicating a layer and subsequently starts incrementing. This feels natural when copying uniquely identified objects, copying files in Finder being the first that comes to mind. Although |
We could implement some sort of conflict avoidance inside the copy method, but that runs counter to the spirit of NSCopying, where the copy would be object-equal with the original object (assuming we override -isEqual:). As long as we provide a -styleLayerWithIdentifier: method, conflict avoidance within -copyWithZone: should be unnecessary. |
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
We should make it easy for a developer to duplicate a style layer. Currently, this is a tedious process that requires hard-coding a method call for each property in the style specification. The most natural way to streamline copying would be to have the concrete subclasses of MGLStyleLayer conform to the NSCopying protocol.
Copying a style layer would not copy the raw pointer to the underlying mbgl object but would create a pending layer object and set all its layout and paint attributes without any developer intervention. We could implement copying support in mbgl, or we could implement it entirely at the SDK level. Either way, we can take advantage of the codegen script to avoid having to hard-code the list of properties ourselves. If we do implement the feature in mbgl, we could take advantage of the JSON serialization that would be added in #7563 to conform to NSSecureCoding at the same time.
I’d consider both NSCopying and NSSecureCoding compliance to be a GL JS parity feature, because it’s quite easy with GL JS to call
getLayer()
and use a common JavaScript library to clone the returned object or stringify the JSON object./cc @frederoni @jfirebaugh
The text was updated successfully, but these errors were encountered: