Skip to content

Commit

Permalink
Replace mapboxMap with maplibreMap (#2314)
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers authored Apr 24, 2024
1 parent b4dcdb1 commit 3454fda
Show file tree
Hide file tree
Showing 53 changed files with 327 additions and 375 deletions.
2 changes: 1 addition & 1 deletion docs/mdbook/src/android/annotation-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Then add markers to the map with GeoJSON:
```

4. Call `mapview.getMapSync()` in order to get a `MapboxMap` object.
After `mapboxMap` is assigned, call the `getEarthQuakeDataFromUSGS()` method
After `maplibreMap` is assigned, call the `getEarthQuakeDataFromUSGS()` method
to make a HTTP request and transform data into the map annotations.

```kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ public void setId(long id) {
/**
* Do not use this method, used internally by the SDK.
*
* @param maplibreMap the hosting mapbox map
* @param maplibreMap the hosting MapLibreMap
*/
public void setMapboxMap(MapLibreMap maplibreMap) {
public void setMapLibreMap(MapLibreMap maplibreMap) {
this.maplibreMap = maplibreMap;
}

/**
* Gets the hosting mapbox map.
* Gets the hosting MapLibreMap.
*
* @return the MapboxMap
* @return the MapLibreMap
*/
protected MapLibreMap getMapboxMap() {
protected MapLibreMap getMapLibreMap() {
return maplibreMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class InfoWindow {

private WeakReference<Marker> boundMarker;
private WeakReference<MapLibreMap> mapboxMap;
private WeakReference<MapLibreMap> maplibreMap;
protected WeakReference<View> view;

private float markerHeightOffset;
Expand All @@ -64,14 +64,14 @@ public class InfoWindow {
}

private void initialize(@NonNull View view, MapLibreMap maplibreMap) {
this.mapboxMap = new WeakReference<>(maplibreMap);
this.maplibreMap = new WeakReference<>(maplibreMap);
isVisible = false;
this.view = new WeakReference<>(view);

view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapLibreMap maplibreMap = InfoWindow.this.mapboxMap.get();
MapLibreMap maplibreMap = InfoWindow.this.maplibreMap.get();
if (maplibreMap != null) {
MapLibreMap.OnInfoWindowClickListener onInfoWindowClickListener = maplibreMap.getOnInfoWindowClickListener();
boolean handledDefaultClick = false;
Expand All @@ -90,7 +90,7 @@ public void onClick(View v) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
MapLibreMap maplibreMap = InfoWindow.this.mapboxMap.get();
MapLibreMap maplibreMap = InfoWindow.this.maplibreMap.get();
if (maplibreMap != null) {
MapLibreMap.OnInfoWindowLongClickListener listener = maplibreMap.getOnInfoWindowLongClickListener();
if (listener != null) {
Expand All @@ -103,7 +103,7 @@ public boolean onLongClick(View v) {
}

private void closeInfoWindow() {
MapLibreMap mapbox = mapboxMap.get();
MapLibreMap mapbox = maplibreMap.get();
Marker marker = boundMarker.get();
if (marker != null && mapbox != null) {
mapbox.deselectMarker(marker);
Expand All @@ -129,7 +129,7 @@ InfoWindow open(@NonNull MapView mapView, Marker boundMarker, @NonNull LatLng po
MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT);

MapLibreMap maplibreMap = this.mapboxMap.get();
MapLibreMap maplibreMap = this.maplibreMap.get();
View view = this.view.get();
if (view != null && maplibreMap != null) {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
Expand Down Expand Up @@ -222,7 +222,7 @@ InfoWindow open(@NonNull MapView mapView, Marker boundMarker, @NonNull LatLng po
*/
@NonNull
InfoWindow close() {
MapLibreMap maplibreMap = this.mapboxMap.get();
MapLibreMap maplibreMap = this.maplibreMap.get();
if (isVisible && maplibreMap != null) {
isVisible = false;
View view = this.view.get();
Expand Down Expand Up @@ -253,7 +253,7 @@ void adaptDefaultMarker(@NonNull Marker overlayItem, MapLibreMap maplibreMap, @N
view = LayoutInflater.from(mapView.getContext()).inflate(layoutRes, mapView, false);
initialize(view, maplibreMap);
}
this.mapboxMap = new WeakReference<>(maplibreMap);
this.maplibreMap = new WeakReference<>(maplibreMap);
String title = overlayItem.getTitle();
TextView titleTextView = ((TextView) view.findViewById(R.id.infowindow_title));
if (!TextUtils.isEmpty(title)) {
Expand Down Expand Up @@ -291,7 +291,7 @@ Marker getBoundMarker() {
* Will result in getting this {@link InfoWindow} and updating the view being displayed.
*/
public void update() {
MapLibreMap maplibreMap = this.mapboxMap.get();
MapLibreMap maplibreMap = this.maplibreMap.get();
Marker marker = boundMarker.get();
View view = this.view.get();
if (maplibreMap != null && marker != null && view != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean isInfoWindowShown() {
*/
public void setPosition(LatLng position) {
this.position = position;
MapLibreMap map = getMapboxMap();
MapLibreMap map = getMapLibreMap();
if (map != null) {
map.updateMarker(this);
}
Expand All @@ -148,7 +148,7 @@ public void setSnippet(String snippet) {
public void setIcon(@Nullable Icon icon) {
this.icon = icon;
this.iconId = icon != null ? icon.getId() : null;
MapLibreMap map = getMapboxMap();
MapLibreMap map = getMapLibreMap();
if (map != null) {
map.updateMarker(this);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ private void refreshInfoWindowContent() {
if (mapView.getContext() != null) {
infoWindow.adaptDefaultMarker(this, maplibreMap, mapView);
}
MapLibreMap map = getMapboxMap();
MapLibreMap map = getMapLibreMap();
if (map != null) {
map.updateMarker(this);
}
Expand All @@ -208,15 +208,15 @@ private void refreshInfoWindowContent() {
* Do not use this method, used internally by the SDK. Use {@link MapLibreMap#selectMarker(Marker)}
* if you want to programmatically display the markers info window.
*
* @param maplibreMap The hosting mapbox map.
* @param maplibreMap The hosting MapLibreMap.
* @param mapView The hosting map view.
* @return The info window that was shown.
*/
@Nullable
public InfoWindow showInfoWindow(@NonNull MapLibreMap maplibreMap, @NonNull MapView mapView) {
setMapboxMap(maplibreMap);
setMapLibreMap(maplibreMap);
setMapView(mapView);
MapLibreMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter();
MapLibreMap.InfoWindowAdapter infoWindowAdapter = getMapLibreMap().getInfoWindowAdapter();
if (infoWindowAdapter != null) {
// end developer is using a custom InfoWindowAdapter
View content = infoWindowAdapter.getInfoWindow(this);
Expand Down Expand Up @@ -244,7 +244,7 @@ private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) {
@Nullable
private InfoWindow getInfoWindow(@NonNull MapView mapView) {
if (infoWindow == null && mapView.getContext() != null) {
infoWindow = new InfoWindow(mapView, R.layout.maplibre_infowindow_content, getMapboxMap());
infoWindow = new InfoWindow(mapView, R.layout.maplibre_infowindow_content, getMapLibreMap());
}
return infoWindow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void addHole(List<LatLng> hole) {

@Override
void update() {
MapLibreMap maplibreMap = getMapboxMap();
MapLibreMap maplibreMap = getMapLibreMap();
if (maplibreMap != null) {
maplibreMap.updatePolygon(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setWidth(float width) {

@Override
void update() {
MapLibreMap maplibreMap = getMapboxMap();
MapLibreMap maplibreMap = getMapLibreMap();
if (maplibreMap != null) {
maplibreMap.updatePolyline(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,54 +365,6 @@ object CameraUpdateFactory {
}
}

/* This class 1. Does not seem to be used 2. The code that calculates targetPoint seems to be a bit suspicious.
commenting out for now.
*/
/*
internal class CameraMoveUpdate(private val x: Float, private val y: Float) : CameraUpdate {
override fun getCameraPosition(mapboxMap: MapboxMap): CameraPosition {
val uiSettings = mapboxMap.uiSettings
val projection = mapboxMap.projection
// Calculate the new center point
val viewPortWidth = uiSettings.width
val viewPortHeight = uiSettings.height
val padding = mapboxMap.cameraPosition.padding!!
// we inverse the map padding, is reapplied when using moveTo/easeTo or animateTo
val targetPoint = PointF((viewPortWidth - padding[0].toFloat() + padding[1].toFloat()) / 2 + x,
(viewPortHeight + padding[1].toFloat() - padding[3].toFloat()) / 2 + y)
val latLng = projection.fromScreenLocation(targetPoint)
val previousPosition = mapboxMap.cameraPosition
return CameraPosition.Builder().target(latLng).zoom(previousPosition.zoom).tilt(previousPosition.tilt).bearing(previousPosition.bearing).build()
}
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
if (other == null || javaClass != other.javaClass) {
return false
}
val that = other as CameraMoveUpdate
return if (java.lang.Float.compare(that.x, x) != 0) {
false
} else {
that.y.compareTo(y) == 0
}
}
override fun hashCode(): Int {
var result = if (x != +0.0f) java.lang.Float.floatToIntBits(x) else 0
result = 31 * result + if (y != +0.0f) java.lang.Float.floatToIntBits(y) else 0
return result
}
override fun toString(): String {
return ("CameraMoveUpdate{" + "x=" + x + ", y=" + y + '}')
}
}
*/

class ZoomUpdate : CameraUpdate {
@IntDef(ZOOM_IN, ZOOM_OUT, ZOOM_BY, ZOOM_TO, ZOOM_TO_POINT)
@Retention(AnnotationRetention.SOURCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ public class MapLibreConstants {
public static final float ZOOM_RATE = 0.65f;

/**
* Fragment Argument Key for MapboxMapOptions
* Fragment Argument Key for MapLibreMapOptions
*/
public static final String FRAG_ARG_MAPLIBREMAPOPTIONS = "MapboxMapOptions";
public static final String FRAG_ARG_MAPLIBREMAPOPTIONS = "MapLibreMapOptions";

/**
* Layer Id of annotations layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
public class MapLibreConfigurationException extends RuntimeException {

/**
* Creates a MapLibre configuration exception thrown by MapboxMap when the SDK hasn't been properly initialised.
* Creates a MapLibre configuration exception thrown by MapLibreMap when the SDK hasn't been properly initialised.
*/
public MapLibreConfigurationException() {
super("\nUsing MapView requires calling MapLibre.getInstance(Context context, String apiKey, "
+ "WellKnownTileServer wellKnownTileServer) before inflating or creating the view.");
}

/**
* Creates a MapLibre configuration exception thrown by MapboxMap when the SDK hasn't been properly initialised.
* Creates a MapLibre configuration exception thrown by MapLibreMap when the SDK hasn't been properly initialised.
*/
public MapLibreConfigurationException(@NonNull String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class AnnotationManager {
this.shapeAnnotations = shapeAnnotations;
}

// TODO refactor MapboxMap out for Projection and Transform
// Requires removing MapboxMap from Annotations by using Peer model from #6912
// TODO refactor MapLibreMap out for Projection and Transform
// Requires removing MapLibreMap from Annotations by using Peer model from #6912
@NonNull
AnnotationManager bind(MapLibreMap maplibreMap) {
this.maplibreMap = maplibreMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void onDestroy() {
}

/**
* Sets a callback object which will be triggered when the MapboxMap instance is ready to be used.
* Sets a callback object which will be triggered when the MapLibreMap instance is ready to be used.
*
* @param onMapReadyCallback The callback to be invoked.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
* you must obtain one from the getMapAsync() method on a MapFragment or MapView that you have
* added to your application.
* <p>
* Note: Similar to a View object, a MapboxMap should only be read and modified from the main thread.
* Note: Similar to a View object, a MapLibreMap should only be read and modified from the main thread.
* </p>
*/
@UiThread
public final class MapLibreMap {

private static final String TAG = "Mbgl-MapboxMap";
private static final String TAG = "Mbgl-MapLibreMap";

private final NativeMap nativeMapView;
private final UiSettings uiSettings;
Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean getPrefetchesTiles() {
* Set the tile pre-fetching zoom delta. Pre-fetching makes sure that a low-resolution
* tile at the (current_zoom_level - delta) is rendered as soon as possible at the
* expense of a little bandwidth.
* Note: This operation will override the MapboxMapOptions#setPrefetchesTiles(boolean)
* Note: This operation will override the MapLibreMapOptions#setPrefetchesTiles(boolean)
* Setting zoom delta to 0 will disable pre-fetching.
* Default zoom delta is 4.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
/**
* Defines configuration MapLibreMapOptions for a MapLibreMap. These options can be used when adding a
* map to your application programmatically (as opposed to via XML). If you are using a MapFragment,
* you can pass these options in using the static factory method newInstance(MapboxMapOptions).
* you can pass these options in using the static factory method newInstance(MapLibreMapOptions).
* If you are using a MapView, you can pass these options in using the constructor
* MapView(Context, MapboxMapOptions). If you add a map using XML, then you can apply these options
* MapView(Context, MapLibreMapOptions). If you add a map using XML, then you can apply these options
* using custom XML tags.
*/
public class MapLibreMapOptions implements Parcelable {
Expand Down Expand Up @@ -95,7 +95,7 @@ public class MapLibreMapOptions implements Parcelable {
private boolean crossSourceCollisions = true;

/**
* Creates a new MapboxMapOptions object.
* Creates a new MapLibreMapOptions object.
*
* @deprecated Use {@link #createFromAttributes(Context, AttributeSet)} instead.
*/
Expand Down Expand Up @@ -154,22 +154,22 @@ private MapLibreMapOptions(Parcel in) {
}

/**
* Creates a default MapboxMapsOptions from a given context.
* Creates a default MapLibreMapsOptions from a given context.
*
* @param context Context related to a map view.
* @return the MapboxMapOptions created from attributes
* @return the MapLibreMapOptions created from attributes
*/
@NonNull
public static MapLibreMapOptions createFromAttributes(@NonNull Context context) {
return createFromAttributes(context, null);
}

/**
* Creates a MapboxMapsOptions from the attribute set.
* Creates a MapLibreMapsOptions from the attribute set.
*
* @param context Context related to a map view.
* @param attrs Attributeset containing configuration
* @return the MapboxMapOptions created from attributes
* @return the MapLibreMapOptions created from attributes
*/
@NonNull
public static MapLibreMapOptions createFromAttributes(@NonNull Context context, @Nullable AttributeSet attrs) {
Expand Down Expand Up @@ -701,7 +701,7 @@ public MapLibreMapOptions setPrefetchesTiles(boolean enable) {
* Set the tile pre-fetching zoom delta. Pre-fetching makes sure that a low-resolution
* tile at the (current_zoom_level - delta) is rendered as soon as possible at the
* expense of a little bandwidth.
* Note: This operation will override the MapboxMapOptions#setPrefetchesTiles(boolean)
* Note: This operation will override the MapLibreMapOptions#setPrefetchesTiles(boolean)
* Setting zoom delta to 0 will disable pre-fetching.
* Default zoom delta is 4.
*
Expand Down
Loading

0 comments on commit 3454fda

Please sign in to comment.