Repository navigation
Check for duplicate layer IDs - #7257
Conversation
|
@ivovandongen, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @boundsj and @tmpsantos to be potential reviewers. |
43008a0 to
9f71100
Compare
|
cc @1ec5 @jfirebaugh |
|
|
||
| self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer)); | ||
| try { | ||
| self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer)); |
There was a problem hiding this comment.
What about the other addLayer() call in this class? (There’s also one in MGLMapView.mm, but that’ll go away as part of #7250.)
There was a problem hiding this comment.
Added (tests) for MGLStyle#insertLayer and and MGLMapView#insertCustomStyleLayerWithIdentifier.
| try { | ||
| self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer)); | ||
| } catch (std::runtime_error & err) { | ||
| [NSException raise:@"Could not add layer" format:@"%s", err.what()]; |
There was a problem hiding this comment.
This reminds me that we need to be more disciplined about exception names in the SDK: #7258. (Not required for this PR.)
| @@ -0,0 +1,25 @@ | |||
| #import "MGLMapViewTests.h" | |||
There was a problem hiding this comment.
Since this file isn’t specific to iOS, it should live in platform/darwin/test/ and also be included in macos.xcodeproj. (This is the theme of our contributing documentation, although we neglected to point out that tests should be shared too when possible.)
There was a problem hiding this comment.
Moved the files and added to macos as well. Excluded the custom layer tests for macos as the header is ios specific. Also changed the source test according to #7203 (comment)
There was a problem hiding this comment.
That’s fine; the custom style layer API is getting folded into the normal style layer API in #7250, so soon there won’t be anything extra to test.
1008bbe to
89bfd97
Compare
1ec5
left a comment
There was a problem hiding this comment.
Looks great!
Once we merge release-ios-v3.4.0 back to master, the particular call sites you’re wrapping in try-catch blocks will be replaced by new call sites in MGLStyle and the various MGLStyleLayer classes, due to #6793, #6793, #6097, and #7250. So we’ll need to be vigilant with that merge.
/cc @boundsj
| MGLCustomStyleLayerPreparationHandler preparationHandler = ^{}; | ||
| MGLCustomStyleLayerDrawingHandler drawingHandler = ^(CGSize size, CLLocationCoordinate2D centerCoordinate, double zoomLevel, CLLocationDirection direction, CGFloat pitch, CGFloat perspectiveSkew) { | ||
| }; | ||
| MGLCustomStyleLayerCompletionHandler completionHander = ^{}; |
There was a problem hiding this comment.
FYI, feel free to inline these blocks into the method call. Long lines are par for the course in Objective-C. 😉
|
The iOS test failure appears to be what I fixed in #7228 on the release-ios-v3.4.0 branch. |
89bfd97 to
d0cb5fa
Compare
| const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String}; | ||
| self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer), belowLayerId); | ||
| try { | ||
| self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer), belowLayerId); |
There was a problem hiding this comment.
Now that #7282 has landed – including the changes in #6793, #6793, #6097, and #7250 – you’ll need to wrap any call to -[MGLStyleLayer addToMapView:] in this try-catch block or alternatively move this try-catch block to every implementation of -addToMapView: in the concrete subclasses of MGLStyleLayer.
04cbd5b to
c005962
Compare
c005962 to
93b5ea0
Compare
There was a problem hiding this comment.
I just realized we’ve been saying “identifer” instead of “identifier”, both for layers and sources. I can fix that typo in a separate PR, since we also need to add a note to the documentation for the affected methods about MGLRedundantLayerIdentifierException (prior art involving sources).
There was a problem hiding this comment.
If you’re in a good spot to do it, can you rename MGLRedundantLayerIdentiferException to MGLRedundantLayerIdentiferException? I don’t think we have any instances of it in the release branch, so this is a good branch to do it in. I can take care of MGLRedundantSourceIdentiferException separately: #7314.
93b5ea0 to
617d3e4
Compare
617d3e4 to
1ed3ff1
Compare
There was a problem hiding this comment.
We're catching a generic exception here, but always forward a MGLRedundantLayerIdentifierException. What we should do long term is to convert all of the generic std::runtime_error into individual exception types, and to exception-specific catches that we can then forward.
There was a problem hiding this comment.
Code style is to have a space after //.
There was a problem hiding this comment.
no need to to c_str() here; std::runtime_error also accepts std::string. You could change this to something like this;
throw std::runtime_error(std::string{"Layer "} + layer->getID() + " already exists");There was a problem hiding this comment.
The rule for exceptions in C++ is to throw by value and catch a const reference
1ed3ff1 to
57b0ba7
Compare
|
@kkaefer Thanks for the review, I've addressed your notes. |
Fixes #7254