MSDK Import Third-party Map

2024-08-05
No Rating

This article instructs users how to import third-party map to achieve centralized map management via DJI MapWidget.

How to Import 3rd-party Map

We take importing amap as an example to introduce how to import 3rd-party map. Click to view the complete codeopen in new window.

  1. Create File Folder

Refer to the following feature to create amap file folder and its subfolder. No restrictions on the location or name of the folder.

  1. Method Realization
.
└── amap
    ├── annotations
    ├── map
    ├── place
    ├── provider
    └── utils
annotations
annotation
Refer to the sample to implement
DJICircle, DJIGroupCircle, DJIMarker, DJIPolygon, DJIPolyline
map
map operations
Refer to the sample to implement
DJIBaseMap: map operations such as long press event.
TextureMapView: primarily control the lifecycle for map view.
DJIProjection: responsible for the switching between the screen coordinates and geographic coordinates.
DJIUiSettings: primarily responsible for some map's built-in widgets, such as scale.
Gesture: whether is allowed to rotate or not.
place
map search
Refer to the sample to implement
IInternalPlacesClient、PoiSearch.OnPoiSearchListener
provider
add maps
Refer to the sample to implement
MapProvider
  1. Marker Operations
DJIMap mMap;
DJIBitmapDescriptor icon = DJIBitmapDescriptorFactory.fromResource(R.drawable.gs_user_annotation_image);
DJIMarker locMarker;
  
// Add Marker
locMarker = mMap.addMarker(new DJIMarkerOptions()
        .draggable(false)
        .position(latLng)
        .anchor(0.5f, 0.5f)
        .icon(icon));
// Rotate Marker
locMarker.setRotation(rotation);
  
//Remove
locMarker.remove();
  1. Circle Operations
DJIMap mMap;
DJICircle circle;
  
// Add
DJICircle circle = mMap.addCircle(new DJICircleOptions()
        .center(new DJILatLng(latLng))
        .radius(radius)
        .strokeWidth(5)
        .strokeColor(unLimitStrokeColor)
        .fillColor(unLimitFillColor));
// Remove
circle.remove();
  1. Polyline Operations
DJIMap mMap;
  
// Add Polyline
DJIPolylineOptions options = new DJIPolylineOptions()
    .width(width)
    .color(color)
    .geodesic(true)
    .add(homeMarker.getPosition(), flyMarker.getPosition())
    .ZIndex(655510);
  
DJIPolyline line = mMap.addPolyline(options);
  
// Update Polyline
options.width(newWidth);
line.setOptions(options);
  
// Remove
line.remove();
  1. Polygon Operations
DJIMap mMap;
  
// Add
DJIPolygon plg = mMap.addPolygon(new DJIPolygonOptions().addAll(points)
                .strokeColor(mColorTransparent)
                .strokeWidth(4f)
                .fillColor(fillColor));
// Remove
pig.remove();
  1. Rotate Map (which is rotating the Camera)
DJIMap mMap;
float newBearing;
  
// Obtain current Camera 
DJICameraPosition p = mMap.getCameraPosition();
DJICameraPosition position = new DJICameraPosition.Builder()
    .target(p.target)
    .zoom(p.zoom)
    .tilt(p.tilt)
    .bearing(newBearing)
    .build();
// Update Camera
mMap.animateCamera(DJICameraUpdateFactory.newCameraPosition(position));
// or
mMap.moveCamera(DJICameraUpdateFactory.newCameraPosition(position));
  1. Projection Operations
DJIMap mMap;
Point point; // Point coordinates on the screen
  
// Obtain map coordinates from screen point
DJIProjection projection = mMap.getProjection();
DJILatLng p = projection.fromScreenLocation(point);
  
// Obtain screen point from map coordinates
DJIProjection projection = mMap.getProjection();
Point p = projection.toScreenLocation(marker.getPosition());
  1. Usage for DJILatLngBounds
DJIMap mMap;
  
DJILatLngBounds.Builder builder = new DJILatLngBounds.Builder();
builder.include(locMarker.getPosition());
builder.include(flyMarker.getPosition());
builder.include(homeMarker.getPosition());
final DJILatLngBounds bounds = builder.build();
mMap.moveCamera(DJICameraUpdateFactory.newLatLngBounds(bounds, width, height, 10));
If you have any comments or confusion about our documentation, you can click here to give feedback and we will get back to you as soon as possible.