@rnmapbox/maps 10.0.0-beta.76 → 10.0.0-beta.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyle.kt +7 -1
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyleFactory.java +5 -5
  3. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt +37 -10
  4. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLBackgroundLayer.kt +21 -0
  5. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLBackgroundLayerManager.kt +65 -0
  6. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLCircleLayer.kt +40 -0
  7. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLCircleLayerManager.kt +76 -0
  8. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillExtrusionLayer.kt +43 -0
  9. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillExtrusionLayerManager.kt +76 -0
  10. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillLayer.kt +40 -0
  11. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillLayerManager.kt +76 -0
  12. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLHeatmapLayer.kt +40 -0
  13. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLHeatmapLayerManager.kt +76 -0
  14. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLLineLayer.kt +40 -0
  15. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLLineLayerManager.kt +76 -0
  16. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLRasterLayer.kt +18 -0
  17. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLRasterLayerManager.kt +65 -0
  18. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLSkyLayerManager.kt +76 -0
  19. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLSymbolLayer.kt +40 -0
  20. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLSymbolLayerManager.kt +76 -0
  21. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLImageSource.kt +69 -0
  22. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLImageSourceManager.kt +54 -0
  23. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterDemSource.kt +82 -0
  24. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterDemSourceManager.kt +30 -0
  25. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterSource.kt +37 -0
  26. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterSourceManager.kt +32 -0
  27. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSource.kt +5 -0
  28. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSourceManager.kt +10 -4
  29. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLTileSource.kt +44 -0
  30. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLTileSourceManager.kt +69 -0
  31. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLVectorSource.kt +78 -0
  32. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLVectorSourceManager.kt +69 -0
  33. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt +101 -85
  34. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/PointAnnotationDragEvent.java +4 -2
  35. package/ios/RCTMGL-v10/RCTMGLCamera.swift +11 -31
  36. package/ios/RCTMGL-v10/RCTMGLInteractiveElement.swift +13 -1
  37. package/ios/RCTMGL-v10/RCTMGLLayer.swift +35 -6
  38. package/ios/RCTMGL-v10/RCTMGLLocationModule.swift +27 -4
  39. package/ios/RCTMGL-v10/RCTMGLMapView.swift +4 -2
  40. package/ios/RCTMGL-v10/RCTMGLSource.swift +35 -17
  41. package/javascript/Mapbox.ts +4 -1
  42. package/javascript/components/AbstractLayer.tsx +2 -1
  43. package/javascript/components/BackgroundLayer.tsx +6 -1
  44. package/javascript/components/{Callout.js → Callout.tsx} +53 -45
  45. package/javascript/components/CircleLayer.tsx +5 -0
  46. package/javascript/components/FillExtrusionLayer.tsx +6 -1
  47. package/javascript/components/FillLayer.tsx +5 -0
  48. package/javascript/components/HeadingIndicator.tsx +24 -13
  49. package/javascript/components/HeatmapLayer.tsx +6 -1
  50. package/javascript/components/ImageSource.tsx +5 -0
  51. package/javascript/components/LineLayer.tsx +5 -0
  52. package/javascript/components/PointAnnotation.tsx +8 -4
  53. package/javascript/components/RasterDemSource.tsx +5 -0
  54. package/javascript/components/RasterLayer.tsx +6 -1
  55. package/javascript/components/RasterSource.tsx +5 -0
  56. package/javascript/components/ShapeSource.tsx +5 -0
  57. package/javascript/components/SkyLayer.tsx +5 -0
  58. package/javascript/components/SymbolLayer.tsx +6 -1
  59. package/javascript/components/UserLocation.tsx +1 -1
  60. package/javascript/components/VectorSource.tsx +5 -0
  61. package/javascript/types/BaseProps.ts +1 -0
  62. package/javascript/utils/index.ts +0 -8
  63. package/javascript/utils/styleMap.ts +0 -1598
  64. package/lib/commonjs/Mapbox.js +8 -1
  65. package/lib/commonjs/Mapbox.js.map +1 -1
  66. package/lib/commonjs/components/AbstractLayer.js +1 -2
  67. package/lib/commonjs/components/AbstractLayer.js.map +1 -1
  68. package/lib/commonjs/components/BackgroundLayer.js.map +1 -1
  69. package/lib/commonjs/components/Callout.js +7 -33
  70. package/lib/commonjs/components/Callout.js.map +1 -1
  71. package/lib/commonjs/components/CircleLayer.js.map +1 -1
  72. package/lib/commonjs/components/FillExtrusionLayer.js.map +1 -1
  73. package/lib/commonjs/components/FillLayer.js.map +1 -1
  74. package/lib/commonjs/components/HeadingIndicator.js +12 -3
  75. package/lib/commonjs/components/HeadingIndicator.js.map +1 -1
  76. package/lib/commonjs/components/HeatmapLayer.js.map +1 -1
  77. package/lib/commonjs/components/ImageSource.js.map +1 -1
  78. package/lib/commonjs/components/LineLayer.js.map +1 -1
  79. package/lib/commonjs/components/PointAnnotation.js.map +1 -1
  80. package/lib/commonjs/components/RasterDemSource.js.map +1 -1
  81. package/lib/commonjs/components/RasterLayer.js.map +1 -1
  82. package/lib/commonjs/components/RasterSource.js.map +1 -1
  83. package/lib/commonjs/components/ShapeSource.js.map +1 -1
  84. package/lib/commonjs/components/SkyLayer.js.map +1 -1
  85. package/lib/commonjs/components/SymbolLayer.js.map +1 -1
  86. package/lib/commonjs/components/UserLocation.js +2 -1
  87. package/lib/commonjs/components/UserLocation.js.map +1 -1
  88. package/lib/commonjs/components/VectorSource.js.map +1 -1
  89. package/lib/commonjs/utils/index.js +0 -16
  90. package/lib/commonjs/utils/index.js.map +1 -1
  91. package/lib/commonjs/utils/styleMap.js +1 -1217
  92. package/lib/commonjs/utils/styleMap.js.map +1 -1
  93. package/lib/module/Mapbox.js +1 -1
  94. package/lib/module/Mapbox.js.map +1 -1
  95. package/lib/module/components/AbstractLayer.js +1 -1
  96. package/lib/module/components/AbstractLayer.js.map +1 -1
  97. package/lib/module/components/BackgroundLayer.js.map +1 -1
  98. package/lib/module/components/Callout.js +7 -33
  99. package/lib/module/components/Callout.js.map +1 -1
  100. package/lib/module/components/CircleLayer.js.map +1 -1
  101. package/lib/module/components/FillExtrusionLayer.js.map +1 -1
  102. package/lib/module/components/FillLayer.js.map +1 -1
  103. package/lib/module/components/HeadingIndicator.js +12 -3
  104. package/lib/module/components/HeadingIndicator.js.map +1 -1
  105. package/lib/module/components/HeatmapLayer.js.map +1 -1
  106. package/lib/module/components/ImageSource.js.map +1 -1
  107. package/lib/module/components/LineLayer.js.map +1 -1
  108. package/lib/module/components/PointAnnotation.js.map +1 -1
  109. package/lib/module/components/RasterDemSource.js.map +1 -1
  110. package/lib/module/components/RasterLayer.js.map +1 -1
  111. package/lib/module/components/RasterSource.js.map +1 -1
  112. package/lib/module/components/ShapeSource.js.map +1 -1
  113. package/lib/module/components/SkyLayer.js.map +1 -1
  114. package/lib/module/components/SymbolLayer.js.map +1 -1
  115. package/lib/module/components/UserLocation.js +2 -1
  116. package/lib/module/components/UserLocation.js.map +1 -1
  117. package/lib/module/components/VectorSource.js.map +1 -1
  118. package/lib/module/utils/index.js +0 -14
  119. package/lib/module/utils/index.js.map +1 -1
  120. package/lib/module/utils/styleMap.js +0 -1201
  121. package/lib/module/utils/styleMap.js.map +1 -1
  122. package/lib/typescript/Mapbox.d.ts +1 -1
  123. package/lib/typescript/Mapbox.d.ts.map +1 -1
  124. package/lib/typescript/components/AbstractLayer.d.ts +1 -0
  125. package/lib/typescript/components/AbstractLayer.d.ts.map +1 -1
  126. package/lib/typescript/components/BackgroundLayer.d.ts +5 -1
  127. package/lib/typescript/components/BackgroundLayer.d.ts.map +1 -1
  128. package/lib/typescript/components/Callout.d.ts +41 -0
  129. package/lib/typescript/components/Callout.d.ts.map +1 -0
  130. package/lib/typescript/components/CircleLayer.d.ts +4 -0
  131. package/lib/typescript/components/CircleLayer.d.ts.map +1 -1
  132. package/lib/typescript/components/FillExtrusionLayer.d.ts +5 -1
  133. package/lib/typescript/components/FillExtrusionLayer.d.ts.map +1 -1
  134. package/lib/typescript/components/FillLayer.d.ts +4 -0
  135. package/lib/typescript/components/FillLayer.d.ts.map +1 -1
  136. package/lib/typescript/components/HeadingIndicator.d.ts +2 -1
  137. package/lib/typescript/components/HeadingIndicator.d.ts.map +1 -1
  138. package/lib/typescript/components/HeatmapLayer.d.ts +5 -1
  139. package/lib/typescript/components/HeatmapLayer.d.ts.map +1 -1
  140. package/lib/typescript/components/ImageSource.d.ts +4 -0
  141. package/lib/typescript/components/ImageSource.d.ts.map +1 -1
  142. package/lib/typescript/components/LineLayer.d.ts +4 -0
  143. package/lib/typescript/components/LineLayer.d.ts.map +1 -1
  144. package/lib/typescript/components/PointAnnotation.d.ts +5 -9
  145. package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
  146. package/lib/typescript/components/RasterDemSource.d.ts +4 -0
  147. package/lib/typescript/components/RasterDemSource.d.ts.map +1 -1
  148. package/lib/typescript/components/RasterLayer.d.ts +5 -1
  149. package/lib/typescript/components/RasterLayer.d.ts.map +1 -1
  150. package/lib/typescript/components/RasterSource.d.ts +4 -0
  151. package/lib/typescript/components/RasterSource.d.ts.map +1 -1
  152. package/lib/typescript/components/ShapeSource.d.ts +4 -0
  153. package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
  154. package/lib/typescript/components/SkyLayer.d.ts +4 -0
  155. package/lib/typescript/components/SkyLayer.d.ts.map +1 -1
  156. package/lib/typescript/components/SymbolLayer.d.ts +5 -1
  157. package/lib/typescript/components/SymbolLayer.d.ts.map +1 -1
  158. package/lib/typescript/components/VectorSource.d.ts +4 -0
  159. package/lib/typescript/components/VectorSource.d.ts.map +1 -1
  160. package/lib/typescript/types/BaseProps.d.ts +1 -0
  161. package/lib/typescript/types/BaseProps.d.ts.map +1 -1
  162. package/lib/typescript/utils/index.d.ts +0 -14
  163. package/lib/typescript/utils/index.d.ts.map +1 -1
  164. package/lib/typescript/utils/styleMap.d.ts +0 -1406
  165. package/lib/typescript/utils/styleMap.d.ts.map +1 -1
  166. package/package.json +35 -37
  167. package/plugin/build/withMapbox.d.ts +10 -6
  168. package/plugin/build/withMapbox.js +119 -137
  169. package/plugin/install.md +21 -0
  170. package/plugin/src/withMapbox.ts +166 -138
  171. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLBackgroundLayer.java +0 -23
  172. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLBackgroundLayerManager.java +0 -60
  173. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLCircleLayer.java +0 -53
  174. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLCircleLayerManager.java +0 -73
  175. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillExtrusionLayer.java +0 -51
  176. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillExtrusionLayerManager.java +0 -76
  177. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillLayer.java +0 -51
  178. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLFillLayerManager.java +0 -77
  179. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLHeatmapLayer.java +0 -51
  180. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLHeatmapLayerManager.java +0 -73
  181. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLLineLayer.java +0 -51
  182. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLLineLayerManager.java +0 -75
  183. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLRasterLayer.java +0 -24
  184. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLRasterLayerManager.java +0 -60
  185. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLSkyLayerManager.java +0 -73
  186. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLSymbolLayer.java +0 -51
  187. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTMGLSymbolLayerManager.java +0 -71
  188. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLImageSource.java +0 -76
  189. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLImageSourceManager.java +0 -68
  190. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterDemSource.java +0 -122
  191. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterDemSourceManager.java +0 -64
  192. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterSource.java +0 -43
  193. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterSourceManager.java +0 -39
  194. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLTileSource.java +0 -103
  195. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLTileSourceManager.java +0 -80
  196. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLVectorSource.java +0 -100
  197. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLVectorSourceManager.java +0 -80
  198. package/javascript/components/Callout.d.ts +0 -35
  199. package/lib/commonjs/components/Callout.d.js +0 -9
  200. package/lib/commonjs/components/Callout.d.js.map +0 -1
  201. package/lib/module/components/Callout.d.js +0 -2
  202. package/lib/module/components/Callout.d.js.map +0 -1
