我创建了android app使用mapbox;新的,我想用户挖出多边形区域并在地图上显示;
我怎么能在mapbox中这样做? mapbox.com
我想你可以使用这个功能:
活动
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.mapbox_token));
// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.main_activity);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
drawPolygon(mapboxMap);
}
});
}
函数drawPolygon:
private void drawPolygon(MapboxMap mapboxMap) {
List<LatLng> polygon = new ArrayList<>();
polygon.add(new LatLng(45.522585, -122.685699));
polygon.add(new LatLng(45.534611, -122.708873));
polygon.add(new LatLng(45.530883, -122.678833));
polygon.add(new LatLng(45.547115, -122.667503));
polygon.add(new LatLng(45.530643, -122.660121));
polygon.add(new LatLng(45.533529, -122.636260));
polygon.add(new LatLng(45.521743, -122.659091));
polygon.add(new LatLng(45.510677, -122.648792));
polygon.add(new LatLng(45.515008, -122.664070));
polygon.add(new LatLng(45.502496, -122.669048));
polygon.add(new LatLng(45.515369, -122.678489));
polygon.add(new LatLng(45.506346, -122.702007));
polygon.add(new LatLng(45.522585, -122.685699));
mapboxMap.addPolygon(new PolygonOptions()
.addAll(polygon)
.fillColor(Color.parseColor("#CD0000")));
}
我希望这可以帮助你。
mapbox api提供了处理地图MapboxMap.setOnMapClickListener(OnMapClickListener)
(https://www.mapbox.com/android-docs/api/map-sdk/6.4.0/)点击的功能,它将为您提供位置。
我建议您使用这些位置逐步创建折线,一旦用户完成多边形,然后通过关闭形状将折线转换为多边形。
用户交互示例:https://www.mapbox.com/android-docs/maps/examples/#user-interaction