تخصيص العلامات
في الإصدارات السابقة من حزمة تطوير البرامج (SDK) للمستهلك، كنت تستخدم عنصر MarkerStyleOptions في حزمة تطوير البرامج (SDK) للمستهلك لتخصيص خصائص نمط محدّد الموقع. في الإصدار 1.0 من حزمة تطوير البرامج (SDK) للمستهلك، يمكنك استخدام عنصر MarkerOptions مباشرةً من حزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google".
// 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));
تخصيص الخطوط المتعدّدة
في الإصدارات السابقة من حزمة تطوير البرامج (SDK) للمستهلك، كنت تستخدم عنصر PolylineStyleOptions في حزمة تطوير البرامج (SDK) للمستهلك لتخصيص سمات نمط الخطوط المتعدّدة. في الإصدار 1.0 من حزمة تطوير البرامج (SDK) للمستهلك، يمكنك استخدام عنصر PolylineOptions من حزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لتخصيص خصائص نمط الخطوط المتعدّدة الأساسية وعنصر TrafficStyle لتخصيص ألوان حركة المرور في الخطوط المتعدّدة.
تتوفّر الخطوط المتعدّدة لحركة المرور في الإصدار الأولي من حزمة تطوير البرامج (SDK) للمستهلك، الإصدار 1.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));