Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Class responsible for synchronising views at a LatLng on top of a Map.
*/
public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListener {
public class MarkerViewManager implements MapView.OnCameraDidChangeListener {

private final MapView mapView;
private final MapboxMap mapboxMap;
Expand All @@ -39,7 +39,7 @@ public MarkerViewManager(MapView mapView, MapboxMap mapboxMap) {
@UiThread
public void onDestroy() {
markers.clear();
mapView.removeOnDidFinishRenderingFrameListener(this);
mapView.removeOnCameraDidChangeListener(this);
initialised = false;
}

Expand All @@ -56,11 +56,12 @@ public void addMarker(@NonNull MarkerView markerView) {

if (!initialised) {
initialised = true;
mapView.addOnDidFinishRenderingFrameListener(this);
mapView.addOnCameraDidChangeListener(this);
}
markerView.setProjection(mapboxMap.getProjection());
mapView.addView(markerView.getView());
markers.add(markerView);
markerView.update();
}

/**
Expand All @@ -78,16 +79,14 @@ public void removeMarker(@NonNull MarkerView markerView) {
markers.remove(markerView);
}

@Override
public void onDidFinishRenderingFrame(boolean fully) {
if (fully) {
update();
}
}

private void update() {
for (MarkerView marker : markers) {
marker.update();
}
}

@Override
public void onCameraDidChange(boolean animated) {
update();
}
}