Skip to content

Commit c9fed9d

Browse files
authored
Merge pull request #1977 from rnmapbox/main
Sync with `main`
2 parents e68e1d4 + a774f5f commit c9fed9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1079
-932
lines changed

.github/label-actions.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@
1919
:thinking: @{issue-author}, closing the issue for lack of activity, if the issue still persist, pls open a new one with steps to reproduce on recent versions
2020
# Close the issue
2121
close: true
22+
"Needs: Project setup instructions":
23+
comment: >
24+
@{issue-author}, sorry for us to look into project setup issues, we require steps to reproduce from `react-native init ...`. If you cannot reproduce starting with a blank project, then compare your setup with a blank working one.
25+
close: true
2226

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ Please add unreleased changes in the following style:
55
PR Title ([#123](link to my pr))
66
```
77

8-
Implement clustering properties to ShapeSource ([#1745](https://github.com/react-native-mapbox-gl/maps/pull/1745))
9-
10-
### UNRELEASED/10.0.0-beta.0
8+
### UNRELEASED/10.0.0-beta.10
119

1210
#### Breaking changes:
1311

1412
The setup was changed - see install instructions for more details. In a nuthsell:
1513
* On both android/ios to select mapbox implementation use `RNMapboxMapsImpl`/`$RNMapboxMapsImpl` variable which can be one of (`maplibre`,`mapbox`(aka v10),`mapbox-gl`)
14+
* Default implementation is `maplibre` as it requires not further setup. *WARNING* using mapbox styles from `maplibre` has different pricing than mapbox native sdk-s.
1615
* On Podfile `$RNMBGL.(pre|post)_install` was changed `$RNMapboxMaps.(pre|post)_install`
1716
* Package name was changed from `@react-native-mapbox-gl/maps` to `@rnmapbox/maps`. If you just testing with the v10 version you can use something like [babel-plugin-transform-rename-import](https://www.npmjs.com/package/babel-plugin-transform-rename-import) to keep using the old imports for a while.
1817

18+
* `MapboxGL.setAccessToken` now requires `MapboxGL.setWellKnownTileServer` on maplibre.
19+
20+
1921
#### Changes:
2022

23+
- Implement clustering properties to ShapeSource ([#1745](https://github.com/react-native-mapbox-gl/maps/pull/1745))
2124
- Initial Mapbox V10 support ([#1750](https://github.com/rnmapbox/maps/pull/1750))
2225
- Updated MapLibre on Android to 9.5.2 ([#1780](https://github.com/rnmapbox/maps/pull/1780))
2326

android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ public void onDidFinishRenderingMap(boolean fully) {
751751
for (Pair<Integer, ReadableArray> preRenderMethod : mPreRenderMethods) {
752752
Integer methodID = preRenderMethod.first;
753753
ReadableArray args = preRenderMethod.second;
754+
754755
mManager.receiveCommand(this, methodID, args);
755756
}
756757
mPreRenderMethods.clear();

android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ public Map<String, Integer> getCommandsMap() {
246246

247247
@Override
248248
public void receiveCommand(RCTMGLMapView mapView, int commandID, @Nullable ReadableArray args) {
249+
String callbackID = args.getString(0);
249250
// allows method calls to work with componentDidMount
250251
MapboxMap mapboxMap = mapView.getMapboxMap();
251252
if (mapboxMap == null) {
@@ -256,41 +257,42 @@ public void receiveCommand(RCTMGLMapView mapView, int commandID, @Nullable Reada
256257
switch (commandID) {
257258
case METHOD_QUERY_FEATURES_POINT:
258259
mapView.queryRenderedFeaturesAtPoint(
259-
args.getString(0),
260+
callbackID,
260261
ConvertUtils.toPointF(args.getArray(1)),
261262
ExpressionParser.from(args.getArray(2)),
262263
ConvertUtils.toStringList(args.getArray(3)));
263264
break;
264265
case METHOD_QUERY_FEATURES_RECT:
265266
mapView.queryRenderedFeaturesInRect(
266-
args.getString(0),
267+
callbackID,
267268
ConvertUtils.toRectF(args.getArray(1)),
268269
ExpressionParser.from(args.getArray(2)),
269270
ConvertUtils.toStringList(args.getArray(3)));
270271
break;
271272
case METHOD_VISIBLE_BOUNDS:
272-
mapView.getVisibleBounds(args.getString(0));
273+
mapView.getVisibleBounds(callbackID);
273274
break;
274275
case METHOD_GET_POINT_IN_VIEW:
275-
mapView.getPointInView(args.getString(0), GeoJSONUtils.toLatLng(args.getArray(1)));
276+
mapView.getPointInView(callbackID, GeoJSONUtils.toLatLng(args.getArray(1)));
276277
break;
277278
case METHOD_GET_COORDINATE_FROM_VIEW:
278-
mapView.getCoordinateFromView(args.getString(0), ConvertUtils.toPointF(args.getArray(1)));
279+
mapView.getCoordinateFromView(callbackID, ConvertUtils.toPointF(args.getArray(1)));
279280
break;
280281
case METHOD_TAKE_SNAP:
281-
mapView.takeSnap(args.getString(0), args.getBoolean(1));
282+
mapView.takeSnap(callbackID, args.getBoolean(1));
282283
break;
283284
case METHOD_GET_ZOOM:
284-
mapView.getZoom(args.getString(0));
285+
mapView.getZoom(callbackID);
285286
break;
286287
case METHOD_GET_CENTER:
287-
mapView.getCenter(args.getString(0));
288+
mapView.getCenter(callbackID);
288289
break;
289290
case METHOD_SET_HANDLED_MAP_EVENTS:
290291
if(args != null) {
292+
ReadableArray events = args.getArray(1);
291293
ArrayList<String> eventsArray = new ArrayList<>();
292-
for (int i = 1; i < args.size(); i++) {
293-
eventsArray.add(args.getString(i));
294+
for (int i = 0; i < events.size(); i++) {
295+
eventsArray.add(events.getString(i));
294296
}
295297
mapView.setHandledMapChangedEvents(eventsArray);
296298
}

android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/modules/RCTMGLModule.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,16 @@ public Map<String, Object> getConstants() {
249249
Map<String, String> locationModuleCallbackNames = new HashMap<>();
250250
locationModuleCallbackNames.put("Update", RCTMGLLocationModule.LOCATION_UPDATE);
251251

252+
// tileServer
253+
Map<String, String> tileServers = InstanceManagerImpl.getTileServers();
254+
255+
// implementation
256+
Map<String, String> implementation = new HashMap<>();
257+
implementation.put("Library", InstanceManagerImpl.getLibraryName());
258+
252259
return MapBuilder.<String, Object>builder()
260+
.put("TileServers", tileServers)
261+
.put("Implementation", implementation)
253262
.put("StyleURL", styleURLS)
254263
.put("EventTypes", eventTypes)
255264
.put("UserTrackingModes", userTrackingModes)
@@ -284,6 +293,11 @@ public Map<String, Object> getConstants() {
284293
.build();
285294
}
286295

296+
@ReactMethod
297+
public void setWellKnownTileServer(final String tileServer) {
298+
InstanceManagerImpl.setWellKnownTileServer(tileServer);
299+
}
300+
287301
@ReactMethod
288302
public void setAccessToken(final String accessToken) {
289303
mReactContext.runOnUiQueueThread(new Runnable() {

android/rctmgl/src/main/java-mapboxgl/mapbox/com/mapbox/rctmgl/impl/InstanceManagerImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,24 @@ public static void getInstance(Context context, String accessToken) {
88
Mapbox.getInstance(context, accessToken);
99
}
1010

11+
public static void setWellKnownTileServer(String wellKnownTileServer) {
12+
if (wellKnownTileServer != "mapbox") {
13+
Logger.w("InstanceManagerImpl", "setWellKnownTileServer: only mapbox is supported");
14+
return;
15+
}
16+
}
17+
1118
public static String getAccessToken() {
1219
return Mapbox.getAccessToken();
1320
}
21+
22+
public static String getLibraryName() {
23+
return "mapbox-gl";
24+
}
25+
26+
public static Map<String,String> getTileServers() {
27+
HashMap<String, String> result = new HashMap();
28+
result.put("Mapbox", "mapbox");
29+
return result;
30+
}
1431
}
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
11
package com.mapbox.rctmgl.impl;
22

33
import android.content.Context;
4+
45
import com.mapbox.mapboxsdk.Mapbox;
56
import com.mapbox.mapboxsdk.WellKnownTileServer;
7+
import com.mapbox.mapboxsdk.log.Logger;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
611

712
public class InstanceManagerImpl {
813
public static void getInstance(Context context, String accessToken) {
9-
Mapbox.getInstance(context, accessToken, WellKnownTileServer.Mapbox);
14+
if (wellKnownTileServer == null) {
15+
Logger.w("InstanceManagerImpl", "setAccessToken requires setWellKnownTileServer for MapLibre, see setWellKnownTileServer docs for implications");
16+
wellKnownTileServer = WellKnownTileServer.MapLibre.name();
17+
}
18+
Mapbox.getInstance(context, accessToken, WellKnownTileServer.valueOf(wellKnownTileServer) );
19+
}
20+
21+
public static Map<String,String> getTileServers() {
22+
HashMap<String, String> result = new HashMap();
23+
result.put("Mapbox", WellKnownTileServer.Mapbox.name());
24+
result.put("MapLibre", WellKnownTileServer.MapLibre.name());
25+
result.put("MapTiler", WellKnownTileServer.MapTiler.name());
26+
return result;
27+
}
28+
29+
static String wellKnownTileServer = null;
30+
31+
public static void setWellKnownTileServer(String wellKnownTileServer) {
32+
InstanceManagerImpl.wellKnownTileServer = wellKnownTileServer;
1033
}
1134

1235
public static String getAccessToken() {
13-
return null;
36+
return Mapbox.getApiKey();
37+
}
38+
39+
public static String getLibraryName() {
40+
return "maplibre";
1441
}
1542
}

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
179179
if (missingImages.size > 0) {
180180
val task = DownloadMapImageTask(context, map, null)
181181
val params = missingImages.toTypedArray()
182-
for (param in params) {
183-
task.execute(param)
184-
}
185-
186-
182+
task.execute(*params)
187183
}
188184
}
189185

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@ import com.mapbox.geojson.Feature
1515
import com.mapbox.geojson.Point
1616
import com.mapbox.maps.*
1717
import com.mapbox.maps.extension.observable.eventdata.MapLoadingErrorEventData
18+
import com.mapbox.maps.extension.observable.eventdata.StyleImageMissingEventData
1819
import com.mapbox.maps.extension.style.layers.Layer
1920
import com.mapbox.maps.extension.style.layers.generated.*
2021
import com.mapbox.maps.extension.style.layers.getLayer
21-
import com.mapbox.maps.extension.style.utils.unwrap
2222
import com.mapbox.maps.extension.style.layers.properties.generated.Visibility
2323
import com.mapbox.maps.plugin.annotation.annotations
2424
import com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationClickListener
2525
import com.mapbox.maps.plugin.annotation.generated.PointAnnotation
2626
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
2727
import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
28-
import com.mapbox.maps.plugin.delegates.listeners.OnCameraChangeListener
29-
import com.mapbox.maps.plugin.delegates.listeners.OnMapIdleListener
30-
import com.mapbox.maps.plugin.delegates.listeners.OnMapLoadErrorListener
31-
import com.mapbox.maps.plugin.delegates.listeners.OnMapLoadedListener
28+
import com.mapbox.maps.plugin.delegates.listeners.*
3229
import com.mapbox.maps.plugin.gestures.*
3330
import com.mapbox.rctmgl.R
3431
import com.mapbox.rctmgl.components.AbstractMapFeature
@@ -363,7 +360,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
363360
ScreenCoordinate(screenPoint.x + halfWidth,
364361
screenPoint.y + halfHeight)
365362
)
366-
getMapboxMap().queryRenderedFeatures(screenBox,
363+
getMapboxMap().queryRenderedFeatures(RenderedQueryGeometry(screenBox),
367364
RenderedQueryOptions(
368365
source.layerIDs,
369366
null
@@ -379,7 +376,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
379376
hitTouchableSources.add(source)
380377
}
381378
} else {
382-
Logger.e("handleTapInSources", features.error)
379+
Logger.e("handleTapInSources", features.error ?: "n/a")
383380
}
384381
handleTapInSources(sources, screenPoint, hits, hitTouchableSources, handleTap)
385382
}
@@ -755,5 +752,15 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
755752
onMapReady(mMap)
756753
val _this = this
757754
mMap.addOnMapLoadedListener(OnMapLoadedListener { (begin, end) -> _this.handleMapChangedEvent(EventTypes.DID_FINISH_LOADING_MAP) })
755+
mMap.addOnStyleImageMissingListener(OnStyleImageMissingListener { (begin, end, id) ->
756+
for (images in mImages) {
757+
if (images.addMissingImageToStyle(id, mMap)) {
758+
return@OnStyleImageMissingListener
759+
}
760+
}
761+
for (images in mImages) {
762+
images.sendImageMissingEvent(id, mMap)
763+
}
764+
})
758765
}
759766
}

android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyle.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)