From eb7926d20572c19363568f53c117cf8eb1b373d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Wed, 5 Jul 2017 17:32:23 +0200 Subject: [android] - invible marker views performance fix #9419 (#9420) --- .../main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java index 6d42842b7d..dce6f6b277 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java @@ -198,7 +198,7 @@ public class MarkerViewManager implements MapView.OnMapChangedListener { // ensure view is measured first // #6805 invalidate marker views to ensure convertView width and height // values are properly measured and up to date - if (marker.getWidth() == 0) { + if (marker.getWidth() == 0 && marker.isVisible()) { convertView.getViewTreeObserver().addOnPreDrawListener(markerViewPreDrawObserver); } } -- cgit v1.2.1 From c966c0e12f828e0e442b8a360314bd69627a228d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 20 Jun 2017 18:04:10 -0700 Subject: [ios] Update SMCalloutView to fix iOS 10 build warnings Reapplied 76a2a2db28ce70d06b64b747cfc59ed493eefc67, which was partially rolled back in f6e79d70735361438655f279c8699a786d25458c. --- platform/ios/vendor/SMCalloutView | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/ios/vendor/SMCalloutView b/platform/ios/vendor/SMCalloutView index 2aede5d8d1..d6ecaba377 160000 --- a/platform/ios/vendor/SMCalloutView +++ b/platform/ios/vendor/SMCalloutView @@ -1 +1 @@ -Subproject commit 2aede5d8d1577101bf18405246220e7a710df607 +Subproject commit d6ecaba377c9f963aef630faf86e3b8f8cdb88d1 -- cgit v1.2.1 From 3fce13349ccdcc1af0efd333020949c355376282 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Mon, 10 Jul 2017 17:32:43 -0400 Subject: [darwin] Include polylabel via cmake --- platform/ios/config.cmake | 1 + platform/ios/ios.xcodeproj/project.pbxproj | 30 ++++++-------------------- platform/macos/config.cmake | 1 + platform/macos/macos.xcodeproj/project.pbxproj | 20 ++++------------- scripts/config.xcconfig.in | 1 - 5 files changed, 12 insertions(+), 41 deletions(-) diff --git a/platform/ios/config.cmake b/platform/ios/config.cmake index fdb286a6d1..e9c56f2454 100644 --- a/platform/ios/config.cmake +++ b/platform/ios/config.cmake @@ -65,6 +65,7 @@ macro(mbgl_platform_core) ) target_add_mason_package(mbgl-core PUBLIC geojson) + target_add_mason_package(mbgl-core PUBLIC polylabel) target_add_mason_package(mbgl-core PRIVATE icu) target_compile_options(mbgl-core diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index ab110bca5c..82e385bbbc 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -2676,10 +2676,7 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = test/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -2703,10 +2700,7 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = test/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -2734,10 +2728,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -2771,10 +2762,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -2825,10 +2813,7 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { BITCODE_GENERATION_MODE = bitcode; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", @@ -2854,10 +2839,7 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { BITCODE_GENERATION_MODE = bitcode; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", diff --git a/platform/macos/config.cmake b/platform/macos/config.cmake index 8dc3c38245..c6ccdf8caf 100644 --- a/platform/macos/config.cmake +++ b/platform/macos/config.cmake @@ -61,6 +61,7 @@ macro(mbgl_platform_core) ) target_add_mason_package(mbgl-core PUBLIC geojson) + target_add_mason_package(mbgl-core PUBLIC polylabel) target_add_mason_package(mbgl-core PRIVATE icu) target_compile_options(mbgl-core diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 564d81afb2..1127524098 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -1779,10 +1779,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = "$(SRCROOT)/sdk/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; @@ -1816,10 +1813,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = "$(SRCROOT)/sdk/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; @@ -1843,10 +1837,7 @@ buildSettings = { CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = test/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; LIBRARY_SEARCH_PATHS = ( @@ -1875,10 +1866,7 @@ buildSettings = { CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - "$(polylabel_INCLUDE_DIRECTORIES)", - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = test/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; OTHER_CFLAGS = "-fvisibility=hidden"; diff --git a/scripts/config.xcconfig.in b/scripts/config.xcconfig.in index b70ff9d677..eb6bc71b89 100644 --- a/scripts/config.xcconfig.in +++ b/scripts/config.xcconfig.in @@ -3,4 +3,3 @@ // mbgl-core mbgl_core_INCLUDE_DIRECTORIES = "@mbgl_core_INCLUDE_DIRECTORIES@" mbgl_core_LINK_LIBRARIES = "@mbgl_core_LINK_LIBRARIES@" -polylabel_INCLUDE_DIRECTORIES = "@MASON_PACKAGE_polylabel_INCLUDE_DIRS@" -- cgit v1.2.1 From 629922f5570abc46011db092d204c2e7642812c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 5 Jan 2017 14:37:29 +0100 Subject: [build] enable -fvisibility=hidden for iOS --- Makefile | 2 +- platform/ios/config.cmake | 1 + platform/ios/ios.xcodeproj/project.pbxproj | 8 ++++++++ platform/ios/src/MGLAnnotationImage.h | 3 +++ platform/ios/src/MGLAnnotationView.h | 3 +++ platform/ios/src/MGLMapView.h | 9 +++++---- platform/ios/src/MGLUserLocation.h | 2 ++ platform/ios/src/MGLUserLocationAnnotationView.h | 2 ++ 8 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1a635cdd3c..b09d1a9ba3 100644 --- a/Makefile +++ b/Makefile @@ -273,7 +273,7 @@ darwin-update-examples: .PHONY: check-public-symbols check-public-symbols: - node platform/darwin/scripts/check-public-symbols.js macOS + node platform/darwin/scripts/check-public-symbols.js macOS iOS endif #### Linux targets ##################################################### diff --git a/platform/ios/config.cmake b/platform/ios/config.cmake index e9c56f2454..0adacddd35 100644 --- a/platform/ios/config.cmake +++ b/platform/ios/config.cmake @@ -70,6 +70,7 @@ macro(mbgl_platform_core) target_compile_options(mbgl-core PRIVATE -fobjc-arc + PRIVATE -fvisibility=hidden ) # TODO: Remove this by converting to ARC diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 82e385bbbc..7c6f1115c5 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -186,6 +186,7 @@ 40F887701D7A1E58008ECB67 /* MGLShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */; }; 40F887711D7A1E59008ECB67 /* MGLShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */; }; 40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */; }; + 5549A0381EF1D86B00073113 /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5549A0371EF1D86B00073113 /* libmbgl-core.a */; }; 556660CA1E1BF3A900E2C41B /* MGLFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 556660C91E1BF3A900E2C41B /* MGLFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 556660D81E1D085500E2C41B /* MGLVersionNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 556660D71E1D085500E2C41B /* MGLVersionNumber.m */; }; 556660DB1E1D8E8D00E2C41B /* MGLFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 556660C91E1BF3A900E2C41B /* MGLFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -656,6 +657,7 @@ 40FDA7691CCAAA6800442548 /* MBXAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXAnnotationView.h; sourceTree = ""; }; 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXAnnotationView.m; sourceTree = ""; }; 554180411D2E97DE00012372 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; + 5549A0371EF1D86B00073113 /* libmbgl-core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-core.a"; path = "../../build/ios/Debug-iphonesimulator/libmbgl-core.a"; sourceTree = ""; }; 556660C91E1BF3A900E2C41B /* MGLFoundation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLFoundation.h; sourceTree = ""; }; 556660D71E1D085500E2C41B /* MGLVersionNumber.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MGLVersionNumber.m; path = ../../darwin/test/MGLVersionNumber.m; sourceTree = ""; }; 558DE79E1E5615E400C7916D /* MGLFoundation_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFoundation_Private.h; sourceTree = ""; }; @@ -945,6 +947,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5549A0381EF1D86B00073113 /* libmbgl-core.a in Frameworks */, DA2E88561CC036F400F24E7B /* Mapbox.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1219,6 +1222,7 @@ DA1DC9921CB6DF24006E619F /* Frameworks */ = { isa = PBXGroup; children = ( + 5549A0371EF1D86B00073113 /* libmbgl-core.a */, 36F1153B1D46080700878E1A /* libmbgl-core.a */, 36F1153C1D46080700878E1A /* libmbgl-platform-ios.a */, 554180411D2E97DE00012372 /* OpenGLES.framework */, @@ -2733,6 +2737,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + OTHER_CFLAGS = "-fvisibility=hidden"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", @@ -2767,6 +2772,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + OTHER_CFLAGS = "-fvisibility=hidden"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", @@ -2814,6 +2820,7 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; + OTHER_CFLAGS = "-fvisibility=hidden"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", @@ -2840,6 +2847,7 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; + OTHER_CFLAGS = "-fvisibility=hidden"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", diff --git a/platform/ios/src/MGLAnnotationImage.h b/platform/ios/src/MGLAnnotationImage.h index fbeee18624..0b5a111841 100644 --- a/platform/ios/src/MGLAnnotationImage.h +++ b/platform/ios/src/MGLAnnotationImage.h @@ -1,5 +1,7 @@ #import +#import "MGLFoundation.h" + NS_ASSUME_NONNULL_BEGIN /** @@ -8,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN objects and may be recycled later and put into a reuse queue that is maintained by the map view. */ +MGL_EXPORT @interface MGLAnnotationImage : NSObject #pragma mark Initializing and Preparing the Image Object diff --git a/platform/ios/src/MGLAnnotationView.h b/platform/ios/src/MGLAnnotationView.h index 2802d31b05..4fa0f196ab 100644 --- a/platform/ios/src/MGLAnnotationView.h +++ b/platform/ios/src/MGLAnnotationView.h @@ -1,5 +1,7 @@ #import +#import "MGLFoundation.h" + NS_ASSUME_NONNULL_BEGIN @protocol MGLAnnotation; @@ -50,6 +52,7 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationViewDragState) { interactivity such as dragging, you can use an `MGLAnnotationImage` instead to conserve memory and optimize drawing performance. */ +MGL_EXPORT @interface MGLAnnotationView : UIView #pragma mark Initializing and Preparing the View diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 31320ac977..a93b8e8511 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -4,6 +4,7 @@ #import #import +#import "MGLFoundation.h" #import "MGLTypes.h" NS_ASSUME_NONNULL_BEGIN @@ -23,13 +24,13 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; /** The default deceleration rate for a map view. */ -extern const CGFloat MGLMapViewDecelerationRateNormal; +extern MGL_EXPORT const CGFloat MGLMapViewDecelerationRateNormal; /** A fast deceleration rate for a map view. */ -extern const CGFloat MGLMapViewDecelerationRateFast; +extern MGL_EXPORT const CGFloat MGLMapViewDecelerationRateFast; /** Disables deceleration in a map view. */ -extern const CGFloat MGLMapViewDecelerationRateImmediate; +extern MGL_EXPORT const CGFloat MGLMapViewDecelerationRateImmediate; /** The vertical alignment of an annotation within a map view. Used with @@ -125,7 +126,7 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingMode) { ensuring that your use adheres to the relevant terms of use. */ -IB_DESIGNABLE +MGL_EXPORT IB_DESIGNABLE @interface MGLMapView : UIView #pragma mark Creating Instances diff --git a/platform/ios/src/MGLUserLocation.h b/platform/ios/src/MGLUserLocation.h index 30bfc592ca..8c6fe46136 100644 --- a/platform/ios/src/MGLUserLocation.h +++ b/platform/ios/src/MGLUserLocation.h @@ -1,6 +1,7 @@ #import #import +#import "MGLFoundation.h" #import "MGLAnnotation.h" NS_ASSUME_NONNULL_BEGIN @@ -11,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN directly. Instead, you retrieve an existing `MGLUserLocation` object from the `userLocation` property of the map view displayed in your application. */ +MGL_EXPORT @interface MGLUserLocation : NSObject #pragma mark Determining the User’s Position diff --git a/platform/ios/src/MGLUserLocationAnnotationView.h b/platform/ios/src/MGLUserLocationAnnotationView.h index 4b36236b8d..4d95f39cf3 100644 --- a/platform/ios/src/MGLUserLocationAnnotationView.h +++ b/platform/ios/src/MGLUserLocationAnnotationView.h @@ -1,6 +1,7 @@ #import #import +#import "MGLFoundation.h" #import "MGLAnnotationView.h" NS_ASSUME_NONNULL_BEGIN @@ -9,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @class MGLUserLocation; /** View representing an `MGLUserLocation` on screen. */ +MGL_EXPORT @interface MGLUserLocationAnnotationView : MGLAnnotationView /** -- cgit v1.2.1 From f16a4e5da6609a17a29fde5295f19ca78adfeb7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 14 Jun 2017 21:47:01 +0200 Subject: [all] make default_styles header-only --- cmake/glfw.cmake | 1 - cmake/offline.cmake | 1 - platform/default/mbgl/util/default_styles.cpp | 18 ------------------ platform/default/mbgl/util/default_styles.hpp | 16 ++++++++-------- platform/ios/config.cmake | 1 - platform/macos/config.cmake | 1 - platform/qt/qt.cmake | 1 - 7 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 platform/default/mbgl/util/default_styles.cpp diff --git a/cmake/glfw.cmake b/cmake/glfw.cmake index f1ace9e6ef..c14bd6f2c2 100644 --- a/cmake/glfw.cmake +++ b/cmake/glfw.cmake @@ -8,7 +8,6 @@ target_sources(mbgl-glfw PRIVATE platform/glfw/settings_json.hpp PRIVATE platform/glfw/settings_json.cpp PRIVATE platform/default/mbgl/util/default_styles.hpp - PRIVATE platform/default/mbgl/util/default_styles.cpp ) # Our GL implementation is internal to mbgl-core, which causes the GL header to diff --git a/cmake/offline.cmake b/cmake/offline.cmake index d0124e661f..a79b22db54 100644 --- a/cmake/offline.cmake +++ b/cmake/offline.cmake @@ -4,7 +4,6 @@ add_executable(mbgl-offline target_sources(mbgl-offline PRIVATE platform/default/mbgl/util/default_styles.hpp - PRIVATE platform/default/mbgl/util/default_styles.cpp ) target_compile_options(mbgl-offline diff --git a/platform/default/mbgl/util/default_styles.cpp b/platform/default/mbgl/util/default_styles.cpp deleted file mode 100644 index 5f4ca862fe..0000000000 --- a/platform/default/mbgl/util/default_styles.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -namespace mbgl { -namespace util { -namespace default_styles { - -const DefaultStyle streets = { "mapbox://styles/mapbox/streets-v10", "Streets", 10 }; -const DefaultStyle outdoors = { "mapbox://styles/mapbox/outdoors-v10", "Outdoors", 10 }; -const DefaultStyle light = { "mapbox://styles/mapbox/light-v9", "Light", 9 }; -const DefaultStyle dark = { "mapbox://styles/mapbox/dark-v9", "Dark", 9 }; -const DefaultStyle satellite = { "mapbox://styles/mapbox/satellite-v9", "Satellite", 9 }; -const DefaultStyle satelliteStreets = { "mapbox://styles/mapbox/satellite-streets-v10", "Satellite Streets", 10 }; -const DefaultStyle trafficDay = { "mapbox://styles/mapbox/traffic-day-v2", "Traffic Day", 2 }; -const DefaultStyle trafficNight = { "mapbox://styles/mapbox/traffic-night-v2", "Traffic Night", 2 }; - -} // namespace default_styles -} // end namespace util -} // end namespace mbgl diff --git a/platform/default/mbgl/util/default_styles.hpp b/platform/default/mbgl/util/default_styles.hpp index 466102d623..43dafb8083 100644 --- a/platform/default/mbgl/util/default_styles.hpp +++ b/platform/default/mbgl/util/default_styles.hpp @@ -13,14 +13,14 @@ struct DefaultStyle { const unsigned currentVersion; }; -extern const DefaultStyle streets; -extern const DefaultStyle outdoors; -extern const DefaultStyle light; -extern const DefaultStyle dark; -extern const DefaultStyle satellite; -extern const DefaultStyle satelliteStreets; -extern const DefaultStyle trafficDay; -extern const DefaultStyle trafficNight; +constexpr const DefaultStyle streets = { "mapbox://styles/mapbox/streets-v10", "Streets", 10 }; +constexpr const DefaultStyle outdoors = { "mapbox://styles/mapbox/outdoors-v10", "Outdoors", 10 }; +constexpr const DefaultStyle light = { "mapbox://styles/mapbox/light-v9", "Light", 9 }; +constexpr const DefaultStyle dark = { "mapbox://styles/mapbox/dark-v9", "Dark", 9 }; +constexpr const DefaultStyle satellite = { "mapbox://styles/mapbox/satellite-v9", "Satellite", 9 }; +constexpr const DefaultStyle satelliteStreets = { "mapbox://styles/mapbox/satellite-streets-v10", "Satellite Streets", 10 }; +constexpr const DefaultStyle trafficDay = { "mapbox://styles/mapbox/traffic-day-v2", "Traffic Day", 2 }; +constexpr const DefaultStyle trafficNight = { "mapbox://styles/mapbox/traffic-night-v2", "Traffic Night", 2 }; const DefaultStyle orderedStyles[] = { streets, outdoors, light, dark, satellite, satelliteStreets, diff --git a/platform/ios/config.cmake b/platform/ios/config.cmake index 0adacddd35..836d0678cb 100644 --- a/platform/ios/config.cmake +++ b/platform/ios/config.cmake @@ -23,7 +23,6 @@ macro(mbgl_platform_core) # Default styles PRIVATE platform/default/mbgl/util/default_styles.hpp - PRIVATE platform/default/mbgl/util/default_styles.cpp # Offline PRIVATE platform/default/mbgl/storage/offline.cpp diff --git a/platform/macos/config.cmake b/platform/macos/config.cmake index c6ccdf8caf..1b8ea35814 100644 --- a/platform/macos/config.cmake +++ b/platform/macos/config.cmake @@ -19,7 +19,6 @@ macro(mbgl_platform_core) # Default styles PRIVATE platform/default/mbgl/util/default_styles.hpp - PRIVATE platform/default/mbgl/util/default_styles.cpp # Offline PRIVATE platform/default/mbgl/storage/offline.cpp diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index cee0d1080c..67622efca6 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -65,7 +65,6 @@ add_library(qmapboxgl SHARED platform/qt/src/qmapboxgl.cpp platform/qt/src/qmapboxgl_p.hpp platform/default/mbgl/util/default_styles.hpp - platform/default/mbgl/util/default_styles.cpp ) # C++ app -- cgit v1.2.1 From 76caec25c73ef3ddbf2d1673ecfe2c4d9e4f1b45 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Thu, 13 Jul 2017 01:52:55 -0400 Subject: [ios] Update changelog; kick-off 3.6.1 --- platform/ios/CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index c08952a664..93da2ff372 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -2,7 +2,11 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started. -## 3.6.0 +## 3.6.1 + +* Reduced the size of the dynamic framework by optimizing symbol visibility. ([#7604](https://github.com/mapbox/mapbox-gl-native/pull/7604)) + +## 3.6.0 - June 29, 2017 ### Packaging -- cgit v1.2.1 From ccb525553786e11fbb76af2caf931ba539713761 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 13 Jun 2017 16:04:13 -0700 Subject: [core] Don't use "current" icon/text-size when binding The current value is not passed to `SymbolSizeBinder::uniformValues`, so we shouldn't check `currentValue.isConstant()` in `SymbolSizeBinder::attributeBindings`. If it were true, then we might end up using attribute bindings that are appropriate only for a constant property, but uniform bindings that are appropriate only for a source or composite function. Instead, just wait for a new bucket to be generated. This will happen automatically, since icon/text-size are layout properties. --- src/mbgl/programs/symbol_program.hpp | 21 +++++---------------- src/mbgl/renderer/painter_symbol.cpp | 1 - 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 01e95f456d..abcba1d033 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -107,7 +107,7 @@ public: const style::DataDrivenPropertyValue& sizeProperty, const float defaultValue); - virtual SymbolSizeAttributes::Bindings attributeBindings(const PossiblyEvaluatedPropertyValue currentValue) const = 0; + virtual SymbolSizeAttributes::Bindings attributeBindings() const = 0; virtual void populateVertexVector(const GeometryTileFeature& feature) = 0; virtual UniformValues uniformValues(float currentZoom) const = 0; virtual void upload(gl::Context&) = 0; @@ -133,8 +133,6 @@ Range getCoveringStops(Stops s, float lowerZoom, float upperZoom) { class ConstantSymbolSizeBinder final : public SymbolSizeBinder { public: - using PropertyValue = variant>; - ConstantSymbolSizeBinder(const float /*tileZoom*/, const float& size, const float /*defaultValue*/) : layoutSize(size) {} @@ -157,7 +155,7 @@ public: ); } - SymbolSizeAttributes::Bindings attributeBindings(const PossiblyEvaluatedPropertyValue) const override { + SymbolSizeAttributes::Bindings attributeBindings() const override { return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::ConstantBinding {{{0, 0, 0}}} }; } void upload(gl::Context&) override {} @@ -211,11 +209,7 @@ public: defaultValue(defaultValue_) { } - SymbolSizeAttributes::Bindings attributeBindings(const PossiblyEvaluatedPropertyValue currentValue) const override { - if (currentValue.isConstant()) { - return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::ConstantBinding {{{0, 0, 0}}} }; - } - + SymbolSizeAttributes::Bindings attributeBindings() const override { return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::variableBinding(*buffer, 0, 1) }; } @@ -268,11 +262,7 @@ public: return getCoveringStops(stops, tileZoom, tileZoom + 1); })) {} - SymbolSizeAttributes::Bindings attributeBindings(const PossiblyEvaluatedPropertyValue currentValue) const override { - if (currentValue.isConstant()) { - return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::ConstantBinding {{{0, 0, 0}}} }; - } - + SymbolSizeAttributes::Bindings attributeBindings() const override { return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::variableBinding(*buffer, 0) }; } @@ -364,7 +354,6 @@ public: UniformValues&& uniformValues, const gl::VertexBuffer& layoutVertexBuffer, const SymbolSizeBinder& symbolSizeBinder, - const PossiblyEvaluatedPropertyValue& currentSizeValue, const gl::IndexBuffer& indexBuffer, const gl::SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, @@ -380,7 +369,7 @@ public: .concat(symbolSizeBinder.uniformValues(currentZoom)) .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)), LayoutAttributes::allVariableBindings(layoutVertexBuffer) - .concat(symbolSizeBinder.attributeBindings(currentSizeValue)) + .concat(symbolSizeBinder.attributeBindings()) .concat(paintPropertyBinders.attributeBindings(currentProperties)), indexBuffer, segments diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 86b2146b9f..c9ed8cc570 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -54,7 +54,6 @@ void Painter::renderSymbol(PaintParameters& parameters, std::move(uniformValues), *buffers.vertexBuffer, *symbolSizeBinder, - values_.layoutSize, *buffers.indexBuffer, buffers.segments, binders, -- cgit v1.2.1 From 874244a65680c4f99b1b549b979e511f37c1542b Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 13 Jun 2017 16:45:12 -0700 Subject: [core] Eliminate constant attribute bindings Rather than binding constant attributes that will never be used, just disable the attribute. --- src/mbgl/gl/attribute.cpp | 176 ++++------------------------ src/mbgl/gl/attribute.hpp | 89 ++++++-------- src/mbgl/gl/segment.hpp | 6 +- src/mbgl/programs/program.hpp | 2 +- src/mbgl/programs/symbol_program.hpp | 11 +- src/mbgl/renderer/paint_property_binder.hpp | 21 +--- 6 files changed, 76 insertions(+), 229 deletions(-) diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index 8c52121f6e..e05ca75866 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -10,6 +10,10 @@ AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location return location; } +void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) const { + MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); +} + template DataType DataTypeOf = static_cast(0); template <> DataType DataTypeOf< int8_t> = DataType::Byte; template <> DataType DataTypeOf = DataType::UnsignedByte; @@ -20,16 +24,9 @@ template <> DataType DataTypeOf = DataType::UnsignedInteger; template <> DataType DataTypeOf = DataType::Float; template -void VariableAttributeBinding::bind(Context& context, - AttributeLocation location, - optional>& oldBinding, - std::size_t vertexOffset) const { - if (oldBinding == *this) { - return; - } +void AttributeBinding::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const { context.vertexBuffer = vertexBuffer; MBGL_CHECK_ERROR(glEnableVertexAttribArray(location)); - oldBinding = *this; MBGL_CHECK_ERROR(glVertexAttribPointer( location, static_cast(attributeSize), @@ -39,156 +36,25 @@ void VariableAttributeBinding::bind(Context& context, reinterpret_cast(attributeOffset + (vertexSize * vertexOffset)))); } -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; - -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; - -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; - -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; -template class VariableAttributeBinding; - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3])); -} - - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3])); -} - - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0])); -} +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1])); -} +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2])); -} +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3])); -} - - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2])); -} - -template <> -void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3])); -} +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; +template class AttributeBinding; } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index d5e8edfc70..48222146fa 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -13,23 +13,33 @@ namespace mbgl { namespace gl { +class DisabledAttribute { +public: + void bind(Context&, AttributeLocation, std::size_t vertexOffset) const; + + friend bool operator==(const DisabledAttribute&, + const DisabledAttribute&) { + return true; + } +}; + template -class VariableAttributeBinding { +class AttributeBinding { public: - VariableAttributeBinding(BufferID vertexBuffer_, - std::size_t vertexSize_, - std::size_t attributeOffset_, - std::size_t attributeSize_ = N) + AttributeBinding(BufferID vertexBuffer_, + std::size_t vertexSize_, + std::size_t attributeOffset_, + std::size_t attributeSize_ = N) : vertexBuffer(vertexBuffer_), vertexSize(vertexSize_), attributeOffset(attributeOffset_), attributeSize(attributeSize_) {} - void bind(Context&, AttributeLocation, optional>&, std::size_t vertexOffset) const; + void bind(Context&, AttributeLocation, std::size_t vertexOffset) const; - friend bool operator==(const VariableAttributeBinding& lhs, - const VariableAttributeBinding& rhs) { + friend bool operator==(const AttributeBinding& lhs, + const AttributeBinding& rhs) { return lhs.vertexBuffer == rhs.vertexBuffer && lhs.vertexSize == rhs.vertexSize && lhs.attributeOffset == rhs.attributeOffset @@ -43,28 +53,8 @@ private: std::size_t attributeSize; }; -template -class ConstantAttributeBinding { -public: - ConstantAttributeBinding() { value.fill(T()); } - - explicit ConstantAttributeBinding(std::array value_) - : value(std::move(value_)) - {} - - void bind(Context&, AttributeLocation, optional>&, std::size_t) const; - - friend bool operator==(const ConstantAttributeBinding& lhs, - const ConstantAttributeBinding& rhs) { - return lhs.value == rhs.value; - } - -private: - std::array value; -}; - /* - gl::Attribute manages the binding of a constant value or vertex buffer to a GL program attribute. + gl::Attribute manages the binding of a vertex buffer to a GL program attribute. - T is the underlying primitive type (exposed as Attribute::ValueType) - N is the number of components in the attribute declared in the shader (exposed as Attribute::Dimensions) */ @@ -75,27 +65,23 @@ public: static constexpr size_t Dimensions = N; using Value = std::array; - using VariableBinding = VariableAttributeBinding; - using ConstantBinding = ConstantAttributeBinding; - using Location = AttributeLocation; using Binding = variant< - ConstantBinding, - VariableBinding>; + DisabledAttribute, + AttributeBinding>; /* - Create a variable (i.e. data-driven) binding for this attribute. The `attributeSize` - parameter may be used to override the number of components available in the buffer for - each vertex. Thus, a buffer with only one float for each vertex can be bound to a - `vec2` attribute + Create a binding for this attribute. The `attributeSize` parameter may be used to + override the number of components available in the buffer for each vertex. Thus, + a buffer with only one float for each vertex can be bound to a `vec2` attribute */ template - static VariableBinding variableBinding(const VertexBuffer& buffer, - std::size_t attributeIndex, - std::size_t attributeSize = N) { + static Binding binding(const VertexBuffer& buffer, + std::size_t attributeIndex, + std::size_t attributeSize = N) { static_assert(std::is_standard_layout::value, "vertex type must use standard layout"); - return VariableBinding { + return AttributeBinding { buffer.buffer, sizeof(Vertex), Vertex::attributeOffsets[attributeIndex], @@ -105,12 +91,18 @@ public: static void bind(Context& context, const Location& location, - optional& oldBinding, + Binding& oldBinding, const Binding& newBinding, std::size_t vertexOffset) { + if (oldBinding == newBinding) { + return; + } + Binding::visit(newBinding, [&] (const auto& binding) { - binding.bind(context, location, oldBinding, vertexOffset); + binding.bind(context, location, vertexOffset); }); + + oldBinding = newBinding; } }; @@ -242,9 +234,6 @@ public: using Bindings = IndexedTuple< TypeList, TypeList>; - using VariableBindings = IndexedTuple< - TypeList, - TypeList...>>; using NamedLocations = std::vector>; using Vertex = detail::Vertex; @@ -266,13 +255,13 @@ public: } template - static Bindings allVariableBindings(const VertexBuffer& buffer) { - return Bindings { As::Type::variableBinding(buffer, Index)... }; + static Bindings bindings(const VertexBuffer& buffer) { + return Bindings { As::Type::binding(buffer, Index)... }; } static void bind(Context& context, const Locations& locations, - VariableBindings& oldBindings, + Bindings& oldBindings, const Bindings& newBindings, std::size_t vertexOffset) { util::ignore({ (As::Type::bind(context, diff --git a/src/mbgl/gl/segment.hpp b/src/mbgl/gl/segment.hpp index 45c81973f2..fe0658bf8e 100644 --- a/src/mbgl/gl/segment.hpp +++ b/src/mbgl/gl/segment.hpp @@ -47,12 +47,12 @@ public: } else { // No VAO support. Force attributes to be rebound. context.elementBuffer = indexBuffer_; - variableBindings = {}; + attributeBindings = {}; } Attributes::bind(context, attributeLocations, - variableBindings, + attributeBindings, attributeBindings_, vertexOffset); } @@ -60,7 +60,7 @@ public: private: mutable optional vao; mutable optional indexBuffer; - mutable typename Attributes::VariableBindings variableBindings; + mutable typename Attributes::Bindings attributeBindings; }; template diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index bbe4885745..65f17e5bdc 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -66,7 +66,7 @@ public: std::move(colorMode), uniformValues .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)), - LayoutAttributes::allVariableBindings(layoutVertexBuffer) + LayoutAttributes::bindings(layoutVertexBuffer) .concat(paintPropertyBinders.attributeBindings(currentProperties)), indexBuffer, segments diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index abcba1d033..47d92f912c 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -156,8 +156,9 @@ public: } SymbolSizeAttributes::Bindings attributeBindings() const override { - return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::ConstantBinding {{{0, 0, 0}}} }; + return SymbolSizeAttributes::Bindings { gl::DisabledAttribute() }; } + void upload(gl::Context&) override {} void populateVertexVector(const GeometryTileFeature&) override {}; @@ -210,9 +211,9 @@ public: } SymbolSizeAttributes::Bindings attributeBindings() const override { - return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::variableBinding(*buffer, 0, 1) }; + return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::binding(*buffer, 0, 1) }; } - + void populateVertexVector(const GeometryTileFeature& feature) override { const auto sizeVertex = Vertex { {{ @@ -263,7 +264,7 @@ public: {} SymbolSizeAttributes::Bindings attributeBindings() const override { - return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::variableBinding(*buffer, 0) }; + return SymbolSizeAttributes::Bindings { SymbolSizeAttributes::Attribute::binding(*buffer, 0) }; } void populateVertexVector(const GeometryTileFeature& feature) override { @@ -368,7 +369,7 @@ public: uniformValues .concat(symbolSizeBinder.uniformValues(currentZoom)) .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)), - LayoutAttributes::allVariableBindings(layoutVertexBuffer) + LayoutAttributes::bindings(layoutVertexBuffer) .concat(symbolSizeBinder.attributeBindings()) .concat(paintPropertyBinders.attributeBindings(currentProperties)), indexBuffer, diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index bcbc7c287d..906a2ea07b 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -102,11 +102,8 @@ public: void populateVertexVector(const GeometryTileFeature&, std::size_t) override {} void upload(gl::Context&) override {} - AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { - auto value = attributeValue(currentValue.constantOr(constant)); - return typename Attribute::ConstantBinding { - zoomInterpolatedAttributeValue(value, value) - }; + AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue&) const override { + return gl::DisabledAttribute(); } float interpolationFactor(float) const override { @@ -151,12 +148,9 @@ public: AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { - BaseAttributeValue value = attributeValue(*currentValue.constant()); - return typename Attribute::ConstantBinding { - zoomInterpolatedAttributeValue(value, value) - }; + return gl::DisabledAttribute(); } else { - return Attribute::variableBinding(*vertexBuffer, 0, BaseAttribute::Dimensions); + return Attribute::binding(*vertexBuffer, 0, BaseAttribute::Dimensions); } } @@ -215,12 +209,9 @@ public: AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { - BaseAttributeValue value = attributeValue(*currentValue.constant()); - return typename Attribute::ConstantBinding { - zoomInterpolatedAttributeValue(value, value) - }; + return gl::DisabledAttribute(); } else { - return Attribute::variableBinding(*vertexBuffer, 0); + return Attribute::binding(*vertexBuffer, 0); } } -- cgit v1.2.1 From e8272ebdbb6e4788e82e4c4555f8ef8225d4013c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 14 Jun 2017 13:07:32 +0200 Subject: [core] rename a_gap_width => a_gapwidth, u_gap_width => u_gapwidth to reflect naming in the shader not sure how this ever worked --- src/mbgl/programs/attributes.hpp | 2 +- src/mbgl/programs/uniforms.hpp | 2 +- src/mbgl/style/layers/line_layer_properties.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp index cfd6a629de..a0b2b93e16 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -106,7 +106,7 @@ struct a_base { using Type = gl::Attribute; }; -struct a_gap_width { +struct a_gapwidth { static auto name() { return "a_gapwidth"; } using Type = gl::Attribute; }; diff --git a/src/mbgl/programs/uniforms.hpp b/src/mbgl/programs/uniforms.hpp index 60a50a7cb2..32d857a94e 100644 --- a/src/mbgl/programs/uniforms.hpp +++ b/src/mbgl/programs/uniforms.hpp @@ -27,7 +27,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_halo_blur); MBGL_DEFINE_UNIFORM_SCALAR(Color, u_outline_color); MBGL_DEFINE_UNIFORM_SCALAR(float, u_height); MBGL_DEFINE_UNIFORM_SCALAR(float, u_base); -MBGL_DEFINE_UNIFORM_SCALAR(float, u_gap_width); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_gapwidth); MBGL_DEFINE_UNIFORM_SCALAR(float, u_offset); MBGL_DEFINE_UNIFORM_SCALAR(Size, u_world); diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index 0b234921ad..6c301e6a0e 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -51,7 +51,7 @@ struct LineWidth : PaintProperty { static float defaultValue() { return 1; } }; -struct LineGapWidth : DataDrivenPaintProperty { +struct LineGapWidth : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -- cgit v1.2.1 From eed89fcf9d099266aa793375ad63493e880f8a80 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Thu, 29 Jun 2017 11:29:48 -0700 Subject: [core] Bind only active attributes in order to avoid exceeding attribute limits (#9373) Introducing two new attributes to enable property functions for line-width (#9250) pushed the attribute count over GL_MAX_VERTEX_ATTRIBS on some devices. Now we selectively bind only attributes that are used, making it unlikely to surpass GL_MAX_VERTEX_ATTRIBS. --- src/mbgl/gl/attribute.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/mbgl/gl/attribute.hpp | 12 +++++++++++- src/mbgl/gl/program.hpp | 12 +++++++----- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index e05ca75866..4e6f78e689 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -2,14 +2,55 @@ #include #include +#include + namespace mbgl { namespace gl { AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { + assert(location < 8); MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); return location; } +int32_t getActiveAttributeCount(ProgramID id) { + GLint numAttributes; + MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &numAttributes)); + return numAttributes; +} + +int32_t getMaxAttributeNameLength(ProgramID id) { + GLint nameLength; + MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &nameLength)); + return nameLength; +} + +std::string getAttributeName(ProgramID id, int32_t maxLength, AttributeLocation location) { + std::string attributeName; + attributeName.resize(maxLength); + GLsizei actualLength; + GLint size; + GLenum type; + MBGL_CHECK_ERROR(glGetActiveAttrib(id, static_cast(location), + static_cast(maxLength), &actualLength, &size, &type, + const_cast(attributeName.data()))); + attributeName.resize(actualLength); + return attributeName; +} + +std::set getActiveAttributes(ProgramID id) { + std::set activeAttributes; + + GLint attributeCount = getActiveAttributeCount(id); + GLint maxAttributeLength = getMaxAttributeNameLength(id); + + for (int32_t i = 0; i < attributeCount; i++) { + activeAttributes.emplace(getAttributeName(id, maxAttributeLength, i)); + } + + return activeAttributes; +} + void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) const { MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); } @@ -25,6 +66,11 @@ template <> DataType DataTypeOf = DataType::Float; template void AttributeBinding::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const { + // FillProgram will attempt to bind at location -1 because it includes + // a fill-outline-color paint property but does not use it or have an + // a_outline_color shader attribute - in this case, we have nothing to bind. + if (location == -1) return; + context.vertexBuffer = vertexBuffer; MBGL_CHECK_ERROR(glEnableVertexAttribArray(location)); MBGL_CHECK_ERROR(glVertexAttribPointer( diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index 48222146fa..f018a1d261 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -8,6 +8,7 @@ #include #include +#include #include namespace mbgl { @@ -223,6 +224,7 @@ const std::size_t Vertex::attributeOffsets[5] = { } // namespace detail AttributeLocation bindAttributeLocation(ProgramID, AttributeLocation, const char * name); +std::set getActiveAttributes(ProgramID); template class Attributes { @@ -242,7 +244,15 @@ public: static constexpr std::size_t Index = TypeIndex::value; static Locations bindLocations(const ProgramID& id) { - return Locations { bindAttributeLocation(id, Index, As::name())... }; + std::set activeAttributes = getActiveAttributes(id); + + AttributeLocation location = -1; + auto bindAndIncrement = [&](const char* name) { + location++; + return bindAttributeLocation(id, location, name); + }; + return Locations{ (activeAttributes.count(As::name()) ? bindAndIncrement(As::name()) + : -1)... }; } template diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 47ad39de7c..583d53e4ec 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -33,15 +33,17 @@ public: : program( context.createProgram(context.createShader(ShaderType::Vertex, vertexSource), context.createShader(ShaderType::Fragment, fragmentSource))), - attributeLocations(Attributes::bindLocations(program)), - uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))) { + uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))), + attributeLocations(Attributes::bindLocations(program)) { + // Re-link program after manually binding only active attributes in Attributes::bindLocations + context.linkProgram(program); } template Program(Context& context, const BinaryProgram& binaryProgram) : program(context.createProgram(binaryProgram.format(), binaryProgram.code())), - attributeLocations(Attributes::loadNamedLocations(binaryProgram)), - uniformsState(Uniforms::loadNamedLocations(binaryProgram)) { + uniformsState(Uniforms::loadNamedLocations(binaryProgram)), + attributeLocations(Attributes::loadNamedLocations(binaryProgram)) { } static Program createProgram(gl::Context& context, @@ -144,8 +146,8 @@ public: private: UniqueProgram program; - typename Attributes::Locations attributeLocations; typename Uniforms::State uniformsState; + typename Attributes::Locations attributeLocations; }; } // namespace gl -- cgit v1.2.1 From f9fe0de806a29cae4e7a2071940949ebffaf3140 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 6 Jul 2017 13:45:52 -0700 Subject: [core] Include what you use --- src/mbgl/gl/program.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 583d53e4ec..ce2b5a335b 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -9,11 +9,11 @@ #include #include +#include #include #include #include - #include namespace mbgl { -- cgit v1.2.1 From fbd437689901d725ce5e8df056abab3dc6c104ec Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 3 Jul 2017 14:05:12 -0700 Subject: [core] Inline getActiveAttributes details --- src/mbgl/gl/attribute.cpp | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index 4e6f78e689..2f817cdcd8 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -13,39 +13,25 @@ AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location return location; } -int32_t getActiveAttributeCount(ProgramID id) { - GLint numAttributes; - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &numAttributes)); - return numAttributes; -} +std::set getActiveAttributes(ProgramID id) { + std::set activeAttributes; -int32_t getMaxAttributeNameLength(ProgramID id) { - GLint nameLength; - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &nameLength)); - return nameLength; -} + GLint attributeCount; + MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount)); + + GLint maxAttributeLength; + MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength)); -std::string getAttributeName(ProgramID id, int32_t maxLength, AttributeLocation location) { std::string attributeName; - attributeName.resize(maxLength); + attributeName.resize(maxAttributeLength); + GLsizei actualLength; GLint size; GLenum type; - MBGL_CHECK_ERROR(glGetActiveAttrib(id, static_cast(location), - static_cast(maxLength), &actualLength, &size, &type, - const_cast(attributeName.data()))); - attributeName.resize(actualLength); - return attributeName; -} - -std::set getActiveAttributes(ProgramID id) { - std::set activeAttributes; - - GLint attributeCount = getActiveAttributeCount(id); - GLint maxAttributeLength = getMaxAttributeNameLength(id); for (int32_t i = 0; i < attributeCount; i++) { - activeAttributes.emplace(getAttributeName(id, maxAttributeLength, i)); + MBGL_CHECK_ERROR(glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0])); + activeAttributes.emplace(std::string(attributeName, 0, actualLength)); } return activeAttributes; -- cgit v1.2.1 From d7bdc7a60d330094dd8af8431e0b1d6f588d9f07 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 3 Jul 2017 14:05:12 -0700 Subject: [core] Rework attribute binding (again) These changes are necessary for programs whose set of active attributes is not fixed at compile time by a template parameter pack, but rather varies based on the generated shader text at runtime. In such cases, the attribute location of a given named attribute may vary between instances of the same Program. Previously, attribute bindings were implicitly associated with a location based on template parameter order, and -1 was used to indicate an inactive attribute. This left us unable to disable the appropriate attribute when it went from active to inactive. Now, the state tracker for bindings explicitly associates locations and state, and an empty optional is used to indicate an inactive attribute. In addition, a gl::VertexArray class is now exposed, allowing more flexibility in the relationship between Programs, Segments, and attribute bindings. In this commit, that relationship does not change, but the subsequent commit adjusts it to match gl-js, reduce rebinds, and work around buggy VAO implementations. VertexArray uses a pimpl idiom in order to support implementations that lack the VAO extension. In that case, all VertexArrays share global binding state, reflecting the platform reality in the absence of VAOs, while still providing a uniform API. --- cmake/core-files.cmake | 6 +- src/mbgl/gl/attribute.cpp | 61 +---------- src/mbgl/gl/attribute.hpp | 150 +++++++++++++++------------- src/mbgl/gl/context.cpp | 31 +++--- src/mbgl/gl/context.hpp | 12 ++- src/mbgl/gl/object.cpp | 4 +- src/mbgl/gl/program.hpp | 26 ++--- src/mbgl/gl/segment.cpp | 7 -- src/mbgl/gl/segment.hpp | 73 -------------- src/mbgl/gl/types.hpp | 2 +- src/mbgl/gl/uniform.hpp | 2 +- src/mbgl/gl/value.cpp | 18 ++++ src/mbgl/gl/value.hpp | 7 ++ src/mbgl/gl/vertex_array.cpp | 18 ++++ src/mbgl/gl/vertex_array.hpp | 58 +++++++++++ src/mbgl/programs/binary_program.cpp | 4 +- src/mbgl/programs/binary_program.hpp | 4 +- src/mbgl/programs/program.hpp | 42 +++++--- src/mbgl/programs/segment.cpp | 7 ++ src/mbgl/programs/segment.hpp | 40 ++++++++ src/mbgl/programs/symbol_program.hpp | 48 +++++---- src/mbgl/renderer/circle_bucket.hpp | 4 +- src/mbgl/renderer/debug_bucket.hpp | 2 +- src/mbgl/renderer/fill_bucket.hpp | 6 +- src/mbgl/renderer/fill_extrusion_bucket.hpp | 4 +- src/mbgl/renderer/line_bucket.hpp | 4 +- src/mbgl/renderer/paint_property_binder.hpp | 15 +-- src/mbgl/renderer/painter.cpp | 4 +- src/mbgl/renderer/painter.hpp | 8 +- src/mbgl/renderer/symbol_bucket.hpp | 8 +- test/programs/binary_program.test.cpp | 16 +-- 31 files changed, 375 insertions(+), 316 deletions(-) delete mode 100644 src/mbgl/gl/segment.cpp delete mode 100644 src/mbgl/gl/segment.hpp create mode 100644 src/mbgl/gl/vertex_array.cpp create mode 100644 src/mbgl/gl/vertex_array.hpp create mode 100644 src/mbgl/programs/segment.cpp create mode 100644 src/mbgl/programs/segment.hpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 069b6cb4c9..8a3c42a1f4 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -76,8 +76,6 @@ set(MBGL_CORE_FILES src/mbgl/gl/program.hpp src/mbgl/gl/program_binary_extension.hpp src/mbgl/gl/renderbuffer.hpp - src/mbgl/gl/segment.cpp - src/mbgl/gl/segment.hpp src/mbgl/gl/state.hpp src/mbgl/gl/stencil_mode.cpp src/mbgl/gl/stencil_mode.hpp @@ -87,6 +85,8 @@ set(MBGL_CORE_FILES src/mbgl/gl/uniform.hpp src/mbgl/gl/value.cpp src/mbgl/gl/value.hpp + src/mbgl/gl/vertex_array.cpp + src/mbgl/gl/vertex_array.hpp src/mbgl/gl/vertex_array_extension.hpp src/mbgl/gl/vertex_buffer.hpp @@ -155,6 +155,8 @@ set(MBGL_CORE_FILES src/mbgl/programs/programs.hpp src/mbgl/programs/raster_program.cpp src/mbgl/programs/raster_program.hpp + src/mbgl/programs/segment.cpp + src/mbgl/programs/segment.hpp src/mbgl/programs/symbol_program.cpp src/mbgl/programs/symbol_program.hpp src/mbgl/programs/uniforms.hpp diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index 2f817cdcd8..bb5b2ddc34 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -1,16 +1,14 @@ #include -#include #include -#include - namespace mbgl { namespace gl { -AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { - assert(location < 8); +void bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { + if (location >= MAX_ATTRIBUTES) { + throw gl::Error("too many vertex attributes"); + } MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); - return location; } std::set getActiveAttributes(ProgramID id) { @@ -37,56 +35,5 @@ std::set getActiveAttributes(ProgramID id) { return activeAttributes; } -void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) const { - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); -} - -template DataType DataTypeOf = static_cast(0); -template <> DataType DataTypeOf< int8_t> = DataType::Byte; -template <> DataType DataTypeOf = DataType::UnsignedByte; -template <> DataType DataTypeOf< int16_t> = DataType::Short; -template <> DataType DataTypeOf = DataType::UnsignedShort; -template <> DataType DataTypeOf< int32_t> = DataType::Integer; -template <> DataType DataTypeOf = DataType::UnsignedInteger; -template <> DataType DataTypeOf = DataType::Float; - -template -void AttributeBinding::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const { - // FillProgram will attempt to bind at location -1 because it includes - // a fill-outline-color paint property but does not use it or have an - // a_outline_color shader attribute - in this case, we have nothing to bind. - if (location == -1) return; - - context.vertexBuffer = vertexBuffer; - MBGL_CHECK_ERROR(glEnableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttribPointer( - location, - static_cast(attributeSize), - static_cast(DataTypeOf), - static_cast(false), - static_cast(vertexSize), - reinterpret_cast(attributeOffset + (vertexSize * vertexOffset)))); -} - -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; - -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; - -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; - -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; -template class AttributeBinding; - } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index f018a1d261..ed4168c21f 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -1,59 +1,51 @@ #pragma once #include -#include +#include #include #include -#include +#include #include #include #include #include +#include +#include namespace mbgl { namespace gl { -class DisabledAttribute { -public: - void bind(Context&, AttributeLocation, std::size_t vertexOffset) const; +static constexpr std::size_t MAX_ATTRIBUTES = 8; - friend bool operator==(const DisabledAttribute&, - const DisabledAttribute&) { - return true; - } -}; +template struct DataTypeOf; +template <> struct DataTypeOf< int8_t> : std::integral_constant {}; +template <> struct DataTypeOf : std::integral_constant {}; +template <> struct DataTypeOf< int16_t> : std::integral_constant {}; +template <> struct DataTypeOf : std::integral_constant {}; +template <> struct DataTypeOf< int32_t> : std::integral_constant {}; +template <> struct DataTypeOf : std::integral_constant {}; +template <> struct DataTypeOf : std::integral_constant {}; -template class AttributeBinding { public: - AttributeBinding(BufferID vertexBuffer_, - std::size_t vertexSize_, - std::size_t attributeOffset_, - std::size_t attributeSize_ = N) - : vertexBuffer(vertexBuffer_), - vertexSize(vertexSize_), - attributeOffset(attributeOffset_), - attributeSize(attributeSize_) - {} - - void bind(Context&, AttributeLocation, std::size_t vertexOffset) const; + DataType attributeType; + std::size_t attributeSize; + std::size_t attributeOffset; + + BufferID vertexBuffer; + std::size_t vertexSize; + std::size_t vertexOffset; friend bool operator==(const AttributeBinding& lhs, const AttributeBinding& rhs) { - return lhs.vertexBuffer == rhs.vertexBuffer - && lhs.vertexSize == rhs.vertexSize - && lhs.attributeOffset == rhs.attributeOffset - && lhs.attributeSize == rhs.attributeSize; + return std::tie(lhs.attributeType, lhs.attributeSize, lhs.attributeOffset, lhs.vertexBuffer, lhs.vertexSize, lhs.vertexOffset) + == std::tie(rhs.attributeType, rhs.attributeSize, rhs.attributeOffset, rhs.vertexBuffer, rhs.vertexSize, rhs.vertexOffset); } - -private: - BufferID vertexBuffer; - std::size_t vertexSize; - std::size_t attributeOffset; - std::size_t attributeSize; }; +using AttributeBindingArray = std::array, MAX_ATTRIBUTES>; + /* gl::Attribute manages the binding of a vertex buffer to a GL program attribute. - T is the underlying primitive type (exposed as Attribute::ValueType) @@ -67,10 +59,7 @@ public: using Value = std::array; using Location = AttributeLocation; - - using Binding = variant< - DisabledAttribute, - AttributeBinding>; + using Binding = AttributeBinding; /* Create a binding for this attribute. The `attributeSize` parameter may be used to @@ -82,28 +71,24 @@ public: std::size_t attributeIndex, std::size_t attributeSize = N) { static_assert(std::is_standard_layout::value, "vertex type must use standard layout"); - return AttributeBinding { + return AttributeBinding { + DataTypeOf::value, + attributeSize, + Vertex::attributeOffsets[attributeIndex], buffer.buffer, sizeof(Vertex), - Vertex::attributeOffsets[attributeIndex], - attributeSize + 0, }; } - static void bind(Context& context, - const Location& location, - Binding& oldBinding, - const Binding& newBinding, - std::size_t vertexOffset) { - if (oldBinding == newBinding) { - return; + static optional offsetBinding(const optional& binding, std::size_t vertexOffset) { + if (binding) { + AttributeBinding result = *binding; + result.vertexOffset = vertexOffset; + return result; + } else { + return binding; } - - Binding::visit(newBinding, [&] (const auto& binding) { - binding.bind(context, location, vertexOffset); - }); - - oldBinding = newBinding; } }; @@ -223,7 +208,7 @@ const std::size_t Vertex::attributeOffsets[5] = { } // namespace detail -AttributeLocation bindAttributeLocation(ProgramID, AttributeLocation, const char * name); +void bindAttributeLocation(ProgramID, AttributeLocation, const char * name); std::set getActiveAttributes(ProgramID); template @@ -232,10 +217,10 @@ public: using Types = TypeList; using Locations = IndexedTuple< TypeList, - TypeList>; + TypeList...>>; using Bindings = IndexedTuple< TypeList, - TypeList>; + TypeList...>>; using NamedLocations = std::vector>; using Vertex = detail::Vertex; @@ -246,13 +231,17 @@ public: static Locations bindLocations(const ProgramID& id) { std::set activeAttributes = getActiveAttributes(id); - AttributeLocation location = -1; - auto bindAndIncrement = [&](const char* name) { - location++; - return bindAttributeLocation(id, location, name); + AttributeLocation location = 0; + auto maybeBindLocation = [&](const char* name) -> optional { + if (activeAttributes.count(name)) { + bindAttributeLocation(id, location, name); + return location++; + } else { + return {}; + } }; - return Locations{ (activeAttributes.count(As::name()) ? bindAndIncrement(As::name()) - : -1)... }; + + return Locations { maybeBindLocation(As::name())... }; } template @@ -261,7 +250,17 @@ public: } static NamedLocations getNamedLocations(const Locations& locations) { - return NamedLocations{ { As::name(), locations.template get() }... }; + NamedLocations result; + + auto maybeAddLocation = [&] (const std::string& name, const optional& location) { + if (location) { + result.emplace_back(name, *location); + } + }; + + util::ignore({ (maybeAddLocation(As::name(), locations.template get()), 0)... }); + + return result; } template @@ -269,16 +268,23 @@ public: return Bindings { As::Type::binding(buffer, Index)... }; } - static void bind(Context& context, - const Locations& locations, - Bindings& oldBindings, - const Bindings& newBindings, - std::size_t vertexOffset) { - util::ignore({ (As::Type::bind(context, - locations.template get(), - oldBindings.template get(), - newBindings.template get(), - vertexOffset), 0)... }); + static Bindings offsetBindings(const Bindings& bindings, std::size_t vertexOffset) { + return Bindings { As::Type::offsetBinding(bindings.template get(), vertexOffset)... }; + } + + static AttributeBindingArray toBindingArray(const Locations& locations, const Bindings& bindings) { + AttributeBindingArray result; + + auto maybeAddBinding = [&] (const optional& location, + const optional& binding) { + if (location) { + result.at(*location) = binding; + } + }; + + util::ignore({ (maybeAddBinding(locations.template get(), bindings.template get()), 0)... }); + + return result; } }; diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 3ab1260d27..2d7354a64e 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -177,8 +177,8 @@ UniqueBuffer Context::createIndexBuffer(const void* data, std::size_t size) { BufferID id = 0; MBGL_CHECK_ERROR(glGenBuffers(1, &id)); UniqueBuffer result { std::move(id), { this } }; - vertexArrayObject = 0; - elementBuffer = result; + bindVertexArray = 0; + globalVertexArrayState.indexBuffer = result; MBGL_CHECK_ERROR(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW)); return result; } @@ -229,11 +229,16 @@ optional> Context::getBinaryProgram( } #endif -UniqueVertexArray Context::createVertexArray() { - assert(supportsVertexArrays()); - VertexArrayID id = 0; - MBGL_CHECK_ERROR(vertexArray->genVertexArrays(1, &id)); - return UniqueVertexArray(std::move(id), { this }); +VertexArray Context::createVertexArray() { + if (supportsVertexArrays()) { + VertexArrayID id = 0; + MBGL_CHECK_ERROR(vertexArray->genVertexArrays(1, &id)); + return { std::make_unique(UniqueVertexArray(std::move(id), { this }), *this) }; + } else { + // On GL implementations which do not support vertex arrays, attribute bindings are global state. + // So return a VertexArray which shares our global state tracking and whose deleter is a no-op. + return { UniqueVertexArrayState(&globalVertexArrayState, [] (VertexArrayState*) {}) }; + } } UniqueFramebuffer Context::createFramebuffer() { @@ -502,8 +507,8 @@ void Context::setDirtyState() { tex.setDirty(); } vertexBuffer.setDirty(); - elementBuffer.setDirty(); - vertexArrayObject.setDirty(); + bindVertexArray.setDirty(); + globalVertexArrayState.setDirty(); } void Context::clear(optional color, @@ -622,8 +627,8 @@ void Context::performCleanup() { for (const auto id : abandonedBuffers) { if (vertexBuffer == id) { vertexBuffer.setDirty(); - } else if (elementBuffer == id) { - elementBuffer.setDirty(); + } else if (globalVertexArrayState.indexBuffer == id) { + globalVertexArrayState.indexBuffer.setDirty(); } } MBGL_CHECK_ERROR(glDeleteBuffers(int(abandonedBuffers.size()), abandonedBuffers.data())); @@ -643,8 +648,8 @@ void Context::performCleanup() { if (!abandonedVertexArrays.empty()) { assert(supportsVertexArrays()); for (const auto id : abandonedVertexArrays) { - if (vertexArrayObject == id) { - vertexArrayObject.setDirty(); + if (bindVertexArray == id) { + bindVertexArray.setDirty(); } } MBGL_CHECK_ERROR(vertexArray->deleteVertexArrays(int(abandonedVertexArrays.size()), diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 56c0618989..8929d24e54 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -53,9 +54,7 @@ public: void verifyProgramLinkage(ProgramID); void linkProgram(ProgramID); UniqueTexture createTexture(); - - bool supportsVertexArrays() const; - UniqueVertexArray createVertexArray(); + VertexArray createVertexArray(); #if MBGL_HAS_BINARY_PROGRAMS bool supportsProgramBinaries() const; @@ -200,10 +199,11 @@ public: State bindFramebuffer; State viewport; std::array, 2> texture; - State vertexArrayObject { *this }; State program; State vertexBuffer; - State elementBuffer; + + State bindVertexArray { *this }; + VertexArrayState globalVertexArrayState { UniqueVertexArray(0, { this }), *this }; #if not MBGL_USE_GLES2 State pixelZoom; @@ -248,6 +248,8 @@ private: void drawPixels(Size size, const void* data, TextureFormat); #endif // MBGL_USE_GLES2 + bool supportsVertexArrays() const; + friend detail::ProgramDeleter; friend detail::ShaderDeleter; friend detail::BufferDeleter; diff --git a/src/mbgl/gl/object.cpp b/src/mbgl/gl/object.cpp index e2d476e0c0..2c5f1bca1f 100644 --- a/src/mbgl/gl/object.cpp +++ b/src/mbgl/gl/object.cpp @@ -33,7 +33,9 @@ void TextureDeleter::operator()(TextureID id) const { void VertexArrayDeleter::operator()(VertexArrayID id) const { assert(context); - context->abandonedVertexArrays.push_back(id); + if (id != 0) { + context->abandonedVertexArrays.push_back(id); + } } void FramebufferDeleter::operator()(FramebufferID id) const { diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index ce2b5a335b..9d8b0a5b04 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -116,10 +117,12 @@ public: DepthMode depthMode, StencilMode stencilMode, ColorMode colorMode, - UniformValues&& uniformValues, - AttributeBindings&& attributeBindings, + const UniformValues& uniformValues, + VertexArray& vertexArray, + const AttributeBindings& attributeBindings, const IndexBuffer& indexBuffer, - const SegmentVector& segments) { + std::size_t indexOffset, + std::size_t indexLength) { static_assert(std::is_same::value, "incompatible draw mode"); context.setDrawMode(drawMode); @@ -129,18 +132,15 @@ public: context.program = program; - Uniforms::bind(uniformsState, std::move(uniformValues)); + Uniforms::bind(uniformsState, uniformValues); - for (const auto& segment : segments) { - segment.bind(context, - indexBuffer.buffer, - attributeLocations, - attributeBindings); + vertexArray.bind(context, + indexBuffer.buffer, + Attributes::toBindingArray(attributeLocations, attributeBindings)); - context.draw(drawMode.primitiveType, - segment.indexOffset, - segment.indexLength); - } + context.draw(drawMode.primitiveType, + indexOffset, + indexLength); } private: diff --git a/src/mbgl/gl/segment.cpp b/src/mbgl/gl/segment.cpp deleted file mode 100644 index aabdc83cd4..0000000000 --- a/src/mbgl/gl/segment.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -namespace mbgl { -namespace gl { - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/segment.hpp b/src/mbgl/gl/segment.hpp deleted file mode 100644 index fe0658bf8e..0000000000 --- a/src/mbgl/gl/segment.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace mbgl { -namespace gl { - -template -class Segment { -public: - Segment(std::size_t vertexOffset_, - std::size_t indexOffset_, - std::size_t vertexLength_ = 0, - std::size_t indexLength_ = 0) - : vertexOffset(vertexOffset_), - indexOffset(indexOffset_), - vertexLength(vertexLength_), - indexLength(indexLength_) {} - - const std::size_t vertexOffset; - const std::size_t indexOffset; - - std::size_t vertexLength; - std::size_t indexLength; - - void bind(Context& context, - BufferID indexBuffer_, - const typename Attributes::Locations& attributeLocations, - const typename Attributes::Bindings& attributeBindings_) const { - if (context.supportsVertexArrays()) { - if (!vao) { - vao = context.createVertexArray(); - context.vertexBuffer.setDirty(); - } - context.vertexArrayObject = *vao; - if (indexBuffer != indexBuffer_) { - indexBuffer = indexBuffer_; - context.elementBuffer.setDirty(); - context.elementBuffer = indexBuffer_; - } - } else { - // No VAO support. Force attributes to be rebound. - context.elementBuffer = indexBuffer_; - attributeBindings = {}; - } - - Attributes::bind(context, - attributeLocations, - attributeBindings, - attributeBindings_, - vertexOffset); - } - -private: - mutable optional vao; - mutable optional indexBuffer; - mutable typename Attributes::Bindings attributeBindings; -}; - -template -class SegmentVector : public std::vector> { -public: - SegmentVector() = default; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp index 0595419674..c80399016e 100644 --- a/src/mbgl/gl/types.hpp +++ b/src/mbgl/gl/types.hpp @@ -15,7 +15,7 @@ using VertexArrayID = uint32_t; using FramebufferID = uint32_t; using RenderbufferID = uint32_t; -using AttributeLocation = int32_t; +using AttributeLocation = uint32_t; using UniformLocation = int32_t; using TextureUnit = uint8_t; diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp index bb3453b2d8..3cac09c526 100644 --- a/src/mbgl/gl/uniform.hpp +++ b/src/mbgl/gl/uniform.hpp @@ -82,7 +82,7 @@ public: return NamedLocations{ { Us::name(), state.template get().location }... }; } - static void bind(State& state, Values&& values) { + static void bind(State& state, const Values& values) { util::ignore({ (state.template get() = values.template get(), 0)... }); } }; diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index c081c941f5..10818e8499 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -353,6 +353,24 @@ BindVertexArray::Type BindVertexArray::Get(const Context& context) { return binding; } +const optional VertexAttribute::Default {}; + +void VertexAttribute::Set(const optional& binding, Context& context, AttributeLocation location) { + if (binding) { + context.vertexBuffer = binding->vertexBuffer; + MBGL_CHECK_ERROR(glEnableVertexAttribArray(location)); + MBGL_CHECK_ERROR(glVertexAttribPointer( + location, + static_cast(binding->attributeSize), + static_cast(binding->attributeType), + static_cast(false), + static_cast(binding->vertexSize), + reinterpret_cast(binding->attributeOffset + (binding->vertexSize * binding->vertexOffset)))); + } else { + MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); + } +} + #if not MBGL_USE_GLES2 const constexpr PointSize::Type PointSize::Default; diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index aa5cca6fec..62fe88a2f4 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -232,6 +233,12 @@ struct BindVertexArray { static Type Get(const Context&); }; +struct VertexAttribute { + using Type = optional; + static const Type Default; + static void Set(const Type&, Context&, AttributeLocation); +}; + #if not MBGL_USE_GLES2 struct PointSize { diff --git a/src/mbgl/gl/vertex_array.cpp b/src/mbgl/gl/vertex_array.cpp new file mode 100644 index 0000000000..68a500ac45 --- /dev/null +++ b/src/mbgl/gl/vertex_array.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +namespace mbgl { +namespace gl { + +void VertexArray::bind(Context& context, BufferID indexBuffer, const AttributeBindingArray& bindings) { + context.bindVertexArray = state->vertexArray; + state->indexBuffer = indexBuffer; + + for (AttributeLocation location = 0; location < MAX_ATTRIBUTES; ++location) { + state->bindings[location] = bindings[location]; + } +} + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/vertex_array.hpp b/src/mbgl/gl/vertex_array.hpp new file mode 100644 index 0000000000..9ccf48d9bd --- /dev/null +++ b/src/mbgl/gl/vertex_array.hpp @@ -0,0 +1,58 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +namespace mbgl { +namespace gl { + +class Context; + +class VertexArrayState { +public: + VertexArrayState(UniqueVertexArray vertexArray_, Context& context) + : vertexArray(std::move(vertexArray_)), + bindings(makeBindings(context, std::make_index_sequence())) { + } + + void setDirty() { + indexBuffer.setDirty(); + for (auto& binding : bindings) { + binding.setDirty(); + } + } + + UniqueVertexArray vertexArray; + State indexBuffer; + + using AttributeState = State; + std::array bindings; + +private: + template + std::array makeBindings(Context& context, std::index_sequence) { + return {{ AttributeState { context, I }... }}; + } +}; + +using UniqueVertexArrayState = std::unique_ptr>; + +class VertexArray { +public: + VertexArray(UniqueVertexArrayState state_) + : state(std::move(state_)) { + } + + void bind(Context&, BufferID indexBuffer, const AttributeBindingArray&); + +private: + UniqueVertexArrayState state; +}; + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/programs/binary_program.cpp b/src/mbgl/programs/binary_program.cpp index 3b37cfa442..1cad0a2693 100644 --- a/src/mbgl/programs/binary_program.cpp +++ b/src/mbgl/programs/binary_program.cpp @@ -96,7 +96,7 @@ std::string BinaryProgram::serialize() const { return data; } -gl::AttributeLocation BinaryProgram::attributeLocation(const std::string& name) const { +optional BinaryProgram::attributeLocation(const std::string& name) const { for (const auto& pair : attributes) { if (pair.first == name) { return pair.second; @@ -111,7 +111,7 @@ gl::UniformLocation BinaryProgram::uniformLocation(const std::string& name) cons return pair.second; } } - return {}; + return -1; } } // namespace mbgl diff --git a/src/mbgl/programs/binary_program.hpp b/src/mbgl/programs/binary_program.hpp index 8ff3863dc1..2806f4fb3e 100644 --- a/src/mbgl/programs/binary_program.hpp +++ b/src/mbgl/programs/binary_program.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -29,7 +30,8 @@ public: const std::string& identifier() const { return binaryIdentifier; } - gl::AttributeLocation attributeLocation(const std::string& name) const; + + optional attributeLocation(const std::string& name) const; gl::UniformLocation uniformLocation(const std::string& name) const; private: diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 65f17e5bdc..3ff6e59c6b 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -51,26 +52,37 @@ public: gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, - UniformValues&& uniformValues, + const UniformValues& uniformValues, const gl::VertexBuffer& layoutVertexBuffer, const gl::IndexBuffer& indexBuffer, - const gl::SegmentVector& segments, + const SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::Evaluated& currentProperties, float currentZoom) { - program.draw( - context, - std::move(drawMode), - std::move(depthMode), - std::move(stencilMode), - std::move(colorMode), - uniformValues - .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)), - LayoutAttributes::bindings(layoutVertexBuffer) - .concat(paintPropertyBinders.attributeBindings(currentProperties)), - indexBuffer, - segments - ); + typename AllUniforms::Values allUniformValues = uniformValues + .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); + + typename Attributes::Bindings allAttributeBindings = LayoutAttributes::bindings(layoutVertexBuffer) + .concat(paintPropertyBinders.attributeBindings(currentProperties)); + + for (auto& segment : segments) { + if (!segment.vertexArray) { + segment.vertexArray = context.createVertexArray(); + } + + program.draw( + context, + std::move(drawMode), + std::move(depthMode), + std::move(stencilMode), + std::move(colorMode), + allUniformValues, + *segment.vertexArray, + Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), + indexBuffer, + segment.indexOffset, + segment.indexLength); + } } }; diff --git a/src/mbgl/programs/segment.cpp b/src/mbgl/programs/segment.cpp new file mode 100644 index 0000000000..bb09843e21 --- /dev/null +++ b/src/mbgl/programs/segment.cpp @@ -0,0 +1,7 @@ +#include + +namespace mbgl { +namespace gl { + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/programs/segment.hpp b/src/mbgl/programs/segment.hpp new file mode 100644 index 0000000000..d8cc9679d7 --- /dev/null +++ b/src/mbgl/programs/segment.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +namespace mbgl { + +template +class Segment { +public: + Segment(std::size_t vertexOffset_, + std::size_t indexOffset_, + std::size_t vertexLength_ = 0, + std::size_t indexLength_ = 0) + : vertexOffset(vertexOffset_), + indexOffset(indexOffset_), + vertexLength(vertexLength_), + indexLength(indexLength_) {} + + const std::size_t vertexOffset; + const std::size_t indexOffset; + + std::size_t vertexLength; + std::size_t indexLength; + + mutable optional vertexArray; +}; + +template +class SegmentVector : public std::vector> { +public: + SegmentVector() = default; +}; + +} // namespace mbgl diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 47d92f912c..2fddebde09 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -156,7 +157,7 @@ public: } SymbolSizeAttributes::Bindings attributeBindings() const override { - return SymbolSizeAttributes::Bindings { gl::DisabledAttribute() }; + return SymbolSizeAttributes::Bindings { {} }; } void upload(gl::Context&) override {} @@ -352,29 +353,40 @@ public: gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, - UniformValues&& uniformValues, + const UniformValues& uniformValues, const gl::VertexBuffer& layoutVertexBuffer, const SymbolSizeBinder& symbolSizeBinder, const gl::IndexBuffer& indexBuffer, - const gl::SegmentVector& segments, + const SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::Evaluated& currentProperties, float currentZoom) { - program.draw( - context, - std::move(drawMode), - std::move(depthMode), - std::move(stencilMode), - std::move(colorMode), - uniformValues - .concat(symbolSizeBinder.uniformValues(currentZoom)) - .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)), - LayoutAttributes::bindings(layoutVertexBuffer) - .concat(symbolSizeBinder.attributeBindings()) - .concat(paintPropertyBinders.attributeBindings(currentProperties)), - indexBuffer, - segments - ); + typename AllUniforms::Values allUniformValues = uniformValues + .concat(symbolSizeBinder.uniformValues(currentZoom)) + .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); + + typename Attributes::Bindings allAttributeBindings = LayoutAttributes::bindings(layoutVertexBuffer) + .concat(symbolSizeBinder.attributeBindings()) + .concat(paintPropertyBinders.attributeBindings(currentProperties)); + + for (auto& segment : segments) { + if (!segment.vertexArray) { + segment.vertexArray = context.createVertexArray(); + } + + program.draw( + context, + std::move(drawMode), + std::move(depthMode), + std::move(stencilMode), + std::move(colorMode), + allUniformValues, + *segment.vertexArray, + Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), + indexBuffer, + segment.indexOffset, + segment.indexLength); + } } }; diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp index b048fd7675..0f27e2a7e3 100644 --- a/src/mbgl/renderer/circle_bucket.hpp +++ b/src/mbgl/renderer/circle_bucket.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -29,7 +29,7 @@ public: gl::VertexVector vertices; gl::IndexVector triangles; - gl::SegmentVector segments; + SegmentVector segments; optional> vertexBuffer; optional> indexBuffer; diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp index 756e58a6de..fc3128e944 100644 --- a/src/mbgl/renderer/debug_bucket.hpp +++ b/src/mbgl/renderer/debug_bucket.hpp @@ -33,7 +33,7 @@ public: const optional expires; const MapDebugOptions debugMode; - gl::SegmentVector segments; + SegmentVector segments; optional> vertexBuffer; optional> indexBuffer; }; diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index 421d8b332b..d3cd92d451 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -30,8 +30,8 @@ public: gl::VertexVector vertices; gl::IndexVector lines; gl::IndexVector triangles; - gl::SegmentVector lineSegments; - gl::SegmentVector triangleSegments; + SegmentVector lineSegments; + SegmentVector triangleSegments; optional> vertexBuffer; optional> lineIndexBuffer; diff --git a/src/mbgl/renderer/fill_extrusion_bucket.hpp b/src/mbgl/renderer/fill_extrusion_bucket.hpp index c54805d743..d1e695c5a3 100644 --- a/src/mbgl/renderer/fill_extrusion_bucket.hpp +++ b/src/mbgl/renderer/fill_extrusion_bucket.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -27,7 +27,7 @@ public: gl::VertexVector vertices; gl::IndexVector triangles; - gl::SegmentVector triangleSegments; + SegmentVector triangleSegments; optional> vertexBuffer; optional> indexBuffer; diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index c319548714..95ef2f9a6f 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -34,7 +34,7 @@ public: gl::VertexVector vertices; gl::IndexVector triangles; - gl::SegmentVector segments; + SegmentVector segments; optional> vertexBuffer; optional> indexBuffer; diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 906a2ea07b..36d2e98082 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -80,7 +81,7 @@ public: virtual void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) = 0; virtual void upload(gl::Context& context) = 0; - virtual AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; + virtual optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; virtual float interpolationFactor(float currentZoom) const = 0; virtual T uniformValue(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; @@ -102,8 +103,8 @@ public: void populateVertexVector(const GeometryTileFeature&, std::size_t) override {} void upload(gl::Context&) override {} - AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue&) const override { - return gl::DisabledAttribute(); + optional attributeBinding(const PossiblyEvaluatedPropertyValue&) const override { + return {}; } float interpolationFactor(float) const override { @@ -146,9 +147,9 @@ public: vertexBuffer = context.createVertexBuffer(std::move(vertexVector)); } - AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { + optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { - return gl::DisabledAttribute(); + return {}; } else { return Attribute::binding(*vertexBuffer, 0, BaseAttribute::Dimensions); } @@ -207,9 +208,9 @@ public: vertexBuffer = context.createVertexBuffer(std::move(vertexVector)); } - AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { + optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { - return gl::DisabledAttribute(); + return {}; } else { return Attribute::binding(*vertexBuffer, 0); } diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index da4903864b..da3268ed76 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -278,7 +278,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp context.activeTexture = 0; context.texture[0] = 0; - context.vertexArrayObject = 0; + context.bindVertexArray = 0; } } @@ -312,7 +312,7 @@ void Painter::renderPass(PaintParameters& parameters, MBGL_DEBUG_GROUP(context, layer.baseImpl.id + " - custom"); // Reset GL state to a known state so the CustomLayer always has a clean slate. - context.vertexArrayObject = 0; + context.bindVertexArray = 0; context.setDepthMode(depthModeForSublayer(0, gl::DepthMode::ReadOnly)); context.setStencilMode(gl::StencilMode::disabled()); context.setColorMode(colorModeForRenderPass()); diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 4658f0c206..1919ad924e 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -177,10 +177,10 @@ private: gl::IndexBuffer quadTriangleIndexBuffer; gl::IndexBuffer tileBorderIndexBuffer; - gl::SegmentVector tileTriangleSegments; - gl::SegmentVector tileBorderSegments; - gl::SegmentVector rasterSegments; - gl::SegmentVector extrusionTextureSegments; + SegmentVector tileTriangleSegments; + SegmentVector tileBorderSegments; + SegmentVector rasterSegments; + SegmentVector extrusionTextureSegments; }; } // namespace mbgl diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index f7e4bcfa20..a9bc868db0 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -45,7 +45,7 @@ public: struct TextBuffer { gl::VertexVector vertices; gl::IndexVector triangles; - gl::SegmentVector segments; + SegmentVector segments; optional> vertexBuffer; optional> indexBuffer; @@ -56,7 +56,7 @@ public: struct IconBuffer { gl::VertexVector vertices; gl::IndexVector triangles; - gl::SegmentVector segments; + SegmentVector segments; optional> vertexBuffer; optional> indexBuffer; @@ -65,7 +65,7 @@ public: struct CollisionBoxBuffer { gl::VertexVector vertices; gl::IndexVector lines; - gl::SegmentVector segments; + SegmentVector segments; optional> vertexBuffer; optional> indexBuffer; diff --git a/test/programs/binary_program.test.cpp b/test/programs/binary_program.test.cpp index ce544e7652..a5cf7b6e39 100644 --- a/test/programs/binary_program.test.cpp +++ b/test/programs/binary_program.test.cpp @@ -14,12 +14,12 @@ TEST(BinaryProgram, ObtainValues) { EXPECT_EQ(42u, binaryProgram.format()); EXPECT_EQ("binary code", binaryProgram.code()); EXPECT_EQ("identifier", binaryProgram.identifier()); - EXPECT_EQ(1, binaryProgram.attributeLocation("a_pos")); - EXPECT_EQ(0, binaryProgram.attributeLocation("u_world")); - EXPECT_EQ(4, binaryProgram.attributeLocation("a_data")); + EXPECT_EQ(1u, binaryProgram.attributeLocation("a_pos")); + EXPECT_FALSE(binaryProgram.attributeLocation("u_world")); + EXPECT_EQ(4u, binaryProgram.attributeLocation("a_data")); EXPECT_EQ(1, binaryProgram.uniformLocation("u_world")); EXPECT_EQ(3, binaryProgram.uniformLocation("u_ratio")); - EXPECT_EQ(0, binaryProgram.uniformLocation("a_data")); + EXPECT_EQ(-1, binaryProgram.uniformLocation("a_data")); auto serialized = binaryProgram.serialize(); @@ -28,12 +28,12 @@ TEST(BinaryProgram, ObtainValues) { EXPECT_EQ(42u, binaryProgram2.format()); EXPECT_EQ("binary code", binaryProgram2.code()); EXPECT_EQ("identifier", binaryProgram2.identifier()); - EXPECT_EQ(1, binaryProgram2.attributeLocation("a_pos")); - EXPECT_EQ(0, binaryProgram2.attributeLocation("u_world")); - EXPECT_EQ(4, binaryProgram2.attributeLocation("a_data")); + EXPECT_EQ(1u, binaryProgram2.attributeLocation("a_pos")); + EXPECT_FALSE(binaryProgram2.attributeLocation("u_world")); + EXPECT_EQ(4u, binaryProgram2.attributeLocation("a_data")); EXPECT_EQ(1, binaryProgram2.uniformLocation("u_world")); EXPECT_EQ(3, binaryProgram2.uniformLocation("u_ratio")); - EXPECT_EQ(0, binaryProgram2.uniformLocation("a_data")); + EXPECT_EQ(-1, binaryProgram2.uniformLocation("a_data")); EXPECT_THROW(BinaryProgram(""), std::runtime_error); } -- cgit v1.2.1 From de91e68090a8b246eb161cc8dfdc5b0f40e5bdc0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 6 Jul 2017 08:06:12 -0700 Subject: [core] Per-segment-per-layer vertex arrays Reduces rebinding, matches gl-js, and works around the buggy VAO implementation on PowerVR SGX544 GPUs. --- src/mbgl/programs/program.hpp | 11 +++++++---- src/mbgl/programs/segment.hpp | 9 ++++++++- src/mbgl/programs/symbol_program.hpp | 11 +++++++---- src/mbgl/renderer/painter.cpp | 15 +++++++++++---- src/mbgl/renderer/painter_background.cpp | 6 ++++-- src/mbgl/renderer/painter_circle.cpp | 3 ++- src/mbgl/renderer/painter_clipping.cpp | 3 ++- src/mbgl/renderer/painter_debug.cpp | 3 ++- src/mbgl/renderer/painter_fill.cpp | 6 ++++-- src/mbgl/renderer/painter_fill_extrusion.cpp | 6 ++++-- src/mbgl/renderer/painter_line.cpp | 3 ++- src/mbgl/renderer/painter_raster.cpp | 3 ++- src/mbgl/renderer/painter_symbol.cpp | 6 ++++-- 13 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 3ff6e59c6b..8cd6c07322 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -58,7 +58,8 @@ public: const SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::Evaluated& currentProperties, - float currentZoom) { + float currentZoom, + const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); @@ -66,8 +67,10 @@ public: .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { - if (!segment.vertexArray) { - segment.vertexArray = context.createVertexArray(); + optional& vertexArray = segment.vertexArrays[layerID]; + + if (!vertexArray) { + vertexArray = context.createVertexArray(); } program.draw( @@ -77,7 +80,7 @@ public: std::move(stencilMode), std::move(colorMode), allUniformValues, - *segment.vertexArray, + *vertexArray, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, diff --git a/src/mbgl/programs/segment.hpp b/src/mbgl/programs/segment.hpp index d8cc9679d7..74bf4a75c5 100644 --- a/src/mbgl/programs/segment.hpp +++ b/src/mbgl/programs/segment.hpp @@ -28,7 +28,14 @@ public: std::size_t vertexLength; std::size_t indexLength; - mutable optional vertexArray; + // One VertexArray per layer ID. This minimizes rebinding in cases where + // several layers share buckets but have different sets of active attributes. + // This can happen: + // * when two layers have the same layout properties, but differing + // data-driven paint properties + // * when two fill layers have the same layout properties, but one + // uses fill-color and the other uses fill-pattern + mutable std::map> vertexArrays; }; template diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 2fddebde09..3bf82009e2 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -360,7 +360,8 @@ public: const SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::Evaluated& currentProperties, - float currentZoom) { + float currentZoom, + const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(symbolSizeBinder.uniformValues(currentZoom)) .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); @@ -370,8 +371,10 @@ public: .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { - if (!segment.vertexArray) { - segment.vertexArray = context.createVertexArray(); + optional& vertexArray = segment.vertexArrays[layerID]; + + if (!vertexArray) { + vertexArray = context.createVertexArray(); } program.draw( @@ -381,7 +384,7 @@ public: std::move(stencilMode), std::move(colorMode), allUniformValues, - *segment.vertexArray, + *vertexArray, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index da3268ed76..fbaf40d5c0 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -353,16 +353,23 @@ void Painter::renderPass(PaintParameters& parameters, const PaintProperties<>::Evaluated properties{}; parameters.programs.extrusionTexture.draw( - context, gl::Triangles(), gl::DepthMode::disabled(), gl::StencilMode::disabled(), + context, + gl::Triangles(), + gl::DepthMode::disabled(), + gl::StencilMode::disabled(), colorModeForRenderPass(), ExtrusionTextureProgram::UniformValues{ uniforms::u_matrix::Value{ viewportMat }, uniforms::u_world::Value{ size }, uniforms::u_image::Value{ 0 }, uniforms::u_opacity::Value{ layer.as() ->evaluated.get() } }, - extrusionTextureVertexBuffer, quadTriangleIndexBuffer, extrusionTextureSegments, - ExtrusionTextureProgram::PaintPropertyBinders{ properties, 0 }, properties, - state.getZoom()); + extrusionTextureVertexBuffer, + quadTriangleIndexBuffer, + extrusionTextureSegments, + ExtrusionTextureProgram::PaintPropertyBinders{ properties, 0 }, + properties, + state.getZoom(), + layer.getID()); } else { for (auto& tileRef : item.tiles) { auto& tile = tileRef.get(); diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index d01696ee3e..9bd9431082 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -53,7 +53,8 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou tileTriangleSegments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } } else { @@ -73,7 +74,8 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou tileTriangleSegments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } } diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index 13acb5f7fe..ecd7598de9 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -50,7 +50,8 @@ void Painter::renderCircle(PaintParameters& parameters, bucket.segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } diff --git a/src/mbgl/renderer/painter_clipping.cpp b/src/mbgl/renderer/painter_clipping.cpp index b3a2d77b1a..162f3b1d96 100644 --- a/src/mbgl/renderer/painter_clipping.cpp +++ b/src/mbgl/renderer/painter_clipping.cpp @@ -30,7 +30,8 @@ void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& cl tileTriangleSegments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + "clipping" ); } diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp index 37fa3bcb12..9a24ab5422 100644 --- a/src/mbgl/renderer/painter_debug.cpp +++ b/src/mbgl/renderer/painter_debug.cpp @@ -39,7 +39,8 @@ void Painter::renderTileDebug(const RenderTile& renderTile) { segments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + "debug" ); }; diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index e1b59d8839..cad76ace4f 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -60,7 +60,8 @@ void Painter::renderFill(PaintParameters& parameters, segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; @@ -104,7 +105,8 @@ void Painter::renderFill(PaintParameters& parameters, segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; diff --git a/src/mbgl/renderer/painter_fill_extrusion.cpp b/src/mbgl/renderer/painter_fill_extrusion.cpp index 95617525c7..5581cfe983 100644 --- a/src/mbgl/renderer/painter_fill_extrusion.cpp +++ b/src/mbgl/renderer/painter_fill_extrusion.cpp @@ -59,7 +59,8 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, bucket.triangleSegments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom()); + state.getZoom(), + layer.getID()); } else { parameters.programs.fillExtrusion.get(properties).draw( @@ -80,7 +81,8 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, bucket.triangleSegments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom()); + state.getZoom(), + layer.getID()); }; } diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 9152ac8512..209b1447d0 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -36,7 +36,8 @@ void Painter::renderLine(PaintParameters& parameters, bucket.segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index fbe025b5b0..f0e5399f4a 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -81,7 +81,8 @@ void Painter::renderRaster(PaintParameters& parameters, rasterSegments, paintAttributeData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index c9ed8cc570..6462eebdcc 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -58,7 +58,8 @@ void Painter::renderSymbol(PaintParameters& parameters, buffers.segments, binders, paintProperties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; @@ -156,7 +157,8 @@ void Painter::renderSymbol(PaintParameters& parameters, bucket.collisionBox.segments, paintAttributeData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } } -- cgit v1.2.1 From cf83f117f0e3e338454ba1bc0e5a13b3b9565228 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 10 Jul 2017 12:19:23 -0700 Subject: [core] Reduce memory requirements of VertexArrays --- src/mbgl/gl/attribute.hpp | 22 ++++++++++++++-------- src/mbgl/gl/context.cpp | 5 +++-- src/mbgl/gl/types.hpp | 2 +- src/mbgl/gl/vertex_array.hpp | 17 ++++++++++++++++- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index ed4168c21f..a85b49c6a5 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace mbgl { namespace gl { @@ -30,12 +31,12 @@ template <> struct DataTypeOf : std::integral_constant::value, "vertex type must use standard layout"); + assert(attributeSize >= 1); + assert(attributeSize <= 4); + assert(Vertex::attributeOffsets[attributeIndex] <= std::numeric_limits::max()); + static_assert(sizeof(Vertex) <= std::numeric_limits::max(), "vertex too large"); return AttributeBinding { DataTypeOf::value, - attributeSize, - Vertex::attributeOffsets[attributeIndex], + static_cast(attributeSize), + static_cast(Vertex::attributeOffsets[attributeIndex]), buffer.buffer, - sizeof(Vertex), + static_cast(sizeof(Vertex)), 0, }; } static optional offsetBinding(const optional& binding, std::size_t vertexOffset) { + assert(vertexOffset <= std::numeric_limits::max()); if (binding) { AttributeBinding result = *binding; - result.vertexOffset = vertexOffset; + result.vertexOffset = static_cast(vertexOffset); return result; } else { return binding; diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 2d7354a64e..19ea9a514f 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -233,11 +233,12 @@ VertexArray Context::createVertexArray() { if (supportsVertexArrays()) { VertexArrayID id = 0; MBGL_CHECK_ERROR(vertexArray->genVertexArrays(1, &id)); - return { std::make_unique(UniqueVertexArray(std::move(id), { this }), *this) }; + UniqueVertexArray vao(std::move(id), { this }); + return { UniqueVertexArrayState(new VertexArrayState(std::move(vao), *this), VertexArrayStateDeleter { true })}; } else { // On GL implementations which do not support vertex arrays, attribute bindings are global state. // So return a VertexArray which shares our global state tracking and whose deleter is a no-op. - return { UniqueVertexArrayState(&globalVertexArrayState, [] (VertexArrayState*) {}) }; + return { UniqueVertexArrayState(&globalVertexArrayState, VertexArrayStateDeleter { false }) }; } } diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp index c80399016e..e7d2ca449a 100644 --- a/src/mbgl/gl/types.hpp +++ b/src/mbgl/gl/types.hpp @@ -24,7 +24,7 @@ enum class ShaderType : uint32_t { Fragment = 0x8B30 }; -enum class DataType : uint32_t { +enum class DataType : uint16_t { Byte = 0x1400, UnsignedByte = 0x1401, Short = 0x1402, diff --git a/src/mbgl/gl/vertex_array.hpp b/src/mbgl/gl/vertex_array.hpp index 9ccf48d9bd..46c67017bb 100644 --- a/src/mbgl/gl/vertex_array.hpp +++ b/src/mbgl/gl/vertex_array.hpp @@ -40,7 +40,22 @@ private: } }; -using UniqueVertexArrayState = std::unique_ptr>; +class VertexArrayStateDeleter { +public: + VertexArrayStateDeleter(bool destroy_) + : destroy(destroy_) {} + + void operator()(VertexArrayState* ptr) const { + if (destroy) { + delete ptr; + } + } + +private: + bool destroy; +}; + +using UniqueVertexArrayState = std::unique_ptr; class VertexArray { public: -- cgit v1.2.1 From 902d9442da0f2f2c74530a4b770c9ff05f5d4d1e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 10 Jul 2017 12:31:46 -0700 Subject: [core] No need for optional in map of VertexArrays --- src/mbgl/programs/program.hpp | 8 ++++---- src/mbgl/programs/segment.hpp | 3 +-- src/mbgl/programs/symbol_program.hpp | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 8cd6c07322..ca8434cf0a 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -67,10 +67,10 @@ public: .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { - optional& vertexArray = segment.vertexArrays[layerID]; + auto vertexArrayIt = segment.vertexArrays.find(layerID); - if (!vertexArray) { - vertexArray = context.createVertexArray(); + if (vertexArrayIt == segment.vertexArrays.end()) { + vertexArrayIt = segment.vertexArrays.emplace(layerID, context.createVertexArray()).first; } program.draw( @@ -80,7 +80,7 @@ public: std::move(stencilMode), std::move(colorMode), allUniformValues, - *vertexArray, + vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, diff --git a/src/mbgl/programs/segment.hpp b/src/mbgl/programs/segment.hpp index 74bf4a75c5..937df4dece 100644 --- a/src/mbgl/programs/segment.hpp +++ b/src/mbgl/programs/segment.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -35,7 +34,7 @@ public: // data-driven paint properties // * when two fill layers have the same layout properties, but one // uses fill-color and the other uses fill-pattern - mutable std::map> vertexArrays; + mutable std::map vertexArrays; }; template diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 3bf82009e2..5fb0c4f15f 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -371,10 +371,10 @@ public: .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { - optional& vertexArray = segment.vertexArrays[layerID]; + auto vertexArrayIt = segment.vertexArrays.find(layerID); - if (!vertexArray) { - vertexArray = context.createVertexArray(); + if (vertexArrayIt == segment.vertexArrays.end()) { + vertexArrayIt = segment.vertexArrays.emplace(layerID, context.createVertexArray()).first; } program.draw( @@ -384,7 +384,7 @@ public: std::move(stencilMode), std::move(colorMode), allUniformValues, - *vertexArray, + vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, -- cgit v1.2.1 From 550da70cf78e700deea4d298e90afe134fda27e2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 11 Jul 2017 14:11:59 -0700 Subject: [core] Pass correct sources to programIdentifier --- src/mbgl/gl/program.hpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 9d8b0a5b04..3b54ec194a 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -52,15 +52,13 @@ public: const char* name, const char* vertexSource_, const char* fragmentSource_) { + const std::string vertexSource = shaders::vertexSource(programParameters, vertexSource_); + const std::string fragmentSource = shaders::fragmentSource(programParameters, fragmentSource_); + #if MBGL_HAS_BINARY_PROGRAMS optional cachePath = programParameters.cachePath(name); if (cachePath && context.supportsProgramBinaries()) { - const std::string vertexSource = - shaders::vertexSource(programParameters, vertexSource_); - const std::string fragmentSource = - shaders::fragmentSource(programParameters, fragmentSource_); - const std::string identifier = - shaders::programIdentifier(vertexSource, fragmentSource_); + const std::string identifier = shaders::programIdentifier(vertexSource, fragmentSource); try { if (auto cachedBinaryProgram = util::readFile(*cachePath)) { @@ -94,11 +92,9 @@ public: return std::move(result); } #endif + (void)name; - return Program { - context, shaders::vertexSource(programParameters, vertexSource_), - shaders::fragmentSource(programParameters, fragmentSource_) - }; + return Program { context, vertexSource, fragmentSource }; } template -- cgit v1.2.1 From 2d147470a5f982afb0c1a63ff632497f85ea85bf Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 11 Jul 2017 14:11:02 -0700 Subject: [android] Force previously cached program binaries to be regenerated --- src/mbgl/shaders/shaders.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mbgl/shaders/shaders.cpp b/src/mbgl/shaders/shaders.cpp index 31ff405f02..2e5a318024 100644 --- a/src/mbgl/shaders/shaders.cpp +++ b/src/mbgl/shaders/shaders.cpp @@ -22,6 +22,7 @@ std::string programIdentifier(const std::string& vertexSource, const std::string ss << std::setfill('0') << std::setw(sizeof(size_t) * 2) << std::hex; ss << std::hash()(vertexSource); ss << std::hash()(fragmentSource); + ss << "v2"; return ss.str(); } -- cgit v1.2.1 From 733661948c004dad70e634aa9f2b41402e460a6e Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Thu, 13 Jul 2017 15:35:02 +0300 Subject: [core] BackendScope prevent double (de-)activation - Guards against duplicate activations by checking wether the backend of the prior scope is the same as the current ones - Makes sure that only the most outer backend scope deactivates by tracking activation state --- cmake/test-files.cmake | 1 + include/mbgl/map/backend.hpp | 5 ++ include/mbgl/map/backend_scope.hpp | 4 ++ src/mbgl/map/backend_scope.cpp | 35 ++++++++--- test/renderer/backend_scope.test.cpp | 113 +++++++++++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 8 deletions(-) create mode 100644 test/renderer/backend_scope.test.cpp diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 6026374de6..c29bd284d7 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -42,6 +42,7 @@ set(MBGL_TEST_FILES test/programs/binary_program.test.cpp # renderer + test/renderer/backend_scope.test.cpp test/renderer/group_by_layout.test.cpp # sprite diff --git a/include/mbgl/map/backend.hpp b/include/mbgl/map/backend.hpp index 884c4b5256..69a998709b 100644 --- a/include/mbgl/map/backend.hpp +++ b/include/mbgl/map/backend.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -80,4 +81,8 @@ private: friend class BackendScope; }; +constexpr bool operator==(const Backend& a, const Backend& b) { + return &a == &b; +} + } // namespace mbgl diff --git a/include/mbgl/map/backend_scope.hpp b/include/mbgl/map/backend_scope.hpp index 4985cd197f..322c17b3fc 100644 --- a/include/mbgl/map/backend_scope.hpp +++ b/include/mbgl/map/backend_scope.hpp @@ -22,10 +22,14 @@ public: static bool exists(); private: + void activate(); + void deactivate(); + BackendScope* priorScope; BackendScope* nextScope; Backend& backend; const ScopeType scopeType; + bool activated = false; }; } // namespace mbgl diff --git a/src/mbgl/map/backend_scope.cpp b/src/mbgl/map/backend_scope.cpp index 824ad4498b..dac90346d7 100644 --- a/src/mbgl/map/backend_scope.cpp +++ b/src/mbgl/map/backend_scope.cpp @@ -16,30 +16,49 @@ BackendScope::BackendScope(Backend& backend_, ScopeType scopeType_) if (priorScope) { assert(priorScope->nextScope == nullptr); priorScope->nextScope = this; + priorScope->deactivate(); } - if (scopeType == ScopeType::Explicit) { - backend.activate(); - } + + activate(); currentScope.set(this); } BackendScope::~BackendScope() { assert(nextScope == nullptr); + deactivate(); + if (priorScope) { - priorScope->backend.activate(); + priorScope->activate(); currentScope.set(priorScope); assert(priorScope->nextScope == this); priorScope->nextScope = nullptr; } else { - if (scopeType == ScopeType::Explicit) { - backend.deactivate(); - } - currentScope.set(nullptr); } } +void BackendScope::activate() { + if (scopeType == ScopeType::Explicit && + !(priorScope && this->backend == priorScope->backend) && + !(nextScope && this->backend == nextScope->backend)) { + // Only activate when set to Explicit and + // only once per RenderBackend + backend.activate(); + activated = true; + } +} + +void BackendScope::deactivate() { + if (activated && + !(nextScope && this->backend == nextScope->backend)) { + // Only deactivate when set to Explicit and + // only once per RenderBackend + backend.deactivate(); + activated = false; + } +} + bool BackendScope::exists() { return currentScope.get(); } diff --git a/test/renderer/backend_scope.test.cpp b/test/renderer/backend_scope.test.cpp new file mode 100644 index 0000000000..6afd8f12ed --- /dev/null +++ b/test/renderer/backend_scope.test.cpp @@ -0,0 +1,113 @@ +#include + +#include +#include + +#include + +using namespace mbgl; + +class StubBackend: public Backend { +public: + + void activate() override { + if (activateFunction) activateFunction(); + } + + void deactivate() override { + if (deactivateFunction) deactivateFunction(); + } + + void updateAssumedState() override { + if (updateAssumedStateFunction) updateAssumedStateFunction(); + } + + void invalidate() override {} + + gl::ProcAddress initializeExtension(const char* ext) override { + if (initializeExtensionFunction) { + return initializeExtensionFunction(ext); + } else { + return {}; + } + } + + std::function activateFunction; + std::function deactivateFunction; + std::function updateAssumedStateFunction; + std::function initializeExtensionFunction; +}; + +// A scope should activate on construction +// and deactivate on descruction (going out +// of scope) +TEST(BackendScope, SingleScope) { + bool activated; + bool deactivated; + + StubBackend backend; + backend.activateFunction = [&] { activated = true; }; + backend.deactivateFunction = [&] { deactivated = true; }; + + { + BackendScope test { backend }; + } + + ASSERT_TRUE(activated); + ASSERT_TRUE(deactivated); +} + +// With nested scopes, only the outer scope +// should activate/deactivate +TEST(BackendScope, NestedScopes) { + int activated = 0; + int deactivated = 0; + + StubBackend backend; + backend.activateFunction = [&] { activated++; }; + backend.deactivateFunction = [&] { deactivated++; }; + + { + BackendScope outer { backend }; + ASSERT_EQ(1, activated); + { + BackendScope inner { backend }; + ASSERT_EQ(1, activated); + } + ASSERT_EQ(0, deactivated); + } + + ASSERT_EQ(1, deactivated); +} + +// With chained scopes, where scopes have +// different backends, the scopes should each +// activate the scope on entering and de-activating +// on leaving the scope +TEST(BackendScope, ChainedScopes) { + bool activatedA = false; + bool activatedB = false; + + StubBackend backendA; + backendA.activateFunction = [&] { activatedA = true; }; + backendA.deactivateFunction = [&] { activatedA = false; }; + + StubBackend backendB; + backendB.activateFunction = [&] { activatedB = true; }; + backendB.deactivateFunction = [&] { activatedB = false; }; + + { + BackendScope scopeA { backendA }; + ASSERT_TRUE(activatedA); + { + BackendScope scopeB { backendB }; + ASSERT_FALSE(activatedA); + ASSERT_TRUE(activatedB); + } + ASSERT_FALSE(activatedB); + ASSERT_TRUE(activatedA); + } + + ASSERT_FALSE(activatedA); + ASSERT_FALSE(activatedB); +} -- cgit v1.2.1 From e7f45e0b19eaa86b587e5269f85ecd0eb8a55de7 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Thu, 13 Jul 2017 12:38:48 +0300 Subject: [android] remove manual ref counting on activation/deactivation --- platform/android/src/native_map_view.cpp | 7 ------- platform/android/src/native_map_view.hpp | 2 -- 2 files changed, 9 deletions(-) diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 0a57d3e6b4..5b0825fa09 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -120,9 +120,6 @@ gl::ProcAddress NativeMapView::initializeExtension(const char* name) { } void NativeMapView::activate() { - if (active++) { - return; - } oldDisplay = eglGetCurrentDisplay(); oldReadSurface = eglGetCurrentSurface(EGL_READ); @@ -151,10 +148,6 @@ void NativeMapView::activate() { * From mbgl::Backend. */ void NativeMapView::deactivate() { - if (--active) { - return; - } - assert(vm != nullptr); if (oldContext != context && oldContext != EGL_NO_CONTEXT) { diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index df43ad08b7..c638de44fb 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -334,8 +334,6 @@ private: std::shared_ptr threadPool; std::unique_ptr map; mbgl::EdgeInsets insets; - - unsigned active = 0; }; } // namespace android -- cgit v1.2.1 From 441644166310314b5e8016405691110e69a0a3cd Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 19 Jul 2017 10:03:59 -0700 Subject: [core] Revert conditional attribute binding Reverts eed89fcf9d099266aa793375ad63493e880f8a80, which causes issues on certain Android devices. We don't actually need this change on this branch, I brought it over only to make the subsequent commits cleanly cherry-pickable. --- src/mbgl/gl/attribute.cpp | 30 ++---------------------------- src/mbgl/gl/attribute.hpp | 18 ++---------------- src/mbgl/gl/program.hpp | 12 +++++------- 3 files changed, 9 insertions(+), 51 deletions(-) diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index bb5b2ddc34..4dd102400d 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -4,35 +4,9 @@ namespace mbgl { namespace gl { -void bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { - if (location >= MAX_ATTRIBUTES) { - throw gl::Error("too many vertex attributes"); - } +AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); -} - -std::set getActiveAttributes(ProgramID id) { - std::set activeAttributes; - - GLint attributeCount; - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount)); - - GLint maxAttributeLength; - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength)); - - std::string attributeName; - attributeName.resize(maxAttributeLength); - - GLsizei actualLength; - GLint size; - GLenum type; - - for (int32_t i = 0; i < attributeCount; i++) { - MBGL_CHECK_ERROR(glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0])); - activeAttributes.emplace(std::string(attributeName, 0, actualLength)); - } - - return activeAttributes; + return location; } } // namespace gl diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index a85b49c6a5..2d1d2386eb 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -214,8 +213,7 @@ const std::size_t Vertex::attributeOffsets[5] = { } // namespace detail -void bindAttributeLocation(ProgramID, AttributeLocation, const char * name); -std::set getActiveAttributes(ProgramID); +AttributeLocation bindAttributeLocation(ProgramID, AttributeLocation, const char * name); template class Attributes { @@ -235,19 +233,7 @@ public: static constexpr std::size_t Index = TypeIndex::value; static Locations bindLocations(const ProgramID& id) { - std::set activeAttributes = getActiveAttributes(id); - - AttributeLocation location = 0; - auto maybeBindLocation = [&](const char* name) -> optional { - if (activeAttributes.count(name)) { - bindAttributeLocation(id, location, name); - return location++; - } else { - return {}; - } - }; - - return Locations { maybeBindLocation(As::name())... }; + return Locations { bindAttributeLocation(id, Index, As::name())... }; } template diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 3b54ec194a..1a429c6630 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -34,17 +34,15 @@ public: : program( context.createProgram(context.createShader(ShaderType::Vertex, vertexSource), context.createShader(ShaderType::Fragment, fragmentSource))), - uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))), - attributeLocations(Attributes::bindLocations(program)) { - // Re-link program after manually binding only active attributes in Attributes::bindLocations - context.linkProgram(program); + attributeLocations(Attributes::bindLocations(program)), + uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))) { } template Program(Context& context, const BinaryProgram& binaryProgram) : program(context.createProgram(binaryProgram.format(), binaryProgram.code())), - uniformsState(Uniforms::loadNamedLocations(binaryProgram)), - attributeLocations(Attributes::loadNamedLocations(binaryProgram)) { + attributeLocations(Attributes::loadNamedLocations(binaryProgram)), + uniformsState(Uniforms::loadNamedLocations(binaryProgram)) { } static Program createProgram(gl::Context& context, @@ -142,8 +140,8 @@ public: private: UniqueProgram program; - typename Uniforms::State uniformsState; typename Attributes::Locations attributeLocations; + typename Uniforms::State uniformsState; }; } // namespace gl -- cgit v1.2.1 From f94d81c305230a1f54ac5e024c98cfeb1b87739f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 19 Jul 2017 00:51:13 -0700 Subject: [android, ios, macos] Updated French localization Updated French localization on iOS and macOS and added French localization on Android. --- platform/android/CHANGELOG.md | 4 + .../src/main/res/values-fr/strings.xml | 15 ++ .../darwin/resources/fr.lproj/Foundation.strings | 291 +++++++++++++++++++++ .../ios/resources/fr.lproj/Localizable.strings | 18 ++ platform/macos/macos.xcodeproj/project.pbxproj | 2 + platform/macos/sdk/fr.lproj/Localizable.strings | 14 +- 6 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml create mode 100644 platform/darwin/resources/fr.lproj/Foundation.strings diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 6d4bb46357..0a3615d805 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -2,6 +2,10 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started. +## 5.1.1 - TBA + +* Add French localization [#9545](https://github.com/mapbox/mapbox-gl-native/pull/9545) + ## 5.1.0 - June 30, 2017 * Update to MAS 2.1.3 [#9402](https://github.com/mapbox/mapbox-gl-native/pull/9402) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml new file mode 100644 index 0000000000..48d90c3324 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml @@ -0,0 +1,15 @@ + + + Boussole. Activer pour rétablir l\'orientation de la carte vers le nord. + Icone d\'attribution. Activer pour montrer le dialogue d\'attribution. + Vue de géolocalisation. Ceci affiche votre localisation sur la carte. + Affichage d\'une carte créée avec Mapbox. Faites la glisser en traînant deux doigts. Zoomez ou dézoomez en écartant ou rapprochant deux doigts. + SDK Mapbox pour Android + Faire de meilleures cartes Mapbox + Vous aidez à améliorer les cartes OpenStreetMap et Mapbox en contribuant des données d\'utilisation anonymes. + D\'accord + Pas d\'accord + Plus d\'informations + Le cadre OfflineRegionDefinition pour définir la région de navigation ne tient pas dans les limites du monde : %s + + diff --git a/platform/darwin/resources/fr.lproj/Foundation.strings b/platform/darwin/resources/fr.lproj/Foundation.strings new file mode 100644 index 0000000000..d2f6c1f6df --- /dev/null +++ b/platform/darwin/resources/fr.lproj/Foundation.strings @@ -0,0 +1,291 @@ +/* Clock position format, long: {hours} o’clock */ +"CLOCK_FMT_LONG" = "%@ heures"; + +/* Clock position format, medium: {hours} o’clock */ +"CLOCK_FMT_MEDIUM" = "%@ heures"; + +/* Clock position format, short: {hours}:00 */ +"CLOCK_FMT_SHORT" = "%@h 00"; + +/* East, long */ +"COMPASS_E_LONG" = "est"; + +/* East, short */ +"COMPASS_E_SHORT" = "E"; + +/* East by north, long */ +"COMPASS_EbN_LONG" = "est par nord"; + +/* East by north, short */ +"COMPASS_EbN_SHORT" = "EpN"; + +/* East by south, long */ +"COMPASS_EbS_LONG" = "est par sud"; + +/* East by south, short */ +"COMPASS_EbS_SHORT" = "EpS"; + +/* East-northeast, long */ +"COMPASS_ENE_LONG" = "est-nord-est"; + +/* East-northeast, short */ +"COMPASS_ENE_SHORT" = "ENE"; + +/* East-southeast, long */ +"COMPASS_ESE_LONG" = "est-sud-est"; + +/* East-southeast, short */ +"COMPASS_ESE_SHORT" = "ESE"; + +/* North, long */ +"COMPASS_N_LONG" = "nord"; + +/* North, short */ +"COMPASS_N_SHORT" = "N"; + +/* North by east, long */ +"COMPASS_NbE_LONG" = "nord par est"; + +/* North by east, short */ +"COMPASS_NbE_SHORT" = "NpE"; + +/* North by west, long */ +"COMPASS_NbW_LONG" = "nord par ouest"; + +/* North by west, short */ +"COMPASS_NbW_SHORT" = "NpO"; + +/* Northeast, long */ +"COMPASS_NE_LONG" = "nord-est"; + +/* Northeast, short */ +"COMPASS_NE_SHORT" = "NE"; + +/* Northeast by east, long */ +"COMPASS_NEbE_LONG" = "nord-est par est"; + +/* Northeast by east, short */ +"COMPASS_NEbE_SHORT" = "NEpE"; + +/* Northeast by north, long */ +"COMPASS_NEbN_LONG" = "nord-est par nord"; + +/* Northeast by north, short */ +"COMPASS_NEbN_SHORT" = "NEpN"; + +/* North-northeast, long */ +"COMPASS_NNE_LONG" = "nord-nord-est"; + +/* North-northeast, short */ +"COMPASS_NNE_SHORT" = "NNE"; + +/* North-northwest, long */ +"COMPASS_NNW_LONG" = "nord-nord-ouest"; + +/* North-northwest, short */ +"COMPASS_NNW_SHORT" = "NNO"; + +/* Northwest, long */ +"COMPASS_NW_LONG" = "nord-ouest"; + +/* Northwest, short */ +"COMPASS_NW_SHORT" = "NO"; + +/* Northwest by north, long */ +"COMPASS_NWbN_LONG" = "nord-ouest par nord"; + +/* Northwest by north, short */ +"COMPASS_NWbN_SHORT" = "NOpN"; + +/* Northwest by west, long */ +"COMPASS_NWbW_LONG" = "nord-ouest par ouest"; + +/* Northwest by west, short */ +"COMPASS_NWbW_SHORT" = "NOpO"; + +/* South, long */ +"COMPASS_S_LONG" = "sud"; + +/* South, short */ +"COMPASS_S_SHORT" = "S"; + +/* South by east, long */ +"COMPASS_SbE_LONG" = "sud par est"; + +/* South by east, short */ +"COMPASS_SbE_SHORT" = "SpE"; + +/* South by west, long */ +"COMPASS_SbW_LONG" = "sud par ouest"; + +/* South by west, short */ +"COMPASS_SbW_SHORT" = "SpO"; + +/* Southeast, long */ +"COMPASS_SE_LONG" = "sud-est"; + +/* Southeast, short */ +"COMPASS_SE_SHORT" = "SE"; + +/* Southeast by east, long */ +"COMPASS_SEbE_LONG" = "sud-est par est"; + +/* Southeast by east, short */ +"COMPASS_SEbE_SHORT" = "SEpE"; + +/* Southeast by south, long */ +"COMPASS_SEbS_LONG" = "sud-est par sud"; + +/* Southeast by south, short */ +"COMPASS_SEbS_SHORT" = "SEpS"; + +/* South-southeast, long */ +"COMPASS_SSE_LONG" = "sud-sud-est"; + +/* South-southeast, short */ +"COMPASS_SSE_SHORT" = "SSE"; + +/* South-southwest, long */ +"COMPASS_SSW_LONG" = "sud-sud-ouest"; + +/* South-southwest, short */ +"COMPASS_SSW_SHORT" = "SSO"; + +/* Southwest, long */ +"COMPASS_SW_LONG" = "sud-ouest"; + +/* Southwest, short */ +"COMPASS_SW_SHORT" = "SO"; + +/* Southwest by south, long */ +"COMPASS_SWbS_LONG" = "sud-ouest par sud"; + +/* Southwest by south, short */ +"COMPASS_SWbS_SHORT" = "SOpS"; + +/* Southwest by west, long */ +"COMPASS_SWbW_LONG" = "sud-ouest par ouest"; + +/* Southwest by west, short */ +"COMPASS_SWbW_SHORT" = "SOpO"; + +/* West, long */ +"COMPASS_W_LONG" = "ouest"; + +/* West, short */ +"COMPASS_W_SHORT" = "O"; + +/* West by north, long */ +"COMPASS_WbN_LONG" = "ouest par nord"; + +/* West by north, short */ +"COMPASS_WbN_SHORT" = "OpN"; + +/* West by south, long */ +"COMPASS_WbS_LONG" = "ouest par sud"; + +/* West by south, short */ +"COMPASS_WbS_SHORT" = "OpS"; + +/* West-northwest, long */ +"COMPASS_WNW_LONG" = "ouest-nord-ouest"; + +/* West-northwest, short */ +"COMPASS_WNW_SHORT" = "ONO"; + +/* West-southwest, long */ +"COMPASS_WSW_LONG" = "ouest-sud-ouest"; + +/* West-southwest, short */ +"COMPASS_WSW_SHORT" = "OSO"; + +/* Degrees format, long */ +"COORD_DEG_LONG" = "%d degré(s)"; + +/* Degrees format, medium: {degrees} */ +"COORD_DEG_MEDIUM" = "%d°"; + +/* Degrees format, short: {degrees} */ +"COORD_DEG_SHORT" = "%d°"; + +/* Coordinate format, long: {degrees}{minutes} */ +"COORD_DM_LONG" = "%1$@ et %2$@"; + +/* Coordinate format, medium: {degrees}{minutes} */ +"COORD_DM_MEDIUM" = "%1$@%2$@"; + +/* Coordinate format, short: {degrees}{minutes} */ +"COORD_DM_SHORT" = "%1$@%2$@"; + +/* Coordinate format, long: {degrees}{minutes}{seconds} */ +"COORD_DMS_LONG" = "%1$@, %2$@ et %3$@"; + +/* Coordinate format, medium: {degrees}{minutes}{seconds} */ +"COORD_DMS_MEDIUM" = "%1$@%2$@%3$@"; + +/* Coordinate format, short: {degrees}{minutes}{seconds} */ +"COORD_DMS_SHORT" = "%1$@%2$@%3$@"; + +/* East longitude format, long: {longitude} */ +"COORD_E_LONG" = "%@ est"; + +/* East longitude format, medium: {longitude} */ +"COORD_E_MEDIUM" = "%@ est"; + +/* East longitude format, short: {longitude} */ +"COORD_E_SHORT" = "%@E"; + +/* Coordinate pair format, long: {latitude}, {longitude} */ +"COORD_FMT_LONG" = "%1$@, %2$@"; + +/* Coordinate pair format, medium: {latitude}, {longitude} */ +"COORD_FMT_MEDIUM" = "%1$@, %2$@"; + +/* Coordinate pair format, short: {latitude}, {longitude} */ +"COORD_FMT_SHORT" = "%1$@, %2$@"; + +/* Minutes format, long */ +"COORD_MIN_LONG" = "%d minute(s)"; + +/* Minutes format, medium: {minutes} */ +"COORD_MIN_MEDIUM" = "%d′"; + +/* Minutes format, short: {minutes} */ +"COORD_MIN_SHORT" = "%d′"; + +/* North latitude format, long: {latitude} */ +"COORD_N_LONG" = "%@ nord"; + +/* North latitude format, medium: {latitude} */ +"COORD_N_MEDIUM" = "%@ nord"; + +/* North latitude format, short: {latitude} */ +"COORD_N_SHORT" = "%@N"; + +/* South latitude format, long: {latitude} */ +"COORD_S_LONG" = "%@ sud"; + +/* South latitude format, medium: {latitude} */ +"COORD_S_MEDIUM" = "%@ sud"; + +/* South latitude format, short: {latitude} */ +"COORD_S_SHORT" = "%@S"; + +/* Seconds format, long */ +"COORD_SEC_LONG" = "%d seconde(s)"; + +/* Seconds format, medium: {seconds} */ +"COORD_SEC_MEDIUM" = "%d″"; + +/* Seconds format, short: {seconds} */ +"COORD_SEC_SHORT" = "%d″"; + +/* West longitude format, long: {longitude} */ +"COORD_W_LONG" = "%@ ouest"; + +/* West longitude format, medium: {longitude} */ +"COORD_W_MEDIUM" = "%@ ouest"; + +/* West longitude format, short: {longitude} */ +"COORD_W_SHORT" = "%@O"; + diff --git a/platform/ios/resources/fr.lproj/Localizable.strings b/platform/ios/resources/fr.lproj/Localizable.strings index 075042c695..7fc85568c7 100644 --- a/platform/ios/resources/fr.lproj/Localizable.strings +++ b/platform/ios/resources/fr.lproj/Localizable.strings @@ -10,6 +10,9 @@ /* No comment provided by engineer. */ "CANCEL" = "Annuler"; +/* Accessibility hint for closing the selected annotation’s callout view and returning to the map */ +"CLOSE_CALLOUT_A11Y_HINT" = "Retour à la carte"; + /* Accessibility hint */ "COMPASS_A11Y_HINT" = "Tourne la carte vers le nord"; @@ -31,6 +34,12 @@ /* Accessibility label */ "INFO_A11Y_LABEL" = "À propos de cette carte"; +/* User-friendly error description */ +"LOAD_MAP_FAILED_DESC" = "La carte n’a pas pu être chargée car une erreur inconnue est survenue."; + +/* User-friendly error description */ +"LOAD_STYLE_FAILED_DESC" = "La carte n’a pas pu être chargée car le style ne peut pas être chargé."; + /* Accessibility label */ "LOGO_A11Y_LABEL" = "Mapbox"; @@ -40,9 +49,18 @@ /* Map accessibility value */ "MAP_A11Y_VALUE" = "Zoom %1$dx\n%2$ld annotation(s) visible(s)"; +/* User-friendly error description */ +"PARSE_STYLE_FAILED_DESC" = "La carte n’a pas pu être chargée car le style est corrompu."; + /* Action sheet title */ "SDK_NAME" = "Mapbox iOS SDK"; +/* Developer-only SDK update notification; {latest version, in format x.x.x} */ +"SDK_UPDATE_AVAILABLE" = "La version %@ du SDK Mapbox pour iOS est maintenant disponible :"; + +/* User-friendly error description */ +"STYLE_NOT_FOUND_DESC" = "La carte n’a pas pu être chargée car le style n’a pas été trouvé ou est incompatible."; + /* Telemetry prompt message */ "TELEMETRY_DISABLED_MSG" = "Vous pouvez contribuer à OpenStreetMap et Mapbox en partageant des données d’utilisation anonymes."; diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 1127524098..be33b822f2 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -475,6 +475,7 @@ DACC22121CF3D3E200D220D9 /* MGLFeature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFeature.h; sourceTree = ""; }; DACC22131CF3D3E200D220D9 /* MGLFeature.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLFeature.mm; sourceTree = ""; }; DACC22171CF3D4F700D220D9 /* MGLFeature_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFeature_Private.h; sourceTree = ""; }; + DACCD9C71F1F443B00BB09A1 /* fr */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Foundation.strings; sourceTree = ""; }; DAD165721CF4CD7A001FF4B9 /* MGLShapeCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLShapeCollection.h; sourceTree = ""; }; DAD165731CF4CD7A001FF4B9 /* MGLShapeCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLShapeCollection.mm; sourceTree = ""; }; DAE6C2E11CC304F900DB3429 /* Credits.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = ""; }; @@ -1598,6 +1599,7 @@ DA618B171E68876C00CB7F44 /* ca */, DA618B231E6891ED00CB7F44 /* lt */, DAE9E0F21EB7BF39001E8E8B /* es */, + DACCD9C71F1F443B00BB09A1 /* fr */, ); name = Foundation.strings; sourceTree = ""; diff --git a/platform/macos/sdk/fr.lproj/Localizable.strings b/platform/macos/sdk/fr.lproj/Localizable.strings index 34e085ef2b..9d73f23d05 100644 --- a/platform/macos/sdk/fr.lproj/Localizable.strings +++ b/platform/macos/sdk/fr.lproj/Localizable.strings @@ -1,6 +1,18 @@ -/* Accessibility title */ +/* User-friendly error description */ +"LOAD_MAP_FAILED_DESC" = "La carte n’a pas pu être chargée car une erreur inconnue est survenue."; + +/* User-friendly error description */ +"LOAD_STYLE_FAILED_DESC" = "La carte n’a pas pu être chargée car le style ne peut pas être chargé."; + +/* Accessibility title */ "MAP_A11Y_TITLE" = "Mapbox"; +/* User-friendly error description */ +"PARSE_STYLE_FAILED_DESC" = "La carte n’a pas pu être chargée car le style est corrompu."; + +/* User-friendly error description */ +"STYLE_NOT_FOUND_DESC" = "La carte n’a pas pu être chargée car le style n’a pas été trouvé ou est incompatible."; + /* Label of Zoom In button */ "ZOOM_IN_LABEL" = "+"; -- cgit v1.2.1 From 9f2990d1677ad099cfb84eaca938de4132924868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 19 Jul 2017 00:53:01 -0700 Subject: [ios] Added Hungarian settings bundle --- platform/ios/framework/Settings.bundle/hu.lproj/Root.strings | 3 +++ platform/ios/ios.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 platform/ios/framework/Settings.bundle/hu.lproj/Root.strings diff --git a/platform/ios/framework/Settings.bundle/hu.lproj/Root.strings b/platform/ios/framework/Settings.bundle/hu.lproj/Root.strings new file mode 100644 index 0000000000..3d761f2b97 --- /dev/null +++ b/platform/ios/framework/Settings.bundle/hu.lproj/Root.strings @@ -0,0 +1,3 @@ +"TELEMETRY_GROUP_TITLE" = "Adatvédelmi beállítások"; +"TELEMETRY_SWITCH_TITLE" = "Mapbox Telemetria"; +"TELEMETRY_GROUP_FOOTER" = "Ez a beállítás megengedi az alkalmazásnak, hogy névtelen helyzeti és használati adatokat osszon meg a Mapbox-szal."; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 7c6f1115c5..8ecbe0c6ab 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -903,6 +903,7 @@ DABCABBF1CB80717000A7C39 /* locations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = locations.cpp; sourceTree = ""; }; DABCABC01CB80717000A7C39 /* locations.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = locations.hpp; sourceTree = ""; }; DAC49C621CD07D74009E1AA3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = ""; }; + DACCD9C81F1F473700BB09A1 /* hu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Root.strings; sourceTree = ""; }; DAD165691CF41981001FF4B9 /* MGLFeature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFeature.h; sourceTree = ""; }; DAD1656A1CF41981001FF4B9 /* MGLFeature_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFeature_Private.h; sourceTree = ""; }; DAD1656B1CF41981001FF4B9 /* MGLFeature.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLFeature.mm; sourceTree = ""; }; @@ -2440,6 +2441,7 @@ DA618B1E1E688A3700CB7F44 /* ca */, DA618B2C1E68933600CB7F44 /* fi */, DAE8CCAE1E6E8C76009B5CB0 /* nl */, + DACCD9C81F1F473700BB09A1 /* hu */, ); name = Root.strings; sourceTree = ""; -- cgit v1.2.1 From af76efac22905be06d23567465e67da97d381a7e Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 6 Jul 2017 21:04:30 +0200 Subject: [android] - validate if platform implementation doesn't return a null motion event (#9434) --- .../main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index 3607703ab1..17eb506b97 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.maps; import android.content.Context; import android.graphics.PointF; import android.location.Location; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.view.GestureDetectorCompat; import android.support.v4.view.ScaleGestureDetectorCompat; @@ -134,7 +133,12 @@ final class MapGestureDetector { * @param event the MotionEvent * @return True if touch event is handled */ - boolean onTouchEvent(@NonNull MotionEvent event) { + boolean onTouchEvent(MotionEvent event) { + // framework can return null motion events in edge cases #9432 + if (event == null) { + return false; + } + // Check and ignore non touch or left clicks if ((event.getButtonState() != 0) && (event.getButtonState() != MotionEvent.BUTTON_PRIMARY)) { return false; -- cgit v1.2.1 From 79f0cc3d812c95a02029749cb13900f31c6eb6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Thu, 6 Jul 2017 21:05:04 +0200 Subject: [android] - map's visible region fix #9427 (#9428) --- .../src/main/java/com/mapbox/mapboxsdk/maps/Projection.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java index ff466c436c..e0a634521b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java @@ -80,10 +80,10 @@ public class Projection { public VisibleRegion getVisibleRegion() { LatLngBounds.Builder builder = new LatLngBounds.Builder(); - float left = contentPadding[0]; - float right = nativeMapView.getWidth() - contentPadding[2]; - float top = contentPadding[1]; - float bottom = nativeMapView.getHeight() - contentPadding[3]; + float left = 0; + float right = nativeMapView.getWidth(); + float top = 0; + float bottom = nativeMapView.getHeight(); LatLng topLeft = fromScreenLocation(new PointF(left, top)); LatLng topRight = fromScreenLocation(new PointF(right, top)); -- cgit v1.2.1 From 0ce62a20c45b3a43629306b7728d474343520025 Mon Sep 17 00:00:00 2001 From: Pablo Guardiola Date: Thu, 6 Jul 2017 11:26:03 +0200 Subject: [android] Fix my location drawable getting tinted (#9410) * fix my location drawable tinted when setting mapbox_myLocationTintColor in xml issue (linking my location foreground drawables with my location foreground tint color and adding the possibility of setting an undefined my location foreground tint color) * link my location background drawable with my location background tint color and add the possibility of setting an undefined my location background tint color --- .../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 21 ++++++++------- .../mapboxsdk/maps/widgets/MyLocationView.java | 31 +++++++++++++++++----- .../maps/widgets/MyLocationViewSettings.java | 10 +++++-- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 2efed1b322..80b25bf0de 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Parcel; @@ -37,6 +36,7 @@ public class MapboxMapOptions implements Parcelable { private static final float FOUR_DP = 4f; private static final float NINETY_TWO_DP = 92f; + private static final int UNDEFINED_COLOR = -1; private CameraPosition cameraPosition; @@ -53,7 +53,7 @@ public class MapboxMapOptions implements Parcelable { private int[] logoMargins; @ColorInt - private int attributionTintColor = -1; + private int attributionTintColor = UNDEFINED_COLOR; private boolean attributionEnabled = true; private int attributionGravity = Gravity.BOTTOM; private int[] attributionMargins; @@ -72,8 +72,10 @@ public class MapboxMapOptions implements Parcelable { private Drawable myLocationForegroundDrawable; private Drawable myLocationForegroundBearingDrawable; private Drawable myLocationBackgroundDrawable; - private int myLocationForegroundTintColor; - private int myLocationBackgroundTintColor; + @ColorInt + private int myLocationForegroundTintColor = UNDEFINED_COLOR; + @ColorInt + private int myLocationBackgroundTintColor = UNDEFINED_COLOR; private int[] myLocationBackgroundPadding; private int myLocationAccuracyTintColor; private int myLocationAccuracyAlpha; @@ -234,7 +236,7 @@ public class MapboxMapOptions implements Parcelable { FOUR_DP * pxlRatio))}); mapboxMapOptions.attributionTintColor(typedArray.getColor( - R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, -1)); + R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, UNDEFINED_COLOR)); mapboxMapOptions.attributionEnabled(typedArray.getBoolean( R.styleable.mapbox_MapView_mapbox_uiAttribution, true)); mapboxMapOptions.attributionGravity(typedArray.getInt( @@ -251,10 +253,9 @@ public class MapboxMapOptions implements Parcelable { mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_myLocation, false)); mapboxMapOptions.myLocationForegroundTintColor( - typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationTintColor, - ColorUtils.getPrimaryColor(context))); + typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationTintColor, UNDEFINED_COLOR)); mapboxMapOptions.myLocationBackgroundTintColor( - typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundTintColor, Color.WHITE)); + typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundTintColor, UNDEFINED_COLOR)); Drawable foregroundDrawable = typedArray.getDrawable(R.styleable.mapbox_MapView_mapbox_myLocationDrawable); if (foregroundDrawable == null) { @@ -638,7 +639,7 @@ public class MapboxMapOptions implements Parcelable { /** * Set the background tint color of MyLocationView. * - * @param myLocationBackgroundTintColor the color to tint the background + * @param myLocationBackgroundTintColor the color to tint the background drawable * @return This */ public MapboxMapOptions myLocationBackgroundTintColor(@ColorInt int myLocationBackgroundTintColor) { @@ -944,6 +945,7 @@ public class MapboxMapOptions implements Parcelable { * * @return the tint color */ + @ColorInt public int getMyLocationForegroundTintColor() { return myLocationForegroundTintColor; } @@ -953,6 +955,7 @@ public class MapboxMapOptions implements Parcelable { * * @return the tint color */ + @ColorInt public int getMyLocationBackgroundTintColor() { return myLocationBackgroundTintColor; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 8b6b93e03a..24da59bb7e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -51,6 +51,7 @@ import timber.log.Timber; */ public class MyLocationView extends View { + private static final int UNDEFINED_TINT_COLOR = -1; private MyLocationBehavior myLocationBehavior; private MapboxMap mapboxMap; @@ -198,12 +199,8 @@ public class MyLocationView extends View { * @param color The color to tint the drawable with */ public final void setForegroundDrawableTint(@ColorInt int color) { - if (foregroundDrawable != null) { - foregroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); - } - if (foregroundBearingDrawable != null) { - foregroundBearingDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); - } + applyDrawableTint(foregroundDrawable, color); + applyDrawableTint(foregroundBearingDrawable, color); invalidate(); } @@ -247,7 +244,7 @@ public class MyLocationView extends View { if (backgroundDrawable == null) { return; } - backgroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); + applyDrawableTint(backgroundDrawable, color); invalidate(); } @@ -737,6 +734,26 @@ public class MyLocationView extends View { setEnabled(isEnabled(), locationSource != null); } + private void applyDrawableTint(Drawable drawable, @ColorInt int color) { + if (color == UNDEFINED_TINT_COLOR) { + removeTintColorFilter(drawable); + } else { + applyTintColorFilter(drawable, color); + } + } + + private void removeTintColorFilter(Drawable drawable) { + if (drawable != null) { + drawable.mutate().setColorFilter(null); + } + } + + private void applyTintColorFilter(Drawable drawable, @ColorInt int color) { + if (drawable != null) { + drawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); + } + } + private static class GpsLocationListener implements LocationEngineListener { private WeakReference userLocationView; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java index 2ad1bf7ebc..fe2f18e4dd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java @@ -119,6 +119,7 @@ public class MyLocationViewSettings { *

