@rnmapbox/maps 10.0.0-beta.43 → 10.0.0-beta.45
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/android/install.md +49 -1
- package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/camera/CameraStop.java +4 -4
- package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java +3 -3
- package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +0 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerView.kt +162 -51
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewManager.kt +10 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLPointAnnotation.kt +6 -6
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +11 -7
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +22 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +17 -19
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyle.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/DownloadMapImageTask.kt +2 -1
- package/docs/MapboxGL.md +1 -1
- package/docs/MarkerView.md +17 -10
- package/docs/PointAnnotation.md +1 -1
- package/docs/ShapeSource.md +13 -9
- package/docs/SymbolLayer.md +1 -1
- package/docs/docs.json +145 -161
- package/index.d.ts +7 -56
- package/ios/RCTMGL-v10/RCTLog.swift +5 -5
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +2 -2
- package/ios/RCTMGL-v10/RCTMGLMapViewManager.swift +2 -2
- package/ios/RCTMGL-v10/RCTMGLMarkerView.swift +186 -105
- package/ios/RCTMGL-v10/RCTMGLMarkerViewManager.m +2 -1
- package/ios/RCTMGL-v10/RCTMGLShapeSourceManager.swift +1 -1
- package/ios/RCTMGL-v10/RCTMGLUtils.swift +1 -1
- package/ios/RCTMGL-v10/RCTMGLVectorLayer.swift +1 -1
- package/ios/install.md +3 -2
- package/javascript/components/AbstractLayer.tsx +9 -6
- package/javascript/components/AbstractSource.tsx +23 -0
- package/javascript/components/HeadingIndicator.tsx +1 -1
- package/javascript/components/Images.js +1 -1
- package/javascript/components/MapView.js +5 -2
- package/javascript/components/MarkerView.tsx +81 -76
- package/javascript/components/NativeBridgeComponent.tsx +20 -14
- package/javascript/components/PointAnnotation.tsx +3 -2
- package/javascript/components/RasterSource.js +1 -1
- package/javascript/components/ShapeSource.tsx +412 -0
- package/javascript/components/Style.js +2 -2
- package/javascript/components/SymbolLayer.tsx +3 -5
- package/javascript/components/VectorSource.js +6 -3
- package/javascript/components/annotations/Annotation.js +1 -1
- package/javascript/index.js +2 -2
- package/javascript/utils/animated/Animated.js +2 -2
- package/javascript/utils/deprecation.ts +7 -4
- package/javascript/utils/filterUtils.tsx +1 -1
- package/javascript/utils/index.d.ts +19 -6
- package/package.json +1 -1
- package/scripts/autogenHelpers/DocJSONBuilder.js +17 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewWrapper.kt +0 -8
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewWrapperManager.kt +0 -21
- package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapper.swift +0 -24
- package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapperManager.m +0 -8
- package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapperManager.swift +0 -14
- package/javascript/components/AbstractSource.js +0 -15
- package/javascript/components/ShapeSource.js +0 -373
package/android/install.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
Add `RNMapboxMapsImpl = "mapbox"` to your gradle file - see bellow for details.
|
|
12
12
|
|
|
13
|
-
###
|
|
13
|
+
### Setting RNMapboxMapsImpl to v10
|
|
14
14
|
|
|
15
15
|
*Warning*: If you set a custom version, make sure you revisit, any time you update @rnmapbox/maps. Setting it to earlier version than what we exepect will likely result in a build error.
|
|
16
16
|
|
|
@@ -22,6 +22,53 @@ buildscript {
|
|
|
22
22
|
ext {
|
|
23
23
|
// ...
|
|
24
24
|
RNMapboxMapsImpl = "mapbox" // required for v10
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Adding mapbox maven repo
|
|
30
|
+
|
|
31
|
+
You will need to authorize your download of the Maps SDK via a secret access token with the `DOWNLOADS:READ` scope.
|
|
32
|
+
This [guide](https://docs.mapbox.com/android/maps/guides/install/#configure-credentials) explains how to `Configure credentials` and `Configure your secret token`.
|
|
33
|
+
|
|
34
|
+
Then under section `allprojects/repositories` add your data:
|
|
35
|
+
|
|
36
|
+
```groovy
|
|
37
|
+
// android/build.gradle
|
|
38
|
+
|
|
39
|
+
allprojects {
|
|
40
|
+
repositories {
|
|
41
|
+
// ...other repos
|
|
42
|
+
maven {
|
|
43
|
+
url 'https://api.mapbox.com/downloads/v2/releases/maven'
|
|
44
|
+
authentication {
|
|
45
|
+
basic(BasicAuthentication)
|
|
46
|
+
}
|
|
47
|
+
credentials {
|
|
48
|
+
// Do not change the username below.
|
|
49
|
+
// This should always be `mapbox` (not your username).
|
|
50
|
+
username = 'mapbox'
|
|
51
|
+
// Use the secret token you stored in gradle.properties as the password
|
|
52
|
+
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// ...even more repos?
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Using non default mapbox version
|
|
61
|
+
|
|
62
|
+
*Warning*: If you set a custom version, make sure you revisit, any time you update @rnmapbox/maps. Setting it to earlier version than what we exepect will likely result in a build error.
|
|
63
|
+
|
|
64
|
+
Set `RNMapboxMapsLibs` in `android/build.gradle > buildscript > ext` section
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
```groovy
|
|
68
|
+
buildscript {
|
|
69
|
+
ext {
|
|
70
|
+
// ...
|
|
71
|
+
RNMapboxMapsImpl = "mapbox"
|
|
25
72
|
|
|
26
73
|
RNMapboxMapsLibs = { // optional - only required if you want to customize it
|
|
27
74
|
implementation 'com.mapbox.maps:android:10.6.0'
|
|
@@ -32,6 +79,7 @@ buildscript {
|
|
|
32
79
|
```
|
|
33
80
|
|
|
34
81
|
|
|
82
|
+
|
|
35
83
|
If you see `2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs` issue see [possible workaround](#workaround-for-2-files-found-with-path-libarm64-v8alibc_sharedso-from-inputs).
|
|
36
84
|
|
|
37
85
|
## Using MapLibre
|
|
@@ -162,10 +162,10 @@ public class CameraStop {
|
|
|
162
162
|
|
|
163
163
|
// scale padding by pixel ratio
|
|
164
164
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
|
165
|
-
paddingTop = Float.valueOf(paddingTop * metrics.
|
|
166
|
-
paddingRight = Float.valueOf(paddingRight * metrics.
|
|
167
|
-
paddingBottom = Float.valueOf(paddingBottom * metrics.
|
|
168
|
-
paddingLeft = Float.valueOf(paddingLeft * metrics.
|
|
165
|
+
paddingTop = Float.valueOf(paddingTop * metrics.density).intValue();
|
|
166
|
+
paddingRight = Float.valueOf(paddingRight * metrics.density).intValue();
|
|
167
|
+
paddingBottom = Float.valueOf(paddingBottom * metrics.density).intValue();
|
|
168
|
+
paddingLeft = Float.valueOf(paddingLeft * metrics.density).intValue();
|
|
169
169
|
|
|
170
170
|
stop.setPadding(
|
|
171
171
|
paddingLeft,
|
|
@@ -326,9 +326,9 @@ public class RCTMGLMapView extends MapView implements OnMapReadyCallback, Mapbox
|
|
|
326
326
|
int[] contentPadding = mMap.getPadding();
|
|
327
327
|
|
|
328
328
|
int mapWidth = (int) ((mMap.getWidth() * 0.75 - (contentPadding[0] + contentPadding[2]))
|
|
329
|
-
/ metrics.
|
|
329
|
+
/ metrics.density);
|
|
330
330
|
int mapHeight = (int) ((mMap.getHeight() * 0.75 - (contentPadding[1] + contentPadding[3]))
|
|
331
|
-
/ metrics.
|
|
331
|
+
/ metrics.density);
|
|
332
332
|
VisibleRegion region = GeoViewport.getRegion(center, (int) zoomLevel, mapWidth, mapHeight);
|
|
333
333
|
return region;
|
|
334
334
|
}
|
|
@@ -1246,7 +1246,7 @@ public class RCTMGLMapView extends MapView implements OnMapReadyCallback, Mapbox
|
|
|
1246
1246
|
|
|
1247
1247
|
final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
|
|
1248
1248
|
|
|
1249
|
-
double[] result = {left * metrics.
|
|
1249
|
+
double[] result = {left * metrics.density, top * metrics.density, right * metrics.density, bottom * metrics.density};
|
|
1250
1250
|
return result;
|
|
1251
1251
|
}
|
|
1252
1252
|
|
|
@@ -107,7 +107,7 @@ public class RCTMGLSnapshotModule extends ReactContextBaseJavaModule {
|
|
|
107
107
|
|
|
108
108
|
options.withLogo(jsOptions.getBoolean("withLogo"));
|
|
109
109
|
options.withStyle(jsOptions.getString("styleURL"));
|
|
110
|
-
options.withPixelRatio(Float.valueOf(mContext.getResources().getDisplayMetrics().
|
|
110
|
+
options.withPixelRatio(Float.valueOf(mContext.getResources().getDisplayMetrics().density).intValue());
|
|
111
111
|
|
|
112
112
|
if (jsOptions.hasKey("bounds")) {
|
|
113
113
|
FeatureCollection bounds = FeatureCollection.fromJson(jsOptions.getString("bounds"));
|
|
@@ -10,7 +10,6 @@ import java.util.ArrayList;
|
|
|
10
10
|
import java.util.Collections;
|
|
11
11
|
import java.util.List;
|
|
12
12
|
|
|
13
|
-
import com.mapbox.rctmgl.components.annotation.RCTMGLMarkerViewWrapperManager;
|
|
14
13
|
import com.mapbox.rctmgl.components.camera.RCTMGLCameraManager;
|
|
15
14
|
|
|
16
15
|
import com.mapbox.rctmgl.components.annotation.RCTMGLCalloutManager;
|
|
@@ -81,7 +80,6 @@ public class RCTMGLPackage implements ReactPackage {
|
|
|
81
80
|
|
|
82
81
|
// annotations
|
|
83
82
|
managers.add(new RCTMGLMarkerViewManager(reactApplicationContext));
|
|
84
|
-
managers.add(new RCTMGLMarkerViewWrapperManager(reactApplicationContext));
|
|
85
83
|
managers.add(new RCTMGLPointAnnotationManager(reactApplicationContext));
|
|
86
84
|
managers.add(new RCTMGLCalloutManager());
|
|
87
85
|
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerView.kt
CHANGED
|
@@ -1,85 +1,196 @@
|
|
|
1
1
|
package com.mapbox.rctmgl.components.annotation
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.util.Log
|
|
4
7
|
import android.view.View
|
|
8
|
+
import android.widget.FrameLayout
|
|
5
9
|
import com.mapbox.geojson.Point
|
|
10
|
+
import com.mapbox.maps.ViewAnnotationAnchor
|
|
6
11
|
import com.mapbox.maps.ViewAnnotationOptions
|
|
12
|
+
import com.mapbox.maps.viewannotation.viewAnnotationOptions
|
|
7
13
|
import com.mapbox.rctmgl.components.AbstractMapFeature
|
|
8
14
|
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
|
|
15
|
+
import com.mapbox.rctmgl.modules.RCTMGLLogging
|
|
16
|
+
import com.mapbox.rctmgl.utils.Logger
|
|
17
|
+
import java.util.Vector
|
|
18
|
+
|
|
19
|
+
private data class Vec2(val dx: Double, val dy: Double)
|
|
20
|
+
|
|
21
|
+
class RCTMGLMarkerView(context: Context?, private val mManager: RCTMGLMarkerViewManager):
|
|
22
|
+
AbstractMapFeature(context),
|
|
23
|
+
View.OnLayoutChangeListener
|
|
24
|
+
{
|
|
25
|
+
// region Instance variables
|
|
9
26
|
|
|
10
|
-
class RCTMGLMarkerView(context: Context?, private val mManager: RCTMGLMarkerViewManager) : AbstractMapFeature(context), View.OnLayoutChangeListener {
|
|
11
27
|
private var mMapView: RCTMGLMapView? = null
|
|
12
|
-
private var
|
|
13
|
-
private var
|
|
14
|
-
private lateinit var mAnchor: Array<Float>
|
|
28
|
+
private var mView: View? = null
|
|
29
|
+
private var didAddToMap = false
|
|
15
30
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
private var mCoordinate: Point? = null
|
|
32
|
+
private var mAnchor: Vec2 = Vec2(0.5, 0.5)
|
|
33
|
+
private var mAllowOverlap = false
|
|
34
|
+
private var mIsSelected = false
|
|
19
35
|
|
|
20
36
|
fun setCoordinate(point: Point?) {
|
|
21
37
|
mCoordinate = point
|
|
22
|
-
|
|
23
|
-
val options = ViewAnnotationOptions.Builder().geometry(mCoordinate).build()
|
|
24
|
-
mMapView?.viewAnnotationManager?.updateViewAnnotation(mChildView!!, options)
|
|
25
|
-
}
|
|
38
|
+
update()
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
fun setAnchor(x: Float, y: Float) {
|
|
29
|
-
mAnchor =
|
|
30
|
-
|
|
42
|
+
mAnchor = Vec2(x.toDouble(), y.toDouble())
|
|
43
|
+
update()
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
fun
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
fun setAllowOverlap(allowOverlap: Boolean) {
|
|
47
|
+
mAllowOverlap = allowOverlap
|
|
48
|
+
update()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fun setIsSelected(isSelected: Boolean) {
|
|
52
|
+
mIsSelected = isSelected
|
|
53
|
+
update()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// endregion
|
|
57
|
+
|
|
58
|
+
// region View methods
|
|
59
|
+
|
|
60
|
+
override fun addView(childView: View, childPosition: Int) {
|
|
61
|
+
mView = childView
|
|
62
|
+
// Note: Do not call this method on `super`. The view is added manually.
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun onLayoutChange(
|
|
66
|
+
v: View,
|
|
67
|
+
left: Int, top: Int, right: Int, bottom: Int,
|
|
68
|
+
oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int
|
|
69
|
+
) {
|
|
70
|
+
addOrUpdate()
|
|
41
71
|
}
|
|
42
72
|
|
|
73
|
+
// endregion
|
|
74
|
+
|
|
75
|
+
// region RCTMGLMapComponent methods
|
|
76
|
+
|
|
43
77
|
override fun addToMap(mapView: RCTMGLMapView) {
|
|
44
78
|
mMapView = mapView
|
|
45
|
-
|
|
46
|
-
mMapView?.getMapAsync {
|
|
47
|
-
if (mChildView != null) {
|
|
48
|
-
val width = mChildView!!.width
|
|
49
|
-
val height = mChildView!!.height
|
|
50
|
-
val options = ViewAnnotationOptions.Builder().geometry(mCoordinate).width(width).height(height).offsetX(((mAnchor[0] - 0.5) * width).toInt()).offsetY(((mAnchor[1] - 0.5) * height).toInt()).build()
|
|
51
|
-
mChildView!!.addOnLayoutChangeListener(rctmglMarkerView)
|
|
52
|
-
if (mChildView!!.layoutParams == null && !mChildView!!.isAttachedToWindow) {
|
|
53
|
-
mMapView?.offscreenAnnotationViewContainer()?.addView(mChildView)
|
|
54
|
-
mMapView?.offscreenAnnotationViewContainer()?.removeView(mChildView)
|
|
55
|
-
}
|
|
56
|
-
mMapView?.viewAnnotationManager?.addViewAnnotation(mChildView!!, options)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
79
|
+
add()
|
|
59
80
|
}
|
|
60
81
|
|
|
61
82
|
override fun removeFromMap(mapView: RCTMGLMapView) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
remove(mapView)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// endregion
|
|
87
|
+
|
|
88
|
+
// region Create, update, and remove methods
|
|
89
|
+
|
|
90
|
+
private fun addOrUpdate() {
|
|
91
|
+
if (didAddToMap) {
|
|
92
|
+
update()
|
|
93
|
+
} else {
|
|
94
|
+
add()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private fun add() {
|
|
99
|
+
if (didAddToMap) {
|
|
100
|
+
return
|
|
67
101
|
}
|
|
102
|
+
|
|
103
|
+
if (mView == null || mCoordinate == null) {
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
val view = mView!!
|
|
107
|
+
|
|
108
|
+
view.addOnLayoutChangeListener(this)
|
|
109
|
+
|
|
110
|
+
if (view.layoutParams == null && !view.isAttachedToWindow) {
|
|
111
|
+
mMapView?.offscreenAnnotationViewContainer?.addView(view)
|
|
112
|
+
mMapView?.offscreenAnnotationViewContainer?.removeView(view)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
val options = getOptions()
|
|
116
|
+
|
|
117
|
+
val annotation = mMapView?.viewAnnotationManager?.addViewAnnotation(
|
|
118
|
+
view,
|
|
119
|
+
options
|
|
120
|
+
)
|
|
121
|
+
didAddToMap = true
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
fun update() {
|
|
125
|
+
if (!didAddToMap) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (mView == null || mCoordinate == null) {
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
val view = mView!!
|
|
133
|
+
|
|
134
|
+
val options = getOptions()
|
|
135
|
+
|
|
136
|
+
val annotation = mMapView?.viewAnnotationManager?.updateViewAnnotation(
|
|
137
|
+
view,
|
|
138
|
+
options
|
|
139
|
+
)
|
|
68
140
|
}
|
|
69
141
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (left != oldLeft || right != oldRight || top != oldTop || bottom != oldBottom) {
|
|
73
|
-
val centerX = oldLeft + (oldRight-oldLeft)*mAnchor[0];
|
|
74
|
-
val centerY = oldTop + (oldBottom-oldTop)*mAnchor[1];
|
|
142
|
+
private fun remove(mapView: RCTMGLMapView) {
|
|
143
|
+
this.removeOnLayoutChangeListener(this)
|
|
75
144
|
|
|
76
|
-
|
|
77
|
-
|
|
145
|
+
mView?.let { view ->
|
|
146
|
+
mapView.endViewTransition(view) // https://github.com/mapbox/mapbox-maps-android/issues/1723
|
|
147
|
+
val removed = mapView.viewAnnotationManager?.removeViewAnnotation(view)
|
|
148
|
+
if (removed == false) {
|
|
149
|
+
Logger.w("RCTMGLMarkerView", "Unable to remove view")
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// endregion
|
|
155
|
+
|
|
156
|
+
// region Helper functions
|
|
157
|
+
|
|
158
|
+
private fun getOptions(): ViewAnnotationOptions {
|
|
159
|
+
val view = mView!!
|
|
160
|
+
val width = view.width
|
|
161
|
+
val height = view.height
|
|
162
|
+
val coordinate = mCoordinate
|
|
163
|
+
|
|
164
|
+
val offset = getOffset()
|
|
78
165
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
166
|
+
val options = viewAnnotationOptions {
|
|
167
|
+
geometry(coordinate)
|
|
168
|
+
width(width)
|
|
169
|
+
height(height)
|
|
170
|
+
allowOverlap(mAllowOverlap)
|
|
171
|
+
offsetX(offset.dx.toInt())
|
|
172
|
+
offsetY(offset.dy.toInt())
|
|
173
|
+
selected(mIsSelected)
|
|
83
174
|
}
|
|
175
|
+
return options
|
|
84
176
|
}
|
|
177
|
+
|
|
178
|
+
private fun getOffset(): Vec2 {
|
|
179
|
+
if (mView == null) {
|
|
180
|
+
return Vec2(0.0, 0.0)
|
|
181
|
+
}
|
|
182
|
+
val view = mView!!
|
|
183
|
+
|
|
184
|
+
val width = view.width
|
|
185
|
+
val height = view.height
|
|
186
|
+
|
|
187
|
+
// Create a modified offset, normalized from 0..1 to -1..1 and scaled to
|
|
188
|
+
// the view size.
|
|
189
|
+
val offsetX = (mAnchor.dx * 2 - 1) * (width / 2) * -1
|
|
190
|
+
val offsetY = (mAnchor.dy * 2 - 1) * (height / 2)
|
|
191
|
+
|
|
192
|
+
return Vec2(offsetX, offsetY)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// endregion
|
|
85
196
|
}
|
|
@@ -25,6 +25,16 @@ class RCTMGLMarkerViewManager(reactApplicationContext: ReactApplicationContext?)
|
|
|
25
25
|
markerView.setAnchor(map.getDouble("x").toFloat(), map.getDouble("y").toFloat())
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
@ReactProp(name = "allowOverlap")
|
|
29
|
+
fun setAllowOverlap(markerView: RCTMGLMarkerView, allowOverlap: Boolean) {
|
|
30
|
+
markerView.setAllowOverlap(allowOverlap)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactProp(name = "isSelected")
|
|
34
|
+
fun setIsSelected(markerView: RCTMGLMarkerView, isSelected: Boolean) {
|
|
35
|
+
markerView.setIsSelected(isSelected)
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
override fun createViewInstance(reactContext: ThemedReactContext): RCTMGLMarkerView {
|
|
29
39
|
return RCTMGLMarkerView(reactContext, this)
|
|
30
40
|
}
|
|
@@ -53,7 +53,7 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
|
|
|
53
53
|
}
|
|
54
54
|
childView.addOnLayoutChangeListener(this)
|
|
55
55
|
|
|
56
|
-
mMapView?.offscreenAnnotationViewContainer
|
|
56
|
+
mMapView?.offscreenAnnotationViewContainer?.addView(childView)
|
|
57
57
|
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -70,7 +70,7 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
|
|
|
70
70
|
}
|
|
71
71
|
})
|
|
72
72
|
}
|
|
73
|
-
mMapView?.offscreenAnnotationViewContainer
|
|
73
|
+
mMapView?.offscreenAnnotationViewContainer?.removeView(childView)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
override fun addToMap(mapView: RCTMGLMapView) {
|
|
@@ -79,14 +79,14 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
|
|
|
79
79
|
makeMarker()
|
|
80
80
|
if (mChildView != null) {
|
|
81
81
|
if (!mChildView!!.isAttachedToWindow) {
|
|
82
|
-
mMapView!!.offscreenAnnotationViewContainer
|
|
82
|
+
mMapView!!.offscreenAnnotationViewContainer?.addView(mChildView)
|
|
83
83
|
}
|
|
84
84
|
addBitmapToStyle(mChildBitmap, mChildBitmapId)
|
|
85
85
|
updateOptions()
|
|
86
86
|
}
|
|
87
87
|
if (calloutView != null) {
|
|
88
88
|
if (!calloutView!!.isAttachedToWindow && mMapView != null) {
|
|
89
|
-
mMapView!!.offscreenAnnotationViewContainer
|
|
89
|
+
mMapView!!.offscreenAnnotationViewContainer?.addView(calloutView)
|
|
90
90
|
}
|
|
91
91
|
addBitmapToStyle(mCalloutBitmap, mCalloutBitmapId)
|
|
92
92
|
}
|
|
@@ -98,10 +98,10 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
|
|
|
98
98
|
map.pointAnnotationManager?.delete(marker!!)
|
|
99
99
|
}
|
|
100
100
|
if (mChildView != null) {
|
|
101
|
-
map.offscreenAnnotationViewContainer
|
|
101
|
+
map.offscreenAnnotationViewContainer?.removeView(mChildView)
|
|
102
102
|
}
|
|
103
103
|
if (calloutView != null) {
|
|
104
|
-
map.offscreenAnnotationViewContainer
|
|
104
|
+
map.offscreenAnnotationViewContainer?.removeView(calloutView)
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -84,8 +84,12 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
fun convert(value: IntArray): EdgeInsets {
|
|
87
|
+
val left = value[0].toDouble();
|
|
88
|
+
val top = value[1].toDouble();
|
|
89
|
+
val right = value[2].toDouble();
|
|
90
|
+
val bottom = value[3].toDouble();
|
|
87
91
|
return EdgeInsets(
|
|
88
|
-
|
|
92
|
+
top, left, bottom, right
|
|
89
93
|
)
|
|
90
94
|
}
|
|
91
95
|
|
|
@@ -162,10 +166,10 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
|
|
|
162
166
|
}
|
|
163
167
|
if (readableMap.hasKey("bounds")) {
|
|
164
168
|
val metrics = context.resources.displayMetrics
|
|
165
|
-
var paddingTop = getBoundsPaddingByKey(readableMap, metrics.
|
|
166
|
-
var paddingRight = getBoundsPaddingByKey(readableMap, metrics.
|
|
167
|
-
var paddingBottom = getBoundsPaddingByKey(readableMap, metrics.
|
|
168
|
-
var paddingLeft = getBoundsPaddingByKey(readableMap, metrics.
|
|
169
|
+
var paddingTop = getBoundsPaddingByKey(readableMap, metrics.density, "paddingTop")
|
|
170
|
+
var paddingRight = getBoundsPaddingByKey(readableMap, metrics.density, "paddingRight")
|
|
171
|
+
var paddingBottom = getBoundsPaddingByKey(readableMap, metrics.density, "paddingBottom")
|
|
172
|
+
var paddingLeft = getBoundsPaddingByKey(readableMap, metrics.density, "paddingLeft")
|
|
169
173
|
|
|
170
174
|
val collection = FeatureCollection.fromJson(readableMap.getString("bounds")!!)
|
|
171
175
|
stop.setBounds(
|
|
@@ -213,9 +217,9 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
|
|
|
213
217
|
return intArrayOf(resultLeft, resultTop, resultRight, resultBottom)
|
|
214
218
|
}
|
|
215
219
|
|
|
216
|
-
private fun getBoundsPaddingByKey(map: ReadableMap,
|
|
220
|
+
private fun getBoundsPaddingByKey(map: ReadableMap, density: Float, key: String): Int? {
|
|
217
221
|
if (map.hasKey(key)) {
|
|
218
|
-
return (map.getInt(key) *
|
|
222
|
+
return (map.getInt(key) * density).toInt()
|
|
219
223
|
} else {
|
|
220
224
|
return null;
|
|
221
225
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt
CHANGED
|
@@ -7,6 +7,9 @@ import com.mapbox.rctmgl.components.AbstractMapFeature
|
|
|
7
7
|
import com.mapbox.rctmgl.utils.ImageEntry
|
|
8
8
|
import android.graphics.drawable.BitmapDrawable
|
|
9
9
|
import androidx.core.content.res.ResourcesCompat
|
|
10
|
+
import com.mapbox.bindgen.Expected
|
|
11
|
+
import com.mapbox.bindgen.None
|
|
12
|
+
import com.mapbox.maps.Image
|
|
10
13
|
import com.mapbox.maps.MapboxMap
|
|
11
14
|
import com.mapbox.maps.Style
|
|
12
15
|
import com.mapbox.rctmgl.R
|
|
@@ -15,11 +18,27 @@ import com.mapbox.rctmgl.components.images.RCTMGLImages
|
|
|
15
18
|
import com.mapbox.rctmgl.events.ImageMissingEvent
|
|
16
19
|
import com.mapbox.rctmgl.utils.BitmapUtils
|
|
17
20
|
import com.mapbox.rctmgl.utils.DownloadMapImageTask
|
|
21
|
+
import java.nio.ByteBuffer
|
|
18
22
|
import java.util.AbstractMap
|
|
19
23
|
import java.util.ArrayList
|
|
20
24
|
import java.util.HashMap
|
|
21
25
|
import java.util.HashSet
|
|
22
26
|
|
|
27
|
+
fun Style.addBitmapImage(imageId: String, bitmap: Bitmap) : Expected<String, None> {
|
|
28
|
+
val byteBuffer = ByteBuffer.allocate(bitmap.byteCount)
|
|
29
|
+
bitmap.copyPixelsToBuffer(byteBuffer)
|
|
30
|
+
val sdf = false
|
|
31
|
+
return this.addStyleImage(
|
|
32
|
+
imageId,
|
|
33
|
+
(1.0/((160.0/bitmap.density))).toFloat(),
|
|
34
|
+
Image(bitmap.width, bitmap.height, byteBuffer.array()),
|
|
35
|
+
sdf,
|
|
36
|
+
listOf(),
|
|
37
|
+
listOf(),
|
|
38
|
+
null
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
23
42
|
class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager) : AbstractMapFeature(context) {
|
|
24
43
|
var mCurrentImages: MutableSet<String?>
|
|
25
44
|
private var mImages: MutableMap<String, ImageEntry>?
|
|
@@ -151,7 +170,8 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
|
|
|
151
170
|
if (style == null || imageEntries == null) return
|
|
152
171
|
for ((key, value) in imageEntries) {
|
|
153
172
|
if (key != null && !hasImage(key, map)) {
|
|
154
|
-
|
|
173
|
+
val bitmap = value!!.bitmap
|
|
174
|
+
style.addBitmapImage(key, bitmap)
|
|
155
175
|
mCurrentImages.add(key)
|
|
156
176
|
}
|
|
157
177
|
}
|
|
@@ -171,7 +191,7 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
|
|
|
171
191
|
// See also: https://github.com/mapbox/mapbox-gl-native/pull/14253#issuecomment-478827792
|
|
172
192
|
for (imageEntry in imageEntries) {
|
|
173
193
|
if (!hasImage(imageEntry.key, map)) {
|
|
174
|
-
mImagePlaceholder?.let { style.
|
|
194
|
+
mImagePlaceholder?.let { style.addBitmapImage(imageEntry.key, it) }
|
|
175
195
|
missingImages.add(imageEntry)
|
|
176
196
|
mCurrentImages.add(imageEntry.key)
|
|
177
197
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt
CHANGED
|
@@ -38,6 +38,7 @@ import com.mapbox.maps.plugin.delegates.listeners.*
|
|
|
38
38
|
import com.mapbox.maps.plugin.gestures.*
|
|
39
39
|
import com.mapbox.maps.plugin.logo.generated.LogoSettings
|
|
40
40
|
import com.mapbox.maps.plugin.logo.logo
|
|
41
|
+
import com.mapbox.maps.viewannotation.ViewAnnotationManager
|
|
41
42
|
import com.mapbox.rctmgl.R
|
|
42
43
|
import com.mapbox.rctmgl.components.AbstractMapFeature
|
|
43
44
|
import com.mapbox.rctmgl.components.annotation.RCTMGLMarkerView
|
|
@@ -70,6 +71,14 @@ interface RCTMGLMapViewLifecycleOwner : LifecycleOwner {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapViewManager /*, MapboxMapOptions options*/) : MapView(mContext), OnMapClickListener, OnMapLongClickListener {
|
|
74
|
+
/**
|
|
75
|
+
* `PointAnnotations` are rendered to a canvas, but the React Native `Image` component is
|
|
76
|
+
* implemented on top of Fresco (https://frescolib.org), which does not load images for
|
|
77
|
+
* views not attached to the window. This provides an offscreen view where views can
|
|
78
|
+
* be rendered to the canvas before being added as annotations.
|
|
79
|
+
*/
|
|
80
|
+
public var offscreenAnnotationViewContainer: ViewGroup? = null
|
|
81
|
+
|
|
73
82
|
private val mSources: MutableMap<String, RCTSource<*>>
|
|
74
83
|
private val mImages: MutableList<RCTMGLImages>
|
|
75
84
|
private var mPointAnnotationManager: PointAnnotationManager? = null
|
|
@@ -87,7 +96,6 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
87
96
|
var savedStyle: Style? = null
|
|
88
97
|
private set
|
|
89
98
|
private val mHandledMapChangedEvents: HashSet<String>? = null
|
|
90
|
-
private var mOffscreenAnnotationViewContainer: ViewGroup? = null
|
|
91
99
|
private var mAnnotationClicked = false
|
|
92
100
|
private var mAnnotationDragged = false
|
|
93
101
|
private var mLocationComponentManager: LocationComponentManager? = null
|
|
@@ -229,7 +237,6 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
229
237
|
mPointAnnotations[annotation.iD.toString()] = annotation
|
|
230
238
|
feature = childView
|
|
231
239
|
} else if (childView is RCTMGLMarkerView) {
|
|
232
|
-
val marker = childView
|
|
233
240
|
feature = childView
|
|
234
241
|
} else if (childView is RCTMGLCamera) {
|
|
235
242
|
mCamera = childView
|
|
@@ -630,23 +637,6 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
630
637
|
)
|
|
631
638
|
}
|
|
632
639
|
|
|
633
|
-
/**
|
|
634
|
-
* PointAnnotations are rendered to a canvas, but react native Image component is
|
|
635
|
-
* implemented on top of Fresco, and fresco will not load images when their view is
|
|
636
|
-
* not attached to the window. So we'll have an offscreen view where we add those views
|
|
637
|
-
* so they can rendered full to canvas.
|
|
638
|
-
*/
|
|
639
|
-
fun offscreenAnnotationViewContainer(): ViewGroup {
|
|
640
|
-
if (mOffscreenAnnotationViewContainer == null) {
|
|
641
|
-
mOffscreenAnnotationViewContainer = FrameLayout(context)
|
|
642
|
-
val flParams = LayoutParams(0, 0)
|
|
643
|
-
flParams.setMargins(-10000, -10000, -10000, -10000)
|
|
644
|
-
(mOffscreenAnnotationViewContainer as FrameLayout).setLayoutParams(flParams)
|
|
645
|
-
addView(mOffscreenAnnotationViewContainer)
|
|
646
|
-
}
|
|
647
|
-
return mOffscreenAnnotationViewContainer!!
|
|
648
|
-
}
|
|
649
|
-
|
|
650
640
|
val locationComponentManager: LocationComponentManager
|
|
651
641
|
get() {
|
|
652
642
|
if (mLocationComponentManager == null) {
|
|
@@ -839,11 +829,19 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
839
829
|
}
|
|
840
830
|
|
|
841
831
|
init {
|
|
832
|
+
offscreenAnnotationViewContainer = FrameLayout(getContext())
|
|
833
|
+
val p = FrameLayout.LayoutParams(0, 0)
|
|
834
|
+
p.setMargins(-10000, -10000, -10000, -10000)
|
|
835
|
+
offscreenAnnotationViewContainer?.setLayoutParams(p)
|
|
836
|
+
addView(offscreenAnnotationViewContainer)
|
|
837
|
+
|
|
842
838
|
mMap = getMapboxMap()
|
|
843
839
|
mSources = HashMap()
|
|
844
840
|
mImages = ArrayList()
|
|
845
841
|
mPointAnnotations = HashMap()
|
|
842
|
+
|
|
846
843
|
onMapReady(mMap)
|
|
844
|
+
|
|
847
845
|
val _this = this
|
|
848
846
|
mMap.addOnMapLoadedListener(OnMapLoadedListener { (begin, end) -> _this.handleMapChangedEvent(EventTypes.DID_FINISH_LOADING_MAP) })
|
|
849
847
|
mMap.addOnStyleImageMissingListener(OnStyleImageMissingListener { (begin, end, id) ->
|
|
@@ -8,7 +8,7 @@ import com.mapbox.rctmgl.utils.DownloadMapImageTask
|
|
|
8
8
|
import java.util.AbstractMap
|
|
9
9
|
import java.util.ArrayList
|
|
10
10
|
|
|
11
|
-
class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap
|
|
11
|
+
class RCTMGLStyle(private val mContext: Context, reactStyle: ReadableMap?, map: MapboxMap) {
|
|
12
12
|
private val mReactStyle: ReadableMap?
|
|
13
13
|
private val mMap: MapboxMap
|
|
14
14
|
val allStyleKeys: List<String>
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java
CHANGED
|
@@ -132,7 +132,7 @@ public class RCTMGLSnapshotModule extends ReactContextBaseJavaModule {
|
|
|
132
132
|
(int) jsOptions.getDouble("height")
|
|
133
133
|
)
|
|
134
134
|
);
|
|
135
|
-
builder.pixelRatio(Float.valueOf(mContext.getResources().getDisplayMetrics().
|
|
135
|
+
builder.pixelRatio(Float.valueOf(mContext.getResources().getDisplayMetrics().density).intValue());
|
|
136
136
|
|
|
137
137
|
builder.resourceOptions(new ResourceOptions.Builder().accessToken(RCTMGLModule.getAccessToken(mContext)).build());
|
|
138
138
|
return builder.build();
|
|
@@ -21,6 +21,7 @@ import com.facebook.imagepipeline.image.CloseableImage
|
|
|
21
21
|
import com.facebook.imagepipeline.image.CloseableStaticBitmap
|
|
22
22
|
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
|
23
23
|
import com.facebook.react.views.imagehelper.ImageSource
|
|
24
|
+
import com.mapbox.rctmgl.components.images.addBitmapImage
|
|
24
25
|
import java.io.File
|
|
25
26
|
import java.lang.ref.WeakReference
|
|
26
27
|
import java.util.AbstractMap
|
|
@@ -120,7 +121,7 @@ class DownloadMapImageTask(context: Context, map: MapboxMap, callback: OnAllImag
|
|
|
120
121
|
val bitmapImages = HashMap<String, Bitmap>()
|
|
121
122
|
for ((key, value) in images) {
|
|
122
123
|
bitmapImages[key] = value
|
|
123
|
-
style.
|
|
124
|
+
style.addBitmapImage(key, value)
|
|
124
125
|
}
|
|
125
126
|
// style.addImages(bitmapImages);
|
|
126
127
|
}
|