As the title says, so when using RouteResult.fromJSON() it returns and objects with properties set in null.
Here is a sample
RouteResult.toJSON() sample The problem is in Line 113 and 115. Please read them.
Am I doing something wrong?
Juan,
The route result is NOT json it is a RouteResult object
RouteResult | API Reference | ArcGIS API for JavaScript 4.9
So your code would need to look something like this, after requiring the dojo/json module
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">showRoute</SPAN><SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> routeResult <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">.</SPAN>routeResults<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>route<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> routeResultJSON <SPAN class="operator token">=</SPAN> JSON<SPAN class="punctuation token">.</SPAN><SPAN class="token function">stringify</SPAN><SPAN class="punctuation token">(</SPAN>routeResult<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN>routeResultJSON<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN>JSON<SPAN class="punctuation token">.</SPAN><SPAN class="token function">parse</SPAN><SPAN class="punctuation token">(</SPAN>routeResultJSON<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> routeResult<SPAN class="punctuation token">.</SPAN>symbol <SPAN class="operator token">=</SPAN> routeSymbol<SPAN class="punctuation token">;</SPAN> routeLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">add</SPAN><SPAN class="punctuation token">(</SPAN>routeResult<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I have no problem with the route being solved. The real problem is in lines 113 and 115 when getting a RouteResult object because I need to convert it to JSON using toJSON() method but it doesn't work, it returns an empty object (Line 113) and then when I try to convert it again to a normal RouteResult object (Line 115) it returns a RouteResult object but with null properties (useless).
Click two points in map then watch the browser console.
Your code pen worked fine for me. I clicked two point in the extent that comes up when the app loads and logged in with my credentials and it produced a route without any issue.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.