Plotting route in MapViewer component

Hello

Does the method route() in the MapViewer (com.haulmont.charts.gui.components.map.MapViewer) works at all? Is there a sample?
The Manual says “For a more detailed information about the methods and parameters of map components, please refer to the corresponding JavaDocs.” Where are the JavaDocs?

Getting my way around some Vaadin demo I got to:
mapViewer.route(mapViewer.createDirectionsRequest(center_p,center_c, TravelMode.DRIVING), new DirectionsRequestCallback() {

        @Override
        public void onCallback(DirectionsResult result, DirectionsStatus status) {
            if (status == DirectionsStatus.OK && result.getRoutes() != null
                    && !result.getRoutes().isEmpty()) {
                DirectionsRoute route = result.getRoutes().get(0);

                Polyline polyline =  mapViewer.createPolyline(route.getOverviewPath());
                polyline.setStrokeWeight(5);
                polyline.setStrokeOpacity(0.5);
                mapViewer.addPolyline(polyline);
            }
        }
    });

wich runs but the RequestCallback never fires.

Thanks for any help.

Hi Pedro,

it seems like there is a typo in direction request constructor, which denies passed points of origin and destination.

For now please try using directions API like this:


DirectionsRequest request = map.createDirectionsRequest();
request.setOrigin(center_p);
request.setDestination(center_c);
request.setTravelMode(TravelMode.DRIVING);
mapViewer.route(request, (result, status) -> {
              if (status == DirectionsStatus.OK && result.getRoutes() != null
                    && !result.getRoutes().isEmpty()) {
                  DirectionsRoute route = result.getRoutes().get(0);

                  Polyline polyline =  mapViewer.createPolyline(route.getOverviewPath());
                  polyline.setStrokeWeight(5);
                  polyline.setStrokeOpacity(0.5);
                  mapViewer.addPolyline(polyline);
              }
});

Thank you for spotting the issue, it will be fixed in the next bugfix release!
I hope it helps.

Hi Igor,

Thank you, your code works.
Trying to pass Waypoints to the request.
How to initialize a List?
Previous experiments tell me to use the constructors (the create… methods) in MapViewer, for instance your code above does not seem to work with DirectionsRequest request = new DirectionsRequest();
I have a map.createDirectionsWaypoint() but how to create the List?

Thanks,
Pedro Armelim

Hi Igor

Discovered my mistake above. Directionsrequest() is an abstract method.
And the list is just List l = new ArrayList
Been learning Java for the past 3 months, on account of CUBA Platform.
Thanks