[ios] Add iOS bindings and example for missing icons event. (#14302)
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.
This commit is contained in:
committed by
Fabian Guerra Soto
parent
f3c3dc49e2
commit
1aa705c2f6
@@ -103,6 +103,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
|
||||
MBXSettingsMiscellaneousToggleTwoMaps,
|
||||
MBXSettingsMiscellaneousLocalizeLabels,
|
||||
MBXSettingsMiscellaneousShowSnapshots,
|
||||
MBXSettingsMiscellaneousMissingIcon,
|
||||
MBXSettingsMiscellaneousShouldLimitCameraChanges,
|
||||
MBXSettingsMiscellaneousShowCustomLocationManager,
|
||||
MBXSettingsMiscellaneousOrnamentsPlacement,
|
||||
@@ -499,6 +500,7 @@ CLLocationCoordinate2D randomWorldCoordinate() {
|
||||
[NSString stringWithFormat:@"%@ Second Map", ([self.view viewWithTag:2] == nil ? @"Show" : @"Hide")],
|
||||
[NSString stringWithFormat:@"Show Labels in %@", (_localizingLabels ? @"Default Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])],
|
||||
@"Show Snapshots",
|
||||
@"Missing Icon",
|
||||
[NSString stringWithFormat:@"%@ Camera Changes", (_shouldLimitCameraChanges ? @"Unlimit" : @"Limit")],
|
||||
@"View Route Simulation",
|
||||
@"Ornaments Placement",
|
||||
@@ -746,6 +748,11 @@ CLLocationCoordinate2D randomWorldCoordinate() {
|
||||
[self performSegueWithIdentifier:@"ShowSnapshots" sender:nil];
|
||||
break;
|
||||
}
|
||||
case MBXSettingsMiscellaneousMissingIcon:
|
||||
{
|
||||
[self loadMissingIcon];
|
||||
break;
|
||||
}
|
||||
case MBXSettingsMiscellaneousShowCustomLocationManager:
|
||||
{
|
||||
[self performSegueWithIdentifier:@"ShowCustomLocationManger" sender:nil];
|
||||
@@ -1718,6 +1725,19 @@ CLLocationCoordinate2D randomWorldCoordinate() {
|
||||
[self.mapView addAnnotation:line];
|
||||
}
|
||||
|
||||
- (void)loadMissingIcon
|
||||
{
|
||||
self.mapView.centerCoordinate = CLLocationCoordinate2DMake(0, 0);
|
||||
self.mapView.zoomLevel = 1;
|
||||
NSURL *customStyleJSON = [[NSBundle mainBundle] URLForResource:@"missing_icon" withExtension:@"json"];
|
||||
[self.mapView setStyleURL:customStyleJSON];
|
||||
}
|
||||
|
||||
- (UIImage *)mapView:(MGLMapView *)mapView didFailToLoadImage:(NSString *)imageName {
|
||||
UIImage *backupImage = [UIImage imageNamed:@"AppIcon"];
|
||||
return backupImage;
|
||||
}
|
||||
|
||||
- (void)printTelemetryLogFile
|
||||
{
|
||||
NSString *fileContents = [NSString stringWithContentsOfFile:[self telemetryDebugLogFilePath] encoding:NSUTF8StringEncoding error:nil];
|
||||
|
||||
40
platform/ios/app/missing_icon.json
Normal file
40
platform/ios/app/missing_icon.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"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]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}]
|
||||
}
|
||||
@@ -459,6 +459,7 @@
|
||||
96F3F73C1F57124B003E2D2C /* MGLUserLocationHeadingIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = 96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */; };
|
||||
9C188C4F2242C95A0022FA55 /* MMEDate.m in Sources */ = {isa = PBXBuildFile; fileRef = 40834BBC1FE05D6E00C1BD0D /* MMEDate.m */; };
|
||||
9C188C502242C96F0022FA55 /* MMEDate.h in Headers */ = {isa = PBXBuildFile; fileRef = 40834BC51FE05D6F00C1BD0D /* MMEDate.h */; };
|
||||
A4F3FB1D2254865900A30170 /* missing_icon.json in Resources */ = {isa = PBXBuildFile; fileRef = A4F3FB1C2254865900A30170 /* missing_icon.json */; };
|
||||
AC1B0916221CA14D00DB56C8 /* CLLocationManager+MMEMobileEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = AC1B0914221CA14500DB56C8 /* CLLocationManager+MMEMobileEvents.h */; };
|
||||
AC1B0917221CA14D00DB56C8 /* CLLocationManager+MMEMobileEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = AC1B0914221CA14500DB56C8 /* CLLocationManager+MMEMobileEvents.h */; };
|
||||
AC1B0918221CA14D00DB56C8 /* CLLocationManager+MMEMobileEvents.m in Sources */ = {isa = PBXBuildFile; fileRef = AC1B0915221CA14C00DB56C8 /* CLLocationManager+MMEMobileEvents.m */; };
|
||||
@@ -1143,6 +1144,7 @@
|
||||
96ED34DD22374C0900E9FCA9 /* MGLMapViewDirectionTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLMapViewDirectionTests.mm; sourceTree = "<group>"; };
|
||||
96F017292118FBAE00892778 /* MGLMapView_Experimental.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Experimental.h; sourceTree = "<group>"; };
|
||||
96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLUserLocationHeadingIndicator.h; sourceTree = "<group>"; };
|
||||
A4F3FB1C2254865900A30170 /* missing_icon.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = missing_icon.json; sourceTree = "<group>"; };
|
||||
AC1B0914221CA14500DB56C8 /* CLLocationManager+MMEMobileEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "CLLocationManager+MMEMobileEvents.h"; path = "../vendor/mapbox-events-ios/MapboxMobileEvents/CLLocationManager+MMEMobileEvents.h"; sourceTree = "<group>"; };
|
||||
AC1B0915221CA14C00DB56C8 /* CLLocationManager+MMEMobileEvents.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "CLLocationManager+MMEMobileEvents.m"; path = "../vendor/mapbox-events-ios/MapboxMobileEvents/CLLocationManager+MMEMobileEvents.m"; sourceTree = "<group>"; };
|
||||
AC518DFD201BB55A00EBC820 /* MGLTelemetryConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLTelemetryConfig.h; sourceTree = "<group>"; };
|
||||
@@ -1883,6 +1885,7 @@
|
||||
children = (
|
||||
353BAEF51D646370009A8DA9 /* amsterdam.geojson */,
|
||||
DA1DC96C1CB6C6CE006E619F /* points.geojson */,
|
||||
A4F3FB1C2254865900A30170 /* missing_icon.json */,
|
||||
DA1DC96D1CB6C6CE006E619F /* polyline.geojson */,
|
||||
1F26B6C220E1A351007BCC21 /* simple_route.json */,
|
||||
DA1DC96F1CB6C6CE006E619F /* threestates.geojson */,
|
||||
@@ -2932,6 +2935,7 @@
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
English,
|
||||
en,
|
||||
Base,
|
||||
"zh-Hans",
|
||||
@@ -3001,6 +3005,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
DD4823771D94AE6C00EB71B7 /* numeric_filter_style.json in Resources */,
|
||||
A4F3FB1D2254865900A30170 /* missing_icon.json in Resources */,
|
||||
DA1DC9701CB6C6CE006E619F /* points.geojson in Resources */,
|
||||
353BAEF61D646370009A8DA9 /* amsterdam.geojson in Resources */,
|
||||
DA1DC9711CB6C6CE006E619F /* polyline.geojson in Resources */,
|
||||
|
||||
@@ -6827,6 +6827,20 @@ public:
|
||||
void onDidFinishLoadingStyle() override {
|
||||
[nativeView didFinishLoadingStyle];
|
||||
}
|
||||
|
||||
void onStyleImageMissing(const std::string& imageIdentifier) override {
|
||||
NSString *imageName = [NSString stringWithUTF8String:imageIdentifier.c_str()];
|
||||
|
||||
if ([nativeView.delegate respondsToSelector:@selector(mapView:didFailToLoadImage:)]) {
|
||||
UIImage *imageToLoad = [nativeView.delegate mapView:nativeView didFailToLoadImage:imageName];
|
||||
|
||||
if (imageToLoad) {
|
||||
auto image = [imageToLoad mgl_styleImageWithIdentifier:imageName];
|
||||
nativeView.mbglMap.getStyle().addImage(std::move(image));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mbgl::gl::ProcAddress getExtensionFunctionPointer(const char* name) override {
|
||||
static CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengles"));
|
||||
|
||||
@@ -275,6 +275,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style;
|
||||
|
||||
- (nullable UIImage *)mapView:(MGLMapView *)mapView didFailToLoadImage:(NSString *)imageName;
|
||||
|
||||
#pragma mark Tracking User Location
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,4 +96,6 @@ extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate {
|
||||
func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera, reason: MGLCameraChangeReason) -> Bool { return false }
|
||||
|
||||
func mapViewUserLocationAnchorPoint(_ mapView: MGLMapView) -> CGPoint { return CGPoint(x: 100, y: 100) }
|
||||
|
||||
func mapView(_ mapView: MGLMapView, didFailToLoadImage imageName: String) -> UIImage? { return nil }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user