gpt4 book ai didi

java - Mapbox:位置符号(圆盘)显示在路线下方

转载 作者:行者123 更新时间:2023-12-05 00:05:45 25 4
gpt4 key购买 nike

有人知道如何使用 Mapbox Android API 使 mapbox 中的位置“圆盘”出现在路线的上方吗?我遵循了 Mapbox Demo App 中的示例,但遗憾的是它仍然无法正常工作。这是问题的演示:

enter image description here

这是我初始化 map 的方式:

mapboxMap.setStyle(style, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
loadedStyle = style;
initRouteLayer();
showActiveRoute();
initIcons();
initLocationComponent(style);
initListeners();

Log.i(TAG, "++ Repaint complete");
}
});

指定路由的初始化:

private void initRouteLayer() {
ROUTE_SOURCE_ID = UUID.randomUUID().toString();
final String routeLayerId = UUID.randomUUID().toString();

loadedStyle.addSource(new GeoJsonSource(ROUTE_SOURCE_ID,
FeatureCollection.fromFeatures(new Feature[]{})));

LineLayer routeLayer = new LineLayer(routeLayerId, ROUTE_SOURCE_ID);

// Add the LineLayer to the map. This layer will display the directions route.
routeLayer.setProperties(
lineCap(Property.LINE_CAP_ROUND),
lineJoin(Property.LINE_JOIN_ROUND),
lineWidth(5f),
lineColor(FrontendUtils.getColor(getContext(), R.color.activeRoute))
);

loadedStyle.addLayer(routeLayer);
}

private void showActiveRoute() {
Log.d(TAG, "Showing active route (activeroute: " + hasActiveRoute()
+ ", fully loaded: " + isFullyLoaded() + ")");

if(hasActiveRoute() && isFullyLoaded()) {
// Retrieve and update the source designated for showing the directions route
GeoJsonSource source = loadedStyle.getSourceAs(ROUTE_SOURCE_ID);

if(source != null) {
source.setGeoJson(routes.get(getActiveRouteIndex()));
}
}
}

这就是位置组件的初始化方式:

private void initLocationComponent(@NonNull Style loadedMapStyle) {
// Get an instance of the component
locationComponent = mapboxMap.getLocationComponent();

LocationComponentOptions customLocationComponentOptions = LocationComponentOptions.builder(getContext())
.foregroundDrawable(R.drawable.location_puck)
.build();

LocationComponentActivationOptions locationComponentActivationOptions =
LocationComponentActivationOptions.builder(getContext(), loadedMapStyle)
.locationComponentOptions(customLocationComponentOptions)
.build();

// Activate with options
locationComponent.activateLocationComponent(locationComponentActivationOptions);

// Enable to make component visible
locationComponent.setLocationComponentEnabled(true);

// Set the component's render mode
locationComponent.setRenderMode(RenderMode.NORMAL);
}

除了由于某种原因在路线下方绘制了位置符号外, map 没有其他问题。我将非常感谢您的帮助!

最佳答案

目前的Mapbox SDK都有这个功能withRouteLineBelowLayerId以确保路线保持在指定层下方(在您的情况下为 LocationComponentConstants.LOCATION_INDICATOR_LAYER)。

关于java - Mapbox:位置符号(圆盘)显示在路线下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57556350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com