-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Add iOS bindings and example for missing icons event. #14302
Conversation
platform/ios/src/MGLMapView.mm
Outdated
|
||
void onStyleImageMissing(const std::string& img) override { | ||
NSString *missing = [NSString stringWithCString:img.c_str() encoding:[NSString defaultCStringEncoding]]; | ||
[nativeView mapViewMissingStyleImage:missing]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to assign the returned image to a variable. Then use the returned image name to load the resource and pass this back to the renderer.
@@ -275,6 +275,8 @@ NS_ASSUME_NONNULL_BEGIN | |||
*/ | |||
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style; | |||
|
|||
|
|||
- (NSString *)mapViewMissingStyleImage:(NSString *)image; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something along the lines of:
-(NSString *)mapView:(MGLMapView *)mapView didFailLoadingImage:(NSString *)missingImage;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...didFailToLoadImage:
?
47fb41f
to
827a83f
Compare
onStyleImageMissing
I started to implement this, but I was not able to finish porting the example. I may have misunderstood what was supposed to happen, sorry! |
3b4c423
to
013b795
Compare
013b795
to
6cb7ede
Compare
onStyleImageMissing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me but I think this should get another review from someone on iOS because I don't understand that part well. This is an "approve" from my side.
If possible, it might be good to expand this test to cover a case where an icon is missing but you don't want to provide it. I've added another couple layers to the style json to test this case:
Expand to see new style json
```json { "version": 8, "name": "Mapbox Streets", "sprite": "mapbox://sprites/mapbox/streets-v8", "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", "sources": { "point": { "type": "geojson", "data": { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [0, 0] } } }, "skip-point": { "type": "geojson", "data": { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [0, 40] } } } }, "layers": [{ "id": "bg", "type": "background", "paint": { "background-color": "#f00" } }, { "id": "point", "type": "circle", "source": "point", "paint": { "circle-radius": 100 } }, { "id": "icon", "type": "symbol", "source": "point", "layout": { "icon-image": "missing-icon" } }, { "id": "show-skip-point", "type": "circle", "source": "skip-point", "paint": { "circle-radius": 100, "circle-color": "#fff" } }, { "id": "skip-icon", "type": "symbol", "source": "skip-point", "layout": { "icon-image": "skip-this-missing-icon" } }] } ```My code for this in the glfw app looks like this:
if (id != "skip-this-missing-icon") {
map->getStyle().addImage(makeImage(id, 22, 22, 1));
}
It should look something like this (no icon above the white circle):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS parts LGTM.
@ansis for whether the callback to GL is correct.
This is how it's rendered on iOS with the substitute image: |
Added a new mapView delegate method that allows reload a style icon in case it couldn't load it from the style. Added an iosapp test example.
Added a new mapView delegate method that allows reload a style icon in case it couldn't load it from the style. Added an iosapp test example.
Adds iOS bindings for #14253.
cc @julianrex @ansis