/** 添加驾车路线添加到地图上显示。 */ public void addToMap() { initPolylineOptions(); try { if (mAMap == null) { return; } if (mWidth == 0 || drivePath == null) { return; } mLatLngsOfPath = new ArrayList<LatLng>(); tmcs = new ArrayList<TMC>(); List<DriveStep> drivePaths = drivePath.getSteps(); mPolylineOptions.add(startPoint); for (DriveStep step : drivePaths) { List<LatLonPoint> latlonPoints = step.getPolyline(); List<TMC> tmclist = step.getTMCs(); tmcs.addAll(tmclist); // addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0))); for (LatLonPoint latlonpoint : latlonPoints) { mPolylineOptions.add(convertToLatLng(latlonpoint)); mLatLngsOfPath.add(convertToLatLng(latlonpoint)); } } mPolylineOptions.add(endPoint); if (startMarker != null) { startMarker.remove(); startMarker = null; } if (endMarker != null) { endMarker.remove(); endMarker = null; } // addStartAndEndMarker(); // addThroughPointMarker(); if (isColorfulline && tmcs.size() > 0) { colorWayUpdate(tmcs); } else { showPolyline(); } } catch (Throwable e) { e.printStackTrace(); } }
/** 初始化线段属性 */ private void initPolylineOptions() { mPolylineOptions = null; mPolylineOptions = new PolylineOptions(); mPolylineOptions.color(getDriveColor()).width(mWidth); }