@rnmapbox/maps 10.0.0-rc.0 → 10.0.0-rc.10
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.
- package/README.md +2 -2
- package/android/rctmgl/build.gradle +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractEventEmitter.kt +75 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt +92 -9
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +2 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/LocationComponentManager.kt +3 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLAndroidTextureMapViewManager.kt +23 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +86 -17
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +24 -8
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterSourceManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLTileSourceManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLVectorSourceManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/AbstractEvent.kt +49 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/IEvent.kt +17 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/LocationEvent.kt +11 -16
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/MapUserTrackingModeEvent.kt +10 -10
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/constants/EventTypes.kt +44 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLLocationModule.kt +36 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLModule.kt +4 -3
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLOfflineModule.kt +474 -405
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/FeatureCollection.kt +10 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/Geometry.kt +22 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/JSONObject.kt +78 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/ReadableArray.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/Value.kt +9 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/writeableMapArrayOf.kt +41 -0
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +1 -6
- package/ios/RCTMGL-v10/RCTMGLImages.swift +0 -1
- package/ios/RCTMGL-v10/RCTMGLLocationModule.m +2 -2
- package/ios/RCTMGL-v10/RCTMGLMapView.swift +7 -1
- package/ios/RCTMGL-v10/RCTMGLOfflineModule.swift +283 -307
- package/ios/install.md +7 -0
- package/lib/commonjs/components/MapView.js +12 -2
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/components/NativeUserLocation.js.map +1 -1
- package/lib/commonjs/components/Terrain.js +1 -2
- package/lib/commonjs/components/Terrain.js.map +1 -1
- package/lib/commonjs/components/VectorSource.js +2 -0
- package/lib/commonjs/components/VectorSource.js.map +1 -1
- package/lib/commonjs/modules/location/locationManager.js +4 -0
- package/lib/commonjs/modules/location/locationManager.js.map +1 -1
- package/lib/module/components/MapView.js +12 -2
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/NativeUserLocation.js.map +1 -1
- package/lib/module/components/Terrain.js +1 -2
- package/lib/module/components/Terrain.js.map +1 -1
- package/lib/module/components/VectorSource.js +3 -0
- package/lib/module/components/VectorSource.js.map +1 -1
- package/lib/module/modules/location/locationManager.js +4 -0
- package/lib/module/modules/location/locationManager.js.map +1 -1
- package/lib/typescript/components/MapView.d.ts +7 -1
- package/lib/typescript/components/MapView.d.ts.map +1 -1
- package/lib/typescript/components/NativeUserLocation.d.ts.map +1 -1
- package/lib/typescript/components/Terrain.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/install.md +17 -0
- package/rnmapbox-maps.podspec +1 -1
- package/src/components/MapView.tsx +11 -3
- package/src/components/NativeUserLocation.tsx +5 -3
- package/src/components/Terrain.tsx +3 -5
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractEventEmitter.java +0 -82
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLAndroidTextureMapView.java +0 -16
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLAndroidTextureMapViewManager.java +0 -31
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/AbstractEvent.java +0 -62
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/IEvent.java +0 -18
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/constants/EventTypes.java +0 -51
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ _See [iOS](ios/install.md) & [Android](android/install.md) setup guide for more
|
|
|
84
84
|
|
|
85
85
|
- [node](https://nodejs.org)
|
|
86
86
|
- [npm](https://www.npmjs.com/)
|
|
87
|
-
- [React Native](https://facebook.github.io/react-native/) (0.
|
|
87
|
+
- [React Native](https://facebook.github.io/react-native/) (0.64+)
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
## Installation
|
|
@@ -225,7 +225,7 @@ const styles = StyleSheet.create({
|
|
|
225
225
|
|
|
226
226
|
### Misc
|
|
227
227
|
|
|
228
|
-
- [
|
|
228
|
+
- [Mapbox](/docs/MapboxGL.md)
|
|
229
229
|
- [CustomHttpHeaders](/docs/CustomHttpHeaders.md)
|
|
230
230
|
- [Logger](/docs/Logger.md)
|
|
231
231
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.components
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.view.ViewGroup
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.common.MapBuilder
|
|
7
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
|
+
import com.facebook.react.uimanager.UIManagerModule
|
|
9
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
10
|
+
import com.facebook.react.uimanager.events.EventDispatcher
|
|
11
|
+
import com.mapbox.rctmgl.events.IEvent
|
|
12
|
+
import javax.annotation.Nonnull
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Created by nickitaliano on 8/23/17.
|
|
16
|
+
*/
|
|
17
|
+
abstract class AbstractEventEmitter<T : ViewGroup?>(reactApplicationContext: ReactApplicationContext) :
|
|
18
|
+
ViewGroupManager<T>() {
|
|
19
|
+
private val mRateLimitedEvents: MutableMap<String, Long>
|
|
20
|
+
private var mEventDispatcher: EventDispatcher? = null
|
|
21
|
+
private val mRCTAppContext: ReactApplicationContext
|
|
22
|
+
|
|
23
|
+
init {
|
|
24
|
+
mRateLimitedEvents = HashMap()
|
|
25
|
+
mRCTAppContext = reactApplicationContext
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
val activity : Activity?
|
|
29
|
+
get() = mRCTAppContext.currentActivity
|
|
30
|
+
|
|
31
|
+
fun handleEvent(event: IEvent) {
|
|
32
|
+
val eventCacheKey = getEventCacheKey(event)
|
|
33
|
+
|
|
34
|
+
// fail safe to protect bridge from being spammed
|
|
35
|
+
if (shouldDropEvent(eventCacheKey, event)) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
mRateLimitedEvents[eventCacheKey] = System.currentTimeMillis()
|
|
39
|
+
mEventDispatcher!!.dispatchEvent(
|
|
40
|
+
AbstractEvent(
|
|
41
|
+
event.iD,
|
|
42
|
+
event.key,
|
|
43
|
+
event.canCoalesce(),
|
|
44
|
+
event.toJSON()
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override fun addEventEmitters(context: ThemedReactContext, @Nonnull view: T) {
|
|
50
|
+
mEventDispatcher = context.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
|
|
54
|
+
val events = customEvents() ?: return null
|
|
55
|
+
val exportedEvents: MutableMap<String, Any> = HashMap()
|
|
56
|
+
for ((key, value) in events) {
|
|
57
|
+
exportedEvents[key] = MapBuilder.of("registrationName", value)
|
|
58
|
+
}
|
|
59
|
+
return exportedEvents
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
abstract fun customEvents(): Map<String, String>?
|
|
63
|
+
private fun shouldDropEvent(cacheKey: String, event: IEvent): Boolean {
|
|
64
|
+
val lastEventTimestamp = mRateLimitedEvents[cacheKey]
|
|
65
|
+
return lastEventTimestamp != null && event.timestamp - lastEventTimestamp <= BRIDGE_TIMEOUT_MS
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private fun getEventCacheKey(event: IEvent): String {
|
|
69
|
+
return String.format("%s-%s", event.key, event.type)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
companion object {
|
|
73
|
+
private const val BRIDGE_TIMEOUT_MS = 10.0
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -14,7 +14,7 @@ import com.mapbox.maps.viewannotation.OnViewAnnotationUpdatedListener
|
|
|
14
14
|
import com.mapbox.maps.viewannotation.ViewAnnotationManager
|
|
15
15
|
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
|
|
16
16
|
|
|
17
|
-
class RCTMGLMarkerViewManager(reactApplicationContext: ReactApplicationContext
|
|
17
|
+
class RCTMGLMarkerViewManager(reactApplicationContext: ReactApplicationContext) :
|
|
18
18
|
AbstractEventEmitter<RCTMGLMarkerView?>(reactApplicationContext) {
|
|
19
19
|
override fun getName(): String {
|
|
20
20
|
return REACT_CLASS
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt
CHANGED
|
@@ -24,6 +24,9 @@ import com.mapbox.maps.plugin.viewport.ViewportStatusObserver
|
|
|
24
24
|
import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateBearing
|
|
25
25
|
import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateOptions
|
|
26
26
|
import com.mapbox.maps.plugin.viewport.data.ViewportStatusChangeReason
|
|
27
|
+
import com.mapbox.maps.plugin.viewport.state.FollowPuckViewportState
|
|
28
|
+
import com.mapbox.maps.plugin.viewport.state.OverviewViewportState
|
|
29
|
+
import com.mapbox.maps.plugin.viewport.state.ViewportState
|
|
27
30
|
import com.mapbox.maps.plugin.viewport.viewport
|
|
28
31
|
import com.mapbox.rctmgl.components.RemovalReason
|
|
29
32
|
import com.mapbox.rctmgl.components.camera.constants.CameraMode
|
|
@@ -31,6 +34,7 @@ import com.mapbox.rctmgl.components.location.*
|
|
|
31
34
|
import com.mapbox.rctmgl.events.MapUserTrackingModeEvent
|
|
32
35
|
import com.mapbox.rctmgl.location.*
|
|
33
36
|
import com.mapbox.rctmgl.utils.Logger
|
|
37
|
+
import com.mapbox.rctmgl.utils.writableMapOf
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCameraManager) :
|
|
@@ -91,7 +95,7 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
91
95
|
setInitialCamera()
|
|
92
96
|
updateMaxBounds()
|
|
93
97
|
mCameraStop?.let { updateCamera(it) }
|
|
94
|
-
_observeViewportState(mapView)
|
|
98
|
+
_observeViewportState(mapView.mapView)
|
|
95
99
|
_updateViewportState()
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -281,27 +285,105 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
281
285
|
}
|
|
282
286
|
}
|
|
283
287
|
|
|
288
|
+
fun toFollowUserLocation(toStatus: ViewportStatus): Boolean {
|
|
289
|
+
when (toStatus) {
|
|
290
|
+
ViewportStatus.Idle -> return false
|
|
291
|
+
is ViewportStatus.State -> return true
|
|
292
|
+
is ViewportStatus.Transition -> return true
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
fun toFollowUserMode(state: ViewportState): String? {
|
|
297
|
+
if (state is FollowPuckViewportState) {
|
|
298
|
+
when (state.options.bearing) {
|
|
299
|
+
is FollowPuckViewportStateBearing.SyncWithLocationPuck ->
|
|
300
|
+
return "normal"
|
|
301
|
+
is FollowPuckViewportStateBearing.Constant ->
|
|
302
|
+
return "constant"
|
|
303
|
+
else -> {
|
|
304
|
+
Logger.w(LOG_TAG, "Unexpected bearing: ${state.options.bearing}")
|
|
305
|
+
return "normal"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
} else if (state is OverviewViewportState) {
|
|
309
|
+
return "overview"
|
|
310
|
+
} else {
|
|
311
|
+
return "custom"
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
fun toFollowUserMode(status: ViewportStatus): String? {
|
|
316
|
+
when (status) {
|
|
317
|
+
ViewportStatus.Idle -> return null
|
|
318
|
+
is ViewportStatus.State ->
|
|
319
|
+
return toFollowUserMode(status)
|
|
320
|
+
is ViewportStatus.Transition ->
|
|
321
|
+
return toFollowUserMode(status.toState)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
fun toReadableMap(status: ViewportStatus): ReadableMap {
|
|
326
|
+
when (status) {
|
|
327
|
+
ViewportStatus.Idle -> return writableMapOf("state" to "idle")
|
|
328
|
+
is ViewportStatus.State ->
|
|
329
|
+
return writableMapOf(
|
|
330
|
+
"state" to status.toString()
|
|
331
|
+
)
|
|
332
|
+
is ViewportStatus.Transition ->
|
|
333
|
+
return writableMapOf(
|
|
334
|
+
"transition" to status.toString()
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
284
339
|
fun _observeViewportState(mapView: MapView) {
|
|
285
340
|
mapView.viewport.addStatusObserver(object: ViewportStatusObserver {
|
|
286
341
|
override fun onViewportStatusChanged(
|
|
287
|
-
|
|
288
|
-
|
|
342
|
+
fromStatus: ViewportStatus,
|
|
343
|
+
toStatus: ViewportStatus,
|
|
289
344
|
reason: ViewportStatusChangeReason
|
|
290
345
|
) {
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
346
|
+
if (reason == ViewportStatusChangeReason.USER_INTERACTION) {
|
|
347
|
+
val followUserLocation = toFollowUserLocation(toStatus)
|
|
348
|
+
|
|
294
349
|
|
|
295
|
-
|
|
296
|
-
|
|
350
|
+
|
|
351
|
+
mManager.handleEvent(MapUserTrackingModeEvent(this@RCTMGLCamera, UserTrackingMode.NONE,
|
|
352
|
+
writableMapOf(
|
|
353
|
+
"followUserMode" to toFollowUserMode(toStatus),
|
|
354
|
+
"followUserLocation" to followUserLocation,
|
|
355
|
+
"fromViewportState" to toReadableMap(fromStatus),
|
|
356
|
+
"toViewportState" to toReadableMap(toStatus),
|
|
357
|
+
"reason" to toString(reason),
|
|
358
|
+
)
|
|
359
|
+
))
|
|
297
360
|
}
|
|
298
361
|
}
|
|
299
362
|
})
|
|
300
363
|
}
|
|
301
364
|
|
|
365
|
+
fun toString(reason: ViewportStatusChangeReason): String {
|
|
366
|
+
when (reason) {
|
|
367
|
+
ViewportStatusChangeReason.IDLE_REQUESTED ->
|
|
368
|
+
return "idleRequested"
|
|
369
|
+
ViewportStatusChangeReason.TRANSITION_FAILED ->
|
|
370
|
+
return "transitionFailed"
|
|
371
|
+
ViewportStatusChangeReason.TRANSITION_STARTED ->
|
|
372
|
+
return "transitionStarted"
|
|
373
|
+
ViewportStatusChangeReason.TRANSITION_SUCCEEDED ->
|
|
374
|
+
return "transitionSucceeded"
|
|
375
|
+
ViewportStatusChangeReason.USER_INTERACTION ->
|
|
376
|
+
return "userInteraction"
|
|
377
|
+
else -> {
|
|
378
|
+
Logger.w(LOG_TAG, "toString; unkown reason: ${reason}")
|
|
379
|
+
return "unkown: $reason"
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
302
384
|
fun _updateViewportState() {
|
|
303
385
|
mMapView?.let {
|
|
304
|
-
val map = it
|
|
386
|
+
val map = it.mapView
|
|
305
387
|
val viewport = map.viewport;
|
|
306
388
|
|
|
307
389
|
if (mLocationComponentManager == null) {
|
|
@@ -418,5 +500,6 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
418
500
|
const val USER_LOCATION_CAMERA_MOVE_DURATION = 1000
|
|
419
501
|
const val minimumZoomLevelForUserTracking = 10.5
|
|
420
502
|
const val defaultZoomLevelForUserTracking = 14.0
|
|
503
|
+
const val LOG_TAG = "RCTMGLCamera"
|
|
421
504
|
}
|
|
422
505
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt
CHANGED
|
@@ -61,7 +61,7 @@ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
|
|
|
61
61
|
ReadableType.String -> {
|
|
62
62
|
val resourceName = dynamic.asString();
|
|
63
63
|
val drawable =
|
|
64
|
-
ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable
|
|
64
|
+
ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable?
|
|
65
65
|
if (drawable != null) {
|
|
66
66
|
return NativeImage(resourceName, drawable)
|
|
67
67
|
} else {
|
|
@@ -97,7 +97,7 @@ class RCTMGLImagesManager(private val mContext: ReactApplicationContext) :
|
|
|
97
97
|
scale = map.getDouble("scale")
|
|
98
98
|
}
|
|
99
99
|
val drawable =
|
|
100
|
-
ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable
|
|
100
|
+
ResourceUtils.getDrawableByName(mContext, resourceName) as BitmapDrawable?
|
|
101
101
|
if (drawable != null && resourceName != null) {
|
|
102
102
|
return NativeImage(resourceName, drawable, scale, sdf, stretchX, stretchY)
|
|
103
103
|
} else {
|
|
@@ -64,6 +64,7 @@ class LocationComponentManager(mapView: RCTMGLMapView, context: Context) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
private fun applyStateChanges(map: RCTMGLMapView, oldState: State, newState: State, fullUpdate: Boolean) {
|
|
67
|
+
val mapView = map.mapView
|
|
67
68
|
if (map.getLifecycleState() != Lifecycle.State.STARTED) {
|
|
68
69
|
// In case lifecycle was already stopped, so we're part of shutdown, do not call updateSettings as it'll just restart
|
|
69
70
|
// the loationComponent that will not be stopped. See https://github.com/mapbox/mapbox-maps-android/issues/2017
|
|
@@ -72,7 +73,7 @@ class LocationComponentManager(mapView: RCTMGLMapView, context: Context) {
|
|
|
72
73
|
}
|
|
73
74
|
return
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
mapView.location.updateSettings {
|
|
76
77
|
enabled = newState.enabled
|
|
77
78
|
|
|
78
79
|
if (fullUpdate || (newState.hidden != oldState.hidden) || (newState.tintColor != oldState.tintColor) || (newState.bearingImage != oldState.bearingImage)) {
|
|
@@ -140,7 +141,7 @@ class LocationComponentManager(mapView: RCTMGLMapView, context: Context) {
|
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
private fun useMapLocationProvider(mapView: RCTMGLMapView) {
|
|
143
|
-
val provider = mapView.location.getLocationProvider()
|
|
144
|
+
val provider = mapView.mapView.location.getLocationProvider()
|
|
144
145
|
if (provider != null) {
|
|
145
146
|
mLocationManager.provider = provider
|
|
146
147
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.components.mapview
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.mapbox.maps.MapInitOptions
|
|
6
|
+
|
|
7
|
+
class RCTMGLAndroidTextureMapViewManager(context: ReactApplicationContext) : RCTMGLMapViewManager(
|
|
8
|
+
context
|
|
9
|
+
) {
|
|
10
|
+
override fun getName(): String {
|
|
11
|
+
return REACT_CLASS
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createViewInstance(themedReactContext: ThemedReactContext): RCTMGLMapView {
|
|
15
|
+
val context = getMapViewContext(themedReactContext)
|
|
16
|
+
val options = MapInitOptions(context = context, textureView= true)
|
|
17
|
+
return RCTMGLMapView(context, this, options)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
companion object {
|
|
21
|
+
const val REACT_CLASS = "RCTMGLAndroidTextureMapView"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt
CHANGED
|
@@ -7,6 +7,7 @@ import android.graphics.RectF
|
|
|
7
7
|
import android.util.Log
|
|
8
8
|
import android.view.Gravity
|
|
9
9
|
import android.view.View
|
|
10
|
+
import android.view.View.OnLayoutChangeListener
|
|
10
11
|
import android.view.ViewGroup
|
|
11
12
|
import android.widget.FrameLayout
|
|
12
13
|
import androidx.lifecycle.Lifecycle
|
|
@@ -45,6 +46,7 @@ import com.mapbox.maps.plugin.logo.generated.LogoSettings
|
|
|
45
46
|
import com.mapbox.maps.plugin.logo.logo
|
|
46
47
|
import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings
|
|
47
48
|
import com.mapbox.maps.plugin.scalebar.scalebar
|
|
49
|
+
import com.mapbox.maps.viewannotation.ViewAnnotationManager
|
|
48
50
|
import com.mapbox.rctmgl.R
|
|
49
51
|
import com.mapbox.rctmgl.components.AbstractMapFeature
|
|
50
52
|
import com.mapbox.rctmgl.components.RemovalReason
|
|
@@ -145,7 +147,7 @@ data class FeatureEntry(val feature: AbstractMapFeature?, val view: View?, var a
|
|
|
145
147
|
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapViewManager
|
|
150
|
+
open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapViewManager, options: MapInitOptions?) : FrameLayout(mContext), OnMapClickListener, OnMapLongClickListener, OnLayoutChangeListener {
|
|
149
151
|
/**
|
|
150
152
|
* `PointAnnotations` are rendered to a canvas, but the React Native `Image` component is
|
|
151
153
|
* implemented on top of Fresco (https://frescolib.org), which does not load images for
|
|
@@ -170,6 +172,8 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
170
172
|
private val mCameraChangeTracker = CameraChangeTracker()
|
|
171
173
|
private val mMap: MapboxMap?
|
|
172
174
|
|
|
175
|
+
private val mMapView: MapView
|
|
176
|
+
|
|
173
177
|
var savedStyle: Style? = null
|
|
174
178
|
private set
|
|
175
179
|
|
|
@@ -183,17 +187,31 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
183
187
|
private set
|
|
184
188
|
|
|
185
189
|
val mapView: MapView
|
|
186
|
-
get() = this
|
|
190
|
+
get() = this.mMapView
|
|
191
|
+
|
|
192
|
+
val viewAnnotationManager: ViewAnnotationManager
|
|
193
|
+
get() = mapView.viewAnnotationManager
|
|
194
|
+
|
|
195
|
+
var requestDisallowInterceptTouchEvent: Boolean = false
|
|
196
|
+
set(value) {
|
|
197
|
+
val oldValue = field
|
|
198
|
+
field = value
|
|
199
|
+
updateRequestDisallowInterceptTouchEvent(oldValue, value)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
fun getMapboxMap(): MapboxMap {
|
|
203
|
+
return mapView.getMapboxMap()
|
|
204
|
+
}
|
|
187
205
|
|
|
188
206
|
val pointAnnotationManager: PointAnnotationManager?
|
|
189
207
|
get() {
|
|
190
208
|
if (mPointAnnotationManager == null) {
|
|
191
209
|
val _this = this
|
|
192
|
-
val gesturesPlugin: GesturesPlugin =
|
|
210
|
+
val gesturesPlugin: GesturesPlugin = mapView.gestures
|
|
193
211
|
gesturesPlugin.removeOnMapClickListener(_this)
|
|
194
212
|
gesturesPlugin.removeOnMapLongClickListener(_this)
|
|
195
213
|
|
|
196
|
-
mPointAnnotationManager = annotations.createPointAnnotationManager(AnnotationConfig(layerId = "rctmgl-mapview-annotations"))
|
|
214
|
+
mPointAnnotationManager = mapView.annotations.createPointAnnotationManager(AnnotationConfig(layerId = "rctmgl-mapview-annotations"))
|
|
197
215
|
mPointAnnotationManager?.addClickListener(OnPointAnnotationClickListener { pointAnnotation ->
|
|
198
216
|
onMarkerClick(pointAnnotation)
|
|
199
217
|
false
|
|
@@ -272,7 +290,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
272
290
|
handleMapChangedEvent(EventTypes.MAP_IDLE);
|
|
273
291
|
})
|
|
274
292
|
|
|
275
|
-
val gesturesPlugin: GesturesPlugin =
|
|
293
|
+
val gesturesPlugin: GesturesPlugin = mapView.gestures
|
|
276
294
|
gesturesPlugin.addOnMapLongClickListener(_this)
|
|
277
295
|
gesturesPlugin.addOnMapClickListener(_this)
|
|
278
296
|
|
|
@@ -581,7 +599,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
581
599
|
ScreenCoordinate(screenPoint.x + halfWidth,
|
|
582
600
|
screenPoint.y + halfHeight)
|
|
583
601
|
)
|
|
584
|
-
getMapboxMap().queryRenderedFeatures(RenderedQueryGeometry(screenBox),
|
|
602
|
+
mapView.getMapboxMap().queryRenderedFeatures(RenderedQueryGeometry(screenBox),
|
|
585
603
|
RenderedQueryOptions(
|
|
586
604
|
source.layerIDs,
|
|
587
605
|
null
|
|
@@ -814,7 +832,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
814
832
|
}
|
|
815
833
|
|
|
816
834
|
fun getMapAsync(mapReady: OnMapReadyCallback) {
|
|
817
|
-
mapReady.onMapReady(getMapboxMap())
|
|
835
|
+
mapReady.onMapReady(mapView.getMapboxMap())
|
|
818
836
|
}
|
|
819
837
|
|
|
820
838
|
//fun setTintColor(color: Int) {
|
|
@@ -938,7 +956,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
938
956
|
}
|
|
939
957
|
|
|
940
958
|
fun takeSnap(callbackID: String?, writeToDisk: Boolean) {
|
|
941
|
-
|
|
959
|
+
mapView.snapshot { snapshot ->
|
|
942
960
|
if (snapshot == null) {
|
|
943
961
|
Logger.e("takeSnap", "snapshot failed")
|
|
944
962
|
|
|
@@ -1030,7 +1048,13 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1030
1048
|
offscreenAnnotationViewContainer?.setLayoutParams(p)
|
|
1031
1049
|
addView(offscreenAnnotationViewContainer)
|
|
1032
1050
|
|
|
1033
|
-
|
|
1051
|
+
mMapView = if (options != null) MapView(mContext, options) else MapView(mContext)
|
|
1052
|
+
|
|
1053
|
+
val matchParent = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
|
1054
|
+
mMapView.setLayoutParams(matchParent)
|
|
1055
|
+
addView(mMapView)
|
|
1056
|
+
|
|
1057
|
+
mMap = mapView.getMapboxMap()
|
|
1034
1058
|
mSources = HashMap()
|
|
1035
1059
|
mImages = ArrayList()
|
|
1036
1060
|
mPointAnnotations = HashMap()
|
|
@@ -1050,7 +1074,9 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1050
1074
|
}
|
|
1051
1075
|
})
|
|
1052
1076
|
|
|
1053
|
-
RCTMGLMarkerViewManager.markerViewContainerSizeFixer(this,
|
|
1077
|
+
RCTMGLMarkerViewManager.markerViewContainerSizeFixer(this, mapView.viewAnnotationManager)
|
|
1078
|
+
|
|
1079
|
+
this.addOnLayoutChangeListener(this)
|
|
1054
1080
|
}
|
|
1055
1081
|
|
|
1056
1082
|
// region Ornaments
|
|
@@ -1135,7 +1161,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1135
1161
|
}
|
|
1136
1162
|
|
|
1137
1163
|
private fun updateCompass() {
|
|
1138
|
-
compass.updateSettings {
|
|
1164
|
+
mapView.compass.updateSettings {
|
|
1139
1165
|
fadeWhenFacingNorth = mCompassFadeWhenNorth
|
|
1140
1166
|
updateOrnament("compass", mCompassSettings, this.toGenericOrnamentSettings())
|
|
1141
1167
|
}
|
|
@@ -1180,8 +1206,8 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1180
1206
|
mapView.forceLayout();
|
|
1181
1207
|
|
|
1182
1208
|
mapView.measure(
|
|
1183
|
-
MeasureSpec.makeMeasureSpec(
|
|
1184
|
-
MeasureSpec.makeMeasureSpec(
|
|
1209
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
1210
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
1185
1211
|
);
|
|
1186
1212
|
mapView.layout(mapView.left, mapView.top, mapView.right, mapView.bottom)
|
|
1187
1213
|
}
|
|
@@ -1236,7 +1262,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1236
1262
|
}
|
|
1237
1263
|
|
|
1238
1264
|
private fun updateAttribution() {
|
|
1239
|
-
attribution.updateSettings {
|
|
1265
|
+
mapView.attribution.updateSettings {
|
|
1240
1266
|
updateOrnament("attribution", mAttributionSettings, this.toGenericOrnamentSettings())
|
|
1241
1267
|
}
|
|
1242
1268
|
workaroundToRelayoutChildOfMapView()
|
|
@@ -1271,7 +1297,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1271
1297
|
}
|
|
1272
1298
|
|
|
1273
1299
|
private fun updateLogo() {
|
|
1274
|
-
logo.updateSettings {
|
|
1300
|
+
mapView.logo.updateSettings {
|
|
1275
1301
|
updateOrnament("logo", mLogoSettings, this.toGenericOrnamentSettings())
|
|
1276
1302
|
}
|
|
1277
1303
|
workaroundToRelayoutChildOfMapView()
|
|
@@ -1290,18 +1316,21 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1290
1316
|
super.onDetachedFromWindow();
|
|
1291
1317
|
}
|
|
1292
1318
|
|
|
1319
|
+
/* FMTODO
|
|
1293
1320
|
override fun onDestroy() {
|
|
1321
|
+
this.removeOnLayoutChangeListener(this)
|
|
1294
1322
|
removeAllFeaturesFromMap(RemovalReason.ON_DESTROY)
|
|
1295
|
-
viewAnnotationManager.removeAllViewAnnotations()
|
|
1323
|
+
mapView.viewAnnotationManager.removeAllViewAnnotations()
|
|
1296
1324
|
mLocationComponentManager?.onDestroy();
|
|
1297
1325
|
|
|
1298
1326
|
lifecycle.onDestroy()
|
|
1299
1327
|
super.onDestroy()
|
|
1300
1328
|
}
|
|
1329
|
+
*/
|
|
1301
1330
|
|
|
1302
1331
|
fun onDropViewInstance() {
|
|
1303
1332
|
removeAllFeaturesFromMap(RemovalReason.ON_DESTROY)
|
|
1304
|
-
viewAnnotationManager.removeAllViewAnnotations()
|
|
1333
|
+
mapView.viewAnnotationManager.removeAllViewAnnotations()
|
|
1305
1334
|
lifecycle.onDestroy()
|
|
1306
1335
|
}
|
|
1307
1336
|
|
|
@@ -1310,10 +1339,50 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1310
1339
|
super.onAttachedToWindow()
|
|
1311
1340
|
}
|
|
1312
1341
|
|
|
1342
|
+
override fun onLayoutChange(
|
|
1343
|
+
v: View?,
|
|
1344
|
+
left: Int,
|
|
1345
|
+
top: Int,
|
|
1346
|
+
right: Int,
|
|
1347
|
+
bottom: Int,
|
|
1348
|
+
oldLeft: Int,
|
|
1349
|
+
oldTop: Int,
|
|
1350
|
+
oldRight: Int,
|
|
1351
|
+
oldBottom: Int
|
|
1352
|
+
) {
|
|
1353
|
+
mapView.post {
|
|
1354
|
+
mapView.measure(
|
|
1355
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
1356
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
1357
|
+
)
|
|
1358
|
+
mapView.layout(mapView.left, mapView.top, mapView.right, mapView.bottom)
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1313
1362
|
|
|
1314
1363
|
// endregion
|
|
1315
1364
|
}
|
|
1316
1365
|
|
|
1366
|
+
// region requestDisallowInterceptTouchEvent
|
|
1367
|
+
fun RCTMGLMapView.updateRequestDisallowInterceptTouchEvent(oldValue: Boolean, value: Boolean) {
|
|
1368
|
+
if (oldValue == value) {
|
|
1369
|
+
return
|
|
1370
|
+
}
|
|
1371
|
+
if (value) {
|
|
1372
|
+
mapView.setOnTouchListener { view, event ->
|
|
1373
|
+
this.requestDisallowInterceptTouchEvent(true)
|
|
1374
|
+
mapView.onTouchEvent(event)
|
|
1375
|
+
true
|
|
1376
|
+
}
|
|
1377
|
+
} else {
|
|
1378
|
+
mapView.setOnTouchListener { view, event ->
|
|
1379
|
+
mapView.onTouchEvent(event)
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
// endregion
|
|
1384
|
+
|
|
1385
|
+
|
|
1317
1386
|
fun OrnamentSettings.setPosAndMargins(posAndMargins: ReadableMap?) {
|
|
1318
1387
|
if (posAndMargins == null) { return }
|
|
1319
1388
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.mapbox.rctmgl.components.mapview
|
|
2
2
|
|
|
3
|
+
import android.content.Context
|
|
3
4
|
import android.util.Log
|
|
4
5
|
import android.view.View
|
|
5
6
|
import com.facebook.react.bridge.*
|
|
@@ -11,6 +12,7 @@ import com.facebook.react.uimanager.annotations.ReactProp
|
|
|
11
12
|
import com.mapbox.rctmgl.events.constants.EventKeys
|
|
12
13
|
import com.mapbox.maps.MapboxMap
|
|
13
14
|
import com.facebook.react.common.MapBuilder
|
|
15
|
+
import com.mapbox.maps.MapInitOptions
|
|
14
16
|
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
|
|
15
17
|
import com.mapbox.maps.plugin.compass.compass
|
|
16
18
|
import com.mapbox.maps.plugin.gestures.gestures
|
|
@@ -36,8 +38,8 @@ fun ReadableArray.asArrayString(): Array<String> {
|
|
|
36
38
|
return result
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
open class RCTMGLMapViewManager(context: ReactApplicationContext
|
|
40
|
-
AbstractEventEmitter<RCTMGLMapView
|
|
41
|
+
open class RCTMGLMapViewManager(context: ReactApplicationContext) :
|
|
42
|
+
AbstractEventEmitter<RCTMGLMapView>(context) {
|
|
41
43
|
private val mViews: MutableMap<Int, RCTMGLMapView>
|
|
42
44
|
override fun getName(): String {
|
|
43
45
|
return REACT_CLASS
|
|
@@ -75,8 +77,13 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
|
|
|
75
77
|
mapView!!.removeFeatureAt(index)
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
fun getMapViewContext(themedReactContext: ThemedReactContext): Context {
|
|
81
|
+
return activity ?: themedReactContext
|
|
82
|
+
}
|
|
83
|
+
|
|
78
84
|
override fun createViewInstance(themedReactContext: ThemedReactContext): RCTMGLMapView {
|
|
79
|
-
|
|
85
|
+
val context = getMapViewContext(themedReactContext)
|
|
86
|
+
return RCTMGLMapView(context, this, options=null)
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
override fun onDropViewInstance(mapView: RCTMGLMapView) {
|
|
@@ -116,24 +123,28 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
|
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
@ReactProp(name = "zoomEnabled")
|
|
119
|
-
fun setZoomEnabled(
|
|
126
|
+
fun setZoomEnabled(map: RCTMGLMapView, zoomEnabled: Boolean) {
|
|
127
|
+
val mapView = map.mapView
|
|
120
128
|
mapView.gestures.pinchToZoomEnabled = zoomEnabled
|
|
121
129
|
mapView.gestures.doubleTouchToZoomOutEnabled = zoomEnabled
|
|
122
130
|
mapView.gestures.doubleTapToZoomInEnabled = zoomEnabled
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
@ReactProp(name = "scrollEnabled")
|
|
126
|
-
fun setScrollEnabled(
|
|
134
|
+
fun setScrollEnabled(map: RCTMGLMapView, scrollEnabled: Boolean) {
|
|
135
|
+
val mapView = map.mapView
|
|
127
136
|
mapView.gestures.scrollEnabled = scrollEnabled
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
@ReactProp(name = "pitchEnabled")
|
|
131
|
-
fun setPitchEnabled(
|
|
140
|
+
fun setPitchEnabled(map: RCTMGLMapView, pitchEnabled: Boolean) {
|
|
141
|
+
val mapView = map.mapView
|
|
132
142
|
mapView.gestures.pitchEnabled = pitchEnabled
|
|
133
143
|
}
|
|
134
144
|
|
|
135
145
|
@ReactProp(name = "rotateEnabled")
|
|
136
|
-
fun setRotateEnabled(
|
|
146
|
+
fun setRotateEnabled(map: RCTMGLMapView, rotateEnabled: Boolean) {
|
|
147
|
+
val mapView = map.mapView
|
|
137
148
|
mapView.gestures.rotateEnabled = rotateEnabled
|
|
138
149
|
}
|
|
139
150
|
|
|
@@ -222,6 +233,11 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
|
|
|
222
233
|
//mapView.setTintColor(tintColor);
|
|
223
234
|
}
|
|
224
235
|
|
|
236
|
+
@ReactProp(name = "requestDisallowInterceptTouchEvent")
|
|
237
|
+
fun setRequestDisallowInterceptTouchEvent(mapView: RCTMGLMapView, requestDisallowInterceptTouchEvent: Boolean) {
|
|
238
|
+
mapView.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent
|
|
239
|
+
}
|
|
240
|
+
|
|
225
241
|
//endregion
|
|
226
242
|
//region Custom Events
|
|
227
243
|
override fun customEvents(): Map<String, String>? {
|
|
@@ -310,7 +326,7 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
|
|
|
310
326
|
}
|
|
311
327
|
METHOD_SET_HANDLED_MAP_EVENTS -> {
|
|
312
328
|
args?.let {
|
|
313
|
-
mapView.setHandledMapChangedEvents(
|
|
329
|
+
mapView.setHandledMapChangedEvents(it.getArray(1).asArrayString());
|
|
314
330
|
}
|
|
315
331
|
}
|
|
316
332
|
}
|
|
@@ -5,7 +5,7 @@ import com.facebook.react.uimanager.ThemedReactContext
|
|
|
5
5
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
6
6
|
import javax.annotation.Nonnull
|
|
7
7
|
|
|
8
|
-
class RCTMGLRasterSourceManager(reactApplicationContext: ReactApplicationContext
|
|
8
|
+
class RCTMGLRasterSourceManager(reactApplicationContext: ReactApplicationContext) :
|
|
9
9
|
RCTMGLTileSourceManager<RCTMGLRasterSource?>(reactApplicationContext) {
|
|
10
10
|
@Nonnull
|
|
11
11
|
override fun getName(): String {
|