Search in sources :

Example 1 with Map

use of com.here.android.mpa.mapping.Map 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));
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PlatformDataItemCollection(com.here.android.mpa.pde.PlatformDataItemCollection) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteResult(com.here.android.mpa.routing.RouteResult) PlatformDataResult(com.here.android.mpa.pde.PlatformDataResult) ArrayList(java.util.ArrayList) List(java.util.List) RoutePlan(com.here.android.mpa.routing.RoutePlan) MapObject(com.here.android.mpa.mapping.MapObject) Route(com.here.android.mpa.routing.Route) MapRoute(com.here.android.mpa.mapping.MapRoute) PlatformDataItem(com.here.android.mpa.pde.PlatformDataItem) MapRoute(com.here.android.mpa.mapping.MapRoute) CoreRouter(com.here.android.mpa.routing.CoreRouter) RoutingError(com.here.android.mpa.routing.RoutingError) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) StringTokenizer(java.util.StringTokenizer) RoutingError(com.here.android.mpa.routing.RoutingError) PlatformDataRequest(com.here.android.mpa.pde.PlatformDataRequest) MapPolyline(com.here.android.mpa.mapping.MapPolyline) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) HashMap(java.util.HashMap) Map(com.here.android.mpa.mapping.Map) GeoPolyline(com.here.android.mpa.common.GeoPolyline)

Example 2 with Map

use of com.here.android.mpa.mapping.Map in project here-android-sdk-examples by heremaps.

the class MapFragmentView method addMarkerAtPlace.

// Place markers handling helpers
private void addMarkerAtPlace(PlaceLink placeLink) {
    Image img = new Image();
    try {
        img.setImageResource(R.drawable.marker);
    } catch (IOException e) {
        e.printStackTrace();
    }
    MapMarker mapMarker = new MapMarker();
    mapMarker.setIcon(img);
    mapMarker.setCoordinate(new GeoCoordinate(placeLink.getPosition()));
    Map map = m_mapFragment.getMap();
    map.addMapObject(mapMarker);
    m_mapObjectList.add(mapMarker);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) IOException(java.io.IOException) Image(com.here.android.mpa.common.Image) Map(com.here.android.mpa.mapping.Map)

Example 3 with Map

use of com.here.android.mpa.mapping.Map in project here-android-sdk-examples by heremaps.

the class MapFragmentView method cleanMap.

private void cleanMap() {
    Map map = m_mapFragment.getMap();
    if (!m_mapObjectList.isEmpty()) {
        map.removeMapObjects(m_mapObjectList);
        m_mapObjectList.clear();
    }
}
Also used : Map(com.here.android.mpa.mapping.Map)

Example 4 with Map

use of com.here.android.mpa.mapping.Map in project here-android-sdk-examples by heremaps.

the class NavigationController method onEgineInited.

private void onEgineInited() {
    map = new Map();
    mapView.setMap(map);
    ftcrRouter = new FTCRRouter();
    ftcrNavigationManager = new FTCRNavigationManager();
    defeultCoreRouter = new CoreRouter();
    defaultNavigationManager = NavigationManager.getInstance();
    createRerouteListener();
    createdefaultNavEventListener();
    // Use STOP waypoint type in originalWaypointList.
    // Stopover is waypoint that must be visited, it is used in SDK calbacks and during voice guidance.
    // Via waypoint is only used in initial route calculation, during recalculation all via point will be removed.
    originalWaypointList = Collections.unmodifiableList(Arrays.asList(new RouteWaypoint(new GeoCoordinate(52.516224, 13.376820), Type.STOP_WAYPOINT), new RouteWaypoint(new GeoCoordinate(52.513934, 13.382110), Type.STOP_WAYPOINT), new RouteWaypoint(new GeoCoordinate(52.512247, 13.391867), Type.STOP_WAYPOINT)));
    buildRouteOptions();
    calculateFTCRRoute(originalWaypointList);
    showWaypointsOnMap();
}
Also used : FTCRRouter(com.here.android.mpa.ftcr.FTCRRouter) CoreRouter(com.here.android.mpa.routing.CoreRouter) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) FTCRNavigationManager(com.here.android.mpa.ftcr.FTCRNavigationManager) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) Map(com.here.android.mpa.mapping.Map)

