Di chuyển cho tùy chỉnh SDK người dùng Android phiên bản 1.0

Tuỳ chỉnh điểm đánh dấu

Trong các phiên bản trước của Consumer SDK, bạn đã sử dụng đối tượng MarkerStyleOptions của Consumer SDK để tuỳ chỉnh các thuộc tính kiểu của điểm đánh dấu. Trong Consumer SDK phiên bản 1.0, bạn trực tiếp sử dụng đối tượng MarkerOptions từ Maps SDK.

// Centering the marker anchor at (0.5, 0.5) is recommended.
// For vehicle markers, set flat to true to allow the vehicle marker to freely
// rotate flat on the map (rather than always have it face the camera).
MarkerOptions vehicleMarkerOptions = new MarkerOptions()
    .flat(true)
    .anchor(0.5f, 0.5f)
    .icon(vehicleIcon)
    .zIndex(1.0f);
consumerMapStyle.setMarkerStyleOptions(MarkerType.TRIP_VEHICLE);

ConsumerMapStyle trả về các lựa chọn kiểu mặc định do SDK chỉ định cho một loại điểm đánh dấu nhất định nếu kiểu đó chưa được đặt hoặc nếu các lựa chọn kiểu đã được đặt thành null.

// ConsumerMapStyle returns the SDK-set default style options if none has been set yet.
MarkerOptions defaultPickupPointStyleOptions = consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);

// Setting the style to null reverts the style back to the SDK-set default properties.
consumerMapStyle.setMarkerStyleOptions(MarkerType.PICKUP_POINT, /* markerStyleOptions= */ null);
MarkerOptions defaultPickupPointStyleOptions = consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);

Nếu không muốn tạo một kiểu mới từ đầu, bạn có thể sửa đổi kiểu mặc định. Ví dụ sau đây chỉ sửa đổi biểu tượng lấy hàng và sử dụng chế độ cài đặt mặc định của SDK cho các lựa chọn còn lại của điểm đánh dấu.

// getMarkerStyleOptions returns the default pickup point style options, since
// the custom style hasn't been set yet.
MarkerOptions pickupPointStyleOptions =
  consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);
// Modify the icon value and set the style.
consumerMapStyle.setMarkerStyleOptions(
  pickupPointStyleOptions.icon(pickupPointIcon));

Tuỳ chỉnh đường nhiều đoạn

Trong các phiên bản trước của Consumer SDK, bạn đã sử dụng đối tượng PolylineStyleOptions của Consumer SDK để tuỳ chỉnh các thuộc tính kiểu đường nhiều đoạn. Trong Consumer SDK phiên bản 1.0, bạn sử dụng đối tượng PolylineOptions từ Maps SDK để tuỳ chỉnh các thuộc tính kiểu đường đa tuyến cơ bản và đối tượng TrafficStyle để tuỳ chỉnh màu sắc giao thông của đường đa tuyến.

Đường nhiều đoạn giao thông có trong biến thể alpha của Consumer SDK phiên bản 1.0. Nếu giao thông xuất hiện, màu đường nhiều đoạn cơ bản sẽ bị ghi đè bằng màu giao thông. Theo mặc định, lưu lượng truy cập sẽ không hiển thị. Các trường trong TrafficStyle chưa được thiết lập sẽ được điền sẵn bằng các giá trị mặc định do SDK chỉ định.

// PolylineOptions is from Maps SDK
PolylineOptions polylineOptions = new PolylineOptions()
  .color(color)
  .width(width)
  .geodesic(geodesic)
  .startCap(startCap)
  .endCap(endCap)
  .zIndex(zIndex);
consumerMapStyle.setPolylineStyleOptions(
  PolylineType.ACTIVE_ROUTE, polylineOptions);

// TrafficStyle is from ConsumerSDK
TrafficStyle trafficStyle = TrafficStyle.builder()
  .setTrafficVisibility(true)
  .setTrafficColor(SpeedType.NO_DATA, Color.GREY)
  .setTrafficColor(SpeedType.NORMAL_VALUE, Color.BLUE)
  .setTrafficColor(SpeedType.SLOW_VALUE, Color.ORANGE)
  .setTrafficColor(SpeedType.TRAFFIC_JAM, Color.RED)
  .build();
consumerMapStyle.setPolylineTrafficStyle(PolylineType.ACTIVE_ROUTE, trafficStyle);

ConsumerMapStyle trả về các lựa chọn kiểu mặc định của SDK cho một loại đường nhiều đoạn nhất định nếu chưa có lựa chọn nào được đặt hoặc nếu các lựa chọn kiểu được đặt thành null. Điều này áp dụng cho cả PolylineOptions cơ sở và TrafficStyle.

// ConsumerMapStyle returns the SDK's default style options if none has been set yet.
PolylineOptions defaultActiveRouteStyleOptions = consumerMapStyle.getPolylineStyleOptions(PolylineType.ACTIVE_ROUTE);

// Setting the style to null reverts the style back to the SDK-set default properties.
consumerMapStyle.setPolylineStyleOptions(
  PolylineType.ACTIVE_ROUTE, /* polylineStyleOptions= */ null);
PolylineOptions defaultActiveRouteStyleOptions =
  consumerMapStyle.getPolylineStyleOptions(PolylineType.ACTIVE_ROUTE);

Nếu không muốn tạo một kiểu mới từ đầu, bạn có thể sửa đổi kiểu mặc định. Ví dụ sau đây chỉ sửa đổi màu đường nhiều đoạn của tuyến đường cơ sở đang hoạt động và sử dụng chế độ cài đặt kiểu mặc định của SDK cho các lựa chọn còn lại của điểm đánh dấu.

// Only customize the remaining route polyline color.
PolylineOptions remainingRouteStyleOptions =
     consumerMapStyle.getPolylineStyleOptions(PolylineType.REMAINING_ROUTE);
consumerMapStyle.setPolylineStyleOptions(
  remainingRouteStyleOptions.color(Color.DARK_BLUE));