I have a details panel in my nearme widget that shows details for a particular facility which are taken from the layer attributes. A 'directions' link is located at the bottom of the details panel, so that when clicked, Google Maps opens in another browser window. As of right now, the destination autofills with the coordinates of the facility in detail, which grabs the coordinates from the 'latitude' and 'longitude' fields in the table. It is proving to be more of a challenge to get the 'origin' to autofill, since I need to grab these coordinates from the widget.js file dynamically (which is not the issue), and then insert them into the popup 'description' in the config.json file (this is proving more difficult).
Below is the code from the config file and the js file. The "description" is where I need to insert the origin coordinates. I know the href link works, because I tested in by hard coding the origin coordinates. I have tried coming at this from two ways. The first, by inserting a key/value into the config file for the originLat and originLong and then grabbing the coordinates from the 'selectedFeature, and inserting them into the config file values. This is simple enough, but I don't know how the grab them and place them into the href link in the description. I tried using a placeholder, but I cannot find the right syntax, and I am not sure that it is possible.
I also tried placing the coordinates directly into the href link by using the replace() method, but it isn't working. I think this has to do with the fact that the entire description is wrapped in quotes, and I think replace() will only work on the entire string. Am I going about this the wrong way? I am open to any suggestions!
<SPAN class="comment token">//nearme widget config.json</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"fontColor"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"#000000"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"searchLayers"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"originLatitude"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"originLongitude"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"popupInfo"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"title"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"{Facility_Name}"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"fieldInfos"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"fieldName"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"label"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"tooltip"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"visible"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"stringFieldOption"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"textbox"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"fieldName"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Shape"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"label"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Shape"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"tooltip"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"visible"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"stringFieldOption"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"textbox"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"fieldName"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Longitude"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"label"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Longitude"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"tooltip"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"visible"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"format"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"places"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"digitSeparator"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">true</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"stringFieldOption"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"textbox"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"fieldName"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Latitude"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"label"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Latitude"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"tooltip"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"visible"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"format"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"places"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"digitSeparator"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">true</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"stringFieldOption"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"textbox"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"description"</SPAN><SPAN class="punctuation token">:</SPAN> "<SPAN class="operator token"><</SPAN>table width<SPAN class="operator token">=</SPAN><SPAN class="string token">'100%'</SPAN><SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tbody<SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td width<SPAN class="operator token">=</SPAN><SPAN class="string token">'50%'</SPAN><SPAN class="operator token">></SPAN>Street Address<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>popup_Address<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td width<SPAN class="operator token">=</SPAN><SPAN class="string token">'50%'</SPAN><SPAN class="operator token">></SPAN>City<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>City<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td width<SPAN class="operator token">=</SPAN><SPAN class="string token">'50%'</SPAN><SPAN class="operator token">></SPAN>State<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>ST<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td
width<SPAN class="operator token">=</SPAN><SPAN class="string token">'50%'</SPAN><SPAN class="operator token">></SPAN>Zip Code<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>Zip_Code<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td width<SPAN class="operator token">=</SPAN><SPAN class="string token">'50%'</SPAN><SPAN class="operator token">></SPAN>Permit Type<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>Permit_Type<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td width<SPAN class="operator token">=</SPAN><SPAN class="string token">'50%'</SPAN><SPAN class="operator token">></SPAN>Comments<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>Comments<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN>\n<SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td width<SPAN class="operator token">=</SPAN><SPAN class="string token">'50%'</SPAN><SPAN class="operator token">></SPAN>Phone<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>a href<SPAN class="operator token">=</SPAN>\<SPAN class="string token"><SPAN>"tel:{Phone}\">{Phone}</a></td></tr>\n<tr><td width='50%'>Alternate Phone</td><td><a href=\"tel:{Alt_Phone}\">{Alt_Phone}</a></td></tr>\n<tr><td colspan='2'><br /><a href='</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.google.com%2Fmaps%3Fsaddr%3D" target="_blank">https://www.google.com/maps?saddr=</A><SPAN> originCoordsGoHere &daddr={Latitude},{Longitude}'>Directions</a>\n</td>\n</tr>\n</tbody>\n</table>"</SPAN></SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"showAttachments"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"mediaInfos"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">//code from nearme widget.js file</SPAN>
<SPAN class="comment token">//method 1</SPAN>
_initWorkflow<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> selectedFeature<SPAN class="punctuation token">,</SPAN> horzontalSliderNode<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//clear previous results</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">_clearResults</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//get selected feature</SPAN>
selectedFeature <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">_getSelectedFeatureFromResult</SPAN><SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//console.log("selectedFeature = ", selectedFeature);</SPAN>
<SPAN class="comment token">//get and configure selectedFeature lat/long for google directions</SPAN>
<SPAN class="keyword token">var</SPAN> normalizedVal <SPAN class="operator token">=</SPAN> webMercatorUtils<SPAN class="punctuation token">.</SPAN><SPAN class="token function">xyToLngLat</SPAN><SPAN class="punctuation token">(</SPAN>selectedFeature<SPAN class="punctuation token">.</SPAN>geometry<SPAN class="punctuation token">.</SPAN>x<SPAN class="punctuation token">,</SPAN> selectedFeature<SPAN class="punctuation token">.</SPAN>geometry<SPAN class="punctuation token">.</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
_originLongitude <SPAN class="operator token">=</SPAN> normalizedVal<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
_originLatitude <SPAN class="operator token">=</SPAN> normalizedVal<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>config<SPAN class="punctuation token">.</SPAN>originLongitude <SPAN class="operator token">=</SPAN> _originLongitude<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>config<SPAN class="punctuation token">.</SPAN>originLatitude <SPAN class="operator token">=</SPAN> _originLatitude<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//method 2</SPAN>
_initWorkflow<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> selectedFeature<SPAN class="punctuation token">,</SPAN> horzontalSliderNode<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//clear previous results</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">_clearResults</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//get selected feature</SPAN>
selectedFeature <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">_getSelectedFeatureFromResult</SPAN><SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> jsonDesc <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>config<SPAN class="punctuation token">.</SPAN>searchLayers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>popupInfo<SPAN class="punctuation token">.</SPAN>description<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>jsonDesc<SPAN class="punctuation token">.</SPAN><SPAN class="token function">includes</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"originCoords"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">alert</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"originCoords found!"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> originCoords <SPAN class="operator token">=</SPAN> _originLatitude <SPAN class="operator token">+</SPAN> <SPAN class="string token">','</SPAN> <SPAN class="operator token">+</SPAN> _originLongitude<SPAN class="punctuation token">;</SPAN>
jsonDesc<SPAN class="punctuation token">.</SPAN><SPAN class="token function">replace</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"originCoords"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"this is not working"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">alert</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"originCoords not found"</SPAN><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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>