From a2c1dd87df23b6ca300851c57312048fc5b70683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Tue, 16 Feb 2021 17:22:57 +0100 Subject: [PATCH 1/2] v10 POC --- .gitignore | 4 + example/ios/Podfile | 33 +- .../project.pbxproj | 12 +- ios/RCTMGL/Bridge/RCTMGL.h | 3 + ios/RCTMGL/CameraMode.h | 17 - ios/RCTMGL/CameraMode.m | 17 - ios/RCTMGL/CameraStop.h | 26 - ios/RCTMGL/CameraStop.m | 81 - ios/RCTMGL/CameraUpdateItem.h | 18 - ios/RCTMGL/CameraUpdateItem.m | 182 -- ios/RCTMGL/CameraUpdateQueue.h | 21 - ios/RCTMGL/CameraUpdateQueue.m | 74 - ios/RCTMGL/FilterParser.h | 14 - ios/RCTMGL/FilterParser.m | 22 - ios/RCTMGL/MGLCustomHeaders.h | 20 - ios/RCTMGL/MGLCustomHeaders.m | 98 - .../MGLFaux3DUserLocationAnnotationView.h | 23 - .../MGLFaux3DUserLocationAnnotationView.m | 474 ----- ios/RCTMGL/MGLModule.h | 13 - ios/RCTMGL/MGLModule.m | 272 +-- ios/RCTMGL/MGLModule.swift | 40 + ios/RCTMGL/MGLOfflineModule.h | 19 - ios/RCTMGL/MGLOfflineModule.m | 516 ----- ios/RCTMGL/MGLSnapshotModule.h | 13 - ios/RCTMGL/MGLSnapshotModule.m | 80 - ios/RCTMGL/MGLUserLocationHeadingArrowLayer.h | 11 - ios/RCTMGL/MGLUserLocationHeadingArrowLayer.m | 57 - ios/RCTMGL/MGLUserLocationHeadingBeamLayer.h | 11 - ios/RCTMGL/MGLUserLocationHeadingBeamLayer.m | 102 - ios/RCTMGL/MGLUserLocationHeadingIndicator.h | 10 - ios/RCTMGL/RCTConvert+Mapbox.h | 16 - ios/RCTMGL/RCTConvert+Mapbox.m | 32 - ios/RCTMGL/RCTMGL.h | 13 - ios/RCTMGL/RCTMGL.m | 13 - ios/RCTMGL/RCTMGLBackgroundLayer.h | 14 - ios/RCTMGL/RCTMGLBackgroundLayer.m | 27 - ios/RCTMGL/RCTMGLBackgroundLayerManager.h | 13 - ios/RCTMGL/RCTMGLBackgroundLayerManager.m | 35 - ios/RCTMGL/RCTMGLCallout.h | 15 - ios/RCTMGL/RCTMGLCallout.m | 74 - ios/RCTMGL/RCTMGLCalloutManager.h | 13 - ios/RCTMGL/RCTMGLCalloutManager.m | 21 - ios/RCTMGL/RCTMGLCamera.h | 39 - ios/RCTMGL/RCTMGLCamera.m | 258 --- ios/RCTMGL/RCTMGLCamera.swift | 3 + ios/RCTMGL/RCTMGLCameraManager.h | 13 - ios/RCTMGL/RCTMGLCameraManager.m | 52 +- ios/RCTMGL/RCTMGLCameraManager.swift | 17 + ios/RCTMGL/RCTMGLCircleLayer.h | 13 - ios/RCTMGL/RCTMGLCircleLayer.m | 34 - ios/RCTMGL/RCTMGLCircleLayerManager.h | 13 - ios/RCTMGL/RCTMGLCircleLayerManager.m | 39 - ios/RCTMGL/RCTMGLEvent.h | 21 - ios/RCTMGL/RCTMGLEvent.m | 47 - ios/RCTMGL/RCTMGLEventProtocol.h | 16 - ios/RCTMGL/RCTMGLEventTypes.h | 50 - ios/RCTMGL/RCTMGLEventTypes.m | 49 - ios/RCTMGL/RCTMGLFillExtrusionLayer.h | 14 - ios/RCTMGL/RCTMGLFillExtrusionLayer.m | 32 - ios/RCTMGL/RCTMGLFillExtrusionLayerManager.h | 13 - ios/RCTMGL/RCTMGLFillExtrusionLayerManager.m | 39 - ios/RCTMGL/RCTMGLFillLayer.h | 14 - ios/RCTMGL/RCTMGLFillLayer.m | 33 - ios/RCTMGL/RCTMGLFillLayerManager.h | 13 - ios/RCTMGL/RCTMGLFillLayerManager.m | 37 - ios/RCTMGL/RCTMGLHeatmapLayer.h | 12 - ios/RCTMGL/RCTMGLHeatmapLayer.m | 30 - ios/RCTMGL/RCTMGLHeatmapLayerManager.h | 12 - ios/RCTMGL/RCTMGLHeatmapLayerManager.m | 38 - ios/RCTMGL/RCTMGLImageQueue.h | 19 - ios/RCTMGL/RCTMGLImageQueue.m | 57 - ios/RCTMGL/RCTMGLImageQueueOperation.h | 17 - ios/RCTMGL/RCTMGLImageQueueOperation.m | 138 -- ios/RCTMGL/RCTMGLImageSource.h | 16 - ios/RCTMGL/RCTMGLImageSource.m | 60 - ios/RCTMGL/RCTMGLImageSourceManager.h | 13 - ios/RCTMGL/RCTMGLImageSourceManager.m | 25 - ios/RCTMGL/RCTMGLImages.h | 25 - ios/RCTMGL/RCTMGLImages.m | 126 -- ios/RCTMGL/RCTMGLImagesManager.h | 5 - ios/RCTMGL/RCTMGLImagesManager.m | 21 - ios/RCTMGL/RCTMGLLayer.h | 52 - ios/RCTMGL/RCTMGLLayer.m | 236 --- ios/RCTMGL/RCTMGLLight.h | 17 - ios/RCTMGL/RCTMGLLight.m | 46 - ios/RCTMGL/RCTMGLLightManager.h | 13 - ios/RCTMGL/RCTMGLLightManager.m | 23 - ios/RCTMGL/RCTMGLLineLayer.h | 14 - ios/RCTMGL/RCTMGLLineLayer.m | 33 - ios/RCTMGL/RCTMGLLineLayerManager.h | 13 - ios/RCTMGL/RCTMGLLineLayerManager.m | 40 - ios/RCTMGL/RCTMGLLocation.h | 19 - ios/RCTMGL/RCTMGLLocation.m | 32 - ios/RCTMGL/RCTMGLLocationManager.h | 30 - ios/RCTMGL/RCTMGLLocationManager.m | 180 -- ios/RCTMGL/RCTMGLLocationManagerDelegate.h | 20 - ios/RCTMGL/RCTMGLLocationModule.h | 15 - ios/RCTMGL/RCTMGLLocationModule.m | 100 +- ios/RCTMGL/RCTMGLLocationModule.swift | 55 + ios/RCTMGL/RCTMGLLogging.h | 18 - ios/RCTMGL/RCTMGLLogging.m | 131 +- ios/RCTMGL/RCTMGLLogging.swift | 23 + ios/RCTMGL/RCTMGLMapTouchEvent.h | 25 - ios/RCTMGL/RCTMGLMapTouchEvent.m | 77 - ios/RCTMGL/RCTMGLMapView.h | 91 - ios/RCTMGL/RCTMGLMapView.m | 511 ----- ios/RCTMGL/RCTMGLMapView.swift | 16 + ios/RCTMGL/RCTMGLMapViewManager.h | 17 - ios/RCTMGL/RCTMGLMapViewManager.m | 624 +------ ios/RCTMGL/RCTMGLMapViewManager.swift | 16 + ios/RCTMGL/RCTMGLNativeUserLocation.h | 18 - ios/RCTMGL/RCTMGLNativeUserLocation.m | 49 - ios/RCTMGL/RCTMGLNativeUserLocationManager.h | 5 - ios/RCTMGL/RCTMGLNativeUserLocationManager.m | 25 - ios/RCTMGL/RCTMGLOfflineModule.m | 4 + ios/RCTMGL/RCTMGLOfflineModule.swift | 18 + ios/RCTMGL/RCTMGLPointAnnotation.h | 41 - ios/RCTMGL/RCTMGLPointAnnotation.m | 252 --- ios/RCTMGL/RCTMGLPointAnnotationManager.h | 13 - ios/RCTMGL/RCTMGLPointAnnotationManager.m | 36 - ios/RCTMGL/RCTMGLRasterLayer.h | 14 - ios/RCTMGL/RCTMGLRasterLayer.m | 30 - ios/RCTMGL/RCTMGLRasterLayerManager.h | 13 - ios/RCTMGL/RCTMGLRasterLayerManager.m | 35 - ios/RCTMGL/RCTMGLRasterSource.h | 16 - ios/RCTMGL/RCTMGLRasterSource.m | 35 - ios/RCTMGL/RCTMGLRasterSourceManager.h | 13 - ios/RCTMGL/RCTMGLRasterSourceManager.m | 32 - ios/RCTMGL/RCTMGLShapeSource.h | 34 - ios/RCTMGL/RCTMGLShapeSource.m | 107 -- ios/RCTMGL/RCTMGLShapeSourceManager.h | 14 - ios/RCTMGL/RCTMGLShapeSourceManager.m | 70 - ios/RCTMGL/RCTMGLSource.h | 35 - ios/RCTMGL/RCTMGLSource.m | 143 -- ios/RCTMGL/RCTMGLStyle.h | 219 --- ios/RCTMGL/RCTMGLStyle.m | 1654 ----------------- ios/RCTMGL/RCTMGLStyleValue.h | 27 - ios/RCTMGL/RCTMGLStyleValue.m | 167 -- ios/RCTMGL/RCTMGLSymbolLayer.h | 19 - ios/RCTMGL/RCTMGLSymbolLayer.m | 121 -- ios/RCTMGL/RCTMGLSymbolLayerManager.h | 13 - ios/RCTMGL/RCTMGLSymbolLayerManager.m | 40 - ios/RCTMGL/RCTMGLTileSource.h | 22 - ios/RCTMGL/RCTMGLTileSource.m | 31 - ios/RCTMGL/RCTMGLUserLocation.h | 15 - ios/RCTMGL/RCTMGLUserLocation.m | 38 - ios/RCTMGL/RCTMGLUtils.h | 31 - ios/RCTMGL/RCTMGLUtils.m | 218 --- ios/RCTMGL/RCTMGLVectorLayer.h | 15 - ios/RCTMGL/RCTMGLVectorLayer.m | 59 - ios/RCTMGL/RCTMGLVectorSource.h | 16 - ios/RCTMGL/RCTMGLVectorSource.m | 28 - ios/RCTMGL/RCTMGLVectorSourceManager.h | 14 - ios/RCTMGL/RCTMGLVectorSourceManager.m | 79 - ios/RCTMGL/RNMBImageUtils.h | 17 - ios/RCTMGL/RNMBImageUtils.m | 31 - ios/RCTMGL/ViewManager.h | 16 - ios/RCTMGL/ViewManager.m | 63 - ios/RCTMGL/index.d.ts | 1116 ----------- react-native-mapbox-gl.podspec | 15 +- 160 files changed, 267 insertions(+), 11398 deletions(-) create mode 100644 ios/RCTMGL/Bridge/RCTMGL.h delete mode 100644 ios/RCTMGL/CameraMode.h delete mode 100644 ios/RCTMGL/CameraMode.m delete mode 100644 ios/RCTMGL/CameraStop.h delete mode 100644 ios/RCTMGL/CameraStop.m delete mode 100644 ios/RCTMGL/CameraUpdateItem.h delete mode 100644 ios/RCTMGL/CameraUpdateItem.m delete mode 100644 ios/RCTMGL/CameraUpdateQueue.h delete mode 100644 ios/RCTMGL/CameraUpdateQueue.m delete mode 100644 ios/RCTMGL/FilterParser.h delete mode 100644 ios/RCTMGL/FilterParser.m delete mode 100644 ios/RCTMGL/MGLCustomHeaders.h delete mode 100644 ios/RCTMGL/MGLCustomHeaders.m delete mode 100644 ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.h delete mode 100644 ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.m delete mode 100644 ios/RCTMGL/MGLModule.h create mode 100644 ios/RCTMGL/MGLModule.swift delete mode 100644 ios/RCTMGL/MGLOfflineModule.h delete mode 100644 ios/RCTMGL/MGLOfflineModule.m delete mode 100644 ios/RCTMGL/MGLSnapshotModule.h delete mode 100644 ios/RCTMGL/MGLSnapshotModule.m delete mode 100644 ios/RCTMGL/MGLUserLocationHeadingArrowLayer.h delete mode 100644 ios/RCTMGL/MGLUserLocationHeadingArrowLayer.m delete mode 100644 ios/RCTMGL/MGLUserLocationHeadingBeamLayer.h delete mode 100644 ios/RCTMGL/MGLUserLocationHeadingBeamLayer.m delete mode 100644 ios/RCTMGL/MGLUserLocationHeadingIndicator.h delete mode 100644 ios/RCTMGL/RCTConvert+Mapbox.h delete mode 100644 ios/RCTMGL/RCTConvert+Mapbox.m delete mode 100644 ios/RCTMGL/RCTMGL.h delete mode 100644 ios/RCTMGL/RCTMGL.m delete mode 100644 ios/RCTMGL/RCTMGLBackgroundLayer.h delete mode 100644 ios/RCTMGL/RCTMGLBackgroundLayer.m delete mode 100644 ios/RCTMGL/RCTMGLBackgroundLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLBackgroundLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLCallout.h delete mode 100644 ios/RCTMGL/RCTMGLCallout.m delete mode 100644 ios/RCTMGL/RCTMGLCalloutManager.h delete mode 100644 ios/RCTMGL/RCTMGLCalloutManager.m delete mode 100644 ios/RCTMGL/RCTMGLCamera.h delete mode 100644 ios/RCTMGL/RCTMGLCamera.m create mode 100644 ios/RCTMGL/RCTMGLCamera.swift delete mode 100644 ios/RCTMGL/RCTMGLCameraManager.h create mode 100644 ios/RCTMGL/RCTMGLCameraManager.swift delete mode 100644 ios/RCTMGL/RCTMGLCircleLayer.h delete mode 100644 ios/RCTMGL/RCTMGLCircleLayer.m delete mode 100644 ios/RCTMGL/RCTMGLCircleLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLCircleLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLEvent.h delete mode 100644 ios/RCTMGL/RCTMGLEvent.m delete mode 100644 ios/RCTMGL/RCTMGLEventProtocol.h delete mode 100644 ios/RCTMGL/RCTMGLEventTypes.h delete mode 100644 ios/RCTMGL/RCTMGLEventTypes.m delete mode 100644 ios/RCTMGL/RCTMGLFillExtrusionLayer.h delete mode 100644 ios/RCTMGL/RCTMGLFillExtrusionLayer.m delete mode 100644 ios/RCTMGL/RCTMGLFillExtrusionLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLFillExtrusionLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLFillLayer.h delete mode 100644 ios/RCTMGL/RCTMGLFillLayer.m delete mode 100644 ios/RCTMGL/RCTMGLFillLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLFillLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLHeatmapLayer.h delete mode 100644 ios/RCTMGL/RCTMGLHeatmapLayer.m delete mode 100644 ios/RCTMGL/RCTMGLHeatmapLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLHeatmapLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLImageQueue.h delete mode 100644 ios/RCTMGL/RCTMGLImageQueue.m delete mode 100644 ios/RCTMGL/RCTMGLImageQueueOperation.h delete mode 100644 ios/RCTMGL/RCTMGLImageQueueOperation.m delete mode 100644 ios/RCTMGL/RCTMGLImageSource.h delete mode 100644 ios/RCTMGL/RCTMGLImageSource.m delete mode 100644 ios/RCTMGL/RCTMGLImageSourceManager.h delete mode 100644 ios/RCTMGL/RCTMGLImageSourceManager.m delete mode 100644 ios/RCTMGL/RCTMGLImages.h delete mode 100644 ios/RCTMGL/RCTMGLImages.m delete mode 100644 ios/RCTMGL/RCTMGLImagesManager.h delete mode 100644 ios/RCTMGL/RCTMGLImagesManager.m delete mode 100644 ios/RCTMGL/RCTMGLLayer.h delete mode 100644 ios/RCTMGL/RCTMGLLayer.m delete mode 100644 ios/RCTMGL/RCTMGLLight.h delete mode 100644 ios/RCTMGL/RCTMGLLight.m delete mode 100644 ios/RCTMGL/RCTMGLLightManager.h delete mode 100644 ios/RCTMGL/RCTMGLLightManager.m delete mode 100644 ios/RCTMGL/RCTMGLLineLayer.h delete mode 100644 ios/RCTMGL/RCTMGLLineLayer.m delete mode 100644 ios/RCTMGL/RCTMGLLineLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLLineLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLLocation.h delete mode 100644 ios/RCTMGL/RCTMGLLocation.m delete mode 100644 ios/RCTMGL/RCTMGLLocationManager.h delete mode 100644 ios/RCTMGL/RCTMGLLocationManager.m delete mode 100644 ios/RCTMGL/RCTMGLLocationManagerDelegate.h delete mode 100644 ios/RCTMGL/RCTMGLLocationModule.h create mode 100644 ios/RCTMGL/RCTMGLLocationModule.swift delete mode 100644 ios/RCTMGL/RCTMGLLogging.h create mode 100644 ios/RCTMGL/RCTMGLLogging.swift delete mode 100644 ios/RCTMGL/RCTMGLMapTouchEvent.h delete mode 100644 ios/RCTMGL/RCTMGLMapTouchEvent.m delete mode 100644 ios/RCTMGL/RCTMGLMapView.h delete mode 100644 ios/RCTMGL/RCTMGLMapView.m create mode 100644 ios/RCTMGL/RCTMGLMapView.swift delete mode 100644 ios/RCTMGL/RCTMGLMapViewManager.h create mode 100644 ios/RCTMGL/RCTMGLMapViewManager.swift delete mode 100644 ios/RCTMGL/RCTMGLNativeUserLocation.h delete mode 100644 ios/RCTMGL/RCTMGLNativeUserLocation.m delete mode 100644 ios/RCTMGL/RCTMGLNativeUserLocationManager.h delete mode 100644 ios/RCTMGL/RCTMGLNativeUserLocationManager.m create mode 100644 ios/RCTMGL/RCTMGLOfflineModule.m create mode 100644 ios/RCTMGL/RCTMGLOfflineModule.swift delete mode 100644 ios/RCTMGL/RCTMGLPointAnnotation.h delete mode 100644 ios/RCTMGL/RCTMGLPointAnnotation.m delete mode 100644 ios/RCTMGL/RCTMGLPointAnnotationManager.h delete mode 100644 ios/RCTMGL/RCTMGLPointAnnotationManager.m delete mode 100644 ios/RCTMGL/RCTMGLRasterLayer.h delete mode 100644 ios/RCTMGL/RCTMGLRasterLayer.m delete mode 100644 ios/RCTMGL/RCTMGLRasterLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLRasterLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLRasterSource.h delete mode 100644 ios/RCTMGL/RCTMGLRasterSource.m delete mode 100644 ios/RCTMGL/RCTMGLRasterSourceManager.h delete mode 100644 ios/RCTMGL/RCTMGLRasterSourceManager.m delete mode 100644 ios/RCTMGL/RCTMGLShapeSource.h delete mode 100644 ios/RCTMGL/RCTMGLShapeSource.m delete mode 100644 ios/RCTMGL/RCTMGLShapeSourceManager.h delete mode 100644 ios/RCTMGL/RCTMGLShapeSourceManager.m delete mode 100644 ios/RCTMGL/RCTMGLSource.h delete mode 100644 ios/RCTMGL/RCTMGLSource.m delete mode 100644 ios/RCTMGL/RCTMGLStyle.h delete mode 100644 ios/RCTMGL/RCTMGLStyle.m delete mode 100644 ios/RCTMGL/RCTMGLStyleValue.h delete mode 100644 ios/RCTMGL/RCTMGLStyleValue.m delete mode 100644 ios/RCTMGL/RCTMGLSymbolLayer.h delete mode 100644 ios/RCTMGL/RCTMGLSymbolLayer.m delete mode 100644 ios/RCTMGL/RCTMGLSymbolLayerManager.h delete mode 100644 ios/RCTMGL/RCTMGLSymbolLayerManager.m delete mode 100644 ios/RCTMGL/RCTMGLTileSource.h delete mode 100644 ios/RCTMGL/RCTMGLTileSource.m delete mode 100644 ios/RCTMGL/RCTMGLUserLocation.h delete mode 100644 ios/RCTMGL/RCTMGLUserLocation.m delete mode 100644 ios/RCTMGL/RCTMGLUtils.h delete mode 100644 ios/RCTMGL/RCTMGLUtils.m delete mode 100644 ios/RCTMGL/RCTMGLVectorLayer.h delete mode 100644 ios/RCTMGL/RCTMGLVectorLayer.m delete mode 100644 ios/RCTMGL/RCTMGLVectorSource.h delete mode 100644 ios/RCTMGL/RCTMGLVectorSource.m delete mode 100644 ios/RCTMGL/RCTMGLVectorSourceManager.h delete mode 100644 ios/RCTMGL/RCTMGLVectorSourceManager.m delete mode 100644 ios/RCTMGL/RNMBImageUtils.h delete mode 100644 ios/RCTMGL/RNMBImageUtils.m delete mode 100644 ios/RCTMGL/ViewManager.h delete mode 100644 ios/RCTMGL/ViewManager.m delete mode 100644 ios/RCTMGL/index.d.ts diff --git a/.gitignore b/.gitignore index 20dc4030cb..c60bc6e078 100644 --- a/.gitignore +++ b/.gitignore @@ -120,4 +120,8 @@ coverage *.core.prefs *.iml +example/accesstoken +example/env.json +example/ios/Podfile.lock + react-native-mapbox-gl-maps.tgz diff --git a/example/ios/Podfile b/example/ios/Podfile index 2dcd8a70ee..7321dcccb5 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,7 +1,8 @@ require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' -platform :ios, '10.0' +platform :ios, '13.0' + # We ingore warning except for RNMBGL INHIBIT_WARNING_BY_DEFAULT = true @@ -42,10 +43,38 @@ target 'RNMapboxGLExample' do # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable these next few lines. - use_flipper! + # use_flipper! + use_flipper!({ 'Flipper-Folly' => '2.3.0' }) + post_install do |installer| flipper_post_install(installer) $RNMBGL.post_install(installer) + + + # Work around for issue described here: https://github.com/CocoaPods/CocoaPods/issues/8122#issuecomment-427680543 + project_path = 'RNMapboxGLExample.xcodeproj' + project = Xcodeproj::Project.open(project_path) + project.targets.each do |target| + build_phase = target.build_phases.find { |bp| bp.display_name == '[CP] Copy Pods Resources' } + + puts "build_phase: #{build_phase}" + if build_phase.present? + puts "Input paths: #{build_phase.input_paths.join(',')}" + build_phase.input_paths.push('${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Assets.car') + build_phase.output_paths.delete('${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Assets.car') + end + end + project.save(project_path) + + project = Xcodeproj::Project.open(project_path) + project.targets.each do |target| + build_phase = target.build_phases.find { |bp| bp.display_name == '[CP] Copy Pods Resources' } + + puts "[1] build_phase: #{build_phase}" + if build_phase.present? + puts "[2] Input paths: #{build_phase.input_paths.join(',')}" + end + end end end diff --git a/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj b/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj index 102b126446..b1f54f413f 100644 --- a/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj +++ b/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj @@ -478,6 +478,8 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-resources.sh", + "${PODS_ROOT}/MapboxMaps/Sources/MapboxMaps/Ornaments/en.lproj/OrnamentsLocalizable.strings", + "${PODS_ROOT}/MapboxMaps/Sources/MapboxMaps/Location/Pucks/IndicatorAssets.xcassets", "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/AntDesign.ttf", "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Entypo.ttf", "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf", @@ -495,9 +497,11 @@ "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/SimpleLineIcons.ttf", "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Zocial.ttf", "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Assets.car", ); name = "[CP] Copy Pods Resources"; outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/OrnamentsLocalizable.strings", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AntDesign.ttf", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Entypo.ttf", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/EvilIcons.ttf", @@ -550,13 +554,17 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-frameworks.sh", - "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework", "${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework", + "${BUILT_PRODUCTS_DIR}/Turf/Turf.framework", + "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxCommon/MapboxCommon.framework/MapboxCommon", + "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxCoreMaps/MapboxCoreMaps.framework/MapboxCoreMaps", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Turf.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxCommon.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxCoreMaps.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/ios/RCTMGL/Bridge/RCTMGL.h b/ios/RCTMGL/Bridge/RCTMGL.h new file mode 100644 index 0000000000..d4e5a6490e --- /dev/null +++ b/ios/RCTMGL/Bridge/RCTMGL.h @@ -0,0 +1,3 @@ +/* Those will be available for Swift */ +#import +#import diff --git a/ios/RCTMGL/CameraMode.h b/ios/RCTMGL/CameraMode.h deleted file mode 100644 index 46c034af24..0000000000 --- a/ios/RCTMGL/CameraMode.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// CameraMode.h -// RCTMGL -// -// Created by Nick Italiano on 9/6/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import - -@interface CameraMode : NSObject - -extern int const RCT_MAPBOX_CAMERA_MODE_FLIGHT; -extern int const RCT_MAPBOX_CAMERA_MODE_EASE; -extern int const RCT_MAPBOX_CAMERA_MODE_NONE; - -@end diff --git a/ios/RCTMGL/CameraMode.m b/ios/RCTMGL/CameraMode.m deleted file mode 100644 index 8bd67224de..0000000000 --- a/ios/RCTMGL/CameraMode.m +++ /dev/null @@ -1,17 +0,0 @@ -// -// CameraMode.m -// RCTMGL -// -// Created by Nick Italiano on 9/6/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "CameraMode.h" - -@implementation CameraMode - -int const RCT_MAPBOX_CAMERA_MODE_FLIGHT = 1; -int const RCT_MAPBOX_CAMERA_MODE_EASE = 2; -int const RCT_MAPBOX_CAMERA_MODE_NONE = 3; - -@end diff --git a/ios/RCTMGL/CameraStop.h b/ios/RCTMGL/CameraStop.h deleted file mode 100644 index 18386180ea..0000000000 --- a/ios/RCTMGL/CameraStop.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// CameraStop.h -// RCTMGL -// -// Created by Nick Italiano on 9/5/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -@import Mapbox; -#import "RCTMGLCamera.h" - -@interface CameraStop : NSObject - -@property (nonatomic, strong) NSNumber *pitch; -@property (nonatomic, strong) NSNumber *heading; -@property (nonatomic, strong) NSNumber *zoom; -@property (nonatomic, strong) NSNumber *mode; -@property (nonatomic, assign) NSTimeInterval duration; - -@property (nonatomic, assign) CLLocationCoordinate2D coordinate; -@property (nonatomic, assign) MGLCoordinateBounds bounds; -@property (nonatomic, assign) UIEdgeInsets boundsPadding; - -+ (CameraStop*)fromDictionary:(NSDictionary*)args; - -@end diff --git a/ios/RCTMGL/CameraStop.m b/ios/RCTMGL/CameraStop.m deleted file mode 100644 index 1d40af9495..0000000000 --- a/ios/RCTMGL/CameraStop.m +++ /dev/null @@ -1,81 +0,0 @@ -// -// CameraStop.m -// RCTMGL -// -// Created by Nick Italiano on 9/5/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "CameraStop.h" -#import "CameraMode.h" -#import "RCTMGLUtils.h" -#import "RCTMGLCamera.h" - -@implementation CameraStop - -- (void)setMode:(NSNumber *)mode -{ - int modeInt = [mode intValue]; - - if (modeInt == RCT_MAPBOX_CAMERA_MODE_FLIGHT) { - _mode = [NSNumber numberWithInt:modeInt]; - } else if (modeInt == RCT_MAPBOX_CAMERA_MODE_NONE) { - _mode = [NSNumber numberWithInt:modeInt]; - } else { - _mode = [NSNumber numberWithInt:RCT_MAPBOX_CAMERA_MODE_EASE]; - } -} - --(id)init { - if (self = [super init]) { - self.coordinate = kCLLocationCoordinate2DInvalid; - self.bounds = MGLCoordinateBoundsMake(kCLLocationCoordinate2DInvalid, kCLLocationCoordinate2DInvalid); - } - return self; -} - - -+ (CameraStop*)fromDictionary:(NSDictionary *)args -{ - CameraStop *stop = [[CameraStop alloc] init]; - - if (args[@"pitch"]) { - stop.pitch = args[@"pitch"]; - } - - if (args[@"heading"]) { - stop.heading = args[@"heading"]; - } - - if (args[@"centerCoordinate"]) { - stop.coordinate = [RCTMGLUtils fromFeature:args[@"centerCoordinate"]]; - } - - if (args[@"zoom"]) { - stop.zoom = args[@"zoom"]; - } - - if (args[@"mode"]) { - stop.mode = args[@"mode"]; - } - - if (args[@"bounds"]) { - stop.bounds = [RCTMGLUtils fromFeatureCollection:args[@"bounds"]]; - - CGFloat paddingTop = args[@"boundsPaddingTop"] ? [args[@"boundsPaddingTop"] floatValue] : 0.0; - CGFloat paddingRight = args[@"boundsPaddingRight"] ? [args[@"boundsPaddingRight"] floatValue] : 0.0; - CGFloat paddingBottom = args[@"boundsPaddingBottom"] ? [args[@"boundsPaddingBottom"] floatValue] : 0.0; - CGFloat paddingLeft = args[@"boundsPaddingLeft"] ? [args[@"boundsPaddingLeft"] floatValue] : 0.0; - stop.boundsPadding = UIEdgeInsetsMake(paddingTop, paddingLeft, paddingBottom, paddingRight); - } - - NSTimeInterval duration = 2.0; - if (args[@"duration"]) { - duration = [RCTMGLUtils fromMS:args[@"duration"]]; - } - stop.duration = duration; - - return stop; -} - -@end diff --git a/ios/RCTMGL/CameraUpdateItem.h b/ios/RCTMGL/CameraUpdateItem.h deleted file mode 100644 index f9be54388f..0000000000 --- a/ios/RCTMGL/CameraUpdateItem.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// CameraUpdateItem.h -// RCTMGL -// -// Created by Nick Italiano on 9/6/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "CameraStop.h" -#import "RCTMGLMapView.h" - -@interface CameraUpdateItem : NSObject - -@property (nonatomic, strong) CameraStop* _Nonnull cameraStop; - -- (void)execute:(RCTMGLMapView* _Nonnull)mapView withCompletionHandler:(nullable void (^)(void))completionHandler; - -@end diff --git a/ios/RCTMGL/CameraUpdateItem.m b/ios/RCTMGL/CameraUpdateItem.m deleted file mode 100644 index 515ee0a7bb..0000000000 --- a/ios/RCTMGL/CameraUpdateItem.m +++ /dev/null @@ -1,182 +0,0 @@ -// -// CameraUpdateItem.m -// RCTMGL -// -// Created by Nick Italiano on 9/6/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "CameraUpdateItem.h" -#import "CameraMode.h" - - -@interface MGLMapView(FlyToWithPadding) -- (void)_flyToCamera:(MGLMapCamera *)camera edgePadding:(UIEdgeInsets)insets withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion; -@end - -@interface RCTMGLCameraWithPadding : MGLMapCamera - -@property (nonatomic) MGLMapCamera* _Nonnull camera; -@property (nonatomic) UIEdgeInsets boundsPadding; - -@end - -@implementation RCTMGLCameraWithPadding - -@end - -@implementation CameraUpdateItem - -- (void)execute:(RCTMGLMapView *)mapView withCompletionHandler:(void (^)(void))completionHandler -{ - if (_cameraStop.mode == [NSNumber numberWithInt:RCT_MAPBOX_CAMERA_MODE_FLIGHT]) { - [self _flyToCamera:mapView withCompletionHandler:completionHandler]; - } else if (_cameraStop.mode == [NSNumber numberWithInt:RCT_MAPBOX_CAMERA_MODE_EASE]) { - [self _moveCamera:mapView animated:YES withCompletionHandler:completionHandler]; - } else if ([self _areBoundsValid:_cameraStop.bounds]) { - [self _fitBoundsCamera:mapView withCompletionHandler:completionHandler]; - } else { - [self _moveCamera:mapView animated:NO withCompletionHandler:completionHandler]; - } -} - -- (void)_flyToCamera:(RCTMGLMapView*)mapView withCompletionHandler:(void (^)(void))completionHandler -{ - RCTMGLCameraWithPadding *nextCamera = [self _makeCamera:mapView]; - - if ([mapView respondsToSelector:@selector(_flyToCamera:edgePadding:withDuration:peakAltitude:completionHandler:)]) { - [mapView _flyToCamera:nextCamera.camera edgePadding:nextCamera.boundsPadding withDuration:_cameraStop.duration peakAltitude:-1 completionHandler:completionHandler]; - } else { - [mapView flyToCamera:nextCamera.camera withDuration:_cameraStop.duration completionHandler:completionHandler]; - } -} - -- (void)_moveCamera:(RCTMGLMapView*)mapView animated:(BOOL)animated withCompletionHandler:(void (^)(void))completionHandler -{ - if ([self _hasCenterCoordAndZoom]) { - [self _centerCoordWithZoomCamera:mapView animated:animated withCompletionHandler:completionHandler]; - } else { - RCTMGLCameraWithPadding *nextCamera = [self _makeCamera:mapView]; - - [mapView setCamera:nextCamera.camera - withDuration:animated ? _cameraStop.duration : 0 - animationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] - edgePadding:nextCamera.boundsPadding - completionHandler:completionHandler]; - } -} - -- (UIEdgeInsets)_clippedPadding:(UIEdgeInsets)padding forView:(RCTMGLMapView*)mapView -{ - UIEdgeInsets result = padding; - if ((padding.top + padding.bottom) >= mapView.frame.size.height) { - double totalPadding = padding.top + padding.bottom; - double extra = totalPadding - mapView.frame.size.height + 1.0; - result.top -= (padding.top * extra) / totalPadding; - result.bottom -= (padding.bottom * extra) / totalPadding; - } - if ((padding.left + padding.right) >= mapView.frame.size.width) { - double totalPadding = padding.left + padding.right; - double extra = totalPadding - mapView.frame.size.width + 1.0; - result.left -= (padding.left * extra) / totalPadding; - result.right -= (padding.right * extra) / totalPadding; - } - return result; -} - -- (void)_fitBoundsCamera:(RCTMGLMapView*)mapView withCompletionHandler:(void (^)(void))completionHandler -{ - MGLCoordinateBounds bounds = _cameraStop.bounds; - CLLocationCoordinate2D coordinates[] = { - { bounds.ne.latitude, bounds.sw.longitude }, - bounds.sw, - { bounds.sw.latitude, bounds.ne.longitude }, - bounds.ne - }; - - [mapView setVisibleCoordinates:coordinates - count:4 - edgePadding:[self _clippedPadding:_cameraStop.boundsPadding forView:mapView] - direction:mapView.direction - duration:_cameraStop.duration - animationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] - completionHandler:completionHandler]; -} - -- (void)_centerCoordWithZoomCamera:(RCTMGLMapView*)mapView animated:(BOOL)animated withCompletionHandler:(void (^)(void))completionHandler -{ - MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:_cameraStop.coordinate - fromDistance:[mapView altitudeFromZoom:[_cameraStop.zoom doubleValue] atLatitude:_cameraStop.coordinate.latitude] - pitch:[_cameraStop.pitch floatValue] - heading:[_cameraStop.heading floatValue]]; - [mapView setCamera:camera - withDuration:animated ? _cameraStop.duration : 0 - animationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] - completionHandler:completionHandler]; -} - -- (RCTMGLCameraWithPadding*)_makeCamera:(RCTMGLMapView*)mapView -{ - MGLMapCamera *nextCamera = [mapView.camera copy]; - - if (_cameraStop.pitch != nil) { - nextCamera.pitch = [_cameraStop.pitch floatValue]; - } - - if (_cameraStop.heading != nil) { - nextCamera.heading = [_cameraStop.heading floatValue]; - } - - if ([self _isCoordValid:_cameraStop.coordinate]) { - nextCamera.centerCoordinate = _cameraStop.coordinate; - } else if ([self _areBoundsValid:_cameraStop.bounds]) { - MGLMapCamera *boundsCamera = [mapView camera:nextCamera fittingCoordinateBounds:_cameraStop.bounds edgePadding: [self _clippedPadding:_cameraStop.boundsPadding forView:mapView]]; - nextCamera.centerCoordinate = boundsCamera.centerCoordinate; - nextCamera.altitude = boundsCamera.altitude; - } - - if (_cameraStop.zoom != nil) { - nextCamera.altitude = [mapView altitudeFromZoom:[_cameraStop.zoom doubleValue] atLatitude:nextCamera.centerCoordinate.latitude atPitch:nextCamera.pitch]; - } - - RCTMGLCameraWithPadding* cameraWithPadding = [[RCTMGLCameraWithPadding alloc] init]; - cameraWithPadding.camera = nextCamera; - cameraWithPadding.boundsPadding = [self _clippedPadding:_cameraStop.boundsPadding forView:mapView]; - return cameraWithPadding; -} - -- (BOOL)_areBoundsValid:(MGLCoordinateBounds)bounds { - BOOL isValid = CLLocationCoordinate2DIsValid(bounds.ne) && CLLocationCoordinate2DIsValid(bounds.sw); - - if (!isValid) { - return NO; - } - - CLLocationCoordinate2D ne = bounds.ne; - CLLocationCoordinate2D sw = bounds.sw; - return [self _isCoordValid:ne] && [self _isCoordValid:sw]; -} - -- (BOOL)_isCoordValid:(CLLocationCoordinate2D)coord -{ - BOOL isValid = CLLocationCoordinate2DIsValid(coord); - - if (!isValid) { - return NO; - } - - return YES; -} - -- (BOOL)_hasCenterCoordAndZoom -{ - BOOL isValid = CLLocationCoordinate2DIsValid(_cameraStop.coordinate) && _cameraStop.zoom != nil; - - if (!isValid) { - return NO; - } - - return [self _isCoordValid:_cameraStop.coordinate]; -} - -@end diff --git a/ios/RCTMGL/CameraUpdateQueue.h b/ios/RCTMGL/CameraUpdateQueue.h deleted file mode 100644 index 45332bac69..0000000000 --- a/ios/RCTMGL/CameraUpdateQueue.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// CameraUpdateQueue.h -// RCTMGL -// -// Created by Nick Italiano on 9/6/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "CameraStop.h" -#import "CameraUpdateItem.h" -#import "RCTMGLMapView.h" - -@interface CameraUpdateQueue : NSObject - -- (void)enqueue:(CameraStop* _Nonnull)cameraUpdateItem; -- (CameraStop* _Nonnull)dequeue; -- (void)flush; -- (BOOL)isEmpty; -- (void)execute:(RCTMGLMapView* _Nonnull)mapView; - -@end diff --git a/ios/RCTMGL/CameraUpdateQueue.m b/ios/RCTMGL/CameraUpdateQueue.m deleted file mode 100644 index 35c4d43a53..0000000000 --- a/ios/RCTMGL/CameraUpdateQueue.m +++ /dev/null @@ -1,74 +0,0 @@ -// -// CameraUpdateQueue.m -// RCTMGL -// -// Created by Nick Italiano on 9/6/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "CameraUpdateQueue.h" - -@implementation CameraUpdateQueue -{ - NSMutableArray *queue; -} - -- (instancetype)init -{ - if (self = [super init]) { - queue = [[NSMutableArray alloc] init]; - } - - return self; -} - -- (void)enqueue:(CameraStop*)cameraUpdateItem -{ - [queue addObject:cameraUpdateItem]; -} - -- (CameraStop*)dequeue -{ - if ([self isEmpty]) { - return nil; - } - CameraStop *stop = queue.firstObject; - [queue removeObjectAtIndex:0]; - return stop; -} - -- (void)flush -{ - [queue removeAllObjects]; -} - -- (BOOL)isEmpty -{ - return queue.count == 0; -} - -- (void)execute:(RCTMGLMapView*)mapView -{ - if (mapView == nil) { - return; - } - - if ([self isEmpty]) { - return; - } - - CameraStop *stop = [self dequeue]; - if (stop == nil) { - return; - } - - CameraUpdateItem *item = [[CameraUpdateItem alloc] init]; - item.cameraStop = stop; - - __weak CameraUpdateQueue *weakSelf = self; - __weak RCTMGLMapView *weakMap = mapView; - - [item execute:mapView withCompletionHandler:^{ [weakSelf execute:weakMap]; }]; -} - -@end diff --git a/ios/RCTMGL/FilterParser.h b/ios/RCTMGL/FilterParser.h deleted file mode 100644 index 74e8920fa4..0000000000 --- a/ios/RCTMGL/FilterParser.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// FilterParser.h -// RCTMGL -// -// Created by Nick Italiano on 10/3/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// -#import - -@interface FilterParser : NSObject - -+ (NSPredicate*)parse:(NSArray *)filter; - -@end diff --git a/ios/RCTMGL/FilterParser.m b/ios/RCTMGL/FilterParser.m deleted file mode 100644 index f2d9a1c056..0000000000 --- a/ios/RCTMGL/FilterParser.m +++ /dev/null @@ -1,22 +0,0 @@ -// -// FilterParser.m -// RCTMGL -// -// Created by Nick Italiano on 10/3/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "FilterParser.h" -#import - -@implementation FilterParser - -+ (NSPredicate*)parse:(NSArray *)filterList -{ - if (filterList == nil || filterList.count < 1) { - return nil; - } - return [NSPredicate predicateWithMGLJSONObject:filterList]; -} - -@end diff --git a/ios/RCTMGL/MGLCustomHeaders.h b/ios/RCTMGL/MGLCustomHeaders.h deleted file mode 100644 index 0dabbd3f28..0000000000 --- a/ios/RCTMGL/MGLCustomHeaders.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// MGLCustomHeaders.h -// RCTMGL -// - -#import - -@interface NSMutableURLRequest (CustomHeaders) -@end - -@interface MGLCustomHeaders : NSObject - -@property (nonatomic, strong) NSMutableDictionary *currentHeaders; - -+ (id)sharedInstance; -- (void)initHeaders; -- (void)addHeader:(NSString*)value forHeaderName:(NSString *)header; -- (void)removeHeader:(NSString *)header; - -@end \ No newline at end of file diff --git a/ios/RCTMGL/MGLCustomHeaders.m b/ios/RCTMGL/MGLCustomHeaders.m deleted file mode 100644 index a7f6e27343..0000000000 --- a/ios/RCTMGL/MGLCustomHeaders.m +++ /dev/null @@ -1,98 +0,0 @@ -// -// MGLCustomHeaders.h -// RCTMGL -// - -#import - -#import "MGLCustomHeaders.h" -#import -#import - -@implementation NSMutableURLRequest (CustomHeaders) - - +(NSMutableURLRequest*) __swizzle_requestWithURL:(NSURL*)url { - if([url.scheme isEqualToString:@"ws"]) { - return [NSMutableURLRequest __swizzle_requestWithURL:url]; - } - - NSArray* stack = [NSThread callStackSymbols]; - if ([stack count] < 2) { - return [NSMutableURLRequest __swizzle_requestWithURL:url]; - } - - if ([stack[1] containsString:@"Mapbox"] == NO) { - return [NSMutableURLRequest __swizzle_requestWithURL:url]; - } - - NSMutableURLRequest *req = [NSMutableURLRequest __swizzle_requestWithURL:url]; - NSDictionary *currentHeaders = [[[MGLCustomHeaders sharedInstance] currentHeaders] copy]; - if(currentHeaders != nil && [currentHeaders count]>0) { - for (NSString* headerName in currentHeaders) { - id headerValue = currentHeaders[headerName]; - [req setValue:headerValue forHTTPHeaderField:headerName]; - } - } - return req; - } - -@end - -@implementation MGLCustomHeaders { - NSMutableDictionary *_currentHeaders; - BOOL areHeadersAdded; -} - -+ (id)sharedInstance -{ - static MGLCustomHeaders *customHeaders; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ customHeaders = [[self alloc] init]; }); - return customHeaders; -} - -// This replaces the [NSMutableURLRequest requestWithURL:] with custom implementation which -// adds runtime headers copied from [MGLCustomHeaders _currentHeaders] --(void)initHeaders -{ - if (!areHeadersAdded) { - areHeadersAdded = YES; - NSLog(@"Replace method [NSMutableURLRequest requestWithURL]"); - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - Class targetClass = [NSMutableURLRequest class]; - Method oldMethod = class_getClassMethod(targetClass, @selector(requestWithURL:)); - Method newMethod = class_getClassMethod(targetClass, @selector(__swizzle_requestWithURL:)); - method_exchangeImplementations(oldMethod, newMethod); - }); - } -} - -- (instancetype)init -{ - if (self = [super init]) { - _currentHeaders = [[NSMutableDictionary alloc] init]; - areHeadersAdded = NO; - } - return self; -} - -- (void)addHeader:(NSString *)value forHeaderName:(NSString *)headerName { - - if(!areHeadersAdded) { - areHeadersAdded = YES; - } - - [_currentHeaders setObject:value forKey:headerName]; - [[[MGLNetworkConfiguration sharedManager] sessionConfiguration] setHTTPAdditionalHeaders:_currentHeaders]; -} - -- (void)removeHeader:(NSString *)header { - if(!areHeadersAdded) { - return; - } - - [_currentHeaders removeObjectForKey:header]; -} - -@end diff --git a/ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.h b/ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.h deleted file mode 100644 index 53cf46151d..0000000000 --- a/ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// MGLFaux3DUserLocationAnnotationView.h -// RCTMGL -// -// Created by Nick Italiano on 12/20/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -@import Mapbox; - -extern const CGFloat MGLUserLocationAnnotationDotSize; -extern const CGFloat MGLUserLocationAnnotationHaloSize; - -extern const CGFloat MGLUserLocationAnnotationPuckSize; -extern const CGFloat MGLUserLocationAnnotationArrowSize; - -// Threshold in radians between heading indicator rotation updates. -extern const CGFloat MGLUserLocationHeadingUpdateThreshold; - -@interface MGLFaux3DUserLocationAnnotationView : MGLUserLocationAnnotationView - -@end diff --git a/ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.m b/ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.m deleted file mode 100644 index ea6a331ae2..0000000000 --- a/ios/RCTMGL/MGLFaux3DUserLocationAnnotationView.m +++ /dev/null @@ -1,474 +0,0 @@ -// -// https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m -// - -#import "MGLFaux3DUserLocationAnnotationView.h" - -#import "MGLUserLocationHeadingIndicator.h" -#import "MGLUserLocationHeadingArrowLayer.h" -#import "MGLUserLocationHeadingBeamLayer.h" - -#import "RCTMGLMapView.h" - -const CGFloat MGLUserLocationAnnotationDotSize = 22.0; -const CGFloat MGLUserLocationAnnotationHaloSize = 115.0; - -const CGFloat MGLUserLocationAnnotationPuckSize = 45.0; -const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuckSize * 0.5; - -const CGFloat MGLUserLocationHeadingUpdateThreshold = 0.01; - -@implementation MGLFaux3DUserLocationAnnotationView -{ - BOOL _puckModeActivated; - - CALayer *_puckDot; - CAShapeLayer *_puckArrow; - - CALayer *_headingIndicatorLayer; - CALayer *_accuracyRingLayer; - CALayer *_dotBorderLayer; - CALayer *_dotLayer; - CALayer *_haloLayer; - - CLLocationDirection _oldHeadingAccuracy; - CLLocationAccuracy _oldHorizontalAccuracy; - double _oldZoom; - double _oldPitch; -} - -- (CALayer *)hitTestLayer -{ - // Only the main dot should be interactive (i.e., exclude the accuracy ring and halo). - return _dotBorderLayer ?: _puckDot; -} - -- (void)update -{ - if (CGSizeEqualToSize(self.frame.size, CGSizeZero)) - { - CGFloat frameSize = (self.mapView.userTrackingMode == MGLUserTrackingModeFollowWithCourse) ? MGLUserLocationAnnotationPuckSize : MGLUserLocationAnnotationDotSize; - [self updateFrameWithSize:frameSize]; - } - - if (CLLocationCoordinate2DIsValid(self.userLocation.coordinate)) - { - RCTMGLMapView *reactMapView = (RCTMGLMapView *)self.mapView; - // FM - TODO - (reactMapView.userTrackingMode == MGLUserTrackingModeFollowWithCourse) ? [self drawPuck] : [self drawDot]; - [self updatePitch]; - } - - _haloLayer.hidden = ! CLLocationCoordinate2DIsValid(self.mapView.userLocation.coordinate) || self.mapView.userLocation.location.horizontalAccuracy > 10; -} - -- (void)setTintColor:(UIColor *)tintColor -{ - CGColorRef newTintColor = [tintColor CGColor]; - - if (_puckModeActivated) - { - _puckArrow.fillColor = newTintColor; - } - else - { - _accuracyRingLayer.backgroundColor = newTintColor; - _haloLayer.backgroundColor = newTintColor; - _dotLayer.backgroundColor = newTintColor; - [_headingIndicatorLayer updateTintColor:newTintColor]; - } -} - -- (void)updatePitch -{ - if (self.mapView.camera.pitch != _oldPitch) - { - // disable implicit animation - [CATransaction begin]; - [CATransaction setDisableActions:YES]; - - CATransform3D t = CATransform3DRotate(CATransform3DIdentity, MGLRadiansFromDegrees(self.mapView.camera.pitch), 1.0, 0, 0); - self.layer.sublayerTransform = t; - - [self updateFaux3DEffect]; - - [CATransaction commit]; - - _oldPitch = self.mapView.camera.pitch; - } -} - -- (void)updateFaux3DEffect -{ - CGFloat pitch = MGLRadiansFromDegrees(self.mapView.camera.pitch); - - if (_puckDot) - { - _puckDot.shadowOffset = CGSizeMake(0, fmaxf(pitch * 10.f, 1.f)); - _puckDot.shadowRadius = fmaxf(pitch * 5.f, 0.75f); - } - - if (_dotBorderLayer) - { - _dotBorderLayer.shadowOffset = CGSizeMake(0.f, pitch * 10.f); - _dotBorderLayer.shadowRadius = fmaxf(pitch * 5.f, 3.f); - } - - if (_dotLayer) - { - _dotLayer.zPosition = pitch * 2.f; - } -} - -- (void)updateFrameWithSize:(CGFloat)size -{ - CGSize newSize = CGSizeMake(size, size); - if (CGSizeEqualToSize(self.frame.size, newSize)) - { - return; - } - - // Update frame size, keeping the existing center point. - CGPoint oldCenter = self.center; - CGRect newFrame = self.frame; - newFrame.size = newSize; - [self setFrame:newFrame]; - [self setCenter:oldCenter]; -} - -- (void)drawPuck -{ - if ( ! _puckModeActivated) - { - self.layer.sublayers = nil; - - _headingIndicatorLayer = nil; - _accuracyRingLayer = nil; - _haloLayer = nil; - _dotBorderLayer = nil; - _dotLayer = nil; - - [self updateFrameWithSize:MGLUserLocationAnnotationPuckSize]; - } - - // background dot (white with black shadow) - // - if ( ! _puckDot) - { - _puckDot = [self circleLayerWithSize:MGLUserLocationAnnotationPuckSize]; - _puckDot.backgroundColor = [[UIColor whiteColor] CGColor]; - _puckDot.shadowColor = [[UIColor blackColor] CGColor]; - _puckDot.shadowOpacity = 0.25; - _puckDot.shadowPath = [[UIBezierPath bezierPathWithOvalInRect:_puckDot.bounds] CGPath]; - - if (self.mapView.camera.pitch) - { - [self updateFaux3DEffect]; - } - else - { - _puckDot.shadowOffset = CGSizeMake(0, 1); - _puckDot.shadowRadius = 0.75; - } - - [self.layer addSublayer:_puckDot]; - } - - // arrow - // - if ( ! _puckArrow) - { - _puckArrow = [CAShapeLayer layer]; - _puckArrow.path = [[self puckArrow] CGPath]; - _puckArrow.fillColor = [self.mapView.tintColor CGColor]; - _puckArrow.bounds = CGRectMake(0, 0, round(MGLUserLocationAnnotationArrowSize), round(MGLUserLocationAnnotationArrowSize)); - _puckArrow.position = CGPointMake(CGRectGetMidX(super.bounds), CGRectGetMidY(super.bounds)); - _puckArrow.shouldRasterize = YES; - _puckArrow.rasterizationScale = [UIScreen mainScreen].scale; - _puckArrow.drawsAsynchronously = YES; - - _puckArrow.lineJoin = @"round"; - _puckArrow.lineWidth = 1.f; - _puckArrow.strokeColor = _puckArrow.fillColor; - - [self.layer addSublayer:_puckArrow]; - } - if (self.userLocation.location.course >= 0) - { - _puckArrow.affineTransform = CGAffineTransformRotate(CGAffineTransformIdentity, -MGLRadiansFromDegrees(self.mapView.direction - self.userLocation.location.course)); - } - - if ( ! _puckModeActivated) - { - _puckModeActivated = YES; - - [self updateFaux3DEffect]; - } -} - -- (UIBezierPath *)puckArrow -{ - CGFloat max = MGLUserLocationAnnotationArrowSize; - - UIBezierPath *bezierPath = UIBezierPath.bezierPath; - [bezierPath moveToPoint: CGPointMake(max * 0.5, 0)]; - [bezierPath addLineToPoint: CGPointMake(max * 0.1, max)]; - [bezierPath addLineToPoint: CGPointMake(max * 0.5, max * 0.65)]; - [bezierPath addLineToPoint: CGPointMake(max * 0.9, max)]; - [bezierPath addLineToPoint: CGPointMake(max * 0.5, 0)]; - [bezierPath closePath]; - - return bezierPath; -} - -- (void)drawDot -{ - if (_puckModeActivated) - { - self.layer.sublayers = nil; - - _puckDot = nil; - _puckArrow = nil; - - [self updateFrameWithSize:MGLUserLocationAnnotationDotSize]; - } - - // heading indicator (tinted, beam or arrow) - RCTMGLMapView *reactMapView = (RCTMGLMapView *)self.mapView; - BOOL headingTrackingModeEnabled = reactMapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading; - BOOL showHeadingIndicator = self.mapView.showsUserHeadingIndicator || headingTrackingModeEnabled; - - if (showHeadingIndicator) - { - _headingIndicatorLayer.hidden = NO; - CLLocationDirection headingAccuracy = self.userLocation.heading.headingAccuracy; - - if (([_headingIndicatorLayer isMemberOfClass:[MGLUserLocationHeadingBeamLayer class]] && ! headingTrackingModeEnabled) || - ([_headingIndicatorLayer isMemberOfClass:[MGLUserLocationHeadingArrowLayer class]] && headingTrackingModeEnabled)) - { - [_headingIndicatorLayer removeFromSuperlayer]; - _headingIndicatorLayer = nil; - _oldHeadingAccuracy = -1; - } - - if ( ! _headingIndicatorLayer && headingAccuracy) - { - if (headingTrackingModeEnabled) - { - _headingIndicatorLayer = [[MGLUserLocationHeadingBeamLayer alloc] initWithUserLocationAnnotationView:self]; - [self.layer insertSublayer:_headingIndicatorLayer below:_dotBorderLayer]; - } - else - { - _headingIndicatorLayer = [[MGLUserLocationHeadingArrowLayer alloc] initWithUserLocationAnnotationView:self]; - [self.layer addSublayer:_headingIndicatorLayer]; - _headingIndicatorLayer.zPosition = 1; - } - } - - if (_oldHeadingAccuracy != headingAccuracy) - { - [_headingIndicatorLayer updateHeadingAccuracy:headingAccuracy]; - _oldHeadingAccuracy = headingAccuracy; - } - - if (self.userLocation.heading.trueHeading >= 0) - { - CGFloat rotation = -MGLRadiansFromDegrees(self.mapView.direction - self.userLocation.heading.trueHeading); - - // Don't rotate if the change is imperceptible. - if (fabs(rotation) > MGLUserLocationHeadingUpdateThreshold) - { - [CATransaction begin]; - [CATransaction setDisableActions:YES]; - - _headingIndicatorLayer.affineTransform = CGAffineTransformRotate(CGAffineTransformIdentity, rotation); - - [CATransaction commit]; - } - } - } - else - { - [_headingIndicatorLayer removeFromSuperlayer]; - _headingIndicatorLayer = nil; - } - - // update accuracy ring (if zoom or horizontal accuracy have changed) - // - if (_accuracyRingLayer && (_oldZoom != self.mapView.zoomLevel || _oldHorizontalAccuracy != self.userLocation.location.horizontalAccuracy)) - { - CGFloat accuracyRingSize = [self calculateAccuracyRingSize]; - - // only show the accuracy ring if it won't be obscured by the location dot - if (accuracyRingSize > MGLUserLocationAnnotationDotSize + 15) - { - _accuracyRingLayer.hidden = NO; - - // disable implicit animation of the accuracy ring, unless triggered by a change in accuracy - BOOL shouldDisableActions = _oldHorizontalAccuracy == self.userLocation.location.horizontalAccuracy; - - [CATransaction begin]; - [CATransaction setDisableActions:shouldDisableActions]; - - _accuracyRingLayer.bounds = CGRectMake(0, 0, accuracyRingSize, accuracyRingSize); - _accuracyRingLayer.cornerRadius = accuracyRingSize / 2.0; - - // match the halo to the accuracy ring - _haloLayer.bounds = _accuracyRingLayer.bounds; - _haloLayer.cornerRadius = _accuracyRingLayer.cornerRadius; - _haloLayer.shouldRasterize = NO; - - [CATransaction commit]; - } - else - { - _accuracyRingLayer.hidden = YES; - - _haloLayer.bounds = CGRectMake(0, 0, MGLUserLocationAnnotationHaloSize, MGLUserLocationAnnotationHaloSize); - _haloLayer.cornerRadius = MGLUserLocationAnnotationHaloSize / 2.0; - _haloLayer.shouldRasterize = YES; - _haloLayer.rasterizationScale = [UIScreen mainScreen].scale; - } - - // store accuracy and zoom so we're not redrawing unchanged location updates - _oldHorizontalAccuracy = self.userLocation.location.horizontalAccuracy; - _oldZoom = self.mapView.zoomLevel; - } - - // accuracy ring (circular, tinted, mostly-transparent) - // - if ( ! _accuracyRingLayer && self.userLocation.location.horizontalAccuracy) - { - CGFloat accuracyRingSize = [self calculateAccuracyRingSize]; - _accuracyRingLayer = [self circleLayerWithSize:accuracyRingSize]; - _accuracyRingLayer.backgroundColor = [self.mapView.tintColor CGColor]; - _accuracyRingLayer.opacity = 0.1; - _accuracyRingLayer.shouldRasterize = NO; - _accuracyRingLayer.allowsGroupOpacity = NO; - - [self.layer addSublayer:_accuracyRingLayer]; - } - - // expanding sonar-like pulse (circular, tinted, fades out) - // - if ( ! _haloLayer) - { - _haloLayer = [self circleLayerWithSize:MGLUserLocationAnnotationHaloSize]; - _haloLayer.backgroundColor = [self.mapView.tintColor CGColor]; - _haloLayer.allowsGroupOpacity = NO; - _haloLayer.zPosition = -0.1f; - - // set defaults for the animations - CAAnimationGroup *animationGroup = [self loopingAnimationGroupWithDuration:3.0]; - - // scale out radially with initial acceleration - CAKeyframeAnimation *boundsAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.xy"]; - boundsAnimation.values = @[@0, @0.35, @1]; - boundsAnimation.keyTimes = @[@0, @0.2, @1]; - - // go transparent as scaled out, start semi-opaque - CAKeyframeAnimation *opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"]; - opacityAnimation.values = @[@0.4, @0.4, @0]; - opacityAnimation.keyTimes = @[@0, @0.2, @1]; - - animationGroup.animations = @[boundsAnimation, opacityAnimation]; - - [_haloLayer addAnimation:animationGroup forKey:@"animateTransformAndOpacity"]; - - [self.layer addSublayer:_haloLayer]; - } - - // background dot (white with black shadow) - // - if ( ! _dotBorderLayer) - { - _dotBorderLayer = [self circleLayerWithSize:MGLUserLocationAnnotationDotSize]; - _dotBorderLayer.backgroundColor = [[UIColor whiteColor] CGColor]; - _dotBorderLayer.shadowColor = [[UIColor blackColor] CGColor]; - _dotBorderLayer.shadowOpacity = 0.25; - _dotBorderLayer.shadowPath = [[UIBezierPath bezierPathWithOvalInRect:_dotBorderLayer.bounds] CGPath]; - - if (self.mapView.camera.pitch) - { - [self updateFaux3DEffect]; - } - else - { - _dotBorderLayer.shadowOffset = CGSizeMake(0, 0); - _dotBorderLayer.shadowRadius = 3; - } - - [self.layer addSublayer:_dotBorderLayer]; - } - - // inner dot (pulsing, tinted) - // - if ( ! _dotLayer) - { - _dotLayer = [self circleLayerWithSize:MGLUserLocationAnnotationDotSize * 0.75]; - _dotLayer.backgroundColor = [self.mapView.tintColor CGColor]; - - // set defaults for the animations - CAAnimationGroup *animationGroup = [self loopingAnimationGroupWithDuration:1.5]; - animationGroup.autoreverses = YES; - animationGroup.fillMode = kCAFillModeBoth; - - // scale the dot up and down - CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.xy"]; - pulseAnimation.fromValue = @0.8; - pulseAnimation.toValue = @1; - - // fade opacity in and out, subtly - CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; - opacityAnimation.fromValue = @0.8; - opacityAnimation.toValue = @1; - - animationGroup.animations = @[pulseAnimation, opacityAnimation]; - - [_dotLayer addAnimation:animationGroup forKey:@"animateTransformAndOpacity"]; - - [self.layer addSublayer:_dotLayer]; - } - - if (_puckModeActivated) - { - _puckModeActivated = NO; - - [self updateFaux3DEffect]; - } -} - -- (CALayer *)circleLayerWithSize:(CGFloat)layerSize -{ - layerSize = round(layerSize); - - CALayer *circleLayer = [CALayer layer]; - circleLayer.bounds = CGRectMake(0, 0, layerSize, layerSize); - circleLayer.position = CGPointMake(CGRectGetMidX(super.bounds), CGRectGetMidY(super.bounds)); - circleLayer.cornerRadius = layerSize / 2.0; - circleLayer.shouldRasterize = YES; - circleLayer.rasterizationScale = [UIScreen mainScreen].scale; - circleLayer.drawsAsynchronously = YES; - - return circleLayer; -} - -- (CAAnimationGroup *)loopingAnimationGroupWithDuration:(CGFloat)animationDuration -{ - CAAnimationGroup *animationGroup = [CAAnimationGroup animation]; - animationGroup.duration = animationDuration; - animationGroup.repeatCount = INFINITY; - animationGroup.removedOnCompletion = NO; - animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]; - - return animationGroup; -} - -- (CGFloat)calculateAccuracyRingSize -{ - // diameter in screen points - return round(self.userLocation.location.horizontalAccuracy / [self.mapView metersPerPointAtLatitude:self.userLocation.coordinate.latitude] * 2.0); -} - -@end diff --git a/ios/RCTMGL/MGLModule.h b/ios/RCTMGL/MGLModule.h deleted file mode 100644 index 902d48835a..0000000000 --- a/ios/RCTMGL/MGLModule.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// MGLModule.h -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import - -@interface MGLModule : NSObject -@end diff --git a/ios/RCTMGL/MGLModule.m b/ios/RCTMGL/MGLModule.m index d9a795000a..0e5e57ed4e 100644 --- a/ios/RCTMGL/MGLModule.m +++ b/ios/RCTMGL/MGLModule.m @@ -1,273 +1,7 @@ -// -// MGLModule.m -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// +#import "React/RCTBridgeModule.h" -#import "MGLModule.h" -#import "RCTMGLEventTypes.h" -#import "MGLOfflineModule.h" -#import "CameraMode.h" -#import "RCTMGLSource.h" -#import "MGLCustomHeaders.h" -@import Mapbox; +@interface RCT_EXTERN_MODULE(MGLModule, NSObject) -@implementation MGLModule - -RCT_EXPORT_MODULE(); - -+ (BOOL)requiresMainQueueSetup -{ - return YES; -} - -- (NSDictionary *)constantsToExport -{ - // style urls - NSMutableDictionary *styleURLS = [[NSMutableDictionary alloc] init]; - [styleURLS setObject:[MGLStyle.streetsStyleURL absoluteString] forKey:@"Street"]; - [styleURLS setObject:[MGLStyle.darkStyleURL absoluteString] forKey:@"Dark"]; - [styleURLS setObject:[MGLStyle.lightStyleURL absoluteString] forKey:@"Light"]; - [styleURLS setObject:[MGLStyle.outdoorsStyleURL absoluteString] forKey:@"Outdoors"]; - [styleURLS setObject:[MGLStyle.satelliteStyleURL absoluteString] forKey:@"Satellite"]; - [styleURLS setObject:[MGLStyle.satelliteStreetsStyleURL absoluteString] forKey:@"SatelliteStreet"]; - - // event types - NSMutableDictionary *eventTypes = [[NSMutableDictionary alloc] init]; - [eventTypes setObject:RCT_MAPBOX_EVENT_TAP forKey:@"MapClick"]; - [eventTypes setObject:RCT_MAPBOX_EVENT_LONGPRESS forKey:@"MapLongClick"]; - [eventTypes setObject:RCT_MAPBOX_REGION_WILL_CHANGE_EVENT forKey:@"RegionWillChange"]; - [eventTypes setObject:RCT_MAPBOX_REGION_IS_CHANGING forKey:@"RegionIsChanging"]; - [eventTypes setObject:RCT_MAPBOX_REGION_DID_CHANGE forKey:@"RegionDidChange"]; - [eventTypes setObject:RCT_MAPBOX_WILL_START_LOADING_MAP forKey:@"WillStartLoadingMap"]; - [eventTypes setObject:RCT_MAPBOX_DID_FINISH_LOADING_MAP forKey:@"DidFinishLoadingMap"]; - [eventTypes setObject:RCT_MAPBOX_DID_FAIL_LOADING_MAP forKey:@"DidFailLoadingMap"]; - [eventTypes setObject:RCT_MAPBOX_WILL_START_RENDERING_FRAME forKey:@"WillStartRenderingFrame"]; - [eventTypes setObject:RCT_MAPBOX_DID_FINSIH_RENDERING_FRAME forKey:@"DidFinishRenderingFrame"]; - [eventTypes setObject:RCT_MAPBOX_DID_FINISH_RENDERING_FRAME_FULLY forKey:@"DidFinishRenderingFrameFully"]; - [eventTypes setObject:RCT_MAPBOX_WILL_START_RENDERING_MAP forKey:@"WillStartRenderingMap"]; - [eventTypes setObject:RCT_MAPBOX_DID_FINISH_RENDERING_MAP forKey:@"DidFinishRenderingMap"]; - [eventTypes setObject:RCT_MAPBOX_DID_FINISH_RENDERING_MAP_FULLY forKey:@"DidFinishRenderingMapFully"]; - [eventTypes setObject:RCT_MAPBOX_DID_FINISH_LOADING_STYLE forKey:@"DidFinishLoadingStyle"]; - - // location module events - NSMutableDictionary *locationModuleEvents = [[NSMutableDictionary alloc] init]; - [locationModuleEvents setObject:RCT_MAPBOX_USER_LOCATION_UPDATE forKey:@"Update"]; - - // user tracking modes - NSMutableDictionary *userTrackingModes = [[NSMutableDictionary alloc] init]; - [userTrackingModes setObject:[NSNumber numberWithInt:MGLUserTrackingModeNone] forKey:@"None"]; - [userTrackingModes setObject:[NSNumber numberWithInt:MGLUserTrackingModeFollow] forKey:@"Follow"]; - [userTrackingModes setObject:[NSNumber numberWithInt:MGLUserTrackingModeFollowWithHeading] forKey:@"FollowWithHeading"]; - [userTrackingModes setObject:[NSNumber numberWithInt:MGLUserTrackingModeFollowWithCourse] forKey:@"FollowWithCourse"]; - - // user location vertical alignment - NSMutableDictionary *userLocationVerticalAlignment = [[NSMutableDictionary alloc] init]; - [userLocationVerticalAlignment setObject:[NSNumber numberWithInt:MGLAnnotationVerticalAlignmentTop] forKey:@"Top"]; - [userLocationVerticalAlignment setObject:[NSNumber numberWithInt:MGLAnnotationVerticalAlignmentCenter] forKey:@"Center"]; - [userLocationVerticalAlignment setObject:[NSNumber numberWithInt:MGLAnnotationVerticalAlignmentBottom] forKey:@"Bottom"]; - - // camera modes - NSMutableDictionary *cameraModes = [[NSMutableDictionary alloc] init]; - [cameraModes setObject:[NSNumber numberWithInt:RCT_MAPBOX_CAMERA_MODE_FLIGHT] forKey:@"Flight"]; - [cameraModes setObject:[NSNumber numberWithInt:RCT_MAPBOX_CAMERA_MODE_EASE] forKey:@"Ease"]; - [cameraModes setObject:[NSNumber numberWithInt:RCT_MAPBOX_CAMERA_MODE_NONE] forKey:@"None"]; - - // style sources - NSMutableDictionary *styleSourceConsts = [[NSMutableDictionary alloc] init]; - [styleSourceConsts setObject:DEFAULT_SOURCE_ID forKey:@"DefaultSourceID"]; - - // line layer constants - NSMutableDictionary *lineJoin = [[NSMutableDictionary alloc] init]; - [lineJoin setObject:@(MGLLineJoinBevel) forKey:@"Bevel"]; - [lineJoin setObject:@(MGLLineJoinRound) forKey:@"Round"]; - [lineJoin setObject:@(MGLLineJoinMiter) forKey:@"Miter"]; - - NSMutableDictionary *lineCap = [[NSMutableDictionary alloc] init]; - [lineCap setObject:@(MGLLineCapButt) forKey:@"Butt"]; - [lineCap setObject:@(MGLLineCapRound) forKey:@"Round"]; - [lineCap setObject:@(MGLLineCapSquare) forKey:@"Square"]; - - NSMutableDictionary *lineTranslateAnchor = [[NSMutableDictionary alloc] init]; - [lineTranslateAnchor setObject:@(MGLLineTranslationAnchorMap) forKey:@"Map"]; - [lineTranslateAnchor setObject:@(MGLLineTranslationAnchorViewport) forKey:@"Viewport"]; - - // circle layer constants - NSMutableDictionary *circlePitchScale = [[NSMutableDictionary alloc] init]; - [circlePitchScale setObject:@(MGLCircleScaleAlignmentMap) forKey:@"Map"]; - [circlePitchScale setObject:@(MGLCircleScaleAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *circlePitchAlignment = [[NSMutableDictionary alloc] init]; - [circlePitchAlignment setObject:@(MGLCirclePitchAlignmentMap) forKey:@"Map"]; - [circlePitchAlignment setObject:@(MGLCirclePitchAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *circleTranslateAnchor = [[NSMutableDictionary alloc] init]; - [circleTranslateAnchor setObject:@(MGLCircleTranslationAnchorMap) forKey:@"Map"]; - [circleTranslateAnchor setObject:@(MGLCircleTranslationAnchorViewport) forKey:@"Viewport"]; - - // fill extrusion layer constants - NSMutableDictionary *fillExtrusionTranslateAnchor = [[NSMutableDictionary alloc] init]; - [fillExtrusionTranslateAnchor setObject:@(MGLFillExtrusionTranslationAnchorMap) forKey:@"Map"]; - [fillExtrusionTranslateAnchor setObject:@(MGLFillExtrusionTranslationAnchorViewport) forKey:@"Viewport"]; - - // fill layer constants - NSMutableDictionary *fillTranslateAnchor = [[NSMutableDictionary alloc] init]; - [fillTranslateAnchor setObject:@(MGLFillTranslationAnchorMap) forKey:@"Map"]; - [fillTranslateAnchor setObject:@(MGLFillTranslationAnchorViewport) forKey:@"Viewport"]; - - // symbol layer constants - NSMutableDictionary *iconRotationAlignment = [[NSMutableDictionary alloc] init]; - [iconRotationAlignment setObject:@(MGLIconRotationAlignmentAuto) forKey:@"Auto"]; - [iconRotationAlignment setObject:@(MGLIconRotationAlignmentMap) forKey:@"Map"]; - [iconRotationAlignment setObject:@(MGLIconRotationAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *iconTextFit = [[NSMutableDictionary alloc] init]; - [iconTextFit setObject:@(MGLIconTextFitNone) forKey:@"None"]; - [iconTextFit setObject:@(MGLIconTextFitWidth) forKey:@"Width"]; - [iconTextFit setObject:@(MGLIconTextFitHeight) forKey:@"Height"]; - [iconTextFit setObject:@(MGLIconTextFitBoth) forKey:@"Both"]; - - NSMutableDictionary *iconAnchor = [[NSMutableDictionary alloc] init]; - [iconAnchor setObject:@(MGLIconAnchorCenter) forKey:@"Center"]; - [iconAnchor setObject:@(MGLIconAnchorTop) forKey:@"Top"]; - [iconAnchor setObject:@(MGLIconAnchorBottom) forKey:@"Bottom"]; - [iconAnchor setObject:@(MGLIconAnchorLeft) forKey:@"Left"]; - [iconAnchor setObject:@(MGLIconAnchorRight) forKey:@"Right"]; - [iconAnchor setObject:@(MGLIconAnchorTopLeft) forKey:@"TopLeft"]; - [iconAnchor setObject:@(MGLIconAnchorTopRight) forKey:@"TopRight"]; - [iconAnchor setObject:@(MGLIconAnchorBottomLeft) forKey:@"BottomLeft"]; - [iconAnchor setObject:@(MGLIconAnchorBottomRight) forKey:@"BottomRight"]; - - NSMutableDictionary *iconTranslateAnchor = [[NSMutableDictionary alloc] init]; - [iconTranslateAnchor setObject:@(MGLIconTranslationAnchorMap) forKey:@"Map"]; - [iconTranslateAnchor setObject:@(MGLIconTranslationAnchorViewport) forKey:@"Viewport"]; - - NSMutableDictionary *iconPitchAlignment = [[NSMutableDictionary alloc] init]; - [iconPitchAlignment setObject:@(MGLIconPitchAlignmentAuto) forKey:@"Auto"]; - [iconPitchAlignment setObject:@(MGLIconPitchAlignmentMap) forKey:@"Map"]; - [iconPitchAlignment setObject:@(MGLIconPitchAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *symbolPlacement = [[NSMutableDictionary alloc] init]; - [symbolPlacement setObject:@(MGLSymbolPlacementLine) forKey:@"Line"]; - [symbolPlacement setObject:@(MGLSymbolPlacementPoint) forKey:@"Point"]; - - NSMutableDictionary *textAnchor = [[NSMutableDictionary alloc] init]; - [textAnchor setObject:@(MGLTextAnchorCenter) forKey:@"Center"]; - [textAnchor setObject:@(MGLTextAnchorLeft) forKey:@"Left"]; - [textAnchor setObject:@(MGLTextAnchorRight) forKey:@"Right"]; - [textAnchor setObject:@(MGLTextAnchorTop) forKey:@"Top"]; - [textAnchor setObject:@(MGLTextAnchorBottom) forKey:@"Bottom"]; - [textAnchor setObject:@(MGLTextAnchorTopLeft) forKey:@"TopLeft"]; - [textAnchor setObject:@(MGLTextAnchorTopRight) forKey:@"TopRight"]; - [textAnchor setObject:@(MGLTextAnchorBottomLeft) forKey:@"BottomLeft"]; - [textAnchor setObject:@(MGLTextAnchorBottomRight) forKey:@"BottomRight"]; - - NSMutableDictionary *textJustify = [[NSMutableDictionary alloc] init]; - [textJustify setObject:@(MGLTextJustificationCenter) forKey:@"Center"]; - [textJustify setObject:@(MGLTextJustificationLeft) forKey:@"Left"]; - [textJustify setObject:@(MGLTextJustificationRight) forKey:@"Right"]; - - NSMutableDictionary *textPitchAlignment = [[NSMutableDictionary alloc] init]; - [textPitchAlignment setObject:@(MGLTextPitchAlignmentAuto) forKey:@"Auto"]; - [textPitchAlignment setObject:@(MGLTextPitchAlignmentMap) forKey:@"Map"]; - [textPitchAlignment setObject:@(MGLTextPitchAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *textRotationAlignment = [[NSMutableDictionary alloc] init]; - [textRotationAlignment setObject:@(MGLTextRotationAlignmentAuto) forKey:@"Auto"]; - [textRotationAlignment setObject:@(MGLTextRotationAlignmentMap) forKey:@"Map"]; - [textRotationAlignment setObject:@(MGLTextRotationAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *textTransform = [[NSMutableDictionary alloc] init]; - [textTransform setObject:@(MGLTextTransformNone) forKey:@"None"]; - [textTransform setObject:@(MGLTextTransformLowercase) forKey:@"Lowercase"]; - [textTransform setObject:@(MGLTextTransformUppercase) forKey:@"Uppercase"]; - - NSMutableDictionary *textTranslateAnchor = [[NSMutableDictionary alloc] init]; - [textTranslateAnchor setObject:@(MGLTextTranslationAnchorMap) forKey:@"Map"]; - [textTranslateAnchor setObject:@(MGLTextTranslationAnchorViewport) forKey:@"Viewport"]; - - // light constants - NSMutableDictionary *lightAnchor = [[NSMutableDictionary alloc] init]; - [lightAnchor setObject:@(MGLLightAnchorMap) forKey:@"Map"]; - [lightAnchor setObject:@(MGLLightAnchorViewport) forKey:@"Viewport"]; - - // offline module callback names - NSMutableDictionary *offlineModuleCallbackNames = [[NSMutableDictionary alloc] init]; - [offlineModuleCallbackNames setObject:RCT_MAPBOX_OFFLINE_CALLBACK_ERROR forKey:@"Error"]; - [offlineModuleCallbackNames setObject:RCT_MAPBOX_OFFLINE_CALLBACK_PROGRESS forKey:@"Progress"]; - - NSMutableDictionary *offlinePackDownloadState = [[NSMutableDictionary alloc] init]; - [offlinePackDownloadState setObject:@(MGLOfflinePackStateInactive) forKey:@"Inactive"]; - [offlinePackDownloadState setObject:@(MGLOfflinePackStateActive) forKey:@"Active"]; - [offlinePackDownloadState setObject:@(MGLOfflinePackStateComplete) forKey:@"Complete"]; - - return @{ - @"StyleURL": styleURLS, - @"EventTypes": eventTypes, - @"UserTrackingModes": userTrackingModes, - @"UserLocationVerticalAlignment": userLocationVerticalAlignment, - @"CameraModes": cameraModes, - @"StyleSource": styleSourceConsts, - @"LineJoin": lineJoin, - @"LineCap": lineCap, - @"LineTranslateAnchor": lineTranslateAnchor, - @"CirclePitchScale": circlePitchScale, - @"CircleTranslateAnchor": circleTranslateAnchor, - @"CirclePitchAlignment": circlePitchAlignment, - @"FillExtrusionTranslateAnchor": fillExtrusionTranslateAnchor, - @"FillTranslateAnchor": fillTranslateAnchor, - @"IconRotationAlignment": iconRotationAlignment, - @"IconTextFit": iconTextFit, - @"IconTranslateAnchor": iconTranslateAnchor, - @"IconAnchor": iconAnchor, - @"IconPitchAlignment": iconPitchAlignment, - @"SymbolPlacement": symbolPlacement, - @"TextAnchor": textAnchor, - @"TextJustify": textJustify, - @"TextPitchAlignment": textPitchAlignment, - @"TextRotationAlignment": textRotationAlignment, - @"TextTransform": textTransform, - @"TextTranslateAnchor": textTranslateAnchor, - @"LightAnchor": lightAnchor, - @"OfflineCallbackName": offlineModuleCallbackNames, - @"OfflinePackDownloadState": offlinePackDownloadState, - @"LocationCallbackName": locationModuleEvents - }; -} - -RCT_EXPORT_METHOD(setAccessToken:(NSString *)accessToken) -{ - [MGLAccountManager setAccessToken:accessToken]; -} - -RCT_EXPORT_METHOD(addCustomHeader:(NSString *)headerName forHeaderValue:(NSString *) headerValue) -{ - [MGLCustomHeaders.sharedInstance addHeader:headerValue forHeaderName:headerName]; -} - -RCT_EXPORT_METHOD(removeCustomHeader:(NSString *)headerName) -{ - [MGLCustomHeaders.sharedInstance removeHeader:headerName]; -} - -RCT_EXPORT_METHOD(getAccessToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - NSString *accessToken = MGLAccountManager.accessToken; - - if (accessToken != nil) { - resolve(accessToken); - return; - } - - reject(@"missing_access_token", @"No access token has been set", nil); -} - -RCT_EXPORT_METHOD(setTelemetryEnabled:(BOOL)telemetryEnabled) -{ - [[NSUserDefaults standardUserDefaults] setBool:telemetryEnabled - forKey:@"MGLMapboxMetricsEnabled"]; -} +RCT_EXTERN_METHOD(setAccessToken:) @end diff --git a/ios/RCTMGL/MGLModule.swift b/ios/RCTMGL/MGLModule.swift new file mode 100644 index 0000000000..168366b6b9 --- /dev/null +++ b/ios/RCTMGL/MGLModule.swift @@ -0,0 +1,40 @@ +import Foundation +import MapboxMaps + + +let DEFAULT_SOURCE_ID = "composite"; + +@objc(MGLModule) +class MGLModule : NSObject { + static var accessToken : String? + + @objc + func constantsToExport() -> [AnyHashable: Any]! { + return [ + "StyleURL": + [ + "Street": StyleURL.streets.url.absoluteString, + "Outdoors": StyleURL.outdoors.url.absoluteString, + "Light": StyleURL.light.url.absoluteString, + "Dark": StyleURL.dark.url.absoluteString, + "Satellite": StyleURL.satellite.url.absoluteString, + "SatelliteStreets": StyleURL.satelliteStreets.url.absoluteString, + ], + "StyleSource": + ["DefaultSourceID": DEFAULT_SOURCE_ID], + "LineJoin": + ["Round": LineJoin.round], + "LocationCallbackName": + ["Update": RCT_MAPBOX_USER_LOCATION_UPDATE] + ]; + } + + @objc + static func requiresMainQueueSetup() -> Bool { + return true + } + + @objc func setAccessToken(_ token: String) { + MGLModule.accessToken = token + } +} diff --git a/ios/RCTMGL/MGLOfflineModule.h b/ios/RCTMGL/MGLOfflineModule.h deleted file mode 100644 index e876a175f0..0000000000 --- a/ios/RCTMGL/MGLOfflineModule.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// MGLOfflineModule.h -// RCTMGL -// -// Created by Nick Italiano on 10/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import - -@import Mapbox; - -@interface MGLOfflineModule : RCTEventEmitter - -extern NSString *const RCT_MAPBOX_OFFLINE_CALLBACK_PROGRESS; -extern NSString *const RCT_MAPBOX_OFFLINE_CALLBACK_ERROR; - -@end diff --git a/ios/RCTMGL/MGLOfflineModule.m b/ios/RCTMGL/MGLOfflineModule.m deleted file mode 100644 index 719deeeb1f..0000000000 --- a/ios/RCTMGL/MGLOfflineModule.m +++ /dev/null @@ -1,516 +0,0 @@ -// -// MGLOfflineModule.m -// RCTMGL -// -// Created by Nick Italiano on 10/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "MGLOfflineModule.h" -#import "RCTMGLUtils.h" -#import "RCTMGLEvent.h" -#import "RCTMGLEventTypes.h" - -@implementation MGLOfflineModule -{ - NSUInteger lastPackState; - double lastPackTimestamp; - double eventThrottle; - BOOL hasListeners; - NSMutableArray *packRequestQueue; -} - -RCT_EXPORT_MODULE() - -+ (BOOL)requiresMainQueueSetup -{ - return YES; -} - -- (void)startObserving -{ - [super startObserving]; - hasListeners = YES; -} - -- (void)stopObserving -{ - [super stopObserving]; - hasListeners = NO; -} - -NSString *const RCT_MAPBOX_OFFLINE_CALLBACK_PROGRESS = @"MapboxOfflineRegionProgress"; -NSString *const RCT_MAPBOX_OFFLINE_CALLBACK_ERROR = @"MapboOfflineRegionError"; - -- (instancetype)init -{ - if (self = [super init]) { - packRequestQueue = [NSMutableArray new]; - eventThrottle = 300; - lastPackState = -1; - - NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; - [defaultCenter addObserver:self selector:@selector(offlinePackProgressDidChange:) name:MGLOfflinePackProgressChangedNotification object:nil]; - [defaultCenter addObserver:self selector:@selector(offlinePackDidReceiveError:) name:MGLOfflinePackErrorNotification object:nil]; - [defaultCenter addObserver:self selector:@selector(offlinePackDidReceiveMaxAllowedMapboxTiles:) name:MGLOfflinePackMaximumMapboxTilesReachedNotification object:nil]; - - [[MGLOfflineStorage sharedOfflineStorage] addObserver:self forKeyPath:@"packs" options:NSKeyValueObservingOptionInitial context:NULL]; - } - return self; -} - -- (void)dealloc -{ - [[MGLOfflineStorage sharedOfflineStorage] removeObserver:self forKeyPath:@"packs"]; - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -- (NSArray *)supportedEvents -{ - return @[RCT_MAPBOX_OFFLINE_CALLBACK_PROGRESS, RCT_MAPBOX_OFFLINE_CALLBACK_ERROR]; -} - -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context -{ - if (packRequestQueue.count == 0) { - return; - } - - NSArray *packs = [[MGLOfflineStorage sharedOfflineStorage] packs]; - if (packs == nil) { - return; - } - - while (packRequestQueue.count > 0) { - RCTPromiseResolveBlock resolve = [packRequestQueue objectAtIndex:0]; - resolve([self _convertPacksToJson:packs]); - [packRequestQueue removeObjectAtIndex:0]; - } -} - -RCT_EXPORT_METHOD(createPack:(NSDictionary *)options - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - NSString *styleURL = options[@"styleURL"]; - MGLCoordinateBounds bounds = [RCTMGLUtils fromFeatureCollection:options[@"bounds"]]; - - id offlineRegion = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:[NSURL URLWithString:styleURL] - bounds:bounds - fromZoomLevel:[options[@"minZoom"] doubleValue] - toZoomLevel:[options[@"maxZoom"] doubleValue]]; - NSData *context = [self _archiveMetadata:options[@"metadata"]]; - - [[MGLOfflineStorage sharedOfflineStorage] addPackForRegion:offlineRegion - withContext:context - completionHandler:^(MGLOfflinePack *pack, NSError *error) { - if (error != nil) { - reject(@"createPack", error.description, error); - return; - } - resolve([self _convertPackToDict:pack]); - [pack resume]; - }]; -} - -RCT_EXPORT_METHOD(mergeOfflineRegions:(NSString *)path - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - NSString *absolutePath; - if ([path isAbsolutePath]) { - absolutePath = path; - } else { - NSBundle *mainBundle = [NSBundle mainBundle]; - NSString *fileName = [path stringByDeletingPathExtension]; - NSString *extension = [path pathExtension]; - absolutePath = [mainBundle pathForResource:fileName ofType:extension]; - if (!absolutePath) { - return reject(@"asset_does_not_exist", [NSString stringWithFormat:@"The given assetName, %@, can't be found in the app's bundle.", path], nil); - } - } - - [[MGLOfflineStorage sharedOfflineStorage] addContentsOfFile:absolutePath withCompletionHandler:^(NSURL *fileURL, NSArray *packs, NSError *error) { - if (error != nil) { - reject(@"mergeOfflineRegions", error.description, error); - return; - } - resolve(nil); - }]; -} - -RCT_EXPORT_METHOD(getPacks:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - dispatch_async(dispatch_get_main_queue(), ^{ - NSArray *packs = [[MGLOfflineStorage sharedOfflineStorage] packs]; - - if (packs == nil) { - // packs have not loaded yet - [self->packRequestQueue addObject:resolve]; - return; - } - - resolve([self _convertPacksToJson:packs]); - }); -} - -RCT_EXPORT_METHOD(invalidateAmbientCache:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - [[MGLOfflineStorage sharedOfflineStorage] invalidateAmbientCacheWithCompletionHandler:^(NSError *error) { - if (error != nil) { - reject(@"invalidateAmbientCache", error.description, error); - return; - } - resolve(nil); - }]; -} - -RCT_EXPORT_METHOD(clearAmbientCache:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - [[MGLOfflineStorage sharedOfflineStorage] clearAmbientCacheWithCompletionHandler:^(NSError *error) { - if (error != nil) { - reject(@"clearAmbientCache", error.description, error); - return; - } - resolve(nil); - }]; -} - -RCT_EXPORT_METHOD(setMaximumAmbientCacheSize:(NSUInteger)cacheSize - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [[MGLOfflineStorage sharedOfflineStorage] setMaximumAmbientCacheSize:cacheSize withCompletionHandler:^(NSError *error) { - if (error != nil) { - reject(@"setMaximumAmbientCacheSize", error.description, error); - return; - } - resolve(nil); - }]; - -} - -RCT_EXPORT_METHOD(resetDatabase:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - [[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError *error) { - if (error != nil) { - reject(@"resetDatabase", error.description, error); - return; - } - resolve(nil); - }]; - -} - -RCT_EXPORT_METHOD(getPackStatus:(NSString *)name - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - MGLOfflinePack *pack = [self _getPackFromName:name]; - - if (pack == nil) { - resolve(nil); - NSLog(@"getPackStatus - Unknown offline region"); - return; - } - - resolve([self _makeRegionStatusPayload:name pack:pack]); -} - -RCT_EXPORT_METHOD(invalidatePack:(NSString *)name - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - MGLOfflinePack *pack = [self _getPackFromName:name]; - - if (pack == nil) { - resolve(nil); - return; - } - [[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError *error) { - if (error != nil) { - reject(@"invalidatePack", error.description, error); - return; - } - resolve(nil); - }]; -} - -RCT_EXPORT_METHOD(deletePack:(NSString *)name - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - MGLOfflinePack *pack = [self _getPackFromName:name]; - - if (pack == nil) { - resolve(nil); - return; - } - if (pack.state == MGLOfflinePackStateInvalid) { - NSError *error = [NSError errorWithDomain:MGLErrorDomain code:1 userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"Pack has already been deleted", nil)}]; - reject(@"deletePack", error.description, error); - return; - } - [[MGLOfflineStorage sharedOfflineStorage] removePack:pack withCompletionHandler:^(NSError *error) { - if (error != nil) { - reject(@"deletePack", error.description, error); - return; - } - resolve(nil); - }]; -} - -RCT_EXPORT_METHOD(pausePackDownload:(NSString *)name - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - MGLOfflinePack *pack = [self _getPackFromName:name]; - - if (pack == nil) { - reject(@"pausePackDownload", @"Unknown offline region", nil); - return; - } - - if (pack.state == MGLOfflinePackStateInactive || pack.state == MGLOfflinePackStateComplete) { - resolve(nil); - return; - } - - [pack suspend]; - resolve(nil); -} - -RCT_EXPORT_METHOD(resumePackDownload:(NSString *)name - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - MGLOfflinePack *pack = [self _getPackFromName:name]; - - if (pack == nil) { - reject(@"resumePack", @"Unknown offline region", nil); - return; - } - - if (pack.state == MGLOfflinePackStateActive || pack.state == MGLOfflinePackStateComplete) { - resolve(nil); - return; - } - - [pack resume]; - resolve(nil); -} - -RCT_EXPORT_METHOD(setTileCountLimit:(nonnull NSNumber *)limit) -{ - [[MGLOfflineStorage sharedOfflineStorage] setMaximumAllowedMapboxTiles:[limit intValue]]; -} - -RCT_EXPORT_METHOD(setProgressEventThrottle:(nonnull NSNumber *)throttleValue) -{ - eventThrottle = [throttleValue doubleValue]; -} - -- (void)offlinePackProgressDidChange:(NSNotification *)notification -{ - MGLOfflinePack *pack = notification.object; - - if (pack.state == MGLOfflinePackStateInvalid) { - return; // Avoid invalid offline pack exception - } - - if ([self _shouldSendProgressEvent:[self _getCurrentTimestamp] pack:pack]) { - NSDictionary *metadata = [self _unarchiveMetadata:pack]; - RCTMGLEvent *event = [self _makeProgressEvent:metadata[@"name"] pack:pack]; - [self _sendEvent:RCT_MAPBOX_OFFLINE_CALLBACK_PROGRESS event:event]; - lastPackTimestamp = [self _getCurrentTimestamp]; - } - - lastPackState = pack.state; -} - -- (void)offlinePackDidReceiveError:(NSNotification *)notification -{ - MGLOfflinePack *pack = notification.object; - if (pack.state == MGLOfflinePackStateInvalid) { - return; // Avoid invalid offline pack exception - } - NSDictionary *metadata = [self _unarchiveMetadata:pack]; - - NSString *name = metadata[@"name"]; - if (name != nil) { - NSError *error = notification.userInfo[MGLOfflinePackUserInfoKeyError]; - RCTMGLEvent *event = [self _makeErrorEvent:name - type:RCT_MAPBOX_OFFLINE_ERROR - message:error.description]; - [self _sendEvent:RCT_MAPBOX_OFFLINE_CALLBACK_ERROR event:event]; - } -} - -- (void)offlinePackDidReceiveMaxAllowedMapboxTiles:(NSNotification *)notification -{ - MGLOfflinePack *pack = notification.object; - NSDictionary *metadata = [self _unarchiveMetadata:pack]; - - NSString *name = metadata[@"name"]; - if (name != nil) { - RCTMGLEvent *event = [self _makeErrorEvent:name - type:RCT_MAPBOX_OFFLINE_ERROR - message:@"Mapbox tile limit exceeded"]; - [self _sendEvent:RCT_MAPBOX_OFFLINE_CALLBACK_ERROR event:event]; - } -} - -- (double)_getCurrentTimestamp -{ - return CACurrentMediaTime() * 1000; -} - -- (NSData *)_archiveMetadata:(NSString *)metadata -{ - return [NSKeyedArchiver archivedDataWithRootObject:metadata]; -} - -- (NSDictionary *)_unarchiveMetadata:(MGLOfflinePack *)pack -{ - id data = [NSKeyedUnarchiver unarchiveObjectWithData:pack.context]; - // Version v5 store data as NSDictionary while v6 store data as JSON string. - // User might save offline pack in v5 and then try to read in v6. - // In v5 are metadata stored nested which need to be handled in JS. - // Example of how data are stored in v5 - // { - // name: "New York", - // metadata: { - // customMeta: "...", - // } - // } - if ([data isKindOfClass:[NSDictionary class]]) { - return data; - } - - if (data == nil) { - return @{}; - } - - return [NSJSONSerialization JSONObjectWithData:[data dataUsingEncoding:NSUTF8StringEncoding] - options:NSJSONReadingMutableContainers - error:nil]; -} - -- (NSDictionary *)_makeRegionStatusPayload:(NSString *)name pack:(MGLOfflinePack *)pack -{ - uint64_t completedResources = pack.progress.countOfResourcesCompleted; - uint64_t expectedResources = pack.progress.countOfResourcesExpected; - float progressPercentage = (float)completedResources / expectedResources; - - // prevent NaN errors when expectedResources is 0 - if(expectedResources == 0) { - progressPercentage = 0; - } - - return @{ - @"state": @(pack.state), - @"name": name, - @"percentage": @(ceilf(progressPercentage * 100.0)), - @"completedResourceCount": @(pack.progress.countOfResourcesCompleted), - @"completedResourceSize": @(pack.progress.countOfBytesCompleted), - @"completedTileSize": @(pack.progress.countOfTileBytesCompleted), - @"completedTileCount": @(pack.progress.countOfTilesCompleted), - @"requiredResourceCount": @(pack.progress.maximumResourcesExpected) - }; -} - -- (RCTMGLEvent *)_makeProgressEvent:(NSString *)name pack:(MGLOfflinePack *)pack -{ - return [RCTMGLEvent makeEvent:RCT_MAPBOX_OFFLINE_PROGRESS withPayload:[self _makeRegionStatusPayload:name pack:pack]]; -} - -- (RCTMGLEvent *)_makeErrorEvent:(NSString *)name type:(NSString *)type message:(NSString *)message -{ - NSDictionary *payload = @{ @"name": name, @"message": message }; - return [RCTMGLEvent makeEvent:type withPayload:payload]; -} - -- (NSArray *)_convertPacksToJson:(NSArray *)packs -{ - NSMutableArray *jsonPacks = [NSMutableArray new]; - - if (packs == nil) { - return jsonPacks; - } - - for (MGLOfflinePack *pack in packs) { - [jsonPacks addObject:[self _convertPackToDict:pack]]; - } - - return jsonPacks; -} - -- (NSDictionary *)_convertPackToDict:(MGLOfflinePack *)pack -{ - // format bounds - MGLTilePyramidOfflineRegion *region = (MGLTilePyramidOfflineRegion *)pack.region; - if (region == nil) { - return nil; - } - - NSArray *jsonBounds = @[ - @[@(region.bounds.ne.longitude), @(region.bounds.ne.latitude)], - @[@(region.bounds.sw.longitude), @(region.bounds.sw.latitude)] - ]; - - // format metadata - NSDictionary *metadata = [self _unarchiveMetadata:pack]; - NSData *jsonMetadata = [NSJSONSerialization dataWithJSONObject:metadata - options:0 - error:nil]; - return @{ - @"metadata": [[NSString alloc] initWithData:jsonMetadata encoding:NSUTF8StringEncoding], - @"bounds": jsonBounds - }; -} - -- (MGLOfflinePack *)_getPackFromName:(NSString *)name -{ - NSArray *packs = [[MGLOfflineStorage sharedOfflineStorage] packs]; - - if (packs == nil) { - return nil; - } - - for (MGLOfflinePack *pack in packs) { - NSDictionary *metadata = [self _unarchiveMetadata:pack]; - - if ([name isEqualToString:metadata[@"name"]]) { - return pack; - } - } - - return nil; -} - -- (void)_sendEvent:(NSString *)eventName event:(RCTMGLEvent *)event -{ - if (!hasListeners) { - return; - } - [self sendEventWithName:eventName body:[event toJSON]]; -} - -- (BOOL)_shouldSendProgressEvent:(double)currentTimestamp pack:(MGLOfflinePack *)currentPack -{ - if (lastPackState == -1) { - return YES; - } - - if (lastPackState != currentPack.state) { - return YES; - } - - if (currentTimestamp - lastPackTimestamp > eventThrottle) { - return YES; - } - - return NO; -} - -@end diff --git a/ios/RCTMGL/MGLSnapshotModule.h b/ios/RCTMGL/MGLSnapshotModule.h deleted file mode 100644 index bf868aeb75..0000000000 --- a/ios/RCTMGL/MGLSnapshotModule.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// MGLSnapshotModule.h -// RCTMGL -// -// Created by Nick Italiano on 12/1/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import - -@interface MGLSnapshotModule : NSObject - -@end diff --git a/ios/RCTMGL/MGLSnapshotModule.m b/ios/RCTMGL/MGLSnapshotModule.m deleted file mode 100644 index 25ba8d1abf..0000000000 --- a/ios/RCTMGL/MGLSnapshotModule.m +++ /dev/null @@ -1,80 +0,0 @@ -// -// MGLSnapshotModule.m -// RCTMGL -// -// Created by Nick Italiano on 12/1/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "MGLSnapshotModule.h" -#import "RCTMGLUtils.h" -#import "RNMBImageUtils.h" -@import Mapbox; - -@implementation MGLSnapshotModule - -RCT_EXPORT_MODULE() - -+ (BOOL)requiresMainQueueSetup -{ - return YES; -} - -RCT_EXPORT_METHOD(takeSnap:(NSDictionary *)jsOptions - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - dispatch_async(dispatch_get_main_queue(), ^{ - MGLMapSnapshotOptions *options = [self _getOptions:jsOptions]; - __block MGLMapSnapshotter *snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options]; - - [snapshotter startWithCompletionHandler:^(MGLMapSnapshot * _Nullable snapshot, NSError * _Nullable err) { - if (err != nil) { - reject(@"takeSnap", @"Could not create snapshot", err); - snapshotter = nil; - return; - } - - NSString *result = nil; - if ([jsOptions[@"writeToDisk"] boolValue]) { - result = [RNMBImageUtils createTempFile:snapshot.image]; - } else { - result = [RNMBImageUtils createBase64:snapshot.image]; - } - - resolve(result); - snapshotter = nil; - }]; - }); -} - -- (MGLMapSnapshotOptions *)_getOptions:(NSDictionary *)jsOptions -{ - MGLMapCamera *camera = [[MGLMapCamera alloc] init]; - - camera.pitch = [jsOptions[@"pitch"] doubleValue]; - camera.heading = [jsOptions[@"heading"] doubleValue]; - - if (jsOptions[@"centerCoordinate"] != nil) { - camera.centerCoordinate = [RCTMGLUtils fromFeature:jsOptions[@"centerCoordinate"]]; - } - - NSNumber *width = jsOptions[@"width"]; - NSNumber *height = jsOptions[@"height"]; - CGSize size = CGSizeMake([width doubleValue], [height doubleValue]); - - MGLMapSnapshotOptions *options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:[NSURL URLWithString:jsOptions[@"styleURL"]] - camera:camera - size:size]; - if (jsOptions[@"zoomLevel"] != nil) { - options.zoomLevel = [jsOptions[@"zoomLevel"] doubleValue]; - } - - if (jsOptions[@"bounds"] != nil) { - options.coordinateBounds = [RCTMGLUtils fromFeatureCollection:jsOptions[@"bounds"]]; - } - - return options; -} - -@end diff --git a/ios/RCTMGL/MGLUserLocationHeadingArrowLayer.h b/ios/RCTMGL/MGLUserLocationHeadingArrowLayer.h deleted file mode 100644 index 90727cd1d2..0000000000 --- a/ios/RCTMGL/MGLUserLocationHeadingArrowLayer.h +++ /dev/null @@ -1,11 +0,0 @@ -#import -#import "MGLUserLocationHeadingIndicator.h" -@import Mapbox; - -@interface MGLUserLocationHeadingArrowLayer : CAShapeLayer - -- (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView; -- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy; -- (void)updateTintColor:(CGColorRef)color; - -@end diff --git a/ios/RCTMGL/MGLUserLocationHeadingArrowLayer.m b/ios/RCTMGL/MGLUserLocationHeadingArrowLayer.m deleted file mode 100644 index b63ba09f12..0000000000 --- a/ios/RCTMGL/MGLUserLocationHeadingArrowLayer.m +++ /dev/null @@ -1,57 +0,0 @@ -#import "MGLUserLocationHeadingArrowLayer.h" -#import "MGLFaux3DUserLocationAnnotationView.h" - -const CGFloat MGLUserLocationHeadingArrowSize = 6; - -@implementation MGLUserLocationHeadingArrowLayer - -- (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView -{ - CGFloat size = userLocationView.bounds.size.width + MGLUserLocationHeadingArrowSize; - - self = [super init]; - self.bounds = CGRectMake(0, 0, size, size); - self.position = CGPointMake(CGRectGetMidX(userLocationView.bounds), CGRectGetMidY(userLocationView.bounds)); - self.path = [self arrowPath]; - self.fillColor = userLocationView.tintColor.CGColor; - self.shouldRasterize = YES; - self.rasterizationScale = UIScreen.mainScreen.scale; - self.drawsAsynchronously = YES; - - self.strokeColor = UIColor.whiteColor.CGColor; - self.lineWidth = 1.0; - self.lineJoin = kCALineJoinRound; - - return self; -} - -- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy -{ - // unimplemented -} - -- (void)updateTintColor:(CGColorRef)color -{ - self.fillColor = color; -} - -- (CGPathRef)arrowPath { - CGFloat center = roundf(CGRectGetMidX(self.bounds)); - CGFloat size = MGLUserLocationHeadingArrowSize; - - CGPoint top = CGPointMake(center, 0); - CGPoint left = CGPointMake(center - size, size); - CGPoint right = CGPointMake(center + size, size); - CGPoint middle = CGPointMake(center, size / M_PI); - - UIBezierPath *bezierPath = [UIBezierPath bezierPath]; - [bezierPath moveToPoint:top]; - [bezierPath addLineToPoint:left]; - [bezierPath addQuadCurveToPoint:right controlPoint:middle]; - [bezierPath addLineToPoint:top]; - [bezierPath closePath]; - - return bezierPath.CGPath; -} - -@end diff --git a/ios/RCTMGL/MGLUserLocationHeadingBeamLayer.h b/ios/RCTMGL/MGLUserLocationHeadingBeamLayer.h deleted file mode 100644 index 4003f7e12d..0000000000 --- a/ios/RCTMGL/MGLUserLocationHeadingBeamLayer.h +++ /dev/null @@ -1,11 +0,0 @@ -#import -#import "MGLUserLocationHeadingIndicator.h" -@import Mapbox; - -@interface MGLUserLocationHeadingBeamLayer : CALayer - -- (MGLUserLocationHeadingBeamLayer *)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView; -- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy; -- (void)updateTintColor:(CGColorRef)color; - -@end diff --git a/ios/RCTMGL/MGLUserLocationHeadingBeamLayer.m b/ios/RCTMGL/MGLUserLocationHeadingBeamLayer.m deleted file mode 100644 index d3d85b18c5..0000000000 --- a/ios/RCTMGL/MGLUserLocationHeadingBeamLayer.m +++ /dev/null @@ -1,102 +0,0 @@ -#import "MGLUserLocationHeadingBeamLayer.h" -#import "MGLFaux3DUserLocationAnnotationView.h" - -@implementation MGLUserLocationHeadingBeamLayer -{ - CAShapeLayer *_maskLayer; -} - -- (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView -{ - CGFloat size = MGLUserLocationAnnotationHaloSize; - - self = [super init]; - self.bounds = CGRectMake(0, 0, size, size); - self.position = CGPointMake(CGRectGetMidX(userLocationView.bounds), CGRectGetMidY(userLocationView.bounds)); - self.contents = (__bridge id)[self gradientImageWithTintColor:userLocationView.tintColor.CGColor]; - self.contentsGravity = kCAGravityBottom; - self.contentsScale = UIScreen.mainScreen.scale; - self.opacity = 0.4; - self.shouldRasterize = YES; - self.rasterizationScale = UIScreen.mainScreen.scale; - self.drawsAsynchronously = YES; - - _maskLayer = [CAShapeLayer layer]; - _maskLayer.frame = self.bounds; - _maskLayer.path = [self clippingMaskForAccuracy:0]; - self.mask = _maskLayer; - - return self; -} - -- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy -{ - // recalculate the clipping mask based on updated accuracy - _maskLayer.path = [self clippingMaskForAccuracy:accuracy]; -} - -- (void)updateTintColor:(CGColorRef)color -{ - // redraw the raw tinted gradient - self.contents = (__bridge id)[self gradientImageWithTintColor:color]; -} - -- (CGImageRef)gradientImageWithTintColor:(CGColorRef)tintColor -{ - UIImage *image; - - CGFloat haloRadius = MGLUserLocationAnnotationHaloSize / 2.0; - - UIGraphicsBeginImageContextWithOptions(CGSizeMake(MGLUserLocationAnnotationHaloSize, haloRadius), NO, 0); - - CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - CGContextRef context = UIGraphicsGetCurrentContext(); - - // gradient from the tint color to no-alpha tint color - CGFloat gradientLocations[] = {0.0, 1.0}; - CGGradientRef gradient = CGGradientCreateWithColors( - colorSpace, - (__bridge CFArrayRef)@[(__bridge id)tintColor, - (id)CFBridgingRelease(CGColorCreateCopyWithAlpha(tintColor, 0))], - gradientLocations); - - // draw the gradient from the center point to the edge (full halo radius) - CGPoint centerPoint = CGPointMake(haloRadius, haloRadius); - CGContextDrawRadialGradient(context, gradient, - centerPoint, 0.0, - centerPoint, haloRadius, - kNilOptions); - - image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - CGGradientRelease(gradient); - CGColorSpaceRelease(colorSpace); - - return image.CGImage; -} - -- (CGPathRef)clippingMaskForAccuracy:(CGFloat)accuracy -{ - // size the mask using accuracy, but keep within a good display range - CGFloat clippingDegrees = 90 - accuracy; - clippingDegrees = fmin(clippingDegrees, 70); // most accurate - clippingDegrees = fmax(clippingDegrees, 10); // least accurate - - CGRect ovalRect = CGRectMake(0, 0, MGLUserLocationAnnotationHaloSize, MGLUserLocationAnnotationHaloSize); - UIBezierPath *ovalPath = UIBezierPath.bezierPath; - - // clip the oval to ± incoming accuracy degrees (converted to radians), from the top - [ovalPath addArcWithCenter:CGPointMake(CGRectGetMidX(ovalRect), CGRectGetMidY(ovalRect)) - radius:CGRectGetWidth(ovalRect) / 2.0 - startAngle:MGLRadiansFromDegrees(-180 + clippingDegrees) - endAngle:MGLRadiansFromDegrees(-clippingDegrees) - clockwise:YES]; - - [ovalPath addLineToPoint:CGPointMake(CGRectGetMidX(ovalRect), CGRectGetMidY(ovalRect))]; - [ovalPath closePath]; - - return ovalPath.CGPath; -} - -@end diff --git a/ios/RCTMGL/MGLUserLocationHeadingIndicator.h b/ios/RCTMGL/MGLUserLocationHeadingIndicator.h deleted file mode 100644 index e17d599395..0000000000 --- a/ios/RCTMGL/MGLUserLocationHeadingIndicator.h +++ /dev/null @@ -1,10 +0,0 @@ -#import -@import Mapbox; - -@protocol MGLUserLocationHeadingIndicator - -- (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView; -- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy; -- (void)updateTintColor:(CGColorRef)color; - -@end diff --git a/ios/RCTMGL/RCTConvert+Mapbox.h b/ios/RCTMGL/RCTConvert+Mapbox.h deleted file mode 100644 index da34b5a74f..0000000000 --- a/ios/RCTMGL/RCTConvert+Mapbox.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// RCTConvert+Mapbox.h -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import - -@interface RCTConvert (Mapbox) - -+ (CLLocationCoordinate2D)GeoJSONPoint:(id)json; - -@end diff --git a/ios/RCTMGL/RCTConvert+Mapbox.m b/ios/RCTMGL/RCTConvert+Mapbox.m deleted file mode 100644 index 318b956818..0000000000 --- a/ios/RCTMGL/RCTConvert+Mapbox.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// RCTConvert+Mapbox.m -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTConvert+Mapbox.h" - -@implementation RCTConvert (Mapbox) - -+ (CLLocationCoordinate2D)GeoJSONPoint:(id)json -{ - NSDictionary *point = [self NSDictionary:json]; - - if (![[point objectForKey:@"type"] isEqual: @"Point"]) { - return CLLocationCoordinate2DMake(0, 0); - } - - NSArray *coords = (NSArray*)[point objectForKey:@"coordinates"]; - if (coords == nil || coords.count < 2) { - return CLLocationCoordinate2DMake(0, 0); - } - - double lat = [[coords objectAtIndex:1] doubleValue]; - double lng = [[coords objectAtIndex:0] doubleValue]; - - return CLLocationCoordinate2DMake(lat, lng); -} - -@end diff --git a/ios/RCTMGL/RCTMGL.h b/ios/RCTMGL/RCTMGL.h deleted file mode 100644 index 3fd628faf8..0000000000 --- a/ios/RCTMGL/RCTMGL.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGL.h -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import - -@interface RCTMGL : NSObject - -@end diff --git a/ios/RCTMGL/RCTMGL.m b/ios/RCTMGL/RCTMGL.m deleted file mode 100644 index a7972e274d..0000000000 --- a/ios/RCTMGL/RCTMGL.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGL.m -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGL.h" - -@implementation RCTMGL - -@end diff --git a/ios/RCTMGL/RCTMGLBackgroundLayer.h b/ios/RCTMGL/RCTMGLBackgroundLayer.h deleted file mode 100644 index ed264d3181..0000000000 --- a/ios/RCTMGL/RCTMGLBackgroundLayer.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// RCTMGLBackgroundLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLayer.h" -@import Mapbox; - -@interface RCTMGLBackgroundLayer : RCTMGLLayer - -@end diff --git a/ios/RCTMGL/RCTMGLBackgroundLayer.m b/ios/RCTMGL/RCTMGLBackgroundLayer.m deleted file mode 100644 index 3321fa797d..0000000000 --- a/ios/RCTMGL/RCTMGLBackgroundLayer.m +++ /dev/null @@ -1,27 +0,0 @@ -// -// RCTMGLBackgroundLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLBackgroundLayer.h" -#import "RCTMGLStyle.h" - -@implementation RCTMGLBackgroundLayer - -- (MGLStyleLayer*)makeLayer:(MGLStyle*)style -{ - return [[MGLBackgroundStyleLayer alloc] initWithIdentifier:self.id]; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style backgroundLayer:(MGLBackgroundStyleLayer*)self.styleLayer withReactStyle:self.reactStyle isValid:^{ return [self isAddedToMap]; - }]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLBackgroundLayerManager.h b/ios/RCTMGL/RCTMGLBackgroundLayerManager.h deleted file mode 100644 index 23baa54980..0000000000 --- a/ios/RCTMGL/RCTMGLBackgroundLayerManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLBackgroundLayerManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLBackgroundLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLBackgroundLayerManager.m b/ios/RCTMGL/RCTMGLBackgroundLayerManager.m deleted file mode 100644 index 0150531dc8..0000000000 --- a/ios/RCTMGL/RCTMGLBackgroundLayerManager.m +++ /dev/null @@ -1,35 +0,0 @@ -// -// RCTMGLBackgroundLayerManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLBackgroundLayerManager.h" -#import "RCTMGLBackgroundLayer.h" - -@implementation RCTMGLBackgroundLayerManager - -RCT_EXPORT_MODULE() - -// standard layer props -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLBackgroundLayer *layer = [[RCTMGLBackgroundLayer alloc] init]; - layer.bridge = self.bridge; - return layer; -} - -@end diff --git a/ios/RCTMGL/RCTMGLCallout.h b/ios/RCTMGL/RCTMGLCallout.h deleted file mode 100644 index 599d109bea..0000000000 --- a/ios/RCTMGL/RCTMGLCallout.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// RCTMGLCalloutView.h -// RCTMGL -// -// Created by Nick Italiano on 10/13/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import - -@import Mapbox; - -@interface RCTMGLCallout : RCTView - -@end diff --git a/ios/RCTMGL/RCTMGLCallout.m b/ios/RCTMGL/RCTMGLCallout.m deleted file mode 100644 index c6c5e137a4..0000000000 --- a/ios/RCTMGL/RCTMGLCallout.m +++ /dev/null @@ -1,74 +0,0 @@ -// -// RCTMGLCalloutView.m -// RCTMGL -// -// Created by Nick Italiano on 10/13/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLCallout.h" -#import "UIView+React.h" - -@implementation RCTMGLCallout -{ - id _representedObject; - __unused UIView *_leftAccessoryView;/* unused */ - __unused UIView *_rightAccessoryView;/* unused */ - __weak id _delegate; - BOOL _dismissesAutomatically; - BOOL _anchoredToAnnotation; -} - -@synthesize representedObject = _representedObject; -@synthesize leftAccessoryView = _leftAccessoryView;/* unused */ -@synthesize rightAccessoryView = _rightAccessoryView;/* unused */ -@synthesize delegate = _delegate; -@synthesize anchoredToAnnotation = _anchoredToAnnotation; -@synthesize dismissesAutomatically = _dismissesAutomatically; - -- (instancetype)init -{ - if (self = [super init]) { - // prevent tap from bubbling up to it's superview - UITapGestureRecognizer *captureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil]; - [self addGestureRecognizer:captureTap]; - } - return self; -} - -// https://github.com/mapbox/mapbox-gl-native/issues/9228 -- (void)setCenter:(CGPoint)center { - center.y = center.y - CGRectGetMidY(self.bounds); - [super setCenter:center]; -} - -- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view constrainedToRect:(CGRect)constrainedRect animated:(BOOL)animated; -{ - // we want to attach to our parents parent to be on the same zPosition stack, so the callout will appear over other custom views - [view.superview addSubview:self]; - - // adjust frame - double centerX = rect.origin.x + (rect.size.width / 2); - CGPoint center = CGPointMake(centerX, rect.origin.y); - [self setCenter:center]; -} - -- (void)dismissCalloutAnimated:(BOOL)animated -{ - [self removeFromSuperview]; -} - -- (BOOL)dismissesAutomatically { - return NO; -} - -- (BOOL)isAnchoredToAnnotation { - return YES; -} - -- (void)update -{ - [self setCenter:self.center]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLCalloutManager.h b/ios/RCTMGL/RCTMGLCalloutManager.h deleted file mode 100644 index f2dbbecbc9..0000000000 --- a/ios/RCTMGL/RCTMGLCalloutManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLCalloutViewManager.h -// RCTMGL -// -// Created by Nick Italiano on 10/13/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLCalloutManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLCalloutManager.m b/ios/RCTMGL/RCTMGLCalloutManager.m deleted file mode 100644 index 4be9a0e9ef..0000000000 --- a/ios/RCTMGL/RCTMGLCalloutManager.m +++ /dev/null @@ -1,21 +0,0 @@ -// -// RCTMGLCalloutViewManager.m -// RCTMGL -// -// Created by Nick Italiano on 10/13/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLCalloutManager.h" -#import "RCTMGLCallout.h" - -@implementation RCTMGLCalloutManager - -RCT_EXPORT_MODULE() - -- (UIView *)view -{ - return [[RCTMGLCallout alloc] init]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLCamera.h b/ios/RCTMGL/RCTMGLCamera.h deleted file mode 100644 index 8fb6c8ce31..0000000000 --- a/ios/RCTMGL/RCTMGLCamera.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// RCTMGLCamera.h -// RCTMGL -// -// Created by Nick Italiano on 6/22/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// -#import -#import -#import "RCTMGLMapView.h" - -@class RCTMGLMapView; - -@interface RCTMGLCamera : UIView - -@property (nonatomic, strong) NSDictionary *stop; -@property (nonatomic, strong) NSDictionary *defaultStop; -@property (nonatomic, strong) RCTMGLMapView *map; - -@property (nonatomic, copy) NSNumber *animationDuration; -@property (nonatomic, copy) NSString *animationMode; - -@property (nonatomic, assign) BOOL followUserLocation; -@property (nonatomic, copy) NSString *followUserMode; -@property (nonatomic, copy) NSNumber *followZoomLevel; -@property (nonatomic, copy) NSNumber *followPitch; -@property (nonatomic, copy) NSNumber *followHeading; - -@property (nonatomic, copy) NSNumber *maxZoomLevel; -@property (nonatomic, copy) NSNumber *minZoomLevel; - -@property (nonatomic, copy) NSString *maxBounds; - -@property (nonatomic, copy) NSString *alignment; -@property (nonatomic, copy, readonly) NSNumber *cameraAnimationMode; - -@property (nonatomic, copy) RCTBubblingEventBlock onUserTrackingModeChange; - -@end diff --git a/ios/RCTMGL/RCTMGLCamera.m b/ios/RCTMGL/RCTMGLCamera.m deleted file mode 100644 index ddf3d01279..0000000000 --- a/ios/RCTMGL/RCTMGLCamera.m +++ /dev/null @@ -1,258 +0,0 @@ -// -// RCTMGLCamera.m -// RCTMGL -// -// Created by Nick Italiano on 6/22/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLCamera.h" -#import "CameraStop.h" -#import "CameraUpdateQueue.h" -#import "RCTMGLLocation.h" -#import "RCTMGLUtils.h" -#import "RCTMGLLocationManager.h" -#import "RCTMGLEvent.h" -#import "RCTMGLEventTypes.h" -#import "CameraMode.h" - -@implementation RCTMGLCamera -{ - CameraUpdateQueue *cameraUpdateQueue; - RCTMGLCamera *followCamera; -} - -- (instancetype)init -{ - if (self = [super init]) { - cameraUpdateQueue = [[CameraUpdateQueue alloc] init]; - } - return self; -} - -- (void)dealloc { - if (_map) { - _map.reactCamera = nil; - } -} - -- (void)setMaxZoomLevel:(NSNumber *)maxZoomLevel { - _maxZoomLevel = maxZoomLevel; - [self _updateMinMaxZoomLevel]; -} - -- (void)setMinZoomLevel:(NSNumber *)minZoomLevel { - _minZoomLevel = minZoomLevel; - [self _updateMinMaxZoomLevel]; -} - -- (void)setMaxBounds:(NSString *)maxBounds { - _maxBounds = maxBounds; - [self _updateMaxBounds]; -} - -- (void)setDefaultStop:(NSDictionary *)stop -{ - _defaultStop = stop; -} - -- (void)setStop:(NSDictionary *)stop -{ - _stop = stop; - - [self _updateCamera]; -} - -- (void)setMap:(RCTMGLMapView *)map -{ - if (_map != nil) { - _map.reactCamera = nil; - } - _map = map; - _map.reactCamera = self; - - [self _setInitialCamera]; - [self _updateMinMaxZoomLevel]; - [self _updateMaxBounds]; - [self _updateCamera]; -} - -- (void)setFollowUserLocation:(BOOL)followUserLocation -{ - _followUserLocation = followUserLocation; - [self _updateCameraFromTrackingMode]; -} - -- (void)setFollowUserMode:(NSString *)followUserMode -{ - _followUserMode = followUserMode; - [self _updateCameraFromTrackingMode]; -} - -- (void)setFollowPitch:(NSNumber *)followPitch -{ - _followPitch = followPitch; - [self _updateCameraFromTrackingMode]; -} - -- (void)setFollowZoomLevel:(NSNumber *)followZoomLevel -{ - _followZoomLevel = followZoomLevel; - [self _updateCameraFromTrackingMode]; -} - -- (void)setFollowHeading:(NSNumber *)followHeading -{ - _followHeading = followHeading; - [self _updateCameraFromTrackingMode]; -} - -- (void)_updateCameraFromJavascript -{ - if (_stop == nil) { - return; - } - - if (_followUserLocation) { - return; - } - - if (_map != nil && _map.userTrackingMode != MGLUserTrackingModeNone) { - _map.userTrackingMode = MGLUserTrackingModeNone; - } - if (_stop[@"stops"]) { - NSArray* stops = _stop[@"stops"]; - for (NSDictionary* stop in stops) { - [cameraUpdateQueue enqueue:[CameraStop fromDictionary:stop]]; - } - } else { - [cameraUpdateQueue enqueue:[CameraStop fromDictionary:_stop]]; - } - [cameraUpdateQueue execute:_map]; -} - -- (void)_setInitialCamera -{ - if (! _defaultStop) { - return; - } - - CameraStop* stop = [CameraStop fromDictionary:_defaultStop]; - stop.duration = 0; - stop.mode = [NSNumber numberWithInt:RCT_MAPBOX_CAMERA_MODE_NONE]; - CameraUpdateItem *item = [[CameraUpdateItem alloc] init]; - item.cameraStop = stop; - [item execute:_map withCompletionHandler:^{ }]; -} - -- (void)_updateCamera -{ - if (_map != nil) { - if (_followUserLocation) { - [self _updateCameraFromTrackingMode]; - } else { - [self _updateCameraFromJavascript]; - } - } -} - -- (void)_updateMinMaxZoomLevel -{ - if (_map != nil) { - if (_maxZoomLevel) { - _map.maximumZoomLevel = [_maxZoomLevel doubleValue]; - } - if (_minZoomLevel) { - _map.minimumZoomLevel = [_minZoomLevel doubleValue]; - } - } -} - -- (void)_updateMaxBounds -{ - if (_map != nil) { - if (_maxBounds) { - _map.maxBounds = [RCTMGLUtils fromFeatureCollection:_maxBounds]; - } - } -} - -- (void)_updateCameraFromTrackingMode -{ - if (_map == nil) { - return; - } - if (!_followUserLocation) { - _map.userTrackingMode = MGLUserTrackingModeNone; - return; - } - - if (_map.userTrackingMode != [self _userTrackingMode]) { - _map.showsUserLocation = [self _userTrackingMode] != MGLUserTrackingModeNone; - _map.userTrackingMode = [self _userTrackingMode]; - } - - MGLMapCamera *camera = _map.camera; - if (_followPitch != nil && [_followPitch floatValue] >= 0.0) { - camera.pitch = [_followPitch floatValue]; - } else if (_stop != nil && _stop[@"pitch"] != nil) { - camera.pitch = [_stop[@"pitch"] floatValue]; - } - - if ([self _userTrackingMode] != MGLUserTrackingModeFollowWithCourse && [self _userTrackingMode] != MGLUserTrackingModeFollowWithHeading) { - if (_followHeading != nil && [_followHeading floatValue] >= 0.0) { - camera.heading = [_followHeading floatValue]; - } else if (_stop != nil && _stop[@"heading"] != nil) { - camera.heading = [_stop[@"heading"] floatValue]; - } - } - - if (_followZoomLevel != nil && [_followZoomLevel doubleValue] >= 0.0) { - camera.altitude = [_map altitudeFromZoom:[_followZoomLevel doubleValue]]; - } - - [_map setCamera:camera animated:YES]; -} - -- (NSUInteger)_userTrackingMode -{ - if ([_followUserMode isEqualToString:@"compass"]) { - return MGLUserTrackingModeFollowWithHeading; - } else if ([_followUserMode isEqualToString:@"course"]) { - return MGLUserTrackingModeFollowWithCourse; - } else if (_followUserLocation) { - return MGLUserTrackingModeFollow; - } else { - return MGLUserTrackingModeNone; - } -} - -- (NSString*)_trackingModeToString:(MGLUserTrackingMode) mode { - switch (mode) { - case MGLUserTrackingModeFollowWithHeading: - return @"compass"; - case MGLUserTrackingModeFollowWithCourse: - return @"course"; - case MGLUserTrackingModeFollow: - return @"normal"; - case MGLUserTrackingModeNone: - return [NSNull null]; - } -} - -- (void)initialLayout -{ - [self _setInitialCamera]; - [self _updateCamera]; -} - -- (void)didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated -{ - NSDictionary *payload = @{ @"followUserMode": [self _trackingModeToString: mode], @"followUserLocation": @((BOOL)(mode != MGLUserTrackingModeNone)) }; - RCTMGLEvent *event = [RCTMGLEvent makeEvent:RCT_MAPBOX_USER_TRACKING_MODE_CHANGE withPayload:payload]; - if (_onUserTrackingModeChange) { - _onUserTrackingModeChange([event toJSON]); - } -} - -@end diff --git a/ios/RCTMGL/RCTMGLCamera.swift b/ios/RCTMGL/RCTMGLCamera.swift new file mode 100644 index 0000000000..219d99df54 --- /dev/null +++ b/ios/RCTMGL/RCTMGLCamera.swift @@ -0,0 +1,3 @@ +class RCTMGLCamera : UIView { + +} diff --git a/ios/RCTMGL/RCTMGLCameraManager.h b/ios/RCTMGL/RCTMGLCameraManager.h deleted file mode 100644 index 8b9ef9a01c..0000000000 --- a/ios/RCTMGL/RCTMGLCameraManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLCameraManager.h -// RCTMGL -// -// Created by Nick Italiano on 6/22/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLCameraManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLCameraManager.m b/ios/RCTMGL/RCTMGLCameraManager.m index cbfc22c8ec..1d69b92c4c 100644 --- a/ios/RCTMGL/RCTMGLCameraManager.m +++ b/ios/RCTMGL/RCTMGLCameraManager.m @@ -1,52 +1,4 @@ -// -// RCTMGLCameraManager.m -// RCTMGL -// -// Created by Nick Italiano on 6/22/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLCameraManager.h" -#import "RCTMGLCamera.h" - -@implementation RCTMGLCameraManager - -RCT_EXPORT_MODULE(RCTMGLCamera) - -#pragma - View Properties - -RCT_EXPORT_VIEW_PROPERTY(stop, NSDictionary) - -RCT_EXPORT_VIEW_PROPERTY(animationDuration, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(animationMode, NSString) - -RCT_EXPORT_VIEW_PROPERTY(followUserLocation, BOOL) -RCT_EXPORT_VIEW_PROPERTY(followUserMode, NSString) -RCT_EXPORT_VIEW_PROPERTY(followZoomLevel, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(followPitch, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(followHeading, NSNumber) - -RCT_EXPORT_VIEW_PROPERTY(alignment, NSString) - -RCT_EXPORT_VIEW_PROPERTY(maxBounds, NSString) - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber) - -RCT_EXPORT_VIEW_PROPERTY(onUserTrackingModeChange, RCTBubblingEventBlock) - -RCT_EXPORT_VIEW_PROPERTY(defaultStop, NSDictionary) - -#pragma Methods - -- (BOOL)requiresMainQueueSetup -{ - return YES; -} - -- (UIView *)view -{ - return [[RCTMGLCamera alloc] init]; -} +#import "React/RCTBridgeModule.h" +@interface RCT_EXTERN_MODULE(RCTMGLCameraManager, NSObject) @end diff --git a/ios/RCTMGL/RCTMGLCameraManager.swift b/ios/RCTMGL/RCTMGLCameraManager.swift new file mode 100644 index 0000000000..5d22513f2f --- /dev/null +++ b/ios/RCTMGL/RCTMGLCameraManager.swift @@ -0,0 +1,17 @@ +import Foundation +import MapboxMaps + +@objc(RCTMGLCameraManager) +class RCTMGLCameraManager : RCTViewManager { + @objc + override static func requiresMainQueueSetup() -> Bool { + return true + } + + @objc + override func constantsToExport() -> [AnyHashable: Any]! { + return [ + "foo": "bar" + ]; + } +} diff --git a/ios/RCTMGL/RCTMGLCircleLayer.h b/ios/RCTMGL/RCTMGLCircleLayer.h deleted file mode 100644 index 3bcc9bb484..0000000000 --- a/ios/RCTMGL/RCTMGLCircleLayer.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLCircleLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLVectorLayer.h" - -@interface RCTMGLCircleLayer : RCTMGLVectorLayer - -@end diff --git a/ios/RCTMGL/RCTMGLCircleLayer.m b/ios/RCTMGL/RCTMGLCircleLayer.m deleted file mode 100644 index 055bf47e59..0000000000 --- a/ios/RCTMGL/RCTMGLCircleLayer.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// RCTMGLCircleLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLCircleLayer.h" -#import "RCTMGLStyle.h" - -#import - -@implementation RCTMGLCircleLayer - -- (MGLCircleStyleLayer*)makeLayer:(MGLStyle*)style -{ - MGLSource *source = [self layerWithSourceIDInStyle:style]; - if (source == nil) { return nil; } - MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:self.id source:source]; - layer.sourceLayerIdentifier = self.sourceLayerID; - return layer; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style circleLayer:(MGLCircleStyleLayer*)self.styleLayer withReactStyle:self.reactStyle isValid:^{ - return [self isAddedToMap]; - }]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLCircleLayerManager.h b/ios/RCTMGL/RCTMGLCircleLayerManager.h deleted file mode 100644 index 09929d1904..0000000000 --- a/ios/RCTMGL/RCTMGLCircleLayerManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLCircleLayerManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLCircleLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLCircleLayerManager.m b/ios/RCTMGL/RCTMGLCircleLayerManager.m deleted file mode 100644 index b8e6b5abf2..0000000000 --- a/ios/RCTMGL/RCTMGLCircleLayerManager.m +++ /dev/null @@ -1,39 +0,0 @@ -// -// RCTMGLCircleLayerManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLCircleLayerManager.h" -#import "RCTMGLCircleLayer.h" - -@implementation RCTMGLCircleLayerManager - -RCT_EXPORT_MODULE() - -// circle layer props -RCT_EXPORT_VIEW_PROPERTY(sourceLayerID, NSString); - -// standard layer props -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); -RCT_EXPORT_VIEW_PROPERTY(filter, NSArray); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLCircleLayer *layer = [RCTMGLCircleLayer new]; - layer.bridge = self.bridge; - return layer; -} - -@end diff --git a/ios/RCTMGL/RCTMGLEvent.h b/ios/RCTMGL/RCTMGLEvent.h deleted file mode 100644 index 3433558b14..0000000000 --- a/ios/RCTMGL/RCTMGLEvent.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// RCTMGLEvent.h -// RCTMGL -// -// Created by Nick Italiano on 8/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLEventProtocol.h" - -@interface RCTMGLEvent : NSObject - -@property (nonatomic, copy) NSString *type; -@property (nonatomic, strong) NSDictionary *payload; -@property (nonatomic, readonly) NSTimeInterval timestamp; - -+ (RCTMGLEvent*)makeEvent:(NSString*)eventType; -+ (RCTMGLEvent*)makeEvent:(NSString*)eventType withPayload:(NSDictionary*)payload; - -@end diff --git a/ios/RCTMGL/RCTMGLEvent.m b/ios/RCTMGL/RCTMGLEvent.m deleted file mode 100644 index 662c92713c..0000000000 --- a/ios/RCTMGL/RCTMGLEvent.m +++ /dev/null @@ -1,47 +0,0 @@ -// -// RCTMGLEvent.m -// RCTMGL -// -// Created by Nick Italiano on 8/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLEvent.h" - -@implementation RCTMGLEvent - -- (instancetype)init -{ - if (self = [super init]) { - _timestamp = [[NSDate date] timeIntervalSince1970]; - } - return self; -} - -- (NSDictionary*)payload -{ - if (_payload == nil) { - return @{}; - } - return _payload; -} - -- (NSDictionary*)toJSON -{ - return @{ @"type": self.type, @"payload": self.payload }; -} - -+ (RCTMGLEvent*)makeEvent:(NSString*)type -{ - return [RCTMGLEvent makeEvent:type withPayload:@{}]; -} - -+ (RCTMGLEvent*)makeEvent:(NSString*)type withPayload:(NSDictionary*)payload -{ - RCTMGLEvent *event = [[RCTMGLEvent alloc] init]; - event.type = type; - event.payload = payload; - return event; -} - -@end diff --git a/ios/RCTMGL/RCTMGLEventProtocol.h b/ios/RCTMGL/RCTMGLEventProtocol.h deleted file mode 100644 index d6f7c7792f..0000000000 --- a/ios/RCTMGL/RCTMGLEventProtocol.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// RCTMGLEvent.h -// RCTMGL -// -// Created by Nick Italiano on 8/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -@protocol RCTMGLEventProtocol - -@property (nonatomic, copy) NSString *type; -@property (nonatomic, strong) NSDictionary *payload; - -- (NSDictionary*)toJSON; - -@end diff --git a/ios/RCTMGL/RCTMGLEventTypes.h b/ios/RCTMGL/RCTMGLEventTypes.h deleted file mode 100644 index 81d463b9aa..0000000000 --- a/ios/RCTMGL/RCTMGLEventTypes.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// RCTMGLEventTypes.h -// RCTMGL -// -// Created by Nick Italiano on 8/27/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import - -@interface RCTMGLEventTypes : NSObject - -extern NSString *const RCT_MAPBOX_EVENT_TAP; -extern NSString *const RCT_MAPBOX_EVENT_LONGPRESS; - -extern NSString *const RCT_MAPBOX_USER_LOCATION_UPDATE; -extern NSString *const RCT_MAPBOX_USER_TRACKING_MODE_CHANGE; - -extern NSString *const RCT_MAPBOX_REGION_WILL_CHANGE_EVENT; -extern NSString *const RCT_MAPBOX_REGION_IS_CHANGING; -extern NSString *const RCT_MAPBOX_REGION_DID_CHANGE; - -extern NSString *const RCT_MAPBOX_WILL_START_LOADING_MAP; -extern NSString *const RCT_MAPBOX_DID_FINISH_LOADING_MAP; -extern NSString *const RCT_MAPBOX_DID_FAIL_LOADING_MAP; - -extern NSString *const RCT_MAPBOX_WILL_START_RENDERING_FRAME; -extern NSString *const RCT_MAPBOX_DID_FINSIH_RENDERING_FRAME; -extern NSString *const RCT_MAPBOX_DID_FINISH_RENDERING_FRAME_FULLY; - -extern NSString *const RCT_MAPBOX_WILL_START_RENDERING_MAP; -extern NSString *const RCT_MAPBOX_DID_FINISH_RENDERING_MAP; -extern NSString *const RCT_MAPBOX_DID_FINISH_RENDERING_MAP_FULLY; - -extern NSString *const RCT_MAPBOX_DID_FINISH_LOADING_STYLE; - -extern NSString *const RCT_MAPBOX_ANNOTATION_TAP; - -extern NSString *const RCT_MAPBOX_OFFLINE_PROGRESS; -extern NSString *const RCT_MAPBOX_OFFLINE_ERROR; -extern NSString *const RCT_MAPBOX_OFFLINE_TILE_LIMIT; - -extern NSString *const RCT_MAPBOX_SHAPE_SOURCE_LAYER_PRESS; -extern NSString *const RCT_MAPBOX_VECTOR_SOURCE_LAYER_PRESS; - -extern NSString *const RCT_MAPBOX_USER_LOCATION_UPDATE; - -extern NSString *const RCT_MAPBOX_IMAGES_MISSING_IMAGE; - -@end diff --git a/ios/RCTMGL/RCTMGLEventTypes.m b/ios/RCTMGL/RCTMGLEventTypes.m deleted file mode 100644 index cc48538b2e..0000000000 --- a/ios/RCTMGL/RCTMGLEventTypes.m +++ /dev/null @@ -1,49 +0,0 @@ -// -// RCTMGLEventTypes.m -// RCTMGL -// -// Created by Nick Italiano on 8/27/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLEventTypes.h" - -@implementation RCTMGLEventTypes - -NSString *const RCT_MAPBOX_EVENT_TAP = @"press"; -NSString *const RCT_MAPBOX_EVENT_LONGPRESS = @"longpress"; - -NSString *const RCT_MAPBOX_USER_TRACKING_MODE_CHANGE = @"usertrackingmodechange"; - -NSString *const RCT_MAPBOX_REGION_WILL_CHANGE_EVENT = @"regionwillchange"; -NSString *const RCT_MAPBOX_REGION_IS_CHANGING = @"regionischanging"; -NSString *const RCT_MAPBOX_REGION_DID_CHANGE = @"regiondidchange"; - -NSString *const RCT_MAPBOX_WILL_START_LOADING_MAP = @"willstartloadingmap"; -NSString *const RCT_MAPBOX_DID_FINISH_LOADING_MAP = @"didfinishloadingmap"; -NSString *const RCT_MAPBOX_DID_FAIL_LOADING_MAP = @"didfailoadingmap"; - -NSString *const RCT_MAPBOX_WILL_START_RENDERING_FRAME = @"willstartrenderingframe"; -NSString *const RCT_MAPBOX_DID_FINSIH_RENDERING_FRAME = @"didfinishrenderingframe"; -NSString *const RCT_MAPBOX_DID_FINISH_RENDERING_FRAME_FULLY = @"didfinishrenderingframefully"; - -NSString *const RCT_MAPBOX_WILL_START_RENDERING_MAP = @"willstartrenderingmap"; -NSString *const RCT_MAPBOX_DID_FINISH_RENDERING_MAP = @"didfinishrenderingmap"; -NSString *const RCT_MAPBOX_DID_FINISH_RENDERING_MAP_FULLY = @"didfinishrenderingmapfully"; - -NSString *const RCT_MAPBOX_DID_FINISH_LOADING_STYLE = @"didfinishloadingstyle"; - -NSString *const RCT_MAPBOX_ANNOTATION_TAP = @"annotationtap"; - -NSString *const RCT_MAPBOX_OFFLINE_PROGRESS = @"offlinestatus"; -NSString *const RCT_MAPBOX_OFFLINE_ERROR = @"offlineerror"; -NSString *const RCT_MAPBOX_OFFLINE_TILE_LIMIT = @"offlinetilelimit"; - -NSString *const RCT_MAPBOX_SHAPE_SOURCE_LAYER_PRESS = @"shapesourcelayerpress"; -NSString *const RCT_MAPBOX_VECTOR_SOURCE_LAYER_PRESS = @"vectorsourcelayerpress"; - -NSString *const RCT_MAPBOX_IMAGES_MISSING_IMAGE = @"imagesmissingimage"; - -NSString *const RCT_MAPBOX_USER_LOCATION_UPDATE = @"MapboxUserLocationUpdate"; - -@end diff --git a/ios/RCTMGL/RCTMGLFillExtrusionLayer.h b/ios/RCTMGL/RCTMGLFillExtrusionLayer.h deleted file mode 100644 index 90e8821af5..0000000000 --- a/ios/RCTMGL/RCTMGLFillExtrusionLayer.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// RCTMGLFillExtrusionLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/15/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLVectorLayer.h" -@import Mapbox; - -@interface RCTMGLFillExtrusionLayer : RCTMGLVectorLayer - -@end diff --git a/ios/RCTMGL/RCTMGLFillExtrusionLayer.m b/ios/RCTMGL/RCTMGLFillExtrusionLayer.m deleted file mode 100644 index d152e67bb7..0000000000 --- a/ios/RCTMGL/RCTMGLFillExtrusionLayer.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// RCTMGLFillExtrusionLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/15/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLFillExtrusionLayer.h" -#import "RCTMGLStyle.h" -#import - -@implementation RCTMGLFillExtrusionLayer - -- (MGLFillExtrusionStyleLayer*)makeLayer:(MGLStyle*)style -{ - MGLSource *source = [self layerWithSourceIDInStyle:style]; - if (source == nil) { return nil; } - MGLFillExtrusionStyleLayer *layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:self.id source:source]; - layer.sourceLayerIdentifier = self.sourceLayerID; - return layer; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style fillExtrusionLayer:(MGLFillExtrusionStyleLayer*)self.styleLayer withReactStyle:self.reactStyle isValid:^{ return [self isAddedToMap]; - }]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLFillExtrusionLayerManager.h b/ios/RCTMGL/RCTMGLFillExtrusionLayerManager.h deleted file mode 100644 index 7da8b635bf..0000000000 --- a/ios/RCTMGL/RCTMGLFillExtrusionLayerManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLFillExtrusionLayerManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/15/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLFillExtrusionLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLFillExtrusionLayerManager.m b/ios/RCTMGL/RCTMGLFillExtrusionLayerManager.m deleted file mode 100644 index 927f65ee02..0000000000 --- a/ios/RCTMGL/RCTMGLFillExtrusionLayerManager.m +++ /dev/null @@ -1,39 +0,0 @@ -// -// RCTMGLFillExtrusionLayerManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/15/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLFillExtrusionLayerManager.h" -#import "RCTMGLFillExtrusionLayer.h" - -@implementation RCTMGLFillExtrusionLayerManager - -RCT_EXPORT_MODULE() - -// fill extrusion layer props -RCT_EXPORT_VIEW_PROPERTY(sourceLayerID, NSString); - -// standard layer props -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); -RCT_EXPORT_VIEW_PROPERTY(filter, NSArray); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLFillExtrusionLayer *layer = [RCTMGLFillExtrusionLayer new]; - layer.bridge = self.bridge; - return layer; -} - -@end diff --git a/ios/RCTMGL/RCTMGLFillLayer.h b/ios/RCTMGL/RCTMGLFillLayer.h deleted file mode 100644 index d00fec4cd4..0000000000 --- a/ios/RCTMGL/RCTMGLFillLayer.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// RCTMGLFillLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLVectorLayer.h" -@import Mapbox; - -@interface RCTMGLFillLayer : RCTMGLVectorLayer - -@end diff --git a/ios/RCTMGL/RCTMGLFillLayer.m b/ios/RCTMGL/RCTMGLFillLayer.m deleted file mode 100644 index 985b5a2377..0000000000 --- a/ios/RCTMGL/RCTMGLFillLayer.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// RCTMGLFillLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLFillLayer.h" -#import "RCTMGLStyle.h" -#import - -@implementation RCTMGLFillLayer - -- (MGLStyleLayer*)makeLayer:(MGLStyle*)style -{ - MGLSource *source = [self layerWithSourceIDInStyle:style]; - if (source == nil) { return nil; } - MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:self.id source:source]; - layer.sourceLayerIdentifier = self.sourceLayerID; - return layer; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style fillLayer:(MGLFillStyleLayer*)self.styleLayer withReactStyle:self.reactStyle isValid:^{ - return [self isAddedToMap]; - }]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLFillLayerManager.h b/ios/RCTMGL/RCTMGLFillLayerManager.h deleted file mode 100644 index 937bd26639..0000000000 --- a/ios/RCTMGL/RCTMGLFillLayerManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLFillLayerManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLFillLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLFillLayerManager.m b/ios/RCTMGL/RCTMGLFillLayerManager.m deleted file mode 100644 index 84556a47ae..0000000000 --- a/ios/RCTMGL/RCTMGLFillLayerManager.m +++ /dev/null @@ -1,37 +0,0 @@ -// -// RCTMGLFillLayerManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLFillLayerManager.h" -#import "RCTMGLFillLayer.h" - -@implementation RCTMGLFillLayerManager - -RCT_EXPORT_MODULE(); - -RCT_EXPORT_VIEW_PROPERTY(sourceLayerID, NSString); - -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); -RCT_EXPORT_VIEW_PROPERTY(filter, NSArray); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLFillLayer *layer = [RCTMGLFillLayer new]; - layer.bridge = self.bridge; - return layer; -} - -@end diff --git a/ios/RCTMGL/RCTMGLHeatmapLayer.h b/ios/RCTMGL/RCTMGLHeatmapLayer.h deleted file mode 100644 index b2dec1f718..0000000000 --- a/ios/RCTMGL/RCTMGLHeatmapLayer.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// RCTMGLHeatmapLayer.h -// RCTMGL -// -// Created by Dheeraj Yalamanchili on 6/8/19. -// - -#import "RCTMGLVectorLayer.h" - -@interface RCTMGLHeatmapLayer : RCTMGLVectorLayer - -@end diff --git a/ios/RCTMGL/RCTMGLHeatmapLayer.m b/ios/RCTMGL/RCTMGLHeatmapLayer.m deleted file mode 100644 index 9009205eb1..0000000000 --- a/ios/RCTMGL/RCTMGLHeatmapLayer.m +++ /dev/null @@ -1,30 +0,0 @@ -// -// RCTMGLHeatmapLayer.m -// RCTMGL -// -// Created by Dheeraj Yalamanchili on 6/8/2019 - -#import "RCTMGLHeatmapLayer.h" -#import "RCTMGLStyle.h" - -@implementation RCTMGLHeatmapLayer - -- (MGLHeatmapStyleLayer*)makeLayer:(MGLStyle*)style -{ - MGLSource *source = [self layerWithSourceIDInStyle:style]; - if (source == nil) { return nil; } - MGLHeatmapStyleLayer *layer = [[MGLHeatmapStyleLayer alloc] initWithIdentifier:self.id source:source]; - layer.sourceLayerIdentifier = self.sourceLayerID; - return layer; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style heatmapLayer:(MGLHeatmapStyleLayer *)self.styleLayer withReactStyle:self.reactStyle isValid:^{ - return [self isAddedToMap]; - }]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLHeatmapLayerManager.h b/ios/RCTMGL/RCTMGLHeatmapLayerManager.h deleted file mode 100644 index 1ad7769694..0000000000 --- a/ios/RCTMGL/RCTMGLHeatmapLayerManager.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// RCTMGLHeatmapLayerManager.h -// RCTMGL -// -// Created by Dheeraj Yalamanchili on 6/8/19. -// - -#import "ViewManager.h" - -@interface RCTMGLHeatmapLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLHeatmapLayerManager.m b/ios/RCTMGL/RCTMGLHeatmapLayerManager.m deleted file mode 100644 index 17ef6d1f2f..0000000000 --- a/ios/RCTMGL/RCTMGLHeatmapLayerManager.m +++ /dev/null @@ -1,38 +0,0 @@ -// -// RCTMGLHeatmapLayerManager.m -// RCTMGL -// -// Created by Dheeraj Yalamanchili on 6/8/19. -// - -#import "RCTMGLHeatmapLayerManager.h" -#import "RCTMGLHeatmapLayer.h" - -@implementation RCTMGLHeatmapLayerManager - -RCT_EXPORT_MODULE() - -// Heatmap layer props -RCT_EXPORT_VIEW_PROPERTY(sourceLayerID, NSString); - -// standard layer props -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); -RCT_EXPORT_VIEW_PROPERTY(filter, NSArray); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLHeatmapLayer *layer = [RCTMGLHeatmapLayer new]; - layer.bridge = self.bridge; - return layer; -} - -@end diff --git a/ios/RCTMGL/RCTMGLImageQueue.h b/ios/RCTMGL/RCTMGLImageQueue.h deleted file mode 100644 index 5a1bb8e004..0000000000 --- a/ios/RCTMGL/RCTMGLImageQueue.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// RCTMGLImageQueue.h -// RCTMGL -// -// Created by Nick Italiano on 10/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import - -@interface RCTMGLImageQueue : NSObject - -+ (instancetype)sharedInstance; - -- (void)cancelAllOperations; -- (void)addImage:(NSString *)imageURL scale:(double)scale bridge:(RCTBridge *)bridge completionHandler:(RCTImageLoaderCompletionBlock)handler; - -@end diff --git a/ios/RCTMGL/RCTMGLImageQueue.m b/ios/RCTMGL/RCTMGLImageQueue.m deleted file mode 100644 index 47a58e71df..0000000000 --- a/ios/RCTMGL/RCTMGLImageQueue.m +++ /dev/null @@ -1,57 +0,0 @@ -// -// RCTMGLImageQueue.m -// RCTMGL -// -// Created by Nick Italiano on 10/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLImageQueue.h" -#import "RCTMGLImageQueueOperation.h" -#import "RCTMGLUtils.h" - -@implementation RCTMGLImageQueue -{ - NSOperationQueue *imageQueue; -} - -- (id)init -{ - if (self = [super init]) { - imageQueue = [[NSOperationQueue alloc] init]; - imageQueue.name = @"com.mapbox.rctmgl.DownloadImageQueue"; - } - return self; -} - -- (void)dealloc -{ - [self cancelAllOperations]; -} - -+ (instancetype)sharedInstance -{ - static RCTMGLImageQueue *sharedInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedInstance = [[RCTMGLImageQueue alloc] init]; - }); - return sharedInstance; -} - -- (void)cancelAllOperations -{ - [imageQueue cancelAllOperations]; -} - -- (void)addImage:(NSString *)imageURL scale:(double)scale bridge:(RCTBridge *)bridge completionHandler:(RCTImageLoaderCompletionBlock)handler -{ - RCTMGLImageQueueOperation *operation = [[RCTMGLImageQueueOperation alloc] init]; - operation.bridge = bridge; - operation.urlRequest = [RCTConvert NSURLRequest:imageURL]; - operation.completionHandler = handler; - operation.scale = scale; - [imageQueue addOperation:operation]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLImageQueueOperation.h b/ios/RCTMGL/RCTMGLImageQueueOperation.h deleted file mode 100644 index 6b30f30270..0000000000 --- a/ios/RCTMGL/RCTMGLImageQueueOperation.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// RCTMGLImageQueueOperation.h -// RCTMGL -// -// Created by Nick Italiano on 2/28/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// -#import - -@interface RCTMGLImageQueueOperation : NSBlockOperation - -@property (nonatomic, weak) RCTBridge *bridge; -@property (nonatomic, copy) RCTImageLoaderCompletionBlock completionHandler; -@property (nonatomic, copy) NSURLRequest *urlRequest; -@property (nonatomic) double scale; - -@end diff --git a/ios/RCTMGL/RCTMGLImageQueueOperation.m b/ios/RCTMGL/RCTMGLImageQueueOperation.m deleted file mode 100644 index 49029f7a0b..0000000000 --- a/ios/RCTMGL/RCTMGLImageQueueOperation.m +++ /dev/null @@ -1,138 +0,0 @@ -// -// RCTMGLImageQueueOperation.m -// RCTMGL -// -// Created by Nick Italiano on 2/28/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLImageQueueOperation.h" - - -typedef NS_ENUM(NSInteger, RCTMGLImageQueueOperationState) { - IOState_Initial, - IOState_CancelledDoNotExecute, - IOState_Executing, // cancellationBlock is set - IOState_Finished, - - /* Not sates, just selectors for only and except params */ - IOState_Filter_None, - IOState_Filter_All, -}; - -@interface RCTMGLImageQueueOperation() -@property (nonatomic) RCTMGLImageQueueOperationState state; -@end - -@implementation RCTMGLImageQueueOperation -{ - RCTImageLoaderCancellationBlock _cancellationBlock; - BOOL _cancelled; -} - -- (instancetype)init { - self = [super init]; - if (self) { - _state = IOState_Initial; - _cancelled = false; - } - return self; -} - -- (BOOL)isExecuting { - @synchronized (self) { - return self.state == IOState_Executing; - } -} - -- (BOOL)isFinished { - @synchronized (self) { - return (self.state == IOState_Finished || self.state == IOState_CancelledDoNotExecute); - } -} - -- (BOOL)isCancelled { - @synchronized (self) { - return self.state == IOState_CancelledDoNotExecute; - } -} - -- (void)setCancellationBlock:(dispatch_block_t) block { - _cancellationBlock = block; -} - --(void)callCancellationBlock { - if (_cancellationBlock) { - _cancellationBlock(); - } -} - -- (RCTMGLImageQueueOperationState)setState:(RCTMGLImageQueueOperationState)newState only:(RCTMGLImageQueueOperationState)only except:(RCTMGLImageQueueOperationState) except -{ - RCTMGLImageQueueOperationState prevState = IOState_Filter_None; - [self willChangeValueForKey:@"isExecuting"]; - [self willChangeValueForKey:@"isFinished"]; - [self willChangeValueForKey:@"isCancelled"]; - - @synchronized (self) { - BOOL allowed = YES; - prevState = self.state; - if (! (only == IOState_Filter_All || prevState == only)) { - allowed = NO; - } - if (prevState == except) { - allowed = NO; - } - if (allowed) { - self.state = newState; - } - } - [self didChangeValueForKey:@"isExecuting"]; - [self didChangeValueForKey:@"isFinished"]; - [self didChangeValueForKey:@"isCancelled"]; - return prevState; -} - -- (RCTMGLImageQueueOperationState)setState:(RCTMGLImageQueueOperationState)newState only:(RCTMGLImageQueueOperationState)only -{ - return [self setState: newState only:only except:IOState_Filter_None]; -} - -- (RCTMGLImageQueueOperationState)setState:(RCTMGLImageQueueOperationState)newState except:(RCTMGLImageQueueOperationState)except -{ - return [self setState: newState only:IOState_Filter_All except:except]; -} - -- (void)start -{ - if (self.state == IOState_CancelledDoNotExecute) { - return; - } - __weak RCTMGLImageQueueOperation *weakSelf = self; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [weakSelf setCancellationBlock: [[weakSelf.bridge moduleForName:@"ImageLoader" lazilyLoadIfNecessary:YES] - loadImageWithURLRequest:weakSelf.urlRequest - size:CGSizeZero - scale:weakSelf.scale - clipped:YES - resizeMode:RCTResizeModeStretch - progressBlock:nil - partialLoadBlock:nil - completionBlock:^void (NSError *error, UIImage *image){ - weakSelf.completionHandler(error, image); - [weakSelf setState:IOState_Finished except:IOState_Finished]; - }]]; - if ([weakSelf setState:IOState_Executing only:IOState_Initial] == IOState_CancelledDoNotExecute) { - [weakSelf callCancellationBlock]; - } - }); -} - -- (void)cancel -{ - if ([self setState:IOState_CancelledDoNotExecute except:IOState_Finished] == IOState_Executing) { - [self callCancellationBlock]; - } -} - -@end diff --git a/ios/RCTMGL/RCTMGLImageSource.h b/ios/RCTMGL/RCTMGLImageSource.h deleted file mode 100644 index 47247d4d4c..0000000000 --- a/ios/RCTMGL/RCTMGLImageSource.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// RCTMGLImageSource.h -// RCTMGL -// -// Created by Nick Italiano on 11/29/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLSource.h" - -@interface RCTMGLImageSource : RCTMGLSource - -@property (nonatomic, copy) NSString *url; -@property (nonatomic, copy) NSArray *> *coordinates; - -@end diff --git a/ios/RCTMGL/RCTMGLImageSource.m b/ios/RCTMGL/RCTMGLImageSource.m deleted file mode 100644 index 817918b20c..0000000000 --- a/ios/RCTMGL/RCTMGLImageSource.m +++ /dev/null @@ -1,60 +0,0 @@ -// -// RCTMGLImageSource.m -// RCTMGL -// -// Created by Nick Italiano on 11/29/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLImageSource.h" -@import Mapbox; - -@implementation RCTMGLImageSource - -- (void)setUrl:(NSString *)url -{ - _url = url; - - if (self.source != nil) { - MGLImageSource *source = (MGLImageSource *)self.source; - source.URL = [NSURL URLWithString:_url]; - } -} - -- (void)setCoordinates:(NSArray *> *)coordinates -{ - _coordinates = coordinates; - if (self.source != nil) { - MGLImageSource *source = (MGLImageSource *)self.source; - source.coordinates = [self _makeCoordQuad]; - } -} - -- (nullable MGLSource *)makeSource -{ - NSURL *myURL; - - if ([[_url substringToIndex:4] isEqualToString:@"http"]) { - myURL = [NSURL URLWithString:_url]; - } - else - { - //Default consider it file url path - myURL = [NSURL fileURLWithPath:_url]; - } - - return [[MGLImageSource alloc] initWithIdentifier:self.id - coordinateQuad:[self _makeCoordQuad] - URL:myURL]; -} - -- (MGLCoordinateQuad)_makeCoordQuad -{ - CLLocationCoordinate2D topLeft = CLLocationCoordinate2DMake([self.coordinates[0][1] floatValue], [self.coordinates[0][0] floatValue]); - CLLocationCoordinate2D topRight = CLLocationCoordinate2DMake([self.coordinates[1][1] floatValue], [self.coordinates[1][0] floatValue]); - CLLocationCoordinate2D bottomRight = CLLocationCoordinate2DMake([self.coordinates[2][1] floatValue], [self.coordinates[2][0] floatValue]); - CLLocationCoordinate2D bottomLeft = CLLocationCoordinate2DMake([self.coordinates[3][1] floatValue], [self.coordinates[3][0] floatValue]); - return MGLCoordinateQuadMake(topLeft, bottomLeft, bottomRight, topRight); -} - -@end diff --git a/ios/RCTMGL/RCTMGLImageSourceManager.h b/ios/RCTMGL/RCTMGLImageSourceManager.h deleted file mode 100644 index 19f27153d1..0000000000 --- a/ios/RCTMGL/RCTMGLImageSourceManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLImageSourceManager.h -// RCTMGL -// -// Created by Nick Italiano on 11/29/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLImageSourceManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLImageSourceManager.m b/ios/RCTMGL/RCTMGLImageSourceManager.m deleted file mode 100644 index 4b0aa0db3b..0000000000 --- a/ios/RCTMGL/RCTMGLImageSourceManager.m +++ /dev/null @@ -1,25 +0,0 @@ -// -// RCTMGLImageSourceManager.m -// RCTMGL -// -// Created by Nick Italiano on 11/29/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLImageSourceManager.h" -#import "RCTMGLImageSource.h" - -@implementation RCTMGLImageSourceManager - -RCT_EXPORT_MODULE() - -RCT_EXPORT_VIEW_PROPERTY(id, NSString) -RCT_EXPORT_VIEW_PROPERTY(url, NSString) -RCT_EXPORT_VIEW_PROPERTY(coordinates, NSArray) - -- (UIView*)view -{ - return [RCTMGLImageSource new]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLImages.h b/ios/RCTMGL/RCTMGLImages.h deleted file mode 100644 index 3fecb2b4a2..0000000000 --- a/ios/RCTMGL/RCTMGLImages.h +++ /dev/null @@ -1,25 +0,0 @@ -#import -#import -#import - -@import Mapbox; - -@class RCTMGLMapView; - -@interface RCTMGLImages : UIView - -@property (nonatomic, weak) RCTBridge *bridge; - -@property (nonatomic, strong) RCTMGLMapView *map; - -@property (nonatomic, strong) NSDictionary *images; -@property (nonatomic, strong) NSArray *nativeImages; - -@property (nonatomic, copy) RCTBubblingEventBlock onImageMissing; -@property (nonatomic, assign) BOOL hasOnImageMissing; - -- (BOOL)addMissingImageToStyle:(NSString *)imageName; -- (void)sendImageMissingEvent:(NSString *)imageName; - -@end - diff --git a/ios/RCTMGL/RCTMGLImages.m b/ios/RCTMGL/RCTMGLImages.m deleted file mode 100644 index d0d42023dc..0000000000 --- a/ios/RCTMGL/RCTMGLImages.m +++ /dev/null @@ -1,126 +0,0 @@ -#import "RCTMGLImages.h" -#import "UIView+React.h" -#import "RCTMGLMapView.h" -#import "RCTMGLUtils.h" -#import "RCTMGLEvent.h" -#import "RCTMGLEventTypes.h" - - -@implementation RCTMGLImages : UIView - -static UIImage * _placeHolderImage; - -- (void)addToMap -{ - if (self.map.style == nil) { - return; - } - [self _addNativeImages:_nativeImages]; - [self _addRemoteImages:_images]; -} - -- (void)removeFromMap -{ - if (self.map.style == nil) { - return; - } - - [self _removeImages]; -} - -- (void)_removeImages -{ - if ([self _hasImages]) { - NSArray *imageNames = _images.allKeys; - - for (NSString *imageName in imageNames) { - [self.map.style removeImageForName:imageName]; - } - } - - if ([self _hasNativeImages]) { - for (NSString *imageName in _nativeImages) { - [self.map.style removeImageForName:imageName]; - } - } -} - --(BOOL)addMissingImageToStyle:(NSString *)imageName { - if (_nativeImages && [_nativeImages containsObject:imageName]) { - [self _addNativeImages:@[imageName]]; - return true; - } - - NSString *remoteImage = _images != nil ? [_images objectForKey:imageName] : nil; - if (remoteImage) { - [self _addRemoteImages:@{imageName: remoteImage}]; - return true; - } - return false; -} - -- (void) sendImageMissingEvent:(NSString *)imageName { - NSDictionary *payload = @{ @"imageKey": imageName }; - RCTMGLEvent *event = [RCTMGLEvent makeEvent:RCT_MAPBOX_IMAGES_MISSING_IMAGE withPayload:payload]; - if (_onImageMissing) { - _onImageMissing([event toJSON]); - } -} - -- (void)_addNativeImages:(NSArray*)nativeImages -{ - if (!nativeImages) return; - - for (NSString *imageName in nativeImages) { - // only add native images if they are not in the style yet (similar to [RCTMGLUtils fetchImages: style:]) - if (![self.map.style imageForName:imageName]) { - UIImage *image = [UIImage imageNamed:imageName]; - [self.map.style setImage:image forName:imageName]; - } - } -} - -- (void)_addRemoteImages:(NSDictionary*)remoteImages -{ - if (!remoteImages) return; - NSDictionary *missingImages = [NSMutableDictionary new]; - - // Add image placeholder for images that are not yet available in the style. This way - // we can load the images asynchronously and add the ShapeSource to the map without delay. - // The same is required when this ShapeSource is updated with new/added images and the - // data references them. In which case addMissingImageToStyle will take care of loading - // them in a similar way. - // - // See also: https://github.com/mapbox/mapbox-gl-native/pull/14253#issuecomment-478827792 - for (NSString *imageName in remoteImages.allKeys) { - if (![self.map.style imageForName:imageName]) { - [self.map.style setImage:[RCTMGLImages placeholderImage] forName:imageName]; - [missingImages setValue:_images[imageName] forKey:imageName]; - } - } - - if (missingImages.count > 0) { - // forceUpdate to ensure the placeholder images are updated - [RCTMGLUtils fetchImages:_bridge style:self.map.style objects:_images forceUpdate:true callback:^{ }]; - } -} - -- (BOOL)_hasImages -{ - return _images != nil && _images.count > 0; -} - -- (BOOL)_hasNativeImages -{ - return _nativeImages != nil && _nativeImages.count > 0; -} - -+ (UIImage *)placeholderImage { - if (_placeHolderImage) return _placeHolderImage; - UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, 0.0); - _placeHolderImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - return _placeHolderImage; -} - -@end diff --git a/ios/RCTMGL/RCTMGLImagesManager.h b/ios/RCTMGL/RCTMGLImagesManager.h deleted file mode 100644 index 0f52cd5578..0000000000 --- a/ios/RCTMGL/RCTMGLImagesManager.h +++ /dev/null @@ -1,5 +0,0 @@ -#import "ViewManager.h" - -@interface RCTMGLImagesManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLImagesManager.m b/ios/RCTMGL/RCTMGLImagesManager.m deleted file mode 100644 index aa20aa17d6..0000000000 --- a/ios/RCTMGL/RCTMGLImagesManager.m +++ /dev/null @@ -1,21 +0,0 @@ -#import "RCTMGLImagesManager.h" -#import "RCTMGLImages.h" - -@implementation RCTMGLImagesManager - -RCT_EXPORT_MODULE() - -RCT_EXPORT_VIEW_PROPERTY(id, NSString) -RCT_EXPORT_VIEW_PROPERTY(images, NSDictionary) -RCT_EXPORT_VIEW_PROPERTY(nativeImages, NSArray) - -RCT_REMAP_VIEW_PROPERTY(onImageMissing, onImageMissing, RCTBubblingEventBlock) - -- (UIView*)view -{ - RCTMGLImages *images = [RCTMGLImages new]; - images.bridge = self.bridge; - return images; -} - -@end diff --git a/ios/RCTMGL/RCTMGLLayer.h b/ios/RCTMGL/RCTMGLLayer.h deleted file mode 100644 index 1ede8a0f3f..0000000000 --- a/ios/RCTMGL/RCTMGLLayer.h +++ /dev/null @@ -1,52 +0,0 @@ -// -// BaseLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import - - -@class RCTMGLMapView; - -@import Mapbox; - -@interface RCTMGLLayer : UIView - -@property (nonatomic, weak, nullable) RCTBridge* bridge; - -@property (nonatomic, strong, nullable) MGLStyleLayer *styleLayer; -@property (nonatomic, strong, nullable) MGLStyle *style; -@property (nonatomic, weak, nullable) RCTMGLMapView* map; -@property (nonatomic, strong, nullable) NSDictionary *reactStyle; -@property (nonatomic, strong, nullable) NSArray *filter; - -@property (nonatomic, copy, nullable) NSString *id; -@property (nonatomic, copy, nullable) NSString *sourceID; - -@property (nonatomic, copy, nullable) NSString *aboveLayerID; -@property (nonatomic, copy, nullable) NSString *belowLayerID; -@property (nonatomic, copy, nullable) NSNumber *layerIndex; - -@property (nonatomic, copy, nullable) NSNumber *maxZoomLevel; -@property (nonatomic, copy, nullable) NSNumber *minZoomLevel; - -- (void)addToMap:(nonnull RCTMGLMapView*)map style:(nonnull MGLStyle*)style; -- (void)addedToMap; -- (void)removeFromMap:(nonnull MGLStyle*)style; -- (nullable T)makeLayer:(nonnull MGLStyle*)style; -- (void)addStyles; -- (void)insertAbove:(nonnull NSString*)layer; -- (void)insertBelow:(nonnull NSString*)layer; -- (void)insertAtIndex:(NSUInteger)index; -- (void)insertLayer; -- (void)setZoomBounds; - -- (BOOL)isAddedToMap; - -- (nullable MGLSource*)layerWithSourceIDInStyle:(nonnull MGLStyle*) style; - -@end diff --git a/ios/RCTMGL/RCTMGLLayer.m b/ios/RCTMGL/RCTMGLLayer.m deleted file mode 100644 index 78cd88184e..0000000000 --- a/ios/RCTMGL/RCTMGLLayer.m +++ /dev/null @@ -1,236 +0,0 @@ -// -// BaseLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLayer.h" -#import "RCTMGLSource.h" -#import "RCTMGLStyleValue.h" -#import "RCTMGLUtils.h" -#import "RCTMGLMapView.h" - -@implementation RCTMGLLayer - -- (void)setMinZoomLevel:(NSNumber*)minZoomLevel -{ - _minZoomLevel = minZoomLevel; - - if (_styleLayer != nil) { - _styleLayer.minimumZoomLevel = [_minZoomLevel doubleValue]; - } -} - -- (void)setMaxZoomLevel:(NSNumber*)maxZoomLevel -{ - _maxZoomLevel = maxZoomLevel; - - if (_styleLayer != nil) { - _styleLayer.maximumZoomLevel = [_maxZoomLevel doubleValue]; - } -} - -- (void)setAboveLayerID:(NSString *)aboveLayerID -{ - if (_aboveLayerID != nil && _aboveLayerID == aboveLayerID) { - return; - } - - _aboveLayerID = aboveLayerID; - if (_styleLayer != nil) { - [self removeFromMap:_style]; - [self insertAbove:aboveLayerID]; - } -} - -- (void)setBelowLayerID:(NSString *)belowLayerID -{ - if (_belowLayerID != nil && _belowLayerID == belowLayerID) { - return; - } - - _belowLayerID = belowLayerID; - if (_styleLayer != nil) { - [self removeFromMap:_style]; - [self insertBelow:_belowLayerID]; - } -} - -- (void)setLayerIndex:(NSNumber *)layerIndex -{ - if (_layerIndex != nil && _layerIndex == layerIndex) { - return; - } - - _layerIndex = layerIndex; - if (_styleLayer != nil) { - [self removeFromMap:_style]; - [self insertAtIndex:_layerIndex.unsignedIntegerValue]; - } -} - -- (void)setMap:(RCTMGLMapView *)map { - if (map == nil) { - [self removeFromMap:_map.style]; - _map = nil; - } else { - _map = map; - [self addToMap:map style:map.style]; - } -} - --(void)setReactStyle:(NSDictionary *)reactStyle -{ - _reactStyle = reactStyle; - - if (_styleLayer != nil) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self addStyles]; - }); - } -} - -- (void)addToMap:(RCTMGLMapView*) map style:(MGLStyle *)style -{ - if (style == nil) { - return; - } - _map = map; - _style = style; - if (_id == nil) { - RCTLogError(@"Cannot add a layer without id to the map: %@", self); - return; - } - MGLStyleLayer *existingLayer = [style layerWithIdentifier:_id]; - if (existingLayer != nil) { - _styleLayer = existingLayer; - } else { - _styleLayer = [self makeLayer:style]; - if (_styleLayer == nil) { - RCTLogError(@"Failed to make layer: %@", _id); - return; - } - [self insertLayer: map]; - } - - [self addStyles]; - [self addedToMap]; -} - -- (nullable MGLSource*)layerWithSourceIDInStyle:(nonnull MGLStyle*) style -{ - MGLSource* result = [style sourceWithIdentifier: self.sourceID]; - if (result == NULL) { - RCTLogError(@"Cannot find layer with id: %@ referenced by layer:%@", self.sourceID, _id); - } - return result; -} - -- (void)removeFromMap:(MGLStyle *)style -{ - if (_styleLayer != nil) { - [style removeLayer:_styleLayer]; - } - _style = nil; -} - -- (BOOL)isAddedToMap -{ - return (_style != nil); -} - -- (nullable MGLStyleLayer*)makeLayer:(MGLStyle*)style -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] - userInfo:nil]; -} - -- (void)addStyles -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] - userInfo:nil]; -} - -- (void)addedToMap -{ - // override if you want -} - -- (void)insertLayer: (RCTMGLMapView*) map -{ - if ([_style layerWithIdentifier:_id] != nil) { - return; // prevent layer from being added twice - } - - if (_aboveLayerID != nil) { - [self insertAbove:_aboveLayerID]; - } else if (_belowLayerID != nil) { - [self insertBelow:_belowLayerID]; - } else if (_layerIndex != nil) { - [self insertAtIndex:_layerIndex.unsignedIntegerValue]; - } else { - [_style addLayer:_styleLayer]; - [_map layerAdded:_styleLayer]; - } - - [self setZoomBounds]; -} - -- (void)setZoomBounds -{ - if (_maxZoomLevel != nil) { - _styleLayer.maximumZoomLevel = [_maxZoomLevel doubleValue]; - } - - if (_minZoomLevel != nil) { - _styleLayer.minimumZoomLevel = [_minZoomLevel doubleValue]; - } -} - --(void)insertAbove:(NSString*)aboveLayerIDs -{ - [_map waitForLayerWithID: aboveLayerIDs then:^void (MGLStyleLayer* layer) { - if (![self _hasInitialized]) { - return; - } - [self->_style insertLayer:self->_styleLayer aboveLayer:layer]; - [self->_map layerAdded:self->_styleLayer]; - }]; -} - --(void)insertBelow:(NSString*)belowLayerID -{ - [_map waitForLayerWithID: belowLayerID then:^void (MGLStyleLayer* layer) { - if (![self _hasInitialized]) { - return; - } - - [self->_style insertLayer:self->_styleLayer belowLayer:layer]; - [self->_map layerAdded:self->_styleLayer]; - }]; -} - --(void)insertAtIndex:(NSUInteger)index -{ - if (![self _hasInitialized]) { - return; - } - NSArray *layers = _style.layers; - if (index >= layers.count) { - RCTLogWarn(@"Layer index is greater than number of layers on map. Layer inserted at end of layer stack."); - index = layers.count - 1; - } - [_style insertLayer:self->_styleLayer atIndex:index]; - [_map layerAdded:self->_styleLayer]; -} - -- (BOOL)_hasInitialized -{ - return _style != nil && _styleLayer != nil; -} - -@end diff --git a/ios/RCTMGL/RCTMGLLight.h b/ios/RCTMGL/RCTMGLLight.h deleted file mode 100644 index e4a971a286..0000000000 --- a/ios/RCTMGL/RCTMGLLight.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// RCTMGLLight.h -// RCTMGL -// -// Created by Nick Italiano on 9/26/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -@import Mapbox; - -@interface RCTMGLLight : UIView - -@property (nonatomic, strong) MGLMapView *map; -@property (nonatomic, strong) NSDictionary *reactStyle; - -@end diff --git a/ios/RCTMGL/RCTMGLLight.m b/ios/RCTMGL/RCTMGLLight.m deleted file mode 100644 index e558e152fc..0000000000 --- a/ios/RCTMGL/RCTMGLLight.m +++ /dev/null @@ -1,46 +0,0 @@ -// -// RCTMGLLight.m -// RCTMGL -// -// Created by Nick Italiano on 9/26/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLight.h" -#import "RCTMGLStyle.h" - -@implementation RCTMGLLight -{ - MGLLight *internalLight; -} - -- (void)setReactStyle:(NSDictionary *)reactStyle -{ - _reactStyle = reactStyle; - - if (_map != nil) { - [self addStyles]; - } -} - -- (void)setMap:(MGLMapView *)map -{ - _map = map; - [self addStyles]; -} - -- (BOOL)isAddedToMap { - return _map != NULL; -} - -- (void)addStyles -{ - MGLLight *light = [[MGLLight alloc] init]; - RCTMGLStyle *style = [[RCTMGLStyle alloc] init]; - [style lightLayer:light withReactStyle:_reactStyle isValid:^{ - return [self isAddedToMap]; - }]; - _map.style.light = light; -} - -@end diff --git a/ios/RCTMGL/RCTMGLLightManager.h b/ios/RCTMGL/RCTMGLLightManager.h deleted file mode 100644 index b404393eab..0000000000 --- a/ios/RCTMGL/RCTMGLLightManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLLightManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/26/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLLightManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLLightManager.m b/ios/RCTMGL/RCTMGLLightManager.m deleted file mode 100644 index 505ebe3f20..0000000000 --- a/ios/RCTMGL/RCTMGLLightManager.m +++ /dev/null @@ -1,23 +0,0 @@ -// -// RCTMGLLightManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/26/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLightManager.h" -#import "RCTMGLLight.h" - -@implementation RCTMGLLightManager - -RCT_EXPORT_MODULE() - -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -- (UIView*)view -{ - return [RCTMGLLight new]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLLineLayer.h b/ios/RCTMGL/RCTMGLLineLayer.h deleted file mode 100644 index 27dade82d9..0000000000 --- a/ios/RCTMGL/RCTMGLLineLayer.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// RCTMGLLineLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLVectorLayer.h" -@import Mapbox; - -@interface RCTMGLLineLayer : RCTMGLVectorLayer - -@end diff --git a/ios/RCTMGL/RCTMGLLineLayer.m b/ios/RCTMGL/RCTMGLLineLayer.m deleted file mode 100644 index 2878314b50..0000000000 --- a/ios/RCTMGL/RCTMGLLineLayer.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// RCTMGLLineLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLineLayer.h" -#import "RCTMGLStyle.h" -#import - -@implementation RCTMGLLineLayer - -- (MGLLineStyleLayer*)makeLayer:(MGLStyle*)style -{ - MGLSource *source = [self layerWithSourceIDInStyle:style]; - if (source == nil) { return nil; } - MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:self.id source:source]; - layer.sourceLayerIdentifier = self.sourceLayerID; - return layer; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style lineLayer:(MGLLineStyleLayer *)self.styleLayer withReactStyle:self.reactStyle isValid:^{ - return [self isAddedToMap]; - }]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLLineLayerManager.h b/ios/RCTMGL/RCTMGLLineLayerManager.h deleted file mode 100644 index 84d4dfadc8..0000000000 --- a/ios/RCTMGL/RCTMGLLineLayerManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLLineLayerManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLLineLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLLineLayerManager.m b/ios/RCTMGL/RCTMGLLineLayerManager.m deleted file mode 100644 index fe97f99a0f..0000000000 --- a/ios/RCTMGL/RCTMGLLineLayerManager.m +++ /dev/null @@ -1,40 +0,0 @@ -// -// RCTMGLLineLayerManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLineLayerManager.h" -#import "RCTMGLLineLayer.h" - -@implementation RCTMGLLineLayerManager - -RCT_EXPORT_MODULE() - -// line layer props -RCT_EXPORT_VIEW_PROPERTY(sourceLayerID, NSString); - -// standard layer props -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); -RCT_EXPORT_VIEW_PROPERTY(filter, NSArray); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLLineLayer *layer = [RCTMGLLineLayer new]; - layer.bridge = self.bridge; - return layer; -} - - -@end diff --git a/ios/RCTMGL/RCTMGLLocation.h b/ios/RCTMGL/RCTMGLLocation.h deleted file mode 100644 index a4501f95f9..0000000000 --- a/ios/RCTMGL/RCTMGLLocation.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// RCTMGLLocation.h -// RCTMGL -// -// Created by Nick Italiano on 6/21/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import -#import - -@interface RCTMGLLocation : NSObject - -@property (nonatomic, strong) CLLocation *location; -@property (nonatomic, strong) CLHeading *heading; - -- (NSDictionary *)toJSON; - -@end diff --git a/ios/RCTMGL/RCTMGLLocation.m b/ios/RCTMGL/RCTMGLLocation.m deleted file mode 100644 index bce7a20701..0000000000 --- a/ios/RCTMGL/RCTMGLLocation.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// RCTMGLLocation.m -// RCTMGL -// -// Created by Nick Italiano on 6/21/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLocation.h" - -@implementation RCTMGLLocation - -- (NSDictionary *)toJSON -{ - NSMutableDictionary *json = [[NSMutableDictionary alloc] init]; - - NSMutableDictionary *coords = [[NSMutableDictionary alloc] init]; - coords[@"longitude"] = @(_location.coordinate.longitude); - coords[@"latitude"] = @(_location.coordinate.latitude); - coords[@"altitude"] = @(_location.altitude); - coords[@"accuracy"] = @(_location.horizontalAccuracy); - coords[@"heading"] = @(_heading.trueHeading); - coords[@"course"] = @(_location.course); - coords[@"speed"] = @(_location.speed); - - json[@"coords"] = coords; - json[@"timestamp"] = @([_location.timestamp timeIntervalSince1970]); - - return json; -} - -@end diff --git a/ios/RCTMGL/RCTMGLLocationManager.h b/ios/RCTMGL/RCTMGLLocationManager.h deleted file mode 100644 index 13846a7fcc..0000000000 --- a/ios/RCTMGL/RCTMGLLocationManager.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// RCTMGLLocationManager.h -// RCTMGL -// -// Created by Nick Italiano on 6/21/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import - -#import "RCTMGLLocation.h" -#import "RCTMGLLocationManagerDelegate.h" - -typedef void (^RCTMGLLocationBlock)(RCTMGLLocation *location); - -@interface RCTMGLLocationManager : NSObject - -@property (nonatomic, strong) id delegate; - -+ (id)sharedInstance; - -- (void)start:(CLLocationDistance)minDisplacement; -- (void)stop; -- (void)setMinDisplacement:(CLLocationDistance)minDisplacement; -- (BOOL)isEnabled; -- (RCTMGLLocation *)getLastKnownLocation; -- (void)addListener:(RCTMGLLocationBlock)listener; -- (void)removeListener:(RCTMGLLocationBlock)listener; - -@end diff --git a/ios/RCTMGL/RCTMGLLocationManager.m b/ios/RCTMGL/RCTMGLLocationManager.m deleted file mode 100644 index c68a1f4da0..0000000000 --- a/ios/RCTMGL/RCTMGLLocationManager.m +++ /dev/null @@ -1,180 +0,0 @@ -// -// RCTMGLLocationManager.m -// RCTMGL -// -// Created by Nick Italiano on 6/21/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLLocationManager.h" - -@interface RCTMGLLocationManager() -@end - -@implementation RCTMGLLocationManager -{ - CLLocationManager *locationManager; - CLLocation *lastKnownLocation; - CLHeading *lastKnownHeading; - CLLocationDistance displacement; - NSMutableArray *listeners; - BOOL isListening; -} - -+ (id)sharedInstance -{ - static RCTMGLLocationManager *manager = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ manager = [[self alloc] init]; }); - return manager; -} - -- (instancetype)init -{ - if (self = [super init]) { - [self _setupLocationManager]; - listeners = [[NSMutableArray alloc] init]; - displacement = 0.0; - } - return self; -} - -- (void)dealloc -{ - locationManager.delegate = nil; - [self stop]; -} - -- (void)start:(CLLocationDistance)minDisplacement -{ - - displacement = minDisplacement; - - if ([self isEnabled]) { - return; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - [self->locationManager requestWhenInUseAuthorization]; - [self->locationManager startUpdatingLocation]; - [self->locationManager startUpdatingHeading]; - [self->locationManager setDistanceFilter:(minDisplacement)]; - self->isListening = YES; - }); -} - -- (void)setMinDisplacement:(CLLocationDistance)minDisplacement -{ - - displacement = minDisplacement; - - dispatch_async(dispatch_get_main_queue(), ^{ - [self->locationManager setDistanceFilter:(minDisplacement)]; - }); -} - -- (void)stop -{ - if (![self isEnabled]) { - return; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - [self->locationManager stopUpdatingLocation]; - [self->locationManager stopUpdatingHeading]; - self->isListening = NO; - }); -} - -- (BOOL)isEnabled -{ - return isListening; -} - -- (RCTMGLLocation *)getLastKnownLocation -{ - CLLocation* newLastLocation = locationManager.location; - if (newLastLocation) { - lastKnownLocation = newLastLocation; - } - RCTMGLLocation *location = [self _convertToMapboxLocation:lastKnownLocation]; - return location; -} - -- (void)addListener:(RCTMGLLocationBlock)listener -{ - if (![listeners containsObject:listener]) { - [listeners addObject:listener]; - } -} - -- (void)removeListener:(RCTMGLLocationBlock)listener -{ - NSUInteger indexOf = [listeners indexOfObject:listener]; - - if (indexOf == NSNotFound) { - return; - } - - [listeners removeObjectAtIndex:indexOf]; -} - -- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)heading -{ - lastKnownHeading = heading; - - if (displacement > 0) { - return; - } - - [self _updateDelegate]; -} - -- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations -{ - lastKnownLocation = [locations lastObject]; - [self _updateDelegate]; -} - -- (void)_setupLocationManager -{ - __weak RCTMGLLocationManager *weakSelf = self; - - dispatch_async(dispatch_get_main_queue(), ^{ - self->locationManager = [[CLLocationManager alloc] init]; - self->locationManager.delegate = weakSelf; - }); -} - -- (void)_updateDelegate -{ - if (_delegate == nil) { - return; - } - - RCTMGLLocation *userLocation = [self _convertToMapboxLocation:lastKnownLocation]; - - if (listeners.count > 0) { - for (int i = 0; i < listeners.count; i++) { - RCTMGLLocationBlock listener = listeners[i]; - listener(userLocation); - } - } - - [_delegate locationManager:self didUpdateLocation:userLocation]; -} - -- (RCTMGLLocation *)_convertToMapboxLocation:(CLLocation *)location -{ - if (location == nil) { - return nil; - } - - RCTMGLLocation *userLocation = [[RCTMGLLocation alloc] init]; - userLocation.location = location; - userLocation.heading = lastKnownHeading; - return userLocation; -} - -@end diff --git a/ios/RCTMGL/RCTMGLLocationManagerDelegate.h b/ios/RCTMGL/RCTMGLLocationManagerDelegate.h deleted file mode 100644 index 03bed36a87..0000000000 --- a/ios/RCTMGL/RCTMGLLocationManagerDelegate.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// RCTMGLLocationManagerDelegate.h -// RCTMGL -// -// Created by Nick Italiano on 6/21/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import - -#import "RCTMGLLocation.h" - -@class RCTMGLLocationManager; - -@protocol RCTMGLLocationManagerDelegate - -- (void)locationManager:(RCTMGLLocationManager *)locationManager didUpdateLocation:(RCTMGLLocation *)location; - -@end - diff --git a/ios/RCTMGL/RCTMGLLocationModule.h b/ios/RCTMGL/RCTMGLLocationModule.h deleted file mode 100644 index 1301ea03fa..0000000000 --- a/ios/RCTMGL/RCTMGLLocationModule.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// RCTMGLLocationManager.h -// RCTMGL -// -// Created by Nick Italiano on 6/21/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import -#import -#import - -@interface RCTMGLLocationModule : RCTEventEmitter - -@end diff --git a/ios/RCTMGL/RCTMGLLocationModule.m b/ios/RCTMGL/RCTMGLLocationModule.m index 153bbf56b0..db0780feaa 100644 --- a/ios/RCTMGL/RCTMGLLocationModule.m +++ b/ios/RCTMGL/RCTMGLLocationModule.m @@ -1,99 +1,15 @@ -// -// RCTMGLLocationManager.m -// RCTMGL -// -// Created by Nick Italiano on 6/21/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// +#import "React/RCTBridgeModule.h" +#import -#import +@class RCTMGLLocation; -#import "RCTMGLLocation.h" -#import "RCTMGLLocationModule.h" -#import "RCTMGLLocationManager.h" -#import "RCTMGLLocationManagerDelegate.h" -#import "RCTMGLEventTypes.h" +@interface RCT_EXTERN_MODULE(RCTMGLLocationModule, RCTEventEmitter) -@interface RCTMGLLocationModule() -@end - -@implementation RCTMGLLocationModule -{ - RCTMGLLocationManager *locationManager; - BOOL hasListeners; -} - -RCT_EXPORT_MODULE(); - -+ (BOOL)requiresMainQueueSetup -{ - return NO; -} - -- (instancetype)init -{ - if (self = [super init]) { - locationManager = [[RCTMGLLocationManager alloc] init]; - locationManager.delegate = self; - } - return self; -} - -- (void)startObserving -{ - [super startObserving]; - hasListeners = YES; -} - -- (void)stopObserving -{ - [super stopObserving]; - hasListeners = NO; -} - -- (NSArray *)supportedEvents -{ - return @[RCT_MAPBOX_USER_LOCATION_UPDATE]; -} +RCT_EXTERN_METHOD(start:(CLLocationDistance)minDisplacement) +RCT_EXTERN_METHOD(stop) +RCT_EXTERN_METHOD(getLastKnownLocation) -RCT_EXPORT_METHOD(start:(CLLocationDistance)minDisplacement) -{ - [locationManager start:minDisplacement]; -} +RCT_EXTERN_METHOD(setMinDisplacement:(CLLocationDistance)minDisplacement) -RCT_EXPORT_METHOD(pause) -{ - [locationManager stop]; -} - -RCT_EXPORT_METHOD(stop) -{ - [locationManager stop]; -} - -RCT_EXPORT_METHOD(setMinDisplacement:(CLLocationDistance)minDisplacement) -{ - [locationManager setMinDisplacement:minDisplacement]; -} - -RCT_EXPORT_METHOD(getLastKnownLocation:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - RCTMGLLocation *lastKnownLocation = [locationManager getLastKnownLocation]; - resolve(lastKnownLocation); -} - -- (void)locationManager:(RCTMGLLocationManager *)locationManager didUpdateLocation:(RCTMGLLocation *)location -{ - if (!hasListeners) { - return; - } - - if (self.bridge == nil) { - return; - } - - [self sendEventWithName:RCT_MAPBOX_USER_LOCATION_UPDATE body:[location toJSON]]; -} @end - diff --git a/ios/RCTMGL/RCTMGLLocationModule.swift b/ios/RCTMGL/RCTMGLLocationModule.swift new file mode 100644 index 0000000000..5e1f8d6f54 --- /dev/null +++ b/ios/RCTMGL/RCTMGLLocationModule.swift @@ -0,0 +1,55 @@ +import Foundation +import MapboxMaps + +@objc(RCTMGLLocation) +class RCTMGLLocation: NSObject { + +} + +typealias RCTMGLLocationBlock = (RCTMGLLocation) -> Void + +let RCT_MAPBOX_USER_LOCATION_UPDATE = "MapboxUserLocationUpdate"; + +@objc(RCTMGLLocationModule) +class RCTMGLLocationModule: RCTEventEmitter { + + @objc + override static func requiresMainQueueSetup() -> Bool { + return true + } + + @objc + override func constantsToExport() -> [AnyHashable: Any]! { + return [ + "foo": "bar" + ]; + } + + @objc override func supportedEvents() -> [String] + { + return [RCT_MAPBOX_USER_LOCATION_UPDATE]; + } + + + @objc override func addListener(_ eventName: String) + { + print("TODO implement addListenerSwift", eventName) + super.addListener(eventName) + } + + @objc func start(_ minDisplacement: CLLocationDistance) { + print("TODO implement RCTMGLLocationModule.start!") + } + + @objc func stop() { + print("TODO implement RCTMGLLocationModule.stop!") + } + + @objc func getLastKnownLocation() -> RCTMGLLocation? { + return RCTMGLLocation() + } + + @objc func setMinDisplacement(_ minDisplacement: CLLocationDistance) { + print("TODO implement RCTMGLLocationModule.setMinDisplacement!") + } +} diff --git a/ios/RCTMGL/RCTMGLLogging.h b/ios/RCTMGL/RCTMGLLogging.h deleted file mode 100644 index 85d37b07fe..0000000000 --- a/ios/RCTMGL/RCTMGLLogging.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RCTMGLLogging_h -#define RCTMGLLogging_h - -#import -#import - - -@class MGLLoggingConfiguration; - -@interface RCTMGLLogging : RCTEventEmitter - -@property (nonatomic, nonnull) MGLLoggingConfiguration* loggingConfiguration; - -- (void)setLoggingLevel:(nonnull NSString*) logLevel; - -@end - -#endif /* RCTMGLLogging_h */ diff --git a/ios/RCTMGL/RCTMGLLogging.m b/ios/RCTMGL/RCTMGLLogging.m index 8516b3308b..b440e3a4bb 100644 --- a/ios/RCTMGL/RCTMGLLogging.m +++ b/ios/RCTMGL/RCTMGLLogging.m @@ -1,132 +1,5 @@ -#import "RCTMGLLogging.h" +#import "React/RCTBridgeModule.h" -@import Mapbox; - -@interface RCTMGLLogging() -@property (nonatomic) BOOL hasListeners; -@end - -@implementation RCTMGLLogging - -+ (id)allocWithZone:(NSZone *)zone { - static RCTMGLLogging *sharedInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedInstance = [super allocWithZone:zone]; - }); - return sharedInstance; -} - --(id)init { - if ( self = [super init] ) { - self.loggingConfiguration = [MGLLoggingConfiguration sharedConfiguration]; - [self.loggingConfiguration setLoggingLevel:MGLLoggingLevelWarning]; - __weak typeof(self) weakSelf = self; - self.loggingConfiguration.handler = ^(MGLLoggingLevel loggingLevel, NSString *filePath, NSUInteger line, NSString *message) { - [weakSelf sendLogWithLevel:loggingLevel filePath: filePath line: line message: message]; - }; - } - return self; -} - -RCT_EXPORT_MODULE(); - -+ (BOOL)requiresMainQueueSetup -{ - return YES; -} - -- (NSArray *)supportedEvents -{ - return @[@"LogEvent"]; -} - -- (void)startObserving -{ - [super startObserving]; - self.hasListeners = true; -} - -- (void)stopObserving -{ - [super stopObserving]; - self.hasListeners = false; -} - -- (void)sendLogWithLevel:(MGLLoggingLevel)loggingLevel filePath:(NSString*)filePath line:(NSUInteger)line message:(NSString*)message -{ - if (!self.hasListeners) return; - - NSString* level = @"n/a"; - switch (loggingLevel) { - case MGLLoggingLevelInfo: - level = @"info"; - break; - case MGLLoggingLevelError: - level = @"error"; - break; -#if MGL_LOGGING_ENABLE_DEBUG - case MGLLoggingLevelDebug: - level = @"debug"; - break; -#endif - case MGLLoggingLevelWarning: - level = @"warning"; - break; - case MGLLoggingLevelNone: - level = @"none"; - break; - case MGLLoggingLevelFault: - level = @"fault"; - break; - case MGLLoggingLevelVerbose: - level = @"verbose"; - break; - } - - NSString* type = nil; - if ([message hasPrefix:@"Failed to load glyph range"]) { - type = @"missing_font"; - } - - NSMutableDictionary* body = [@{ - @"level": level, - @"message": message, - @"filePath": filePath, - @"line": @(line) - } mutableCopy]; - - if (type != nil) { - body[@"type"] = type; - } - [self sendEventWithName:@"LogEvent" body:body]; -} - -RCT_EXPORT_METHOD(setLogLevel: (nonnull NSString*)logLevel) -{ - MGLLoggingLevel mglLogLevel = MGLLoggingLevelNone; - if ([logLevel isEqualToString:@"none"]) { - mglLogLevel = MGLLoggingLevelNone; - } else if ([logLevel isEqualToString:@"debug"]) { - mglLogLevel = MGLLoggingLevelInfo; - } else if ([logLevel isEqualToString:@"fault"]) { - mglLogLevel = MGLLoggingLevelFault; - } else if ([logLevel isEqualToString:@"error"]) { - mglLogLevel = MGLLoggingLevelError; - } else if ([logLevel isEqualToString:@"warning"]) { - mglLogLevel = MGLLoggingLevelWarning; - } else if ([logLevel isEqualToString:@"info"]) { - mglLogLevel = MGLLoggingLevelInfo; - } else if ([logLevel isEqualToString:@"debug"]) { -#if MGL_LOGGING_ENABLE_DEBUG - mglLogLevel = MGLLoggingLevelDebug; -#else - mglLogLevel = MGLLoggingLevelVerbose; -#endif - } else if ([logLevel isEqualToString:@"verbose"]) { - mglLogLevel = MGLLoggingLevelVerbose; - } - self.loggingConfiguration.loggingLevel = mglLogLevel; -} +@interface RCT_EXTERN_MODULE(RCTMGLLogging, NSObject) @end diff --git a/ios/RCTMGL/RCTMGLLogging.swift b/ios/RCTMGL/RCTMGLLogging.swift new file mode 100644 index 0000000000..a57df5e9c7 --- /dev/null +++ b/ios/RCTMGL/RCTMGLLogging.swift @@ -0,0 +1,23 @@ +import Foundation +import MapboxMaps + +@objc(RCTMGLLogging) +class RCTMGLLogging: RCTEventEmitter { + @objc + static override func requiresMainQueueSetup() -> Bool { + return true + } + + @objc + override func constantsToExport() -> [AnyHashable: Any]! { + return [ + "todo": "implement" + ]; + } + + @objc + override func supportedEvents() -> [String] + { + return ["LogEvent"]; + } +} diff --git a/ios/RCTMGL/RCTMGLMapTouchEvent.h b/ios/RCTMGL/RCTMGLMapTouchEvent.h deleted file mode 100644 index 467613a3b9..0000000000 --- a/ios/RCTMGL/RCTMGLMapTouchEvent.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// RCTMGLTouchEvent.h -// RCTMGL -// -// Created by Nick Italiano on 8/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLEvent.h" -#import "RCTMGLPointAnnotation.h" -@import Mapbox; - -@interface RCTMGLMapTouchEvent : RCTMGLEvent - -@property (nonatomic, copy) NSString *id; -@property (nonatomic, assign) CLLocationCoordinate2D coordinate; -@property (nonatomic, assign) CGPoint screenPoint; - -+ (RCTMGLMapTouchEvent*)makeTapEvent:(MGLMapView*)mapView withPoint:(CGPoint)point; -+ (RCTMGLMapTouchEvent*)makeLongPressEvent:(MGLMapView*)mapView withPoint:(CGPoint)point; -+ (RCTMGLMapTouchEvent *)makeAnnotationTapEvent:(RCTMGLPointAnnotation *)pointAnnotation; -+ (RCTMGLMapTouchEvent *)makeAnnotationTapEventOnDrag:(RCTMGLPointAnnotation *)pointAnnotation; - -@end diff --git a/ios/RCTMGL/RCTMGLMapTouchEvent.m b/ios/RCTMGL/RCTMGLMapTouchEvent.m deleted file mode 100644 index ec3ac19d7d..0000000000 --- a/ios/RCTMGL/RCTMGLMapTouchEvent.m +++ /dev/null @@ -1,77 +0,0 @@ -// -// RCTMGLTouchEvent.m -// RCTMGL -// -// Created by Nick Italiano on 8/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLMapTouchEvent.h" -#import "RCTMGLEventTypes.h" -#import "RCTMGLPointAnnotation.h" -@import Mapbox; - -@implementation RCTMGLMapTouchEvent - -- (NSDictionary*)payload -{ - MGLPointFeature *feature = [[MGLPointFeature alloc] init]; - feature.coordinate = _coordinate; - if (_id == nil) { - feature.attributes = @{ - @"screenPointX": [NSNumber numberWithDouble:_screenPoint.x], - @"screenPointY":[NSNumber numberWithDouble:_screenPoint.y] - }; - } else { - feature.attributes = @{ - @"id": _id, - @"screenPointX": [NSNumber numberWithDouble:_screenPoint.x], - @"screenPointY":[NSNumber numberWithDouble:_screenPoint.y] - }; - } - return [feature geoJSONDictionary]; -} - -+ (RCTMGLMapTouchEvent*)makeTapEvent:(MGLMapView*)mapView withPoint:(CGPoint)point -{ - return [RCTMGLMapTouchEvent _fromPoint:point withMapView:mapView andEventType:RCT_MAPBOX_EVENT_TAP]; -} - -+ (RCTMGLMapTouchEvent*)makeLongPressEvent:(MGLMapView*)mapView withPoint:(CGPoint)point -{ - return [RCTMGLMapTouchEvent _fromPoint:point withMapView:mapView andEventType:RCT_MAPBOX_EVENT_LONGPRESS]; -} - -+ (RCTMGLMapTouchEvent *)makeAnnotationTapEvent:(RCTMGLPointAnnotation *)pointAnnotation -{ - RCTMGLMapTouchEvent *event = [[RCTMGLMapTouchEvent alloc] init]; - event.type = RCT_MAPBOX_ANNOTATION_TAP; - event.id = pointAnnotation.id; - event.coordinate = pointAnnotation.coordinate; - event.screenPoint = [pointAnnotation.superview convertPoint:pointAnnotation.frame.origin toView:nil]; - return event; -} - -+ (RCTMGLMapTouchEvent *)makeAnnotationTapEventOnDrag:(RCTMGLPointAnnotation *)pointAnnotation -{ - RCTMGLMapTouchEvent *event = [[RCTMGLMapTouchEvent alloc] init]; - event.type = RCT_MAPBOX_ANNOTATION_TAP; - event.id = pointAnnotation.id; - CGPoint screenPoint = [pointAnnotation.superview convertPoint:pointAnnotation.layer.position toView:nil]; - screenPoint.x -= (pointAnnotation.layer.bounds.size.width * pointAnnotation.layer.anchorPoint.x); - screenPoint.y -= (pointAnnotation.layer.bounds.size.height * pointAnnotation.layer.anchorPoint.y); - event.screenPoint = screenPoint; - event.coordinate = [pointAnnotation.map convertPoint:pointAnnotation.layer.position toCoordinateFromView:pointAnnotation.map]; - return event; -} - -+ (RCTMGLMapTouchEvent*)_fromPoint:(CGPoint)point withMapView:(MGLMapView *)mapView andEventType:(NSString*)eventType -{ - RCTMGLMapTouchEvent *event = [[RCTMGLMapTouchEvent alloc] init]; - event.type = eventType; - event.coordinate = [mapView convertPoint:point toCoordinateFromView:mapView]; - event.screenPoint = point; - return event; -} - -@end diff --git a/ios/RCTMGL/RCTMGLMapView.h b/ios/RCTMGL/RCTMGLMapView.h deleted file mode 100644 index 413e63f3e0..0000000000 --- a/ios/RCTMGL/RCTMGLMapView.h +++ /dev/null @@ -1,91 +0,0 @@ -// -// RCTMGLMapView.h -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLSource.h" -#import "RCTMGLShapeSource.h" -#import "RCTMGLPointAnnotation.h" -#import "RCTMGLLight.h" - -@import Mapbox; - -@class CameraUpdateQueue; -@class RCTMGLImages; -@class RCTMGLLogging; - -@protocol RCTMGLMapViewCamera -- (void)initialLayout; -- (void)didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated; -@end - -typedef void (^FoundLayerBlock) (MGLStyleLayer* __nonnull layer); -typedef void (^StyleLoadedBlock) (MGLStyle* __nonnull style); - -@interface RCTMGLMapView : MGLMapView - -@property (nonatomic, strong, nonnull) RCTMGLLogging* logging; -@property (nonatomic, strong) CameraUpdateQueue *cameraUpdateQueue; -@property (nonatomic, weak) id reactCamera; -@property (nonatomic, strong) NSMutableArray> *reactSubviews; -@property (nonatomic, strong) NSMutableArray *sources; -@property (nonatomic, strong) NSMutableArray *images; -@property (nonatomic, strong) NSMutableArray *layers; -@property (nonatomic, strong) NSMutableArray *pointAnnotations; -@property (nonatomic, strong) RCTMGLLight *light; -@property (nonatomic, copy) NSArray *reactContentInset; - -@property (nonatomic, strong) NSMutableDictionary*> *layerWaiters; -@property (nonatomic, strong) NSMutableArray *styleWaiters; - -@property (nonatomic, assign) BOOL reactLocalizeLabels; -@property (nonatomic, assign) BOOL reactScrollEnabled; -@property (nonatomic, assign) BOOL reactPitchEnabled; -@property (nonatomic, assign) BOOL reactRotateEnabled; -@property (nonatomic, assign) BOOL reactAttributionEnabled; -@property (nonatomic, strong) NSDictionary *reactAttributionPosition; -@property (nonatomic, assign) BOOL reactLogoEnabled; -@property (nonatomic, assign) BOOL reactCompassEnabled; -@property (nonatomic, assign) BOOL reactZoomEnabled; - -@property (nonatomic, assign) NSInteger *reactCompassViewPosition; -@property (nonatomic, assign) CGPoint reactCompassViewMargins; - -@property (nonatomic, copy) NSString *reactStyleURL; -@property (nonatomic, assign) NSInteger reactPreferredFramesPerSecond; - -@property (nonatomic, assign) MGLCoordinateBounds maxBounds; - -@property (nonatomic, assign) BOOL isUserInteraction; -@property (nonatomic, assign) BOOL useNativeUserLocationAnnotationView; - -@property (nonatomic, copy) RCTBubblingEventBlock onPress; -@property (nonatomic, copy) RCTBubblingEventBlock onLongPress; -@property (nonatomic, copy) RCTBubblingEventBlock onMapChange; - - -- (void)layerAdded:(MGLStyleLayer*) layer; - -- (CLLocationDistance)getMetersPerPixelAtLatitude:(double)latitude withZoom:(double)zoomLevel; -- (CLLocationDistance)altitudeFromZoom:(double)zoomLevel; -- (CLLocationDistance)altitudeFromZoom:(double)zoomLevel atLatitude:(CLLocationDegrees)latitude; -- (CLLocationDistance)altitudeFromZoom:(double)zoomLevel atLatitude:(CLLocationDegrees)latitude atPitch:(CGFloat)pitch; -- (RCTMGLPointAnnotation*)getRCTPointAnnotation:(MGLPointAnnotation*)mglAnnotation; -- (NSArray *)getAllTouchableSources; -- (NSArray *)getAllShapeSources; -- (NSArray *)getAllImages; -- (RCTMGLSource *)getTouchableSourceWithHighestZIndex:(NSArray *)touchableSources; -- (NSString *)takeSnap:(BOOL)writeToDisk; -- (void)didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated; - -- (void)waitForLayerWithID:(nonnull NSString*)layerID then:(void (^ _Nonnull)(MGLStyleLayer* _Nonnull layer))foundLayer; - -- (void)setSourceVisibility:(BOOL)visiblity sourceId:(nonnull NSString*)sourceId sourceLayerId:(nullable NSString*)sourceLayerId; - -- (void)notifyStyleLoaded; - -@end diff --git a/ios/RCTMGL/RCTMGLMapView.m b/ios/RCTMGL/RCTMGLMapView.m deleted file mode 100644 index 6a72c529e5..0000000000 --- a/ios/RCTMGL/RCTMGLMapView.m +++ /dev/null @@ -1,511 +0,0 @@ -// -// RCTMGLMapView.m -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLMapView.h" -#import "CameraUpdateQueue.h" -#import "RCTMGLUtils.h" -#import "RNMBImageUtils.h" -#import "RCTMGLImages.h" -#import "UIView+React.h" -#import "RCTMGLNativeUserLocation.h" -#import "RCTMGLLogging.h" - -@implementation RCTMGLMapView -{ - BOOL _pendingInitialLayout; -} - -static double const DEG2RAD = M_PI / 180; -static double const LAT_MAX = 85.051128779806604; -static double const TILE_SIZE = 256; -static double const EARTH_RADIUS_M = 6378137; -static double const M2PI = M_PI * 2; - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - _pendingInitialLayout = YES; - _cameraUpdateQueue = [[CameraUpdateQueue alloc] init]; - _sources = [[NSMutableArray alloc] init]; - _images = [[NSMutableArray alloc] init]; - _layers = [[NSMutableArray alloc] init]; - _pointAnnotations = [[NSMutableArray alloc] init]; - _reactSubviews = [[NSMutableArray alloc] init]; - _layerWaiters = [[NSMutableDictionary alloc] init]; - _styleWaiters = [[NSMutableArray alloc] init]; - _logging = [[RCTMGLLogging alloc] init]; - } - return self; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - if (_pendingInitialLayout) { - _pendingInitialLayout = NO; - - [ _reactCamera initialLayout]; - } -} - -- (void)invalidate -{ - if (_reactSubviews.count == 0) { - return; - } - for (int i = 0; i < _reactSubviews.count; i++) { - [self removeFromMap:_reactSubviews[i]]; - } -} - -- (void)layerAdded:(MGLStyleLayer*) layer -{ - NSString* layerID = layer.identifier; - NSMutableArray* waiters = [_layerWaiters valueForKey:layerID]; - if (waiters) { - for (FoundLayerBlock foundLayerBlock in waiters) { - foundLayerBlock(layer); - } - [_layerWaiters removeObjectForKey:layerID]; - } -} - -- (void)waitForLayerWithID:(nonnull NSString*)layerID then:(void (^)(MGLStyleLayer* layer))foundLayer { - if (self.style) { - MGLStyleLayer* layer = [self.style layerWithIdentifier:layerID]; - if (layer) { - foundLayer(layer); - } else { - NSMutableArray* existingWaiters = [_layerWaiters valueForKey:layerID]; - - NSMutableArray* waiters = existingWaiters; - if (waiters == nil) { - waiters = [[NSMutableArray alloc] init]; - } - [waiters addObject:foundLayer]; - if (! existingWaiters) { - [_layerWaiters setObject:waiters forKey:layerID]; - } - } - } else { - // TODO - } -} - -- (void)getStyle:(void (^)(MGLStyle* style))onStyleLoaded { - if (self.style) { - onStyleLoaded(self.style); - } else { - [_styleWaiters addObject:onStyleLoaded]; - } -} - -- (void)notifyStyleLoaded { - if (!self.style) return; - for (StyleLoadedBlock styleLoadedBlock in self.styleWaiters) { - styleLoadedBlock(self.style); - } - [self.styleWaiters removeAllObjects]; -} - - -- (void) addToMap:(id)subview -{ - if ([subview isKindOfClass:[RCTMGLSource class]]) { - RCTMGLSource *source = (RCTMGLSource*)subview; - source.map = self; - [_sources addObject:(RCTMGLSource*)subview]; - } else if ([subview isKindOfClass:[RCTMGLLight class]]) { - RCTMGLLight *light = (RCTMGLLight*)subview; - _light = light; - _light.map = self; - } else if ([subview isKindOfClass:[RCTMGLNativeUserLocation class]]) { - RCTMGLNativeUserLocation *nativeUserLocation = (RCTMGLNativeUserLocation*)subview; - nativeUserLocation.map = self; - } else if ([subview isKindOfClass:[RCTMGLPointAnnotation class]]) { - RCTMGLPointAnnotation *pointAnnotation = (RCTMGLPointAnnotation *)subview; - pointAnnotation.map = self; - [_pointAnnotations addObject:pointAnnotation]; - } else if ([subview isKindOfClass:[RCTMGLCamera class]]) { - RCTMGLCamera *camera = (RCTMGLCamera *)subview; - camera.map = self; - } else if ([subview isKindOfClass:[RCTMGLImages class]]) { - RCTMGLImages *images = (RCTMGLImages*)subview; - images.map = self; - [_images addObject:images]; - } else if ([subview isKindOfClass:[RCTMGLLayer class]]) { - RCTMGLLayer *layer = (RCTMGLLayer*)subview; - layer.map = self; - [_layers addObject:layer]; - } else { - NSArray> *childSubviews = [subview reactSubviews]; - - for (int i = 0; i < childSubviews.count; i++) { - [self addToMap:childSubviews[i]]; - } - } -} - -- (void) removeFromMap:(id)subview -{ - if ([subview isKindOfClass:[RCTMGLSource class]]) { - RCTMGLSource *source = (RCTMGLSource*)subview; - source.map = nil; - [_sources removeObject:source]; - } else if ([subview isKindOfClass:[RCTMGLPointAnnotation class]]) { - RCTMGLPointAnnotation *pointAnnotation = (RCTMGLPointAnnotation *)subview; - pointAnnotation.map = nil; - [_pointAnnotations removeObject:pointAnnotation]; - } else if ([subview isKindOfClass:[RCTMGLCamera class]]) { - RCTMGLCamera *camera = (RCTMGLCamera *)subview; - camera.map = nil; - } else if ([subview isKindOfClass:[RCTMGLImages class]]) { - RCTMGLImages *images = (RCTMGLImages*)subview; - images.map = nil; - [_images removeObject:images]; - } else if ([subview isKindOfClass:[RCTMGLLayer class]]) { - RCTMGLLayer *layer = (RCTMGLLayer*)subview; - layer.map = nil; - [_layers removeObject:layer]; - } else if ([subview isKindOfClass:[RCTMGLNativeUserLocation class]]) { - RCTMGLNativeUserLocation *nativeUserLocation = (RCTMGLNativeUserLocation *)subview; - nativeUserLocation.map = nil; - } else if ([subview isKindOfClass:[RCTMGLLight class]]) { - RCTMGLLight *light = (RCTMGLLight*)subview; - light.map = nil; - } else { - NSArray> *childSubViews = [subview reactSubviews]; - - for (int i = 0; i < childSubViews.count; i++) { - [self removeFromMap:childSubViews[i]]; - } - } - if ([_layerWaiters count] > 0) { - RCTLogWarn(@"The following layers were waited on but never added to the map: %@", [_layerWaiters allKeys]); - [_layerWaiters removeAllObjects]; - } -} - -- (void)setSourceVisibility:(BOOL)visible sourceId:(NSString *)sourceId sourceLayerId:(NSString *)sourceLayerId { - __weak typeof(self) weakSelf = self; - [self getStyle:^(MGLStyle *style) { - __strong typeof(self) strongSelf = weakSelf; - for (MGLStyleLayer *layer in strongSelf.style.layers) { - if ([layer isKindOfClass:[MGLForegroundStyleLayer class]]) { - MGLForegroundStyleLayer *foregroundLayer = (MGLForegroundStyleLayer*)layer; - if (![foregroundLayer.sourceIdentifier isEqualToString:sourceId]) continue; - if (sourceLayerId == nil || sourceLayerId.length == 0) { - layer.visible = visible; - } else if ([layer isKindOfClass:[MGLVectorStyleLayer class]]) { - MGLVectorStyleLayer *vectorLayer = (MGLVectorStyleLayer*)layer; - if ([vectorLayer.sourceLayerIdentifier isEqualToString:sourceLayerId]) { - layer.visible = visible; - } - } - } - } - }]; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (void)insertReactSubview:(id)subview atIndex:(NSInteger)atIndex { - [self addToMap:subview]; - [_reactSubviews insertObject:(UIView *)subview atIndex:(NSUInteger) atIndex]; -} -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (void)removeReactSubview:(id)subview { - // similarly, when the children are being removed we have to do the appropriate - // underlying mapview action here. - [self removeFromMap:subview]; - [_reactSubviews removeObject:(UIView *)subview]; - [(UIView *)subview removeFromSuperview]; -} -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (NSArray> *)reactSubviews { - return _reactSubviews; -} -#pragma clang diagnostic pop - -- (void)setReactZoomEnabled:(BOOL)reactZoomEnabled -{ - _reactZoomEnabled = reactZoomEnabled; - self.zoomEnabled = _reactZoomEnabled; -} - -- (void)setReactScrollEnabled:(BOOL)reactScrollEnabled -{ - _reactScrollEnabled = reactScrollEnabled; - self.scrollEnabled = _reactScrollEnabled; -} - -- (void)setReactPitchEnabled:(BOOL)reactPitchEnabled -{ - _reactPitchEnabled = reactPitchEnabled; - self.pitchEnabled = _reactPitchEnabled; -} - -- (void)setReactRotateEnabled:(BOOL)reactRotateEnabled -{ - _reactRotateEnabled = reactRotateEnabled; - self.rotateEnabled = _reactRotateEnabled; -} - -- (void)setReactAttributionEnabled:(BOOL)reactAttributionEnabled -{ - _reactAttributionEnabled = reactAttributionEnabled; - self.attributionButton.hidden = !_reactAttributionEnabled; - -} - -- (void)setReactAttributionPosition:(NSDictionary *)position -{ - NSNumber *left = [position valueForKey:@"left"]; - NSNumber *right = [position valueForKey:@"right"]; - NSNumber *top = [position valueForKey:@"top"]; - NSNumber *bottom = [position valueForKey:@"bottom"]; - if (left != nil && top != nil) { - [self setAttributionButtonPosition:MGLOrnamentPositionTopLeft]; - [self setAttributionButtonMargins:CGPointMake([left floatValue], [top floatValue])]; - } else if (right != nil && top != nil) { - [self setAttributionButtonPosition:MGLOrnamentPositionTopRight]; - [self setAttributionButtonMargins:CGPointMake([right floatValue], [top floatValue])]; - } else if (bottom != nil && right != nil) { - [self setAttributionButtonPosition:MGLOrnamentPositionBottomRight]; - [self setAttributionButtonMargins:CGPointMake([right floatValue], [bottom floatValue])]; - } else if (bottom != nil && left != nil) { - [self setAttributionButtonPosition:MGLOrnamentPositionBottomLeft]; - [self setAttributionButtonMargins:CGPointMake([left floatValue], [bottom floatValue])]; - } else { - [self setAttributionButtonPosition:MGLOrnamentPositionBottomRight]; - // same as MGLOrnamentDefaultPositionOffset in MGLMapView.mm - [self setAttributionButtonMargins:CGPointMake(8, 8)]; - } - -} - -- (void)setReactLogoEnabled:(BOOL)reactLogoEnabled -{ - _reactLogoEnabled = reactLogoEnabled; - self.logoView.hidden = !_reactLogoEnabled; -} - -- (void)setReactCompassEnabled:(BOOL)reactCompassEnabled -{ - _reactCompassEnabled = reactCompassEnabled; - self.compassView.hidden = !_reactCompassEnabled; -} - -- (void)setReactCompassViewPosition:(NSInteger *)reactCompassViewPosition -{ - if(!self.compassView.hidden) - { - _reactCompassViewPosition = reactCompassViewPosition; - self.compassViewPosition = _reactCompassViewPosition; - } -} - -- (void)setReactCompassViewMargins:(CGPoint)reactCompassViewMargins -{ - if(!self.compassView.hidden) - { - CGPoint point; - point = reactCompassViewMargins; - self.compassViewMargins = point; - } -} - -- (void)setReactShowUserLocation:(BOOL)reactShowUserLocation -{ - // FMTODO - //_reactShowUserLocation = reactShowUserLocation; - self.showsUserLocation = reactShowUserLocation; //_reactShowUserLocation; -} - -- (void)setReactContentInset:(NSArray *)reactContentInset -{ - CGFloat top = 0.0f, right = 0.0f, left = 0.0f, bottom = 0.0f; - - if (reactContentInset.count == 4) { - top = [reactContentInset[0] floatValue]; - right = [reactContentInset[1] floatValue]; - bottom = [reactContentInset[2] floatValue]; - left = [reactContentInset[3] floatValue]; - } else if (reactContentInset.count == 2) { - top = [reactContentInset[0] floatValue]; - right = [reactContentInset[1] floatValue]; - bottom = [reactContentInset[0] floatValue]; - left = [reactContentInset[1] floatValue]; - } else if (reactContentInset.count == 1) { - top = [reactContentInset[0] floatValue]; - right = [reactContentInset[0] floatValue]; - bottom = [reactContentInset[0] floatValue]; - left = [reactContentInset[0] floatValue]; - } - - self.contentInset = UIEdgeInsetsMake(top, left, bottom, right); -} - -- (void)setReactStyleURL:(NSString *)reactStyleURL -{ - _reactStyleURL = reactStyleURL; - [self _removeAllSourcesFromMap]; - self.styleURL = [self _getStyleURLFromKey:_reactStyleURL]; -} - -- (void)setReactPreferredFramesPerSecond:(NSInteger)reactPreferredFramesPerSecond -{ - self.preferredFramesPerSecond = reactPreferredFramesPerSecond; -} - - -#pragma mark - methods - -- (NSString *)takeSnap:(BOOL)writeToDisk -{ - UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0); - [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; - UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - return writeToDisk ? [RNMBImageUtils createTempFile:snapshot] : [RNMBImageUtils createBase64:snapshot]; -} - -- (CLLocationDistance)getMetersPerPixelAtLatitude:(double)latitude withZoom:(double)zoomLevel -{ - double constrainedZoom = [[RCTMGLUtils clamp:[NSNumber numberWithDouble:zoomLevel] - min:[NSNumber numberWithDouble:self.minimumZoomLevel] - max:[NSNumber numberWithDouble:self.maximumZoomLevel]] doubleValue]; - - double constrainedLatitude = [[RCTMGLUtils clamp:[NSNumber numberWithDouble:latitude] - min:[NSNumber numberWithDouble:-LAT_MAX] - max:[NSNumber numberWithDouble:LAT_MAX]] doubleValue]; - - double constrainedScale = pow(2.0, constrainedZoom); - return cos(constrainedLatitude * DEG2RAD) * M2PI * EARTH_RADIUS_M / (constrainedScale * TILE_SIZE); -} - -- (CLLocationDistance)altitudeFromZoom:(double)zoomLevel -{ - return [self altitudeFromZoom:zoomLevel atLatitude:self.camera.centerCoordinate.latitude]; -} - -- (CLLocationDistance)altitudeFromZoom:(double)zoomLevel atLatitude:(CLLocationDegrees)latitude -{ - return [self altitudeFromZoom:zoomLevel atLatitude:latitude atPitch:self.camera.pitch]; -} - -- (CLLocationDistance)altitudeFromZoom:(double)zoomLevel atLatitude:(CLLocationDegrees)latitude atPitch:(CGFloat)pitch -{ - return MGLAltitudeForZoomLevel(zoomLevel, pitch, latitude, self.frame.size); -} - -- (RCTMGLPointAnnotation*)getRCTPointAnnotation:(MGLPointAnnotation *)mglAnnotation -{ - for (int i = 0; i < _pointAnnotations.count; i++) { - RCTMGLPointAnnotation *rctAnnotation = _pointAnnotations[i]; - if (rctAnnotation.annotation == mglAnnotation) { - return rctAnnotation; - } - } - return nil; -} - -- (NSArray *)getAllTouchableSources -{ - NSMutableArray *touchableSources = [[NSMutableArray alloc] init]; - - for (RCTMGLSource *source in _sources) { - if (source.hasPressListener) { - [touchableSources addObject:source]; - } - } - - return touchableSources; -} - -- (NSArray*)getAllImages -{ - return [_images copy]; -} - -- (NSArray *)getAllShapeSources -{ - NSMutableArray *shapeSources = [[NSMutableArray alloc] init]; - - for (RCTMGLSource *source in _sources) { - if ([source isKindOfClass:[RCTMGLShapeSource class]]) { - [shapeSources addObject:source]; - } - } - - return shapeSources; -} -- (RCTMGLSource *)getTouchableSourceWithHighestZIndex:(NSArray *)touchableSources -{ - if (touchableSources == nil || touchableSources.count == 0) { - return nil; - } - - if (touchableSources.count == 1) { - return touchableSources[0]; - } - - NSMutableDictionary *layerToSoureDict = [[NSMutableDictionary alloc] init]; - for (RCTMGLSource *touchableSource in touchableSources) { - NSArray *layerIDs = [touchableSource getLayerIDs]; - - for (NSString *layerID in layerIDs) { - layerToSoureDict[layerID] = touchableSource; - } - } - - NSArray *layers = self.style.layers; - for (int i = (int)layers.count - 1; i >= 0; i--) { - MGLStyleLayer *layer = layers[i]; - - RCTMGLSource *source = layerToSoureDict[layer.identifier]; - if (source != nil) { - return source; - } - } - - return nil; -} - -- (NSURL*)_getStyleURLFromKey:(NSString *)styleURL -{ - NSURL *url = [NSURL URLWithString:styleURL]; - if (url) { - return url; - } else if (RCTJSONParse(styleURL, nil)) { - return [RCTMGLUtils styleURLFromStyleJSON:styleURL]; - } - return url; -} - -- (void)_removeAllSourcesFromMap -{ - if (self.style == nil || _sources.count == 0) { - return; - } - for (RCTMGLSource *source in _sources) { - source.map = nil; - } -} - -- (void)didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated { - [_reactCamera didChangeUserTrackingMode:mode animated:animated]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLMapView.swift b/ios/RCTMGL/RCTMGLMapView.swift new file mode 100644 index 0000000000..d2dc520ac5 --- /dev/null +++ b/ios/RCTMGL/RCTMGLMapView.swift @@ -0,0 +1,16 @@ +import MapboxMaps + +@objc class RCTMGLMapView : MapView { + @objc func setReactStyleURL(_ value: String) { + self.style.styleURL = StyleURL.custom(url: URL(string:value)!); + } + + required init(frame:CGRect) { + let resourceOptions = ResourceOptions(accessToken: MGLModule.accessToken!) + super.init(with: frame, resourceOptions: resourceOptions) + } + + required init (coder: NSCoder) { + fatalError("not implemented") + } +} diff --git a/ios/RCTMGL/RCTMGLMapViewManager.h b/ios/RCTMGL/RCTMGLMapViewManager.h deleted file mode 100644 index b2ca19a9f5..0000000000 --- a/ios/RCTMGL/RCTMGLMapViewManager.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// RCTMGLMapViewManager.h -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" -@import Mapbox; - -@interface RCTMGLMapViewManager : ViewManager - -- (void)didTapMap:(UITapGestureRecognizer *)recognizer; -- (void)didLongPressMap:(UILongPressGestureRecognizer *)recognizer; - -@end diff --git a/ios/RCTMGL/RCTMGLMapViewManager.m b/ios/RCTMGL/RCTMGLMapViewManager.m index 95293be3d0..f7e9a598db 100644 --- a/ios/RCTMGL/RCTMGLMapViewManager.m +++ b/ios/RCTMGL/RCTMGLMapViewManager.m @@ -1,624 +1,6 @@ -// -// RCTMGLMapViewManager.m -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// +#import +#import -#import - -#import "RCTMGLMapViewManager.h" -#import "RCTMGLMapView.h" -#import "RCTMGLEventTypes.h" -#import "RCTMGLEvent.h" -#import "RCTMGLMapTouchEvent.h" -#import "RCTMGLUtils.h" -#import "CameraStop.h" -#import "CameraUpdateQueue.h" -#import "RCTMGLUserLocation.h" -#import "FilterParser.h" -#import "RCTMGLImages.h" - -@interface RCTMGLMapViewManager() -@end - -@implementation RCTMGLMapViewManager - - -RCT_EXPORT_MODULE(RCTMGLMapView) - -- (BOOL)requiresMainQueueSetup -{ - return YES; -} - -// prevents SDK from crashing and cluttering logs -// since we don't have access to the frame right away -- (CGRect)defaultFrame -{ - return [[UIScreen mainScreen] bounds]; -} - -- (UIView *)view -{ - RCTMGLMapView *mapView = [[RCTMGLMapView alloc] initWithFrame:[self defaultFrame]]; - mapView.delegate = self; - - - // setup map gesture recongizers - UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil]; - doubleTap.numberOfTapsRequired = 2; - - UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMap:)]; - [tap requireGestureRecognizerToFail:doubleTap]; - - UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPressMap:)]; - - // this allows the internal annotation gestures to take precedents over the map tap gesture - for (int i = 0; i < mapView.gestureRecognizers.count; i++) { - UIGestureRecognizer *gestuerReconginer = mapView.gestureRecognizers[i]; - - if ([gestuerReconginer isKindOfClass:[UITapGestureRecognizer class]]) { - [tap requireGestureRecognizerToFail:gestuerReconginer]; - } - } - - [mapView addGestureRecognizer:doubleTap]; - [mapView addGestureRecognizer:tap]; - [mapView addGestureRecognizer:longPress]; - - return mapView; -} - -#pragma mark - React View Props - -RCT_REMAP_VIEW_PROPERTY(localizeLabels, reactLocalizeLabels, BOOL) -RCT_REMAP_VIEW_PROPERTY(scrollEnabled, reactScrollEnabled, BOOL) -RCT_REMAP_VIEW_PROPERTY(pitchEnabled, reactPitchEnabled, BOOL) -RCT_REMAP_VIEW_PROPERTY(rotateEnabled, reactRotateEnabled, BOOL) -RCT_REMAP_VIEW_PROPERTY(attributionEnabled, reactAttributionEnabled, BOOL) -RCT_REMAP_VIEW_PROPERTY(attributionPosition, reactAttributionPosition, NSDictionary) -RCT_REMAP_VIEW_PROPERTY(logoEnabled, reactLogoEnabled, BOOL) -RCT_REMAP_VIEW_PROPERTY(compassEnabled, reactCompassEnabled, BOOL) -RCT_REMAP_VIEW_PROPERTY(zoomEnabled, reactZoomEnabled, BOOL) - -RCT_REMAP_VIEW_PROPERTY(compassViewPosition, reactCompassViewPosition, NSInteger *) -RCT_REMAP_VIEW_PROPERTY(compassViewMargins, reactCompassViewMargins, CGPoint) - -RCT_REMAP_VIEW_PROPERTY(contentInset, reactContentInset, NSArray) +@interface RCT_EXTERN_MODULE(RCTMGLMapViewManager, RCTViewManager) RCT_REMAP_VIEW_PROPERTY(styleURL, reactStyleURL, NSString) -RCT_REMAP_VIEW_PROPERTY(preferredFramesPerSecond, reactPreferredFramesPerSecond, NSInteger) - -RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor) - -RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) -RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock) -RCT_EXPORT_VIEW_PROPERTY(onMapChange, RCTBubblingEventBlock) - -#pragma mark - React Methods - -RCT_EXPORT_METHOD(getPointInView:(nonnull NSNumber*)reactTag - atCoordinate:(NSArray*)coordinate - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - - CGPoint pointInView = [reactMapView convertCoordinate:CLLocationCoordinate2DMake([coordinate[1] doubleValue], [coordinate[0] doubleValue]) - toPointToView:reactMapView]; - - resolve(@{ @"pointInView": @[@(pointInView.x), @(pointInView.y)] }); - }]; -} - -RCT_EXPORT_METHOD(getCoordinateFromView:(nonnull NSNumber*)reactTag - atPoint:(CGPoint)point - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - - CLLocationCoordinate2D coordinate = [reactMapView convertPoint:point - toCoordinateFromView:reactMapView]; - - resolve(@{ @"coordinateFromView": @[@(coordinate.longitude), @(coordinate.latitude)] }); - }]; -} - - -RCT_EXPORT_METHOD(takeSnap:(nonnull NSNumber*)reactTag - writeToDisk:(BOOL)writeToDisk - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - NSString *uri = [reactMapView takeSnap:writeToDisk]; - resolve(@{ @"uri": uri }); - }]; -} - -RCT_EXPORT_METHOD(getVisibleBounds:(nonnull NSNumber*)reactTag - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - resolve(@{ @"visibleBounds": [RCTMGLUtils fromCoordinateBounds:reactMapView.visibleCoordinateBounds] }); - }]; -} - -RCT_EXPORT_METHOD(getZoom:(nonnull NSNumber*)reactTag - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - resolve(@{ @"zoom": @(reactMapView.zoomLevel) }); - }]; -} - -RCT_EXPORT_METHOD(getCenter:(nonnull NSNumber*)reactTag - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - resolve(@{ @"center": @[@(reactMapView.centerCoordinate.longitude), @(reactMapView.centerCoordinate.latitude)]}); - }]; -} - -RCT_EXPORT_METHOD(queryRenderedFeaturesAtPoint:(nonnull NSNumber*)reactTag - atPoint:(NSArray*)point - withFilter:(NSArray*)filter - withLayerIDs:(NSArray*)layerIDs - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - NSSet *layerIDSet = nil; - if (layerIDs != nil && layerIDs.count > 0) { - layerIDSet = [NSSet setWithArray:layerIDs]; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - NSPredicate* predicate = [FilterParser parse:filter]; - NSArray> *shapes = [reactMapView visibleFeaturesAtPoint:CGPointMake([point[0] floatValue], [point[1] floatValue]) - inStyleLayersWithIdentifiers:layerIDSet - predicate:predicate]; - - NSMutableArray *features = [[NSMutableArray alloc] init]; - for (int i = 0; i < shapes.count; i++) { - [features addObject:shapes[i].geoJSONDictionary]; - } - - resolve(@{ - @"data": @{ @"type": @"FeatureCollection", @"features": features } - }); - }]; -} - -RCT_EXPORT_METHOD(queryRenderedFeaturesInRect:(nonnull NSNumber*)reactTag - withBBox:(NSArray*)bbox - withFilter:(NSArray*)filter - withLayerIDs:(NSArray*)layerIDs - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - - // bbox[top, right, bottom, left] - CGFloat width = [bbox[1] floatValue] - [bbox[3] floatValue]; - CGFloat height = [bbox[0] floatValue] - [bbox[2] floatValue]; - CGRect rect = CGRectMake([bbox[3] floatValue], [bbox[2] floatValue], width, height); - - NSSet *layerIDSet = nil; - if (layerIDs != nil && layerIDs.count > 0) { - layerIDSet = [NSSet setWithArray:layerIDs]; - } - - NSPredicate* predicate = [FilterParser parse:filter]; - NSArray> *shapes = [reactMapView visibleFeaturesInRect:rect - inStyleLayersWithIdentifiers:layerIDSet - predicate:predicate]; - - NSArray* features = [self featuresToJSON:shapes]; - - resolve(@{ @"data": @{ @"type": @"FeatureCollection", @"features": features }}); - }]; -} - -RCT_EXPORT_METHOD(showAttribution:(nonnull NSNumber *)reactTag - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - __weak RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - [reactMapView showAttribution:reactMapView]; - resolve(nil); - }]; -} - -RCT_EXPORT_METHOD(setSourceVisibility:(nonnull NSNumber *)reactTag - visible:(BOOL)visible - sourceId:(nonnull NSString*)sourceId - sourceLayerId:(nullable NSString*)sourceLayerId - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - id view = viewRegistry[reactTag]; - - if (![view isKindOfClass:[RCTMGLMapView class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - __weak RCTMGLMapView *reactMapView = (RCTMGLMapView*)view; - [reactMapView setSourceVisibility:visible sourceId:sourceId sourceLayerId:sourceLayerId]; - resolve(nil); - }]; -} - -#pragma mark - UIGestureRecognizers - -- (void)didTapMap:(UITapGestureRecognizer *)recognizer -{ - RCTMGLMapView *mapView = (RCTMGLMapView*)recognizer.view; - CGPoint screenPoint = [recognizer locationInView:mapView]; - NSArray *touchableSources = [mapView getAllTouchableSources]; - - NSMutableDictionary>* > *hits = [[NSMutableDictionary alloc] init]; - NSMutableArray *hitTouchableSources = [[NSMutableArray alloc] init]; - for (RCTMGLSource *touchableSource in touchableSources) { - NSDictionary *hitbox = touchableSource.hitbox; - float halfWidth = [hitbox[@"width"] floatValue] / 2.f; - float halfHeight = [hitbox[@"height"] floatValue] / 2.f; - - CGFloat top = screenPoint.y - halfHeight; - CGFloat left = screenPoint.x - halfWidth; - CGRect hitboxRect = CGRectMake(left, top, [hitbox[@"width"] floatValue], [hitbox[@"height"] floatValue]); - - NSArray> *features = [mapView visibleFeaturesInRect:hitboxRect - inStyleLayersWithIdentifiers:[NSSet setWithArray:[touchableSource getLayerIDs]] - predicate:nil]; - - if (features.count > 0) { - hits[touchableSource.id] = features; - [hitTouchableSources addObject:touchableSource]; - } - } - - if (hits.count > 0) { - RCTMGLSource *source = [mapView getTouchableSourceWithHighestZIndex:hitTouchableSources]; - if (source != nil && source.hasPressListener) { - NSArray* geoJSONDicts = [self featuresToJSON: hits[source.id]]; - - NSString *eventType = RCT_MAPBOX_VECTOR_SOURCE_LAYER_PRESS; - if ([source isKindOfClass:[RCTMGLShapeSource class]]) { - eventType = RCT_MAPBOX_SHAPE_SOURCE_LAYER_PRESS; - } - - CLLocationCoordinate2D coordinate = [mapView convertPoint:screenPoint - toCoordinateFromView:mapView]; - - RCTMGLEvent *event = [RCTMGLEvent makeEvent:eventType withPayload: @{ - @"features": geoJSONDicts, - @"point": @{ - @"x": [NSNumber numberWithDouble: screenPoint.x], - @"y":[NSNumber numberWithDouble: screenPoint.y] - }, - @"coordinates": @{ - @"latitude": [NSNumber numberWithDouble: coordinate.latitude], - @"longitude": [NSNumber numberWithDouble: coordinate.longitude] - } - }]; - [self fireEvent:event withCallback:source.onPress]; - return; - } - } - - if (mapView.onPress == nil) { - return; - } - - RCTMGLMapTouchEvent *event = [RCTMGLMapTouchEvent makeTapEvent:mapView withPoint:screenPoint]; - [self fireEvent:event withCallback:mapView.onPress]; -} - -- (void)didLongPressMap:(UILongPressGestureRecognizer *)recognizer -{ - RCTMGLMapView *mapView = (RCTMGLMapView*)recognizer.view; - - if (mapView == nil || mapView.onPress == nil || recognizer.state != UIGestureRecognizerStateBegan) { - return; - } - - RCTMGLMapTouchEvent *event = [RCTMGLMapTouchEvent makeLongPressEvent:mapView withPoint:[recognizer locationInView:mapView]]; - [self fireEvent:event withCallback:mapView.onLongPress]; -} - -#pragma mark - MGLMapViewDelegate - -- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id)annotation -{ - if ([annotation isKindOfClass:[MGLUserLocation class]] && mapView.userLocation != nil) { - RCTMGLMapView* reactMapView = ((RCTMGLMapView *) mapView); - if (reactMapView.useNativeUserLocationAnnotationView) { - return nil; - } - return [[RCTMGLUserLocation sharedInstance] hiddenUserAnnotation]; - } - else if ([annotation isKindOfClass:[RCTMGLPointAnnotation class]]) { - RCTMGLPointAnnotation *rctAnnotation = (RCTMGLPointAnnotation *)annotation; - return [rctAnnotation getAnnotationView]; - } - return nil; -} - -- (void)mapView:(MGLMapView *)mapView didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated -{ - RCTMGLMapView* reactMapView = ((RCTMGLMapView *) mapView); - [reactMapView didChangeUserTrackingMode:mode animated:animated]; -} - -- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(nonnull id)annotation -{ - if ([annotation isKindOfClass:[RCTMGLPointAnnotation class]]) { - RCTMGLPointAnnotation *rctAnnotation = (RCTMGLPointAnnotation *)annotation; - - if (rctAnnotation.onSelected != nil) { - RCTMGLMapTouchEvent *event = [RCTMGLMapTouchEvent makeAnnotationTapEvent:rctAnnotation]; - rctAnnotation.onSelected([event toJSON]); - } - } -} - -- (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(nonnull id)annotation -{ - if ([annotation isKindOfClass:[RCTMGLPointAnnotation class]]) { - RCTMGLPointAnnotation *rctAnnotation = (RCTMGLPointAnnotation *)annotation; - - if (rctAnnotation.onDeselected != nil) { - rctAnnotation.onDeselected(nil); - } - } -} - -- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id)annotation { - if ([annotation isKindOfClass:[RCTMGLPointAnnotation class]]) { - RCTMGLPointAnnotation *rctAnnotation = (RCTMGLPointAnnotation *)annotation; - return rctAnnotation.calloutView != nil; - } - return NO; -} - -- (UIView *)mapView:(MGLMapView *)mapView calloutViewForAnnotation:(id)annotation -{ - if ([annotation isKindOfClass:[RCTMGLPointAnnotation class]]) { - RCTMGLPointAnnotation *rctAnnotation = (RCTMGLPointAnnotation *)annotation; - return rctAnnotation.calloutView; - } - return nil; -} - -- (BOOL)mapView:(MGLMapView *)mapView shouldChangeFromCamera:(MGLMapCamera *)oldCamera toCamera:(MGLMapCamera *)newCamera -{ - RCTMGLMapView* reactMapView = ((RCTMGLMapView *) mapView); - return MGLCoordinateBoundsIsEmpty(reactMapView.maxBounds) || MGLCoordinateInCoordinateBounds(newCamera.centerCoordinate, reactMapView.maxBounds); -} - -- (void)mapView:(MGLMapView *)mapView regionWillChangeWithReason:(MGLCameraChangeReason)reason animated:(BOOL)animated -{ - ((RCTMGLMapView *) mapView).isUserInteraction = (BOOL)(reason & ~MGLCameraChangeReasonProgrammatic); - NSDictionary *payload = [self _makeRegionPayload:mapView animated:animated]; - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_WILL_CHANGE_EVENT andPayload:payload]; -} - -- (void)mapViewRegionIsChanging:(MGLMapView *)mapView -{ - NSDictionary *payload = [self _makeRegionPayload:mapView animated:false]; - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_IS_CHANGING andPayload:payload]; -} - -- (void)mapView:(MGLMapView *)mapView regionDidChangeWithReason:(MGLCameraChangeReason)reason animated:(BOOL)animated -{ - if (((reason & MGLCameraChangeReasonTransitionCancelled) == MGLCameraChangeReasonTransitionCancelled) - && ((reason & MGLCameraChangeReasonGesturePan) != MGLCameraChangeReasonGesturePan)) return; - - ((RCTMGLMapView *) mapView).isUserInteraction = (BOOL)(reason & ~MGLCameraChangeReasonProgrammatic); - - NSDictionary *payload = [self _makeRegionPayload:mapView animated:animated]; - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_DID_CHANGE andPayload:payload]; -} - -- (void)mapViewWillStartLoadingMap:(MGLMapView *)mapView -{ - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_LOADING_MAP]; -} - -- (void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView -{ - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_LOADING_MAP]; -} - -- (void)mapViewDidFailLoadingMap:(MGLMapView *)mapView withError:(NSError *)error -{ - NSLog(@"Failed loading map %@", error); - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FAIL_LOADING_MAP]; -} - -- (void)mapViewWillStartRenderingFrame:(MGLMapView *)mapView -{ - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_RENDERING_FRAME]; -} - -- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered -{ - if (fullyRendered) { - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_FRAME_FULLY]; - } else { - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINSIH_RENDERING_FRAME]; - } -} - -- (void)mapViewWillStartRenderingMap:(MGLMapView *)mapView -{ - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_RENDERING_MAP]; -} - -- (void)mapViewDidFinishRenderingMap:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered -{ - if (fullyRendered) { - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_MAP_FULLY]; - } else { - [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_MAP]; - } -} - -- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style -{ - RCTMGLMapView *reactMapView = (RCTMGLMapView*)mapView; - if(reactMapView.reactLocalizeLabels == true) { - [style localizeLabelsIntoLocale:nil]; - } - - for (int i = 0; i < reactMapView.sources.count; i++) { - RCTMGLSource *source = reactMapView.sources[i]; - source.map = reactMapView; - } - for (int i = 0; i < reactMapView.layers.count; i++) { - RCTMGLLayer *layer = reactMapView.layers[i]; - layer.map = reactMapView; - } - - if (reactMapView.light != nil) { - reactMapView.light.map = reactMapView; - } - - [reactMapView notifyStyleLoaded]; - [self reactMapDidChange:reactMapView eventType:RCT_MAPBOX_DID_FINISH_LOADING_STYLE]; -} - --(UIImage *)mapView:(MGLMapView *)mapView didFailToLoadImage:(NSString *)imageName -{ - RCTMGLMapView* reactMapView = ((RCTMGLMapView *) mapView); - NSArray *allImages = [reactMapView getAllImages]; - for (RCTMGLImages *images in allImages) { - if([images addMissingImageToStyle:imageName]) { - // The image was added inside addMissingImageToStyle so we can return nil - return nil; - } - } - - for (RCTMGLImages *images in allImages) { - [images sendImageMissingEvent:imageName]; - } - return nil; -} - -- (void)reactMapDidChange:(MGLMapView*)mapView eventType:(NSString*)type -{ - [self reactMapDidChange:mapView eventType:type andPayload:nil]; -} - -- (void)reactMapDidChange:(MGLMapView*)mapView eventType:(NSString*)type andPayload:(NSDictionary*)payload -{ - RCTMGLMapView *reactMapView = (RCTMGLMapView*)mapView; - RCTMGLEvent *event = [RCTMGLEvent makeEvent:type withPayload:payload]; - [self fireEvent:event withCallback:reactMapView.onMapChange]; -} - -- (NSDictionary*)_makeRegionPayload:(MGLMapView*)mapView animated:(BOOL)animated -{ - RCTMGLMapView *rctMapView = (RCTMGLMapView *)mapView; - MGLPointFeature *feature = [[MGLPointFeature alloc] init]; - feature.coordinate = mapView.centerCoordinate; - feature.attributes = @{ - @"zoomLevel": [NSNumber numberWithDouble:mapView.zoomLevel], - @"heading": [NSNumber numberWithDouble:mapView.camera.heading], - @"pitch": [NSNumber numberWithDouble:mapView.camera.pitch], - @"animated": [NSNumber numberWithBool:animated], - @"isUserInteraction": @(rctMapView.isUserInteraction), - @"visibleBounds": [RCTMGLUtils fromCoordinateBounds:mapView.visibleCoordinateBounds] - }; - return feature.geoJSONDictionary; -} - -- (NSArray *) featuresToJSON:(NSArray> *) features -{ - NSMutableArray *json = [[NSMutableArray alloc] init]; - for(id feature in features) { - [json addObject:feature.geoJSONDictionary]; - } - return json; -} - @end diff --git a/ios/RCTMGL/RCTMGLMapViewManager.swift b/ios/RCTMGL/RCTMGLMapViewManager.swift new file mode 100644 index 0000000000..aaa2fb5221 --- /dev/null +++ b/ios/RCTMGL/RCTMGLMapViewManager.swift @@ -0,0 +1,16 @@ +@objc(RCTMGLMapViewManager) +class RCTMGLMapViewManager: RCTViewManager { + @objc + override static func requiresMainQueueSetup() -> Bool { + return true + } + + func defaultFrame() -> CGRect { + return UIScreen.main.bounds + } + + override func view() -> UIView! { + let result = RCTMGLMapView(frame: self.defaultFrame()) + return result + } +} diff --git a/ios/RCTMGL/RCTMGLNativeUserLocation.h b/ios/RCTMGL/RCTMGLNativeUserLocation.h deleted file mode 100644 index 25d54729ae..0000000000 --- a/ios/RCTMGL/RCTMGLNativeUserLocation.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// RCTMGLCamera.h -// RCTMGL -// -// Created by Nick Italiano on 6/22/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// -#import -#import - -@class RCTMGLMapView; - -@interface RCTMGLNativeUserLocation : UIView - -@property (nonatomic, strong) RCTMGLMapView *map; -@property (nonatomic) BOOL iosShowsUserHeadingIndicator; - -@end diff --git a/ios/RCTMGL/RCTMGLNativeUserLocation.m b/ios/RCTMGL/RCTMGLNativeUserLocation.m deleted file mode 100644 index 6bff974058..0000000000 --- a/ios/RCTMGL/RCTMGLNativeUserLocation.m +++ /dev/null @@ -1,49 +0,0 @@ -// -// RCTMGLCamera.m -// RCTMGL -// -// Created by Nick Italiano on 6/22/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLNativeUserLocation.h" -#import "CameraStop.h" -#import "CameraUpdateQueue.h" -#import "RCTMGLLocation.h" -#import "RCTMGLUtils.h" -#import "RCTMGLLocationManager.h" -#import "RCTMGLEvent.h" -#import "RCTMGLEventTypes.h" -#import "CameraMode.h" - -@implementation RCTMGLNativeUserLocation -{ - -} - -- (void)setMap:(RCTMGLMapView *)map -{ - if (map == nil && _map) { - _map.useNativeUserLocationAnnotationView = NO; - _map.showsUserLocation = NO; - _map.showsUserHeadingIndicator = NO; - } else if (map) { - map.useNativeUserLocationAnnotationView = YES; - // Toggle off/on showsUserLocation in order for Mapbox to invalidate the - // current (hidden) user location annotation view. See also: HiddenUserLocationAnnotationView - map.showsUserLocation = NO; - map.showsUserLocation = YES; - map.showsUserHeadingIndicator = self.iosShowsUserHeadingIndicator; - } - - _map = map; -} - -- (void)setIosShowsUserHeadingIndicator:(BOOL)iosShowsUserHeadingIndicator { - _iosShowsUserHeadingIndicator = iosShowsUserHeadingIndicator; - if (_map) { - _map.showsUserHeadingIndicator = iosShowsUserHeadingIndicator; - } -} - -@end diff --git a/ios/RCTMGL/RCTMGLNativeUserLocationManager.h b/ios/RCTMGL/RCTMGLNativeUserLocationManager.h deleted file mode 100644 index 5258a4d6f3..0000000000 --- a/ios/RCTMGL/RCTMGLNativeUserLocationManager.h +++ /dev/null @@ -1,5 +0,0 @@ -#import "ViewManager.h" - -@interface RCTMGLNativeUserLocationManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLNativeUserLocationManager.m b/ios/RCTMGL/RCTMGLNativeUserLocationManager.m deleted file mode 100644 index 9eb42f6fd6..0000000000 --- a/ios/RCTMGL/RCTMGLNativeUserLocationManager.m +++ /dev/null @@ -1,25 +0,0 @@ -#import "RCTMGLNativeUserLocationManager.h" -#import "RCTMGLNativeUserLocation.h" - -@implementation RCTMGLNativeUserLocationManager - -RCT_EXPORT_MODULE(RCTMGLNativeUserLocation) -RCT_EXPORT_VIEW_PROPERTY(iosShowsUserHeadingIndicator, BOOL) - - -#pragma - View Properties - - -#pragma Methods - -- (BOOL)requiresMainQueueSetup -{ - return YES; -} - -- (UIView *)view -{ - return [[RCTMGLNativeUserLocation alloc] init]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLOfflineModule.m b/ios/RCTMGL/RCTMGLOfflineModule.m new file mode 100644 index 0000000000..cc6734fcae --- /dev/null +++ b/ios/RCTMGL/RCTMGLOfflineModule.m @@ -0,0 +1,4 @@ +#import "React/RCTBridgeModule.h" + +@interface RCT_EXTERN_MODULE(RCTMGLOfflineModule, NSObject) +@end diff --git a/ios/RCTMGL/RCTMGLOfflineModule.swift b/ios/RCTMGL/RCTMGLOfflineModule.swift new file mode 100644 index 0000000000..6bf4fd6f44 --- /dev/null +++ b/ios/RCTMGL/RCTMGLOfflineModule.swift @@ -0,0 +1,18 @@ +import Foundation +import MapboxMaps + +@objc(RCTMGLOfflineModule) +class RCTMGLOfflineModule: NSObject { + + @objc + static func requiresMainQueueSetup() -> Bool { + return true + } + + @objc + func constantsToExport() -> [AnyHashable: Any]! { + return [ + "foo": "bar" + ]; + } +} diff --git a/ios/RCTMGL/RCTMGLPointAnnotation.h b/ios/RCTMGL/RCTMGLPointAnnotation.h deleted file mode 100644 index 1fdd014a67..0000000000 --- a/ios/RCTMGL/RCTMGLPointAnnotation.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// RCTMGLPointAnnotation.h -// RCTMGL -// -// Created by Nick Italiano on 10/12/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import -#import -#import "RCTMGLCallout.h" - -@import Mapbox; - -@interface RCTMGLPointAnnotation : MGLAnnotationView - -@property (nonatomic, weak) MGLMapView *map; -@property (nonatomic, strong) RCTMGLCallout *calloutView; - -@property (nonatomic, copy) NSString *id; -@property (nonatomic, copy) NSString *reactTitle; -@property (nonatomic, copy) NSString *reactSnippet; - -@property (nonatomic, copy) NSString *reactCoordinate; -@property (nonatomic, assign) CLLocationCoordinate2D coordinate; - -@property (nonatomic, copy) NSDictionary *anchor; - -@property (nonatomic, copy) RCTBubblingEventBlock onSelected; -@property (nonatomic, copy) RCTBubblingEventBlock onDeselected; -@property (nonatomic, copy) RCTBubblingEventBlock onDragStart; -@property (nonatomic, copy) RCTBubblingEventBlock onDrag; -@property (nonatomic, copy) RCTBubblingEventBlock onDragEnd; - -@property (nonatomic, assign) BOOL reactSelected; -@property (nonatomic, assign) BOOL reactDraggable; - -- (MGLAnnotationView *)getAnnotationView; - -@end diff --git a/ios/RCTMGL/RCTMGLPointAnnotation.m b/ios/RCTMGL/RCTMGLPointAnnotation.m deleted file mode 100644 index e68501460f..0000000000 --- a/ios/RCTMGL/RCTMGLPointAnnotation.m +++ /dev/null @@ -1,252 +0,0 @@ -// -// RCTMGLPointAnnotation.m -// RCTMGL -// -// Created by Nick Italiano on 10/12/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLPointAnnotation.h" -#import "RCTMGLMapTouchEvent.h" -#import "RCTMGLUtils.h" -#import "UIView+React.h" - -const float CENTER_X_OFFSET_BASE = -0.5f; -const float CENTER_Y_OFFSET_BASE = -0.5f; - -@implementation RCTMGLPointAnnotation -{ - UITapGestureRecognizer *customViewTap; -} - -- (id)init -{ - if (self = [super init]) { - customViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTap:)]; - } - return self; -} - -- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex -{ - if ([subview isKindOfClass:[RCTMGLCallout class]]) { - self.calloutView = (RCTMGLCallout *)subview; - self.calloutView.representedObject = self; - } else { - [super insertReactSubview:subview atIndex:0]; - } -} - -- (void)removeReactSubview:(UIView *)subview -{ - if ([subview isKindOfClass:[RCTMGLCallout class]]) { - self.calloutView = nil; - } else { - [super removeReactSubview:subview]; - } -} - -- (void)reactSetFrame:(CGRect)frame -{ - if ([_map.annotations containsObject:self]) { - [_map removeAnnotation:self]; - } - [super reactSetFrame:frame]; - [self _setCenterOffset:frame]; - [self _addAnnotation]; -} - -- (void)setAnchor:(NSDictionary *)anchor -{ - _anchor = anchor; - [self _setCenterOffset:self.frame]; -} - -- (void)setMap:(MGLMapView *)map -{ - if (map == nil) { - [_map removeAnnotation:self]; - _map = nil; - } else { - _map = map; - - // prevents annotations from flying in from the top left corner - // if the frame hasn't been set yet - if (![self _isFrameSet]) { - return; - } - - [self _addAnnotation]; - } -} - -- (void)setReactSelected:(BOOL)reactSelected -{ - _reactSelected = reactSelected; - - if (_map != nil) { - if (_reactSelected) { - [_map selectAnnotation:self animated:NO completionHandler:nil]; - } else { - [_map deselectAnnotation:self animated:NO]; - } - } -} - -- (void)setReactDraggable:(BOOL)reactDraggable -{ - _reactDraggable = reactDraggable; - self.draggable = _reactDraggable; -} - -- (void)setReactCoordinate:(NSString *)reactCoordinate -{ - _reactCoordinate = reactCoordinate; - [self _updateCoordinate]; -} - -- (NSString *)reuseIdentifier -{ - return _id; -} - -- (NSString *)title -{ - return _reactTitle; -} - -- (NSString *)subtitle -{ - return _reactSnippet; -} - -- (NSString *)toolTip -{ - return _reactTitle; -} - -- (MGLAnnotationView *)getAnnotationView -{ - if (self.reactSubviews.count == 0) { - // default pin view - return nil; - } else { - // custom view - self.enabled = YES; - const CGFloat defaultZPosition = 0.0; - if (self.layer.zPosition == defaultZPosition) { - self.layer.zPosition = [self _getZPosition]; - } - [self addGestureRecognizer:customViewTap]; - return self; - } -} - -- (CGFloat)_getZPosition -{ - double latitudeMax = 90.0; - return latitudeMax - self.coordinate.latitude; -} - -- (void)_handleTap:(UITapGestureRecognizer *)recognizer -{ - [_map selectAnnotation:self animated:NO completionHandler:nil]; -} - -- (void)_setCenterOffset:(CGRect)frame -{ - if (frame.size.width == 0 || frame.size.height == 0 || _anchor == nil) { - return; - } - - float x = [_anchor[@"x"] floatValue]; - float y = [_anchor[@"y"] floatValue]; - - // (fullWidthOffset - centerWidthOffset) / 2 - float dx = -(x * frame.size.width - (frame.size.width / 2)) / 2; - float dy = -(y * frame.size.height - (frame.size.height / 2)) / 2; - - // special cases 0 and 1 - - if (x == 0) { - dx = frame.size.width / 2; - } else if (x == 1) { - dy = -frame.size.height / 2; - } - - if (y == 0) { - dy = frame.size.width / 2; - } else if (y == 1) { - dy = -frame.size.height / 2; - } - - self.centerOffset = CGVectorMake(dx, dy); -} - - -- (void)_updateCoordinate -{ - if (_reactCoordinate == nil) { - return; - } - - MGLPointFeature *feature = (MGLPointFeature *)[RCTMGLUtils shapeFromGeoJSON:_reactCoordinate]; - if (feature == nil) { - return; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - self.coordinate = feature.coordinate; - }); -} - -- (void)_addAnnotation -{ - if ([_map.annotations containsObject:self]) { - return; - } - - [_map addAnnotation:self]; - if (_reactSelected) { - [_map selectAnnotation:self animated:NO completionHandler:nil]; - } -} - -- (BOOL)_isFrameSet -{ - return self.frame.size.width > 0 && self.frame.size.height > 0; -} - -- (void)setDragState:(MGLAnnotationViewDragState)dragState animated:(BOOL)animated { - [super setDragState:dragState animated:animated]; - switch (dragState) { - case MGLAnnotationViewDragStateStarting: { - if (self.onDragStart != nil) { - RCTMGLMapTouchEvent *event = [RCTMGLMapTouchEvent makeAnnotationTapEvent:self]; - self.onDragStart([event toJSON]); - } - break; - } - - case MGLAnnotationViewDragStateDragging: - if (self.onDrag != nil) { - RCTMGLMapTouchEvent *event = [RCTMGLMapTouchEvent makeAnnotationTapEventOnDrag:self]; - self.onDrag([event toJSON]); - } - break; - - case MGLAnnotationViewDragStateEnding: - case MGLAnnotationViewDragStateCanceling: { - if (self.onDragEnd != nil) { - RCTMGLMapTouchEvent *event = [RCTMGLMapTouchEvent makeAnnotationTapEvent:self]; - self.onDragEnd([event toJSON]); - } - break; - } - - case MGLAnnotationViewDragStateNone: - return; - } -} - -@end diff --git a/ios/RCTMGL/RCTMGLPointAnnotationManager.h b/ios/RCTMGL/RCTMGLPointAnnotationManager.h deleted file mode 100644 index fcbf7c7f10..0000000000 --- a/ios/RCTMGL/RCTMGLPointAnnotationManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLPointAnnotationManager.h -// RCTMGL -// -// Created by Nick Italiano on 10/12/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLPointAnnotationManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLPointAnnotationManager.m b/ios/RCTMGL/RCTMGLPointAnnotationManager.m deleted file mode 100644 index 164d406740..0000000000 --- a/ios/RCTMGL/RCTMGLPointAnnotationManager.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// RCTMGLPointAnnotationManager.m -// RCTMGL -// -// Created by Nick Italiano on 10/12/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLPointAnnotationManager.h" -#import "RCTMGLPointAnnotation.h" - -@implementation RCTMGLPointAnnotationManager - -RCT_EXPORT_MODULE() - -RCT_EXPORT_VIEW_PROPERTY(id, NSString) -RCT_EXPORT_VIEW_PROPERTY(anchor, NSDictionary) - -RCT_REMAP_VIEW_PROPERTY(selected, reactSelected, BOOL) -RCT_REMAP_VIEW_PROPERTY(title, reactTitle, NSString) -RCT_REMAP_VIEW_PROPERTY(snippet, reactSnippet, NSString) -RCT_REMAP_VIEW_PROPERTY(coordinate, reactCoordinate, NSString) -RCT_REMAP_VIEW_PROPERTY(draggable, reactDraggable, BOOL) - -RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationSelected, onSelected, RCTBubblingEventBlock) -RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDeselected, onDeselected, RCTBubblingEventBlock) -RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDragStart, onDragStart, RCTBubblingEventBlock) -RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDrag, onDrag, RCTBubblingEventBlock) -RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDragEnd, onDragEnd, RCTBubblingEventBlock) - -- (UIView *)view -{ - return [[RCTMGLPointAnnotation alloc] init]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLRasterLayer.h b/ios/RCTMGL/RCTMGLRasterLayer.h deleted file mode 100644 index af47421220..0000000000 --- a/ios/RCTMGL/RCTMGLRasterLayer.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// RCTMGLRasterLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLayer.h" -@import Mapbox; - -@interface RCTMGLRasterLayer : RCTMGLLayer - -@end diff --git a/ios/RCTMGL/RCTMGLRasterLayer.m b/ios/RCTMGL/RCTMGLRasterLayer.m deleted file mode 100644 index aacc1437f8..0000000000 --- a/ios/RCTMGL/RCTMGLRasterLayer.m +++ /dev/null @@ -1,30 +0,0 @@ -// -// RCTMGLRasterLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLRasterLayer.h" -#import "RCTMGLStyle.h" - -@implementation RCTMGLRasterLayer - -- (MGLStyleLayer*)makeLayer:(MGLStyle*)style -{ - MGLSource *source = [style sourceWithIdentifier:self.sourceID]; - if (source == nil) { return nil; } - MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithIdentifier:self.id source:source]; - return layer; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style rasterLayer:(MGLRasterStyleLayer*)self.styleLayer withReactStyle:self.reactStyle isValid:^{ return [self isAddedToMap]; - }]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLRasterLayerManager.h b/ios/RCTMGL/RCTMGLRasterLayerManager.h deleted file mode 100644 index cc6d56adde..0000000000 --- a/ios/RCTMGL/RCTMGLRasterLayerManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLRasterLayerManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLRasterLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLRasterLayerManager.m b/ios/RCTMGL/RCTMGLRasterLayerManager.m deleted file mode 100644 index 7d8dba840e..0000000000 --- a/ios/RCTMGL/RCTMGLRasterLayerManager.m +++ /dev/null @@ -1,35 +0,0 @@ -// -// RCTMGLRasterLayerManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLRasterLayerManager.h" -#import "RCTMGLRasterLayer.h" - -@implementation RCTMGLRasterLayerManager - -RCT_EXPORT_MODULE() - -// standard layer props -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLRasterLayer *layer = [[RCTMGLRasterLayer alloc] init]; - layer.bridge = self.bridge; - return layer; -} - -@end diff --git a/ios/RCTMGL/RCTMGLRasterSource.h b/ios/RCTMGL/RCTMGLRasterSource.h deleted file mode 100644 index c9b60012cd..0000000000 --- a/ios/RCTMGL/RCTMGLRasterSource.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// RCTMGLRasterSource.h -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLTileSource.h" -@import Mapbox; - -@interface RCTMGLRasterSource : RCTMGLTileSource - -@property (nonatomic, strong) NSNumber *tileSize; - -@end diff --git a/ios/RCTMGL/RCTMGLRasterSource.m b/ios/RCTMGL/RCTMGLRasterSource.m deleted file mode 100644 index 049da0db87..0000000000 --- a/ios/RCTMGL/RCTMGLRasterSource.m +++ /dev/null @@ -1,35 +0,0 @@ -// -// RCTMGLRasterSource.m -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLRasterSource.h" - -@implementation RCTMGLRasterSource - -- (nullable MGLSource*)makeSource -{ - if (self.url != nil) { - NSURL *url = [NSURL URLWithString:self.url]; - if (self.tileSize != nil) { - return [[MGLRasterTileSource alloc] initWithIdentifier:self.id configurationURL:url tileSize:[self.tileSize floatValue]]; - } - return [[MGLRasterTileSource alloc] initWithIdentifier:self.id configurationURL:url]; - } - return [[MGLRasterTileSource alloc] initWithIdentifier:self.id tileURLTemplates:self.tileUrlTemplates options:[self getOptions]]; -} - -- (NSDictionary *)getOptions { - NSMutableDictionary *options = [[NSMutableDictionary alloc] initWithDictionary:[super getOptions]]; - - if (self.tileSize != nil) { - options[MGLTileSourceOptionTileSize] = _tileSize; - } - - return options; -} - -@end diff --git a/ios/RCTMGL/RCTMGLRasterSourceManager.h b/ios/RCTMGL/RCTMGLRasterSourceManager.h deleted file mode 100644 index b654b4b94d..0000000000 --- a/ios/RCTMGL/RCTMGLRasterSourceManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLRasterSourceManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLRasterSourceManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLRasterSourceManager.m b/ios/RCTMGL/RCTMGLRasterSourceManager.m deleted file mode 100644 index d5da4a4dce..0000000000 --- a/ios/RCTMGL/RCTMGLRasterSourceManager.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// RCTMGLRasterSourceManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/25/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLRasterSourceManager.h" -#import "RCTMGLRasterSource.h" - -@implementation RCTMGLRasterSourceManager - -RCT_EXPORT_MODULE() - -RCT_EXPORT_VIEW_PROPERTY(id, NSString) -RCT_EXPORT_VIEW_PROPERTY(url, NSString) -RCT_EXPORT_VIEW_PROPERTY(tileUrlTemplates, NSArray) -RCT_EXPORT_VIEW_PROPERTY(attribution, NSString) - -RCT_EXPORT_VIEW_PROPERTY(tileSize, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber) - -RCT_EXPORT_VIEW_PROPERTY(tms, BOOL) - -- (UIView*)view -{ - return [RCTMGLRasterSource new]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLShapeSource.h b/ios/RCTMGL/RCTMGLShapeSource.h deleted file mode 100644 index d848555020..0000000000 --- a/ios/RCTMGL/RCTMGLShapeSource.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// RCTMGLShapeSource.h -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLSource.h" - -@import Mapbox; - -@interface RCTMGLShapeSource : RCTMGLSource - -@property (nonatomic, weak) RCTBridge *bridge; - -@property (nonatomic, copy) NSString *url; -@property (nonatomic, copy) NSString *shape; - -@property (nonatomic, strong) NSNumber *cluster; -@property (nonatomic, strong) NSNumber *clusterRadius; -@property (nonatomic, strong) NSNumber *clusterMaxZoomLevel; - -@property (nonatomic, strong) NSNumber *maxZoomLevel; -@property (nonatomic, strong) NSNumber *buffer; -@property (nonatomic, strong) NSNumber *tolerance; - -@property (nonatomic, copy) RCTBubblingEventBlock onPress; -@property (nonatomic, assign) BOOL hasPressListener; - -- (nonnull NSArray> *)featuresMatchingPredicate:(nullable NSPredicate *)predicate; - -@end diff --git a/ios/RCTMGL/RCTMGLShapeSource.m b/ios/RCTMGL/RCTMGLShapeSource.m deleted file mode 100644 index 524fb07569..0000000000 --- a/ios/RCTMGL/RCTMGLShapeSource.m +++ /dev/null @@ -1,107 +0,0 @@ -// -// RCTMGLShapeSource.m -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLShapeSource.h" -#import "RCTMGLUtils.h" -#import "RCTMGLMapView.h" - -@implementation RCTMGLShapeSource - -static UIImage * _placeHolderImage; - -- (void)setUrl: (NSString*) url -{ - _url = url; - if (self.source != nil) { - MGLShapeSource *source = (MGLShapeSource *)self.source; - [source setURL: url == nil ? nil : [NSURL URLWithString:url]]; - } -} - -- (void)setShape:(NSString *)shape -{ - _shape = shape; - - if (self.source != nil) { - MGLShapeSource *source = (MGLShapeSource *)self.source; - [source setShape: shape == nil ? nil : [RCTMGLUtils shapeFromGeoJSON:_shape]]; - } -} - -- (void)addToMap -{ - if (self.map.style == nil) { - return; - } - [super addToMap]; -} - -- (void)removeFromMap -{ - if (self.map.style == nil) { - return; - } - - [super removeFromMap]; -} - -- (nullable MGLSource*)makeSource -{ - NSDictionary *options = [self _getOptions]; - - if (_shape != nil) { - MGLShape *shape = [RCTMGLUtils shapeFromGeoJSON:_shape]; - return [[MGLShapeSource alloc] initWithIdentifier:self.id shape:shape options:options]; - } - - if (_url != nil) { - NSURL *url = [[NSURL alloc] initWithString:_url]; - return [[MGLShapeSource alloc] initWithIdentifier:self.id URL:url options:options]; - } - return nil; -} - -- (NSDictionary*)_getOptions -{ - NSMutableDictionary *options = [[NSMutableDictionary alloc] init]; - - if (_cluster != nil) { - options[MGLShapeSourceOptionClustered] = [NSNumber numberWithBool:[_cluster intValue] == 1]; - } - - if (_clusterRadius != nil) { - options[MGLShapeSourceOptionClusterRadius] = _clusterRadius; - } - - if (_clusterMaxZoomLevel != nil) { - options[MGLShapeSourceOptionMaximumZoomLevelForClustering] = _clusterMaxZoomLevel; - } - - if (_maxZoomLevel != nil) { - options[MGLShapeSourceOptionMaximumZoomLevel] = _maxZoomLevel; - } - - if (_buffer != nil) { - options[MGLShapeSourceOptionBuffer] = _buffer; - } - - if (_tolerance != nil) { - options[MGLShapeSourceOptionSimplificationTolerance] = _tolerance; - } - - return options; -} - -- (nonnull NSArray> *)featuresMatchingPredicate:(nullable NSPredicate *)predicate -{ - MGLShapeSource *shapeSource = (MGLShapeSource *)self.source; - - return [shapeSource featuresMatchingPredicate:predicate]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLShapeSourceManager.h b/ios/RCTMGL/RCTMGLShapeSourceManager.h deleted file mode 100644 index 4fde63538f..0000000000 --- a/ios/RCTMGL/RCTMGLShapeSourceManager.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// RCTMGLShapeSourceManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" -#import - -@interface RCTMGLShapeSourceManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLShapeSourceManager.m b/ios/RCTMGL/RCTMGLShapeSourceManager.m deleted file mode 100644 index 9e067a4f7d..0000000000 --- a/ios/RCTMGL/RCTMGLShapeSourceManager.m +++ /dev/null @@ -1,70 +0,0 @@ -// -// RCTMGLShapeSourceManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// -#import - -#import "RCTMGLShapeSourceManager.h" -#import "RCTMGLShapeSource.h" - -#import "FilterParser.h" - -@implementation RCTMGLShapeSourceManager - -RCT_EXPORT_MODULE(RCTMGLShapeSource) - -RCT_EXPORT_VIEW_PROPERTY(id, NSString) -RCT_EXPORT_VIEW_PROPERTY(url, NSString) -RCT_EXPORT_VIEW_PROPERTY(shape, NSString) - -RCT_EXPORT_VIEW_PROPERTY(cluster, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(clusterRadius, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(clusterMaxZoomLevel, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(buffer, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(tolerance, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(images, NSDictionary) -RCT_EXPORT_VIEW_PROPERTY(nativeImages, NSArray) -RCT_EXPORT_VIEW_PROPERTY(hasPressListener, BOOL) -RCT_EXPORT_VIEW_PROPERTY(hitbox, NSDictionary) -RCT_REMAP_VIEW_PROPERTY(onMapboxShapeSourcePress, onPress, RCTBubblingEventBlock) - -- (UIView*)view -{ - RCTMGLShapeSource *source = [RCTMGLShapeSource new]; - source.bridge = self.bridge; - return source; -} - -RCT_EXPORT_METHOD(features:(nonnull NSNumber*)reactTag - withFilter:(NSArray *)filter - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - RCTMGLShapeSource* shapeSource = viewRegistry[reactTag]; - - if (![shapeSource isKindOfClass:[RCTMGLShapeSource class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - NSPredicate* predicate = [FilterParser parse:filter]; - NSArray> *shapes = [shapeSource featuresMatchingPredicate: predicate]; - - NSMutableArray *features = [[NSMutableArray alloc] initWithCapacity:shapes.count]; - for (int i = 0; i < shapes.count; i++) { - [features addObject:shapes[i].geoJSONDictionary]; - } - - resolve(@{ - @"data": @{ @"type": @"FeatureCollection", @"features": features } - }); - }]; -} - - -@end diff --git a/ios/RCTMGL/RCTMGLSource.h b/ios/RCTMGL/RCTMGLSource.h deleted file mode 100644 index 03c66c5e1f..0000000000 --- a/ios/RCTMGL/RCTMGLSource.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// BaseSource.h -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLLayer.h" -#import -@import Mapbox; - -@interface RCTMGLSource : UIView - -extern NSString * _Nonnull const DEFAULT_SOURCE_ID; - -@property (nonatomic, strong) NSMutableArray> *reactSubviews; -@property (nonatomic, strong) NSMutableArray *layers; -@property (nonatomic, strong) MGLSource *source; -@property (nonatomic, strong) RCTMGLMapView *map; -@property (nonatomic, strong) NSDictionary *hitbox; - -@property (nonatomic, copy) NSString *id; -@property (nonatomic, assign) BOOL hasPressListener; -@property (nonatomic, copy) RCTBubblingEventBlock onPress; - -- (void)addToMap; -- (void)removeFromMap; -- (nullable MGLSource*)makeSource; -- (NSArray *)getLayerIDs; - -+ (BOOL)isDefaultSource:(NSString*)sourceID; - -@end diff --git a/ios/RCTMGL/RCTMGLSource.m b/ios/RCTMGL/RCTMGLSource.m deleted file mode 100644 index 9886602905..0000000000 --- a/ios/RCTMGL/RCTMGLSource.m +++ /dev/null @@ -1,143 +0,0 @@ -// -// BaseSource.m -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLSource.h" -#import "UIView+React.h" -#import "RCTMGLMapView.h" -#import - -@implementation RCTMGLSource - -double const DEFAULT_HITBOX_AREA = 44.0; -NSString *const DEFAULT_SOURCE_ID = @"composite"; - - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - _layers = [[NSMutableArray alloc] init]; - _reactSubviews = [[NSMutableArray alloc] init]; - _hitbox = @{ @"width": @(DEFAULT_HITBOX_AREA), @"height": @(DEFAULT_HITBOX_AREA) }; - } - return self; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (void)insertReactSubview:(id)subview atIndex:(NSInteger)atIndex { - if ([subview isKindOfClass:[RCTMGLLayer class]]) { - RCTMGLLayer *layer = (RCTMGLLayer*)subview; - - if (_map.style != nil) { - [layer addToMap:_map style:_map.style]; - } - - [_layers addObject:layer]; - [_reactSubviews insertObject:layer atIndex:atIndex]; - } -} -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (void)removeReactSubview:(id)subview { - if ([subview isKindOfClass:[RCTMGLLayer class]]) { - RCTMGLLayer *layer = (RCTMGLLayer*)subview; - [layer removeFromMap:_map.style]; - [_layers removeObject:layer]; - [_reactSubviews removeObject:layer]; - } -} -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (NSArray> *)reactSubviews { - return _reactSubviews; -} -#pragma clang diagnostic pop - -- (void)setMap:(RCTMGLMapView *)map -{ - if (map == nil) { - [self removeFromMap]; - _map = nil; - } else { - _map = map; - [self addToMap]; - } -} - -- (void)addToMap -{ - if (_map.style == nil) { - return; - } - - MGLSource *existingSource = [_map.style sourceWithIdentifier:_id]; - if (existingSource != nil) { - _source = existingSource; - } else { - _source = [self makeSource]; - if (_source != nil) { - [_map.style addSource:_source]; - } else { - RCTLogError(@"Could not create source with id:%@. Make sure url/shape is provided", _id); - } - } - - if (_layers.count > 0) { - for (int i = 0; i < _layers.count; i++) { - RCTMGLLayer *layer = [_layers objectAtIndex:i]; - [layer addToMap:_map style:_map.style]; - } - } -} - -- (void)removeFromMap -{ - if (_map.style == nil) { - return; - } - - for (int i = 0; i < _layers.count; i++) { - RCTMGLLayer *layer = [_layers objectAtIndex:i]; - [layer removeFromMap:_map.style]; - } - - if (![RCTMGLSource isDefaultSource:_id]) { - if (_source != nil) { - [_map.style removeSource:_source]; - } - } -} - -- (nullable MGLSource*)makeSource -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] - userInfo:nil]; -} - -- (NSArray *)getLayerIDs -{ - NSMutableArray *layerIDs = [[NSMutableArray alloc] init]; - - for (RCTMGLLayer *layer in _layers) { - [layerIDs addObject:layer.id]; - } - - return layerIDs; -} - -+ (BOOL)isDefaultSource:(NSString *)sourceID -{ - return [sourceID isEqualToString:DEFAULT_SOURCE_ID]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLStyle.h b/ios/RCTMGL/RCTMGLStyle.h deleted file mode 100644 index c1fe31ed73..0000000000 --- a/ios/RCTMGL/RCTMGLStyle.h +++ /dev/null @@ -1,219 +0,0 @@ -// DO NOT MODIFY -// THIS FILE IS AUTOGENERATED - -#import "RCTMGLStyle.h" -#import "RCTMGLStyleValue.h" -#import - -@import Mapbox; - -@interface RCTMGLStyle : NSObject - -@property (nonatomic, weak) RCTBridge *bridge; -@property (nonatomic, strong) MGLStyle *style; - -- (id)initWithMGLStyle:(MGLStyle*)mglStyle; - -- (void)fillLayer:(MGLFillStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)lineLayer:(MGLLineStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)symbolLayer:(MGLSymbolStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)circleLayer:(MGLCircleStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)heatmapLayer:(MGLHeatmapStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)fillExtrusionLayer:(MGLFillExtrusionStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)rasterLayer:(MGLRasterStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)hillshadeLayer:(MGLHillshadeStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)backgroundLayer:(MGLBackgroundStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; -- (void)lightLayer:(MGLLight *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid; - -- (void)setFillStyleLayerVisibility:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillAntialias:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillOpacity:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillOpacityTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillColor:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillColorTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillOutlineColor:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillOutlineColorTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillTranslate:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillTranslateTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillTranslateAnchor:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillPattern:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillPatternTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineCap:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineJoin:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineMiterLimit:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineRoundLimit:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineStyleLayerVisibility:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineOpacity:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineOpacityTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineColor:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineColorTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineTranslate:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineTranslateTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineTranslateAnchor:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineWidth:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineWidthTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineGapWidth:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineGapWidthTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineOffset:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineOffsetTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineBlur:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineBlurTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineDasharray:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineDasharrayTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLinePattern:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLinePatternTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setLineGradient:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setSymbolPlacement:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setSymbolSpacing:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setSymbolAvoidEdges:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setSymbolSortKey:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setSymbolZOrder:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconAllowOverlap:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconIgnorePlacement:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconOptional:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconRotationAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconSize:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconTextFit:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconTextFitPadding:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconImage:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconRotate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconPadding:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconKeepUpright:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconOffset:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconPitchAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextPitchAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextRotationAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextField:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextFont:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextSize:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextMaxWidth:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextLineHeight:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextLetterSpacing:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextJustify:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextRadialOffset:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextVariableAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextMaxAngle:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextWritingMode:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextRotate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextPadding:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextKeepUpright:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextTransform:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextOffset:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextAllowOverlap:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextIgnorePlacement:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextOptional:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setSymbolStyleLayerVisibility:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconOpacity:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconOpacityTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconHaloColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconHaloColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconHaloWidth:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconHaloWidthTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconHaloBlur:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconHaloBlurTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconTranslate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconTranslateTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIconTranslateAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextOpacity:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextOpacityTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextHaloColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextHaloColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextHaloWidth:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextHaloWidthTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextHaloBlur:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextHaloBlurTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextTranslate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextTranslateTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setTextTranslateAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleStyleLayerVisibility:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleRadius:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleRadiusTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleColor:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleColorTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleBlur:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleBlurTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleOpacity:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleOpacityTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleTranslate:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleTranslateTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleTranslateAnchor:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCirclePitchScale:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCirclePitchAlignment:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleStrokeWidth:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleStrokeWidthTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleStrokeColor:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleStrokeColorTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleStrokeOpacity:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setCircleStrokeOpacityTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapStyleLayerVisibility:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapRadius:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapRadiusTransition:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapWeight:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapIntensity:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapIntensityTransition:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapColor:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapOpacity:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHeatmapOpacityTransition:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionStyleLayerVisibility:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionOpacity:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionOpacityTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionColor:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionColorTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionTranslate:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionTranslateTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionTranslateAnchor:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionPattern:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionPatternTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionHeight:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionHeightTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionBase:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setFillExtrusionBaseTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterStyleLayerVisibility:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterOpacity:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterOpacityTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterHueRotate:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterHueRotateTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterBrightnessMin:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterBrightnessMinTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterBrightnessMax:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterBrightnessMaxTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterSaturation:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterSaturationTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterContrast:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterContrastTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterResampling:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setRasterFadeDuration:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeStyleLayerVisibility:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeIlluminationDirection:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeIlluminationAnchor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeExaggeration:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeExaggerationTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeShadowColor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeShadowColorTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeHighlightColor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeHighlightColorTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeAccentColor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setHillshadeAccentColorTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setBackgroundStyleLayerVisibility:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setBackgroundColor:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setBackgroundColorTransition:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setBackgroundPattern:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setBackgroundPatternTransition:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setBackgroundOpacity:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setBackgroundOpacityTransition:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setAnchor:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setPosition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setPositionTransition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setColor:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setColorTransition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIntensity:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; -- (void)setIntensityTransition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue; - - -@end diff --git a/ios/RCTMGL/RCTMGLStyle.m b/ios/RCTMGL/RCTMGLStyle.m deleted file mode 100644 index 6723baca89..0000000000 --- a/ios/RCTMGL/RCTMGLStyle.m +++ /dev/null @@ -1,1654 +0,0 @@ -// DO NOT MODIFY -// THIS FILE IS AUTOGENERATED - -#import "RCTMGLStyle.h" -#import "RCTMGLUtils.h" - -@implementation RCTMGLStyle - -- (id)initWithMGLStyle:(MGLStyle*)mglStyle -{ - if (self = [super init]) { - _style = mglStyle; - } - return self; -} - - -- (void)fillLayer:(MGLFillStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"visibility"]) { - [self setFillStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillAntialias"]) { - [self setFillAntialias:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillOpacity"]) { - [self setFillOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillOpacityTransition"]) { - [self setFillOpacityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillColor"]) { - [self setFillColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillColorTransition"]) { - [self setFillColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillOutlineColor"]) { - [self setFillOutlineColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillOutlineColorTransition"]) { - [self setFillOutlineColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillTranslate"]) { - [self setFillTranslate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillTranslateTransition"]) { - [self setFillTranslateTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillTranslateAnchor"]) { - [self setFillTranslateAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillPattern"]) { - if (![styleValue shouldAddImage]) { - [self setFillPattern:layer withReactStyleValue:styleValue]; - } else { - NSString *imageURI = [styleValue getImageURI]; - - [RCTMGLUtils fetchImage:_bridge url:imageURI scale:[styleValue getImageScale] callback:^(NSError *error, UIImage *image) { - if (image != nil) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (isValid()) { - [self->_style setImage:image forName:imageURI]; - [self setFillPattern:layer withReactStyleValue:styleValue]; - } - }); - } - }]; - } - } else if ([prop isEqualToString:@"fillPatternTransition"]) { - [self setFillPatternTransition:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)lineLayer:(MGLLineStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"lineCap"]) { - [self setLineCap:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineJoin"]) { - [self setLineJoin:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineMiterLimit"]) { - [self setLineMiterLimit:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineRoundLimit"]) { - [self setLineRoundLimit:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"visibility"]) { - [self setLineStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineOpacity"]) { - [self setLineOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineOpacityTransition"]) { - [self setLineOpacityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineColor"]) { - [self setLineColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineColorTransition"]) { - [self setLineColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineTranslate"]) { - [self setLineTranslate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineTranslateTransition"]) { - [self setLineTranslateTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineTranslateAnchor"]) { - [self setLineTranslateAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineWidth"]) { - [self setLineWidth:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineWidthTransition"]) { - [self setLineWidthTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineGapWidth"]) { - [self setLineGapWidth:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineGapWidthTransition"]) { - [self setLineGapWidthTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineOffset"]) { - [self setLineOffset:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineOffsetTransition"]) { - [self setLineOffsetTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineBlur"]) { - [self setLineBlur:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineBlurTransition"]) { - [self setLineBlurTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineDasharray"]) { - [self setLineDasharray:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineDasharrayTransition"]) { - [self setLineDasharrayTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"linePattern"]) { - if (![styleValue shouldAddImage]) { - [self setLinePattern:layer withReactStyleValue:styleValue]; - } else { - NSString *imageURI = [styleValue getImageURI]; - - [RCTMGLUtils fetchImage:_bridge url:imageURI scale:[styleValue getImageScale] callback:^(NSError *error, UIImage *image) { - if (image != nil) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (isValid()) { - [self->_style setImage:image forName:imageURI]; - [self setLinePattern:layer withReactStyleValue:styleValue]; - } - }); - } - }]; - } - } else if ([prop isEqualToString:@"linePatternTransition"]) { - [self setLinePatternTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"lineGradient"]) { - [self setLineGradient:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)symbolLayer:(MGLSymbolStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"symbolPlacement"]) { - [self setSymbolPlacement:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"symbolSpacing"]) { - [self setSymbolSpacing:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"symbolAvoidEdges"]) { - [self setSymbolAvoidEdges:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"symbolSortKey"]) { - [self setSymbolSortKey:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"symbolZOrder"]) { - [self setSymbolZOrder:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconAllowOverlap"]) { - [self setIconAllowOverlap:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconIgnorePlacement"]) { - [self setIconIgnorePlacement:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconOptional"]) { - [self setIconOptional:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconRotationAlignment"]) { - [self setIconRotationAlignment:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconSize"]) { - [self setIconSize:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconTextFit"]) { - [self setIconTextFit:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconTextFitPadding"]) { - [self setIconTextFitPadding:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconImage"]) { - if (![styleValue shouldAddImage]) { - [self setIconImage:layer withReactStyleValue:styleValue]; - } else { - NSString *imageURI = [styleValue getImageURI]; - - [RCTMGLUtils fetchImage:_bridge url:imageURI scale:[styleValue getImageScale] callback:^(NSError *error, UIImage *image) { - if (image != nil) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (isValid()) { - [self->_style setImage:image forName:imageURI]; - [self setIconImage:layer withReactStyleValue:styleValue]; - } - }); - } - }]; - } - } else if ([prop isEqualToString:@"iconRotate"]) { - [self setIconRotate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconPadding"]) { - [self setIconPadding:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconKeepUpright"]) { - [self setIconKeepUpright:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconOffset"]) { - [self setIconOffset:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconAnchor"]) { - [self setIconAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconPitchAlignment"]) { - [self setIconPitchAlignment:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textPitchAlignment"]) { - [self setTextPitchAlignment:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textRotationAlignment"]) { - [self setTextRotationAlignment:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textField"]) { - [self setTextField:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textFont"]) { - [self setTextFont:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textSize"]) { - [self setTextSize:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textMaxWidth"]) { - [self setTextMaxWidth:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textLineHeight"]) { - [self setTextLineHeight:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textLetterSpacing"]) { - [self setTextLetterSpacing:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textJustify"]) { - [self setTextJustify:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textRadialOffset"]) { - [self setTextRadialOffset:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textVariableAnchor"]) { - [self setTextVariableAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textAnchor"]) { - [self setTextAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textMaxAngle"]) { - [self setTextMaxAngle:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textWritingMode"]) { - [self setTextWritingMode:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textRotate"]) { - [self setTextRotate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textPadding"]) { - [self setTextPadding:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textKeepUpright"]) { - [self setTextKeepUpright:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textTransform"]) { - [self setTextTransform:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textOffset"]) { - [self setTextOffset:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textAllowOverlap"]) { - [self setTextAllowOverlap:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textIgnorePlacement"]) { - [self setTextIgnorePlacement:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textOptional"]) { - [self setTextOptional:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"visibility"]) { - [self setSymbolStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconOpacity"]) { - [self setIconOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconOpacityTransition"]) { - [self setIconOpacityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconColor"]) { - [self setIconColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconColorTransition"]) { - [self setIconColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconHaloColor"]) { - [self setIconHaloColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconHaloColorTransition"]) { - [self setIconHaloColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconHaloWidth"]) { - [self setIconHaloWidth:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconHaloWidthTransition"]) { - [self setIconHaloWidthTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconHaloBlur"]) { - [self setIconHaloBlur:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconHaloBlurTransition"]) { - [self setIconHaloBlurTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconTranslate"]) { - [self setIconTranslate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconTranslateTransition"]) { - [self setIconTranslateTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"iconTranslateAnchor"]) { - [self setIconTranslateAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textOpacity"]) { - [self setTextOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textOpacityTransition"]) { - [self setTextOpacityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textColor"]) { - [self setTextColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textColorTransition"]) { - [self setTextColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textHaloColor"]) { - [self setTextHaloColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textHaloColorTransition"]) { - [self setTextHaloColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textHaloWidth"]) { - [self setTextHaloWidth:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textHaloWidthTransition"]) { - [self setTextHaloWidthTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textHaloBlur"]) { - [self setTextHaloBlur:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textHaloBlurTransition"]) { - [self setTextHaloBlurTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textTranslate"]) { - [self setTextTranslate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textTranslateTransition"]) { - [self setTextTranslateTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"textTranslateAnchor"]) { - [self setTextTranslateAnchor:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)circleLayer:(MGLCircleStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"visibility"]) { - [self setCircleStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleRadius"]) { - [self setCircleRadius:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleRadiusTransition"]) { - [self setCircleRadiusTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleColor"]) { - [self setCircleColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleColorTransition"]) { - [self setCircleColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleBlur"]) { - [self setCircleBlur:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleBlurTransition"]) { - [self setCircleBlurTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleOpacity"]) { - [self setCircleOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleOpacityTransition"]) { - [self setCircleOpacityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleTranslate"]) { - [self setCircleTranslate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleTranslateTransition"]) { - [self setCircleTranslateTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleTranslateAnchor"]) { - [self setCircleTranslateAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circlePitchScale"]) { - [self setCirclePitchScale:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circlePitchAlignment"]) { - [self setCirclePitchAlignment:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleStrokeWidth"]) { - [self setCircleStrokeWidth:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleStrokeWidthTransition"]) { - [self setCircleStrokeWidthTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleStrokeColor"]) { - [self setCircleStrokeColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleStrokeColorTransition"]) { - [self setCircleStrokeColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleStrokeOpacity"]) { - [self setCircleStrokeOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"circleStrokeOpacityTransition"]) { - [self setCircleStrokeOpacityTransition:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)heatmapLayer:(MGLHeatmapStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"visibility"]) { - [self setHeatmapStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapRadius"]) { - [self setHeatmapRadius:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapRadiusTransition"]) { - [self setHeatmapRadiusTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapWeight"]) { - [self setHeatmapWeight:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapIntensity"]) { - [self setHeatmapIntensity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapIntensityTransition"]) { - [self setHeatmapIntensityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapColor"]) { - [self setHeatmapColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapOpacity"]) { - [self setHeatmapOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"heatmapOpacityTransition"]) { - [self setHeatmapOpacityTransition:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)fillExtrusionLayer:(MGLFillExtrusionStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"visibility"]) { - [self setFillExtrusionStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionOpacity"]) { - [self setFillExtrusionOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionOpacityTransition"]) { - [self setFillExtrusionOpacityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionColor"]) { - [self setFillExtrusionColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionColorTransition"]) { - [self setFillExtrusionColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionTranslate"]) { - [self setFillExtrusionTranslate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionTranslateTransition"]) { - [self setFillExtrusionTranslateTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionTranslateAnchor"]) { - [self setFillExtrusionTranslateAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionPattern"]) { - if (![styleValue shouldAddImage]) { - [self setFillExtrusionPattern:layer withReactStyleValue:styleValue]; - } else { - NSString *imageURI = [styleValue getImageURI]; - - [RCTMGLUtils fetchImage:_bridge url:imageURI scale:[styleValue getImageScale] callback:^(NSError *error, UIImage *image) { - if (image != nil) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (isValid()) { - [self->_style setImage:image forName:imageURI]; - [self setFillExtrusionPattern:layer withReactStyleValue:styleValue]; - } - }); - } - }]; - } - } else if ([prop isEqualToString:@"fillExtrusionPatternTransition"]) { - [self setFillExtrusionPatternTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionHeight"]) { - [self setFillExtrusionHeight:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionHeightTransition"]) { - [self setFillExtrusionHeightTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionBase"]) { - [self setFillExtrusionBase:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"fillExtrusionBaseTransition"]) { - [self setFillExtrusionBaseTransition:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)rasterLayer:(MGLRasterStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"visibility"]) { - [self setRasterStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterOpacity"]) { - [self setRasterOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterOpacityTransition"]) { - [self setRasterOpacityTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterHueRotate"]) { - [self setRasterHueRotate:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterHueRotateTransition"]) { - [self setRasterHueRotateTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterBrightnessMin"]) { - [self setRasterBrightnessMin:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterBrightnessMinTransition"]) { - [self setRasterBrightnessMinTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterBrightnessMax"]) { - [self setRasterBrightnessMax:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterBrightnessMaxTransition"]) { - [self setRasterBrightnessMaxTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterSaturation"]) { - [self setRasterSaturation:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterSaturationTransition"]) { - [self setRasterSaturationTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterContrast"]) { - [self setRasterContrast:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterContrastTransition"]) { - [self setRasterContrastTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterResampling"]) { - [self setRasterResampling:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"rasterFadeDuration"]) { - [self setRasterFadeDuration:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)hillshadeLayer:(MGLHillshadeStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"visibility"]) { - [self setHillshadeStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeIlluminationDirection"]) { - [self setHillshadeIlluminationDirection:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeIlluminationAnchor"]) { - [self setHillshadeIlluminationAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeExaggeration"]) { - [self setHillshadeExaggeration:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeExaggerationTransition"]) { - [self setHillshadeExaggerationTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeShadowColor"]) { - [self setHillshadeShadowColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeShadowColorTransition"]) { - [self setHillshadeShadowColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeHighlightColor"]) { - [self setHillshadeHighlightColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeHighlightColorTransition"]) { - [self setHillshadeHighlightColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeAccentColor"]) { - [self setHillshadeAccentColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"hillshadeAccentColorTransition"]) { - [self setHillshadeAccentColorTransition:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)backgroundLayer:(MGLBackgroundStyleLayer *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"visibility"]) { - [self setBackgroundStyleLayerVisibility:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"backgroundColor"]) { - [self setBackgroundColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"backgroundColorTransition"]) { - [self setBackgroundColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"backgroundPattern"]) { - if (![styleValue shouldAddImage]) { - [self setBackgroundPattern:layer withReactStyleValue:styleValue]; - } else { - NSString *imageURI = [styleValue getImageURI]; - - [RCTMGLUtils fetchImage:_bridge url:imageURI scale:[styleValue getImageScale] callback:^(NSError *error, UIImage *image) { - if (image != nil) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (isValid()) { - [self->_style setImage:image forName:imageURI]; - [self setBackgroundPattern:layer withReactStyleValue:styleValue]; - } - }); - } - }]; - } - } else if ([prop isEqualToString:@"backgroundPatternTransition"]) { - [self setBackgroundPatternTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"backgroundOpacity"]) { - [self setBackgroundOpacity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"backgroundOpacityTransition"]) { - [self setBackgroundOpacityTransition:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - -- (void)lightLayer:(MGLLight *)layer withReactStyle:(NSDictionary *)reactStyle isValid:(BOOL (^)(void)) isValid -{ - if (![self _hasReactStyle:reactStyle]) { - // TODO throw exception - return; - } - - NSArray *styleProps = [reactStyle allKeys]; - for (NSString *prop in styleProps) { - if ([prop isEqualToString:@"__MAPBOX_STYLESHEET__"]) { - continue; - } - - RCTMGLStyleValue *styleValue = [RCTMGLStyleValue make:reactStyle[prop]]; - - if ([prop isEqualToString:@"anchor"]) { - [self setAnchor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"position"]) { - [self setPosition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"positionTransition"]) { - [self setPositionTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"color"]) { - [self setColor:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"colorTransition"]) { - [self setColorTransition:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"intensity"]) { - [self setIntensity:layer withReactStyleValue:styleValue]; - } else if ([prop isEqualToString:@"intensityTransition"]) { - [self setIntensityTransition:layer withReactStyleValue:styleValue]; - } else { - // TODO throw exception - } - } -} - - - - -- (void)setFillStyleLayerVisibility:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setFillAntialias:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillAntialiased = styleValue.mglStyleValue; -} - -- (void)setFillOpacity:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillOpacity = styleValue.mglStyleValue; -} - -- (void)setFillOpacityTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillOpacityTransition = [styleValue getTransition]; -} - -- (void)setFillColor:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillColor = styleValue.mglStyleValue; -} - -- (void)setFillColorTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillColorTransition = [styleValue getTransition]; -} - -- (void)setFillOutlineColor:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillOutlineColor = styleValue.mglStyleValue; -} - -- (void)setFillOutlineColorTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillOutlineColorTransition = [styleValue getTransition]; -} - -- (void)setFillTranslate:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillTranslation = styleValue.mglStyleValue; -} - -- (void)setFillTranslateTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillTranslationTransition = [styleValue getTransition]; -} - -- (void)setFillTranslateAnchor:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillTranslationAnchor = styleValue.mglStyleValue; -} - -- (void)setFillPattern:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillPattern = styleValue.mglStyleValue; -} - -- (void)setFillPatternTransition:(MGLFillStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillPatternTransition = [styleValue getTransition]; -} - - - -- (void)setLineCap:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineCap = styleValue.mglStyleValue; -} - -- (void)setLineJoin:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineJoin = styleValue.mglStyleValue; -} - -- (void)setLineMiterLimit:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineMiterLimit = styleValue.mglStyleValue; -} - -- (void)setLineRoundLimit:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineRoundLimit = styleValue.mglStyleValue; -} - -- (void)setLineStyleLayerVisibility:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setLineOpacity:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineOpacity = styleValue.mglStyleValue; -} - -- (void)setLineOpacityTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineOpacityTransition = [styleValue getTransition]; -} - -- (void)setLineColor:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineColor = styleValue.mglStyleValue; -} - -- (void)setLineColorTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineColorTransition = [styleValue getTransition]; -} - -- (void)setLineTranslate:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineTranslation = styleValue.mglStyleValue; -} - -- (void)setLineTranslateTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineTranslationTransition = [styleValue getTransition]; -} - -- (void)setLineTranslateAnchor:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineTranslationAnchor = styleValue.mglStyleValue; -} - -- (void)setLineWidth:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineWidth = styleValue.mglStyleValue; -} - -- (void)setLineWidthTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineWidthTransition = [styleValue getTransition]; -} - -- (void)setLineGapWidth:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineGapWidth = styleValue.mglStyleValue; -} - -- (void)setLineGapWidthTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineGapWidthTransition = [styleValue getTransition]; -} - -- (void)setLineOffset:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineOffset = styleValue.mglStyleValue; -} - -- (void)setLineOffsetTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineOffsetTransition = [styleValue getTransition]; -} - -- (void)setLineBlur:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineBlur = styleValue.mglStyleValue; -} - -- (void)setLineBlurTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineBlurTransition = [styleValue getTransition]; -} - -- (void)setLineDasharray:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineDashPattern = styleValue.mglStyleValue; -} - -- (void)setLineDasharrayTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineDashPatternTransition = [styleValue getTransition]; -} - -- (void)setLinePattern:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.linePattern = styleValue.mglStyleValue; -} - -- (void)setLinePatternTransition:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.linePatternTransition = [styleValue getTransition]; -} - -- (void)setLineGradient:(MGLLineStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.lineGradient = styleValue.mglStyleValue; -} - - - -- (void)setSymbolPlacement:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.symbolPlacement = styleValue.mglStyleValue; -} - -- (void)setSymbolSpacing:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.symbolSpacing = styleValue.mglStyleValue; -} - -- (void)setSymbolAvoidEdges:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.symbolAvoidsEdges = styleValue.mglStyleValue; -} - -- (void)setSymbolSortKey:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.symbolSortKey = styleValue.mglStyleValue; -} - -- (void)setSymbolZOrder:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.symbolZOrder = styleValue.mglStyleValue; -} - -- (void)setIconAllowOverlap:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconAllowsOverlap = styleValue.mglStyleValue; -} - -- (void)setIconIgnorePlacement:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconIgnoresPlacement = styleValue.mglStyleValue; -} - -- (void)setIconOptional:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconOptional = styleValue.mglStyleValue; -} - -- (void)setIconRotationAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconRotationAlignment = styleValue.mglStyleValue; -} - -- (void)setIconSize:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconScale = styleValue.mglStyleValue; -} - -- (void)setIconTextFit:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconTextFit = styleValue.mglStyleValue; -} - -- (void)setIconTextFitPadding:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconTextFitPadding = styleValue.mglStyleValue; -} - -- (void)setIconImage:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconImageName = styleValue.mglStyleValue; -} - -- (void)setIconRotate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconRotation = styleValue.mglStyleValue; -} - -- (void)setIconPadding:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconPadding = styleValue.mglStyleValue; -} - -- (void)setIconKeepUpright:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.keepsIconUpright = styleValue.mglStyleValue; -} - -- (void)setIconOffset:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconOffset = styleValue.mglStyleValue; -} - -- (void)setIconAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconAnchor = styleValue.mglStyleValue; -} - -- (void)setIconPitchAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconPitchAlignment = styleValue.mglStyleValue; -} - -- (void)setTextPitchAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textPitchAlignment = styleValue.mglStyleValue; -} - -- (void)setTextRotationAlignment:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textRotationAlignment = styleValue.mglStyleValue; -} - -- (void)setTextField:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.text = styleValue.mglStyleValue; -} - -- (void)setTextFont:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textFontNames = styleValue.mglStyleValue; -} - -- (void)setTextSize:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textFontSize = styleValue.mglStyleValue; -} - -- (void)setTextMaxWidth:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.maximumTextWidth = styleValue.mglStyleValue; -} - -- (void)setTextLineHeight:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textLineHeight = styleValue.mglStyleValue; -} - -- (void)setTextLetterSpacing:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textLetterSpacing = styleValue.mglStyleValue; -} - -- (void)setTextJustify:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textJustification = styleValue.mglStyleValue; -} - -- (void)setTextRadialOffset:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textRadialOffset = styleValue.mglStyleValue; -} - -- (void)setTextVariableAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textVariableAnchor = styleValue.mglStyleValue; -} - -- (void)setTextAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textAnchor = styleValue.mglStyleValue; -} - -- (void)setTextMaxAngle:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.maximumTextAngle = styleValue.mglStyleValue; -} - -- (void)setTextWritingMode:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textWritingModes = styleValue.mglStyleValue; -} - -- (void)setTextRotate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textRotation = styleValue.mglStyleValue; -} - -- (void)setTextPadding:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textPadding = styleValue.mglStyleValue; -} - -- (void)setTextKeepUpright:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.keepsTextUpright = styleValue.mglStyleValue; -} - -- (void)setTextTransform:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textTransform = styleValue.mglStyleValue; -} - -- (void)setTextOffset:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textOffset = styleValue.mglStyleValue; -} - -- (void)setTextAllowOverlap:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textAllowsOverlap = styleValue.mglStyleValue; -} - -- (void)setTextIgnorePlacement:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textIgnoresPlacement = styleValue.mglStyleValue; -} - -- (void)setTextOptional:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textOptional = styleValue.mglStyleValue; -} - -- (void)setSymbolStyleLayerVisibility:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setIconOpacity:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconOpacity = styleValue.mglStyleValue; -} - -- (void)setIconOpacityTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconOpacityTransition = [styleValue getTransition]; -} - -- (void)setIconColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconColor = styleValue.mglStyleValue; -} - -- (void)setIconColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconColorTransition = [styleValue getTransition]; -} - -- (void)setIconHaloColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconHaloColor = styleValue.mglStyleValue; -} - -- (void)setIconHaloColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconHaloColorTransition = [styleValue getTransition]; -} - -- (void)setIconHaloWidth:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconHaloWidth = styleValue.mglStyleValue; -} - -- (void)setIconHaloWidthTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconHaloWidthTransition = [styleValue getTransition]; -} - -- (void)setIconHaloBlur:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconHaloBlur = styleValue.mglStyleValue; -} - -- (void)setIconHaloBlurTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconHaloBlurTransition = [styleValue getTransition]; -} - -- (void)setIconTranslate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconTranslation = styleValue.mglStyleValue; -} - -- (void)setIconTranslateTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconTranslationTransition = [styleValue getTransition]; -} - -- (void)setIconTranslateAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.iconTranslationAnchor = styleValue.mglStyleValue; -} - -- (void)setTextOpacity:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textOpacity = styleValue.mglStyleValue; -} - -- (void)setTextOpacityTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textOpacityTransition = [styleValue getTransition]; -} - -- (void)setTextColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textColor = styleValue.mglStyleValue; -} - -- (void)setTextColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textColorTransition = [styleValue getTransition]; -} - -- (void)setTextHaloColor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textHaloColor = styleValue.mglStyleValue; -} - -- (void)setTextHaloColorTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textHaloColorTransition = [styleValue getTransition]; -} - -- (void)setTextHaloWidth:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textHaloWidth = styleValue.mglStyleValue; -} - -- (void)setTextHaloWidthTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textHaloWidthTransition = [styleValue getTransition]; -} - -- (void)setTextHaloBlur:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textHaloBlur = styleValue.mglStyleValue; -} - -- (void)setTextHaloBlurTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textHaloBlurTransition = [styleValue getTransition]; -} - -- (void)setTextTranslate:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textTranslation = styleValue.mglStyleValue; -} - -- (void)setTextTranslateTransition:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textTranslationTransition = [styleValue getTransition]; -} - -- (void)setTextTranslateAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.textTranslationAnchor = styleValue.mglStyleValue; -} - - - -- (void)setCircleStyleLayerVisibility:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setCircleRadius:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleRadius = styleValue.mglStyleValue; -} - -- (void)setCircleRadiusTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleRadiusTransition = [styleValue getTransition]; -} - -- (void)setCircleColor:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleColor = styleValue.mglStyleValue; -} - -- (void)setCircleColorTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleColorTransition = [styleValue getTransition]; -} - -- (void)setCircleBlur:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleBlur = styleValue.mglStyleValue; -} - -- (void)setCircleBlurTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleBlurTransition = [styleValue getTransition]; -} - -- (void)setCircleOpacity:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleOpacity = styleValue.mglStyleValue; -} - -- (void)setCircleOpacityTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleOpacityTransition = [styleValue getTransition]; -} - -- (void)setCircleTranslate:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleTranslation = styleValue.mglStyleValue; -} - -- (void)setCircleTranslateTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleTranslationTransition = [styleValue getTransition]; -} - -- (void)setCircleTranslateAnchor:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleTranslationAnchor = styleValue.mglStyleValue; -} - -- (void)setCirclePitchScale:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleScaleAlignment = styleValue.mglStyleValue; -} - -- (void)setCirclePitchAlignment:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circlePitchAlignment = styleValue.mglStyleValue; -} - -- (void)setCircleStrokeWidth:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleStrokeWidth = styleValue.mglStyleValue; -} - -- (void)setCircleStrokeWidthTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleStrokeWidthTransition = [styleValue getTransition]; -} - -- (void)setCircleStrokeColor:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleStrokeColor = styleValue.mglStyleValue; -} - -- (void)setCircleStrokeColorTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleStrokeColorTransition = [styleValue getTransition]; -} - -- (void)setCircleStrokeOpacity:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleStrokeOpacity = styleValue.mglStyleValue; -} - -- (void)setCircleStrokeOpacityTransition:(MGLCircleStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.circleStrokeOpacityTransition = [styleValue getTransition]; -} - - - -- (void)setHeatmapStyleLayerVisibility:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setHeatmapRadius:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapRadius = styleValue.mglStyleValue; -} - -- (void)setHeatmapRadiusTransition:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapRadiusTransition = [styleValue getTransition]; -} - -- (void)setHeatmapWeight:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapWeight = styleValue.mglStyleValue; -} - -- (void)setHeatmapIntensity:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapIntensity = styleValue.mglStyleValue; -} - -- (void)setHeatmapIntensityTransition:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapIntensityTransition = [styleValue getTransition]; -} - -- (void)setHeatmapColor:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapColor = styleValue.mglStyleValue; -} - -- (void)setHeatmapOpacity:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapOpacity = styleValue.mglStyleValue; -} - -- (void)setHeatmapOpacityTransition:(MGLHeatmapStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.heatmapOpacityTransition = [styleValue getTransition]; -} - - - -- (void)setFillExtrusionStyleLayerVisibility:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setFillExtrusionOpacity:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionOpacity = styleValue.mglStyleValue; -} - -- (void)setFillExtrusionOpacityTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionOpacityTransition = [styleValue getTransition]; -} - -- (void)setFillExtrusionColor:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionColor = styleValue.mglStyleValue; -} - -- (void)setFillExtrusionColorTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionColorTransition = [styleValue getTransition]; -} - -- (void)setFillExtrusionTranslate:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionTranslation = styleValue.mglStyleValue; -} - -- (void)setFillExtrusionTranslateTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionTranslationTransition = [styleValue getTransition]; -} - -- (void)setFillExtrusionTranslateAnchor:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionTranslationAnchor = styleValue.mglStyleValue; -} - -- (void)setFillExtrusionPattern:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionPattern = styleValue.mglStyleValue; -} - -- (void)setFillExtrusionPatternTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionPatternTransition = [styleValue getTransition]; -} - -- (void)setFillExtrusionHeight:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionHeight = styleValue.mglStyleValue; -} - -- (void)setFillExtrusionHeightTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionHeightTransition = [styleValue getTransition]; -} - -- (void)setFillExtrusionBase:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionBase = styleValue.mglStyleValue; -} - -- (void)setFillExtrusionBaseTransition:(MGLFillExtrusionStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.fillExtrusionBaseTransition = [styleValue getTransition]; -} - - - -- (void)setRasterStyleLayerVisibility:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setRasterOpacity:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterOpacity = styleValue.mglStyleValue; -} - -- (void)setRasterOpacityTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterOpacityTransition = [styleValue getTransition]; -} - -- (void)setRasterHueRotate:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterHueRotation = styleValue.mglStyleValue; -} - -- (void)setRasterHueRotateTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterHueRotationTransition = [styleValue getTransition]; -} - -- (void)setRasterBrightnessMin:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.minimumRasterBrightness = styleValue.mglStyleValue; -} - -- (void)setRasterBrightnessMinTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.minimumRasterBrightnessTransition = [styleValue getTransition]; -} - -- (void)setRasterBrightnessMax:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.maximumRasterBrightness = styleValue.mglStyleValue; -} - -- (void)setRasterBrightnessMaxTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.maximumRasterBrightnessTransition = [styleValue getTransition]; -} - -- (void)setRasterSaturation:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterSaturation = styleValue.mglStyleValue; -} - -- (void)setRasterSaturationTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterSaturationTransition = [styleValue getTransition]; -} - -- (void)setRasterContrast:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterContrast = styleValue.mglStyleValue; -} - -- (void)setRasterContrastTransition:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterContrastTransition = [styleValue getTransition]; -} - -- (void)setRasterResampling:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterResamplingMode = styleValue.mglStyleValue; -} - -- (void)setRasterFadeDuration:(MGLRasterStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.rasterFadeDuration = styleValue.mglStyleValue; -} - - - -- (void)setHillshadeStyleLayerVisibility:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setHillshadeIlluminationDirection:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeIlluminationDirection = styleValue.mglStyleValue; -} - -- (void)setHillshadeIlluminationAnchor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeIlluminationAnchor = styleValue.mglStyleValue; -} - -- (void)setHillshadeExaggeration:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeExaggeration = styleValue.mglStyleValue; -} - -- (void)setHillshadeExaggerationTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeExaggerationTransition = [styleValue getTransition]; -} - -- (void)setHillshadeShadowColor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeShadowColor = styleValue.mglStyleValue; -} - -- (void)setHillshadeShadowColorTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeShadowColorTransition = [styleValue getTransition]; -} - -- (void)setHillshadeHighlightColor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeHighlightColor = styleValue.mglStyleValue; -} - -- (void)setHillshadeHighlightColorTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeHighlightColorTransition = [styleValue getTransition]; -} - -- (void)setHillshadeAccentColor:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeAccentColor = styleValue.mglStyleValue; -} - -- (void)setHillshadeAccentColorTransition:(MGLHillshadeStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.hillshadeAccentColorTransition = [styleValue getTransition]; -} - - - -- (void)setBackgroundStyleLayerVisibility:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.visible = [styleValue isVisible]; -} - -- (void)setBackgroundColor:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.backgroundColor = styleValue.mglStyleValue; -} - -- (void)setBackgroundColorTransition:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.backgroundColorTransition = [styleValue getTransition]; -} - -- (void)setBackgroundPattern:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.backgroundPattern = styleValue.mglStyleValue; -} - -- (void)setBackgroundPatternTransition:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.backgroundPatternTransition = [styleValue getTransition]; -} - -- (void)setBackgroundOpacity:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.backgroundOpacity = styleValue.mglStyleValue; -} - -- (void)setBackgroundOpacityTransition:(MGLBackgroundStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.backgroundOpacityTransition = [styleValue getTransition]; -} - - - -- (void)setAnchor:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.anchor = styleValue.mglStyleValue; -} - -- (void)setPosition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.position = [styleValue getSphericalPosition]; -} - -- (void)setPositionTransition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.positionTransition = [styleValue getTransition]; -} - -- (void)setColor:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.color = styleValue.mglStyleValue; -} - -- (void)setColorTransition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.colorTransition = [styleValue getTransition]; -} - -- (void)setIntensity:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.intensity = styleValue.mglStyleValue; -} - -- (void)setIntensityTransition:(MGLLight *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue -{ - layer.intensityTransition = [styleValue getTransition]; -} - - - -- (BOOL)_hasReactStyle:(NSDictionary *)reactStyle -{ - return reactStyle != nil && reactStyle.allKeys.count > 0; -} - -@end diff --git a/ios/RCTMGL/RCTMGLStyleValue.h b/ios/RCTMGL/RCTMGLStyleValue.h deleted file mode 100644 index 645aaca3fb..0000000000 --- a/ios/RCTMGL/RCTMGLStyleValue.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// RCTMGLStyleValue.h -// RCTMGL -// -// Created by Nick Italiano on 9/11/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -@import Mapbox; - -@interface RCTMGLStyleValue : NSObject - -@property (nonatomic, strong) NSString *styleType; -@property (nonatomic, strong) NSDictionary *rawStyleValue; -@property (nonatomic, readonly) NSExpression *mglStyleValue; - -- (BOOL)shouldAddImage; -- (NSString *)getImageURI; -- (double)getImageScale; -- (MGLTransition)getTransition; -- (NSExpression *)getSphericalPosition; -- (BOOL)isVisible; - -+ (RCTMGLStyleValue*)make:(NSString*)expressionJSONStr; - -@end diff --git a/ios/RCTMGL/RCTMGLStyleValue.m b/ios/RCTMGL/RCTMGLStyleValue.m deleted file mode 100644 index 6a6ddea517..0000000000 --- a/ios/RCTMGL/RCTMGLStyleValue.m +++ /dev/null @@ -1,167 +0,0 @@ -// -// RCTMGLStyleValue.m -// RCTMGL -// -// Created by Nick Italiano on 9/11/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLStyleValue.h" -#import "RCTMGLUtils.h" -#import - -@implementation RCTMGLStyleValue -{ - NSObject *expressionJSON; -} - -- (NSExpression *)mglStyleValue -{ - if ([_styleType isEqualToString:@"color"] && [expressionJSON respondsToSelector:@selector(objectEnumerator)] && [[[(NSArray*)expressionJSON objectEnumerator] nextObject] isKindOfClass:[NSNumber class]]) { - UIColor *color = [RCTMGLUtils toColor:expressionJSON]; - return [NSExpression expressionWithMGLJSONObject:color]; - } else if ([_styleType isEqualToString:@"color"] && [expressionJSON isKindOfClass:[NSNumber class]]) { - - UIColor *color = [RCTMGLUtils toColor:expressionJSON]; - return [NSExpression expressionWithMGLJSONObject:color]; - } else if ([_styleType isEqualToString:@"vector"] && [expressionJSON respondsToSelector:@selector(objectEnumerator)] && [[[(NSArray*)expressionJSON objectEnumerator] nextObject] isKindOfClass:[NSNumber class]]) { - CGVector vector = [RCTMGLUtils toCGVector:(NSArray *)expressionJSON]; - return [NSExpression expressionWithMGLJSONObject:[NSValue valueWithCGVector:vector]]; - } else if ([_styleType isEqualToString:@"image"] && [expressionJSON isKindOfClass:[NSDictionary class]]) { - return [NSExpression expressionForConstantValue:[self getImageURI]]; - } else if ([_styleType isEqual:@"edgeinsets"] && [expressionJSON respondsToSelector:@selector(objectEnumerator)] && [[[(NSArray*)expressionJSON objectEnumerator] nextObject] isKindOfClass:[NSNumber class]]){ - UIEdgeInsets edgeInsets = [RCTMGLUtils toUIEdgeInsets:(NSArray *)expressionJSON]; - return [NSExpression expressionWithMGLJSONObject:[NSValue valueWithUIEdgeInsets:edgeInsets]]; - } else if ([_styleType isEqualToString:@"enum"] && [expressionJSON isKindOfClass:[NSNumber class]]) { - // ensure we pass through values as NSUInteger when mapping to an MGL enum - NSUInteger uintValue = [(NSNumber*)expressionJSON unsignedIntegerValue]; - id rawValue = [NSValue value:&uintValue withObjCType:@encode(NSUInteger)]; - return [NSExpression expressionWithMGLJSONObject:rawValue]; - } else if ([expressionJSON respondsToSelector:@selector(objectEnumerator)] && [[[(NSArray*)expressionJSON objectEnumerator] nextObject] isKindOfClass:[NSNumber class]]) { - return [NSExpression expressionForConstantValue:expressionJSON]; - } else { - return [NSExpression expressionWithMGLJSONObject:expressionJSON]; - } -} - -- (void)setStyleObject:(NSObject *)object -{ - expressionJSON = object; -} - -- (NSObject *)parse:(NSDictionary *)rawStyleValue -{ - NSObject *object = nil; - NSString *type = (NSString *)rawStyleValue[@"type"]; - - if ([type isEqualToString:@"string"]) { - object = (NSString *)rawStyleValue[@"value"]; - } else if ([type isEqualToString:@"number"]) { - object = (NSNumber *)rawStyleValue[@"value"]; - } else if ([type isEqualToString:@"boolean"]) { - object = rawStyleValue[@"value"]; - } else if ([type isEqualToString:@"hashmap"]) { - NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; - NSArray *values = (NSArray *)rawStyleValue[@"value"]; - - for (int i = 0; i < values.count; i++) { - NSObject *key = [self parse:values[i][0]]; - NSObject *value = [self parse:values[i][1]]; - dict[[key mutableCopy]] = value; - } - - object = dict; - } else if ([type isEqualToString:@"array"]) { - NSMutableArray *arr = [[NSMutableArray alloc] init]; - NSArray *values = (NSArray *)rawStyleValue[@"value"]; - - for (int i = 0; i < values.count; i++) { - [arr addObject:[self parse:values[i]]]; - } - - object = arr; - } - - return object; -} - - - -- (BOOL)shouldAddImage -{ - NSString *imageURI = [self getImageURI]; - - return [imageURI containsString:@"://"]; -} - -- (NSString *)getImageURI -{ - if ([expressionJSON isKindOfClass:[NSDictionary class]]) { - return [expressionJSON valueForKey:@"uri"]; - } else if ([expressionJSON isKindOfClass:[NSArray class]]) { - return nil; - } else { - return (NSString *)expressionJSON; - } -} - -- (double)getImageScale -{ - if ([expressionJSON isKindOfClass:[NSDictionary class]]) { - id scale = [expressionJSON valueForKey:@"scale"]; - if ([scale isKindOfClass:[NSNumber class]]) { - return [scale doubleValue]; - } else { - return 1.0; - } - } else { - return 1.0; - } -} - -- (MGLTransition)getTransition -{ - if (![expressionJSON isKindOfClass:[NSDictionary class]]) { - return MGLTransitionMake(0.f, 0.f); - } - - NSDictionary *config = (NSDictionary *)expressionJSON; - double duration = config[@"duration"] != nil ? [config[@"duration"] doubleValue] : 300.0; - double delay = config[@"delay"] != nil ? [config[@"delay"] doubleValue] : 0.0; - - const double millisecondsToSeconds = 1.0/1000.0; - - return MGLTransitionMake(duration * millisecondsToSeconds, delay * millisecondsToSeconds); -} - -- (NSExpression *)getSphericalPosition -{ - NSArray *values = (NSArray *)expressionJSON; - - CGFloat radial = [values[0] floatValue]; - CLLocationDistance azimuthal = [values[1] doubleValue]; - CLLocationDistance polar = [values[2] doubleValue]; - - MGLSphericalPosition pos = MGLSphericalPositionMake(radial, azimuthal, polar); - return [NSExpression expressionWithMGLJSONObject:@(pos)]; -} - -- (BOOL)isVisible -{ - if ([expressionJSON isKindOfClass:[NSString class]]) { - NSString *visible = (NSString *)expressionJSON; - return [visible isEqualToString:@"visible"]; - } - return YES; -} - -+ (RCTMGLStyleValue*)make:(NSDictionary*)rawStyleValue; -{ - RCTMGLStyleValue *styleValue = [[RCTMGLStyleValue alloc] init]; - styleValue.styleType = (NSString *)rawStyleValue[@"styletype"]; - NSObject *object = [styleValue parse:(NSDictionary *)rawStyleValue[@"stylevalue"]]; - [styleValue setStyleObject:object]; - return styleValue; -} - -@end diff --git a/ios/RCTMGL/RCTMGLSymbolLayer.h b/ios/RCTMGL/RCTMGLSymbolLayer.h deleted file mode 100644 index c35c129344..0000000000 --- a/ios/RCTMGL/RCTMGLSymbolLayer.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// RCTMGLSymbolLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLVectorLayer.h" - -@interface RCTMGLSymbolLayer : RCTMGLVectorLayer - -@property (nonatomic, strong) NSMutableArray> *reactSubviews; - -@property (nonatomic, assign) BOOL snapshot; -@property (nonatomic, copy) NSString *sourceLayerID; - -@end diff --git a/ios/RCTMGL/RCTMGLSymbolLayer.m b/ios/RCTMGL/RCTMGLSymbolLayer.m deleted file mode 100644 index 5c7df30961..0000000000 --- a/ios/RCTMGL/RCTMGLSymbolLayer.m +++ /dev/null @@ -1,121 +0,0 @@ -// -// RCTMGLSymbolLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLSymbolLayer.h" -#import "RCTMGLStyle.h" -#import "UIView+React.h" -#import - -@implementation RCTMGLSymbolLayer - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - _reactSubviews = [[NSMutableArray alloc] init]; - } - return self; -} - -- (void)invalidate -{ - if (_snapshot == YES && self.style != nil) { - [self.style removeImageForName:self.id]; - } -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (void)insertReactSubview:(id)subview atIndex:(NSInteger)atIndex { - [_reactSubviews insertObject:(UIView *)subview atIndex:(NSUInteger) atIndex]; -} -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (void)removeReactSubview:(id)subview { - [_reactSubviews removeObject:(UIView *)subview]; -} -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-missing-super-calls" -- (NSArray> *)reactSubviews { - return nil; -} -#pragma clang diagnostic pop - -- (void)setSnapshot:(BOOL)snapshot -{ - _snapshot = snapshot; - - if (self.style != nil) { - UIImage *image; - MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *) self.styleLayer; - - if (_snapshot == YES) { - image = [self _createViewSnapshot]; - [self.style setImage:image forName:self.id]; - layer.iconImageName = [NSExpression expressionWithFormat:self.id]; - } else { - image = [self.style imageForName:self.id]; - - if (image != nil) { - [self.style removeImageForName:self.id]; - layer.iconImageName = nil; - } - } - } -} - -- (void)addedToMap -{ - [super addedToMap]; - - if (_snapshot == YES) { - UIImage *image = [self _createViewSnapshot]; - - if (image != nil) { - [self.style setImage:image forName:self.id]; - - MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)self.styleLayer; - layer.iconImageName = [NSExpression expressionForConstantValue:self.id]; - } - } -} - -- (MGLSymbolStyleLayer*)makeLayer:(MGLStyle*)style -{ - MGLSource *source = [self layerWithSourceIDInStyle: style]; - if (source == nil) { return nil; } - MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:self.id source:source]; - layer.sourceLayerIdentifier = self.sourceLayerID; - return layer; -} - -- (void)addStyles -{ - RCTMGLStyle *style = [[RCTMGLStyle alloc] initWithMGLStyle:self.style]; - style.bridge = self.bridge; - [style symbolLayer:(MGLSymbolStyleLayer*)self.styleLayer withReactStyle:self.reactStyle isValid:^{ return [self isAddedToMap]; - }]; -} - -- (UIImage *)_createViewSnapshot -{ - if (_reactSubviews.count == 0) { - return nil; - } - UIView *view = (UIView *)_reactSubviews[0]; - UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.f); - [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES]; - UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - return snapshot; -} - -@end diff --git a/ios/RCTMGL/RCTMGLSymbolLayerManager.h b/ios/RCTMGL/RCTMGLSymbolLayerManager.h deleted file mode 100644 index cdfeb61781..0000000000 --- a/ios/RCTMGL/RCTMGLSymbolLayerManager.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// RCTMGLSymbolLayerManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@interface RCTMGLSymbolLayerManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLSymbolLayerManager.m b/ios/RCTMGL/RCTMGLSymbolLayerManager.m deleted file mode 100644 index 5fd8b3e05b..0000000000 --- a/ios/RCTMGL/RCTMGLSymbolLayerManager.m +++ /dev/null @@ -1,40 +0,0 @@ -// -// RCTMGLSymbolLayerManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/19/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLSymbolLayerManager.h" -#import "RCTMGLSymbolLayer.h" - -@implementation RCTMGLSymbolLayerManager - -RCT_EXPORT_MODULE() - -// circle layer props -RCT_EXPORT_VIEW_PROPERTY(sourceLayerID, NSString); - -// standard layer props -RCT_EXPORT_VIEW_PROPERTY(id, NSString); -RCT_EXPORT_VIEW_PROPERTY(sourceID, NSString); -RCT_EXPORT_VIEW_PROPERTY(filter, NSArray); -RCT_EXPORT_VIEW_PROPERTY(snapshot, BOOL); - -RCT_EXPORT_VIEW_PROPERTY(aboveLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(belowLayerID, NSString); -RCT_EXPORT_VIEW_PROPERTY(layerIndex, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); - -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber); -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber); - -- (UIView*)view -{ - RCTMGLSymbolLayer *layer = [RCTMGLSymbolLayer new]; - layer.bridge = self.bridge; - return layer; -} - -@end diff --git a/ios/RCTMGL/RCTMGLTileSource.h b/ios/RCTMGL/RCTMGLTileSource.h deleted file mode 100644 index 5736fb4ec8..0000000000 --- a/ios/RCTMGL/RCTMGLTileSource.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// RCTMGLTileSource.h -// RCTMGL -// - -#import "RCTMGLSource.h" -@import Mapbox; - -@interface RCTMGLTileSource : RCTMGLSource - -@property (nonatomic, copy) NSString *url; -@property (nonatomic, strong) NSArray *tileUrlTemplates; -@property (nonatomic, copy) NSString *attribution; - -@property (nonatomic, strong) NSNumber *minZoomLevel; -@property (nonatomic, strong) NSNumber *maxZoomLevel; - -@property (nonatomic, assign) BOOL tms; - -- (NSDictionary*)getOptions; - -@end diff --git a/ios/RCTMGL/RCTMGLTileSource.m b/ios/RCTMGL/RCTMGLTileSource.m deleted file mode 100644 index a775cbc980..0000000000 --- a/ios/RCTMGL/RCTMGLTileSource.m +++ /dev/null @@ -1,31 +0,0 @@ -// -// BaseSource.m -// RCTMGL -// - -#import "RCTMGLTileSource.h" - -@implementation RCTMGLTileSource - -- (NSDictionary*)getOptions { - NSMutableDictionary *options = [[NSMutableDictionary alloc] init]; - - if (self.maxZoomLevel != nil) { - options[MGLTileSourceOptionMaximumZoomLevel] = self.maxZoomLevel; - } - - if (self.minZoomLevel != nil) { - options[MGLTileSourceOptionMinimumZoomLevel] = self.minZoomLevel; - } - - if (self.tms) { - options[MGLTileSourceOptionTileCoordinateSystem] = [NSNumber numberWithUnsignedInteger:MGLTileCoordinateSystemTMS]; - } - - if (self.attribution != nil) { - options[MGLTileSourceOptionAttributionHTMLString] = self.attribution; - } - - return options; -} -@end diff --git a/ios/RCTMGL/RCTMGLUserLocation.h b/ios/RCTMGL/RCTMGLUserLocation.h deleted file mode 100644 index bae840eb8a..0000000000 --- a/ios/RCTMGL/RCTMGLUserLocation.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// RCTMGLUserLocation.h -// RCTMGL - -#import -#import -#import - -@interface RCTMGLUserLocation : NSObject - -+ (id)sharedInstance; - -- (MGLUserLocationAnnotationView*)hiddenUserAnnotation; - -@end diff --git a/ios/RCTMGL/RCTMGLUserLocation.m b/ios/RCTMGL/RCTMGLUserLocation.m deleted file mode 100644 index 6880af290d..0000000000 --- a/ios/RCTMGL/RCTMGLUserLocation.m +++ /dev/null @@ -1,38 +0,0 @@ -// -// RCTMGLUserLocation.m -// RCTMGL -// - -#import "RCTMGLUserLocation.h" -#import - -@interface HiddenUserLocationAnnotationView : MGLUserLocationAnnotationView - -@end - -@implementation HiddenUserLocationAnnotationView - - -- (void)update { - self.frame = CGRectNull; -} - -@end - - -@implementation RCTMGLUserLocation : NSObject - -+ (id)sharedInstance -{ - static RCTMGLUserLocation *userLocation = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ userLocation = [[self alloc] init]; }); - return userLocation; -} - -- (MGLUserLocationAnnotationView*)hiddenUserAnnotation -{ - return [[HiddenUserLocationAnnotationView alloc] init]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLUtils.h b/ios/RCTMGL/RCTMGLUtils.h deleted file mode 100644 index d32381eabf..0000000000 --- a/ios/RCTMGL/RCTMGLUtils.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// RCTConvert+Mapbox.h -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import -#import -#import - -@import Mapbox; - -@interface RCTMGLUtils: NSObject - -+ (CLLocationCoordinate2D)fromFeature:(NSString*)json; -+ (MGLShape*)shapeFromGeoJSON:(NSString*)json; -+ (MGLCoordinateBounds)fromFeatureCollection:(NSString*)json; -+ (NSArray *)fromCoordinateBounds:(MGLCoordinateBounds)bounds; -+ (NSTimeInterval)fromMS:(NSNumber*)number; -+ (NSNumber*)clamp:(NSNumber*)value min:(NSNumber*)min max:(NSNumber*)max; -+ (UIColor*)toColor:(id)value; -+ (void)fetchImage:(RCTBridge*)bridge url:(NSString*)url scale:(double)scale callback:(RCTImageLoaderCompletionBlock)callback; -+ (void)fetchImages:(RCTBridge *)bridge style:(MGLStyle *)style objects:(NSDictionary*)objects forceUpdate:(BOOL)forceUpdate callback:(void (^)(void))callback; -+ (CGVector)toCGVector:(NSArray*)arr; -+ (UIEdgeInsets)toUIEdgeInsets:(NSArray *)arr; -+ (NSURL*)styleURLFromStyleJSON:(NSString *)styleJSON; - -@end diff --git a/ios/RCTMGL/RCTMGLUtils.m b/ios/RCTMGL/RCTMGLUtils.m deleted file mode 100644 index 1dca4bed43..0000000000 --- a/ios/RCTMGL/RCTMGLUtils.m +++ /dev/null @@ -1,218 +0,0 @@ -// -// RCTConvert+Mapbox.m -// RCTMGL -// -// Created by Nick Italiano on 8/23/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLUtils.h" -#import "RCTMGLImageQueue.h" - -@import Mapbox; - -@implementation RCTMGLUtils - -static double const MS_TO_S = 0.001; - -+ (CLLocationCoordinate2D)fromFeature:(NSString*)jsonStr -{ - NSData* data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding]; - MGLPointFeature *feature = (MGLPointFeature*)[MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:nil]; - return feature.coordinate; -} - -+ (UIEdgeInsets)toUIEdgeInsets:(NSArray *)arr -{ - return UIEdgeInsetsMake([arr[0] floatValue], [arr[1] floatValue], [arr[2] floatValue], [arr[3] floatValue]); -} - -+ (MGLShape*)shapeFromGeoJSON:(NSString*)jsonStr -{ - NSData* data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding]; - NSError* error = nil; - MGLShape* result = [MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:&error]; - if (error != nil) { - RCTLogWarn(@"Failed to convert data to shape error:%@ src:%@", error, jsonStr); - } - return result; -} - -+ (NSString *)hashURI:(NSString *)uri -{ - if (uri == nil) { - return @"-1"; - } - NSUInteger hash = [uri hash]; - return [NSString stringWithFormat:@"%lu", (unsigned long)hash]; -} - -+ (MGLCoordinateBounds)fromFeatureCollection:(NSString*)jsonStr -{ - NSData* data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding]; - MGLShapeCollectionFeature *featureCollection = (MGLShapeCollectionFeature*)[MGLShapeCollectionFeature shapeWithData:data encoding:NSUTF8StringEncoding error:nil]; - - CLLocationCoordinate2D ne = featureCollection.shapes[0].coordinate; - CLLocationCoordinate2D sw = featureCollection.shapes[1].coordinate; - - return MGLCoordinateBoundsMake(sw, ne); -} - -+ (NSArray *)fromCoordinateBounds:(MGLCoordinateBounds)bounds -{ - return @[ - @[@(bounds.ne.longitude), @(bounds.ne.latitude)], - @[@(bounds.sw.longitude), @(bounds.sw.latitude)] - ]; -} - -+ (NSTimeInterval)fromMS:(NSNumber *)number -{ - return [number doubleValue] * MS_TO_S; -} - -+ (NSNumber*)clamp:(NSNumber *)value min:(NSNumber *)min max:(NSNumber *)max -{ - if ([value doubleValue] < [min doubleValue]) return min; - if ([value doubleValue] > [max doubleValue]) return max; - return value; -} - -+ (UIColor*)toColor:(id)value -{ - return [RCTConvert UIColor:value]; -} - -+ (CGVector)toCGVector:(NSArray *)arr -{ - return CGVectorMake([arr[0] floatValue], [arr[1] floatValue]); -} - -+ (void)fetchImage:(RCTBridge*)bridge url:(NSString *)url scale:(double)scale callback:(RCTImageLoaderCompletionBlock)callback -{ - [RCTMGLImageQueue.sharedInstance addImage:url scale:scale bridge:bridge completionHandler:callback]; -} - -+ (void)fetchImages:(RCTBridge *)bridge style:(MGLStyle *)style objects:(NSDictionary*)objects forceUpdate:(BOOL)forceUpdate callback:(void (^)(void))callback -{ - if (objects == nil) { - callback(); - return; - } - - NSArray *imageNames = objects.allKeys; - if (imageNames.count == 0) { - callback(); - return; - } - - __block NSUInteger imagesLeftToLoad = imageNames.count; - __weak MGLStyle *weakStyle = style; - - void (^imageLoadedBlock)(void) = ^{ - imagesLeftToLoad--; - - if (imagesLeftToLoad == 0) { - callback(); - } - }; - - for (NSString *imageName in imageNames) { - UIImage *foundImage = forceUpdate ? nil : [style imageForName:imageName]; - - if (forceUpdate || foundImage == nil) { - NSDictionary* image = objects[imageName]; - BOOL hasScale = [image isKindOfClass:[NSDictionary class]] && ([image objectForKey:@"scale"] != nil); - double scale = hasScale ? [[image objectForKey:@"scale"] doubleValue] : 1.0; - [RCTMGLImageQueue.sharedInstance addImage:objects[imageName] scale:scale bridge:bridge completionHandler:^(NSError *error, UIImage *image) { - if (!image) { - RCTLogWarn(@"Failed to fetch image: %@ error:%@", imageName, error); - } - else { - dispatch_async(dispatch_get_main_queue(), ^{ - [weakStyle setImage:image forName:imageName]; - imageLoadedBlock(); - }); - } - }]; - } else { - imageLoadedBlock(); - } - } -} - -+ (NSString*)getStyleJsonTempDirectory -{ - static NSString *styleJsonTempDirectory; - if (!styleJsonTempDirectory) { - styleJsonTempDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:@"RCTMGLStyleJSON"]; - } - return styleJsonTempDirectory; -} - -/** - * Clears cached style-json entries from previous app runs. Can be safely called multiple times as it will - * only perform the action once per app run. - * - * @see styleURLFromStyleJSON: - */ -+ (void)cleanCustomStyleJSONCacheIfNeeded -{ - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *styleJsonTempDirectory = [RCTMGLUtils getStyleJsonTempDirectory]; - - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - if ([fileManager fileExistsAtPath:styleJsonTempDirectory]) { - [fileManager removeItemAtPath:styleJsonTempDirectory error:NULL]; - } - }); -} - -/** - * Provides a way to convert raw style-json into a file so it can be directly referenced / used as styleURL. - * It's a crude / alternative approach to support Android's API: Style.Builder.fromJson(). - */ -+ (NSURL*)styleURLFromStyleJSON:(NSString *)styleJSON -{ - [RCTMGLUtils cleanCustomStyleJSONCacheIfNeeded]; - - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *styleJsonTempDirectory = [RCTMGLUtils getStyleJsonTempDirectory]; - - // attempt to create the temporary directory - if (![fileManager fileExistsAtPath:styleJsonTempDirectory]) { - NSError *error; - [fileManager createDirectoryAtPath:styleJsonTempDirectory - withIntermediateDirectories:YES - attributes:nil - error:&error]; - if (error) { - RCTLogError(@"Failed to create temporary directory '%@' for storing style-json. Error: %@", styleJsonTempDirectory, error); - return nil; - } - } - - // Determine filename based on the md5 hash of the style-json. - // This way, the written file can also act as a cached entry in case - // the same style-json is used again. - NSString *hashedFilename = [RCTMD5Hash(styleJSON) stringByAppendingPathExtension:@"json"]; - - // Construct temporary file path (tempdir + md5 hash for filename) - NSString *styleJsonTempPath = [styleJsonTempDirectory stringByAppendingPathComponent:hashedFilename]; - NSURL* styleJsonTempURL = [NSURL fileURLWithPath:styleJsonTempPath isDirectory:false]; - - // Write style-json to temporary file in case it doesn't already exist - if (![fileManager fileExistsAtPath:styleJsonTempPath isDirectory:false]) { - NSError *error; - [styleJSON writeToURL:styleJsonTempURL atomically:YES encoding:NSUTF8StringEncoding error:&error]; - if (error) { - RCTLogError(@"Failed to write style-json to temporary file '%@'. Error: %@", styleJsonTempURL, error); - return nil; - } - } - - return styleJsonTempURL; -} - -@end diff --git a/ios/RCTMGL/RCTMGLVectorLayer.h b/ios/RCTMGL/RCTMGLVectorLayer.h deleted file mode 100644 index 6e7e2385d6..0000000000 --- a/ios/RCTMGL/RCTMGLVectorLayer.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// RCTMGLCircleLayer.h -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLLayer.h" - -@interface RCTMGLVectorLayer : RCTMGLLayer - -@property (nonatomic, copy) NSString *sourceLayerID; - -@end diff --git a/ios/RCTMGL/RCTMGLVectorLayer.m b/ios/RCTMGL/RCTMGLVectorLayer.m deleted file mode 100644 index 39a188ed16..0000000000 --- a/ios/RCTMGL/RCTMGLVectorLayer.m +++ /dev/null @@ -1,59 +0,0 @@ -// -// RCTMGLCircleLayer.m -// RCTMGL -// -// Created by Nick Italiano on 9/18/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLVectorLayer.h" -#import "RCTMGLStyle.h" -#import "FilterParser.h" -#import - -@implementation RCTMGLVectorLayer - - -- (NSPredicate*)buildFilters -{ - return self.filter ? [FilterParser parse:self.filter] : nil; -} - -- (void)updateFilter:(NSPredicate *)predicate -{ - @try { - ((MGLVectorStyleLayer *) self.styleLayer).predicate = predicate; - } - @catch (NSException* exception) { - RCTLogError(@"Invalid predicate: %@ on layer %@ - %@ reason: %@", predicate, self, exception.name, exception.reason); - } -} - -- (void)setSourceLayerID:(NSString *)sourceLayerID -{ - _sourceLayerID = sourceLayerID; - - if (self.styleLayer != nil) { - ((MGLVectorStyleLayer*) self.styleLayer).sourceLayerIdentifier = _sourceLayerID; - } -} - -- (void)addedToMap -{ - NSPredicate *filter = [self buildFilters]; - if (filter != nil) { - [self updateFilter:filter]; - } -} - -- (void)setFilter:(NSArray*)filter -{ - [super setFilter: filter]; - - if (self.styleLayer != nil) { - NSPredicate *predicate = [self buildFilters]; - [self updateFilter:predicate]; - } -} - -@end diff --git a/ios/RCTMGL/RCTMGLVectorSource.h b/ios/RCTMGL/RCTMGLVectorSource.h deleted file mode 100644 index 98263940dc..0000000000 --- a/ios/RCTMGL/RCTMGLVectorSource.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// RCTMGLVectorSource.h -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLTileSource.h" -@import Mapbox; - -@interface RCTMGLVectorSource : RCTMGLTileSource - -- (nonnull NSArray> *)featuresInSourceLayersWithIdentifiers:(nonnull NSSet *)sourceLayerIdentifiers predicate:(nullable NSPredicate *)predicate; - -@end diff --git a/ios/RCTMGL/RCTMGLVectorSource.m b/ios/RCTMGL/RCTMGLVectorSource.m deleted file mode 100644 index 84e5ff51f6..0000000000 --- a/ios/RCTMGL/RCTMGLVectorSource.m +++ /dev/null @@ -1,28 +0,0 @@ -// -// RCTMGLVectorSource.m -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "RCTMGLVectorSource.h" - -@implementation RCTMGLVectorSource - -- (nullable MGLSource*)makeSource -{ - if (self.url != nil) { - return [[MGLVectorTileSource alloc] initWithIdentifier:self.id configurationURL:[NSURL URLWithString:self.url]]; - } - return [[MGLVectorTileSource alloc] initWithIdentifier:self.id tileURLTemplates:self.tileUrlTemplates options:[self getOptions]]; -} - -- (nonnull NSArray> *)featuresInSourceLayersWithIdentifiers:(nonnull NSSet *)sourceLayerIdentifiers predicate:(nullable NSPredicate *)predicate -{ - MGLVectorTileSource* vectorSource = (MGLVectorTileSource*)self.source; - - return [vectorSource featuresInSourceLayersWithIdentifiers:sourceLayerIdentifiers predicate: predicate]; -} - -@end diff --git a/ios/RCTMGL/RCTMGLVectorSourceManager.h b/ios/RCTMGL/RCTMGLVectorSourceManager.h deleted file mode 100644 index 5d1b5cefd1..0000000000 --- a/ios/RCTMGL/RCTMGLVectorSourceManager.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// RCTMGLVectorSourceManager.h -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" -#import - -@interface RCTMGLVectorSourceManager : ViewManager - -@end diff --git a/ios/RCTMGL/RCTMGLVectorSourceManager.m b/ios/RCTMGL/RCTMGLVectorSourceManager.m deleted file mode 100644 index 662156e90f..0000000000 --- a/ios/RCTMGL/RCTMGLVectorSourceManager.m +++ /dev/null @@ -1,79 +0,0 @@ -// -// RCTMGLVectorSourceManager.m -// RCTMGL -// -// Created by Nick Italiano on 9/8/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import - -#import "RCTMGLVectorSourceManager.h" -#import "RCTMGLVectorSource.h" - -#import "FilterParser.h" - -@implementation RCTMGLVectorSourceManager - -RCT_EXPORT_MODULE(RCTMGLVectorSource); - -RCT_EXPORT_VIEW_PROPERTY(id, NSString); - -- (UIView*)view -{ - return [RCTMGLVectorSource new]; -} - -RCT_EXPORT_VIEW_PROPERTY(url, NSString) -RCT_EXPORT_VIEW_PROPERTY(tileUrlTemplates, NSArray) -RCT_EXPORT_VIEW_PROPERTY(attribution, NSString) - -RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, NSNumber) - -RCT_EXPORT_VIEW_PROPERTY(tms, BOOL) -RCT_EXPORT_VIEW_PROPERTY(hasPressListener, BOOL) -RCT_REMAP_VIEW_PROPERTY(onMapboxVectorSourcePress, onPress, RCTBubblingEventBlock) -RCT_EXPORT_VIEW_PROPERTY(hitbox, NSDictionary) - - -RCT_EXPORT_METHOD(features:(nonnull NSNumber*)reactTag - withLayerIDs:(NSArray*)layerIDs - withFilter:(NSArray *> *)filter - resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary *viewRegistry) { - RCTMGLVectorSource* vectorSource = viewRegistry[reactTag]; - - if (![vectorSource isKindOfClass:[RCTMGLVectorSource class]]) { - RCTLogError(@"Invalid react tag, could not find RCTMGLMapView"); - return; - } - - NSSet* layerIDSet = nil; - if (layerIDs != nil && layerIDs.count > 0) { - layerIDSet = [NSSet setWithArray:layerIDs]; - } - NSPredicate* predicate = [FilterParser parse:filter]; - NSArray> *shapes = [vectorSource - featuresInSourceLayersWithIdentifiers: layerIDSet - predicate: predicate]; - - NSMutableArray *features = [[NSMutableArray alloc] initWithCapacity:shapes.count]; - for (int i = 0; i < shapes.count; i++) { - [features addObject:shapes[i].geoJSONDictionary]; - } - - resolve(@{ - @"data": @{ @"type": @"FeatureCollection", @"features": features } - }); - }]; -} - -RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location) -{ - RCTLogInfo(@"Pretending to create an event %@ at %@", name, location); -} - -@end diff --git a/ios/RCTMGL/RNMBImageUtils.h b/ios/RCTMGL/RNMBImageUtils.h deleted file mode 100644 index 8800fe3ca0..0000000000 --- a/ios/RCTMGL/RNMBImageUtils.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// RNMBImageUtils.h -// RCTMGL -// -// Created by Nick Italiano on 1/18/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import -#import - -@interface RNMBImageUtils : NSObject - -+(NSString *)createTempFile:(UIImage *)image; -+(NSString *)createBase64:(UIImage *)image; - -@end diff --git a/ios/RCTMGL/RNMBImageUtils.m b/ios/RCTMGL/RNMBImageUtils.m deleted file mode 100644 index be96749988..0000000000 --- a/ios/RCTMGL/RNMBImageUtils.m +++ /dev/null @@ -1,31 +0,0 @@ -// -// RNMBImageUtils.m -// RCTMGL -// -// Created by Nick Italiano on 1/18/18. -// Copyright © 2018 Mapbox Inc. All rights reserved. -// - -#import "RNMBImageUtils.h" - -@implementation RNMBImageUtils - -+ (NSString *)createTempFile:(UIImage *)image -{ - NSString *fileID = [[NSUUID UUID] UUIDString]; - NSString *pathComponent = [NSString stringWithFormat:@"Documents/rctmgl-snapshot-%@.%@", fileID, @"png"]; - NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: pathComponent]; - - NSData *data = UIImagePNGRepresentation(image); - [data writeToFile:filePath atomically:YES]; - - return filePath; -} - -+ (NSString *)createBase64:(UIImage *)image -{ - NSData *data = UIImagePNGRepresentation(image); - return [NSString stringWithFormat:@"%@%@", @"data:image/png;base64,", [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]]; -} - -@end diff --git a/ios/RCTMGL/ViewManager.h b/ios/RCTMGL/ViewManager.h deleted file mode 100644 index 83a5b1d8b2..0000000000 --- a/ios/RCTMGL/ViewManager.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// ViewManager.h -// RCTMGL -// -// Created by Nick Italiano on 8/31/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import -#import "RCTMGLEvent.h" - -@interface ViewManager : RCTViewManager - --(void)fireEvent:(RCTMGLEvent*)event withCallback:(RCTBubblingEventBlock)callback; - -@end diff --git a/ios/RCTMGL/ViewManager.m b/ios/RCTMGL/ViewManager.m deleted file mode 100644 index 6eb5cd2aaf..0000000000 --- a/ios/RCTMGL/ViewManager.m +++ /dev/null @@ -1,63 +0,0 @@ -// -// ViewManager.m -// RCTMGL -// -// Created by Nick Italiano on 8/31/17. -// Copyright © 2017 Mapbox Inc. All rights reserved. -// - -#import "ViewManager.h" - -@implementation ViewManager -{ - NSMutableDictionary *eventTimestampCache; -} - -+ (BOOL)requiresMainQueueSetup -{ - return YES; -} - -+ (NSString *)moduleName -{ - // Hack, to prevent JS from throwing a useless warning - return @"RCTViewManager"; -} - -static NSTimeInterval EVENT_THROTTLE_S = 0.01; - -- (instancetype)init -{ - if (self = [super init]) { - eventTimestampCache = [[NSMutableDictionary alloc] init]; - } - - return self; -} - -- (void)fireEvent:(RCTMGLEvent*)event withCallback:(RCTBubblingEventBlock)callback -{ - if (![self _shouldDropEvent:event]) { - NSString *cacheKey = [self _getCacheKey:event]; - NSTimeInterval now = [[NSDate date] timeIntervalSince1970]; - [eventTimestampCache setObject:[NSNumber numberWithDouble:now] forKey:cacheKey]; - - if (callback != nil) { - callback([event toJSON]); - } - } -} - -- (BOOL)_shouldDropEvent:(RCTMGLEvent *)event -{ - NSString *cacheKey = [self _getCacheKey:event]; - NSNumber *lastTimestamp = [eventTimestampCache objectForKey:cacheKey]; - return lastTimestamp != nil && (event.timestamp - [lastTimestamp doubleValue]) <= EVENT_THROTTLE_S; -} - -- (NSString*)_getCacheKey:(RCTMGLEvent*)event -{ - return event.type; -} - -@end diff --git a/ios/RCTMGL/index.d.ts b/ios/RCTMGL/index.d.ts deleted file mode 100644 index 3c19b6ab6b..0000000000 --- a/ios/RCTMGL/index.d.ts +++ /dev/null @@ -1,1116 +0,0 @@ -/* eslint-disable */ -// DO NOT MODIFY -// THIS FILE IS AUTOGENERATED - -export interface ConstantProps { - styletype: string; - payload: { - value: any; - }; -} - -export interface StyleFunctionProps { - styletype: string; - payload: { - fn: string; - attributeName: string; - stops: any[]; - mode: any; - }; -} - -export interface TransitionProps { - duration: number; - delay: number; -} - -export type TranslationProps = { x: number; y: number } | number[]; - -export interface fillLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * Whether or not the fill should be antialiased. - */ - fillAntialias: string; - - /** - * The opacity of the entire fill layer. In contrast to the `fillColor`, this value will also affect the 1px stroke around the fill, if the stroke is used. - */ - fillOpacity: number; - - /** - * The transition affecting any changes to this layer’s fillOpacity property. - */ - fillOpacityTransition: TransitionProps; - - /** - * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. - * - * @disabledBy fillPattern - */ - fillColor: string; - - /** - * The transition affecting any changes to this layer’s fillColor property. - */ - fillColorTransition: TransitionProps; - - /** - * The outline color of the fill. Matches the value of `fillColor` if unspecified. - * - * @disabledBy fillPattern - */ - fillOutlineColor: string; - - /** - * The transition affecting any changes to this layer’s fillOutlineColor property. - */ - fillOutlineColorTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - */ - fillTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s fillTranslate property. - */ - fillTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `fillTranslate`. - * - * @requires fillTranslate - */ - fillTranslateAnchor: TranslationProps; - - /** - * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoomDependent expressions will be evaluated only at integer zoom levels. - */ - fillPattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s fillPattern property. - */ - fillPatternTransition: TransitionProps; -} - -export interface lineLayerStyleProps { - /** - * The display of line endings. - */ - lineCap: any; - - /** - * The display of lines when joining. - */ - lineJoin: TransitionProps | any | StyleFunctionProps; - - /** - * Used to automatically convert miter joins to bevel joins for sharp angles. - */ - lineMiterLimit: number; - - /** - * Used to automatically convert round joins to miter joins for shallow angles. - */ - lineRoundLimit: number; - - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity at which the line will be drawn. - */ - lineOpacity: number; - - /** - * The transition affecting any changes to this layer’s lineOpacity property. - */ - lineOpacityTransition: TransitionProps; - - /** - * The color with which the line will be drawn. - * - * @disabledBy linePattern - */ - lineColor: string; - - /** - * The transition affecting any changes to this layer’s lineColor property. - */ - lineColorTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - */ - lineTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s lineTranslate property. - */ - lineTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `lineTranslate`. - * - * @requires lineTranslate - */ - lineTranslateAnchor: TranslationProps; - - /** - * Stroke thickness. - */ - lineWidth: TransitionProps | number | StyleFunctionProps; - - /** - * The transition affecting any changes to this layer’s lineWidth property. - */ - lineWidthTransition: TransitionProps; - - /** - * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. - */ - lineGapWidth: number; - - /** - * The transition affecting any changes to this layer’s lineGapWidth property. - */ - lineGapWidthTransition: TransitionProps; - - /** - * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. - */ - lineOffset: number; - - /** - * The transition affecting any changes to this layer’s lineOffset property. - */ - lineOffsetTransition: TransitionProps; - - /** - * Blur applied to the line, in pixels. - */ - lineBlur: number; - - /** - * The transition affecting any changes to this layer’s lineBlur property. - */ - lineBlurTransition: TransitionProps; - - /** - * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. Note that GeoJSON sources with `lineMetrics: true` specified won't render dashed lines to the expected scale. Also note that zoomDependent expressions will be evaluated only at integer zoom levels. - * - * @disabledBy linePattern - */ - lineDasharray: number[]; - - /** - * The transition affecting any changes to this layer’s lineDasharray property. - */ - lineDasharrayTransition: TransitionProps; - - /** - * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). Note that zoomDependent expressions will be evaluated only at integer zoom levels. - */ - linePattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s linePattern property. - */ - linePatternTransition: TransitionProps; - - /** - * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`. - * - * @disabledBy lineDasharray, linePattern - */ - lineGradient: string; -} - -export interface symbolLayerStyleProps { - /** - * Label placement relative to its geometry. - */ - symbolPlacement: any; - - /** - * Distance between two symbol anchors. - */ - symbolSpacing: number; - - /** - * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. When using a client that supports global collision detection, like Mapbox GL JS version 0.42.0 or greater, enabling this property is not needed to prevent clipped labels at tile boundaries. - */ - symbolAvoidEdges: string; - - /** - * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key when they overlap. Features with a lower sort key will have priority over other features when doing placement. - */ - symbolSortKey: number; - - /** - * Controls the order in which overlapping symbols in the same layer are rendered - */ - symbolZOrder: any; - - /** - * If true, the icon will be visible even if it collides with other previously drawn symbols. - * - * @requires iconImage - */ - iconAllowOverlap: string; - - /** - * If true, other symbols can be visible even if they collide with the icon. - * - * @requires iconImage - */ - iconIgnorePlacement: string; - - /** - * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. - * - * @requires iconImage, textField - */ - iconOptional: string; - - /** - * In combination with `symbolPlacement`, determines the rotation behavior of icons. - * - * @requires iconImage - */ - iconRotationAlignment: any; - - /** - * Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by `iconSize`. 1 is the original size; 3 triples the size of the image. - * - * @requires iconImage - */ - iconSize: number; - - /** - * Scales the icon to fit around the associated text. - * - * @requires iconImage, textField - */ - iconTextFit: any; - - /** - * Size of the additional area added to dimensions determined by `iconTextFit`, in clockwise order: top, right, bottom, left. - * - * @requires iconImage, textField - */ - iconTextFitPadding: number[]; - - /** - * Name of image in sprite to use for drawing an image background. - */ - iconImage: TransitionProps | number | string; - - /** - * Rotates the icon clockwise. - * - * @requires iconImage - */ - iconRotate: number; - - /** - * Size of the additional area around the icon bounding box used for detecting symbol collisions. - * - * @requires iconImage - */ - iconPadding: number; - - /** - * If true, the icon may be flipped to prevent it from being rendered upsideDown. - * - * @requires iconImage - */ - iconKeepUpright: string; - - /** - * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of `iconSize` to obtain the final offset in pixels. When combined with `iconRotate` the offset will be as if the rotated direction was up. - * - * @requires iconImage - */ - iconOffset: number[]; - - /** - * Part of the icon placed closest to the anchor. - * - * @requires iconImage - */ - iconAnchor: any; - - /** - * Orientation of icon when map is pitched. - * - * @requires iconImage - */ - iconPitchAlignment: any; - - /** - * Orientation of text when map is pitched. - * - * @requires textField - */ - textPitchAlignment: any; - - /** - * In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. - * - * @requires textField - */ - textRotationAlignment: any; - - /** - * Value to use for a text label. If a plain `string` is provided, it will be treated as a `formatted` with default/inherited formatting options. - */ - textField: string; - - /** - * Font stack to use for displaying text. - * - * @requires textField - */ - textFont: TransitionProps | string[] | any[] | StyleFunctionProps; - - /** - * Font size. - * - * @requires textField - */ - textSize: number; - - /** - * The maximum line width for text wrapping. - * - * @requires textField - */ - textMaxWidth: TransitionProps | number | StyleFunctionProps; - - /** - * Text leading value for multiLine text. - * - * @requires textField - */ - textLineHeight: number; - - /** - * Text tracking amount. - * - * @requires textField - */ - textLetterSpacing: TransitionProps | number | StyleFunctionProps; - - /** - * Text justification options. - * - * @requires textField - */ - textJustify: TransitionProps | any | StyleFunctionProps; - - /** - * Radial offset of text, in the direction of the symbol's anchor. Useful in combination with `textVariableAnchor`, which defaults to using the twoDimensional `textOffset` if present. - * - * @requires textField - */ - textRadialOffset: number; - - /** - * To increase the chance of placing highPriority labels on the map, you can provide an array of `textAnchor` locations: the renderer will attempt to place the label at each location, in order, before moving onto the next label. Use `textJustify: auto` to choose justification based on anchor position. To apply an offset, use the `textRadialOffset` or the twoDimensional `textOffset`. - * - * @requires textField - */ - textVariableAnchor: any[]; - - /** - * Part of the text placed closest to the anchor. - * - * @requires textField - * - * @disabledBy textVariableAnchor - */ - textAnchor: TransitionProps | any | StyleFunctionProps; - - /** - * Maximum angle change between adjacent characters. - * - * @requires textField - */ - textMaxAngle: number; - - /** - * The property allows control over a symbol's orientation. Note that the property values act as a hint, so that a symbol whose language doesn’t support the provided orientation will be laid out in its natural orientation. Example: English point symbol will be rendered horizontally even if array value contains single 'vertical' enum value. The order of elements in an array define priority order for the placement of an orientation variant. - * - * @requires textField - */ - textWritingMode: any[]; - - /** - * Rotates the text clockwise. - * - * @requires textField - */ - textRotate: number; - - /** - * Size of the additional area around the text bounding box used for detecting symbol collisions. - * - * @requires textField - */ - textPadding: number; - - /** - * If true, the text may be flipped vertically to prevent it from being rendered upsideDown. - * - * @requires textField - */ - textKeepUpright: string; - - /** - * Specifies how to capitalize text, similar to the CSS `textTransform` property. - * - * @requires textField - */ - textTransform: any; - - /** - * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. If used with textVariableAnchor, input values will be taken as absolute values. Offsets along the x and yAxis will be applied automatically based on the anchor position. - * - * @requires textField - * - * @disabledBy textRadialOffset - */ - textOffset: number[]; - - /** - * If true, the text will be visible even if it collides with other previously drawn symbols. - * - * @requires textField - */ - textAllowOverlap: string; - - /** - * If true, other symbols can be visible even if they collide with the text. - * - * @requires textField - */ - textIgnorePlacement: string; - - /** - * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. - * - * @requires textField, iconImage - */ - textOptional: string; - - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity at which the icon will be drawn. - * - * @requires iconImage - */ - iconOpacity: number; - - /** - * The transition affecting any changes to this layer’s iconOpacity property. - */ - iconOpacityTransition: TransitionProps; - - /** - * The color of the icon. This can only be used with sdf icons. - * - * @requires iconImage - */ - iconColor: string; - - /** - * The transition affecting any changes to this layer’s iconColor property. - */ - iconColorTransition: TransitionProps; - - /** - * The color of the icon's halo. Icon halos can only be used with SDF icons. - * - * @requires iconImage - */ - iconHaloColor: string; - - /** - * The transition affecting any changes to this layer’s iconHaloColor property. - */ - iconHaloColorTransition: TransitionProps; - - /** - * Distance of halo to the icon outline. - * - * @requires iconImage - */ - iconHaloWidth: number; - - /** - * The transition affecting any changes to this layer’s iconHaloWidth property. - */ - iconHaloWidthTransition: TransitionProps; - - /** - * Fade out the halo towards the outside. - * - * @requires iconImage - */ - iconHaloBlur: number; - - /** - * The transition affecting any changes to this layer’s iconHaloBlur property. - */ - iconHaloBlurTransition: TransitionProps; - - /** - * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. - * - * @requires iconImage - */ - iconTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s iconTranslate property. - */ - iconTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `iconTranslate`. - * - * @requires iconImage, iconTranslate - */ - iconTranslateAnchor: TranslationProps; - - /** - * The opacity at which the text will be drawn. - * - * @requires textField - */ - textOpacity: number; - - /** - * The transition affecting any changes to this layer’s textOpacity property. - */ - textOpacityTransition: TransitionProps; - - /** - * The color with which the text will be drawn. - * - * @requires textField - */ - textColor: string; - - /** - * The transition affecting any changes to this layer’s textColor property. - */ - textColorTransition: TransitionProps; - - /** - * The color of the text's halo, which helps it stand out from backgrounds. - * - * @requires textField - */ - textHaloColor: string; - - /** - * The transition affecting any changes to this layer’s textHaloColor property. - */ - textHaloColorTransition: TransitionProps; - - /** - * Distance of halo to the font outline. Max text halo width is 1/4 of the fontSize. - * - * @requires textField - */ - textHaloWidth: number; - - /** - * The transition affecting any changes to this layer’s textHaloWidth property. - */ - textHaloWidthTransition: TransitionProps; - - /** - * The halo's fadeout distance towards the outside. - * - * @requires textField - */ - textHaloBlur: number; - - /** - * The transition affecting any changes to this layer’s textHaloBlur property. - */ - textHaloBlurTransition: TransitionProps; - - /** - * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. - * - * @requires textField - */ - textTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s textTranslate property. - */ - textTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `textTranslate`. - * - * @requires textField, textTranslate - */ - textTranslateAnchor: TranslationProps; -} - -export interface circleLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * Circle radius. - */ - circleRadius: number; - - /** - * The transition affecting any changes to this layer’s circleRadius property. - */ - circleRadiusTransition: TransitionProps; - - /** - * The fill color of the circle. - */ - circleColor: string; - - /** - * The transition affecting any changes to this layer’s circleColor property. - */ - circleColorTransition: TransitionProps; - - /** - * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. - */ - circleBlur: number; - - /** - * The transition affecting any changes to this layer’s circleBlur property. - */ - circleBlurTransition: TransitionProps; - - /** - * The opacity at which the circle will be drawn. - */ - circleOpacity: number; - - /** - * The transition affecting any changes to this layer’s circleOpacity property. - */ - circleOpacityTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - */ - circleTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s circleTranslate property. - */ - circleTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `circleTranslate`. - * - * @requires circleTranslate - */ - circleTranslateAnchor: TranslationProps; - - /** - * Controls the scaling behavior of the circle when the map is pitched. - */ - circlePitchScale: any; - - /** - * Orientation of circle when map is pitched. - */ - circlePitchAlignment: any; - - /** - * The width of the circle's stroke. Strokes are placed outside of the `circleRadius`. - */ - circleStrokeWidth: number; - - /** - * The transition affecting any changes to this layer’s circleStrokeWidth property. - */ - circleStrokeWidthTransition: TransitionProps; - - /** - * The stroke color of the circle. - */ - circleStrokeColor: string; - - /** - * The transition affecting any changes to this layer’s circleStrokeColor property. - */ - circleStrokeColorTransition: TransitionProps; - - /** - * The opacity of the circle's stroke. - */ - circleStrokeOpacity: number; - - /** - * The transition affecting any changes to this layer’s circleStrokeOpacity property. - */ - circleStrokeOpacityTransition: TransitionProps; -} - -export interface heatmapLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * Radius of influence of one heatmap point in pixels. Increasing the value makes the heatmap smoother, but less detailed. - */ - heatmapRadius: number; - - /** - * The transition affecting any changes to this layer’s heatmapRadius property. - */ - heatmapRadiusTransition: TransitionProps; - - /** - * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering. - */ - heatmapWeight: number; - - /** - * Similar to `heatmapWeight` but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level. - */ - heatmapIntensity: number; - - /** - * The transition affecting any changes to this layer’s heatmapIntensity property. - */ - heatmapIntensityTransition: TransitionProps; - - /** - * Defines the color of each pixel based on its density value in a heatmap. Should be an expression that uses `["heatmapDensity"]` as input. - */ - heatmapColor: string; - - /** - * The global opacity at which the heatmap layer will be drawn. - */ - heatmapOpacity: number; - - /** - * The transition affecting any changes to this layer’s heatmapOpacity property. - */ - heatmapOpacityTransition: TransitionProps; -} - -export interface fillExtrusionLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity of the entire fill extrusion layer. This is rendered on a perLayer, not perFeature, basis, and dataDriven styling is not available. - */ - fillExtrusionOpacity: number; - - /** - * The transition affecting any changes to this layer’s fillExtrusionOpacity property. - */ - fillExtrusionOpacityTransition: TransitionProps; - - /** - * The base color of the extruded fill. The extrusion's surfaces will be shaded differently based on this color in combination with the root `light` settings. If this color is specified as `rgba` with an alpha component, the alpha component will be ignored; use `fillExtrusionOpacity` to set layer opacity. - * - * @disabledBy fillExtrusionPattern - */ - fillExtrusionColor: string; - - /** - * The transition affecting any changes to this layer’s fillExtrusionColor property. - */ - fillExtrusionColorTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up (on the flat plane), respectively. - */ - fillExtrusionTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s fillExtrusionTranslate property. - */ - fillExtrusionTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `fillExtrusionTranslate`. - * - * @requires fillExtrusionTranslate - */ - fillExtrusionTranslateAnchor: TranslationProps; - - /** - * Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoomDependent expressions will be evaluated only at integer zoom levels. - */ - fillExtrusionPattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s fillExtrusionPattern property. - */ - fillExtrusionPatternTransition: TransitionProps; - - /** - * The height with which to extrude this layer. - */ - fillExtrusionHeight: number; - - /** - * The transition affecting any changes to this layer’s fillExtrusionHeight property. - */ - fillExtrusionHeightTransition: TransitionProps; - - /** - * The height with which to extrude the base of this layer. Must be less than or equal to `fillExtrusionHeight`. - * - * @requires fillExtrusionHeight - */ - fillExtrusionBase: number; - - /** - * The transition affecting any changes to this layer’s fillExtrusionBase property. - */ - fillExtrusionBaseTransition: TransitionProps; -} - -export interface rasterLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity at which the image will be drawn. - */ - rasterOpacity: number; - - /** - * The transition affecting any changes to this layer’s rasterOpacity property. - */ - rasterOpacityTransition: TransitionProps; - - /** - * Rotates hues around the color wheel. - */ - rasterHueRotate: number; - - /** - * The transition affecting any changes to this layer’s rasterHueRotate property. - */ - rasterHueRotateTransition: TransitionProps; - - /** - * Increase or reduce the brightness of the image. The value is the minimum brightness. - */ - rasterBrightnessMin: number; - - /** - * The transition affecting any changes to this layer’s rasterBrightnessMin property. - */ - rasterBrightnessMinTransition: TransitionProps; - - /** - * Increase or reduce the brightness of the image. The value is the maximum brightness. - */ - rasterBrightnessMax: number; - - /** - * The transition affecting any changes to this layer’s rasterBrightnessMax property. - */ - rasterBrightnessMaxTransition: TransitionProps; - - /** - * Increase or reduce the saturation of the image. - */ - rasterSaturation: number; - - /** - * The transition affecting any changes to this layer’s rasterSaturation property. - */ - rasterSaturationTransition: TransitionProps; - - /** - * Increase or reduce the contrast of the image. - */ - rasterContrast: number; - - /** - * The transition affecting any changes to this layer’s rasterContrast property. - */ - rasterContrastTransition: TransitionProps; - - /** - * The resampling/interpolation method to use for overscaling, also known as texture magnification filter - */ - rasterResampling: any; - - /** - * Fade duration when a new tile is added. - */ - rasterFadeDuration: number; -} - -export interface hillshadeLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if `hillshadeIlluminationAnchor` is set to `viewport` and due north if `hillshadeIlluminationAnchor` is set to `map`. - */ - hillshadeIlluminationDirection: number; - - /** - * Direction of light source when map is rotated. - */ - hillshadeIlluminationAnchor: any; - - /** - * Intensity of the hillshade - */ - hillshadeExaggeration: number; - - /** - * The transition affecting any changes to this layer’s hillshadeExaggeration property. - */ - hillshadeExaggerationTransition: TransitionProps; - - /** - * The shading color of areas that face away from the light source. - */ - hillshadeShadowColor: string; - - /** - * The transition affecting any changes to this layer’s hillshadeShadowColor property. - */ - hillshadeShadowColorTransition: TransitionProps; - - /** - * The shading color of areas that faces towards the light source. - */ - hillshadeHighlightColor: string; - - /** - * The transition affecting any changes to this layer’s hillshadeHighlightColor property. - */ - hillshadeHighlightColorTransition: TransitionProps; - - /** - * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. - */ - hillshadeAccentColor: string; - - /** - * The transition affecting any changes to this layer’s hillshadeAccentColor property. - */ - hillshadeAccentColorTransition: TransitionProps; -} - -export interface backgroundLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The color with which the background will be drawn. - * - * @disabledBy backgroundPattern - */ - backgroundColor: string; - - /** - * The transition affecting any changes to this layer’s backgroundColor property. - */ - backgroundColorTransition: TransitionProps; - - /** - * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoomDependent expressions will be evaluated only at integer zoom levels. - */ - backgroundPattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s backgroundPattern property. - */ - backgroundPatternTransition: TransitionProps; - - /** - * The opacity at which the background will be drawn. - */ - backgroundOpacity: number; - - /** - * The transition affecting any changes to this layer’s backgroundOpacity property. - */ - backgroundOpacityTransition: TransitionProps; -} - -export interface lightLayerStyleProps { - /** - * Whether extruded geometries are lit relative to the map or viewport. - */ - anchor: any; - - /** - * Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). - */ - position: number[]; - - /** - * The transition affecting any changes to this layer’s position property. - */ - positionTransition: TransitionProps; - - /** - * Color tint for lighting extruded geometries. - */ - color: string; - - /** - * The transition affecting any changes to this layer’s color property. - */ - colorTransition: TransitionProps; - - /** - * Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. - */ - intensity: number; - - /** - * The transition affecting any changes to this layer’s intensity property. - */ - intensityTransition: TransitionProps; -} diff --git a/react-native-mapbox-gl.podspec b/react-native-mapbox-gl.podspec index cceaa53b24..5ac26b1e3e 100644 --- a/react-native-mapbox-gl.podspec +++ b/react-native-mapbox-gl.podspec @@ -2,13 +2,14 @@ require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) -default_ios_mapbox_version = '~> 5.9.0' +default_ios_mapbox_version = '~> 10.0.0-beta.15' + rnmbgl_ios_version = $ReactNativeMapboxGLIOSVersion || ENV["REACT_NATIVE_MAPBOX_MAPBOX_IOS_VERSION"] || default_ios_mapbox_version if ENV.has_key?("REACT_NATIVE_MAPBOX_MAPBOX_IOS_VERSION") puts "REACT_NATIVE_MAPBOX_MAPBOX_IOS_VERSION env is deprecated please use `$ReactNativeMapboxGLIOSVersion = \"#{rnmbgl_ios_version}\"`" end -TargetsToChangeToDynamic = ['MapboxMobileEvents'] +TargetsToChangeToDynamic = ['MapboxMobileEvents', 'Turf'] $RNMBGL = Object.new @@ -42,14 +43,16 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/@react-native-mapbox-gl/maps#readme" s.source = { :git => "https://github.com/@react-native-mapbox-gl/maps.git" } s.license = "MIT" - s.platform = :ios, "8.0" + s.platform = :ios, "13.0" - s.dependency 'Mapbox-iOS-SDK', rnmbgl_ios_version + s.dependency 'MapboxMaps', rnmbgl_ios_version + s.dependency 'Turf' s.dependency 'React-Core' s.dependency 'React' - + s.swift_version = '5.0' s.subspec 'DynamicLibrary' do |sp| - sp.source_files = "ios/RCTMGL/**/*.{h,m}" + sp.source_files = "ios/RCTMGL/**/*.{h,m,swift}" + s.public_header_files = 'ios/RCTMGL/Bridge/*.h' end if ENV["REACT_NATIVE_MAPBOX_GL_USE_FRAMEWORKS"] From 9199f959fd4936071ab0d120caabd11fba06bb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Wed, 10 Mar 2021 12:39:14 +0100 Subject: [PATCH 2/2] Support onPRess and onMapChange --- ios/RCTMGL/MGLModule.swift | 10 +++- ios/RCTMGL/RCTMGLEvent.swift | 32 +++++++++++ ios/RCTMGL/RCTMGLLogging.swift | 9 +++ ios/RCTMGL/RCTMGLMapView.swift | 91 ++++++++++++++++++++++++++++++- ios/RCTMGL/RCTMGLMapViewManager.m | 2 + 5 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 ios/RCTMGL/RCTMGLEvent.swift diff --git a/ios/RCTMGL/MGLModule.swift b/ios/RCTMGL/MGLModule.swift index 168366b6b9..a145b9267f 100644 --- a/ios/RCTMGL/MGLModule.swift +++ b/ios/RCTMGL/MGLModule.swift @@ -25,7 +25,15 @@ class MGLModule : NSObject { "LineJoin": ["Round": LineJoin.round], "LocationCallbackName": - ["Update": RCT_MAPBOX_USER_LOCATION_UPDATE] + ["Update": RCT_MAPBOX_USER_LOCATION_UPDATE], + "CameraModes": + [ + "Ease": "ease", + ], + "EventTypes": + [ + "RegionDidChange" : RCTMGLEvent.EventType.regionDidChange.rawValue + ], ]; } diff --git a/ios/RCTMGL/RCTMGLEvent.swift b/ios/RCTMGL/RCTMGLEvent.swift new file mode 100644 index 0000000000..f318b5b311 --- /dev/null +++ b/ios/RCTMGL/RCTMGLEvent.swift @@ -0,0 +1,32 @@ +import Foundation + +protocol RCTMGLEventProtocol { + + func toJSON() -> [String: Any]; +} + +@objc +class RCTMGLEvent : NSObject, RCTMGLEventProtocol { + var type: String = "" + var payload: [String:Any]? = nil + func toJSON() -> [String: Any] + { + if let payload = payload { + return ["type": type, "payload": payload]; + } else { + return ["type": type] + } + } + + enum EventType : String { + case tap = "press" + case regionDidChange = "regiondidchange" + } + + init(type: EventType, payload: [String:Any]?) { + self.type = type.rawValue + self.payload = payload + } + +} + diff --git a/ios/RCTMGL/RCTMGLLogging.swift b/ios/RCTMGL/RCTMGLLogging.swift index a57df5e9c7..ec29cb4107 100644 --- a/ios/RCTMGL/RCTMGLLogging.swift +++ b/ios/RCTMGL/RCTMGLLogging.swift @@ -3,6 +3,15 @@ import MapboxMaps @objc(RCTMGLLogging) class RCTMGLLogging: RCTEventEmitter { + + enum ErrorType { + case argumentError + } + + static func error(_ errorType : ErrorType, _ message: String) { + print("RCTMGL error \(message)") + } + @objc static override func requiresMainQueueSetup() -> Bool { return true diff --git a/ios/RCTMGL/RCTMGLMapView.swift b/ios/RCTMGL/RCTMGLMapView.swift index d2dc520ac5..0dc4c54601 100644 --- a/ios/RCTMGL/RCTMGLMapView.swift +++ b/ios/RCTMGL/RCTMGLMapView.swift @@ -1,8 +1,97 @@ import MapboxMaps +import Turf @objc class RCTMGLMapView : MapView { + var reactOnPress : RCTBubblingEventBlock? = nil + var reactOnMapChange : RCTBubblingEventBlock? = nil + + var mapView : MapView { + get { return self } + } + @objc func setReactStyleURL(_ value: String) { - self.style.styleURL = StyleURL.custom(url: URL(string:value)!); + if let url = URL(string: value) { + self.style.styleURL = StyleURL.custom(url: url); + } else { + if RCTJSONParse(value, nil) != nil { + do { + try self.style.styleManager.setStyleJSONForJson(value) + } catch { + RCTMGLLogging.error(.argumentError, "RCTMGLMapView.setReactStyleURL unexpected error \(error)"); + } + } + } + } + + func fireEvent(event: RCTMGLEvent, callback: @escaping RCTBubblingEventBlock) { + callback(event.toJSON()) + } + + @objc func handleTap(_ sender: UITapGestureRecognizer) { + if let reactOnPress = self.reactOnPress { + let tapPoint = sender.location(in: self) + let location = mapView.coordinate(for: tapPoint) + print("Tap point \(tapPoint) => \(location)") + + var geojson = Feature(geometry: .point(Point(location))); + geojson.properties = [ + "screenPointX": Double(tapPoint.x), + "screenPointY": Double(tapPoint.y) + ]; + let event = try! RCTMGLEvent(type:.tap, payload: GeoJSONManager.dictionaryFrom(geojson)!); + self.fireEvent(event: event, callback: reactOnPress) + } + } + + @objc func setReactOnPress(_ value: @escaping RCTBubblingEventBlock) { + self.reactOnPress = value + + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap)) + self.addGestureRecognizer(tapGesture) + } + + func _toArray(bounds: CoordinateBounds) -> [[Double]] { + return [ + [ + Double(bounds.northeast.longitude), + Double(bounds.northeast.latitude), + ], + [ + Double(bounds.southwest.longitude), + Double(bounds.southwest.latitude) + ] + ] + } + + func toJSON(geometry: Geometry, properties: [String: Any]? = nil) -> [String: Any] { + let geojson = Feature(geometry: geometry); + var result = try! GeoJSONManager.dictionaryFrom(geojson)! + if let properties = properties { + result["properties"] = properties + } + return result + } + + func _makeRegionPayload() -> [String:Any] { + return toJSON( + geometry: .point(Point(mapView.centerCoordinate)), + properties: [ + "zoomLevel" : Double(mapView.zoom), + "heading": Double(mapView.cameraView.bearing), + "bearing": Double(mapView.cameraView.bearing), + "pitch": Double(mapView.cameraView.pitch), + "visibleBounds": _toArray(bounds: mapView.cameraView.visibleCoordinateBounds) + ] + ) + } + + @objc func setReactOnMapChange(_ value: @escaping RCTBubblingEventBlock) { + self.reactOnMapChange = value + self.mapView.on(.cameraChanged, handler: { cameraEvent in + + let event = RCTMGLEvent(type:.regionDidChange, payload: self._makeRegionPayload()); + self.fireEvent(event: event, callback: self.reactOnMapChange!) + }) } required init(frame:CGRect) { diff --git a/ios/RCTMGL/RCTMGLMapViewManager.m b/ios/RCTMGL/RCTMGLMapViewManager.m index f7e9a598db..c00707b91b 100644 --- a/ios/RCTMGL/RCTMGLMapViewManager.m +++ b/ios/RCTMGL/RCTMGLMapViewManager.m @@ -3,4 +3,6 @@ @interface RCT_EXTERN_MODULE(RCTMGLMapViewManager, RCTViewManager) RCT_REMAP_VIEW_PROPERTY(styleURL, reactStyleURL, NSString) +RCT_REMAP_VIEW_PROPERTY(onPress, reactOnPress, RCTBubblingEventBlock) +RCT_REMAP_VIEW_PROPERTY(onMapChange, reactOnMapChange, RCTBubblingEventBlock) @end