I am using the ArcGIS API for Javascript 4.3 and want to zoom to features that correspond to a definition expression. It was suggested by @RobErt Scheitlin that I use queryTask.executeForExtent to accomplish this. Although, this may be correct, I am still unsure how to incorporate this into my code.
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">selectionDefExpression</SPAN><SPAN class="punctuation token">(</SPAN>selectionArray<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
routeNameStr <SPAN class="operator token">=</SPAN> selectionArray<SPAN class="punctuation token">.</SPAN><SPAN class="token function">join</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"', '"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> definitionExpression <SPAN class="operator token">=</SPAN> corridorLayer<SPAN class="punctuation token">.</SPAN>definitionExpression <SPAN class="operator token">=</SPAN> <SPAN class="string token">"BOTH_ROUTE_NAME IN ('"</SPAN> <SPAN class="operator token">+</SPAN> routeNameStr <SPAN class="operator token">+</SPAN> <SPAN class="string token">"')"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> definitionExpression<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">deselectionDefExpression</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">return</SPAN> corridorLayer<SPAN class="punctuation token">.</SPAN>definitionExpression <SPAN class="operator token">=</SPAN> <SPAN class="string token">"BOTH_ROUTE_NAME IN ('"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">""</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"')"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">var</SPAN> routeName<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> routeNameStr<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> selectedRows <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
grid<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'dgrid-select'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>event<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
routeName <SPAN class="operator token">=</SPAN> event<SPAN class="punctuation token">.</SPAN>rows<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>data<SPAN class="punctuation token">.</SPAN>routeName<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> rows <SPAN class="operator token">=</SPAN> event<SPAN class="punctuation token">.</SPAN>rows<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN>i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> i <SPAN class="operator token"><</SPAN> rows<SPAN class="punctuation token">.</SPAN>length<SPAN class="punctuation token">;</SPAN> i<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
selectedRows<SPAN class="punctuation token">.</SPAN><SPAN class="token function">push</SPAN><SPAN class="punctuation token">(</SPAN>routeName<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
selection <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getElementById</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"selectedRoutes"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
selection<SPAN class="punctuation token">.</SPAN>innerHTML <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="string token">"<li>"</SPAN> <SPAN class="operator token">+</SPAN> routeName <SPAN class="operator token">+</SPAN> <SPAN class="string token">"<a href='#'> Remove</a></li>"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="token function">selectionDefExpression</SPAN><SPAN class="punctuation token">(</SPAN>selectedRows<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="operator token">!</SPAN>corridorURL<SPAN class="punctuation token">.</SPAN>visible<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
corridorLayer<SPAN class="punctuation token">.</SPAN>visible <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>error<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>error<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
grid<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'dgrid-deselect'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="punctuation token">(</SPAN>event<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//var x = [].slice.call(document.querySelectorAll("#selectedRoutes li"));</SPAN>
<SPAN class="comment token">//x.filter(function(e){</SPAN>
<SPAN class="comment token">// return e.firstChild.checked</SPAN>
<SPAN class="comment token">//}).forEach(function (e) {</SPAN>
<SPAN class="comment token">// e.remove();</SPAN>
<SPAN class="comment token">//})</SPAN>
<SPAN class="token function">deselectionDefExpression</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</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>I could also use some assistance on adjusting my definitionExpression based on what is deselected. The act of selection and deselection should make the extend of my features change, thus re-positioning the map as well.
Any suggestions or samples would be greatly appreciated.
Thanks!