* The foreground drawable is the image visible on screen *

+ * It's linked with the foreground tint color * * @param foregroundDrawable the drawable to show as foreground without bearing * @param foregroundBearingDrawable the drawable to show as foreground when bearing is enabled @@ -127,6 +128,7 @@ public class MyLocationViewSettings { this.foregroundDrawable = foregroundDrawable; this.foregroundBearingDrawable = foregroundBearingDrawable; myLocationView.setForegroundDrawables(foregroundDrawable, foregroundBearingDrawable); + myLocationView.setForegroundDrawableTint(foregroundTintColor); } /** @@ -153,7 +155,8 @@ public class MyLocationViewSettings { * The color will tint both the foreground and the bearing foreground drawable. *

* - * @param foregroundTintColor the color to tint the foreground drawable + * @param foregroundTintColor the color to tint the foreground drawable or -1 (undefined color) to remove the + * existing foreground tint color */ public void setForegroundTintColor(@ColorInt int foregroundTintColor) { this.foregroundTintColor = foregroundTintColor; @@ -174,6 +177,7 @@ public class MyLocationViewSettings { *

* Padding can be added to provide an offset to the background *

+ * It's linked with the background tint color * * @param backgroundDrawable the drawable to show as background * @param padding the padding added to the background @@ -186,6 +190,7 @@ public class MyLocationViewSettings { } else { myLocationView.setShadowDrawable(backgroundDrawable); } + myLocationView.setShadowDrawableTint(backgroundTintColor); } /** @@ -200,7 +205,8 @@ public class MyLocationViewSettings { /** * Set the background tint color. * - * @param backgroundTintColor the color to tint the background + * @param backgroundTintColor the color to tint the background drawable or -1 (undefined color) to remove the + * existing background tint color */ public void setBackgroundTintColor(@ColorInt int backgroundTintColor) { this.backgroundTintColor = backgroundTintColor; -- cgit v1.2.1 From 23210cb15c39c3742defe11338d85edbcc2c8220 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 18 Jul 2017 15:34:36 +0200 Subject: [android] - bump OkHttp dependency to avoid null pointer exceptions on Android 7.0 (#9522) --- platform/android/dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/dependencies.gradle b/platform/android/dependencies.gradle index 500b99def6..3d8f48b46b 100644 --- a/platform/android/dependencies.gradle +++ b/platform/android/dependencies.gradle @@ -47,7 +47,7 @@ ext { // square crew timber : 'com.jakewharton.timber:timber:4.5.1', - okhttp3 : 'com.squareup.okhttp3:okhttp:3.7.0', + okhttp3 : 'com.squareup.okhttp3:okhttp:3.8.0', leakCanaryDebug : "com.squareup.leakcanary:leakcanary-android:${leakCanaryVersion}", leakCanaryRelease : "com.squareup.leakcanary:leakcanary-android-no-op:${leakCanaryVersion}", leakCanaryTest : "com.squareup.leakcanary:leakcanary-android-no-op:${leakCanaryVersion}" -- cgit v1.2.1 From 655e23269542c63b2ca32692aea9f8782c09cf59 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 18 Jul 2017 12:32:40 +0200 Subject: [android] - fine tune fling gesture (#9532) --- .../src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 2 +- platform/android/src/native_map_view.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index 17eb506b97..c1e997c3a1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -370,7 +370,7 @@ final class MapGestureDetector { // tilt results in a bigger translation, limiting input for #5281 double tilt = transform.getTilt(); - double tiltFactor = 1 + ((tilt != 0) ? (tilt / 10) : 0); /* 1 -> 7 */ + double tiltFactor = 1.5 + ((tilt != 0) ? (tilt / 10) : 0); double offsetX = velocityX / tiltFactor / screenDensity; double offsetY = velocityY / tiltFactor / screenDensity; diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 5b0825fa09..159ba70508 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -371,7 +371,7 @@ void NativeMapView::moveBy(jni::JNIEnv&, jni::jdouble dx, jni::jdouble dy, jni:: mbgl::AnimationOptions animationOptions; if (duration > 0) { animationOptions.duration.emplace(mbgl::Milliseconds(duration)); - animationOptions.easing.emplace(mbgl::util::UnitBezier { 0, 0.3, 0.6, 1.0 }); + animationOptions.easing.emplace(mbgl::util::UnitBezier {0.25, 0.46, 0.45, 0.94}); } map->moveBy({dx, dy}, animationOptions); } -- cgit v1.2.1 From 9c73d3458dfe70187209562c60a73081648e1015 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 7 Jul 2017 12:28:19 +0200 Subject: Hit test Marker and MarkerViews (#9424) * [android] - hit test Marker and MarkerViews * fixup --- .../mapbox/mapboxsdk/maps/AnnotationManager.java | 199 +++++++++++++-------- .../com/mapbox/mapboxsdk/maps/IconManager.java | 4 + .../mapbox/mapboxsdk/maps/MapGestureDetector.java | 2 +- .../src/main/res/drawable/ic_check_box.xml | 9 + 4 files changed, 140 insertions(+), 74 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_check_box.xml diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index 3694668a7e..392eededdc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -1,10 +1,13 @@ package com.mapbox.mapboxsdk.maps; +import android.graphics.Bitmap; import android.graphics.PointF; +import android.graphics.Rect; import android.graphics.RectF; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.util.LongSparseArray; +import android.view.View; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; @@ -19,7 +22,6 @@ import com.mapbox.mapboxsdk.annotations.Polyline; import com.mapbox.mapboxsdk.annotations.PolylineOptions; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import timber.log.Timber; @@ -55,7 +57,7 @@ class AnnotationManager { this.markerViewManager = markerViewManager; if (view != null) { // null checking needed for unit tests - nativeMapView.addOnMapChangedListener(markerViewManager); + view.addOnMapChangedListener(markerViewManager); } } @@ -616,84 +618,135 @@ class AnnotationManager { // Click event // - boolean onTap(PointF tapPoint, float screenDensity) { - float toleranceSides = 4 * screenDensity; - float toleranceTopBottom = 10 * screenDensity; - boolean handledDefaultClick = false; - - RectF tapRect = new RectF(tapPoint.x - iconManager.getAverageIconWidth() / 2 - toleranceSides, - tapPoint.y - iconManager.getAverageIconHeight() / 2 - toleranceTopBottom, - tapPoint.x + iconManager.getAverageIconWidth() / 2 + toleranceSides, - tapPoint.y + iconManager.getAverageIconHeight() / 2 + toleranceTopBottom); - - List nearbyMarkers = getMarkersInRect(tapRect); - long newSelectedMarkerId = -1; - - // find a Marker that isn't selected yet - if (nearbyMarkers.size() > 0) { - Collections.sort(nearbyMarkers); - for (Marker nearbyMarker : nearbyMarkers) { - boolean found = false; - for (Marker selectedMarker : selectedMarkers) { - if (selectedMarker.equals(nearbyMarker)) { - found = true; - } - } - if (!found) { - newSelectedMarkerId = nearbyMarker.getId(); - break; + boolean onTap(PointF tapPoint) { + MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint); + long markerId = new MarkerHitResolver(markerViewManager, mapboxMap.getProjection()).execute(markerHit); + return markerId >= 0 && isClickHandledForMarker(markerId); + } + + private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) { + int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2; + int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2; + final RectF tapRect = new RectF(tapPoint.x - averageIconWidthOffset, + tapPoint.y - averageIconHeightOffset, + tapPoint.x + averageIconWidthOffset, + tapPoint.y + averageIconHeightOffset + ); + return new MarkerHit(tapRect, getMarkersInRect(tapRect)); + } + + private boolean isClickHandledForMarker(long markerId) { + boolean handledDefaultClick; + Marker marker = (Marker) getAnnotation(markerId); + if (marker instanceof MarkerView) { + handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker); + } else { + handledDefaultClick = onClickMarker(marker); + } + + if (!handledDefaultClick) { + setMarkerSelectionState(marker); + } + return true; + } + + private boolean onClickMarker(Marker marker) { + return onMarkerClickListener != null && onMarkerClickListener.onMarkerClick(marker); + } + + private void setMarkerSelectionState(Marker marker) { + if (!selectedMarkers.contains(marker)) { + selectMarker(marker); + } else { + deselectMarker(marker); + } + } + + private static class MarkerHitResolver { + + private final MarkerViewManager markerViewManager; + private final Projection projection; + + private View view; + private Bitmap bitmap; + private PointF markerLocation; + + private Rect hitRectView = new Rect(); + private RectF hitRectMarker = new RectF(); + private RectF highestSurfaceIntersection = new RectF(); + + private long closestMarkerId = -1; + + MarkerHitResolver(@NonNull MarkerViewManager markerViewManager, @NonNull Projection projection) { + this.markerViewManager = markerViewManager; + this.projection = projection; + } + + public long execute(MarkerHit markerHit) { + resolveForMarkers(markerHit); + return closestMarkerId; + } + + private void resolveForMarkers(MarkerHit markerHit) { + for (Marker marker : markerHit.markers) { + if (marker instanceof MarkerView) { + resolveForMarkerView(markerHit, (MarkerView) marker); + } else { + resolveForMarker(markerHit, marker); } } } - // if unselected marker found - if (newSelectedMarkerId >= 0) { - List annotations = getAnnotations(); - int count = annotations.size(); - for (int i = 0; i < count; i++) { - Annotation annotation = annotations.get(i); - if (annotation instanceof Marker) { - if (annotation.getId() == newSelectedMarkerId) { - Marker marker = (Marker) annotation; - - if (marker instanceof MarkerView) { - handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker); - } else { - if (onMarkerClickListener != null) { - // end developer has provided a custom click listener - handledDefaultClick = onMarkerClickListener.onMarkerClick(marker); - } - } - - if (!handledDefaultClick) { - // only select marker if user didn't handle the click event themselves - selectMarker(marker); - } - - return true; - } - } + private void resolveForMarkerView(MarkerHit markerHit, MarkerView markerView) { + view = markerViewManager.getView(markerView); + if (view != null) { + view.getHitRect(hitRectView); + hitRectMarker = new RectF(hitRectView); + hitTestMarker(markerHit, markerView, hitRectMarker); } - } else if (nearbyMarkers.size() > 0) { - // we didn't find an unselected marker, check if we can close an already open markers - for (Marker nearbyMarker : nearbyMarkers) { - for (Marker selectedMarker : selectedMarkers) { - if (nearbyMarker.equals(selectedMarker)) { - if (nearbyMarker instanceof MarkerView) { - handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) nearbyMarker); - } else if (onMarkerClickListener != null) { - handledDefaultClick = onMarkerClickListener.onMarkerClick(nearbyMarker); - } - - if (!handledDefaultClick) { - // only deselect marker if user didn't handle the click event themselves - deselectMarker(nearbyMarker); - } - return true; - } + } + + private void resolveForMarker(MarkerHit markerHit, Marker marker) { + markerLocation = projection.toScreenLocation(marker.getPosition()); + bitmap = marker.getIcon().getBitmap(); + hitRectMarker.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); + hitRectMarker.offsetTo( + markerLocation.x - bitmap.getWidth() / 2, + markerLocation.y - bitmap.getHeight() / 2 + ); + hitTestMarker(markerHit, marker, hitRectMarker); + } + + private void hitTestMarker(MarkerHit markerHit, Marker marker, RectF hitRectMarker) { + if (hitRectMarker.contains(markerHit.getTapPointX(), markerHit.getTapPointY())) { + hitRectMarker.intersect(markerHit.tapRect); + if (isRectangleHighestSurfaceIntersection(hitRectMarker)) { + highestSurfaceIntersection = new RectF(hitRectMarker); + closestMarkerId = marker.getId(); } } } - return false; + + private boolean isRectangleHighestSurfaceIntersection(RectF rectF) { + return rectF.width() * rectF.height() > highestSurfaceIntersection.width() * highestSurfaceIntersection.height(); + } + } + + private static class MarkerHit { + private final RectF tapRect; + private final List markers; + + MarkerHit(RectF tapRect, List markers) { + this.tapRect = tapRect; + this.markers = markers; + } + + float getTapPointX() { + return tapRect.centerX(); + } + + float getTapPointY() { + return tapRect.centerY(); + } } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java index 9f4171aee8..b5da5f59aa 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java @@ -12,6 +12,8 @@ import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException; import java.util.ArrayList; import java.util.List; +import timber.log.Timber; + /** * Responsible for managing icons added to the Map. *

@@ -105,6 +107,8 @@ class IconManager { int iconSize = icons.size() + 1; averageIconHeight = averageIconHeight + (height - averageIconHeight) / iconSize; averageIconWidth = averageIconWidth + (width - averageIconWidth) / iconSize; + Timber.e("OnUpdateAverageSizeIcon with: %s %s", width, height); + Timber.e("OnUpdateAverageSizeIcon now: %s %s", averageIconWidth, averageIconHeight); } private void loadIcon(Icon icon) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index c1e997c3a1..d2973bf558 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -315,7 +315,7 @@ final class MapGestureDetector { @Override public boolean onSingleTapConfirmed(MotionEvent motionEvent) { PointF tapPoint = new PointF(motionEvent.getX(), motionEvent.getY()); - boolean tapHandled = annotationManager.onTap(tapPoint, uiSettings.getPixelRatio()); + boolean tapHandled = annotationManager.onTap(tapPoint); if (!tapHandled) { if (uiSettings.isDeselectMarkersOnTap()) { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_check_box.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_check_box.xml new file mode 100644 index 0000000000..cf8bfa24b5 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_check_box.xml @@ -0,0 +1,9 @@ + + + -- cgit v1.2.1 From d7401f9e219e4607146cf1c34af23edb474348eb Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 18 Jul 2017 15:34:55 +0200 Subject: [android] - add OnPolygonClickListener and OnPolylineClickListener (#9443) --- .../mapbox/mapboxsdk/maps/AnnotationManager.java | 96 ++++++++++++++++++++-- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 50 +++++++++++ .../activity/annotation/PolygonActivity.java | 14 ++++ .../activity/annotation/PolylineActivity.java | 14 +++- 4 files changed, 164 insertions(+), 10 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index 392eededdc..404cc5f3bd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -9,6 +9,8 @@ import android.support.annotation.Nullable; import android.support.v4.util.LongSparseArray; import android.view.View; +import com.mapbox.mapboxsdk.Mapbox; +import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions; @@ -20,6 +22,7 @@ import com.mapbox.mapboxsdk.annotations.Polygon; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.Polyline; import com.mapbox.mapboxsdk.annotations.PolylineOptions; +import com.mapbox.services.commons.geojson.Feature; import java.util.ArrayList; import java.util.List; @@ -39,6 +42,8 @@ import timber.log.Timber; */ class AnnotationManager { + private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape."; + private final NativeMapView nativeMapView; private final MapView mapView; private final IconManager iconManager; @@ -46,9 +51,12 @@ class AnnotationManager { private final MarkerViewManager markerViewManager; private final LongSparseArray annotations = new LongSparseArray<>(); private final List selectedMarkers = new ArrayList<>(); + private final List shapeAnnotationIds = new ArrayList<>(); private MapboxMap mapboxMap; private MapboxMap.OnMarkerClickListener onMarkerClickListener; + private MapboxMap.OnPolygonClickListener onPolygonClickListener; + private MapboxMap.OnPolylineClickListener onPolylineClickListener; AnnotationManager(NativeMapView view, MapView mapView, MarkerViewManager markerViewManager) { this.nativeMapView = view; @@ -101,6 +109,9 @@ class AnnotationManager { if (marker instanceof MarkerView) { markerViewManager.removeMarkerView((MarkerView) marker); } + } else { + // instanceOf Polygon/Polyline + shapeAnnotationIds.remove(annotation.getId()); } long id = annotation.getId(); if (nativeMapView != null) { @@ -131,6 +142,9 @@ class AnnotationManager { if (marker instanceof MarkerView) { markerViewManager.removeMarkerView((MarkerView) marker); } + } else { + // instanceOf Polygon/Polyline + shapeAnnotationIds.remove(annotation.getId()); } ids[i] = annotationList.get(i).getId(); } @@ -158,6 +172,9 @@ class AnnotationManager { if (marker instanceof MarkerView) { markerViewManager.removeMarkerView((MarkerView) marker); } + } else { + // instanceOf Polygon/Polyline + shapeAnnotationIds.remove(annotation.getId()); } } @@ -244,7 +261,6 @@ class AnnotationManager { return marker; } - List addMarkerViews(@NonNull List markerViewOptions, @NonNull MapboxMap mapboxMap) { List markers = new ArrayList<>(); @@ -278,7 +294,6 @@ class AnnotationManager { Timber.w("Attempting to update non-added Marker with value %s", updatedMarker); return; } - ensureIconLoaded(updatedMarker); nativeMapView.updateMarker(updatedMarker); annotations.setValueAt(annotations.indexOfKey(updatedMarker.getId()), updatedMarker); @@ -310,6 +325,14 @@ class AnnotationManager { onMarkerClickListener = listener; } + void setOnPolygonClickListener(@Nullable MapboxMap.OnPolygonClickListener listener) { + onPolygonClickListener = listener; + } + + void setOnPolylineClickListener(@Nullable MapboxMap.OnPolylineClickListener listener) { + onPolylineClickListener = listener; + } + void selectMarker(@NonNull Marker marker) { if (selectedMarkers.contains(marker)) { return; @@ -374,7 +397,7 @@ class AnnotationManager { @NonNull List getMarkersInRect(@NonNull RectF rectangle) { - // convert Rectangle to be density depedent + // convert Rectangle to be density dependent float pixelRatio = nativeMapView.getPixelRatio(); RectF rect = new RectF(rectangle.left / pixelRatio, rectangle.top / pixelRatio, @@ -438,6 +461,7 @@ class AnnotationManager { long id = nativeMapView != null ? nativeMapView.addPolygon(polygon) : 0; polygon.setId(id); polygon.setMapboxMap(mapboxMap); + shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id); annotations.put(id, polygon); } return polygon; @@ -472,6 +496,7 @@ class AnnotationManager { id++; } polygon.setId(id); + shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id); annotations.put(id, polygon); } } @@ -510,6 +535,7 @@ class AnnotationManager { long id = nativeMapView != null ? nativeMapView.addPolyline(polyline) : 0; polyline.setMapboxMap(mapboxMap); polyline.setId(id); + shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id); annotations.put(id, polyline); } return polyline; @@ -546,6 +572,7 @@ class AnnotationManager { id++; } p.setId(id); + shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id); annotations.put(id, p); } } @@ -555,6 +582,7 @@ class AnnotationManager { void updatePolyline(@NonNull Polyline polyline) { if (!isAddedToMap(polyline)) { Timber.w("Attempting to update non-added Polyline with value %s", polyline); + return; } nativeMapView.updatePolyline(polyline); @@ -619,11 +647,37 @@ class AnnotationManager { // boolean onTap(PointF tapPoint) { + ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint); + long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit); + if (shapeAnnotationId >= 0) { + handleClickForShapeAnnotation(shapeAnnotationId); + } + MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint); - long markerId = new MarkerHitResolver(markerViewManager, mapboxMap.getProjection()).execute(markerHit); + long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit); return markerId >= 0 && isClickHandledForMarker(markerId); } + private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) { + float touchTargetSide = Mapbox.getApplicationContext().getResources().getDimension(R.dimen.mapbox_eight_dp); + RectF tapRect = new RectF( + tapPoint.x - touchTargetSide, + tapPoint.y - touchTargetSide, + tapPoint.x + touchTargetSide, + tapPoint.y + touchTargetSide + ); + return new ShapeAnnotationHit(tapRect, shapeAnnotationIds.toArray(new String[shapeAnnotationIds.size()])); + } + + private void handleClickForShapeAnnotation(long shapeAnnotationId) { + Annotation annotation = getAnnotation(shapeAnnotationId); + if (annotation instanceof Polygon && onPolygonClickListener != null) { + onPolygonClickListener.onPolygonClick((Polygon) annotation); + } else if (annotation instanceof Polyline && onPolylineClickListener != null) { + onPolylineClickListener.onPolylineClick((Polyline) annotation); + } + } + private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) { int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2; int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2; @@ -645,7 +699,7 @@ class AnnotationManager { } if (!handledDefaultClick) { - setMarkerSelectionState(marker); + toggleMarkerSelectionState(marker); } return true; } @@ -654,7 +708,7 @@ class AnnotationManager { return onMarkerClickListener != null && onMarkerClickListener.onMarkerClick(marker); } - private void setMarkerSelectionState(Marker marker) { + private void toggleMarkerSelectionState(Marker marker) { if (!selectedMarkers.contains(marker)) { selectMarker(marker); } else { @@ -662,6 +716,20 @@ class AnnotationManager { } } + private static class ShapeAnnotationHitResolver { + + private MapboxMap mapboxMap; + + ShapeAnnotationHitResolver(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + } + + public long execute(ShapeAnnotationHit shapeHit) { + List features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds); + return features.isEmpty() ? -1 : Long.valueOf(features.get(0).getId()); + } + } + private static class MarkerHitResolver { private final MarkerViewManager markerViewManager; @@ -677,9 +745,9 @@ class AnnotationManager { private long closestMarkerId = -1; - MarkerHitResolver(@NonNull MarkerViewManager markerViewManager, @NonNull Projection projection) { - this.markerViewManager = markerViewManager; - this.projection = projection; + MarkerHitResolver(@NonNull MapboxMap mapboxMap) { + this.markerViewManager = mapboxMap.getMarkerViewManager(); + this.projection = mapboxMap.getProjection(); } public long execute(MarkerHit markerHit) { @@ -732,6 +800,16 @@ class AnnotationManager { } } + private static class ShapeAnnotationHit { + private final RectF tapPoint; + private final String[] layerIds; + + ShapeAnnotationHit(RectF tapRect, String[] layerIds) { + this.tapPoint = tapRect; + this.layerIds = layerIds; + } + } + private static class MarkerHit { private final RectF tapRect; private final List markers; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index d672ab37c3..c8725d8d8d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -1459,6 +1459,28 @@ public final class MapboxMap { annotationManager.setOnMarkerClickListener(listener); } + /** + * Sets a callback that's invoked when the user clicks on a polygon. + * + * @param listener The callback that's invoked when the user clicks on a polygon. + * To unset the callback, use null. + */ + @UiThread + public void setOnPolygonClickListener(@Nullable OnPolygonClickListener listener) { + annotationManager.setOnPolygonClickListener(listener); + } + + /** + * Sets a callback that's invoked when the user clicks on a polyline. + * + * @param listener The callback that's invoked when the user clicks on a polyline. + * To unset the callback, use null. + */ + @UiThread + public void setOnPolylineClickListener(@Nullable OnPolylineClickListener listener) { + annotationManager.setOnPolylineClickListener(listener); + } + /** *

* Selects a marker. The selected marker will have it's info window opened. @@ -2150,6 +2172,34 @@ public final class MapboxMap { boolean onMarkerClick(@NonNull Marker marker); } + /** + * Interface definition for a callback to be invoked when the user clicks on a polygon. + * + * @see MapboxMap#setOnPolygonClickListener(OnPolygonClickListener) + */ + public interface OnPolygonClickListener { + /** + * Called when the user clicks on a polygon. + * + * @param polygon The polygon the user clicked on. + */ + void onPolygonClick(@NonNull Polygon polygon); + } + + /** + * Interface definition for a callback to be invoked when the user clicks on a polyline. + * + * @see MapboxMap#setOnPolylineClickListener(OnPolylineClickListener) + */ + public interface OnPolylineClickListener { + /** + * Called when the user clicks on a polyline. + * + * @param polyline The polyline the user clicked on. + */ + void onPolylineClick(@NonNull Polyline polyline); + } + /** * Interface definition for a callback to be invoked when the user clicks on an info window. * diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java index b51d717f33..fecfe2a842 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java @@ -2,9 +2,11 @@ package com.mapbox.mapboxsdk.testapp.activity.annotation; import android.graphics.Color; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; +import android.widget.Toast; import com.mapbox.mapboxsdk.annotations.Polygon; import com.mapbox.mapboxsdk.annotations.PolygonOptions; @@ -77,6 +79,18 @@ public class PolygonActivity extends AppCompatActivity implements OnMapReadyCall @Override public void onMapReady(MapboxMap map) { mapboxMap = map; + + map.setOnPolygonClickListener(new MapboxMap.OnPolygonClickListener() { + @Override + public void onPolygonClick(@NonNull Polygon polygon) { + Toast.makeText( + PolygonActivity.this, + "You clicked on polygon with id = " + polygon.getId(), + Toast.LENGTH_SHORT + ).show(); + } + }); + polygon = mapboxMap.addPolygon(new PolygonOptions() .addAll(STAR_SHAPE_POINTS) .fillColor(BLUE_COLOR)); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java index 0aaa6127f4..b9dc39e5d4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java @@ -67,8 +67,20 @@ public class PolylineActivity extends AppCompatActivity { mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() { @Override - public void onMapReady(@NonNull MapboxMap mapboxMap) { + public void onMapReady(@NonNull final MapboxMap mapboxMap) { PolylineActivity.this.mapboxMap = mapboxMap; + + mapboxMap.setOnPolylineClickListener(new MapboxMap.OnPolylineClickListener() { + @Override + public void onPolylineClick(@NonNull Polyline polyline) { + Toast.makeText( + PolylineActivity.this, + "You clicked on polygon with id = " + polyline.getId(), + Toast.LENGTH_SHORT + ).show(); + } + }); + polylines = mapboxMap.addPolylines(polylineOptions); } }); -- cgit v1.2.1 From 108cbc7ba58b3597b779029323e56b54f29546f0 Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Thu, 20 Jul 2017 11:44:53 +0200 Subject: [android] - update changelog for 5.1.1 --- platform/android/CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 0a3615d805..33ac486964 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -4,6 +4,16 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to ## 5.1.1 - TBA +* Rework attribution binding [#9433](https://github.com/mapbox/mapbox-gl-native/pull/9433) +* BackendScope changes [#9538](https://github.com/mapbox/mapbox-gl-native/pull/9538) +* Invisible MarkerView performance fix [#9420](https://github.com/mapbox/mapbox-gl-native/pull/9420) +* Polyline/Polygon click listeners [#9443](https://github.com/mapbox/mapbox-gl-native/pull/9443) +* Hit test Marker/MarkerViews [#9424](https://github.com/mapbox/mapbox-gl-native/pull/9424) +* Fine tune fling gesture [#9532](https://github.com/mapbox/mapbox-gl-native/pull/9532) +* Bump OkHttp 3.8.0, Android 7.x crashes [#9522](https://github.com/mapbox/mapbox-gl-native/pull/9522) +* MyLocationView tint fix [#9410](https://github.com/mapbox/mapbox-gl-native/pull/9410) +* VisibleRegion logic [#9428](https://github.com/mapbox/mapbox-gl-native/pull/9428) +* Validate motion event [#9434](https://github.com/mapbox/mapbox-gl-native/pull/9434) * Add French localization [#9545](https://github.com/mapbox/mapbox-gl-native/pull/9545) ## 5.1.0 - June 30, 2017 -- cgit v1.2.1 From a39b4cfb00c567d93bb83390d9bbdccef12b1c65 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 20 Jul 2017 17:26:28 +0200 Subject: [android] - manage InfoWindow selection in AnnotationManager (#9567) --- .../java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java index dce6f6b277..8704e882ea 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java @@ -570,11 +570,6 @@ public class MarkerViewManager implements MapView.OnMapChangedListener { clickHandled = onMarkerViewClickListener.onMarkerClick(markerView, view, adapter); } - if (!clickHandled) { - ensureInfoWindowOffset(markerView); - select(markerView, view, adapter); - } - return clickHandled; } -- cgit v1.2.1 From 820c04efbfa5c7e30bf5ff055538ccdd6e11b14d Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 20 Jul 2017 16:51:27 +0200 Subject: [android] - increase touch target to match largest Marker icon (#9565) --- .../mapbox/mapboxsdk/maps/AnnotationManager.java | 12 +++---- .../com/mapbox/mapboxsdk/maps/IconManager.java | 42 +++++++++++----------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index 404cc5f3bd..f35eb9b4f0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -679,12 +679,12 @@ class AnnotationManager { } private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) { - int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2; - int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2; - final RectF tapRect = new RectF(tapPoint.x - averageIconWidthOffset, - tapPoint.y - averageIconHeightOffset, - tapPoint.x + averageIconWidthOffset, - tapPoint.y + averageIconHeightOffset + int touchSurfaceWidth = (int) (iconManager.getHighestIconHeight() * 1.5); + int touchSurfaceHeight = (int) (iconManager.getHighestIconWidth() * 1.5); + final RectF tapRect = new RectF(tapPoint.x - touchSurfaceWidth, + tapPoint.y - touchSurfaceHeight, + tapPoint.x + touchSurfaceWidth, + tapPoint.y + touchSurfaceHeight ); return new MarkerHit(tapRect, getMarkersInRect(tapRect)); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java index b5da5f59aa..18eecfd9c3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java @@ -12,8 +12,6 @@ import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException; import java.util.ArrayList; import java.util.List; -import timber.log.Timber; - /** * Responsible for managing icons added to the Map. *

@@ -30,8 +28,8 @@ class IconManager { private NativeMapView nativeMapView; private List icons; - private int averageIconHeight; - private int averageIconWidth; + private int highestIconWidth; + private int highestIconHeight; IconManager(NativeMapView nativeMapView) { this.nativeMapView = nativeMapView; @@ -47,7 +45,7 @@ class IconManager { // TODO we can move this code afterwards to getIcon as with MarkerView.getIcon icon = loadDefaultIconForMarker(marker); } else { - updateAverageIconSize(icon); + updateHighestIconSize(icon); } addIcon(icon); return icon; @@ -56,7 +54,7 @@ class IconManager { void loadIconForMarkerView(MarkerView marker) { Icon icon = marker.getIcon(); Bitmap bitmap = icon.getBitmap(); - updateAverageIconSize(bitmap); + updateHighestIconSize(bitmap); addIcon(icon, false); } @@ -64,18 +62,18 @@ class IconManager { return (int) (nativeMapView.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMapView.getPixelRatio()); } - int getAverageIconHeight() { - return averageIconHeight; + int getHighestIconWidth() { + return highestIconWidth; } - int getAverageIconWidth() { - return averageIconWidth; + int getHighestIconHeight() { + return highestIconHeight; } private Icon loadDefaultIconForMarker(Marker marker) { Icon icon = IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarker(); Bitmap bitmap = icon.getBitmap(); - updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight() / 2); + updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight() / 2); marker.setIcon(icon); return icon; } @@ -95,20 +93,22 @@ class IconManager { } } - private void updateAverageIconSize(Icon icon) { - updateAverageIconSize(icon.getBitmap()); + private void updateHighestIconSize(Icon icon) { + updateHighestIconSize(icon.getBitmap()); } - private void updateAverageIconSize(Bitmap bitmap) { - updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight()); + private void updateHighestIconSize(Bitmap bitmap) { + updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight()); } - private void updateAverageIconSize(int width, int height) { - int iconSize = icons.size() + 1; - averageIconHeight = averageIconHeight + (height - averageIconHeight) / iconSize; - averageIconWidth = averageIconWidth + (width - averageIconWidth) / iconSize; - Timber.e("OnUpdateAverageSizeIcon with: %s %s", width, height); - Timber.e("OnUpdateAverageSizeIcon now: %s %s", averageIconWidth, averageIconHeight); + private void updateHighestIconSize(int width, int height) { + if (width > highestIconWidth) { + highestIconWidth = width; + } + + if (height > highestIconHeight) { + highestIconHeight = height; + } } private void loadIcon(Icon icon) { -- cgit v1.2.1 From b34a5ab276145dd5499133738caf0e8d6d30ddb7 Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Thu, 20 Jul 2017 17:32:23 +0200 Subject: [android] - update change log, fix typo public xml --- platform/android/CHANGELOG.md | 4 ++++ .../android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 33ac486964..b2eaaa2a9c 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -15,6 +15,10 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to * VisibleRegion logic [#9428](https://github.com/mapbox/mapbox-gl-native/pull/9428) * Validate motion event [#9434](https://github.com/mapbox/mapbox-gl-native/pull/9434) * Add French localization [#9545](https://github.com/mapbox/mapbox-gl-native/pull/9545) +* Fix public.xml [#9525](https://github.com/mapbox/mapbox-gl-native/pull/9525/files) +* Manage InfoWindow selection in AnnotationManager [#9567](https://github.com/mapbox/mapbox-gl-native/pull/9567) +* Increase touch target size [#9565](https://github.com/mapbox/mapbox-gl-native/pull/9565) +* Work around Adreno 2xx GPU bugs [#9573](https://github.com/mapbox/mapbox-gl-native/pull/9573) ## 5.1.0 - June 30, 2017 diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index 7294f43c02..f30cb7c27a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -20,7 +20,7 @@ - + -- cgit v1.2.1 From ea337866e9870e95a977308f0926b15e25c7a0ce Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 21 Jul 2017 01:17:50 -0700 Subject: [core] Work around Adreno 2xx GPU bugs (#9573) --- src/mbgl/gl/context.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 19ea9a514f..e5609db7b8 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -564,6 +564,13 @@ void Context::setDrawMode(const TriangleStrip&) { void Context::setDepthMode(const DepthMode& depth) { if (depth.func == DepthMode::Always && !depth.mask) { depthTest = false; + + // Workaround for rendering errors on Adreno 2xx GPUs. Depth-related state should + // not matter when the depth test is disabled, but on these GPUs it apparently does. + // https://github.com/mapbox/mapbox-gl-native/issues/9164 + depthFunc = depth.func; + depthMask = depth.mask; + depthRange = depth.range; } else { depthTest = true; depthFunc = depth.func; -- cgit v1.2.1 From 7aad3613c3549ae5f4388fcbeef969e13274892b Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Fri, 21 Jul 2017 11:18:26 +0200 Subject: update release config --- circle.yml | 2 +- .../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 6bced990de..7d75427bcb 100644 --- a/circle.yml +++ b/circle.yml @@ -133,4 +133,4 @@ jobs: - deploy: name: Publish to Maven command: | - if [ "${CIRCLE_BRANCH}" == "release-ios-v3.6.0-android-v5.1.0" ]; then make run-android-upload-archives ; fi + if [ "${CIRCLE_BRANCH}" == "master" ]; then make run-android-upload-archives ; fi diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties index 029d25e046..a02b5d63ac 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties +++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties @@ -1,3 +1,3 @@ fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk -fabric-version=5.1.0 +fabric-version=5.1.1 fabric-build-type=binary -- cgit v1.2.1 From dcd9a38388fe5fc4c70a3e39af4db10a3c09ed49 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Mon, 24 Jul 2017 19:24:24 -0400 Subject: [ios] Don't force the attribution button tint color to update --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.mm | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 93da2ff372..9ebf52311f 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ## 3.6.1 * Reduced the size of the dynamic framework by optimizing symbol visibility. ([#7604](https://github.com/mapbox/mapbox-gl-native/pull/7604)) +* Fixed an issue where the attribution button would have its custom tint color reset when the map view received a tint color change notification, such as when an alert controller was presented. ([#9598](https://github.com/mapbox/mapbox-gl-native/pull/9598)) ## 3.6.0 - June 29, 2017 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index f3b0d8506a..2de1496998 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1144,8 +1144,10 @@ public: - (void)updateTintColorForView:(UIView *)view { - // stop at recursing container & annotation views (#8522) - if ([view isEqual:self.annotationContainerView]) return; + // Don't update: + // - annotation views + // - attribution button (handled automatically) + if ([view isEqual:self.annotationContainerView] || [view isEqual:self.attributionButton]) return; if ([view respondsToSelector:@selector(setTintColor:)]) view.tintColor = self.tintColor; -- cgit v1.2.1 From 612a1e8377834211a273b30aff51839a219b5b73 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Fri, 14 Jul 2017 21:40:40 -0400 Subject: [build] Remove unused iOS 'self contained' static framework packaging This was a faux framework once required by Fabric. --- platform/ios/scripts/package.sh | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/platform/ios/scripts/package.sh b/platform/ios/scripts/package.sh index e4403c4652..6222ee0f9f 100755 --- a/platform/ios/scripts/package.sh +++ b/platform/ios/scripts/package.sh @@ -21,33 +21,17 @@ elif [[ ${FORMAT} == "dynamic" ]]; then BUILD_STATIC=false fi -SELF_CONTAINED=${SELF_CONTAINED:-} -STATIC_BUNDLE_DIR= -if [[ ${SELF_CONTAINED} ]]; then - STATIC_BUNDLE_DIR="${OUTPUT}/static/${NAME}.framework" -else - STATIC_BUNDLE_DIR="${OUTPUT}/static" -fi - -STATIC_SETTINGS_DIR= -if [[ ${SELF_CONTAINED} ]]; then - STATIC_SETTINGS_DIR="${OUTPUT}/static/${NAME}.framework" -else - STATIC_SETTINGS_DIR="${OUTPUT}" -fi - SDK=iphonesimulator if [[ ${BUILD_FOR_DEVICE} == true ]]; then SDK=iphoneos fi IOS_SDK_VERSION=`xcrun --sdk ${SDK} --show-sdk-version` -echo "Configuring ${FORMAT:-dynamic and static} ${BUILDTYPE} framework for ${SDK}; symbols: ${SYMBOLS}; self-contained static framework: ${SELF_CONTAINED:-NO}" - function step { >&2 echo -e "\033[1m\033[36m* $@\033[0m"; } function finish { >&2 echo -en "\033[0m"; } trap finish EXIT +step "Configuring ${FORMAT:-dynamic and static} ${BUILDTYPE} framework for ${SDK}; symbols: ${SYMBOLS}" rm -rf ${OUTPUT} if [[ ${BUILD_STATIC} == true ]]; then @@ -69,7 +53,7 @@ PROJ_VERSION=$(git rev-list --count HEAD) SEM_VERSION=$( git describe --tags --match=ios-v*.*.* --abbrev=0 | sed 's/^ios-v//' ) SHORT_VERSION=${SEM_VERSION%-*} -step "Building targets (build ${PROJ_VERSION}, version ${SEM_VERSION})…" +step "Building targets (build ${PROJ_VERSION}, version ${SEM_VERSION})" SCHEME='dynamic' if [[ ${BUILD_DYNAMIC} == true && ${BUILD_STATIC} == true ]]; then @@ -78,6 +62,7 @@ elif [[ ${BUILD_STATIC} == true ]]; then SCHEME='static' fi +step "Building for iOS Simulator using scheme ${SCHEME}" xcodebuild \ CURRENT_PROJECT_VERSION=${PROJ_VERSION} \ CURRENT_SHORT_VERSION=${SHORT_VERSION} \ @@ -92,6 +77,7 @@ xcodebuild \ -jobs ${JOBS} | xcpretty if [[ ${BUILD_FOR_DEVICE} == true ]]; then + step "Building for iOS devices using scheme ${SCHEME}" xcodebuild \ CURRENT_PROJECT_VERSION=${PROJ_VERSION} \ CURRENT_SHORT_VERSION=${SHORT_VERSION} \ @@ -119,7 +105,7 @@ if [[ ${BUILD_FOR_DEVICE} == true ]]; then ${LIBS[@]/#/${PRODUCTS}/${BUILDTYPE}-iphonesimulator/lib} \ `cmake -LA -N ${DERIVED_DATA} | grep MASON_PACKAGE_icu_LIBRARIES | cut -d= -f2` - cp -rv ${PRODUCTS}/${BUILDTYPE}-iphoneos/${NAME}.bundle ${STATIC_BUNDLE_DIR} + cp -rv ${PRODUCTS}/${BUILDTYPE}-iphoneos/${NAME}.bundle ${OUTPUT}/static fi if [[ ${BUILD_DYNAMIC} == true ]]; then @@ -149,7 +135,7 @@ if [[ ${BUILD_FOR_DEVICE} == true ]]; then -create -output ${OUTPUT}/dynamic/${NAME}.framework/${NAME} | echo fi - cp -rv ${PRODUCTS}/${BUILDTYPE}-iphoneos/Settings.bundle ${STATIC_SETTINGS_DIR} + cp -rv ${PRODUCTS}/${BUILDTYPE}-iphoneos/Settings.bundle ${OUTPUT} else if [[ ${BUILD_STATIC} == true ]]; then step "Assembling static library for iOS Simulator…" @@ -159,7 +145,7 @@ else ${LIBS[@]/#/${PRODUCTS}/${BUILDTYPE}-iphonesimulator/lib} \ `cmake -LA -N ${DERIVED_DATA} | grep MASON_PACKAGE_icu_LIBRARIES | cut -d= -f2` - cp -rv ${PRODUCTS}/${BUILDTYPE}-iphonesimulator/${NAME}.bundle ${STATIC_BUNDLE_DIR} + cp -rv ${PRODUCTS}/${BUILDTYPE}-iphonesimulator/${NAME}.bundle ${OUTPUT}/static fi if [[ ${BUILD_DYNAMIC} == true ]]; then @@ -174,7 +160,7 @@ else fi fi - cp -rv ${PRODUCTS}/${BUILDTYPE}-iphonesimulator/Settings.bundle ${STATIC_SETTINGS_DIR} + cp -rv ${PRODUCTS}/${BUILDTYPE}-iphonesimulator/Settings.bundle ${OUTPUT} fi if [[ ${SYMBOLS} = NO ]]; then @@ -244,9 +230,9 @@ if [[ ${BUILD_STATIC} == true ]]; then fi step "Copying library resources…" -cp -pv LICENSE.md ${STATIC_SETTINGS_DIR} +cp -pv LICENSE.md ${OUTPUT} if [[ ${BUILD_STATIC} == true ]]; then - cp -pv "${STATIC_BUNDLE_DIR}/${NAME}.bundle/Info.plist" "${OUTPUT}/static/${NAME}.framework/Info.plist" + cp -pv "${OUTPUT}/static/${NAME}.bundle/Info.plist" "${OUTPUT}/static/${NAME}.framework/Info.plist" plutil -replace CFBundlePackageType -string FMWK "${OUTPUT}/static/${NAME}.framework/Info.plist" mkdir "${OUTPUT}/static/${NAME}.framework/Modules" cp -pv platform/ios/framework/modulemap "${OUTPUT}/static/${NAME}.framework/Modules/module.modulemap" -- cgit v1.2.1 From 82c2d4b3ca76c6b73564cd96d93ebd39969eb820 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 25 Jul 2017 23:58:21 -0400 Subject: [build] Include bcsymbolmap files in iOS dynamic framework package --- platform/ios/CHANGELOG.md | 1 + platform/ios/scripts/package.sh | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 9ebf52311f..63e6a4d398 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Reduced the size of the dynamic framework by optimizing symbol visibility. ([#7604](https://github.com/mapbox/mapbox-gl-native/pull/7604)) * Fixed an issue where the attribution button would have its custom tint color reset when the map view received a tint color change notification, such as when an alert controller was presented. ([#9598](https://github.com/mapbox/mapbox-gl-native/pull/9598)) +* Bitcode symbol maps (.bcsymbolmap files) are now included with the dynamic framework. ([#9613](https://github.com/mapbox/mapbox-gl-native/pull/9613)) ## 3.6.0 - June 29, 2017 diff --git a/platform/ios/scripts/package.sh b/platform/ios/scripts/package.sh index 6222ee0f9f..a5e2f87e20 100755 --- a/platform/ios/scripts/package.sh +++ b/platform/ios/scripts/package.sh @@ -237,6 +237,10 @@ if [[ ${BUILD_STATIC} == true ]]; then mkdir "${OUTPUT}/static/${NAME}.framework/Modules" cp -pv platform/ios/framework/modulemap "${OUTPUT}/static/${NAME}.framework/Modules/module.modulemap" fi +if [[ ${BUILD_DYNAMIC} == true && ${BUILD_FOR_DEVICE} == true ]]; then + step "Copying bitcode symbol maps…" + find "${PRODUCTS}/${BUILDTYPE}-iphoneos" -name '*.bcsymbolmap' -type f -exec cp -pv {} "${OUTPUT}/dynamic/" \; +fi sed -n -e '/^## /,$p' platform/ios/CHANGELOG.md > "${OUTPUT}/CHANGELOG.md" rm -rf /tmp/mbgl -- cgit v1.2.1 From fa0b307680aa47537e04f48134c8a38c2cb7e17c Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Thu, 27 Jul 2017 09:20:40 -0400 Subject: [android] Disable program caching on Adreno 3xx, 4xx, and 5xx GPUs due to known bugs (#9625) --- src/mbgl/gl/context.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index e5609db7b8..a530528da1 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -203,7 +203,21 @@ bool Context::supportsVertexArrays() const { #if MBGL_HAS_BINARY_PROGRAMS bool Context::supportsProgramBinaries() const { - return programBinary && programBinary->programBinary && programBinary->getProgramBinary; + if (!programBinary || !programBinary->programBinary || !programBinary->getProgramBinary) { + return false; + } + + // Blacklist Adreno 3xx, 4xx, and 5xx GPUs due to known bugs: + // https://bugs.chromium.org/p/chromium/issues/detail?id=510637 + // https://chromium.googlesource.com/chromium/src/gpu/+/master/config/gpu_driver_bug_list.json#2316 + const std::string renderer = reinterpret_cast(glGetString(GL_RENDERER)); + if (renderer.find("Adreno (TM) 3") != std::string::npos + || renderer.find("Adreno (TM) 4") != std::string::npos + || renderer.find("Adreno (TM) 5") != std::string::npos) { + return false; + } + + return true; } optional> -- cgit v1.2.1 From 0cdef85798f7d2f78a732bb637f378560c1dce58 Mon Sep 17 00:00:00 2001 From: danielamitaysc Date: Mon, 24 Jul 2017 15:32:39 -0400 Subject: [ios] Proper limiting behavior when trying to zoom out fully - Bail from quick zoom if new zoom is same as old zoom - Allow pinch gesture at minZoom to still move the map --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.mm | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 63e6a4d398..a8efb491dd 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Reduced the size of the dynamic framework by optimizing symbol visibility. ([#7604](https://github.com/mapbox/mapbox-gl-native/pull/7604)) * Fixed an issue where the attribution button would have its custom tint color reset when the map view received a tint color change notification, such as when an alert controller was presented. ([#9598](https://github.com/mapbox/mapbox-gl-native/pull/9598)) +* Improved the behavior of zoom gestures when the map reaches the minimum zoom limit. ([#9626](https://github.com/mapbox/mapbox-gl-native/pull/9626)) * Bitcode symbol maps (.bcsymbolmap files) are now included with the dynamic framework. ([#9613](https://github.com/mapbox/mapbox-gl-native/pull/9613)) ## 3.6.0 - June 29, 2017 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 2de1496998..3db0bc03b2 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1280,8 +1280,6 @@ public: { if ( ! self.isZoomEnabled) return; - if (_mbglMap->getZoom() <= _mbglMap->getMinZoom() && pinch.scale < 1) return; - _mbglMap->cancelTransitions(); CGPoint centerPoint = [self anchorPointForGesture:pinch]; @@ -1297,17 +1295,17 @@ public: } else if (pinch.state == UIGestureRecognizerStateChanged) { + // Zoom limiting happens at the core level. CGFloat newScale = self.scale * pinch.scale; - double zoom = log2(newScale); - if (zoom < _mbglMap->getMinZoom()) return; - + double newZoom = log2(newScale); + // Calculates the final camera zoom, has no effect within current map camera. - MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint]; + MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:newZoom aroundAnchorPoint:centerPoint]; if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] || [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera]) { - _mbglMap->setZoom(zoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }); + _mbglMap->setZoom(newZoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }); // The gesture recognizer only reports the gesture’s current center // point, so use the previous center point to anchor the transition. // If the number of touches has changed, the remembered center point is @@ -1655,9 +1653,9 @@ public: { CGFloat distance = [quickZoom locationInView:quickZoom.view].y - self.quickZoomStart; - CGFloat newZoom = log2f(self.scale) + (distance / 75); + CGFloat newZoom = MAX(log2f(self.scale) + (distance / 75), _mbglMap->getMinZoom()); - if (newZoom < _mbglMap->getMinZoom()) return; + if (_mbglMap->getZoom() == newZoom) return; CGPoint centerPoint = [self anchorPointForGesture:quickZoom]; -- cgit v1.2.1 From 6d629597d7e05684ece16ae4239f5ab06ec386e2 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Thu, 27 Jul 2017 15:16:39 -0700 Subject: [ios] Make tilt gesture recognizer recognizable only with two horizontal fingers (#9571) * [ios] Make tilt gesture recognizer recognizable only with two horizontal fingers * [ios] Make tilt gesture recognizer tolerance degree less restrictive --- platform/ios/src/MGLMapView.mm | 81 +++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 3db0bc03b2..8dbf26da55 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1788,39 +1788,6 @@ public: return [gesture locationInView:gesture.view]; } -- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer -{ - if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) - { - UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gestureRecognizer; - - if (panGesture.minimumNumberOfTouches == 2) - { - CGPoint velocity = [panGesture velocityInView:panGesture.view]; - double gestureAngle = MGLDegreesFromRadians(atan(velocity.y / velocity.x)); - double horizontalToleranceDegrees = 20.0; - - // cancel if gesture angle is not 90º±20º (more or less vertical) - if ( ! (fabs((fabs(gestureAngle) - 90.0)) < horizontalToleranceDegrees)) - { - return NO; - } - } - } - else if (gestureRecognizer == _singleTapGestureRecognizer) - { - // Gesture will be recognized if it could deselect an annotation - if(!self.selectedAnnotation) - { - idannotation = [self annotationForGestureRecognizer:(UITapGestureRecognizer*)gestureRecognizer persistingResults:NO]; - if(!annotation) { - return NO; - } - } - } - return YES; -} - - (void)handleCalloutAccessoryTapGesture:(UITapGestureRecognizer *)tap { if ([self.delegate respondsToSelector:@selector(mapView:annotation:calloutAccessoryControlTapped:)]) @@ -1864,12 +1831,60 @@ public: UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, calloutView); } +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer +{ + if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) + { + UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gestureRecognizer; + + if (panGesture.minimumNumberOfTouches == 2) + { + CGPoint west = [panGesture locationOfTouch:0 inView:panGesture.view]; + CGPoint east = [panGesture locationOfTouch:1 inView:panGesture.view]; + + if (west.x > east.x) { + CGPoint swap = west; + west = east; + east = swap; + } + + float horizontalToleranceDegrees = 60.0; + if ([self angleBetweenPoints:west east:east] > horizontalToleranceDegrees) { + return NO; + } + + } + } + else if (gestureRecognizer == _singleTapGestureRecognizer) + { + // Gesture will be recognized if it could deselect an annotation + if(!self.selectedAnnotation) + { + idannotation = [self annotationForGestureRecognizer:(UITapGestureRecognizer*)gestureRecognizer persistingResults:NO]; + if(!annotation) { + return NO; + } + } + } + return YES; +} + - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { NSArray *validSimultaneousGestures = @[ self.pan, self.pinch, self.rotate ]; return ([validSimultaneousGestures containsObject:gestureRecognizer] && [validSimultaneousGestures containsObject:otherGestureRecognizer]); } + +- (float)angleBetweenPoints:(CGPoint)west east:(CGPoint)east +{ + float slope = (west.y - east.y) / (west.x - east.x); + + float angle = atan(fabs(slope)); + float degrees = MGLDegreesFromRadians(angle); + + return degrees; +} - (void)trackGestureEvent:(NSString *)gestureID forRecognizer:(UIGestureRecognizer *)recognizer { -- cgit v1.2.1 From 5e6ca3ada217c84fa2f198e5de6bc89bc2c5874d Mon Sep 17 00:00:00 2001 From: Pablo Guardiola Date: Mon, 24 Jul 2017 12:08:20 +0200 Subject: [android] fix geojson source proguard issue (#9569) (#9577) --- platform/android/MapboxGLAndroidSDK/proguard-rules.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro index 8e47815451..68edc12f35 100644 --- a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro +++ b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro @@ -6,4 +6,5 @@ -keep class com.mapbox.mapboxsdk.** { *; } -keep interface com.mapbox.mapboxsdk.** { *; } -keep class com.mapbox.services.android.telemetry.** { *; } --keep class com.mapbox.services.commons.** { *;} \ No newline at end of file +-keep class com.mapbox.services.commons.** { *;} +-keep class com.google.gson.** { *; } \ No newline at end of file -- cgit v1.2.1 From 0eee31e212a9936bcfe0c61a3bf3635a8778a434 Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Mon, 24 Jul 2017 10:45:35 +0200 Subject: [android] - harden click handling of shape annotations --- .../mapbox/mapboxsdk/maps/AnnotationManager.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index f35eb9b4f0..ef794c8482 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -43,6 +43,7 @@ import timber.log.Timber; class AnnotationManager { private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape."; + private static final long NO_ANNOTATION_ID = -1; private final NativeMapView nativeMapView; private final MapView mapView; @@ -649,13 +650,13 @@ class AnnotationManager { boolean onTap(PointF tapPoint) { ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint); long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit); - if (shapeAnnotationId >= 0) { + if (shapeAnnotationId != NO_ANNOTATION_ID) { handleClickForShapeAnnotation(shapeAnnotationId); } MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint); long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit); - return markerId >= 0 && isClickHandledForMarker(markerId); + return markerId != NO_ANNOTATION_ID && isClickHandledForMarker(markerId); } private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) { @@ -725,8 +726,21 @@ class AnnotationManager { } public long execute(ShapeAnnotationHit shapeHit) { + long foundAnnotationId = NO_ANNOTATION_ID; List features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds); - return features.isEmpty() ? -1 : Long.valueOf(features.get(0).getId()); + if (!features.isEmpty()) { + foundAnnotationId = getIdFromFeature(features.get(0)); + } + return foundAnnotationId; + } + + private long getIdFromFeature(Feature feature) { + try { + return Long.valueOf(feature.getId()); + } catch (NumberFormatException exception) { + Timber.e(exception, "Couldn't parse feature id to a long, with id: %s", feature.getId()); + return NO_ANNOTATION_ID; + } } } @@ -743,7 +757,7 @@ class AnnotationManager { private RectF hitRectMarker = new RectF(); private RectF highestSurfaceIntersection = new RectF(); - private long closestMarkerId = -1; + private long closestMarkerId = NO_ANNOTATION_ID; MarkerHitResolver(@NonNull MapboxMap mapboxMap) { this.markerViewManager = mapboxMap.getMarkerViewManager(); -- cgit v1.2.1 From beaee9349f0608246547d9092b6690a80d633e6e Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Mon, 24 Jul 2017 11:05:29 +0200 Subject: [android] - validate Marker before opening InfoWindow --- .../main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java index 7599b6afa6..11100d6f17 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java @@ -1,6 +1,5 @@ package com.mapbox.mapboxsdk.maps; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; @@ -56,12 +55,8 @@ class InfoWindowManager { return allowConcurrentMultipleInfoWindows; } - List getInfoWindows() { - return infoWindows; - } - - boolean isInfoWindowValidForMarker(@NonNull Marker marker) { - return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet()); + boolean isInfoWindowValidForMarker(Marker marker) { + return marker != null && (!TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet())); } void setOnInfoWindowClickListener(@Nullable MapboxMap.OnInfoWindowClickListener listener) { -- cgit v1.2.1 From 635a3f21a0373335d4a334f5bb487251f027f47c Mon Sep 17 00:00:00 2001 From: Pablo Guardiola Date: Tue, 25 Jul 2017 13:01:31 +0200 Subject: [android] fix added to map checks because LongSparseArray#indexOfKey could return a negative number when the specified key is not mapped (#9602) --- .../src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index ef794c8482..251e5afabe 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -301,7 +301,7 @@ class AnnotationManager { } private boolean isAddedToMap(Annotation annotation) { - return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1; + return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) > -1; } private void ensureIconLoaded(Marker marker) { -- cgit v1.2.1 From 009da507fa780d111bb574154840a061ab284c8f Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Tue, 25 Jul 2017 12:50:36 +0200 Subject: [android] - don't query for shape annotations if none were added --- .../main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index 251e5afabe..712ab67de0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -648,10 +648,12 @@ class AnnotationManager { // boolean onTap(PointF tapPoint) { - ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint); - long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit); - if (shapeAnnotationId != NO_ANNOTATION_ID) { - handleClickForShapeAnnotation(shapeAnnotationId); + if (!shapeAnnotationIds.isEmpty()) { + ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint); + long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit); + if (shapeAnnotationId != NO_ANNOTATION_ID) { + handleClickForShapeAnnotation(shapeAnnotationId); + } } MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint); -- cgit v1.2.1 From 9b770f382ef7f1251f0f770175514345899101a8 Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Wed, 26 Jul 2017 16:45:49 +0200 Subject: [android] - build snapshots from release branch for v5.1.2 --- circle.yml | 2 +- platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 7d75427bcb..6bced990de 100644 --- a/circle.yml +++ b/circle.yml @@ -133,4 +133,4 @@ jobs: - deploy: name: Publish to Maven command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then make run-android-upload-archives ; fi + if [ "${CIRCLE_BRANCH}" == "release-ios-v3.6.0-android-v5.1.0" ]; then make run-android-upload-archives ; fi diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties index 078fdbc801..a8646e3270 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle.properties +++ b/platform/android/MapboxGLAndroidSDK/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.mapbox.mapboxsdk -VERSION_NAME=5.2.0-SNAPSHOT +VERSION_NAME=5.1.2-SNAPSHOT POM_DESCRIPTION=Mapbox GL Android SDK POM_URL=https://github.com/mapbox/mapbox-gl-native -- cgit v1.2.1 From caba393c0ec3042a3e8e7f1a782e0283d131a996 Mon Sep 17 00:00:00 2001 From: Pablo Guardiola Date: Thu, 27 Jul 2017 15:38:53 +0200 Subject: [android] fix compass direction (Transform::getCameraOptions returns counterclockwise angle after transform.invalidateCameraPosition() which needs to be transformed to a clockwise bearing) (#9632) --- .../src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index 7f8ba21e3e..3f43c23a7f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -421,7 +421,8 @@ public final class UiSettings { return; } - compassView.update(cameraPosition.bearing); + double clockwiseBearing = -cameraPosition.bearing; + compassView.update(clockwiseBearing); } /** -- cgit v1.2.1 From b0bae6d1dde4e8c3b0b0b50d4255e1073f36022a Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Fri, 28 Jul 2017 10:22:16 -0700 Subject: [ios] tilt gesture type fix (#9642) * [ios] Change function:angleBetweenPoints return type * [ios] Update changelog --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.mm | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index a8efb491dd..43df49a9ac 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Reduced the size of the dynamic framework by optimizing symbol visibility. ([#7604](https://github.com/mapbox/mapbox-gl-native/pull/7604)) * Fixed an issue where the attribution button would have its custom tint color reset when the map view received a tint color change notification, such as when an alert controller was presented. ([#9598](https://github.com/mapbox/mapbox-gl-native/pull/9598)) * Improved the behavior of zoom gestures when the map reaches the minimum zoom limit. ([#9626](https://github.com/mapbox/mapbox-gl-native/pull/9626)) +* Fixed an issue where tilt gesture was triggered with two fingers aligned vertically and panning down. ([#9571](https://github.com/mapbox/mapbox-gl-native/pull/9571)) * Bitcode symbol maps (.bcsymbolmap files) are now included with the dynamic framework. ([#9613](https://github.com/mapbox/mapbox-gl-native/pull/9613)) ## 3.6.0 - June 29, 2017 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 8dbf26da55..9cc4c42e5a 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1848,7 +1848,7 @@ public: east = swap; } - float horizontalToleranceDegrees = 60.0; + CLLocationDegrees horizontalToleranceDegrees = 60.0; if ([self angleBetweenPoints:west east:east] > horizontalToleranceDegrees) { return NO; } @@ -1876,12 +1876,12 @@ public: return ([validSimultaneousGestures containsObject:gestureRecognizer] && [validSimultaneousGestures containsObject:otherGestureRecognizer]); } -- (float)angleBetweenPoints:(CGPoint)west east:(CGPoint)east +- (CLLocationDegrees)angleBetweenPoints:(CGPoint)west east:(CGPoint)east { - float slope = (west.y - east.y) / (west.x - east.x); + CGFloat slope = (west.y - east.y) / (west.x - east.x); - float angle = atan(fabs(slope)); - float degrees = MGLDegreesFromRadians(angle); + CGFloat angle = atan(fabs(slope)); + CLLocationDegrees degrees = MGLDegreesFromRadians(angle); return degrees; } -- cgit v1.2.1 From 9a9c43308526dcb043981b68cc5d6e3aae8d987b Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Fri, 28 Jul 2017 10:35:24 -0700 Subject: [ios] Bump podspec to 3.6.1 --- platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec | 2 +- platform/ios/Mapbox-iOS-SDK-symbols.podspec | 2 +- platform/ios/Mapbox-iOS-SDK.podspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec b/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec index c7b14ead3b..db5ca23c16 100644 --- a/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec +++ b/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |m| - version = '3.6.0-alpha.1' + version = '3.6.1' m.name = 'Mapbox-iOS-SDK-nightly-dynamic' m.version = "#{version}-nightly" diff --git a/platform/ios/Mapbox-iOS-SDK-symbols.podspec b/platform/ios/Mapbox-iOS-SDK-symbols.podspec index d2a686f1fb..be4d469f70 100644 --- a/platform/ios/Mapbox-iOS-SDK-symbols.podspec +++ b/platform/ios/Mapbox-iOS-SDK-symbols.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |m| - version = '3.6.0' + version = '3.6.1' m.name = 'Mapbox-iOS-SDK-symbols' m.version = "#{version}-symbols" diff --git a/platform/ios/Mapbox-iOS-SDK.podspec b/platform/ios/Mapbox-iOS-SDK.podspec index 55e8791b4c..53779307a8 100644 --- a/platform/ios/Mapbox-iOS-SDK.podspec +++ b/platform/ios/Mapbox-iOS-SDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |m| - version = '3.6.0' + version = '3.6.1' m.name = 'Mapbox-iOS-SDK' m.version = version -- cgit v1.2.1 From 21bbf5a9e0e82e60250f5b05dd5430052a7b2469 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 1 Aug 2017 16:33:52 +0200 Subject: [android] - fix OnCameraMoveStartedListener typo (#9664) --- .../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 2 +- .../mapboxsdk/testapp/activity/camera/CameraPositionActivity.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index c8725d8d8d..e074d938fd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -1708,7 +1708,7 @@ public final class MapboxMap { * @param listener the listener to notify */ @UiThread - public void setOnCameraMoveStartedistener(@Nullable OnCameraMoveStartedListener listener) { + public void setOnCameraMoveStartedListener(@Nullable OnCameraMoveStartedListener listener) { cameraChangeDispatcher.setOnCameraMoveStartedListener(listener); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java index cb2f57d860..10464b087a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java @@ -67,7 +67,7 @@ public class CameraPositionActivity extends AppCompatActivity implements OnMapRe } }); - mapboxMap.setOnCameraMoveStartedistener(new MapboxMap.OnCameraMoveStartedListener() { + mapboxMap.setOnCameraMoveStartedListener(new MapboxMap.OnCameraMoveStartedListener() { private final String[] REASONS = {"REASON_API_GESTURE", "REASON_DEVELOPER_ANIMATION", "REASON_API_ANIMATION"}; -- cgit v1.2.1 From e4a61426bf1893637617159ebea5b61b37114d12 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 1 Aug 2017 15:25:24 +0200 Subject: [android] - try/catch initalisation of Telemetry (#9658) --- .../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java index 6722000be7..eadc3fdcf5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java @@ -15,6 +15,8 @@ import com.mapbox.services.android.telemetry.MapboxTelemetry; import com.mapbox.services.android.telemetry.location.LocationEngine; import com.mapbox.services.android.telemetry.location.LocationEnginePriority; +import timber.log.Timber; + /** * The entry point to initialize the Mapbox Android SDK. *

@@ -48,8 +50,14 @@ public final class Mapbox { INSTANCE = new Mapbox(appContext, accessToken, new LocationSource(appContext)); LocationEngine locationEngine = new LocationSource(appContext); locationEngine.setPriority(LocationEnginePriority.NO_POWER); - MapboxTelemetry.getInstance().initialize( - appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine); + + try { + MapboxTelemetry.getInstance().initialize( + appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine); + } catch (Exception exception) { + Timber.e(exception, "Unable to instantiate Mapbox telemetry"); + } + ConnectivityReceiver.instance(appContext); } return INSTANCE; -- cgit v1.2.1 From f5b48a5d06be88bfb373c8dab4d9576d122c8937 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 1 Aug 2017 15:25:07 +0200 Subject: [android] - remove preview image integration (#9657) --- .../java/com/mapbox/mapboxsdk/maps/MapView.java | 3 +- .../drawable-v21/mapbox_default_bg_selector.xml | 9 ---- .../res/drawable-xxhdpi/mapbox_mapview_preview.jpg | Bin 166053 -> 0 bytes .../res/drawable/mapbox_default_bg_selector.xml | 6 --- .../src/main/res/layout/mapbox_mapview_preview.xml | 52 --------------------- .../src/main/res/values/colors.xml | 1 - 6 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index c51d9327d2..32c4952aa1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -95,8 +95,7 @@ public class MapView extends FrameLayout { private void initialise(@NonNull final Context context, @NonNull final MapboxMapOptions options) { if (isInEditMode()) { - // in IDE, show preview map - LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_preview, this); + // in IDE layout editor, just return return; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml deleted file mode 100644 index 2fd6815c23..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg deleted file mode 100644 index 3a21fc08bc..0000000000 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg and /dev/null differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml deleted file mode 100644 index 3efe48615b..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml deleted file mode 100644 index 1c1ab0e71b..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml index 63ef42c2c3..69ab7568bb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml @@ -1,7 +1,6 @@ #7D7F80 - #EEEEEE #1E8CAB @color/mapbox_blue -- cgit v1.2.1 From f8c418e2b1cf7229908dd322e1442fda1a05605e Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 1 Aug 2017 21:31:35 +0200 Subject: [android] - bump MAS dependency (#9671) --- platform/android/dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/dependencies.gradle b/platform/android/dependencies.gradle index 3d8f48b46b..5fd2ec3716 100644 --- a/platform/android/dependencies.gradle +++ b/platform/android/dependencies.gradle @@ -7,7 +7,7 @@ ext { versionCode = 11 versionName = "5.0.0" - mapboxServicesVersion = "2.1.3" + mapboxServicesVersion = "2.2.0" supportLibVersion = "25.3.1" wearableVersion = '2.0.0' espressoVersion = '2.2.2' -- cgit v1.2.1 From a523b710aceccc992c5aa193acbcd4bf4c93a62d Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Tue, 1 Aug 2017 21:33:31 +0200 Subject: [android] - update changelog for release v5.1.2 --- platform/android/CHANGELOG.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index b2eaaa2a9c..485ceaab8a 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -2,7 +2,21 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started. -## 5.1.1 - TBA +## 5.1.2 - August 2, 20017 + +* Disable program caching on Ardreno GPU 3xx, 4xx and 5xx [#9625](https://github.com/mapbox/mapbox-gl-native/pull/9625) +* GeoJSON proguard issue [#9577](https://github.com/mapbox/mapbox-gl-native/pull/9577) +* Harden click events of shape annotations [#9585](https://github.com/mapbox/mapbox-gl-native/pull/9585) +* Validate Marker before opening InfoWindow [#9586](https://github.com/mapbox/mapbox-gl-native/pull/9586) +* Fix added to map check [#9602](https://github.com/mapbox/mapbox-gl-native/pull/9602) +* Don't query shape annotations if none were added [#9606](https://github.com/mapbox/mapbox-gl-native/pull/9606) +* Fix compass direction [#9632](https://github.com/mapbox/mapbox-gl-native/pull/9632) +* Remove preview image integration [#9657](https://github.com/mapbox/mapbox-gl-native/pull/9657) +* Try/catch initialization of telemetry [#9658](https://github.com/mapbox/mapbox-gl-native/pull/9658) +* Fix typo OnCameraMoveStartedListener [#9664](https://github.com/mapbox/mapbox-gl-native/pull/9664) +* Bump MAS dependency to 5.2.0 [#9671](https://github.com/mapbox/mapbox-gl-native/pull/9671) + +## 5.1.1 - July 21, 2017 * Rework attribution binding [#9433](https://github.com/mapbox/mapbox-gl-native/pull/9433) * BackendScope changes [#9538](https://github.com/mapbox/mapbox-gl-native/pull/9538) -- cgit v1.2.1 From afd4df9dbcdff08654a09e95fdae236061aaa4bd Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Tue, 1 Aug 2017 16:14:41 -0400 Subject: =?UTF-8?q?[ios]=20adapt=20Mapbox=20Streets=E2=80=93sourced=20laye?= =?UTF-8?q?rs=20for=20user=20preferred=20language=20(#9582)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ios] Update label localization * [ios, macos] Move MGLVectorSource+MBXAdditions.h to darwin. * [ios, macos] Adapt Mapbox Streets to the user preferred language. * [ios, macos] Clarify style localization documentation. * [ios, macos] Update localization examples * [ios, macos] Add style language reset to original. * [ios, macos] Update changelogs. * [ios, macos] Rename Vector Source Additions to MGL standard. * [ios, macos] Add suport for stop localization. --- platform/darwin/src/MGLStyle.h | 15 +++ platform/darwin/src/MGLStyle.mm | 136 +++++++++++++++++++++ platform/darwin/src/MGLVectorSource+MGLAdditions.h | 15 +++ platform/darwin/src/MGLVectorSource+MGLAdditions.m | 53 ++++++++ platform/ios/CHANGELOG.md | 6 +- platform/ios/app/MBXViewController.m | 43 +------ platform/ios/ios.xcodeproj/project.pbxproj | 12 ++ platform/macos/CHANGELOG.md | 4 + platform/macos/app/MGLVectorSource+MBXAdditions.h | 15 --- platform/macos/app/MGLVectorSource+MBXAdditions.m | 53 -------- platform/macos/app/MapDocument.m | 49 +------- platform/macos/macos.xcodeproj/project.pbxproj | 14 ++- 12 files changed, 253 insertions(+), 162 deletions(-) create mode 100644 platform/darwin/src/MGLVectorSource+MGLAdditions.h create mode 100644 platform/darwin/src/MGLVectorSource+MGLAdditions.m delete mode 100644 platform/macos/app/MGLVectorSource+MBXAdditions.h delete mode 100644 platform/macos/app/MGLVectorSource+MBXAdditions.m diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 8ffd7db2b2..8c009d22c6 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -610,6 +610,21 @@ MGL_EXPORT */ @property (nonatomic, strong) MGLLight *light; +#pragma mark Localizing Map Content + +/** + A Boolean value that determines whether the style attempts to localize labels in + the style into the system’s preferred language. + + When this property is enabled, the style automatically modifies the text property + of any symbol style layer whose source is the + Mapbox + Streets source. On iOS, the user can set the system’s preferred language in + Settings, General Settings, Language & Region. On macOS, the user can set the + system’s preferred language in the Language & Region pane of System Preferences. + */ +@property (nonatomic) BOOL localizesLabels; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index eb838085d7..1e0a2e02b7 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -21,6 +21,7 @@ #import "MGLSource.h" #import "MGLTileSource_Private.h" #import "MGLVectorSource.h" +#import "MGLVectorSource+MGLAdditions.h" #import "MGLRasterSource.h" #import "MGLShapeSource.h" @@ -48,11 +49,34 @@ #import "NSImage+MGLAdditions.h" #endif +/** + Model class for localization changes. + */ +@interface MGLTextLanguage: NSObject +@property (strong, nonatomic) NSString *originalTextField; +@property (strong, nonatomic) NSString *updatedTextField; + +- (instancetype)initWithTextLanguage:(NSString *)originalTextField updatedTextField:(NSString *)updatedTextField; + +@end + +@implementation MGLTextLanguage +- (instancetype)initWithTextLanguage:(NSString *)originalTextField updatedTextField:(NSString *)updatedTextField +{ + if (self = [super init]) { + _originalTextField = originalTextField; + _updatedTextField = updatedTextField; + } + return self; +} +@end + @interface MGLStyle() @property (nonatomic, readwrite, weak) MGLMapView *mapView; @property (readonly, copy, nullable) NSURL *URL; @property (nonatomic, readwrite, strong) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLOpenGLStyleLayer *) *openGLLayers; +@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, NS_DICTIONARY_OF(NSObject *, MGLTextLanguage *) *) *localizedLayersByIdentifier; @end @@ -116,6 +140,7 @@ static NSURL *MGLStyleURL_emerald; if (self = [super init]) { _mapView = mapView; _openGLLayers = [NSMutableDictionary dictionary]; + _localizedLayersByIdentifier = [NSMutableDictionary dictionary]; } return self; } @@ -609,4 +634,115 @@ static NSURL *MGLStyleURL_emerald; self.URL ? [NSString stringWithFormat:@"\"%@\"", self.URL] : self.URL]; } +#pragma mark Style language preferences + +- (void)setLocalizesLabels:(BOOL)localizesLabels +{ + if (_localizesLabels != localizesLabels) { + _localizesLabels = localizesLabels; + } else { + return; + } + + if (_localizesLabels) { + NSString *preferredLanguage = [MGLVectorSource preferredMapboxStreetsLanguage]; + NSMutableDictionary *localizedKeysByKeyBySourceIdentifier = [NSMutableDictionary dictionary]; + for (MGLSymbolStyleLayer *layer in self.layers) { + if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { + continue; + } + + MGLVectorSource *source = (MGLVectorSource *)[self sourceWithIdentifier:layer.sourceIdentifier]; + if (![source isKindOfClass:[MGLVectorSource class]] || !source.mapboxStreets) { + continue; + } + + NSDictionary *localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier]; + if (!localizedKeysByKey) { + localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier] = [source localizedKeysByKeyForPreferredLanguage:preferredLanguage]; + } + + NSString *(^stringByLocalizingString)(NSString *) = ^ NSString * (NSString *string) { + NSMutableString *localizedString = string.mutableCopy; + [localizedKeysByKey enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull localizedKey, BOOL * _Nonnull stop) { + NSAssert([key isKindOfClass:[NSString class]], @"key is not a string"); + NSAssert([localizedKey isKindOfClass:[NSString class]], @"localizedKey is not a string"); + [localizedString replaceOccurrencesOfString:[NSString stringWithFormat:@"{%@}", key] + withString:[NSString stringWithFormat:@"{%@}", localizedKey] + options:0 + range:NSMakeRange(0, localizedString.length)]; + }]; + return localizedString; + }; + + if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { + NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; + NSString *localizingString = stringByLocalizingString(textField); + if (![textField isEqualToString:localizingString]) { + MGLTextLanguage *textLanguage = [[MGLTextLanguage alloc] initWithTextLanguage:textField + updatedTextField:localizingString]; + [self.localizedLayersByIdentifier setObject:@{ textField : textLanguage } forKey:layer.identifier]; + layer.text = [MGLStyleValue valueWithRawValue:localizingString]; + } + } + else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { + MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; + NSMutableDictionary *stops = function.stops.mutableCopy; + NSMutableDictionary *cameraStops = [NSMutableDictionary dictionary]; + [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { + NSString *textField = stop.rawValue; + NSString *localizingString = stringByLocalizingString(textField); + if (![textField isEqualToString:localizingString]) { + MGLTextLanguage *textLanguage = [[MGLTextLanguage alloc] initWithTextLanguage:textField + updatedTextField:localizingString]; + [cameraStops setObject:textLanguage forKey:zoomLevel]; + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:localizingString]; + } + + }]; + if (cameraStops.count > 0) { + [self.localizedLayersByIdentifier setObject:cameraStops forKey:layer.identifier]; + } + function.stops = stops; + layer.text = function; + } + } + } else { + + [self.localizedLayersByIdentifier enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, NSDictionary *textFields, BOOL *done) { + MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:identifier]; + + if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { + NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; + [textFields enumerateKeysAndObjectsUsingBlock:^(NSObject *originalLanguage, MGLTextLanguage *textLanguage, BOOL *done) { + if ([textLanguage.updatedTextField isEqualToString:textField]) { + layer.text = [MGLStyleValue valueWithRawValue:textLanguage.originalTextField]; + } + }]; + + } + else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { + MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; + NSMutableDictionary *stops = function.stops.mutableCopy; + [textFields enumerateKeysAndObjectsUsingBlock:^(NSObject *zoomKey, MGLTextLanguage *textLanguage, BOOL *done) { + if ([zoomKey isKindOfClass:[NSNumber class]]) { + NSNumber *zoomLevel = (NSNumber*)zoomKey; + MGLConstantStyleValue *stop = [stops objectForKey:zoomLevel]; + NSString *textField = stop.rawValue; + if ([textLanguage.updatedTextField isEqualToString:textField]) { + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:textLanguage.originalTextField]; + } + } + }]; + + function.stops = stops; + layer.text = function; + } + + }]; + + self.localizedLayersByIdentifier = [NSMutableDictionary dictionary]; + } +} + @end diff --git a/platform/darwin/src/MGLVectorSource+MGLAdditions.h b/platform/darwin/src/MGLVectorSource+MGLAdditions.h new file mode 100644 index 0000000000..43b0aba747 --- /dev/null +++ b/platform/darwin/src/MGLVectorSource+MGLAdditions.h @@ -0,0 +1,15 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MGLVectorSource (MGLAdditions) + ++ (NSString *)preferredMapboxStreetsLanguage; + +- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage; + +@property (nonatomic, readonly, getter=isMapboxStreets) BOOL mapboxStreets; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLVectorSource+MGLAdditions.m b/platform/darwin/src/MGLVectorSource+MGLAdditions.m new file mode 100644 index 0000000000..a305388117 --- /dev/null +++ b/platform/darwin/src/MGLVectorSource+MGLAdditions.m @@ -0,0 +1,53 @@ +#import "MGLVectorSource+MGLAdditions.h" + +@implementation MGLVectorSource (MGLAdditions) + ++ (NS_SET_OF(NSString *) *)mapboxStreetsLanguages { + // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview + static dispatch_once_t onceToken; + static NS_SET_OF(NSString *) *mapboxStreetsLanguages; + dispatch_once(&onceToken, ^{ + // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview + mapboxStreetsLanguages = [NSSet setWithObjects:@"ar", @"de", @"en", @"es", @"fr", @"pt", @"ru", @"zh", @"zh-Hans", nil]; + }); + return mapboxStreetsLanguages; +} + ++ (NSString *)preferredMapboxStreetsLanguage { + NSArray *supportedLanguages = [MGLVectorSource mapboxStreetsLanguages].allObjects; + NSArray *preferredLanguages = [NSBundle preferredLocalizationsFromArray:supportedLanguages + forPreferences:[NSLocale preferredLanguages]]; + NSString *mostSpecificLanguage; + for (NSString *language in preferredLanguages) { + if (language.length > mostSpecificLanguage.length) { + mostSpecificLanguage = language; + } + } + return mostSpecificLanguage ?: @"en"; +} + +- (BOOL)isMapboxStreets { + NSURL *url = self.configurationURL; + if (![url.scheme isEqualToString:@"mapbox"]) { + return NO; + } + NSArray *identifiers = [url.host componentsSeparatedByString:@","]; + return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"]; +} + +- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage { + if (!self.mapboxStreets) { + return @{}; + } + + // Replace {name} and {name_*} with the matching localized name tag. + NSString *localizedKey = preferredLanguage ? [NSString stringWithFormat:@"name_%@", preferredLanguage] : @"name"; + NSMutableDictionary *localizedKeysByKey = [NSMutableDictionary dictionaryWithObject:localizedKey forKey:@"name"]; + for (NSString *languageCode in [MGLVectorSource mapboxStreetsLanguages]) { + NSString *key = [NSString stringWithFormat:@"name_%@", languageCode]; + localizedKeysByKey[key] = localizedKey; + } + return localizedKeysByKey; +} + +@end diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 43df49a9ac..55790577cd 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -2,7 +2,11 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started. -## 3.6.1 +## 3.6.2 + +* Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) + +## 3.6.1 - July 28, 2017 * Reduced the size of the dynamic framework by optimizing symbol visibility. ([#7604](https://github.com/mapbox/mapbox-gl-native/pull/7604)) * Fixed an issue where the attribution button would have its custom tint color reset when the map view received a tint color change notification, such as when an alert controller was presented. ([#9598](https://github.com/mapbox/mapbox-gl-native/pull/9598)) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index d3927374a7..ebbc218017 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -343,7 +343,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Update Shape Source: Features", @"Style Vector Source", @"Style Raster Source", - [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], + [NSString stringWithFormat:@"Show Labels in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], @"Add Route Line", @"Dynamically Style Polygon", ]]; @@ -1274,12 +1274,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { -(void)styleCountryLabelsLanguage { - NSArray *labelLayers = @[ - @"country-label-lg", - @"country-label-md", - @"country-label-sm", - ]; - [self styleLabelLanguageForLayersNamed:labelLayers]; + _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; + self.mapView.style.localizesLabels = _usingLocaleBasedCountryLabels; } - (void)styleRouteLine @@ -1362,39 +1358,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addLayer:fillStyleLayer]; } -- (void)styleLabelLanguageForLayersNamed:(NSArray *)layers -{ - _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; - NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]]; - NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @"{name}"; - - for (NSString *layerName in layers) { - MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:layerName]; - - if ([layer isKindOfClass:[MGLSymbolStyleLayer class]]) { - if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { - MGLConstantStyleValue *label = (MGLConstantStyleValue *)layer.text; - if ([label.rawValue hasPrefix:@"{name"]) { - layer.text = [MGLStyleValue valueWithRawValue:language]; - } - } - else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { - if ([stop.rawValue hasPrefix:@"{name"]) { - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:language]; - } - }]; - function.stops = stops; - layer.text = function; - } - } else { - NSLog(@"%@ is not a symbol style layer", layerName); - } - } -} - - (NSString *)bestLanguageForUser { // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 8ecbe0c6ab..83b267df43 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -17,6 +17,10 @@ 1F7454971ECD450D00021D39 /* MGLLight_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F7454941ECD450D00021D39 /* MGLLight_Private.h */; }; 1F7454A91ED08AB400021D39 /* MGLLightTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454A61ED08AB400021D39 /* MGLLightTest.mm */; }; 1F95931D1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */; }; + 1FB7DAAF1F2A4DBD00410606 /* MGLVectorSource+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */; }; + 1FB7DAB01F2A4DC200410606 /* MGLVectorSource+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */; }; + 1FB7DAB11F2A4DC800410606 /* MGLVectorSource+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */; }; + 1FB7DAB21F2A4DC900410606 /* MGLVectorSource+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */; }; 30E578171DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; }; 30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; }; 30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 30E578121DAA7D690050F07E /* UIImage+MGLAdditions.mm */; }; @@ -547,6 +551,8 @@ 1F7454941ECD450D00021D39 /* MGLLight_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLLight_Private.h; sourceTree = ""; }; 1F7454A61ED08AB400021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLLightTest.mm; path = ../../darwin/test/MGLLightTest.mm; sourceTree = ""; }; 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLNSDateAdditionsTests.mm; path = ../../darwin/test/MGLNSDateAdditionsTests.mm; sourceTree = ""; }; + 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MGLAdditions.h"; sourceTree = ""; }; + 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MGLAdditions.m"; sourceTree = ""; }; 20DABE861DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Foundation.strings"; sourceTree = ""; }; 20DABE881DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 20DABE8A1DF78149007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Root.strings"; sourceTree = ""; }; @@ -1537,6 +1543,8 @@ DAD165831CF4CFED001FF4B9 /* Categories */ = { isa = PBXGroup; children = ( + 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */, + 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */, 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */, 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */, 7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */, @@ -1642,6 +1650,7 @@ 350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */, DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */, 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */, + 1FB7DAAF1F2A4DBD00410606 /* MGLVectorSource+MGLAdditions.h in Headers */, DA88483B1CBAFB8500AB86E3 /* MGLCalloutView.h in Headers */, 35E0CFE61D3E501500188327 /* MGLStyle_Private.h in Headers */, 3510FFF01D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, @@ -1819,6 +1828,7 @@ 35136D4D1D4277FC00C20EFD /* MGLSource.h in Headers */, DA35A2BC1CCA9A6900E826B2 /* MGLClockDirectionFormatter.h in Headers */, 35D13AC41D3D19DD00AFB4E0 /* MGLFillStyleLayer.h in Headers */, + 1FB7DAB01F2A4DC200410606 /* MGLVectorSource+MGLAdditions.h in Headers */, DABFB86E1CBE9A0F00D62B32 /* MGLCalloutView.h in Headers */, 1F7454971ECD450D00021D39 /* MGLLight_Private.h in Headers */, DABFB8601CBE99E500D62B32 /* MGLMapCamera.h in Headers */, @@ -2197,6 +2207,7 @@ 9620BB3A1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */, 354B83981D2E873E005D9406 /* MGLUserLocationAnnotationView.m in Sources */, DA88485D1CBAFB9800AB86E3 /* MGLFaux3DUserLocationAnnotationView.m in Sources */, + 1FB7DAB11F2A4DC800410606 /* MGLVectorSource+MGLAdditions.m in Sources */, DAD165701CF41981001FF4B9 /* MGLFeature.mm in Sources */, 30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C11CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, @@ -2279,6 +2290,7 @@ 9620BB3B1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */, DAA4E4221CBB730400178DFB /* MGLPointAnnotation.mm in Sources */, DAED38661D62D0FC00D7640F /* NSURL+MGLAdditions.m in Sources */, + 1FB7DAB21F2A4DC900410606 /* MGLVectorSource+MGLAdditions.m in Sources */, DAD165711CF41981001FF4B9 /* MGLFeature.mm in Sources */, 30E5781A1DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C21CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index f69f7e1b5d..1af3c03d68 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for Mapbox macOS SDK +## 0.5.1 + +* Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) + ## 0.5.0 This version of the Mapbox macOS SDK corresponds to version 3.6.0 of the Mapbox iOS SDK. diff --git a/platform/macos/app/MGLVectorSource+MBXAdditions.h b/platform/macos/app/MGLVectorSource+MBXAdditions.h deleted file mode 100644 index 1e25ee5a60..0000000000 --- a/platform/macos/app/MGLVectorSource+MBXAdditions.h +++ /dev/null @@ -1,15 +0,0 @@ -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface MGLVectorSource (MBXAdditions) - -+ (NSString *)preferredMapboxStreetsLanguage; - -- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage; - -@property (nonatomic, readonly, getter=isMapboxStreets) BOOL mapboxStreets; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/macos/app/MGLVectorSource+MBXAdditions.m b/platform/macos/app/MGLVectorSource+MBXAdditions.m deleted file mode 100644 index 323bc74366..0000000000 --- a/platform/macos/app/MGLVectorSource+MBXAdditions.m +++ /dev/null @@ -1,53 +0,0 @@ -#import "MGLVectorSource+MBXAdditions.h" - -@implementation MGLVectorSource (MBXAdditions) - -+ (NS_SET_OF(NSString *) *)mapboxStreetsLanguages { - // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview - static dispatch_once_t onceToken; - static NS_SET_OF(NSString *) *mapboxStreetsLanguages; - dispatch_once(&onceToken, ^{ - // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview - mapboxStreetsLanguages = [NSSet setWithObjects:@"ar", @"de", @"en", @"es", @"fr", @"pt", @"ru", @"zh", @"zh-Hans", nil]; - }); - return mapboxStreetsLanguages; -} - -+ (NSString *)preferredMapboxStreetsLanguage { - NSArray *supportedLanguages = [MGLVectorSource mapboxStreetsLanguages].allObjects; - NSArray *preferredLanguages = [NSBundle preferredLocalizationsFromArray:supportedLanguages - forPreferences:[NSLocale preferredLanguages]]; - NSString *mostSpecificLanguage; - for (NSString *language in preferredLanguages) { - if (language.length > mostSpecificLanguage.length) { - mostSpecificLanguage = language; - } - } - return mostSpecificLanguage ?: @"en"; -} - -- (BOOL)isMapboxStreets { - NSURL *url = self.configurationURL; - if (![url.scheme isEqualToString:@"mapbox"]) { - return NO; - } - NSArray *identifiers = [url.host componentsSeparatedByString:@","]; - return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"]; -} - -- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage { - if (!self.mapboxStreets) { - return @{}; - } - - // Replace {name} and {name_*} with the matching localized name tag. - NSString *localizedKey = preferredLanguage ? [NSString stringWithFormat:@"name_%@", preferredLanguage] : @"name"; - NSMutableDictionary *localizedKeysByKey = [NSMutableDictionary dictionaryWithObject:localizedKey forKey:@"name"]; - for (NSString *languageCode in [MGLVectorSource mapboxStreetsLanguages]) { - NSString *key = [NSString stringWithFormat:@"name_%@", languageCode]; - localizedKeysByKey[key] = localizedKey; - } - return localizedKeysByKey; -} - -@end diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 59844d363e..1d22295f50 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -5,7 +5,7 @@ #import "DroppedPinAnnotation.h" #import "MGLStyle+MBXAdditions.h" -#import "MGLVectorSource+MBXAdditions.h" +#import "MGLVectorSource+MGLAdditions.h" #import @@ -344,52 +344,7 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id *)layer.text rawValue]; - layer.text = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; - } - else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { - NSString *textField = stop.rawValue; - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; - }]; - function.stops = stops; - layer.text = function; - } - } + self.mapView.style.localizesLabels = _isLocalizingLabels; } - (void)applyPendingState { diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index be33b822f2..00cb6ce975 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -13,6 +13,8 @@ 1F7454A51ECFB00300021D39 /* MGLLight.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454A21ECFB00300021D39 /* MGLLight.mm */; }; 1F7454AB1ED1DDBD00021D39 /* MGLLightTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454AA1ED1DDBD00021D39 /* MGLLightTest.mm */; }; 1F95931B1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F95931A1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm */; }; + 1FCDF1421F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FCDF1401F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h */; }; + 1FCDF1431F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FCDF1411F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m */; }; 30E5781B1DAA857E0050F07E /* NSImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578141DAA7D920050F07E /* NSImage+MGLAdditions.h */; }; 3508EC641D749D39009B0EE4 /* NSExpression+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */; }; 3508EC651D749D39009B0EE4 /* NSExpression+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */; }; @@ -233,7 +235,6 @@ DAEDC4371D606291000224FF /* MGLAttributionButtonTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DAEDC4361D606291000224FF /* MGLAttributionButtonTests.m */; }; DAF0D80E1DFE0E5D00B28378 /* MGLPointCollection_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAF0D80D1DFE0E5D00B28378 /* MGLPointCollection_Private.h */; }; DAF0D8161DFE6B1800B28378 /* MGLAttributionInfo_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAF0D8151DFE6B1800B28378 /* MGLAttributionInfo_Private.h */; }; - DAF0D81C1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DAF0D81B1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m */; }; DD0902B21DB1AC6400C5BDCE /* MGLNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0902AF1DB1AC6400C5BDCE /* MGLNetworkConfiguration.m */; }; DD0902B31DB1AC6400C5BDCE /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902B01DB1AC6400C5BDCE /* MGLNetworkConfiguration.h */; }; DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD58A4C71D822C6200E1F038 /* MGLExpressionTests.mm */; }; @@ -277,6 +278,8 @@ 1F7454A21ECFB00300021D39 /* MGLLight.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLight.mm; sourceTree = ""; }; 1F7454AA1ED1DDBD00021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLightTest.mm; sourceTree = ""; }; 1F95931A1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLNSDateAdditionsTests.mm; path = ../../darwin/test/MGLNSDateAdditionsTests.mm; sourceTree = ""; }; + 1FCDF1401F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MGLAdditions.h"; sourceTree = ""; }; + 1FCDF1411F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MGLAdditions.m"; sourceTree = ""; }; 30E578141DAA7D920050F07E /* NSImage+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSImage+MGLAdditions.h"; path = "src/NSImage+MGLAdditions.h"; sourceTree = SOURCE_ROOT; }; 3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSExpression+MGLAdditions.h"; sourceTree = ""; }; 3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSExpression+MGLAdditions.mm"; sourceTree = ""; }; @@ -568,8 +571,6 @@ DAEDC4361D606291000224FF /* MGLAttributionButtonTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLAttributionButtonTests.m; sourceTree = ""; }; DAF0D80D1DFE0E5D00B28378 /* MGLPointCollection_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLPointCollection_Private.h; sourceTree = ""; }; DAF0D8151DFE6B1800B28378 /* MGLAttributionInfo_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo_Private.h; sourceTree = ""; }; - DAF0D81A1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MBXAdditions.h"; sourceTree = ""; }; - DAF0D81B1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MBXAdditions.m"; sourceTree = ""; }; DAFBD0D51E3FA969000CD6BF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = ""; }; DAFBD0D61E3FA983000CD6BF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Foundation.strings"; sourceTree = ""; }; DD0902AF1DB1AC6400C5BDCE /* MGLNetworkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLNetworkConfiguration.m; sourceTree = ""; }; @@ -740,8 +741,6 @@ DA839E9E1CC2E3400062CAFB /* MapDocument.xib */, DACB0C371E18DFFD005DDBEA /* MGLStyle+MBXAdditions.h */, DACB0C381E18DFFD005DDBEA /* MGLStyle+MBXAdditions.m */, - DAF0D81A1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.h */, - DAF0D81B1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m */, DAE6C2E91CC3050F00DB3429 /* OfflinePackNameValueTransformer.h */, DAE6C2EA1CC3050F00DB3429 /* OfflinePackNameValueTransformer.m */, DAA48EFB1D6A4731006A7E36 /* StyleLayerIconTransformer.h */, @@ -920,6 +919,8 @@ DAD1657F1CF4CF50001FF4B9 /* Categories */ = { isa = PBXGroup; children = ( + 1FCDF1401F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h */, + 1FCDF1411F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m */, 408AA8601DAEED3300022900 /* MGLPolygon+MGLAdditions.h */, 408AA85C1DAEED3300022900 /* MGLPolygon+MGLAdditions.m */, 408AA8611DAEED3300022900 /* MGLPolyline+MGLAdditions.h */, @@ -1154,6 +1155,7 @@ DAE6C3601CC31E0400DB3429 /* MGLOfflineRegion.h in Headers */, DAE6C3681CC31E0400DB3429 /* MGLTilePyramidOfflineRegion.h in Headers */, DA35A2CF1CCAAED300E826B2 /* NSValue+MGLAdditions.h in Headers */, + 1FCDF1421F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h in Headers */, DAE6C3A61CC31E9400DB3429 /* MGLMapViewDelegate.h in Headers */, DAE6C38B1CC31E2A00DB3429 /* MGLOfflinePack_Private.h in Headers */, 558DE7A61E56161C00C7916D /* MGLFoundation_Private.h in Headers */, @@ -1378,7 +1380,6 @@ DACB0C391E18DFFD005DDBEA /* MGLStyle+MBXAdditions.m in Sources */, DA839E9A1CC2E3400062CAFB /* main.m in Sources */, DA839E971CC2E3400062CAFB /* AppDelegate.m in Sources */, - DAF0D81C1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m in Sources */, DAE6C2F01CC3050F00DB3429 /* OfflinePackNameValueTransformer.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1394,6 +1395,7 @@ 40B77E461DB11BCD003DA2FE /* NSArray+MGLAdditions.mm in Sources */, DAE6C38C1CC31E2A00DB3429 /* MGLOfflinePack.mm in Sources */, 35D65C5B1D65AD5500722C23 /* NSDate+MGLAdditions.mm in Sources */, + 1FCDF1431F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m in Sources */, DD0902B21DB1AC6400C5BDCE /* MGLNetworkConfiguration.m in Sources */, 1F7454A51ECFB00300021D39 /* MGLLight.mm in Sources */, DAE6C3B11CC31EF300DB3429 /* MGLAnnotationImage.m in Sources */, -- cgit v1.2.1 From ebab0c1a1bb6e8e76cefff72b262e33f9ac0555c Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Wed, 2 Aug 2017 12:29:10 +0200 Subject: [android] - release android v5.1.2, update config --- platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +- .../fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +- platform/android/dependencies.gradle | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties index a8646e3270..af1d04ab97 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle.properties +++ b/platform/android/MapboxGLAndroidSDK/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.mapbox.mapboxsdk -VERSION_NAME=5.1.2-SNAPSHOT +VERSION_NAME=5.1.3-SNAPSHOT POM_DESCRIPTION=Mapbox GL Android SDK POM_URL=https://github.com/mapbox/mapbox-gl-native diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties index a02b5d63ac..3cfc7d5fdc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties +++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties @@ -1,3 +1,3 @@ fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk -fabric-version=5.1.1 +fabric-version=5.1.2 fabric-build-type=binary diff --git a/platform/android/dependencies.gradle b/platform/android/dependencies.gradle index 5fd2ec3716..a4b202086a 100644 --- a/platform/android/dependencies.gradle +++ b/platform/android/dependencies.gradle @@ -4,8 +4,8 @@ ext { compileSdkVersion = 25 buildToolsVersion = "25.0.2" - versionCode = 11 - versionName = "5.0.0" + versionCode = 12 + versionName = "5.1.3" mapboxServicesVersion = "2.2.0" supportLibVersion = "25.3.1" -- cgit v1.2.1 From 141cd328043fb58c137c77bcb4f7c949c31831ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 8 May 2017 16:27:56 +0200 Subject: [ios] remove Secure Transport exception from demo app --- platform/ios/app/Info.plist | 13 ------------- platform/ios/app/MBXViewController.m | 3 +-- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/platform/ios/app/Info.plist b/platform/ios/app/Info.plist index d05d81e49d..d5b6825422 100644 --- a/platform/ios/app/Info.plist +++ b/platform/ios/app/Info.plist @@ -51,18 +51,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - NSAppTransportSecurity - - NSExceptionDomains - - stamen.com - - NSIncludesSubdomains - - NSTemporaryExceptionAllowsInsecureHTTPLoads - - - - diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index ebbc218017..b6b9eea7db 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1261,8 +1261,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { - (void)styleRasterSource { - // 3rd party raster source requires NSAppTransportSecurity exception for stamen.com - NSArray *tileURLTemplates = @[@"http://a.tile.stamen.com/terrain-background/{z}/{x}/{y}.jpg"]; + NSArray *tileURLTemplates = @[@"https://stamen-tiles.a.ssl.fastly.net/terrain-background/{z}/{x}/{y}.jpg"]; MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"style-raster-source-id" tileURLTemplates:tileURLTemplates options:@{ MGLTileSourceOptionTileSize: @256, }]; -- cgit v1.2.1 From 55d31922fcd47947b17261177e6d91201fe7c02a Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 1 Aug 2017 18:37:46 -0400 Subject: [ios] Add iosapp Settings.app force touch quick action shortcut --- .../Assets.xcassets/settings.imageset/Contents.json | 15 +-------------- .../Assets.xcassets/settings.imageset/settings.pdf | Bin 0 -> 9177 bytes .../Assets.xcassets/settings.imageset/settings.png | Bin 528 -> 0 bytes .../Assets.xcassets/settings.imageset/settings@2x.png | Bin 1130 -> 0 bytes platform/ios/app/Info.plist | 11 +++++++++++ platform/ios/app/MBXAppDelegate.m | 18 ++++++++++++++++++ 6 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 platform/ios/app/Assets.xcassets/settings.imageset/settings.pdf delete mode 100644 platform/ios/app/Assets.xcassets/settings.imageset/settings.png delete mode 100644 platform/ios/app/Assets.xcassets/settings.imageset/settings@2x.png diff --git a/platform/ios/app/Assets.xcassets/settings.imageset/Contents.json b/platform/ios/app/Assets.xcassets/settings.imageset/Contents.json index 1eeddba9b9..228b81a818 100644 --- a/platform/ios/app/Assets.xcassets/settings.imageset/Contents.json +++ b/platform/ios/app/Assets.xcassets/settings.imageset/Contents.json @@ -2,24 +2,11 @@ "images" : [ { "idiom" : "universal", - "filename" : "settings.png", - "scale" : "1x" - }, - { - "idiom" : "universal", - "filename" : "settings@2x.png", - "scale" : "2x" - }, - { - "idiom" : "universal", - "scale" : "3x" + "filename" : "settings.pdf" } ], "info" : { "version" : 1, "author" : "xcode" - }, - "properties" : { - "template-rendering-intent" : "template" } } \ No newline at end of file diff --git a/platform/ios/app/Assets.xcassets/settings.imageset/settings.pdf b/platform/ios/app/Assets.xcassets/settings.imageset/settings.pdf new file mode 100644 index 0000000000..46aa7443f0 Binary files /dev/null and b/platform/ios/app/Assets.xcassets/settings.imageset/settings.pdf differ diff --git a/platform/ios/app/Assets.xcassets/settings.imageset/settings.png b/platform/ios/app/Assets.xcassets/settings.imageset/settings.png deleted file mode 100644 index 5d7643eef5..0000000000 Binary files a/platform/ios/app/Assets.xcassets/settings.imageset/settings.png and /dev/null differ diff --git a/platform/ios/app/Assets.xcassets/settings.imageset/settings@2x.png b/platform/ios/app/Assets.xcassets/settings.imageset/settings@2x.png deleted file mode 100644 index 2bb9f0ebad..0000000000 Binary files a/platform/ios/app/Assets.xcassets/settings.imageset/settings@2x.png and /dev/null differ diff --git a/platform/ios/app/Info.plist b/platform/ios/app/Info.plist index d5b6825422..167e66fa09 100644 --- a/platform/ios/app/Info.plist +++ b/platform/ios/app/Info.plist @@ -51,5 +51,16 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIApplicationShortcutItems + + + UIApplicationShortcutItemTitle + Settings + UIApplicationShortcutItemType + $(PRODUCT_BUNDLE_IDENTIFIER).settings + UIApplicationShortcutItemIconFile + settings + + diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m index c2834bfa7f..1934f4912b 100644 --- a/platform/ios/app/MBXAppDelegate.m +++ b/platform/ios/app/MBXAppDelegate.m @@ -26,4 +26,22 @@ NSString * const MBXMapboxAccessTokenDefaultsKey = @"MBXMapboxAccessToken"; return YES; } +#pragma mark - Quick actions + +- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler { + completionHandler([self handleShortcut:shortcutItem]); +} + +- (BOOL)handleShortcut:(UIApplicationShortcutItem *)shortcut { + if ([[shortcut.type componentsSeparatedByString:@"."].lastObject isEqual:@"settings"]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; + }); + + return YES; + } + + return NO; +} + @end -- cgit v1.2.1 From a0402475052b1fd29b107aca5bbe9074fadc2cb9 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 1 Aug 2017 18:55:04 -0400 Subject: [ios] Clean-up iosapp project --- platform/ios/app/Default-568h@2x.png | Bin 18594 -> 0 bytes platform/ios/app/LaunchScreen.storyboard | 14 ++- platform/ios/app/MBXViewController.m | 181 ++++++++++++++--------------- platform/ios/ios.xcodeproj/project.pbxproj | 26 +++-- 4 files changed, 114 insertions(+), 107 deletions(-) delete mode 100644 platform/ios/app/Default-568h@2x.png diff --git a/platform/ios/app/Default-568h@2x.png b/platform/ios/app/Default-568h@2x.png deleted file mode 100644 index 0891b7aabf..0000000000 Binary files a/platform/ios/app/Default-568h@2x.png and /dev/null differ diff --git a/platform/ios/app/LaunchScreen.storyboard b/platform/ios/app/LaunchScreen.storyboard index 323bd43177..299e186886 100644 --- a/platform/ios/app/LaunchScreen.storyboard +++ b/platform/ios/app/LaunchScreen.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,9 +18,9 @@ - + - + diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index b6b9eea7db..992b7d587a 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -34,7 +34,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsCoreRenderingRows) { MBXSettingsCoreRenderingTimestamps, MBXSettingsCoreRenderingCollisionBoxes, MBXSettingsCoreRenderingOverdrawVisualization, - MBXSettingsCoreRenderingToggleTwoMaps, }; typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) { @@ -48,6 +47,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) { MBXSettingsAnnotationsTestShapes, MBXSettingsAnnotationsCustomCallout, MBXSettingsAnnotationsQueryAnnotations, + MBXSettingsAnnotationsCustomUserDot, MBXSettingsAnnotationsRemoveAnnotations, }; @@ -71,7 +71,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { MBXSettingsRuntimeStylingUpdateShapeSourceFeatures, MBXSettingsRuntimeStylingVectorSource, MBXSettingsRuntimeStylingRasterSource, - MBXSettingsRuntimeStylingCountryLabels, MBXSettingsRuntimeStylingRouteLine, MBXSettingsRuntimeStylingDDSPolygon, }; @@ -79,9 +78,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MBXSettingsMiscellaneousShowReuseQueueStats = 0, MBXSettingsMiscellaneousWorldTour, - MBXSettingsMiscellaneousCustomUserDot, MBXSettingsMiscellaneousShowZoomLevel, MBXSettingsMiscellaneousScrollView, + MBXSettingsMiscellaneousToggleTwoMaps, + MBXSettingsMiscellaneousCountryLabels, MBXSettingsMiscellaneousPrintLogFile, MBXSettingsMiscellaneousDeleteLogFile, }; @@ -303,8 +303,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { (debugMask & MGLMapDebugCollisionBoxesMask ? @"Hide" :@"Show")], [NSString stringWithFormat:@"%@ Overdraw Visualization", (debugMask & MGLMapDebugOverdrawVisualizationMask ? @"Hide" :@"Show")], - [NSString stringWithFormat:@"%@ Second Map", - ([self.view viewWithTag:2] == nil ? @"Show" : @"Hide")], ]]; break; case MBXSettingsAnnotations: @@ -319,6 +317,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Add Test Shapes", @"Add Point With Custom Callout", @"Query Annotations", + [NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")], @"Remove Annotations", ]]; break; @@ -343,7 +342,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Update Shape Source: Features", @"Style Vector Source", @"Style Raster Source", - [NSString stringWithFormat:@"Show Labels in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], @"Add Route Line", @"Dynamically Style Polygon", ]]; @@ -352,9 +350,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [settingsTitles addObjectsFromArray:@[ [NSString stringWithFormat:@"%@ Reuse Queue Stats", (_reuseQueueStatsEnabled ? @"Hide" :@"Show")], @"Start World Tour", - [NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")], [NSString stringWithFormat:@"%@ Zoom Level", (_showZoomLevelEnabled ? @"Hide" :@"Show")], @"Embedded Map View", + [NSString stringWithFormat:@"%@ Second Map", ([self.view viewWithTag:2] == nil ? @"Show" : @"Hide")], + [NSString stringWithFormat:@"Show Labels in %@", (_usingLocaleBasedCountryLabels ? @"Default Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], ]]; if (self.debugLoggingEnabled) @@ -399,81 +398,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsCoreRenderingOverdrawVisualization: self.mapView.debugMask ^= MGLMapDebugOverdrawVisualizationMask; break; - case MBXSettingsCoreRenderingToggleTwoMaps: - if ([self.view viewWithTag:2] == nil) { - MGLMapView *secondMapView = [[MGLMapView alloc] initWithFrame: - CGRectMake(0, self.view.bounds.size.height / 2, - self.view.bounds.size.width, self.view.bounds.size.height / 2)]; - secondMapView.translatesAutoresizingMaskIntoConstraints = false; - secondMapView.tag = 2; - for (NSLayoutConstraint *constraint in self.view.constraints) - { - if ((constraint.firstItem == self.mapView && constraint.firstAttribute == NSLayoutAttributeBottom) || - (constraint.secondItem == self.mapView && constraint.secondAttribute == NSLayoutAttributeBottom)) - { - [self.view removeConstraint:constraint]; - break; - } - } - [self.view addSubview:secondMapView]; - [self.view addConstraints:@[ - [NSLayoutConstraint constraintWithItem:self.mapView - attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationEqual - toItem:self.view - attribute:NSLayoutAttributeCenterY - multiplier:1 - constant:0], - [NSLayoutConstraint constraintWithItem:secondMapView - attribute:NSLayoutAttributeCenterX - relatedBy:NSLayoutRelationEqual - toItem:self.view - attribute:NSLayoutAttributeCenterX - multiplier:1 - constant:0], - [NSLayoutConstraint constraintWithItem:secondMapView - attribute:NSLayoutAttributeWidth - relatedBy:NSLayoutRelationEqual - toItem:self.view - attribute:NSLayoutAttributeWidth - multiplier:1 - constant:0], - [NSLayoutConstraint constraintWithItem:secondMapView - attribute:NSLayoutAttributeTop - relatedBy:NSLayoutRelationEqual - toItem:self.view - attribute:NSLayoutAttributeCenterY - multiplier:1 - constant:0], - [NSLayoutConstraint constraintWithItem:secondMapView - attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationEqual - toItem:self.bottomLayoutGuide - attribute:NSLayoutAttributeTop - multiplier:1 - constant:0], - ]]; - } else { - NSMutableArray *constraintsToRemove = [NSMutableArray array]; - MGLMapView *secondMapView = (MGLMapView *)[self.view viewWithTag:2]; - for (NSLayoutConstraint *constraint in self.view.constraints) - { - if (constraint.firstItem == secondMapView || constraint.secondItem == secondMapView) - { - [constraintsToRemove addObject:constraint]; - } - } - [self.view removeConstraints:constraintsToRemove]; - [secondMapView removeFromSuperview]; - [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.mapView - attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationEqual - toItem:self.bottomLayoutGuide - attribute:NSLayoutAttributeTop - multiplier:1 - constant:0]]; - } - break; default: NSAssert(NO, @"All core rendering setting rows should be implemented"); break; @@ -512,6 +436,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsAnnotationsQueryAnnotations: [self testQueryPointAnnotations]; break; + case MBXSettingsAnnotationsCustomUserDot: + [self toggleCustomUserDot]; + break; case MBXSettingsAnnotationsRemoveAnnotations: [self.mapView removeAnnotations:self.mapView.annotations]; break; @@ -580,9 +507,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsRuntimeStylingRasterSource: [self styleRasterSource]; break; - case MBXSettingsRuntimeStylingCountryLabels: - [self styleCountryLabelsLanguage]; - break; case MBXSettingsRuntimeStylingRouteLine: [self styleRouteLine]; break; @@ -597,12 +521,12 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsMiscellaneous: switch (indexPath.row) { + case MBXSettingsMiscellaneousCountryLabels: + [self styleCountryLabelsLanguage]; + break; case MBXSettingsMiscellaneousWorldTour: [self startWorldTour]; break; - case MBXSettingsMiscellaneousCustomUserDot: - [self toggleCustomUserDot]; - break; case MBXSettingsMiscellaneousPrintLogFile: [self printTelemetryLogFile]; break; @@ -630,6 +554,81 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.navigationController pushViewController:embeddedMapViewController animated:YES]; break; } + case MBXSettingsMiscellaneousToggleTwoMaps: + if ([self.view viewWithTag:2] == nil) { + MGLMapView *secondMapView = [[MGLMapView alloc] initWithFrame: + CGRectMake(0, self.view.bounds.size.height / 2, + self.view.bounds.size.width, self.view.bounds.size.height / 2)]; + secondMapView.translatesAutoresizingMaskIntoConstraints = false; + secondMapView.tag = 2; + for (NSLayoutConstraint *constraint in self.view.constraints) + { + if ((constraint.firstItem == self.mapView && constraint.firstAttribute == NSLayoutAttributeBottom) || + (constraint.secondItem == self.mapView && constraint.secondAttribute == NSLayoutAttributeBottom)) + { + [self.view removeConstraint:constraint]; + break; + } + } + [self.view addSubview:secondMapView]; + [self.view addConstraints:@[ + [NSLayoutConstraint constraintWithItem:self.mapView + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationEqual + toItem:self.view + attribute:NSLayoutAttributeCenterY + multiplier:1 + constant:0], + [NSLayoutConstraint constraintWithItem:secondMapView + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:self.view + attribute:NSLayoutAttributeCenterX + multiplier:1 + constant:0], + [NSLayoutConstraint constraintWithItem:secondMapView + attribute:NSLayoutAttributeWidth + relatedBy:NSLayoutRelationEqual + toItem:self.view + attribute:NSLayoutAttributeWidth + multiplier:1 + constant:0], + [NSLayoutConstraint constraintWithItem:secondMapView + attribute:NSLayoutAttributeTop + relatedBy:NSLayoutRelationEqual + toItem:self.view + attribute:NSLayoutAttributeCenterY + multiplier:1 + constant:0], + [NSLayoutConstraint constraintWithItem:secondMapView + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationEqual + toItem:self.bottomLayoutGuide + attribute:NSLayoutAttributeTop + multiplier:1 + constant:0], + ]]; + } else { + NSMutableArray *constraintsToRemove = [NSMutableArray array]; + MGLMapView *secondMapView = (MGLMapView *)[self.view viewWithTag:2]; + for (NSLayoutConstraint *constraint in self.view.constraints) + { + if (constraint.firstItem == secondMapView || constraint.secondItem == secondMapView) + { + [constraintsToRemove addObject:constraint]; + } + } + [self.view removeConstraints:constraintsToRemove]; + [secondMapView removeFromSuperview]; + [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.mapView + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationEqual + toItem:self.bottomLayoutGuide + attribute:NSLayoutAttributeTop + multiplier:1 + constant:0]]; + } + break; default: NSAssert(NO, @"All miscellaneous setting rows should be implemented"); break; @@ -1261,8 +1260,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { - (void)styleRasterSource { - NSArray *tileURLTemplates = @[@"https://stamen-tiles.a.ssl.fastly.net/terrain-background/{z}/{x}/{y}.jpg"]; - MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"style-raster-source-id" tileURLTemplates:tileURLTemplates options:@{ + NSString *tileURL = [NSString stringWithFormat:@"https://stamen-tiles.a.ssl.fastly.net/terrain-background/{z}/{x}/{y}%@.jpg", UIScreen.mainScreen.nativeScale > 1 ? @"@2x" : @""]; + MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"style-raster-source-id" tileURLTemplates:@[tileURL] options:@{ MGLTileSourceOptionTileSize: @256, }]; [self.mapView.style addSource:rasterSource]; @@ -1574,7 +1573,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [sender setAccessibilityValue:nextAccessibilityValue]; } -#pragma mark - Map Delegate +#pragma mark - MGLMapViewDelegate - (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id)annotation { diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 83b267df43..76b35be2de 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -233,7 +233,6 @@ DA1DC9971CB6E046006E619F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1DC9961CB6E046006E619F /* main.m */; }; DA1DC9991CB6E054006E619F /* MBXAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1DC9981CB6E054006E619F /* MBXAppDelegate.m */; }; DA1DC99B1CB6E064006E619F /* MBXViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1DC99A1CB6E064006E619F /* MBXViewController.m */; }; - DA1DC99D1CB6E076006E619F /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DA1DC99C1CB6E076006E619F /* Default-568h@2x.png */; }; DA1DC99F1CB6E088006E619F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DA1DC99E1CB6E088006E619F /* Assets.xcassets */; }; DA1F8F3D1EBD287B00367E42 /* MGLDocumentationGuideTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA1F8F3C1EBD287B00367E42 /* MGLDocumentationGuideTests.swift */; }; DA2207BF1DC0805F0002F84D /* MGLStyleValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */; }; @@ -718,7 +717,6 @@ DA1DC9961CB6E046006E619F /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; DA1DC9981CB6E054006E619F /* MBXAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXAppDelegate.m; sourceTree = ""; }; DA1DC99A1CB6E064006E619F /* MBXViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXViewController.m; sourceTree = ""; }; - DA1DC99C1CB6E076006E619F /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; DA1DC99E1CB6E088006E619F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; DA1F8F3C1EBD287B00367E42 /* MGLDocumentationGuideTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MGLDocumentationGuideTests.swift; path = ../../darwin/test/MGLDocumentationGuideTests.swift; sourceTree = ""; }; DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MGLStyleValueTests.swift; path = ../../darwin/test/MGLStyleValueTests.swift; sourceTree = ""; }; @@ -1154,6 +1152,20 @@ name = Sources; sourceTree = ""; }; + 9604FC341F313A5E003EEA02 /* Fixtures */ = { + isa = PBXGroup; + children = ( + 353BAEF51D646370009A8DA9 /* amsterdam.geojson */, + DA1DC96C1CB6C6CE006E619F /* points.geojson */, + DA1DC96D1CB6C6CE006E619F /* polyline.geojson */, + DA1DC96F1CB6C6CE006E619F /* threestates.geojson */, + DD4823721D94AE6C00EB71B7 /* fill_filter_style.json */, + DD4823731D94AE6C00EB71B7 /* line_filter_style.json */, + DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */, + ); + name = Fixtures; + sourceTree = ""; + }; DA1DC9411CB6C1C2006E619F = { isa = PBXGroup; children = ( @@ -1202,16 +1214,9 @@ DA821D051CCC6D59007508D4 /* Main.storyboard */, DA821D041CCC6D59007508D4 /* LaunchScreen.storyboard */, DA1DC99E1CB6E088006E619F /* Assets.xcassets */, - DA1DC96C1CB6C6CE006E619F /* points.geojson */, - DA1DC96D1CB6C6CE006E619F /* polyline.geojson */, - DA1DC96F1CB6C6CE006E619F /* threestates.geojson */, - 353BAEF51D646370009A8DA9 /* amsterdam.geojson */, - DD4823721D94AE6C00EB71B7 /* fill_filter_style.json */, - DD4823731D94AE6C00EB71B7 /* line_filter_style.json */, - DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */, DA1DC95E1CB6C1C2006E619F /* Info.plist */, - DA1DC99C1CB6E076006E619F /* Default-568h@2x.png */, 96E027251E57C76E004B8E66 /* Localizable.strings */, + 9604FC341F313A5E003EEA02 /* Fixtures */, DA1DC94D1CB6C1C2006E619F /* Supporting Files */, ); name = "Demo App"; @@ -2056,7 +2061,6 @@ 353BAEF61D646370009A8DA9 /* amsterdam.geojson in Resources */, DA1DC9711CB6C6CE006E619F /* polyline.geojson in Resources */, DD4823761D94AE6C00EB71B7 /* line_filter_style.json in Resources */, - DA1DC99D1CB6E076006E619F /* Default-568h@2x.png in Resources */, DA821D071CCC6D59007508D4 /* Main.storyboard in Resources */, DA1DC9731CB6C6CE006E619F /* threestates.geojson in Resources */, DA821D061CCC6D59007508D4 /* LaunchScreen.storyboard in Resources */, -- cgit v1.2.1 From 6a8ed6f83ae6ae9494cfc075214ba4558abd7e85 Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Mon, 31 Jul 2017 13:57:41 +0200 Subject: [ios] expose setCamera with edge padding --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.h | 17 +++++++++++++++++ platform/ios/src/MGLMapView.mm | 6 +++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 55790577cd..dad6d0c4ba 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ## 3.6.2 * Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) +* Added an additional camera method to MGLMapView that accepts an edge padding parameter. ([#9651](https://github.com/mapbox/mapbox-gl-native/pull/9651)) ## 3.6.1 - July 28, 2017 diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index a93b8e8511..a0aada9a9c 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -764,6 +764,23 @@ MGL_EXPORT IB_DESIGNABLE */ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion; +/** + Moves the viewpoint to a different location with respect to the map with an + optional transition duration and timing function. + + @param camera The new viewpoint. + @param duration The amount of time, measured in seconds, that the transition + animation should take. Specify `0` to jump to the new viewpoint + instantaneously. + @param function A timing function used for the animation. Set this parameter to + `nil` for a transition that matches most system animations. If the duration + is `0`, this parameter is ignored. + @param edgePadding The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @param completion The block to execute after the animation finishes. + */ +- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function edgePadding:(UIEdgeInsets)edgePadding completionHandler:(nullable void (^)(void))completion; + /** Moves the viewpoint to a different location using a transition animation that evokes powered flight and a default duration based on the length of the flight diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9cc4c42e5a..715c32186d 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2788,6 +2788,10 @@ public: - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { + [self setCamera:camera withDuration:duration animationTimingFunction:function edgePadding:self.contentInset completionHandler:completion]; +} + +- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function edgePadding:(UIEdgeInsets)edgePadding completionHandler:(nullable void (^)(void))completion { mbgl::AnimationOptions animationOptions; if (duration > 0) { @@ -2816,7 +2820,7 @@ public: [self willChangeValueForKey:@"camera"]; _mbglMap->cancelTransitions(); - mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:self.contentInset]; + mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:edgePadding]; _mbglMap->easeTo(cameraOptions, animationOptions); [self didChangeValueForKey:@"camera"]; } -- cgit v1.2.1 From 01d801c8c73b77c75a28f4fa8148780d58fe464d Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Fri, 4 Aug 2017 15:47:42 -0400 Subject: [ios] Update READMEs to link to help page --- platform/ios/docs/doc-README.md | 2 +- platform/ios/docs/pod-README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/ios/docs/doc-README.md b/platform/ios/docs/doc-README.md index 6c2693cbbf..ebad32e04c 100644 --- a/platform/ios/docs/doc-README.md +++ b/platform/ios/docs/doc-README.md @@ -6,4 +6,4 @@ The Mapbox iOS SDK is an open-source framework for embedding interactive map vie For setup information, check out the [Mapbox iOS SDK homepage](https://www.mapbox.com/ios-sdk/). For detailed usage instructions, read “[First steps with the Mapbox iOS SDK](https://www.mapbox.com/help/first-steps-ios-sdk/)” and consult the [online examples](https://www.mapbox.com/ios-sdk/examples/). A [full changelog](https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/CHANGELOG.md) is also available. -If you have any questions, please [contact our support team](https://www.mapbox.com/contact/). We welcome your [bug reports and feature requests](https://github.com/mapbox/mapbox-gl-native/issues/). +If you have any questions, please see [our help page](https://www.mapbox.com/help/). We welcome your [bug reports, feature requests, and contributions](https://github.com/mapbox/mapbox-gl-native/issues/). diff --git a/platform/ios/docs/pod-README.md b/platform/ios/docs/pod-README.md index 0a7edc5a41..2e5a78841c 100644 --- a/platform/ios/docs/pod-README.md +++ b/platform/ios/docs/pod-README.md @@ -96,4 +96,4 @@ class ViewController: UIViewController { Full API documentation is included in this package, within the `documentation` folder. For more details, read “[First steps with the Mapbox iOS SDK](https://www.mapbox.com/help/first-steps-ios-sdk/)” and consult the [online examples](https://www.mapbox.com/ios-sdk/examples/). -If you have any questions, please [contact our support team](https://www.mapbox.com/contact/). We welcome your [bug reports and feature requests](https://github.com/mapbox/mapbox-gl-native/issues/). +If you have any questions, please see [our help page](https://www.mapbox.com/help/). We welcome your [bug reports, feature requests, and contributions](https://github.com/mapbox/mapbox-gl-native/issues/). -- cgit v1.2.1 From 1394bfb554c5daa5d2384d960c9118e880a30480 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Mon, 7 Aug 2017 14:33:39 -0400 Subject: [ios] Fix user location horizontal accuracy ring inaccuracy Accuracy was off by +25%, depending on latitude. --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLFaux3DUserLocationAnnotationView.m | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index dad6d0c4ba..8535073cd0 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) * Added an additional camera method to MGLMapView that accepts an edge padding parameter. ([#9651](https://github.com/mapbox/mapbox-gl-native/pull/9651)) +* Fixed an issue with the scaling of the user location annotation’s horizontal accuracy indicator. ([#9721](https://github.com/mapbox/mapbox-gl-native/pull/9721)) ## 3.6.1 - July 28, 2017 diff --git a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m index 6db9c0db10..5f67f24f4e 100644 --- a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m +++ b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m @@ -460,11 +460,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck - (CGFloat)calculateAccuracyRingSize { - CGFloat latitudeRadians = MGLRadiansFromDegrees(self.userLocation.coordinate.latitude); - CGFloat metersPerPoint = [self.mapView metersPerPointAtLatitude:self.userLocation.coordinate.latitude]; - CGFloat pixelRadius = self.userLocation.location.horizontalAccuracy / cos(latitudeRadians) / metersPerPoint; - - return pixelRadius * 2.0; + // diameter in screen points + return self.userLocation.location.horizontalAccuracy / [self.mapView metersPerPointAtLatitude:self.userLocation.coordinate.latitude] * 2.0; } - (UIImage *)headingIndicatorTintedGradientImage -- cgit v1.2.1 From 2e24562ee8d2c0ca43fa5eab4170222e544e1d26 Mon Sep 17 00:00:00 2001 From: Nadia Barbosa Date: Mon, 7 Aug 2017 15:06:13 -0400 Subject: [ios] Update MGLPolyline docs about antimeridian crossings --- platform/darwin/src/MGLPolyline.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/MGLPolyline.h b/platform/darwin/src/MGLPolyline.h index b3db0fd39f..079a1c617d 100644 --- a/platform/darwin/src/MGLPolyline.h +++ b/platform/darwin/src/MGLPolyline.h @@ -33,8 +33,19 @@ NS_ASSUME_NONNULL_BEGIN `MGLPolygon` object. To group multiple polylines together in one shape, use an `MGLMultiPolyline` or `MGLShapeCollection` object. - To make the polyline straddle the antimeridian, specify some longitudes less - than −180 degrees or greater than 180 degrees. + To make the polyline go across the antimeridian or international date line, + specify some longitudes less than −180 degrees or greater than 180 degrees. + For example, a polyline that stretches from Tokyo to San Francisco would have + coordinates of (35.68476, -220.24257) and (37.78428, -122.41310). + + ```swift + let coordinates = [ + CLLocationCoordinate2D(latitude: 35.68476, longitude: -220.24257), + CLLocationCoordinate2D(latitude: 37.78428, longitude: -122.41310) + ] + + let polyline = MGLPolyline(coordinates: &coordinates, count: UInt(coordinates.count)) +``` A polyline is known as a LineString -- cgit v1.2.1 From 5d641f4d6892ae22c9b96f77d92a5295f3ca28b3 Mon Sep 17 00:00:00 2001 From: Nadia Barbosa Date: Tue, 8 Aug 2017 17:16:25 -0400 Subject: [ios] Add test for code snippet added to MGLPolyline doc change --- platform/darwin/src/MGLPolyline.h | 5 ++--- platform/darwin/test/MGLDocumentationExampleTests.swift | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/platform/darwin/src/MGLPolyline.h b/platform/darwin/src/MGLPolyline.h index 079a1c617d..e46baa91cc 100644 --- a/platform/darwin/src/MGLPolyline.h +++ b/platform/darwin/src/MGLPolyline.h @@ -43,9 +43,8 @@ NS_ASSUME_NONNULL_BEGIN CLLocationCoordinate2D(latitude: 35.68476, longitude: -220.24257), CLLocationCoordinate2D(latitude: 37.78428, longitude: -122.41310) ] - - let polyline = MGLPolyline(coordinates: &coordinates, count: UInt(coordinates.count)) -``` + let polyline = MGLPolyline(coordinates: coordinates, count: UInt(coordinates.count)) + ``` A polyline is known as a LineString diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift index 48e6b17f44..3e949b0967 100644 --- a/platform/darwin/test/MGLDocumentationExampleTests.swift +++ b/platform/darwin/test/MGLDocumentationExampleTests.swift @@ -103,6 +103,18 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { XCTAssertNotNil(mapView.style?.source(withIdentifier: "pois")) } + + func testMGLPolyline() { + //#-example-code + let coordinates = [ + CLLocationCoordinate2D(latitude: 35.68476, longitude: -220.24257), + CLLocationCoordinate2D(latitude: 37.78428, longitude: -122.41310) + ] + let polyline = MGLPolyline(coordinates: coordinates, count: UInt(coordinates.count)) + //#-end-example-code + + XCTAssertNotNil(polyline) + } func testMGLCircleStyleLayer() { let population = MGLVectorSource(identifier: "population", configurationURL: URL(string: "https://example.com/style.json")!) -- cgit v1.2.1 From c7d7319c77dd138cac487eda2232f9bc3bc7d0b6 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Thu, 17 Aug 2017 19:19:06 -0400 Subject: [ios, macos] Fix querying features returning nil when features available. (#9784) * [ios, macos] Fix querying features returning nil when features available. * [ios, macos] Copyedited changelogs Also, macOS SDK v0.5.1 has yet to be released, because none of the changes that went into iOS SDK v3.6.1 were relevant to macOS. --- platform/darwin/src/MGLSource.mm | 5 +++-- platform/darwin/src/MGLSource_Private.h | 2 +- platform/darwin/src/MGLStyle.mm | 9 +++++---- platform/ios/CHANGELOG.md | 3 ++- platform/macos/CHANGELOG.md | 5 ++++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm index eb859ba2c0..7bab90e9de 100644 --- a/platform/darwin/src/MGLSource.mm +++ b/platform/darwin/src/MGLSource.mm @@ -27,17 +27,18 @@ return self; } -- (instancetype)initWithRawSource:(mbgl::style::Source *)rawSource { +- (instancetype)initWithRawSource:(mbgl::style::Source *)rawSource mapView:(MGLMapView *)mapView { NSString *identifier = @(rawSource->getID().c_str()); if (self = [self initWithIdentifier:identifier]) { _rawSource = rawSource; _rawSource->peer = SourceWrapper { self }; + _mapView = mapView; } return self; } - (instancetype)initWithPendingSource:(std::unique_ptr)pendingSource { - if (self = [self initWithRawSource:pendingSource.get()]) { + if (self = [self initWithRawSource:pendingSource.get() mapView:nil]) { _pendingSource = std::move(pendingSource); } return self; diff --git a/platform/darwin/src/MGLSource_Private.h b/platform/darwin/src/MGLSource_Private.h index 91bfac6390..13a3dd5a30 100644 --- a/platform/darwin/src/MGLSource_Private.h +++ b/platform/darwin/src/MGLSource_Private.h @@ -26,7 +26,7 @@ struct SourceWrapper { Initializes and returns a source with a raw pointer to the backing store, associated with a style. */ -- (instancetype)initWithRawSource:(mbgl::style::Source *)rawSource; +- (instancetype)initWithRawSource:(mbgl::style::Source *)rawSource mapView:(nullable MGLMapView *)mapView; /** Initializes and returns a source with an owning pointer to the backing store, diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 1e0a2e02b7..d8aa014341 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -187,6 +187,7 @@ static NSURL *MGLStyleURL_emerald; - (MGLSource *)sourceWithIdentifier:(NSString *)identifier { auto rawSource = self.mapView.mbglMap->getSource(identifier.UTF8String); + return rawSource ? [self sourceFromMBGLSource:rawSource] : nil; } @@ -198,13 +199,13 @@ static NSURL *MGLStyleURL_emerald; // TODO: Fill in options specific to the respective source classes // https://github.com/mapbox/mapbox-gl-native/issues/6584 if (auto vectorSource = rawSource->as()) { - return [[MGLVectorSource alloc] initWithRawSource:vectorSource]; + return [[MGLVectorSource alloc] initWithRawSource:vectorSource mapView:self.mapView]; } else if (auto geoJSONSource = rawSource->as()) { - return [[MGLShapeSource alloc] initWithRawSource:geoJSONSource]; + return [[MGLShapeSource alloc] initWithRawSource:geoJSONSource mapView:self.mapView]; } else if (auto rasterSource = rawSource->as()) { - return [[MGLRasterSource alloc] initWithRawSource:rasterSource]; + return [[MGLRasterSource alloc] initWithRawSource:rasterSource mapView:self.mapView]; } else { - return [[MGLSource alloc] initWithRawSource:rawSource]; + return [[MGLSource alloc] initWithRawSource:rawSource mapView:self.mapView]; } } diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 8535073cd0..e657472aa5 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -4,9 +4,10 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ## 3.6.2 -* Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) +* Added an `MGLStyle.localizesLabels` property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) * Added an additional camera method to MGLMapView that accepts an edge padding parameter. ([#9651](https://github.com/mapbox/mapbox-gl-native/pull/9651)) * Fixed an issue with the scaling of the user location annotation’s horizontal accuracy indicator. ([#9721](https://github.com/mapbox/mapbox-gl-native/pull/9721)) +* Fixed an issue that caused `-[MGLShapeSource featuresMatchingPredicate:]` and `-[MGLVectorSource featuresInSourceLayersWithIdentifiers:predicate:]` to always return an empty array. ([#9784](https://github.com/mapbox/mapbox-gl-native/pull/9784)) ## 3.6.1 - July 28, 2017 diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 1af3c03d68..b8ed40cde6 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -2,7 +2,10 @@ ## 0.5.1 -* Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) +This version of the Mapbox macOS SDK corresponds to version 3.6.2 of the Mapbox iOS SDK. + +* Added an `MGLStyle.localizesLabels` property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) +* Fixed an issue that caused `-[MGLShapeSource featuresMatchingPredicate:]` and `-[MGLVectorSource featuresInSourceLayersWithIdentifiers:predicate:]` to always return an empty array. ([#9784](https://github.com/mapbox/mapbox-gl-native/pull/9784)) ## 0.5.0 -- cgit v1.2.1 From 1188707dc3ca6d88349d4bf323d03e3e93c0e548 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 10 Aug 2017 11:47:31 -0700 Subject: [core] Use separate attribute component for line normals Selective cherry pick of 822df3dd514ec3d05f876e6746cb8ba6348ac89d --- include/mbgl/util/constants.hpp | 3 ++- src/mbgl/programs/attributes.hpp | 1 + src/mbgl/programs/line_program.cpp | 2 +- src/mbgl/programs/line_program.hpp | 12 +++++++----- src/mbgl/renderer/line_bucket.cpp | 6 +++--- src/mbgl/shaders/line.cpp | 20 +++++++++----------- src/mbgl/shaders/line_pattern.cpp | 19 +++++++++---------- src/mbgl/shaders/line_sdf.cpp | 19 +++++++++---------- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index 0f2779e33b..dbc4bddde5 100644 --- a/include/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -19,7 +19,8 @@ constexpr float tileSize = 512; * * Positions are stored as signed 16bit integers. * One bit is lost for signedness to support features extending past the left edge of the tile. - * One bit is lost because the line vertex buffer packs 1 bit of other data into the int. + * One bit is lost because the line vertex buffer used to pack 1 bit of other data into the int. + * This is no longer the case but we're reserving this bit anyway. * One bit is lost to support features extending past the extent on the right edge of the tile. * This leaves us with 2^13 = 8192 */ diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp index a0b2b93e16..53eae49b77 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -23,6 +23,7 @@ inline uint16_t packUint8Pair(T a, T b) { MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos); MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_extrude); MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_pos_offset); +MBGL_DEFINE_ATTRIBUTE(int16_t, 3, a_pos_normal); MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos); MBGL_DEFINE_ATTRIBUTE(int16_t, 3, a_normal); MBGL_DEFINE_ATTRIBUTE(uint16_t, 1, a_edgedistance); diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp index d9778ba7ce..d18dc1e7eb 100644 --- a/src/mbgl/programs/line_program.cpp +++ b/src/mbgl/programs/line_program.cpp @@ -10,7 +10,7 @@ namespace mbgl { using namespace style; -static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size"); +static_assert(sizeof(LineLayoutVertex) == 10, "expected LineLayoutVertex size"); template Values makeValues(const LinePaintProperties::Evaluated& properties, diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index b2e55a4f3b..0a56ae5dad 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -31,7 +31,7 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_gl_units_to_pixels); } // namespace uniforms struct LineLayoutAttributes : gl::Attributes< - attributes::a_pos, + attributes::a_pos_normal, attributes::a_data> {}; @@ -52,14 +52,16 @@ public: /* * @param p vertex position * @param e extrude normal - * @param t texture normal + * @param round whether the vertex uses a round line cap + * @param up whether the line normal points up or down * @param dir direction of the line cap (-1/0/1) */ - static LayoutVertex layoutVertex(Point p, Point e, Point t, int8_t dir, int32_t linesofar = 0) { + static LayoutVertex layoutVertex(Point p, Point e, bool round, bool up, int8_t dir, int32_t linesofar = 0) { return LayoutVertex { {{ - static_cast((p.x * 2) | t.x), - static_cast((p.y * 2) | t.y) + p.x, + p.y, + static_cast(attributes::packUint8Pair(round ? 1 : 0, up ? 1 : 0)) }}, {{ // add 128 to store a byte in an unsigned byte diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index 7bb4e2f202..c80b8900ea 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -398,7 +398,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate, Point extrude = normal; if (endLeft) extrude = extrude - (util::perp(normal) * endLeft); - vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, { round, false }, endLeft, distance * LINE_DISTANCE_SCALE)); + vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, round, false, endLeft, distance * LINE_DISTANCE_SCALE)); e3 = vertices.vertexSize() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); @@ -409,7 +409,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate, extrude = normal * -1.0; if (endRight) extrude = extrude - (util::perp(normal) * endRight); - vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, { round, true }, -endRight, distance * LINE_DISTANCE_SCALE)); + vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, round, true, -endRight, distance * LINE_DISTANCE_SCALE)); e3 = vertices.vertexSize() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); @@ -434,7 +434,7 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex, std::size_t startVertex, std::vector& triangleStore) { Point flippedExtrude = extrude * (lineTurnsLeft ? -1.0 : 1.0); - vertices.emplace_back(LineProgram::layoutVertex(currentVertex, flippedExtrude, { false, lineTurnsLeft }, 0, distance * LINE_DISTANCE_SCALE)); + vertices.emplace_back(LineProgram::layoutVertex(currentVertex, flippedExtrude, false, lineTurnsLeft, 0, distance * LINE_DISTANCE_SCALE)); e3 = vertices.vertexSize() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index dce6046257..ce62ecb3bd 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -21,7 +21,7 @@ const char* line::vertexSource = R"MBGL_SHADER( // #define scale 63.0 #define scale 0.015873016 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -107,20 +107,21 @@ void main() { vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); - v_normal = normal; + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float width = u_width / 2.0; - offset = -1.0 * offset; + offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -137,9 +138,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index 1c07b4f515..f43b3a3cf7 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -23,7 +23,7 @@ const char* line_pattern::vertexSource = R"MBGL_SHADER( // Retina devices need a smaller distance to avoid aliasing. #define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -97,19 +97,21 @@ void main() { float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float width = u_width / 2.0; - offset = -1.0 * offset; + offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -126,9 +128,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index b37bf688d4..24b7153c7f 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -23,7 +23,7 @@ const char* line_sdf::vertexSource = R"MBGL_SHADER( // Retina devices need a smaller distance to avoid aliasing. #define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -116,20 +116,22 @@ void main() { float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float width = u_width / 2.0; offset = -1.0 * offset; - + float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -145,9 +147,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; -- cgit v1.2.1 From cd36ec00bc44990df1bde02668e104307b30e7d2 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 18 Jul 2017 19:17:11 -0400 Subject: [ios] Add debug descriptions to shapes and features --- platform/darwin/src/MGLFeature.mm | 49 ++++++++++++++++++++++++++++++++++++++ platform/darwin/src/MGLPolygon.mm | 10 ++++++++ platform/darwin/src/MGLPolyline.mm | 10 ++++++++ 3 files changed, 69 insertions(+) diff --git a/platform/darwin/src/MGLFeature.mm b/platform/darwin/src/MGLFeature.mm index e169ee19bb..84f1a1ff25 100644 --- a/platform/darwin/src/MGLFeature.mm +++ b/platform/darwin/src/MGLFeature.mm @@ -42,6 +42,15 @@ MGL_DEFINE_FEATURE_IS_EQUAL(); return mbglFeature({[self geometryObject]}, identifier, self.attributes); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@, coordinate = %f, %f, attributes = %@>", + NSStringFromClass([self class]), (void *)self, + self.identifier ? [NSString stringWithFormat:@"\"%@\"", self.identifier] : self.identifier, + self.coordinate.latitude, self.coordinate.longitude, + self.attributes.count ? self.attributes : @"none"]; +} + @end @interface MGLPolylineFeature () @@ -68,6 +77,16 @@ MGL_DEFINE_FEATURE_IS_EQUAL(); return mbglFeature({[self geometryObject]}, identifier, self.attributes); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@, count = %lu, bounds = %@, attributes = %@>", + NSStringFromClass([self class]), (void *)self, + self.identifier ? [NSString stringWithFormat:@"\"%@\"", self.identifier] : self.identifier, + (unsigned long)[self pointCount], + MGLStringFromCoordinateBounds(self.overlayBounds), + self.attributes.count ? self.attributes : @"none"]; +} + @end @interface MGLPolygonFeature () @@ -94,6 +113,16 @@ MGL_DEFINE_FEATURE_IS_EQUAL(); return mbglFeature({[self geometryObject]}, identifier, self.attributes); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@, count = %lu, bounds = %@, attributes = %@>", + NSStringFromClass([self class]), (void *)self, + self.identifier ? [NSString stringWithFormat:@"\"%@\"", self.identifier] : self.identifier, + (unsigned long)[self pointCount], + MGLStringFromCoordinateBounds(self.overlayBounds), + self.attributes.count ? self.attributes : @"none"]; +} + @end @interface MGLPointCollectionFeature () @@ -146,6 +175,16 @@ MGL_DEFINE_FEATURE_IS_EQUAL(); return mbglFeature({[self geometryObject]}, identifier, self.attributes); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@, count = %lu, bounds = %@, attributes = %@>", + NSStringFromClass([self class]), (void *)self, + self.identifier ? [NSString stringWithFormat:@"\"%@\"", self.identifier] : self.identifier, + (unsigned long)self.polylines.count, + MGLStringFromCoordinateBounds(self.overlayBounds), + self.attributes.count ? self.attributes : @"none"]; +} + @end @interface MGLMultiPolygonFeature () @@ -172,6 +211,16 @@ MGL_DEFINE_FEATURE_IS_EQUAL(); return mbglFeature({[self geometryObject]}, identifier, self.attributes); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@, count = %lu, bounds = %@, attributes = %@>", + NSStringFromClass([self class]), (void *)self, + self.identifier ? [NSString stringWithFormat:@"\"%@\"", self.identifier] : self.identifier, + (unsigned long)self.polygons.count, + MGLStringFromCoordinateBounds(self.overlayBounds), + self.attributes.count ? self.attributes : @"none"]; +} + @end @interface MGLShapeCollectionFeature () diff --git a/platform/darwin/src/MGLPolygon.mm b/platform/darwin/src/MGLPolygon.mm index d966ff13ce..e7843224e9 100644 --- a/platform/darwin/src/MGLPolygon.mm +++ b/platform/darwin/src/MGLPolygon.mm @@ -200,4 +200,14 @@ @"coordinates": coordinates}; } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; title = %@, subtitle: = %@, count = %lu; bounds = %@>", + NSStringFromClass([self class]), (void *)self, + self.title ? [NSString stringWithFormat:@"\"%@\"", self.title] : self.title, + self.subtitle ? [NSString stringWithFormat:@"\"%@\"", self.subtitle] : self.subtitle, + (unsigned long)self.polygons.count, + MGLStringFromCoordinateBounds(self.overlayBounds)]; +} + @end diff --git a/platform/darwin/src/MGLPolyline.mm b/platform/darwin/src/MGLPolyline.mm index fd75dc2795..0e371a4dda 100644 --- a/platform/darwin/src/MGLPolyline.mm +++ b/platform/darwin/src/MGLPolyline.mm @@ -201,4 +201,14 @@ @"coordinates": coordinates}; } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; title = %@, subtitle: = %@, count = %lu; bounds = %@>", + NSStringFromClass([self class]), (void *)self, + self.title ? [NSString stringWithFormat:@"\"%@\"", self.title] : self.title, + self.subtitle ? [NSString stringWithFormat:@"\"%@\"", self.subtitle] : self.subtitle, + (unsigned long)self.polylines.count, + MGLStringFromCoordinateBounds(self.overlayBounds)]; +} + @end -- cgit v1.2.1 From b5b84ef52db663f07fb5ecfdd0a9a0ea80b87b01 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 18 Jul 2017 19:11:55 -0400 Subject: [ios] Warn about using MGLFeature-conforming annotations w/querying --- platform/darwin/docs/guides/Working with GeoJSON Data.md | 6 ++++-- platform/darwin/src/MGLFeature.h | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/platform/darwin/docs/guides/Working with GeoJSON Data.md b/platform/darwin/docs/guides/Working with GeoJSON Data.md index 57aaa3855d..f3b3dc0918 100644 --- a/platform/darwin/docs/guides/Working with GeoJSON Data.md +++ b/platform/darwin/docs/guides/Working with GeoJSON Data.md @@ -81,8 +81,10 @@ Linear ring | `MGLPolygon.coordinates`, `MGLPolygon.interiorPolygons` A `Feature` object in GeoJSON corresponds to an instance of an `MGLShape` subclass conforming to the `MGLFeature` protocol. There is a distinct `MGLFeature`-conforming class for each type of geometry that a GeoJSON feature -can contain. This allows features to be used as shapes where convenient. For -example, some features can be added to a map view as annotations. +can contain. This allows features to be used as raw shapes where convenient. For +example, some features can be added to a map view as annotations. Note that +identifiers and attributes will not be available for feature querying when a +feature is used as an annotation. In contrast to the GeoJSON standard, it is possible for `MGLShape` subclasses other than `MGLPointAnnotation` to straddle the antimeridian. diff --git a/platform/darwin/src/MGLFeature.h b/platform/darwin/src/MGLFeature.h index 491c89b608..a13821cf96 100644 --- a/platform/darwin/src/MGLFeature.h +++ b/platform/darwin/src/MGLFeature.h @@ -18,15 +18,23 @@ NS_ASSUME_NONNULL_BEGIN You can add custom data to display on the map by creating feature objects and adding them to an `MGLShapeSource` using the `-[MGLShapeSource initWithIdentifier:shape:options:]` method or - `MGLShapeSource.shape` property. Similarly, you can add `MGLPointFeature`, - `MGLPolylineFeature`, and `MGLPolygonFeature` objects to the map as annotations - using `-[MGLMapView addAnnotations:]` and related methods. + `MGLShapeSource.shape` property. In addition to adding data to the map, you can also extract data from the map: `-[MGLMapView visibleFeaturesAtPoint:]` and related methods return feature objects that correspond to features in the source. This enables you to inspect the properties of features in vector tiles loaded by `MGLVectorSource` objects. You also reuse these feature objects as overlay annotations. + + While it is possible to add `MGLFeature`-conforming objects to the map as + annotations using `-[MGLMapView addAnnotations:]` and related methods, doing so + has trade-offs: + + - Features added as annotations will not have `identifier` or `attributes` + properties when used with feature querying. + + - Features added as annotations become interactive. Taps and selection can be + handled in `-[MGLMapViewDelegate mapView:didSelectAnnotation:]`. */ @protocol MGLFeature -- cgit v1.2.1 From 001988fba1e6eb2f6db2acdb68f26d583c48f53a Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Fri, 18 Aug 2017 15:38:16 -0400 Subject: [ios] Update pods spec for iOS v3.6.2 (#9806) --- platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec | 2 +- platform/ios/Mapbox-iOS-SDK-symbols.podspec | 2 +- platform/ios/Mapbox-iOS-SDK.podspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec b/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec index db5ca23c16..b5f9af2e61 100644 --- a/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec +++ b/platform/ios/Mapbox-iOS-SDK-nightly-dynamic.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |m| - version = '3.6.1' + version = '3.6.2' m.name = 'Mapbox-iOS-SDK-nightly-dynamic' m.version = "#{version}-nightly" diff --git a/platform/ios/Mapbox-iOS-SDK-symbols.podspec b/platform/ios/Mapbox-iOS-SDK-symbols.podspec index be4d469f70..0fcd335071 100644 --- a/platform/ios/Mapbox-iOS-SDK-symbols.podspec +++ b/platform/ios/Mapbox-iOS-SDK-symbols.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |m| - version = '3.6.1' + version = '3.6.2' m.name = 'Mapbox-iOS-SDK-symbols' m.version = "#{version}-symbols" diff --git a/platform/ios/Mapbox-iOS-SDK.podspec b/platform/ios/Mapbox-iOS-SDK.podspec index 53779307a8..0224048ff5 100644 --- a/platform/ios/Mapbox-iOS-SDK.podspec +++ b/platform/ios/Mapbox-iOS-SDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |m| - version = '3.6.1' + version = '3.6.2' m.name = 'Mapbox-iOS-SDK' m.version = version -- cgit v1.2.1 From 05cbd4e31d40921acea40ad935ceb06a0ea08324 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 29 Jun 2017 13:36:59 +0200 Subject: [android] - keep state of initial overlain views margins (#9391) --- .../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 45 ++++++++++++++-------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index 3f43c23a7f..e71d509fcf 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -36,8 +36,14 @@ public final class UiSettings { private final FocalPointChangeListener focalPointChangeListener; private final Projection projection; private final CompassView compassView; + private final int[] compassMargins = new int[4]; + private final ImageView attributionsView; + private final int[] attributionsMargins = new int[4]; + private final View logoView; + private final int[] logoMargins = new int[4]; + private float pixelRatio; private boolean rotateGesturesEnabled = true; @@ -368,7 +374,7 @@ public final class UiSettings { */ @UiThread public void setCompassMargins(int left, int top, int right, int bottom) { - setWidgetMargins(compassView, left, top, right, bottom); + setWidgetMargins(compassView, compassMargins, left, top, right, bottom); } /** @@ -377,7 +383,7 @@ public final class UiSettings { * @return The left margin in pixels */ public int getCompassMarginLeft() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).leftMargin; + return compassMargins[0]; } /** @@ -386,7 +392,7 @@ public final class UiSettings { * @return The top margin in pixels */ public int getCompassMarginTop() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).topMargin; + return compassMargins[1]; } /** @@ -395,7 +401,7 @@ public final class UiSettings { * @return The right margin in pixels */ public int getCompassMarginRight() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).rightMargin; + return compassMargins[2]; } /** @@ -404,7 +410,7 @@ public final class UiSettings { * @return The bottom margin in pixels */ public int getCompassMarginBottom() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).bottomMargin; + return compassMargins[3]; } /** @@ -478,7 +484,7 @@ public final class UiSettings { * @param bottom The bottom margin in pixels. */ public void setLogoMargins(int left, int top, int right, int bottom) { - setWidgetMargins(logoView, left, top, right, bottom); + setWidgetMargins(logoView, logoMargins, left, top, right, bottom); } /** @@ -487,7 +493,7 @@ public final class UiSettings { * @return The left margin in pixels */ public int getLogoMarginLeft() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).leftMargin; + return logoMargins[0]; } /** @@ -496,7 +502,7 @@ public final class UiSettings { * @return The top margin in pixels */ public int getLogoMarginTop() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).topMargin; + return logoMargins[1]; } /** @@ -505,7 +511,7 @@ public final class UiSettings { * @return The right margin in pixels */ public int getLogoMarginRight() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).rightMargin; + return logoMargins[2]; } /** @@ -514,7 +520,7 @@ public final class UiSettings { * @return The bottom margin in pixels */ public int getLogoMarginBottom() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).bottomMargin; + return logoMargins[3]; } /** @@ -568,7 +574,7 @@ public final class UiSettings { * @param bottom The bottom margin in pixels. */ public void setAttributionMargins(int left, int top, int right, int bottom) { - setWidgetMargins(attributionsView, left, top, right, bottom); + setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom); } /** @@ -595,7 +601,7 @@ public final class UiSettings { * @return The left margin in pixels */ public int getAttributionMarginLeft() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).leftMargin; + return attributionsMargins[0]; } /** @@ -604,7 +610,7 @@ public final class UiSettings { * @return The top margin in pixels */ public int getAttributionMarginTop() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).topMargin; + return attributionsMargins[1]; } /** @@ -613,7 +619,7 @@ public final class UiSettings { * @return The right margin in pixels */ public int getAttributionMarginRight() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).rightMargin; + return attributionsMargins[2]; } /** @@ -622,7 +628,7 @@ public final class UiSettings { * @return The bottom margin in pixels */ public int getAttributionMarginBottom() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).bottomMargin; + return attributionsMargins[3]; } /** @@ -926,7 +932,14 @@ public final class UiSettings { view.setLayoutParams(layoutParams); } - private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) { + private void setWidgetMargins(@NonNull final View view, int[] initMargins, int left, int top, int right, int bottom) { + // keep state of initially set margins + initMargins[0] = left; + initMargins[1] = top; + initMargins[2] = right; + initMargins[3] = bottom; + + // convert inital margins with padding int[] contentPadding = projection.getContentPadding(); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams(); left += contentPadding[0]; -- cgit v1.2.1 From b4cb719ceba57b5b2879d54473531c3404a20c77 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 10 Aug 2017 13:18:46 +0200 Subject: [android] - provide compability with Samsung devices forcing 3-4 array matrix length --- .../mapboxsdk/maps/widgets/MyLocationView.java | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 24da59bb7e..61b0efe656 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -797,6 +797,9 @@ public class MyLocationView extends View { private Sensor rotationVectorSensor; private float[] matrix = new float[9]; + private float[] rotationVectorValue; + private float[] truncatedRotationVectorValue = new float[4]; + private float[] orientation = new float[3]; private boolean reportMissingSensor = true; // Compass data @@ -833,9 +836,8 @@ public class MyLocationView extends View { } if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { - - // calculate the rotation matrix - SensorManager.getRotationMatrixFromVector(matrix, event.values); + rotationVectorValue = getRotationVectorFromSensorEvent(event); + SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValue); SensorManager.getOrientation(matrix, orientation); magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation)[0]); @@ -852,6 +854,28 @@ public class MyLocationView extends View { } } + /** + * Pulls out the rotation vector from a SensorEvent, with a maximum length + * vector of four elements to avoid potential compatibility issues. + * + * @param event the sensor event + * @return the events rotation vector, potentially truncated + */ + @NonNull + float[] getRotationVectorFromSensorEvent(@NonNull SensorEvent event) { + if (event.values.length > 4) { + // On some Samsung devices SensorManager.getRotationMatrixFromVector + // appears to throw an exception if rotation vector has length > 4. + // For the purposes of this class the first 4 values of the + // rotation vector are sufficient (see crbug.com/335298 for details). + // Only affects Android 4.3 + System.arraycopy(event.values, 0, truncatedRotationVectorValue, 0, 4); + return truncatedRotationVectorValue; + } else { + return event.values; + } + } + private void rotateCamera(float rotation) { CameraPosition.Builder builder = new CameraPosition.Builder(); builder.bearing(rotation); -- cgit v1.2.1 From 2802c55bd5e4f104fee991cb944e4d2503cbb18d Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 10 Aug 2017 15:07:48 +0200 Subject: [android] - create smallest possible LatLngBounds when visible region crosses the dateline --- .../com/mapbox/mapboxsdk/geometry/LatLngBounds.java | 10 ++++++++++ .../java/com/mapbox/mapboxsdk/maps/Projection.java | 15 +++++++-------- .../activity/maplayout/SimpleMapActivity.java | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java index 505b2db192..8b2ccffef1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java @@ -221,6 +221,16 @@ public class LatLngBounds implements Parcelable { return new LatLng[] {getNorthEast(), getSouthWest()}; } + /** + * Constructs a LatLngBounds from doubles representing a LatLng pair. + *

+ * This method doesn't recalculate most east or most west boundaries. + *

+ */ + public static LatLngBounds from(double latNorth, double lonEast, double latSouth, double lonWest) { + return new LatLngBounds(latNorth, lonEast, latSouth, lonWest); + } + /** * Constructs a LatLngBounds from current bounds with an additional latitude-longitude pair. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java index e0a634521b..3841809a65 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java @@ -78,8 +78,6 @@ public class Projection { * @return The projection of the viewing frustum in its current state. */ public VisibleRegion getVisibleRegion() { - LatLngBounds.Builder builder = new LatLngBounds.Builder(); - float left = 0; float right = nativeMapView.getWidth(); float top = 0; @@ -90,12 +88,13 @@ public class Projection { LatLng bottomRight = fromScreenLocation(new PointF(right, bottom)); LatLng bottomLeft = fromScreenLocation(new PointF(left, bottom)); - builder.include(topLeft) - .include(topRight) - .include(bottomRight) - .include(bottomLeft); - - return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight, builder.build()); + return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight, + LatLngBounds.from( + topRight.getLatitude(), + topRight.getLongitude(), + bottomLeft.getLatitude(), + bottomLeft.getLongitude()) + ); } /** diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java index 8f8a5af3cc..badb6718cf 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java @@ -1,11 +1,18 @@ package com.mapbox.mapboxsdk.testapp.activity.maplayout; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; +import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.Projection; import com.mapbox.mapboxsdk.testapp.R; +import timber.log.Timber; + /** * Test activity showcasing a simple MapView without any MapboxMap interaction. */ @@ -20,6 +27,19 @@ public class SimpleMapActivity extends AppCompatActivity { mapView = (MapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap mapboxMap) { + final Projection projection = mapboxMap.getProjection(); + + mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() { + @Override + public void onMapClick(@NonNull LatLng point) { + Timber.e(projection.getVisibleRegion().toString()); + } + }); + } + }); } @Override -- cgit v1.2.1 From a83c19e9543ae3a84bfe41db9a03a9f4f4957064 Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Mon, 14 Aug 2017 14:18:51 +0200 Subject: [android] - re-add projectedMeters --- .../main/java/com/mapbox/mapboxsdk/maps/Projection.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java index 3841809a65..16c73b1ca5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java @@ -6,6 +6,7 @@ import android.support.annotation.NonNull; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.ProjectedMeters; import com.mapbox.mapboxsdk.geometry.VisibleRegion; /** @@ -44,6 +45,20 @@ public class Projection { setContentPadding(contentPadding, userLocationViewPadding); } + /** + * Returns the spherical Mercator projected meters for a LatLng. + */ + public ProjectedMeters getProjectedMetersForLatLng(LatLng latLng) { + return nativeMapView.projectedMetersForLatLng(latLng); + } + + /** + * Returns the LatLng for a spherical Mercator projected meters. + */ + public LatLng getLatLngForProjectedMeters(ProjectedMeters projectedMeters) { + return nativeMapView.latLngForProjectedMeters(projectedMeters); + } + /** *

* Returns the distance spanned by one pixel at the specified latitude and current zoom level. -- cgit v1.2.1 From f356ff4b0047179d42e25d46578fc464e341ee5d Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Wed, 16 Aug 2017 10:31:21 +0200 Subject: [android] - enable location change animation of MyLocationView by default --- .../src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 61b0efe656..f74286705c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -75,7 +75,7 @@ public class MyLocationView extends View { private ValueAnimator locationChangeAnimator; private ValueAnimator accuracyAnimator; private ValueAnimator directionAnimator; - private boolean locationChangeAnimationEnabled; + private boolean locationChangeAnimationEnabled = true; private ValueAnimator.AnimatorUpdateListener invalidateSelfOnUpdateListener = new ValueAnimator.AnimatorUpdateListener() { -- cgit v1.2.1 From 341165cef44c7ecd67f3a911eb29e0433d33e14c Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Thu, 17 Aug 2017 10:32:49 +0200 Subject: [android] - avoid IndexOutOfBounds when destroying map object --- .../mapbox/mapboxsdk/maps/AnnotationManager.java | 46 +++++++++------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index 712ab67de0..d15d5eddf8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -212,22 +212,19 @@ class AnnotationManager { } if (markers.size() > 0) { - long[] ids = null; + long[] ids; if (nativeMapView != null) { ids = nativeMapView.addMarkers(markers); + } else { + ids = new long[markers.size()]; } - long id = 0; + long id; Marker m; - for (int i = 0; i < markers.size(); i++) { + for (int i = 0; i < ids.length; i++) { m = markers.get(i); m.setMapboxMap(mapboxMap); - if (ids != null) { - id = ids[i]; - } else { - // unit test - id++; - } + id = ids[i]; m.setId(id); annotations.put(id, m); } @@ -481,21 +478,18 @@ class AnnotationManager { } } - long[] ids = null; + long[] ids; if (nativeMapView != null) { ids = nativeMapView.addPolygons(polygons); + } else { + ids = new long[polygons.size()]; } - long id = 0; - for (int i = 0; i < polygons.size(); i++) { + long id; + for (int i = 0; i < ids.length; i++) { polygon = polygons.get(i); polygon.setMapboxMap(mapboxMap); - if (ids != null) { - id = ids[i]; - } else { - // unit test - id++; - } + id = ids[i]; polygon.setId(id); shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id); annotations.put(id, polygon); @@ -555,23 +549,19 @@ class AnnotationManager { } } - long[] ids = null; + long[] ids; if (nativeMapView != null) { ids = nativeMapView.addPolylines(polylines); + } else { + ids = new long[polylines.size()]; } - long id = 0; + long id; Polyline p; - - for (int i = 0; i < polylines.size(); i++) { + for (int i = 0; i < ids.length; i++) { p = polylines.get(i); p.setMapboxMap(mapboxMap); - if (ids != null) { - id = ids[i]; - } else { - // unit test - id++; - } + id = ids[i]; p.setId(id); shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id); annotations.put(id, p); -- cgit v1.2.1 From 78633322d76f68d552e1059dc069afaf59a132d2 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Thu, 17 Aug 2017 17:34:43 -0400 Subject: bumped MAS version number --- platform/android/dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/dependencies.gradle b/platform/android/dependencies.gradle index a4b202086a..1257ec59a6 100644 --- a/platform/android/dependencies.gradle +++ b/platform/android/dependencies.gradle @@ -7,7 +7,7 @@ ext { versionCode = 12 versionName = "5.1.3" - mapboxServicesVersion = "2.2.0" + mapboxServicesVersion = "2.2.1" supportLibVersion = "25.3.1" wearableVersion = '2.0.0' espressoVersion = '2.2.2' -- cgit v1.2.1 From 6de3e6fe7001bf8ce6bfff066855e73150377124 Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Fri, 18 Aug 2017 11:49:00 +0200 Subject: [android] - update changelog for v5.1.3 --- platform/android/CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 485ceaab8a..6d1422e234 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -2,7 +2,18 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started. -## 5.1.2 - August 2, 20017 +## 5.1.3 - August 18, 2017 + +* Use separate attribute component for line normals [#9753](https://github.com/mapbox/mapbox-gl-native/pull/9753) +* Track state of initial overlain views margins [#9391](https://github.com/mapbox/mapbox-gl-native/pull/9391) +* Compability for Samsung devices forcing 3-4 array vector length [#9746](https://github.com/mapbox/mapbox-gl-native/pull/9746) +* Smallest LatLngBounds when visible region crosses dateline [#9747](https://github.com/mapbox/mapbox-gl-native/pull/9747) +* Readd ProjectMeters [#9766](https://github.com/mapbox/mapbox-gl-native/pull/9766) +* Enable location change animation of MyLocationView by default [#9779](https://github.com/mapbox/mapbox-gl-native/pull/9779) +* Avoid IndexOutOfBoundsException when destroying map object [#9789](https://github.com/mapbox/mapbox-gl-native/pull/9789) +* MAS 2.2.1 [#9796](https://github.com/mapbox/mapbox-gl-native/pull/9796) + +## 5.1.2 - August 2, 2017 * Disable program caching on Ardreno GPU 3xx, 4xx and 5xx [#9625](https://github.com/mapbox/mapbox-gl-native/pull/9625) * GeoJSON proguard issue [#9577](https://github.com/mapbox/mapbox-gl-native/pull/9577) -- cgit v1.2.1 From 8d04e099c7a4b0c8b100c24930f0407ba13b454c Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Fri, 18 Aug 2017 11:50:45 +0200 Subject: [android] - update config for next reelease --- platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +- .../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +- platform/android/dependencies.gradle | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties index af1d04ab97..033903822f 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle.properties +++ b/platform/android/MapboxGLAndroidSDK/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.mapbox.mapboxsdk -VERSION_NAME=5.1.3-SNAPSHOT +VERSION_NAME=5.1.4-SNAPSHOT POM_DESCRIPTION=Mapbox GL Android SDK POM_URL=https://github.com/mapbox/mapbox-gl-native diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties index 3cfc7d5fdc..81e0e5d7a8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties +++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties @@ -1,3 +1,3 @@ fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk -fabric-version=5.1.2 +fabric-version=5.1.3 fabric-build-type=binary diff --git a/platform/android/dependencies.gradle b/platform/android/dependencies.gradle index 1257ec59a6..4302fd816a 100644 --- a/platform/android/dependencies.gradle +++ b/platform/android/dependencies.gradle @@ -5,7 +5,7 @@ ext { buildToolsVersion = "25.0.2" versionCode = 12 - versionName = "5.1.3" + versionName = "5.1.4" mapboxServicesVersion = "2.2.1" supportLibVersion = "25.3.1" -- cgit v1.2.1 From acb8199d326eda02102b2d409ebec510053fec1b Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Fri, 18 Aug 2017 15:17:04 -0400 Subject: [ios] Document annotations-as-features limitations w/feature querying Also move visibleAnnotations next to visibleAnnotationsInRect:. --- platform/ios/src/MGLMapView.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index a0aada9a9c..a514d15b41 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -990,16 +990,6 @@ MGL_EXPORT IB_DESIGNABLE */ @property (nonatomic, readonly, nullable) NS_ARRAY_OF(id ) *annotations; -/** - The complete list of annotations associated with the receiver that are - currently visible. - - The objects in this array must adopt the `MGLAnnotation` protocol. If no - annotations are associated with the map view or if no annotations associated - with the map view are currently visible, the value of this property is `nil`. - */ -@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id ) *visibleAnnotations; - /** Adds an annotation to the map view. @@ -1094,6 +1084,16 @@ MGL_EXPORT IB_DESIGNABLE */ - (nullable __kindof MGLAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier; +/** + The complete list of annotations associated with the receiver that are + currently visible. + + The objects in this array must adopt the `MGLAnnotation` protocol. If no + annotations are associated with the map view or if no annotations associated + with the map view are currently visible, the value of this property is `nil`. + */ +@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id ) *visibleAnnotations; + /** Returns the list of annotations associated with the receiver that intersect with the given rectangle. @@ -1254,6 +1254,11 @@ MGL_EXPORT IB_DESIGNABLE `-[MGLVectorSource featuresInSourceLayersWithIdentifiers:predicate:]` and `-[MGLShapeSource featuresMatchingPredicate:]` methods on the relevant sources. + The returned features may also include features corresponding to annotations. + These features are not object-equal to the `MGLAnnotation` objects that were + originally added to the map. To query the map for annotations, use + `visibleAnnotations` or `-[MGLMapView visibleAnnotationsInRect:]`. + @note Layer identifiers are not guaranteed to exist across styles or different versions of the same style. Applications that use this API must first set the style URL to an explicitly versioned style using a convenience method -- cgit v1.2.1