diff --git a/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.java b/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.java index f872fa37..0f4ccf69 100644 --- a/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.java +++ b/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.java @@ -115,7 +115,7 @@ public class MLRNMapView extends MapView implements OnMapReadyCallback, MapLibre private LocalizationPlugin mLocalizationPlugin; - private String mStyleURL; + private String mMapStyle; private Integer mPreferredFramesPerSecond; private boolean mLocalizeLabels; @@ -169,7 +169,7 @@ public MLRNMapView(Context context, MLRNMapViewManager manager, MapLibreMapOptio mHandler = new Handler(); - mStyleURL = MLRNModule.DEFAULT_STYLE_URL; + mMapStyle = MLRNModule.DEFAULT_STYLE_URL; setLifecycleListeners(); @@ -434,10 +434,10 @@ public boolean isJSONValid(String test) { public void onMapReady(final MapLibreMap mapboxMap) { mMap = mapboxMap; - if (isJSONValid(mStyleURL)) { - mMap.setStyle(new Style.Builder().fromJson(mStyleURL)); + if (isJSONValid(mMapStyle)) { + mMap.setStyle(new Style.Builder().fromJson(mMapStyle)); } else { - mMap.setStyle(new Style.Builder().fromUri(mStyleURL)); + mMap.setStyle(new Style.Builder().fromUri(mMapStyle)); } reflow(); @@ -774,21 +774,21 @@ private float getDisplayDensity() { return mContext.getResources().getDisplayMetrics().density; } - public void setReactStyleURL(String styleURL) { - mStyleURL = styleURL; + public void setReactMapStyle(String mapStyle) { + mMapStyle = mapStyle; if (mMap != null) { removeAllSourcesFromMap(); - if (isJSONValid(mStyleURL)) { - mMap.setStyle(new Style.Builder().fromJson(mStyleURL), new Style.OnStyleLoaded() { + if (isJSONValid(mMapStyle)) { + mMap.setStyle(new Style.Builder().fromJson(mMapStyle), new Style.OnStyleLoaded() { @Override public void onStyleLoaded(@NonNull Style style) { addAllSourcesToMap(); } }); } else { - mMap.setStyle(styleURL, new Style.OnStyleLoaded() { + mMap.setStyle(mapStyle, new Style.OnStyleLoaded() { @Override public void onStyleLoaded(@NonNull Style style) { addAllSourcesToMap(); diff --git a/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewManager.java b/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewManager.java index 9e34fb95..bbf50d94 100644 --- a/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewManager.java +++ b/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewManager.java @@ -1,7 +1,6 @@ package org.maplibre.reactnative.components.mapview; import android.util.Log; -import android.view.Gravity; import android.view.View; import com.facebook.react.bridge.ReactApplicationContext; @@ -11,23 +10,17 @@ import com.facebook.react.uimanager.LayoutShadowNode; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.annotations.ReactProp; -import org.maplibre.android.geometry.LatLngBounds; -import org.maplibre.android.log.Logger; + import org.maplibre.android.maps.MapLibreMap; import org.maplibre.reactnative.components.AbstractEventEmitter; import org.maplibre.reactnative.events.constants.EventKeys; import org.maplibre.reactnative.utils.ConvertUtils; import org.maplibre.reactnative.utils.ExpressionParser; import org.maplibre.reactnative.utils.GeoJSONUtils; -import org.maplibre.geojson.FeatureCollection; -import org.maplibre.geojson.Point; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.FutureTask; -import java.util.concurrent.RunnableFuture; import javax.annotation.Nullable; @@ -111,9 +104,9 @@ public MLRNMapView getByReactTag(int reactTag) { //region React Props - @ReactProp(name="styleURL") - public void setStyleURL(MLRNMapView mapView, String styleURL) { - mapView.setReactStyleURL(styleURL); + @ReactProp(name="mapStyle") + public void setMapStyle(MLRNMapView mapView, String mapStyle) { + mapView.setReactMapStyle(mapStyle); } @ReactProp(name="preferredFramesPerSecond") diff --git a/ios/MLRN/MLRNMapView.h b/ios/MLRN/MLRNMapView.h index e6efa336..b95e47e4 100644 --- a/ios/MLRN/MLRNMapView.h +++ b/ios/MLRN/MLRNMapView.h @@ -47,7 +47,7 @@ typedef void (^StyleLoadedBlock) (MLNStyle* __nonnull style); @property (nonatomic, assign) NSInteger *reactCompassViewPosition; @property (nonatomic, assign) CGPoint reactCompassViewMargins; -@property (nonatomic, copy) NSString *reactStyleURL; +@property (nonatomic, copy) NSString *reactMapStyle; @property (nonatomic, assign) NSInteger reactPreferredFramesPerSecond; @property (nonatomic, assign) MLNCoordinateBounds maxBounds; diff --git a/ios/MLRN/MLRNMapView.m b/ios/MLRN/MLRNMapView.m index a6690cde..fbbea936 100644 --- a/ios/MLRN/MLRNMapView.m +++ b/ios/MLRN/MLRNMapView.m @@ -374,11 +374,11 @@ - (void)setReactContentInset:(NSArray *)reactContentInset self.contentInset = UIEdgeInsetsMake(top, left, bottom, right); } -- (void)setReactStyleURL:(NSString *)reactStyleURL +- (void)setReactMapStyle:(NSString *)reactMapStyle { - _reactStyleURL = reactStyleURL; + _reactMapStyle = reactMapStyle; [self _removeAllSourcesFromMap]; - self.styleURL = [self _getStyleURLFromKey:_reactStyleURL]; + self.styleURL = [self _getStyleURLFromKey:_reactMapStyle]; } - (void)setReactPreferredFramesPerSecond:(NSInteger)reactPreferredFramesPerSecond @@ -500,13 +500,13 @@ - (MLRNSource *)getTouchableSourceWithHighestZIndex:(NSArray *)tou return nil; } -- (NSURL*)_getStyleURLFromKey:(NSString *)styleURL +- (NSURL*)_getStyleURLFromKey:(NSString *)mapStyle { - NSURL *url = [NSURL URLWithString:styleURL]; + NSURL *url = [NSURL URLWithString:mapStyle]; if (url) { return url; - } else if (RCTJSONParse(styleURL, nil)) { - return [MLRNUtils styleURLFromStyleJSON:styleURL]; + } else if (RCTJSONParse(mapStyle, nil)) { + return [MLRNUtils styleURLFromStyleJSON:mapStyle]; } return url; } diff --git a/ios/MLRN/MLRNMapViewManager.m b/ios/MLRN/MLRNMapViewManager.m index a8b6cc5d..df7b34ed 100644 --- a/ios/MLRN/MLRNMapViewManager.m +++ b/ios/MLRN/MLRNMapViewManager.m @@ -80,7 +80,7 @@ - (UIView *)view RCT_REMAP_VIEW_PROPERTY(compassViewMargins, reactCompassViewMargins, CGPoint) RCT_REMAP_VIEW_PROPERTY(contentInset, reactContentInset, NSArray) -RCT_REMAP_VIEW_PROPERTY(styleURL, reactStyleURL, NSString) +RCT_REMAP_VIEW_PROPERTY(mapStyle, reactMapStyle, NSString) RCT_REMAP_VIEW_PROPERTY(preferredFramesPerSecond, reactPreferredFramesPerSecond, NSInteger) RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor) diff --git a/src/components/MapView.tsx b/src/components/MapView.tsx index 0ef76c79..63342a2f 100644 --- a/src/components/MapView.tsx +++ b/src/components/MapView.tsx @@ -244,7 +244,7 @@ type CallableProps = { }[keyof MapViewProps]; interface NativeProps extends Omit { - styleURL?: string; + mapStyle?: string; onPress(event: NativeSyntheticEvent<{ payload: GeoJSON.Feature }>): void; onLongPress(event: NativeSyntheticEvent<{ payload: GeoJSON.Feature }>): void; } @@ -769,12 +769,12 @@ const MapView = memo( const nativeProps = useMemo(() => { const { mapStyle, ...otherProps } = props; - let styleURL = undefined; + let nativeMapStyle = undefined; if (mapStyle) { if (typeof mapStyle === "string") { - styleURL = mapStyle; + nativeMapStyle = mapStyle; } else if (typeof mapStyle === "object") { - styleURL = JSON.stringify(mapStyle); + nativeMapStyle = JSON.stringify(mapStyle); } } @@ -789,7 +789,7 @@ const MapView = memo( surfaceView, regionWillChangeDebounceTime, regionDidChangeDebounceTime, - styleURL, + mapStyle: nativeMapStyle, contentInset: contentInsetValue, style: styles.matchParent, };