Route Layer Javascript API 4.24 Issue route layer not solving

458
1
10-06-2022 12:47 PM
MarcoSotoDev
New Contributor II

Hello, 

 

We have built a custom map application using Arcgis/core 4.24.7. Per the documentation for the route api, you can solve it using just the api key but thats not the case when you go to solve method in code. always requires you to enter route params. I initialize a route params object with my api key and stops needed. This is the error I get back when the solve method is rejected

TypeError: t.toJSON is not a function
at l._writeNetworkFeatures (RouteParameters.js:5:3920)
at l.writeStops (RouteParameters.js:5:2346)
at f (write.js:5:472)
at d (write.js:5:1835)
at l.write (JSONSupport.js:5:657)
at l.toJSON (JSONSupport.js:5:690)
at e.toQueryParams (queryUtils.js:5:187)
at route.js:5:1591
at Generator.next (<anonymous>)
at asyncGeneratorStep (asyncToGenerator.js:3:1)

 

below is my route layer angular code

//test stop coordinates

let combinedLatLongs: LatLong[] = [{lat: 25.881941, lon: -80.234704 }, {lat: 25.863912, lon: -80.234184}];
 
 
    let allStops: Stop[] = [];
    combinedLatLongs.forEach(s => {
      allStops.push(new Stop({geometry: {latitude: s.lat, longitude: s.lon}}))
    })

    //create stops for fiber route
    const newRouteLayer = new RouteLayer({
 
    })
    this._map.add(newRouteLayer);
 
    const routeParams = new RouteParameters({
      //comes from angular env
      apiKey: environment.esriKey,    
      stops: allStops
    });
    let loaded = await newRouteLayer.load();
   
    if(loaded){
        await newRouteLayer.solve(routeParams)
      .then((resolved: any) => {
        newRouteLayer.update(resolved)
      }, failed => {
        console.log(failed);
      });
    }

 

also want to ask why route layer solves with RouteLayerSolveResult but routeLayer.update() is expecting a RouteLayerUpdateRouteLayerSolveResult object. 

 

big disconnect from the docs. please help 

 

0 Kudos
1 Reply
TimPurdum
New Contributor

I ran into this same issue today. Stop.toJSON() is missing in the TypeScript definitions, even though it is in the docs. Running latest JS 4.28.10. This is definitely a bug in the JS library. The workaround is to use a FeatureSet instead of a collection of Stops.

0 Kudos