添加的标记不可见 - Mapbox 6.7.0
Added marker is not visible - Mapbox 6.7.0
尝试使用符号层将标记添加到 mapbox 时,标记不可见。
尝试添加如下所示的标记,
mapView.getMapAsync(m -> {
isMapReady = true;
mapboxMap = m;
mapboxMap.addOnMapClickListener(MapViewFragment.this);
addMarkerToSymbolLayer(45);
updateCameraPosition(location); });
private void updateCameraPosition(Location location){
if (mapboxMap != null) {
LatLng latLong = new LatLng();
if (location != null) {
latLong.setLatitude(location.getLatitude());
latLong.setLongitude(location.getLongitude());
}
final CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLong)
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mapView.postDelayed(() -> mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), AppConstants.MAP_CAMERA_ANIMATE_DURATION_MS_5000), 100);
private void addMarkerToSymbolLayer(float headDirection) {
GeoJsonSource geoJsonSource = new GeoJsonSource("geojson-source",
Feature.fromGeometry(Point.fromLngLat(77.6387, 12.9610)));
mapboxMap.addSource(geoJsonSource);
Bitmap compassNeedleSymbolLayerIcon = BitmapFactory.decodeResource(
getResources(), R.drawable.compass_needle);
mapboxMap.addImage("compass-needle-image-id", compassNeedleSymbolLayerIcon);
SymbolLayer aircraftLayer = new SymbolLayer("aircraft-layer", "geojson-source")
.withProperties(
PropertyFactory.iconImage("compass-needle-image-id"),
PropertyFactory.iconRotate(headDirection),
PropertyFactory.iconIgnorePlacement(true),
PropertyFactory.iconAllowOverlap(true)
);
mapboxMap.addLayer(aircraftLayer);
}
如果在移动相机后调用 addMarkerToSymbolLayer(),则标记可见。为什么添加标记取决于相机位置?我必须多次移动相机才能满足我的要求。如何处理?
此外,在已弃用的 MarkerView 和 MarkerViewOptions 中,我在添加标记时没有遇到任何问题。
我注意到,如果在调用函数 addMarkerToSymbolLayer(45) 时有 100 毫秒的延迟,则标记可见并且一切正常!
甚至在加载所有样式之前调用 onMapReady()。在添加符号层之前加载所有样式是必要的。添加以下侦听器并调用在其中添加标记。
mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
@Override
public void onDidFinishLoadingStyle() {
}
});
尝试使用符号层将标记添加到 mapbox 时,标记不可见。 尝试添加如下所示的标记,
mapView.getMapAsync(m -> {
isMapReady = true;
mapboxMap = m;
mapboxMap.addOnMapClickListener(MapViewFragment.this);
addMarkerToSymbolLayer(45);
updateCameraPosition(location); });
private void updateCameraPosition(Location location){
if (mapboxMap != null) {
LatLng latLong = new LatLng();
if (location != null) {
latLong.setLatitude(location.getLatitude());
latLong.setLongitude(location.getLongitude());
}
final CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLong)
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mapView.postDelayed(() -> mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), AppConstants.MAP_CAMERA_ANIMATE_DURATION_MS_5000), 100);
private void addMarkerToSymbolLayer(float headDirection) {
GeoJsonSource geoJsonSource = new GeoJsonSource("geojson-source",
Feature.fromGeometry(Point.fromLngLat(77.6387, 12.9610)));
mapboxMap.addSource(geoJsonSource);
Bitmap compassNeedleSymbolLayerIcon = BitmapFactory.decodeResource(
getResources(), R.drawable.compass_needle);
mapboxMap.addImage("compass-needle-image-id", compassNeedleSymbolLayerIcon);
SymbolLayer aircraftLayer = new SymbolLayer("aircraft-layer", "geojson-source")
.withProperties(
PropertyFactory.iconImage("compass-needle-image-id"),
PropertyFactory.iconRotate(headDirection),
PropertyFactory.iconIgnorePlacement(true),
PropertyFactory.iconAllowOverlap(true)
);
mapboxMap.addLayer(aircraftLayer);
}
如果在移动相机后调用 addMarkerToSymbolLayer(),则标记可见。为什么添加标记取决于相机位置?我必须多次移动相机才能满足我的要求。如何处理?
此外,在已弃用的 MarkerView 和 MarkerViewOptions 中,我在添加标记时没有遇到任何问题。
我注意到,如果在调用函数 addMarkerToSymbolLayer(45) 时有 100 毫秒的延迟,则标记可见并且一切正常!
甚至在加载所有样式之前调用 onMapReady()。在添加符号层之前加载所有样式是必要的。添加以下侦听器并调用在其中添加标记。
mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
@Override
public void onDidFinishLoadingStyle() {
}
});