@@ -0,0 +1,30 @@
1
+ package com.mapbox.rctmgl.components.styles.sources
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.common.MapBuilder
5
+ import com.facebook.react.uimanager.ThemedReactContext
6
+
7
+ // import com.mapbox.rctmgl.components.annotation.RCTMGLCallout;
8
+ // import com.mapbox.rctmgl.utils.ResourceUtils;
9
+ class RCTMGLRasterDemSourceManager(private val mContext: ReactApplicationContext) :
10
+ RCTMGLTileSourceManager<RCTMGLRasterDemSource?>(
11
+ mContext
12
+ ) {
13
+ override fun customEvents(): Map<String, String>? {
14
+ return MapBuilder.builder<String, String>()
15
+ .build()
16
+ }
17
+
18
+ override fun getName(): String {
19
+ return REACT_CLASS
20
+ }
21
+
22
+ override fun createViewInstance(reactContext: ThemedReactContext): RCTMGLRasterDemSource {
23
+ return RCTMGLRasterDemSource(reactContext, this)
24
+ }
25
+
26
+ companion object {
27
+ const val LOG_TAG = "RCTMGLRasterDemSourceManager"
28
+ const val REACT_CLASS = "RCTMGLRasterDemSource"
29
+ }
30
+ }
@@ -0,0 +1,37 @@
1
+ package com.mapbox.rctmgl.components.styles.sources
2
+
3
+ import android.content.Context
4
+ import com.mapbox.maps.extension.style.sources.generated.RasterSource
5
+
6
+ class RCTMGLRasterSource(context: Context?) : RCTMGLTileSource<RasterSource?>(context) {
7
+ private var mTileSize: Int? = null
8
+ override fun makeSource(): RasterSource {
9
+ val id = iD!!
10
+ val configurationUrl = uRL
11
+ val tileSize = if (mTileSize == null) DEFAULT_TILE_SIZE else mTileSize!!
12
+ return if (configurationUrl != null) {
13
+ RasterSource.Builder(id).url(configurationUrl).tileSize(tileSize.toLong()).build()
14
+ } else RasterSource.Builder(id).tileSet(buildTileset())
15
+ .tileSize(tileSize.toLong()).build()
16
+ }
17
+
18
+ fun setTileSize(tileSize: Int) {
19
+ mTileSize = tileSize
20
+ }
21
+
22
+ override fun hasPressListener(): Boolean {
23
+ return false
24
+ }
25
+
26
+ override fun onPress(feature: OnPressEvent?) {
27
+ // ignore, cannot query raster layers
28
+ }
29
+
30
+ override fun hasNoDataSoRefersToExisting(): Boolean {
31
+ return uRL == null
32
+ }
33
+
34
+ companion object {
35
+ const val DEFAULT_TILE_SIZE = 512
36
+ }
37
+ }
@@ -0,0 +1,32 @@
1
+ package com.mapbox.rctmgl.components.styles.sources
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.facebook.react.uimanager.annotations.ReactProp
6
+ import javax.annotation.Nonnull
7
+
8
+ class RCTMGLRasterSourceManager(reactApplicationContext: ReactApplicationContext?) :
9
+ RCTMGLTileSourceManager<RCTMGLRasterSource?>(reactApplicationContext) {
10
+ @Nonnull
11
+ override fun getName(): String {
12
+ return REACT_CLASS
13
+ }
14
+
15
+ @Nonnull
16
+ override fun createViewInstance(@Nonnull reactContext: ThemedReactContext): RCTMGLRasterSource {
17
+ return RCTMGLRasterSource(reactContext)
18
+ }
19
+
20
+ @ReactProp(name = "tileSize")
21
+ fun setTileSize(source: RCTMGLRasterSource, tileSize: Int) {
22
+ source.setTileSize(tileSize)
23
+ }
24
+
25
+ override fun customEvents(): Map<String, String>? {
26
+ return null
27
+ }
28
+
29
+ companion object {
30
+ const val REACT_CLASS = "RCTMGLRasterSource"
31
+ }
32
+ }
@@ -34,6 +34,11 @@ class RCTMGLShapeSource(context: Context, private val mManager: RCTMGLShapeSourc
34
34
  private var mLineMetrics: Boolean? = null
35
35
  private val mImages: List<Map.Entry<String, ImageEntry>>? = null
36
36
  private val mNativeImages: List<Map.Entry<String, BitmapDrawable>>? = null
37
+
38
+ override fun hasNoDataSoRefersToExisting(): Boolean {
39
+ return (mURL == null) && (mShape == null)
40
+ }
41
+
37
42
  override fun addToMap(mapView: RCTMGLMapView) {
38
43
  // Wait for style before adding the source to the map
39
44
  mapView.getMapboxMap().getStyle {
@@ -14,6 +14,7 @@ import com.mapbox.bindgen.Value
14
14
  import com.mapbox.maps.extension.style.expressions.generated.Expression
15
15
  import com.mapbox.rctmgl.events.constants.EventKeys
16
16
  import com.mapbox.rctmgl.utils.ExpressionParser
17
+ import com.mapbox.rctmgl.utils.Logger
17
18
  import java.net.MalformedURLException
18
19
  import java.net.URL
19
20
  import java.util.ArrayList
@@ -33,11 +34,11 @@ class RCTMGLShapeSourceManager(private val mContext: ReactApplicationContext) :
33
34
  }
34
35
 
35
36
  override fun getChildAt(source: RCTMGLShapeSource, childPosition: Int): View {
36
- return source.getLayerAt(childPosition)
37
+ return source.getChildAt(childPosition)
37
38
  }
38
39
 
39
40
  override fun getChildCount(source: RCTMGLShapeSource): Int {
40
- return source.layerCount
41
+ return source.childCount
41
42
  }
42
43
 
43
44
  override fun addView(source: RCTMGLShapeSource, childView: View, childPosition: Int) {
@@ -53,12 +54,17 @@ class RCTMGLShapeSourceManager(private val mContext: ReactApplicationContext) :
53
54
  source.iD = id
54
55
  }
55
56
 
57
+ @ReactProp(name = "existing")
58
+ fun setExisting(source: RCTMGLShapeSource, existing: Boolean) {
59
+ source.mExisting = existing;
60
+ }
61
+
56
62
  @ReactProp(name = "url")
57
63
  fun setURL(source: RCTMGLShapeSource, urlStr: String) {
58
64
  try {
59
65
  source.setURL(URL(urlStr))
60
66
  } catch (e: MalformedURLException) {
61
- Log.w(LOG_TAG, e.localizedMessage ?: "Unknown URL error")
67
+ Logger.w(LOG_TAG, e.localizedMessage ?: "Unknown URL error")
62
68
  }
63
69
  }
64
70
 
@@ -186,7 +192,7 @@ class RCTMGLShapeSourceManager(private val mContext: ReactApplicationContext) :
186
192
  }
187
193
 
188
194
  companion object {
189
- const val LOG_TAG = "RCTMGLShapeSourceManager"
195
+ const val LOG_TAG = "RCTMGLShapeSourceMgr"
190
196
  const val REACT_CLASS = "RCTMGLShapeSource"
191
197
 
192
198
  //region React Methods
@@ -0,0 +1,44 @@
1
+ package com.mapbox.rctmgl.components.styles.sources
2
+
3
+ import android.accessibilityservice.GestureDescription
4
+ import android.content.Context
5
+ import com.mapbox.maps.extension.style.sources.Source
6
+ import com.mapbox.maps.extension.style.sources.TileSet
7
+ import com.mapbox.maps.extension.style.sources.generated.Scheme
8
+ import java.util.*
9
+
10
+ abstract class RCTMGLTileSource<T : Source?>(context: Context?) : RCTSource<T>(context) {
11
+ var uRL: String? = null
12
+ public var tileUrlTemplates: Collection<String> = ArrayList()
13
+ var attribution: String? = null
14
+ var minZoomLevel: Int? = null
15
+ var maxZoomLevel: Int? = null
16
+ var tMS = false
17
+ fun buildTileset(): TileSet {
18
+ val tileUrlTemplates =
19
+ tileUrlTemplates.toTypedArray()
20
+
21
+ val builder = TileSet.Builder(
22
+ TILE_SPEC_VERSION,
23
+ Arrays.asList<String>(*tileUrlTemplates.clone())
24
+ )
25
+ if (minZoomLevel != null) {
26
+ builder.minZoom(minZoomLevel!!.toFloat().toInt())
27
+ }
28
+ if (maxZoomLevel != null) {
29
+ builder.maxZoom(maxZoomLevel!!.toFloat().toInt())
30
+ }
31
+ if (tMS) {
32
+ builder.scheme(Scheme.TMS)
33
+ }
34
+ val attribution = this.attribution
35
+ if (attribution != null) {
36
+ builder.attribution(attribution)
37
+ }
38
+ return builder.build()
39
+ }
40
+
41
+ companion object {
42
+ const val TILE_SPEC_VERSION = "2.1.0"
43
+ }
44
+ }
@@ -0,0 +1,69 @@
1
+ package com.mapbox.rctmgl.components.styles.sources
2
+
3
+ import android.view.View
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReadableArray
6
+ import com.facebook.react.bridge.ReadableType
7
+ import com.facebook.react.uimanager.annotations.ReactProp
8
+ import com.mapbox.rctmgl.components.AbstractEventEmitter
9
+
10
+ abstract class RCTMGLTileSourceManager<T : RCTMGLTileSource<*>?> internal constructor(
11
+ reactApplicationContext: ReactApplicationContext?
12
+ ) : AbstractEventEmitter<T>(reactApplicationContext) {
13
+ override fun getChildAt(source: T, childPosition: Int): View {
14
+ return source!!.getChildAt(childPosition)
15
+ }
16
+
17
+ override fun getChildCount(source: T): Int {
18
+ return source!!.childCount
19
+ }
20
+
21
+ override fun addView(source: T, childView: View, childPosition: Int) {
22
+ source!!.addLayer(childView, childPosition)
23
+ }
24
+
25
+ override fun removeViewAt(source: T, childPosition: Int) {
26
+ source!!.removeLayer(childPosition)
27
+ }
28
+
29
+ @ReactProp(name = "id")
30
+ fun setID(source: T, id: String?) {
31
+ source!!.iD = id
32
+ }
33
+
34
+ @ReactProp(name = "url")
35
+ fun setURL(source: T, url: String?) {
36
+ source!!.uRL = url
37
+ }
38
+
39
+ @ReactProp(name = "tileUrlTemplates")
40
+ fun setTileUrlTemplates(source: T, tileUrlTemplates: ReadableArray) {
41
+ val urls: MutableList<String> = ArrayList()
42
+ for (i in 0 until tileUrlTemplates.size()) {
43
+ if (tileUrlTemplates.getType(0) == ReadableType.String) {
44
+ urls.add(tileUrlTemplates.getString(i))
45
+ }
46
+ }
47
+ source!!.tileUrlTemplates = urls
48
+ }
49
+
50
+ @ReactProp(name = "attribution")
51
+ fun setAttribution(source: T, attribution: String?) {
52
+ source!!.attribution = attribution
53
+ }
54
+
55
+ @ReactProp(name = "minZoomLevel")
56
+ fun setMinZoomLevel(source: T, minZoomLevel: Int) {
57
+ source!!.minZoomLevel = minZoomLevel
58
+ }
59
+
60
+ @ReactProp(name = "maxZoomLevel")
61
+ fun setMaxZoomLevel(source: T, maxZoomLevel: Int) {
62
+ source!!.maxZoomLevel = maxZoomLevel
63
+ }
64
+
65
+ @ReactProp(name = "tms")
66
+ fun setTMS(source: T, tms: Boolean) {
67
+ source!!.tMS = tms
68
+ }
69
+ }
@@ -0,0 +1,78 @@
1
+ package com.mapbox.rctmgl.components.styles.sources
2
+
3
+ import android.content.Context
4
+ import androidx.annotation.Size
5
+ import com.facebook.react.bridge.WritableMap
6
+ import com.facebook.react.bridge.WritableNativeMap
7
+ import com.mapbox.geojson.Feature
8
+ import com.mapbox.geojson.FeatureCollection
9
+ import com.mapbox.maps.SourceQueryOptions
10
+ import com.mapbox.maps.extension.style.expressions.generated.Expression
11
+ import com.mapbox.maps.extension.style.sources.generated.VectorSource
12
+ import com.mapbox.maps.extension.style.sources.getSource
13
+ import com.mapbox.rctmgl.events.AndroidCallbackEvent
14
+ import com.mapbox.rctmgl.events.FeatureClickEvent
15
+ import java.util.*
16
+
17
+ class RCTMGLVectorSource(context: Context?, private val mManager: RCTMGLVectorSourceManager) :
18
+ RCTMGLTileSource<VectorSource?>(context) {
19
+ override fun onPress(event: OnPressEvent?) {
20
+ mManager.handleEvent(FeatureClickEvent.makeVectorSourceEvent(this, event))
21
+ }
22
+
23
+ override fun hasNoDataSoRefersToExisting(): Boolean {
24
+ return uRL == null;
25
+ }
26
+
27
+ override fun makeSource(): VectorSource {
28
+ val id = iD
29
+ if (id == null) {
30
+ throw RuntimeException("id should be specified for VectorSource");
31
+ }
32
+ if (isDefaultSource(id)) {
33
+ return mMap!!.getStyle()!!.getSource(DEFAULT_ID) as VectorSource
34
+ }
35
+ val configurationUrl = uRL
36
+ return if (configurationUrl != null) {
37
+ VectorSource(
38
+ VectorSource.Builder(id)
39
+ .url(configurationUrl)
40
+ )
41
+ } else VectorSource(
42
+ VectorSource.Builder(id)
43
+ .tileSet(buildTileset())
44
+ )
45
+ }
46
+
47
+ fun querySourceFeatures(
48
+ callbackID: String?,
49
+ @Size(min = 1) layerIDs: List<String?>?,
50
+ filter: Expression?
51
+ ) {
52
+ if (mSource == null) {
53
+ val payload: WritableMap = WritableNativeMap()
54
+ payload.putString("error", "source is not yet loaded")
55
+ val event = AndroidCallbackEvent(this, callbackID, payload)
56
+ mManager.handleEvent(event)
57
+ return
58
+ }
59
+ mMap!!.querySourceFeatures(
60
+ iD!!,
61
+ SourceQueryOptions(layerIDs, filter!!)
62
+ ) { queriedFeatures ->
63
+ val payload: WritableMap = WritableNativeMap()
64
+ if (queriedFeatures.isError) {
65
+ //V10todo
66
+ payload.putString("error", queriedFeatures.error)
67
+ } else {
68
+ val features: MutableList<Feature> = LinkedList()
69
+ for (feature in queriedFeatures.value!!) {
70
+ features.add(feature.feature)
71
+ }
72
+ payload.putString("data", FeatureCollection.fromFeatures(features).toJson())
73
+ }
74
+ val event = AndroidCallbackEvent(this@RCTMGLVectorSource, callbackID, payload)
75
+ mManager.handleEvent(event)
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,69 @@
1
+ package com.mapbox.rctmgl.components.styles.sources
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReadableArray
5
+ import com.facebook.react.bridge.ReadableMap
6
+ import com.facebook.react.common.MapBuilder
7
+ import com.facebook.react.uimanager.ThemedReactContext
8
+ import com.facebook.react.uimanager.annotations.ReactProp
9
+ import com.mapbox.rctmgl.events.constants.EventKeys
10
+ import com.mapbox.rctmgl.utils.ConvertUtils
11
+ import com.mapbox.rctmgl.utils.ExpressionParser
12
+ import javax.annotation.Nonnull
13
+
14
+ class RCTMGLVectorSourceManager(reactApplicationContext: ReactApplicationContext?) :
15
+ RCTMGLTileSourceManager<RCTMGLVectorSource?>(reactApplicationContext) {
16
+ @Nonnull
17
+ override fun getName(): String {
18
+ return REACT_CLASS
19
+ }
20
+
21
+ @Nonnull
22
+ override fun createViewInstance(@Nonnull reactContext: ThemedReactContext): RCTMGLVectorSource {
23
+ return RCTMGLVectorSource(reactContext, this)
24
+ }
25
+
26
+ @ReactProp(name = "hasPressListener")
27
+ fun setHasPressListener(source: RCTMGLVectorSource, hasPressListener: Boolean) {
28
+ source.setHasPressListener(hasPressListener)
29
+ }
30
+
31
+ @ReactProp(name = "hitbox")
32
+ fun setHitbox(source: RCTMGLVectorSource, map: ReadableMap?) {
33
+ source.setHitbox(map!!)
34
+ }
35
+
36
+ override fun customEvents(): Map<String, String>? {
37
+ return MapBuilder.builder<String, String>()
38
+ .put(EventKeys.VECTOR_SOURCE_LAYER_CLICK, "onMapboxVectorSourcePress")
39
+ .put(EventKeys.MAP_ANDROID_CALLBACK, "onAndroidCallback")
40
+ .build()
41
+ }
42
+
43
+ override fun getCommandsMap(): Map<String, Int>? {
44
+ return MapBuilder.builder<String, Int>()
45
+ .put("features", METHOD_FEATURES)
46
+ .build()
47
+ }
48
+
49
+ override fun receiveCommand(
50
+ vectorSource: RCTMGLVectorSource,
51
+ commandID: Int,
52
+ args: ReadableArray?
53
+ ) {
54
+ when (commandID) {
55
+ METHOD_FEATURES -> vectorSource.querySourceFeatures(
56
+ args!!.getString(0),
57
+ ConvertUtils.toStringList(args.getArray(1)),
58
+ ExpressionParser.from(args.getArray(2))
59
+ )
60
+ }
61
+ }
62
+
63
+ companion object {
64
+ const val REACT_CLASS = "RCTMGLVectorSource"
65
+
66
+ //region React Methods
67
+ const val METHOD_FEATURES = 102
68
+ }
69
+ }
@@ -23,6 +23,9 @@ import java.lang.ClassCastException
23
23
  import java.util.ArrayList
24
24
  import java.util.HashMap
25
25
 
26
+ data class FeatureInfo(val feature: AbstractMapFeature?, var added: Boolean) {
27
+ }
28
+
26
29
  abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(context) {
27
30
  @JvmField
28
31
  protected var mMap: MapboxMap? = null
@@ -31,19 +34,40 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
31
34
  protected var mSource: T? = null
32
35
  protected var mHasPressListener = false
33
36
  protected var mTouchHitbox: Map<String, Double>? = null
34
- protected var mLayers: MutableList<AbstractSourceConsumer>
35
- private var mQueuedLayers: MutableList<AbstractSourceConsumer>?
37
+ private var mSubFeatures = mutableListOf<FeatureInfo>()
38
+
36
39
  val layerIDs: List<String>
37
40
  get() {
38
- val layerIDs: MutableList<String> = ArrayList()
39
- for (i in mLayers.indices) {
40
- val layer = mLayers[i]
41
- val id = layer.iD
42
- if (id != null) {
43
- layerIDs.add(id)
41
+ return mSubFeatures.mapIndexed { index, featureInfo ->
42
+ if (featureInfo.added && featureInfo.feature is AbstractSourceConsumer) {
43
+ featureInfo.feature.iD
44
+ } else {
45
+ null
46
+ }
47
+ }.filterNotNull()
48
+ }
49
+
50
+ abstract fun hasNoDataSoRefersToExisting(): Boolean;
51
+
52
+ public var mExisting: Boolean? = null
53
+
54
+ val existing: Boolean
55
+ get() {
56
+ var result: Boolean = false
57
+ mExisting?.also {
58
+ result = it
59
+ } ?: run {
60
+ if (hasNoDataSoRefersToExisting()) {
61
+ Logger.w(
62
+ LOG_TAG,
63
+ "RCTSource: soure with id: $id seems to refer to existing value but existing flag is not set. This is deprecated."
64
+ )
65
+ result = true
66
+ } else {
67
+ result = false
44
68
  }
45
69
  }
46
- return layerIDs
70
+ return result
47
71
  }
48
72
 
49
73
  private fun getSourceAs(style: Style, id: String?): T? {
@@ -55,18 +79,6 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
55
79
  }
56
80
  }
57
81
 
58
- protected fun addLayerToMap(layer: AbstractSourceConsumer?, childPosition: Int) {
59
- mMapView?.let {
60
- val mapView = it
61
- layer?.let {
62
- it.addToMap(mapView)
63
- if (!mLayers.contains(it)) {
64
- mLayers.add(childPosition, it)
65
- }
66
- }
67
- }
68
- }
69
-
70
82
  open fun hasPressListener(): Boolean {
71
83
  return mHasPressListener
72
84
  }
@@ -94,51 +106,56 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
94
106
  .build()
95
107
  } else mTouchHitbox
96
108
  }
97
- val layerCount: Int
98
- get() {
99
- var totalCount = 0
100
- if (mQueuedLayers != null) {
101
- totalCount = mQueuedLayers!!.size
109
+
110
+ fun addToMap(existings: Boolean, style: Style, mapView: RCTMGLMapView) {
111
+ mSource = null
112
+ if (existings) {
113
+ val existingSource = getSourceAs(style, iD)
114
+ if (existingSource != null) {
115
+ mSource = existingSource
116
+ } else {
117
+ Logger.w(LOG_TAG, "Source $iD was makred as existing but was not found in style")
102
118
  }
103
- totalCount += mLayers.size
104
- return totalCount
105
119
  }
120
+ if (mSource == null) {
121
+ mSource = makeSource()
122
+ style.addSource(mSource as StyleContract.StyleSourceExtension)
123
+ }
124
+ mSubFeatures?.forEach {
125
+ it.feature?.let {
126
+ it.addToMap(mapView)
127
+ }
128
+ it.added = true
129
+ }
130
+ }
106
131
 
107
132
  override fun addToMap(mapView: RCTMGLMapView) {
108
133
  super.addToMap(mapView)
109
134
  mMap = mapView.getMapboxMap()
110
- mMap?.getStyle(object : Style.OnStyleLoaded {
111
- override fun onStyleLoaded(style: Style) {
112
- val existingSource = getSourceAs(style, iD)
113
- if (existingSource != null) {
114
- mSource = existingSource
115
- } else {
116
- mSource = makeSource()
117
- style.addSource(mSource as StyleContract.StyleSourceExtension)
118
- }
119
- if (mQueuedLayers != null && mQueuedLayers!!.size > 0) { // first load
120
- for (i in mQueuedLayers!!.indices) {
121
- addLayerToMap(mQueuedLayers!![i], i)
122
- }
123
- mQueuedLayers = null
124
- } else if (mLayers.size > 0) { // handles the case of switching style url, but keeping layers on map
125
- for (i in mLayers.indices) {
126
- addLayerToMap(mLayers[i], i)
127
- }
135
+ val map = mMap
136
+ if (map == null) {
137
+ Logger.e("RCTSource", "map is exepted to be valid but was null, $iD")
138
+ return
139
+ }
140
+ val style = map.getStyle()
141
+ if (existing || style == null) {
142
+ map.getStyle(object : Style.OnStyleLoaded {
143
+ override fun onStyleLoaded(style: Style) {
144
+ addToMap(existing, style, mapView)
128
145
  }
129
- }
130
- })
146
+ })
147
+ } else {
148
+ addToMap(existing, style, mapView)
149
+ }
150
+
131
151
  }
132
152
 
133
153
  override fun removeFromMap(mapView: RCTMGLMapView) {
134
- if (mLayers.size > 0) {
135
- for (i in mLayers.indices) {
136
- val layer = mLayers[i]
137
- layer.removeFromMap(mapView)
154
+ mSubFeatures.forEach { it
155
+ it.feature?.let {
156
+ it.removeFromMap(mapView)
138
157
  }
139
- }
140
- if (mQueuedLayers != null) {
141
- mQueuedLayers!!.clear()
158
+ it.added = false
142
159
  }
143
160
  if (mMap != null && mSource != null && mMap!!.getStyle() != null) {
144
161
  try {
@@ -151,47 +168,48 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
151
168
  }
152
169
 
153
170
  fun addLayer(childView: View?, childPosition: Int) {
154
- if (childView !is AbstractSourceConsumer) {
155
- return
171
+ var feature: AbstractMapFeature? = null
172
+ if (childView !is AbstractMapFeature) {
173
+ Logger.w(LOG_TAG, "Attempted to insert view: $childView to shape source: $iD, since it's not a MapFeature it will not be added")
174
+ } else {
175
+ feature = childView
156
176
  }
157
- val layer = childView
158
- if (mMap == null) {
159
- mQueuedLayers?.add(childPosition, layer)
177
+
178
+ val mapView = mMapView
179
+
180
+ val added = if (mapView != null && feature != null) {
181
+ feature.addToMap(mapView)
182
+ true
160
183
  } else {
161
- addLayerToMap(layer, childPosition)
184
+ false
162
185
  }
186
+ mSubFeatures.add(childPosition, FeatureInfo(feature, added))
163
187
  }
164
188
 
165
189
  fun removeLayer(childPosition: Int) {
166
- val layer: AbstractSourceConsumer
167
- layer = if (mQueuedLayers != null && mQueuedLayers!!.size > 0) {
168
- mQueuedLayers!![childPosition]
169
- } else {
170
- mLayers[childPosition]
190
+ var featureInfo = mSubFeatures[childPosition]
191
+ if (featureInfo.added) {
192
+ val mapView = mMapView
193
+ if (mapView != null) {
194
+ featureInfo.feature?.let { it.removeFromMap(mapView) }
195
+ }
196
+ featureInfo.added = false
171
197
  }
172
- removeLayerFromMap(layer, childPosition)
198
+ mSubFeatures.removeAt(childPosition)
173
199
  }
174
200
 
175
- fun getLayerAt(childPosition: Int): AbstractSourceConsumer {
176
- return if (mQueuedLayers != null && mQueuedLayers!!.size > 0) {
177
- mQueuedLayers!![childPosition]
178
- } else mLayers[childPosition]
201
+ val childViews: List<AbstractMapFeature>
202
+ get() = mSubFeatures.map { it.feature }.filterNotNull()
203
+
204
+ override fun getChildAt(childPosition: Int): View {
205
+ return childViews[childPosition]
179
206
  }
180
207
 
181
- protected fun removeLayerFromMap(layer: AbstractSourceConsumer?, childPosition: Int) {
182
- mMapView?.let {
183
- val mapView = it
184
- layer?.let {
185
- it.removeFromMap(mapView)
186
- }
187
- }
188
- if (mQueuedLayers != null && mQueuedLayers!!.size > 0) {
189
- mQueuedLayers?.removeAt(childPosition)
190
- } else {
191
- mLayers.removeAt(childPosition)
192
- }
208
+ override fun getChildCount(): Int {
209
+ return childViews.size;
193
210
  }
194
211
 
212
+
195
213
  abstract fun makeSource(): T
196
214
  class OnPressEvent(var features: List<Feature>, var latLng: LatLng, var screenPoint: PointF)
197
215
 
@@ -209,7 +227,5 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
209
227
  }
210
228
 
211
229
  init {
212
- mLayers = ArrayList()
213
- mQueuedLayers = ArrayList()
214
230
  }
215
231
  }