将数字添加到 mapbox 中的标记 android
Adding numbers to marker in mapbox android
我正在尝试弄清楚如何在 mapbox 中以编程方式向标记添加数字以获得下图的结果
MARKERS WITH NUMBERS
这是显示一些标记的地图代码
public class DepartMissionFragment extends Fragment {
private MapView mapView;
private static final String TAG = "DirectionsActivity";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Mapbox.getInstance(requireActivity(), getString(R.string.access_token));
View view = inflater.inflate(R.layout.fragment_mission_depart, container, false);
mapView = view.findViewById(R.id.mapView20);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.589886, -7.603869))
.title("marker one"));
// It is possible to use .setIcon() to get a custom icon from ressources
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.589790, -7.603989))
.title("marker two"));
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.589190, -7.603089))
.title("marker three"));
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.588790, -7.603289))
.title("etc.."));
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.580790, -7.603989))
.title("etc...."));
mapboxMap.setStyle(getString(R.string.navigation_guidance_day), new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
}
});
}
});
return view;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
我正在寻找一种为标记提供数字的方法,对我来说正确的方法是从 drawable 添加自定义标记。
欢迎任何其他方法。
与其使用 MapboxMap#addMarker
方法并根据可绘制资源显示标记,您可以使用符号图层从存储为 GeoJSON 要素的坐标添加图标,如 Mapbox 的 this example 所示Android 的地图 SDK。
将表示坐标的每个 Feature
添加到 GeoJSON object, you could add a property to each Feature
's properties
object containing the number to display on the marker for this coordinate. Then, in addition to the iconImage
added with SymbolLayer#setProperties
as shown in the example, you could also add a textField
for each symbol populated by the property added to the GeoJSON. This symbol layer clustering example 时,显示了应用于集群用例的类似工作流。聚类示例和您的实现之间的区别主要在于,您不是从聚类计数中获取要显示的数字,而是从您为坐标指定的 GeoJSON 属性 中获取它。
我正在尝试弄清楚如何在 mapbox 中以编程方式向标记添加数字以获得下图的结果
MARKERS WITH NUMBERS
这是显示一些标记的地图代码
public class DepartMissionFragment extends Fragment {
private MapView mapView;
private static final String TAG = "DirectionsActivity";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Mapbox.getInstance(requireActivity(), getString(R.string.access_token));
View view = inflater.inflate(R.layout.fragment_mission_depart, container, false);
mapView = view.findViewById(R.id.mapView20);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.589886, -7.603869))
.title("marker one"));
// It is possible to use .setIcon() to get a custom icon from ressources
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.589790, -7.603989))
.title("marker two"));
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.589190, -7.603089))
.title("marker three"));
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.588790, -7.603289))
.title("etc.."));
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(33.580790, -7.603989))
.title("etc...."));
mapboxMap.setStyle(getString(R.string.navigation_guidance_day), new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
}
});
}
});
return view;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
我正在寻找一种为标记提供数字的方法,对我来说正确的方法是从 drawable 添加自定义标记。
欢迎任何其他方法。
与其使用 MapboxMap#addMarker
方法并根据可绘制资源显示标记,您可以使用符号图层从存储为 GeoJSON 要素的坐标添加图标,如 Mapbox 的 this example 所示Android 的地图 SDK。
将表示坐标的每个 Feature
添加到 GeoJSON object, you could add a property to each Feature
's properties
object containing the number to display on the marker for this coordinate. Then, in addition to the iconImage
added with SymbolLayer#setProperties
as shown in the example, you could also add a textField
for each symbol populated by the property added to the GeoJSON. This symbol layer clustering example 时,显示了应用于集群用例的类似工作流。聚类示例和您的实现之间的区别主要在于,您不是从聚类计数中获取要显示的数字,而是从您为坐标指定的 GeoJSON 属性 中获取它。