use of com.here.android.mpa.common.GeoPolyline in project here-android-sdk-examples by heremaps.
the class MapFragmentView method roadSlopes.
/**
* Method contains logic for extracting data about slopes and showing it on a route
*/
private void roadSlopes() {
final java.util.Map<String, Integer> slopesMap = new HashMap<>();
final java.util.Map<String, List<GeoCoordinate>> geometryMap = new HashMap<>();
/*
* Create a route plan for route calculation
*/
RoutePlan rp = new RoutePlan();
rp.addWaypoint(new RouteWaypoint(new GeoCoordinate(37.79513, -122.47603)));
rp.addWaypoint(new RouteWaypoint(new GeoCoordinate(37.78166, -122.44450)));
CoreRouter router = new CoreRouter();
/*
* For getting list of Link IDs routing should be forced to work online
*/
router.setConnectivity(CoreRouter.Connectivity.ONLINE);
router.calculateRoute(rp, new CoreRouter.Listener() {
@Override
public void onCalculateRouteFinished(List<RouteResult> list, RoutingError routingError) {
if (routingError == RoutingError.NONE) {
Route route = list.get(0).getRoute();
/*
* Show route on the map and zoom to the route
*/
GeoBoundingBox bbox = route.getBoundingBox();
map.addMapObject(new MapRoute(route));
map.zoomTo(bbox, Map.Animation.NONE, 0);
/*
* Get list of Link IDs for the route
*/
final List<Long> ids = route.getPermanentLinkIds();
for (Long id : ids) {
pvids.add(id);
}
Set<String> layers = new HashSet<>(Arrays.asList(ADAS_LAYER, ROAD_GEOM_LAYER));
PlatformDataRequest request = PlatformDataRequest.createBoundingBoxRequest(layers, bbox);
request.execute(new PlatformDataRequest.Listener<PlatformDataResult>() {
@Override
public void onCompleted(PlatformDataResult data, PlatformDataRequest.Error error) {
if (error == null) {
/*
* Process route geometry from PDE
*/
PlatformDataItemCollection roadDataCollection = data.get(ROAD_GEOM_LAYER);
for (PlatformDataItem item : roadDataCollection) {
geometryMap.put(item.getLinkId(), item.getCoordinates());
}
/*
* Process ADAS data from PDE
*/
PlatformDataItemCollection adasDataCollection = data.get(ADAS_LAYER);
for (PlatformDataItem item : adasDataCollection) {
List<String> values = new ArrayList<>();
/*
* Split slopes data
*/
StringTokenizer tokenizer = new StringTokenizer(item.get("SLOPES"));
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken(",");
/*
* Filter out invalid data
*/
if (!token.equals("NULL") && !token.equals("1000000000")) {
values.add(token);
}
}
/*
* Mark slopes data if it contains either high or low value
*/
int max = 0;
int min = 0;
for (String str : values) {
int temp = Integer.valueOf(str);
if (temp > max)
max = temp;
if (temp < min)
min = temp;
}
if ((min * -1) > max && min <= -5_000)
slopesMap.put(item.getLinkId(), LOW_COLOR);
else if ((min * -1) < max && max >= 5_000)
slopesMap.put(item.getLinkId(), HIGH_COLOR);
}
/*
* Process list of geometry
* find route segment with high or low slopes value
* and add this geometry to the list
*/
List<MapObject> polylines = new ArrayList<>();
for (java.util.Map.Entry<String, List<GeoCoordinate>> entry : geometryMap.entrySet()) {
if (pvids.contains(Long.parseLong(entry.getKey()))) {
GeoPolyline polyline = new GeoPolyline();
polyline.add(entry.getValue());
MapPolyline line = new MapPolyline(polyline);
if (slopesMap.containsKey(entry.getKey())) {
line.setLineColor(slopesMap.get(entry.getKey()));
line.setLineWidth(15);
polylines.add(line);
}
}
}
/*
* Show a list of slopes geometry on the map
*/
map.addMapObjects(polylines);
} else {
/*
* Process PDE request error
*/
Log.i(TAG, "PDE error: " + error.getFaultCode());
Log.i(TAG, "PDE error: " + error.getMessage());
Log.i(TAG, "PDE error: " + error.getResponseCode());
Log.i(TAG, "PDE error: " + error.getType().toString());
}
}
});
} else {
Log.e(TAG, "Routing error: " + routingError);
}
}
@Override
public void onProgress(int i) {
Log.i(TAG, String.format("Route calculation progress: %d%%", i));
}
});
}
use of com.here.android.mpa.common.GeoPolyline in project here-android-sdk-examples by heremaps.
the class MapFragmentView method createPolyline.
/**
* Create a MapPolyline and add the MapPolyline to active map view.
*/
private void createPolyline() {
// create boundingBox centered at current location
GeoBoundingBox boundingBox = new GeoBoundingBox(m_map.getCenter(), 1000, 1000);
// add boundingBox's top left and bottom right vertices to list of GeoCoordinates
List<GeoCoordinate> coordinates = new ArrayList<GeoCoordinate>();
coordinates.add(boundingBox.getTopLeft());
coordinates.add(boundingBox.getBottomRight());
// create GeoPolyline with list of GeoCoordinates
GeoPolyline geoPolyline = new GeoPolyline(coordinates);
m_polyline = new MapPolyline(geoPolyline);
m_polyline.setLineColor(Color.BLUE);
m_polyline.setLineWidth(12);
// add GeoPolyline to current active map
m_map.addMapObject(m_polyline);
}
use of com.here.android.mpa.common.GeoPolyline in project here-android-sdk-examples by heremaps.
the class MapFragmentView method addFakeRoute.
// Sends the fake route into the server and displays on the map.
// Note, layer uploading functionality is not part of the Mobile SDK 3.X, this was added
// added for demo purposes.
// Refer to the official fleet telematics documentation to properly implement uploading
// layer on the server.
private void addFakeRoute() {
m_fakeRoute = new GeoCoordinate[] { new GeoCoordinate(52.51517456956208, 13.35019220598042), new GeoCoordinate(52.51693326048553, 13.350012330338359), new GeoCoordinate(52.51796909607947, 13.350633010268211), new GeoCoordinate(52.51875473186374, 13.351499531418085), new GeoCoordinate(52.519415309652686, 13.350413320586085), new GeoCoordinate(52.51992283388972, 13.351393081247807) };
m_startPoint = new GeoCoordinate(52.50920455902815, 13.351180600002408);
m_endPoint = new GeoCoordinate(52.521314984187484, 13.350122384727001);
uploadRouteGeometryOnServer();
GeoPolyline fakeRoutePolyLine = new GeoPolyline();
fakeRoutePolyLine.add(Arrays.asList(m_fakeRoute));
MapPolyline mapFakeRoutePolyline = new MapPolyline(fakeRoutePolyLine);
mapFakeRoutePolyline.setLineWidth(15);
mapFakeRoutePolyline.setLineColor(argb(255, 185, 63, 2));
mapFakeRoutePolyline.setPatternStyle(MapPolyline.PatternStyle.DASH_PATTERN);
m_map.addMapObject(mapFakeRoutePolyline);
MapMarker startMapMarker = new MapMarker(m_startPoint);
MapMarker endMapMarker = new MapMarker(m_endPoint);
m_map.addMapObject(startMapMarker);
m_map.addMapObject(endMapMarker);
}
use of com.here.android.mpa.common.GeoPolyline in project here-android-sdk-examples by heremaps.
the class MapFragmentView method addPolylineObject.
/**
* Create a MapPolyline and add the MapPolyline to active map view.
*/
private void addPolylineObject() {
// create boundingBox centered at current location
GeoBoundingBox boundingBox = new GeoBoundingBox(m_map.getCenter(), 1000, 1000);
// add boundingBox's top left and bottom right vertices to list of GeoCoordinates
List<GeoCoordinate> coordinates = new ArrayList<GeoCoordinate>();
coordinates.add(boundingBox.getTopLeft());
coordinates.add(boundingBox.getBottomRight());
// create GeoPolyline with list of GeoCoordinates
GeoPolyline geoPolyline = new GeoPolyline(coordinates);
MapPolyline polyline = new MapPolyline(geoPolyline);
polyline.setLineColor(Color.BLUE);
polyline.setLineWidth(12);
// add GeoPolyline to current active map
m_map.addMapObject(polyline);
m_polylines.add(polyline);
}
Aggregations