Calculate route in javascript

This forum deals with any kind of routing computation whether it is simple A:B-routing, calculation of isochrones, simple matrix computation or nearest search.
Post Reply
broadhorizon
Posts: 4
Joined: Tue Sep 08, 2020 10:09 am

Calculate route in javascript

Post by broadhorizon »

Within my leaflet map I want to show a route from A to B. But I get the following error:
"Can not deserialize instance of com.ptvag.xserver.xroute.WaypointDesc[] out of START_OBJECT token
at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@304171af; line: 1, column: 2] (through reference chain: com.ptvag.xserver.xroute.CalculateRouteJsonParams["waypoints"])"

What am I doing wrong?

Below is my declaration of scripts and the script for calculating the route.

Code: Select all

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
    <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>

    <script type='text/javascript' src='http://localhost:50010/xmap/xmap-client.js'></script>
    <script type='text/javascript' src='http://loalhost:50030/xroute/xroute-client.js'></script>
    
    <script type='text/javascript' src='http://loalhost:50020/xlocate/xlocate-client.js'></script>
    <script type='text/javascript' src='http://loalhost:50010/leaflet/pages/leaflet/leaflet.js'></script>
    <script type='text/javascript' src='http://loalhost:50010/leaflet/leaflet.ptv.js'></script>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-polylinedecorator/1.1.0/leaflet.polylineDecorator.js"></script>

Code: Select all

var A = {
            "$type": "OffRoadWaypoint",
            "location": {
                "offRoadCoordinate": {
                    "x": 6.1256572,
                    "y": 49.5983745
                }
            }
        };

        var B = {
            "$type": "OnRoadWaypoint",
            "location": {
                "coordinate": {
                    "x": 6.1256572,
                    "y": 49.4816576
                }
            }
        };
     
        var xroute = new XRouteClient();
        xroute.calculateRoute({ "waypoints": [A, B] }, routed);
Joost
Posts: 310
Joined: Fri Apr 25, 2014 1:46 pm

Re: Calculate route in javascript

Post by Joost »

Your code is a call for xRoute 2 but the you are using xRoute 1. XServer 2 has a different API 1 then xServer 1.

For some xServer 1 javascript example i would recommend to check the xServer 1 code same browser: https://svc-eu-h-test.cloud.ptvgroup.co ... pleBrowser . It has been written in Javascript and for each sample you can use the edit button in the top right to have a look at the source code.

Direct link to a routing sample source code:
https://svc-eu-h-test.cloud.ptvgroup.co ... imple/edit
Joost Claessen
Senior Technical Consultant
PTV Benelux
broadhorizon
Posts: 4
Joined: Tue Sep 08, 2020 10:09 am

Re: Calculate route in javascript

Post by broadhorizon »

Joost wrote:Your code is a call for xRoute 2 but the you are using xRoute 1. XServer 2 has a different API 1 then xServer 1.

For some xServer 1 javascript example i would recommend to check the xServer 1 code same browser: https://svc-eu-h-test.cloud.ptvgroup.co ... pleBrowser . It has been written in Javascript and for each sample you can use the edit button in the top right to have a look at the source code.

Direct link to a routing sample source code:
https://svc-eu-h-test.cloud.ptvgroup.co ... imple/edit
Dank je wel Joost.

Ik ga ermee aan de slag.

groet Lanzo
Post Reply