Skip to content

Commit

Permalink
Merge pull request #1 from react-native-mapbox-gl/master
Browse files Browse the repository at this point in the history
Updating with master
  • Loading branch information
dorthwein authored Jul 10, 2019
2 parents e8e35bc + 27520b7 commit 410e504
Show file tree
Hide file tree
Showing 87 changed files with 2,262 additions and 450 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ reactnativemapboxgl.iml
coverage
.project
*.core.prefs
*.iml

# Buck
.buckd
Expand All @@ -58,3 +59,6 @@ buck-out
/ReactAndroid/src/main/jni/prebuilt/lib/x86/
/ReactAndroid/src/main/gen

# VSCode
.vscode/
.classpath
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Breaking changes:

* iOS mapbox libraries updated to [5.0.0](https://github.com/mapbox/mapbox-gl-native/releases/tag/ios-v5.0.0) android libraries updated to [8.0.0](https://github.com/mapbox/mapbox-gl-native/releases/tag/android-v8.0.0)
* iOS mapbox libraries updated to [5.1.0](https://github.com/mapbox/mapbox-gl-native/releases/tag/ios-v5.1.0) android libraries updated to [8.1.0](https://github.com/mapbox/mapbox-gl-native/releases/tag/android-v8.1.0)
* `StyleSheet.create` removed.
Mapbox styles are now just a map no need for `StyleSheet.create`.
`StylesSheet.identity` also removed, use expressions array instead:
Expand Down Expand Up @@ -78,4 +78,18 @@ Mapbox styles are now just a map no need for `StyleSheet.create`.
* followUserMode is now a string with ('normal','compass','course'), and UserTrackingModes enum is deprecated
* MapView#onUserTrackingModeChange is now Camera#onUserTrackingModeChange and payload contains followUserMode and followUserLocation.

* ShapeSource#images was depreacted, use Images#images instead.
```jsx
<MapView
...
>
...
<Images images={{pin, dot}} />
...
<ShapeSource ... >
<SymbolLayer ...>
</ShapeSource>
</MapView>
```

* TODO document all changes
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ npm install @react-native-mapbox-gl/maps --save
* [Callout](/docs/Callout.md)
* [Camera](docs/Camera.md)
* [UserLocation](docs/UserLocation.md)
* [Images](docs/Images.md)

### Sources
* [VectorSource](/docs/VectorSource.md)
Expand All @@ -62,6 +63,7 @@ npm install @react-native-mapbox-gl/maps --save
* [LineLayer](/docs/LineLayer.md)
* [RasterLayer](/docs/RasterLayer.md)
* [SymbolLayer](/docs/SymbolLayer.md)
* [HeatmapLayer](/docs/HeatmapLayer.md)

### Offline
* [OfflineManager](/docs/OfflineManager.md)
Expand Down
6 changes: 6 additions & 0 deletions __tests__/__mocks__/react-native-mapbox-gl.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,9 @@ NativeModules.MGLSnapshotModule = {
return Promise.resolve('file://test.png');
},
};

NativeModules.MGLLocationModule = {
getLastKnownLocation: jest.fn(),
start: jest.fn(),
pause: jest.fn(),
};
2 changes: 2 additions & 0 deletions __tests__/interface.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Public Interface', () => {
'FillLayer',
'FillExtrusionLayer',
'CircleLayer',
'HeatmapLayer',
'LineLayer',
'SymbolLayer',
'BackgroundLayer',
Expand All @@ -33,6 +34,7 @@ describe('Public Interface', () => {
'ShapeSource',
'RasterSource',
'ImageSource',
'Images',

// constants
'UserTrackingModes',
Expand Down
34 changes: 34 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven { url "https://jitpack.io" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
6 changes: 3 additions & 3 deletions android/rctmgl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
// Mapbox SDK

implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.8.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.0.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.1.0'

// Dependencies
implementation "com.android.support:support-vector-drawable:${safeExtGet('supportLibVersion', '28.0.0')}"
Expand All @@ -41,7 +41,7 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttpVersion', '3.12.1')}"

// Mapbox plugins
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.9.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v7:0.2.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v8:0.10.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v8:0.3.0'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.8.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.mapbox.rctmgl.components.styles.layers.RCTMGLCircleLayerManager;
import com.mapbox.rctmgl.components.styles.layers.RCTMGLFillExtrusionLayerManager;
import com.mapbox.rctmgl.components.styles.layers.RCTMGLFillLayerManager;
import com.mapbox.rctmgl.components.styles.layers.RCTMGLHeatmapLayerManager;
import com.mapbox.rctmgl.components.styles.layers.RCTMGLLineLayerManager;
import com.mapbox.rctmgl.components.styles.layers.RCTMGLRasterLayerManager;
import com.mapbox.rctmgl.components.styles.layers.RCTMGLSymbolLayerManager;
Expand Down Expand Up @@ -76,6 +77,7 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactApplica
// layers
managers.add(new RCTMGLFillLayerManager());
managers.add(new RCTMGLFillExtrusionLayerManager());
managers.add(new RCTMGLHeatmapLayerManager());
managers.add(new RCTMGLLineLayerManager());
managers.add(new RCTMGLCircleLayerManager());
managers.add(new RCTMGLSymbolLayerManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

public class AbstractEvent extends Event<AbstractEvent> {
private String mEventName;
private final boolean mCanCoalesce;
private WritableMap mEvent;

public AbstractEvent(int viewId, String eventName, @Nullable WritableMap event) {
public AbstractEvent(int viewId, String eventName, boolean canCoalesce, @Nullable WritableMap event) {
super(viewId);
mEventName = eventName;
mCanCoalesce = canCoalesce;
mEvent = event;
}

Expand All @@ -25,4 +27,9 @@ public String getEventName() {
public void dispatch(RCTEventEmitter rctEventEmitter) {
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mEvent);
}

@Override
public boolean canCoalesce() {
return mCanCoalesce;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public void handleEvent(IEvent event) {
}

mRateLimitedEvents.put(eventCacheKey, System.currentTimeMillis());
mEventDispatcher.dispatchEvent(new AbstractEvent(event.getID(), event.getKey(), event.toJSON()));

RCTEventEmitter emitter = EventEmitter.getViewEmitter(mRCTAppContext);
if (emitter != null) {
emitter.receiveEvent(event.getID(), event.getKey(), event.toJSON());
}
mEventDispatcher.dispatchEvent(new AbstractEvent(event.getID(), event.getKey(), event.canCoalesce(), event.toJSON()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public class CameraStop {
private int mBoundsPaddingLeft = 0;
private int mBoundsPaddingRight = 0;
private int mBoundsPaddingBottom = 0;
private int mBooundsPaddingTop = 0;
private int mBoundsPaddingTop = 0;

private int mMode = CameraMode.EASE;
private int mDuration = 2000;
private MapboxMap.CancelableCallback mCallback;

public CameraStop() {}
public CameraStop() {
}

public void setBearing(double bearing) {
mBearing = bearing;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void setBounds(LatLngBounds bounds, int paddingLeft, int paddingRight, in
mBounds = bounds;
mBoundsPaddingLeft = paddingLeft;
mBoundsPaddingRight = paddingRight;
mBooundsPaddingTop = paddingTop;
mBoundsPaddingTop = paddingTop;
mBoundsPaddingBottom = paddingBottom;
}

Expand All @@ -75,13 +76,8 @@ public void setMode(@CameraMode.Mode int mode) {
}

public CameraUpdateItem toCameraUpdate(MapboxMap map) {
if (mBounds != null) {
CameraUpdate update = CameraUpdateFactory.newLatLngBounds(mBounds, mBoundsPaddingLeft,
mBooundsPaddingTop, mBoundsPaddingRight, mBoundsPaddingBottom);
return new CameraUpdateItem(map, update, mDuration, mCallback, CameraMode.FLIGHT);
}

CameraPosition.Builder builder = new CameraPosition.Builder();
CameraPosition currentCamera = map.getCameraPosition();
CameraPosition.Builder builder = new CameraPosition.Builder(currentCamera);

if (mBearing != null) {
builder.bearing(mBearing);
Expand All @@ -91,12 +87,34 @@ public CameraUpdateItem toCameraUpdate(MapboxMap map) {
builder.tilt(mTilt);
}

if (mZoom != null) {
builder.zoom(mZoom);
}

if (mLatLng != null) {
builder.target(mLatLng);
} else if (mBounds != null) {
double tilt = mTilt != null ? mTilt : currentCamera.tilt;
double bearing = mBearing != null ? mBearing : currentCamera.bearing;

// Adding map padding to the camera padding which is the same behavior as
// mapbox native does on iOS
int[] mapPadding = map.getPadding();
int paddingLeft = mapPadding[0] + mBoundsPaddingLeft;
int paddingTop = mapPadding[1] + mBoundsPaddingTop;
int paddingRight = mapPadding[2] + mBoundsPaddingRight;
int paddingBottom = mapPadding[3] + mBoundsPaddingBottom;

int[] cameraPadding = {paddingLeft, paddingTop, paddingRight, paddingBottom};
CameraPosition boundsCamera = map.getCameraForLatLngBounds(mBounds, cameraPadding, bearing, tilt);
if (boundsCamera != null) {
builder.target(boundsCamera.target);
builder.zoom(boundsCamera.zoom);
} else {
CameraUpdate update = CameraUpdateFactory.newLatLngBounds(mBounds, paddingLeft,
paddingTop, paddingRight, paddingBottom);
return new CameraUpdateItem(map, update, mDuration, mCallback, mMode);
}
}

if (mZoom != null) {
builder.zoom(mZoom);
}

return new CameraUpdateItem(map, CameraUpdateFactory.newCameraPosition(builder.build()), mDuration, mCallback, mMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.support.annotation.NonNull;

import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.rctmgl.components.camera.constants.CameraMode;

Expand Down Expand Up @@ -63,12 +64,20 @@ public void onFinish() {
return;
}

if (mCameraMode == CameraMode.FLIGHT && mDuration > 0) {
map.animateCamera(mCameraUpdate, mDuration, callback);
} else if (mCameraMode == CameraMode.EASE) {
map.easeCamera(mCameraUpdate, mDuration, callback);
} else {
// animateCamera / easeCamera only allows positive duration
if (mDuration == 0 || mCameraMode == CameraMode.NONE) {
map.moveCamera(mCameraUpdate, callback);
return;
}

// On iOS a duration of -1 means default or dynamic duration (based on flight-path length)
// On Android we can fallback to Mapbox's default duration as there is no such API
int duration = mDuration < 0 ? MapboxConstants.ANIMATION_DURATION : mDuration;

if (mCameraMode == CameraMode.FLIGHT) {
map.animateCamera(mCameraUpdate, duration, callback);
} else if (mCameraMode == CameraMode.EASE) {
map.easeCamera(mCameraUpdate, duration, callback);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
// import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.rctmgl.components.AbstractMapFeature;
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView;
import com.mapbox.rctmgl.events.IEvent;
import com.mapbox.rctmgl.events.MapUserTrackingModeEvent;
import com.mapbox.rctmgl.events.MapChangeEvent;
import com.mapbox.rctmgl.location.LocationManager;
import com.mapbox.rctmgl.location.UserLocation;
import com.mapbox.rctmgl.location.UserLocationLayerConstants;
import com.mapbox.rctmgl.location.UserLocationVerticalAlignment;
import com.mapbox.rctmgl.location.UserTrackingMode;
import com.mapbox.rctmgl.location.UserTrackingState;
Expand All @@ -52,6 +48,7 @@ public class RCTMGLCamera extends AbstractMapFeature {

private boolean hasSentFirstRegion = false;

private CameraStop mDefaultStop;
private CameraStop mCameraStop;
private CameraUpdateQueue mCameraUpdateQueue;

Expand Down Expand Up @@ -133,10 +130,11 @@ public RCTMGLCamera(Context context, RCTMGLCameraManager manager) {
public void addToMap(RCTMGLMapView mapView) {
mMapView = mapView;

setInitialCamera();
updateMaxMinZoomLevel();
if (mCameraStop != null) {
updateCamera();
}
updateMaxMinZoomLevel();

if (mShowUserLocation || mFollowUserLocation) {
enableLocation();
Expand All @@ -157,6 +155,10 @@ public void setStop(CameraStop stop) {
}
}

public void setDefaultStop(CameraStop stop) {
mDefaultStop = stop;
}

private void updateMaxMinZoomLevel() {
MapboxMap map = getMapboxMap();
if (map != null) {
Expand All @@ -169,6 +171,15 @@ private void updateMaxMinZoomLevel() {
}
}

private void setInitialCamera() {
if (mDefaultStop != null) {
mDefaultStop.setDuration(0);
mDefaultStop.setMode(com.mapbox.rctmgl.components.camera.constants.CameraMode.NONE);
CameraUpdateItem item = mDefaultStop.toCameraUpdate(mMapView.getMapboxMap());
item.run();
}
}

private void updateCamera() {
mCameraUpdateQueue.offer(mCameraStop);
mCameraUpdateQueue.execute(mMapView.getMapboxMap());
Expand Down Expand Up @@ -235,7 +246,7 @@ private void sendUserLocationUpdateEvent(Location location) {
if(location == null){
return;
}
IEvent event = new MapChangeEvent(this, makeLocationChangePayload(location), EventTypes.USER_LOCATION_UPDATED);
IEvent event = new MapChangeEvent(this, EventTypes.USER_LOCATION_UPDATED, makeLocationChangePayload(location));
mManager.handleEvent(event);
}

Expand Down
Loading

0 comments on commit 410e504

Please sign in to comment.