การปรับแต่งเครื่องหมายระบุตำแหน่ง
ใน Consumer SDK เวอร์ชันก่อนหน้า คุณใช้ออบเจ็กต์ MarkerStyleOptions ของ Consumer SDK เพื่อปรับแต่งพร็อพเพอร์ตี้สไตล์เครื่องหมาย ใน Consumer SDK v1.0 คุณจะใช้ออบเจ็กต์ MarkerOptions จาก 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 จะแสดงผลตัวเลือกรูปแบบเริ่มต้นที่ SDK ระบุไว้สำหรับประเภทเครื่องหมายที่กำหนด หากยังไม่ได้ตั้งค่ารูปแบบหรือตั้งค่าตัวเลือกรูปแบบเป็น 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);
หากไม่ต้องการสร้างสไตล์ใหม่ตั้งแต่ต้น คุณสามารถแก้ไขสไตล์เริ่มต้นได้ ตัวอย่างต่อไปนี้จะแก้ไขเฉพาะไอคอนจุดรับและใช้การตั้งค่าเริ่มต้นของ SDK สำหรับตัวเลือกเครื่องหมายที่เหลือ
// 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));
การปรับแต่งเส้นประกอบ
ใน Consumer SDK เวอร์ชันก่อนหน้า คุณใช้ออบเจ็กต์ PolylineStyleOptions ของ Consumer SDK เพื่อปรับแต่งพร็อพเพอร์ตี้สไตล์เส้นประกอบ ใน Consumer SDK v1.0 คุณใช้ออบเจ็กต์ PolylineOptions จาก Maps SDK เพื่อปรับแต่งพร็อพเพอร์ตี้สไตล์เส้นประกอบพื้นฐาน และใช้ออบเจ็กต์ TrafficStyle เพื่อปรับแต่งสีการจราจรของเส้นประกอบ
เส้นประกอบการจราจรพร้อมใช้งานในตัวแปรอัลฟ่าของ Consumer SDK v1.0 หากมองเห็นการจราจร สีเส้นประกอบพื้นฐานจะถูกแทนที่ด้วยสีการจราจร การจราจรจะไม่แสดงโดยค่าเริ่มต้น ระบบจะป้อนข้อมูลในช่องใน TrafficStyle ที่ไม่ได้ตั้งค่าด้วยค่าเริ่มต้นที่ SDK ระบุ
// 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 จะแสดงตัวเลือกสไตล์เริ่มต้นของ SDK สำหรับประเภทเส้นประกอบที่ระบุ หากยังไม่ได้ตั้งค่า หรือหากตั้งค่าตัวเลือกสไตล์เป็น null ซึ่งจะมีผลกับทั้ง PolylineOptions พื้นฐานและ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);
หากไม่ต้องการสร้างสไตล์ใหม่ตั้งแต่ต้น คุณสามารถแก้ไขสไตล์เริ่มต้นได้ ตัวอย่างต่อไปนี้จะแก้ไขเฉพาะสีเส้นประกอบของเส้นทางที่ใช้งานอยู่ฐาน และใช้การตั้งค่าสไตล์เริ่มต้นของ SDK สำหรับตัวเลือกเครื่องหมายที่เหลือ
// Only customize the remaining route polyline color.
PolylineOptions remainingRouteStyleOptions =
consumerMapStyle.getPolylineStyleOptions(PolylineType.REMAINING_ROUTE);
consumerMapStyle.setPolylineStyleOptions(
remainingRouteStyleOptions.color(Color.DARK_BLUE));