Example 5 with Map

use of com.here.android.mpa.mapping.Map in project here-android-sdk-examples by heremaps.

the class MapFragmentView method showCapitals.

/**
 * Method contains logic for extracting data about capitals and placing it on a map
 */
private void showCapitals() {
    /*
         * Create an image for marker
         */
    final int[] colorArray = new int[25 * 25];
    for (int i = 0; i < colorArray.length; i++) {
        colorArray[i] = Color.GREEN;
    }
    Bitmap bitmap = Bitmap.createBitmap(colorArray, 25, 25, Bitmap.Config.ARGB_8888);
    final Image image = new Image();
    image.setBitmap(bitmap);
    /*
         * Create list of PDE layers to extract
         */
    Set<String> layers = new HashSet<>(Arrays.asList(CITY_POI_LAYER));
    GeoBoundingBox bbox = map.getBoundingBox();
    /*
         * Check that bounding box is valid
         */
    if (bbox == null || bbox.isEmpty()) {
        Log.e(TAG, "PDE bbox is null or empty!");
        Toast.makeText(this.activity.getApplicationContext(), "Current zoom level is too low. Please zoom closer.", Toast.LENGTH_LONG).show();
    } else {
        /*
             * Create and send PDE request
             */
        final PlatformDataRequest request = PlatformDataRequest.createBoundingBoxRequest(layers, bbox);
        request.execute(new PlatformDataRequest.Listener<PlatformDataResult>() {

            @Override
            public void onCompleted(PlatformDataResult platformDataResult, PlatformDataRequest.Error error) {
                if (error == null) {
                    /*
                         * Process PDE request response
                         */
                    PlatformDataItemCollection result = platformDataResult.get(CITY_POI_LAYER);
                    List<MapObject> markers = new ArrayList<>();
                    for (java.util.Map<String, String> entry : result.extract()) {
                        double lat = Double.parseDouble(entry.get("LAT")) / 100_000;
                        double lon = Double.parseDouble(entry.get("LON")) / 100_000;
                        MapMarker marker = new MapMarker();
                        marker.setCoordinate(new GeoCoordinate(lat, lon));
                        marker.setIcon(image);
                        markers.add(marker);
                    }
                    /*
                         * Add list of map markers on map
                         */
                    map.addMapObjects(markers);
                    /*
                         * Set the zoom level.
                         */
                    map.setZoomLevel(3.95);
                } 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());
                }
            }
        });
    }
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) PlatformDataItemCollection(com.here.android.mpa.pde.PlatformDataItemCollection) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) Image(com.here.android.mpa.common.Image) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) Bitmap(android.graphics.Bitmap) PlatformDataRequest(com.here.android.mpa.pde.PlatformDataRequest) PlatformDataResult(com.here.android.mpa.pde.PlatformDataResult) ArrayList(java.util.ArrayList) List(java.util.List) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox) HashMap(java.util.HashMap) Map(com.here.android.mpa.mapping.Map) HashSet(java.util.HashSet)

Aggregations

Map (com.here.android.mpa.mapping.Map)5 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)4 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)3 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)2 Image (com.here.android.mpa.common.Image)2 MapMarker (com.here.android.mpa.mapping.MapMarker)2 PlatformDataItemCollection (com.here.android.mpa.pde.PlatformDataItemCollection)2 PlatformDataRequest (com.here.android.mpa.pde.PlatformDataRequest)2 PlatformDataResult (com.here.android.mpa.pde.PlatformDataResult)2 CoreRouter (com.here.android.mpa.routing.CoreRouter)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Bitmap (android.graphics.Bitmap)1 GeoPolyline (com.here.android.mpa.common.GeoPolyline)1 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)1 FTCRNavigationManager (com.here.android.mpa.ftcr.FTCRNavigationManager)1 FTCRRouter (com.here.android.mpa.ftcr.FTCRRouter)1 MapObject (com.here.android.mpa.mapping.MapObject)1