Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / mason / breeders_toolbox / drone_imagery / standard_process_raw_images.mas
blobd55857f656532fc28c670a536a71d7adb137ad2b
1 <%args>
2 </%args>
4 <& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form', 'CXGN.BreederSearch', 'd3.d3v4Min.js', "opencv.opencv" ] &>
6 <style>
7 .ui-autocomplete { z-index:2147483647; }
9 .straightLine, .hrLine{
10   position: absolute;
11   background-color: red;
12   transition: transform .05s ease-in-out;
14 </style>
16 <div id="manage_drone_imagery_standard_process_raw_images_interactive_div" style="display:none">
18     <& /page/page_title.mas, title=>"Manage Aerial Imagery: Run A Standard Process On Raw Images Interactively" &>
20     <&| /util/workflow.mas, id=> "manage_drone_imagery_standard_process_raw_images_interactive_workflow" &>
21         <&| /util/workflow.mas:step, title=> "Intro" &>
22             <& /page/page_title.mas, title=>"This workflow will guide you through applying a standard process to your aerial imaging bands interactively" &>
24             <div class="well well-sm">
25                 <center>
26                 <p>This process will allow you to assign plot-polygons to the raw images.</p>
27                 <p><b>Please finish uploading your raw images before proceeding!</b></p>
28                 </center>
29             </div>
31             <br/><br/>
32             <center>
33             <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
34             </center>
35         </&>
36         <&| /util/workflow.mas:step, title=> "Imaging Band Select" &>
37             <& /page/page_title.mas, title=>"Select a drone run band" &>
39             <div class="well well-sm">
40                 <p>Please select one drone run band to take through the process. The NIR band is currently implemented and provides best contrast.</p>
41             </div>
43             <div class="well well-sm">
44                 <div class="panel panel-default">
45                     <div class="panel-body">
46                         <table class="table table-bordered table-hover" id="manage_drone_imagery_standard_process_interactive_drone_run_bands_table">
47                             <thead>
48                                 <tr>
49                                     <th>Select</th>
50                                     <th>Drone Run Band Name</th>
51                                     <th>Drone Run Band Description</th>
52                                     <th>Drone Run Band Type</th>
53                                     <th>Drone Run Name</th>
54                                     <th>Drone Run Description</th>
55                                     <th>Drone Run Date</th>
56                                     <th>Field Trial Name</th>
57                                     <th>Field Trial Description</th>
58                                 </tr>
59                             </thead>
60                         </table>
61                     </div>
62                 </div>
63             </div>
65             <br/><br/>
66             <center>
67             <button class="btn btn-primary" id="manage_drone_imagery_standard_process_interactive_select_drone_run_band_step">Go to Next Step</button>
68             </center>
69         </&>
70         <&| /util/workflow.mas:step, title=> "Passes" &>
71             <& /page/page_title.mas, title=>"Separated imaging passes" &>
73             <div class="well well-sm">
74                 <p>The process will be applied to each imaging pass at a time. An imaging pass corresponds to the camera moving in one direction over the field experiment, such as an aerial vehicle flying a pass over the field. The passes are automatically separated from the images you uploaded using GPS.</p>
75             </div>
77             <div id="manage_drone_imagery_standard_process_interactive_separated_passes_info"></div>
79             <br/><br/>
80             <center>
81             <button class="btn btn-primary" id="manage_drone_imagery_standard_process_interactive_separated_passes_step">Go to Next Step</button>
82             </center>
83         </&>
84         <&| /util/workflow.mas:step, title=> "Rotate" &>
85             <& /page/page_title.mas, title=>"Rotate images to help with alignment" &>
87             <div class="well well-sm">
88                 <p>Please rotate the images so that they make sense as far as your field experiment</p>
89                 <p>The plots should be in a vertically straight orientation</p>
90                 <p>You should zoom out on your browser (Cntrl + -)</p>
91                 <p><b>This process will cycle over the different imaging event passes.</b></p>
93                 <div id="drone_imagery_standard_process_interactive_rotate_flight_pass"></div>
95                 <hr>
97                 <form class="form-horizontal">
98                     <div class="form-group form-group-sm">
99                         <label class="col-sm-6 control-label">Rotate Images (Use Left and Right Arrows For Fine Tuning): </label>
100                         <div class="col-sm-6">
101                             <input type="range" min="-180" max="180" step="0.01" id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_degrees_input" name="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_degrees_input" value="0.00"><div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_degrees_input_text"></div>
102                         </div>
103                     </div>
104                 </form>
106                 <button class="btn btn-default" id="drone_imagery_standard_process_interactive_rotate_crosshairs">Draw Crosshairs Assist</button>
107                 <button class="btn btn-primary" id="manage_drone_imagery_standard_process_interactive_rotate_step">Save Rotation And Go To Next</button>
108                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_rotate_previous_pass">Go To Previous Imaging Pass</button>
109                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_rotate_next_pass">Go To Next Imaging Pass</button>
110                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_rotate_restart">Start Over Rotation</button>
111                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_rotate_skip_forward">Go To Plot Polygons</button>
112             </div>
114             <hr>
116             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_50"></div>
117             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_49"></div>
118             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_48"></div>
119             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_47"></div>
120             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_46"></div>
121             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_45"></div>
122             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_44"></div>
123             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_43"></div>
124             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_42"></div>
125             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_41"></div>
126             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_40"></div>
127             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_39"></div>
128             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_38"></div>
129             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_37"></div>
130             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_36"></div>
131             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_35"></div>
132             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_34"></div>
133             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_33"></div>
134             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_32"></div>
135             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_31"></div>
136             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_30"></div>
137             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_29"></div>
138             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_28"></div>
139             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_27"></div>
140             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_26"></div>
141             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_25"></div>
142             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_24"></div>
143             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_23"></div>
144             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_22"></div>
145             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_21"></div>
146             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_20"></div>
147             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_19"></div>
148             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_18"></div>
149             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_17"></div>
150             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_16"></div>
151             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_15"></div>
152             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_14"></div>
153             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_13"></div>
154             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_12"></div>
155             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_11"></div>
156             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_10"></div>
157             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_9"></div>
158             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_8"></div>
159             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_7"></div>
160             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_6"></div>
161             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_5"></div>
162             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_4"></div>
163             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_3"></div>
164             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_2"></div>
165             <div id="drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_1"></div>
167         </&>
168         <&| /util/workflow.mas:step, title=> "Plot Polygons" &>
169             <& /page/page_title.mas, title=>"Assign plot-polygons to raw images" &>
171             <div class="well well-sm">
172                 <ul>
173                     <li>(0) You should zoom out on your browser (Cntrl + -).</li>
174                     <li>(0) Please be very careful with the mouse clicking.</li>
175                     <li>(1) Give the number of rows and columns in the area of interest.</li>
176                     <li>(2) Use the templating tools below to generate plot polygons. There are three templating tools to choose from:</li>
177                     <ul>
178                         <li>(A) Click the four light blue buttons and then click the four corners encompassing the area of interest.</li>
179                         <li>(B) Or paste a previously used template onto the area of interest.</li>
180                     </ul>
181                     <li>(3) Assign plot numbers to the generated plot polygons, either automatically or manually. Click blue button to go to next.</li>
182                     <li>(4)<b> This process will cycle over the different imaging event passes.</b></li>
183                 </ul>
185                 <hr>
186                 <div id="drone_imagery_standard_process_interactive_plot_polygons_flight_pass"></div>
188                 <hr>
189                 <!-- button class="btn btn-primary" id="drone_imagery_standard_process_raw_images_interactive_match">Match and Align Images</button -->
190                 <!-- button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_match_view">View Match</button -->
191                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_match_previous_pass">Go To Previous Imaging Pass</button>
192                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_match_next_pass">Go To Next Imaging Pass</button>
193                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_match_restart">Start Over Alignment</button>
194                 <button class="btn btn-default" id="drone_imagery_standard_process_raw_images_interactive_drop_pin">Drop Pin Marker</button>
195             </div>
197             <form class="form-horizontal">
198                 <!--div class="form-group form-group-sm">
199                     <label class="col-sm-6 control-label">Fine-tuning Rotate Images: </label>
200                     <div class="col-sm-6">
201                         <input type="range" min="0" max="10" id="drone_imagery_standard_process_raw_images_interactive_rotate_degrees_input" name="drone_imagery_standard_process_raw_images_interactive_rotate_degrees_input" value="0.00">
202                     </div>
203                 </div-->
204                 <!--div class="form-group form-group-sm">
205                     <label class="col-sm-6 control-label">Flip North and South: </label>
206                     <div class="col-sm-6">
207                         <select class="form-control" id="drone_imagery_standard_process_raw_images_interactive_north_south_input" name="drone_imagery_standard_process_raw_images_interactive_north_south_input" >
208                             <option value="South">South</option>
209                             <option value="North">North</option>
210                         </select>
211                     </div>
212                 </div-->
213                 <!--div class="form-group form-group-sm">
214                     <label class="col-sm-6 control-label">Flip East and West: </label>
215                     <div class="col-sm-6">
216                         <select class="form-control" id="drone_imagery_standard_process_raw_images_interactive_east_or_west" name="drone_imagery_standard_process_raw_images_interactive_east_or_west" >
217                             <option value="East">East</option>
218                             <option value="West">West</option>
219                         </select>
220                     </div>
221                 </div-->
222                 <!--div class="form-group form-group-sm">
223                     <label class="col-sm-6 control-label">Rotate Frame: </label>
224                     <div class="col-sm-6">
225                         <input type="range" min="0" max="360" id="drone_imagery_standard_process_raw_images_interactive_rotate_frame_degrees_input" name="drone_imagery_standard_process_raw_images_interactive_rotate_frame_degrees_input" value="0.00">
226                     </div>
227                 </div-->
228             </form>
229             <!--<hr>-->
231             <& /page/detail_page_2_col_section.mas, info_section_collapsible=>1, info_section_collapsed=>1, info_section_title => "<h4 style='display:inline'>(1) Generate Polygon Template Tool</h4>", info_section_subtitle => 'Overlay a uniform grid over the image.', icon_class => "glyphicon glyphicon-th-large", info_section_id => "manage_drone_imagery_generate_plot_polygons_standard_process_raw_images_section", id_extension => '_raw_images_interactive' &>
233             <& /page/detail_page_2_col_section.mas, info_section_collapsible=>1, info_section_collapsed=>1, info_section_title => "<h4 style='display:inline'>(2) Or, Use Ground Control Points</h4>", info_section_subtitle => 'Overlay a uniform grid over the image.', icon_class => "glyphicon glyphicon-th-large", info_section_id => "manage_drone_imagery_generate_plot_polygons_standard_process_raw_images_section_ground_control_points" &>
235             <div class="well well-sm">
236                 <button id="drone_imagery_interactive_plot_polygons_clear" class="btn btn-danger">Clear All Polygons</button>
237                 <button id="drone_imagery_interactive_plot_polygons_clear_one" class="btn btn-danger">Remove One Polygon</button>
238             </div>
240             <div id="drone_imagery_standard_process_interactive_generated_polygons_input_div" style="display:none">
242                 <div class="well well-sm">
243                     <h2>Either, Manually Assign Plot Numbers to Generated Polygons</h2>
245                     <&| /page/info_section.mas, title => 'Manually Assign Plot Numbers to Polygon Numbers', collapsible=>1, collapsed => 1, subtitle=> 'Table for manually assigning plot numbers to polygon numbers.' &>
246                         <div id="drone_imagery_standard_process_interactive_generated_polygons_table"></div>
247                     </&>
248                 </div>
250                 <div id="drone_imagery_interactive_generated_polygons_div"></div>
252                 <hr>
254                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_50"></div>
255                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_49"></div>
256                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_48"></div>
257                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_47"></div>
258                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_46"></div>
259                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_45"></div>
260                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_44"></div>
261                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_43"></div>
262                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_42"></div>
263                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_41"></div>
264                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_40"></div>
265                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_39"></div>
266                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_38"></div>
267                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_37"></div>
268                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_36"></div>
269                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_35"></div>
270                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_34"></div>
271                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_33"></div>
272                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_32"></div>
273                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_31"></div>
274                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_30"></div>
275                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_29"></div>
276                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_28"></div>
277                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_27"></div>
278                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_26"></div>
279                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_25"></div>
280                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_24"></div>
281                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_23"></div>
282                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_22"></div>
283                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_21"></div>
284                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_20"></div>
285                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_19"></div>
286                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_18"></div>
287                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_17"></div>
288                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_16"></div>
289                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_15"></div>
290                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_14"></div>
291                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_13"></div>
292                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_12"></div>
293                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_11"></div>
294                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_10"></div>
295                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_9"></div>
296                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_8"></div>
297                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_7"></div>
298                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_6"></div>
299                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_5"></div>
300                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_4"></div>
301                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_3"></div>
302                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_2"></div>
303                 <div id="drone_imagery_standard_process_raw_images_image_id_interactive_select_div_1"></div>
305             </div>
307             <hr>
309             <div class="well well-sm">
310                 <div id="drone_imagery_interactive_trial_layout_div"></div>
311             </div>
312         </&>
313         <&| /util/workflow.mas:step, title=> "Apply" &>
314             <& /page/page_title.mas, title=>"Apply these same steps to other drone run bands in the current drone run" &>
316             <div class="well well-sm">
317                 <ul>
318                     <li>Here you can apply the same actions you did for the previous steps 1 to 6, to additional drone run bands in this drone run.</li>
319                     <li>Thresholding will be done dynamically, by removing the top and bottom 20% of pixel values.</li>
320                 </ul>
321             </div>
323             <div class="well well-sm">
324                 <div class="panel panel-default">
325                     <div class="panel-body">
326                         <table class="table table-bordered table-hover" id="manage_drone_imagery_standard_process_interactive_drone_run_bands_apply_table">
327                             <thead>
328                                 <tr>
329                                     <th>Select</th>
330                                     <th>Drone Run Band Name</th>
331                                     <th>Drone Run Band Description</th>
332                                     <th>Drone Run Band Type</th>
333                                     <th>Drone Run Name</th>
334                                     <th>Drone Run Description</th>
335                                     <th>Drone Run Date</th>
336                                     <th>Field Trial Name</th>
337                                     <th>Field Trial Description</th>
338                                 </tr>
339                             </thead>
340                         </table>
342                         <br/>
344                         <center>
345                         <button class="btn btn-primary" id="manage_drone_imagery_standard_process_interactive_drone_run_band_apply_step">Go to Next Step</button>
346                         </center>
347                     </div>
348                 </div>
349             </div>
350         </&>
351         <&| /util/workflow.mas:step, title=> "Indices" &>
352             <& /page/page_title.mas, title=>"Create and apply these same steps to vegetative indices" &>
354             <form class="form-horizontal">
355                 <div class="form-group form-group-sm">
356                     <label class="col-sm-6 control-label">Vegetative Indices To Apply: </label>
357                     <div class="col-sm-6">
358                         <input name="drone_imagery_standard_process_interactive_apply_indices_select" value="TGI" type="checkbox" checked disabled> Triangular Greenness Index (TGI) <br/>
359                         <input name="drone_imagery_standard_process_interactive_apply_indices_select" value="VARI" type="checkbox" checked disabled> Visible Atmospheric Resistant Index (VARI) <br/>
360                         <input name="drone_imagery_standard_process_interactive_apply_indices_select" value="NDVI" type="checkbox" checked disabled> Normalized Difference Vegetative Index (NDVI) <br/>
361                         <input name="drone_imagery_standard_process_interactive_apply_indices_select" value="NDRE" type="checkbox" checked disabled> Normalized Difference Red Edge Vegetative Index (NDRE) <br/>
362                     </div>
363                 </div>
364             </form>
366             <br/>
368             <center>
369             <button type="button" class="btn btn-primary" id="manage_drone_imagery_standard_interactive_process_indices_step">Go to Next Step</button>
370             </center>
371         </&>
372         <&| /util/workflow.mas:step, title=> "Phenotypes" &>
373             <& /page/page_title.mas, title=>"Calculate phenotypes for all plot polygon images" &>
375             <form class="form-horizontal">
376                 <div class="form-group form-group-sm">
377                     <label class="col-sm-6 control-label">Zonal Statistics to Calculate and Save in Database: </label>
378                     <div class="col-sm-6">
379                         <input name="drone_imagery_standard_process_interactive_phenotypes_select" value="zonal" type="checkbox" checked disabled> Zonal Statistics: nonzero_pixel_count, total_pixel_sum, mean_pixel_value, harmonic_mean_value, median_pixel_value, variance_pixel_value, stdev_pixel_value, pstdev_pixel_value, min_pixel_value, max_pixel_value, minority_pixel_value, minority_pixel_count, majority_pixel_value, majority_pixel_count, pixel_variety_count <br/>
380                     </div>
381                 </div>
382             </form>
383             <br/>
385             <div id="drone_imagery_standard_process_interactive_week_term_div"></div>
387             <center>
388             <button type="button" class="btn btn-info" id="manage_drone_imagery_standard_process_interactive_phenotypes_step">Finish</button>
389             </center>
390         </&>
391     </&>
393 </div>
395 <div class="modal fade" id="drone_imagery_interactive_plot_polygon_template_options_dialog" name="drone_imagery_interactive_plot_polygon_template_options_dialog" tabindex="-1" role="dialog" aria-labelledby="droneImageryInteractivePlotPolygonTemplateDialog" data-backdrop="static">
396   <div class="modal-dialog modal-xl" role="document">
397     <div class="modal-content">
398       <div class="modal-header">
399         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
400         <h4 class="modal-title" id="droneImageryInteractivePlotPolygonTemplateDialog">Plot Template Options</h4>
401       </div>
402       <div class="modal-body">
403         <div class="container-fluid">
404             <&| /page/info_section.mas, title => 'Copy/Paste Template', collapsible=>1, collapsed => 0, subtitle=> 'Copy/Paste this template onto the image.' &>
405                 <button class="btn btn-primary" id="drone_imagery_interactive_plot_polygon_template_options_paste_click">Click To Paste</button>
406             </&>
407         </div>
408       </div>
409       <div class="modal-footer">
410         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
411       </div>
412     </div>
413   </div>
414 </div>
416 <div class="modal fade" id="drone_imagery_interactive_plot_polygon_remove_polygon" name="drone_imagery_interactive_plot_polygon_remove_polygon" tabindex="-1" role="dialog" aria-labelledby="droneImageryInteractiveRemovePlotPolygonDialog" data-backdrop="static">
417   <div class="modal-dialog modal-sm" role="document">
418     <div class="modal-content">
419       <div class="modal-header">
420         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
421         <h4 class="modal-title" id="droneImageryInteractiveRemovePlotPolygonDialog">Remove Plot Polygon</h4>
422       </div>
423       <div class="modal-body">
424         <div class="container-fluid">
425             <form class="form-horizontal">
426                 <div class="form-group">
427                     <label class="col-sm-5 control-label">Polygon Identifier:</label>
428                     <div class="col-sm-7">
429                         <input class="form-control" id="drone_imagery_interactive_plot_polygon_remove_polygon_number" name="drone_imagery_interactive_plot_polygon_remove_polygon_number" type="number" placeholder="e.g. 3" />
430                     </div>
431                 </div>
432             </form>
433         </div>
434       </div>
435       <div class="modal-footer">
436         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
437         <button type="button" class="btn btn-primary" id="drone_imagery_interactive_plot_polygon_remove_polygon_submit">Remove Plot Polygon</button>
438       </div>
439     </div>
440   </div>
441 </div>
443 <div class="modal fade" id="drone_imagery_standard_process_raw_images_interactive_match_modal" name="drone_imagery_standard_process_raw_images_interactive_match_modal" tabindex="-1" role="dialog" aria-labelledby="droneImageryInteractiveMatchViewDialog" data-backdrop="static">
444   <div class="modal-dialog modal-xl" role="document">
445     <div class="modal-content">
446       <div class="modal-header">
447         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
448         <h4 class="modal-title" id="droneImageryInteractiveMatchViewDialog">View Match From Alignment</h4>
449       </div>
450       <div class="modal-body">
451         <div class="container-fluid" id="drone_imagery_standard_process_raw_images_interactive_match_modal_div">
452         </div>
453       </div>
454       <div class="modal-footer">
455         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
456       </div>
457     </div>
458   </div>
459 </div>
461 <div class="modal fade" id="drone_imagery_standard_process_interactive_complete_dialog" name="drone_imagery_standard_process_interactive_complete_dialog" tabindex="-1" role="dialog" aria-labelledby="droneImageryStandardProcessInteractiveCompleteDialog" data-backdrop="static">
462   <div class="modal-dialog modal-xl" role="document">
463     <div class="modal-content">
464       <div class="modal-header">
465         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
466         <h4 class="modal-title" id="droneImageryStandardProcessInteractiveCompleteDialog">Standard Process Complete</h4>
467       </div>
468       <div class="modal-body">
469         <div class="container-fluid">
470             <p>
471                 <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
472                 It will take time to finish processing your drone run and calculating phenotypes for all plot polygon images, vegetative indices, and processing combinations. Once it is complete, the "Processing Icon" on the Manage->Drone Imagery page will disappear from the drone run.
473             </p>
474         </div>
475       </div>
476       <div class="modal-footer">
477         <button type="button" class="btn btn-primary" data-dismiss="modal">Finish</button>
478       </div>
479     </div>
480   </div>
481 </div>
483 <script>
484 jQuery(document).ready(function(){
486     var manage_drone_imagery_standard_process_raw_images_interactive_current_pass = 1;
487     var manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass;
488     var manage_drone_imagery_standard_process_raw_images_interactive_is_rotating = 1;
489     var manage_drone_imagery_standard_process_raw_images_interactive_field_trial_id;
490     var manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id;
491     var manage_drone_imagery_standard_process_raw_images_interactive_north_or_south = 'South';
492     var manage_drone_imagery_standard_process_raw_images_interactive_east_or_west = 'East';
493     var manage_drone_imagery_standard_process_interactive_drone_run_band_project_id;
494     var manage_drone_imagery_standard_process_raw_images_interactive_bulk_rotate_angle = 0;
495     var manage_drone_imagery_standard_process_raw_images_interactive_rotate_angle = 0;
496     var manage_drone_imagery_standard_process_raw_images_interactive_rotate_frame_angle = 0;
497     var manage_drone_imagery_standard_process_raw_images_interactive_x_factor = 10000000;
498     var manage_drone_imagery_standard_process_raw_images_interactive_y_factor = 16000000;
499     var manage_drone_imagery_standard_process_raw_images_interactive_svg;
500     var manage_drone_imagery_standard_process_raw_images_interactive_image;
501     var manage_drone_imagery_standard_process_raw_images_nir_image_counter = 0;
502     var manage_drone_imagery_standard_process_raw_images_nir_images = [];
503     var drone_imagery_interactive_total_width;
504     var drone_imagery_interactive_total_length;
505     var manage_drone_imagery_standard_process_interactive_gps_images;
506     var manage_drone_imagery_standard_process_interactive_saved_gps_positions;
507     var manage_drone_imagery_standard_process_interactive_latitudes;
508     var manage_drone_imagery_standard_process_interactive_latitudes_rounded;
509     var manage_drone_imagery_standard_process_interactive_longitudes;
510     var manage_drone_imagery_standard_process_interactive_longitudes_rounded;
511     var manage_drone_imagery_standard_process_interactive_min_longitude;
512     var manage_drone_imagery_standard_process_interactive_min_latitude;
513     var manage_drone_imagery_standard_process_interactive_latitude_counter = 0;
514     var manage_drone_imagery_standard_process_interactive_longitude_counter = 0;
515     var drone_imagery_interactive_plot_polygons_removed_numbers = [];
516     var drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions = [];
517     var plot_polygons_interactive_num_rows_generated;
518     var plot_polygons_interactive_num_cols_generated;
519     var plot_polygons_interactive_generated_polygons = [];
520     var drone_imagery_interactive_plot_polygons_display = [];
521     var drone_imagery_interactive_plot_polygons = {};
522     var drone_imagery_interactive_plot_generated_polygons = [];
523     var plot_polygons_interactive_number_generated;
524     var plot_polygons_interactive_ind_4_points = [];
525     var plot_polygons_interactive_display_points = [];
526     var drone_imagery_interactive_plot_polygons_available_stock_names = [];
527     var drone_imagery_interactive_field_trial_layout_response;
528     var drone_imagery_interactive_plot_polygons_removed_numbers = [];
529     var plot_polygons_interactive_total_height_generated;
530     var manage_drone_imagery_standard_process_interactive_apply_drone_run_band_project_ids = [];
531     var manage_drone_imagery_standard_process_interactive_phenotype_time;
532     var manage_drone_imagery_standard_process_interactive_apply_drone_run_band_vegetative_indices = [];
533     var manage_drone_imagery_standard_process_interactive_latitude_rounded_map = {};
534     var manage_drone_imagery_standard_process_interactive_longitude_rounded_map = {};
535     var manage_drone_imagery_standard_process_interactive_latitude_ordinal_max;
536     var manage_drone_imagery_standard_process_interactive_longitude_ordinal_max;
537     var manage_drone_imagery_standard_process_interactive_current_ordinal_latitude_raw;
538     var manage_drone_imagery_standard_process_interactive_current_ordinal_latitude_current;
539     var manage_drone_imagery_standard_process_interactive_current_ordinal_longitude_raw;
540     var manage_drone_imagery_standard_process_interactive_current_ordinal_longitude_current;
541     var project_drone_imagery_interactive_ground_control_points_saved_div_table;
542     var project_drone_imagery_interactive_ground_control_points_saved;
543     var project_drone_imagery_interactive_ground_control_points_saved_array;
545     d3.selection.prototype.moveToFront = function() {
546         return this.each(function(){
547             this.parentNode.appendChild(this);
548         });
549     };
551     var droneImageryInteractiveSaveGPStimeout = null;
552     function saveGPSPixelPositions() {
553         if (droneImageryInteractiveSaveGPStimeout !== null) {
554             clearTimeout(droneImageryInteractiveSaveGPStimeout);
555         }
556         droneImageryInteractiveSaveGPStimeout = setTimeout(function () {
558             jQuery.ajax({
559                 url : '/api/drone_imagery/save_gps_images',
560                 type: 'POST',
561                 data : {
562                     'gps_images': JSON.stringify(manage_drone_imagery_standard_process_interactive_gps_images),
563                     'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
564                     'flight_pass_counter':manage_drone_imagery_standard_process_raw_images_interactive_current_pass
565                 },
566                 success: function(response){
567                     console.log(response);
568                 },
569                 error: function(response){
570                     alert('Error saving GPS images positions!');
571                 }
572             });
574         }, 100);
575     }
577     function appendDraggableImage(url, x_pos, y_pos, latitude, longitude, nir_image_id, stack_image_ids, rotate_angle, enable_drag, rotated_bound, match_problem) {
579         var color = "orange";
580         if (match_problem == 1) {
581             color = "red";
582         }
583         else if (match_problem == 0) {
584             color = "green";
585         }
587         var imageGroup = manage_drone_imagery_standard_process_raw_images_interactive_svg.append("g")
588             .datum({position: x_pos,y_pos})
589             .attr("x_pos", x_pos)
590             .attr("y_pos", y_pos)
591             .attr("latitude", latitude)
592             .attr("longitude", longitude)
593             .attr("rotate_angle", rotate_angle)
594             .attr("nir_image_id", nir_image_id )
595             .attr("stack_image_ids", stack_image_ids )
596             .attr("id", "nir_image_"+nir_image_id )
597             .attr("match_problem", match_problem )
598             .attr("transform", d => "translate("+x_pos+","+y_pos+") rotate("+rotate_angle+","+manage_drone_imagery_standard_process_raw_images_interactive_image.width/2+","+manage_drone_imagery_standard_process_raw_images_interactive_image.length/2+")");
600         if (enable_drag == 1) {
601             imageGroup.call(d3.drag()
602                 .on("start", dragstarted)
603                 .on("drag", dragged)
604                 .on("end", dragended));
605         }
607         var imageElem = imageGroup.append("image")
608             .attr("xlink:href", url)
609             //.style("stroke", color)
610             //.style("stroke-width", 2)
611             .attr("height", manage_drone_imagery_standard_process_raw_images_interactive_image.length)
612             .attr("width", manage_drone_imagery_standard_process_raw_images_interactive_image.width);
614         var squareFill = imageGroup.append("square")
615             .attr("class", "square-fill")
616             //.style("stroke", color)
617             //.style("stroke-width", 2)
618             .attr("cx", manage_drone_imagery_standard_process_raw_images_interactive_image.width)
619             .attr("cy", manage_drone_imagery_standard_process_raw_images_interactive_image.length);
621         var imageborder = imageGroup.append('rect')
622             .attr('class', 'image-border')
623             .style("fill", "none")
624             //.style("stroke", color)
625             //.style("stroke-width", 2)
626             .attr('width', manage_drone_imagery_standard_process_raw_images_interactive_image.width)
627             .attr('height', manage_drone_imagery_standard_process_raw_images_interactive_image.length);
629         if (rotated_bound && rotated_bound.length>0) {
630             var bound_x1 = parseFloat(rotated_bound[0][0]) + parseFloat(x_pos);
631             var bound_y1 = parseFloat(rotated_bound[0][1]) + parseFloat(y_pos);
632             var bound_x2 = parseFloat(rotated_bound[1][0]) + parseFloat(x_pos);
633             var bound_y2 = parseFloat(rotated_bound[1][1]) + parseFloat(y_pos);
634             var bound_x3 = parseFloat(rotated_bound[2][0]) + parseFloat(x_pos);
635             var bound_y3 = parseFloat(rotated_bound[2][1]) + parseFloat(y_pos);
636             var bound_x4 = parseFloat(rotated_bound[3][0]) + parseFloat(x_pos);
637             var bound_y4 = parseFloat(rotated_bound[3][1]) + parseFloat(y_pos);
639             var rotatedBoundGroup = manage_drone_imagery_standard_process_raw_images_interactive_svg.append("g")
640                 .datum({position: x_pos,y_pos})
641                 .attr("x_pos", x_pos)
642                 .attr("y_pos", y_pos)
643                 .attr("nir_image_id", nir_image_id )
644                 .attr("match_problem", match_problem )
645                 .attr("is_rotated_bound", 1);
646             var line1 = rotatedBoundGroup.append('line')
647                 .style("stroke", color)
648                 .style("stroke-width", 2)
649                 .attr("x1", bound_x1)
650                 .attr("y1", bound_y1)
651                 .attr("x2", bound_x2)
652                 .attr("y2", bound_y2)
653                 .attr("latitude", latitude)
654                 .attr("longitude", longitude)
655                 .attr("bnum", 0)
656                 .attr("nir_image_id", nir_image_id )
657                 .attr("match_problem", match_problem )
658                 .attr("is_rotated_bound", 1);
659             var line2 = rotatedBoundGroup.append('line')
660                 .style("stroke", color)
661                 .style("stroke-width", 2)
662                 .attr("x1", bound_x2)
663                 .attr("y1", bound_y2)
664                 .attr("x2", bound_x3)
665                 .attr("y2", bound_y3)
666                 .attr("latitude", latitude)
667                 .attr("longitude", longitude)
668                 .attr("bnum", 1)
669                 .attr("nir_image_id", nir_image_id )
670                 .attr("match_problem", match_problem )
671                 .attr("is_rotated_bound", 1);
672             var line3 = rotatedBoundGroup.append('line')
673                 .style("stroke", color)
674                 .style("stroke-width", 2)
675                 .attr("x1", bound_x3)
676                 .attr("y1", bound_y3)
677                 .attr("x2", bound_x4)
678                 .attr("y2", bound_y4)
679                 .attr("latitude", latitude)
680                 .attr("longitude", longitude)
681                 .attr("bnum", 2)
682                 .attr("nir_image_id", nir_image_id )
683                 .attr("match_problem", match_problem )
684                 .attr("is_rotated_bound", 1);
685             var line4 = rotatedBoundGroup.append('line')
686                 .style("stroke", color)
687                 .style("stroke-width", 2)
688                 .attr("x1", bound_x4)
689                 .attr("y1", bound_y4)
690                 .attr("x2", bound_x1)
691                 .attr("y2", bound_y1)
692                 .attr("latitude", latitude)
693                 .attr("longitude", longitude)
694                 .attr("bnum", 3)
695                 .attr("nir_image_id", nir_image_id )
696                 .attr("match_problem", match_problem )
697                 .attr("is_rotated_bound", 1);
699             manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotated_bound_translated'] = [[bound_x1, bound_y1], [bound_x2, bound_y2], [bound_x3, bound_y3], [bound_x4, bound_y4]];
700             saveGPSPixelPositions();
701         }
702     }
704     function dragstarted(d) {
705         d3.select(this).style("opacity", 0.6);
706         d3.select(this).moveToFront();
707     }
709     function dragged(d) {
710         var newX = d3.event.x - manage_drone_imagery_standard_process_raw_images_interactive_image.width / 2;
711         var newY = d3.event.y - manage_drone_imagery_standard_process_raw_images_interactive_image.length / 2;
712         d.x_pos = newX;
713         d.y_pos = newY;
714         var rotate_angle = d3.select(this).attr("rotate_angle");
716         d3.select(this)
717             .attr("transform", "translate("+newX+","+newY+") rotate("+rotate_angle+","+manage_drone_imagery_standard_process_raw_images_interactive_image.width/2+","+manage_drone_imagery_standard_process_raw_images_interactive_image.length/2+")");
718     }
720     function dragended(d) {
721         d3.select(this).lower();
722         d3.select(this).style("opacity", 1.0);
723         d3.select(this).moveToFront();
725         var newX = d3.event.x - manage_drone_imagery_standard_process_raw_images_interactive_image.width / 2;
726         var newY = d3.event.y - manage_drone_imagery_standard_process_raw_images_interactive_image.length / 2;
727         d3.select(this).datum({position: newX,newY});
728         d3.select(this).attr("x_pos", newX);
729         d3.select(this).attr("y_pos", newY);
731         var latitude = d3.select(this).attr("latitude");
732         var longitude = d3.select(this).attr("longitude");
733         manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['manual_match'] = 1;
734         manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['x_pos'] = newX;
735         manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['y_pos'] = newY;
736         manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotate_angle'] = manage_drone_imagery_standard_process_raw_images_interactive_rotate_angle;
738         d3.selectAll("text").moveToFront();
739         d3.selectAll("line").moveToFront();
740         d3.selectAll("circle").moveToFront();
741         saveGPSPixelPositions();
742     }
744     jQuery('#drone_imagery_standard_process_raw_images_interactive_rotate_previous_pass').click(function(){
745         if (manage_drone_imagery_standard_process_raw_images_interactive_current_pass > 1) {
746             manage_drone_imagery_standard_process_raw_images_interactive_current_pass = manage_drone_imagery_standard_process_raw_images_interactive_current_pass - 1;
748             initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div', 'drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_area', 1, 0);
750             jQuery('#drone_imagery_standard_process_interactive_rotate_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
751         }
752         else {
753             alert('No previous imaging pass to go to!');
754             return false;
755         }
756     });
758     jQuery('#drone_imagery_standard_process_raw_images_interactive_rotate_next_pass').click(function(){
759         if (manage_drone_imagery_standard_process_raw_images_interactive_current_pass < manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass) {
760             manage_drone_imagery_standard_process_raw_images_interactive_current_pass = manage_drone_imagery_standard_process_raw_images_interactive_current_pass + 1;
762             initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div', 'drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_area', 1, 0);
764             jQuery('#drone_imagery_standard_process_interactive_rotate_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
765         }
766         else {
767             alert('No next imaging pass to go to!');
768             return false;
769         }
770     });
772     jQuery('#manage_drone_imagery_standard_process_interactive_rotate_step').click(function(){
774         jQuery.ajax({
775             url : '/api/drone_imagery/update_gps_images_rotation',
776             type: 'POST',
777             //beforeSend: function(){
778             //    jQuery('#working_modal').show();
779             //},
780             data : {
781                 'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
782                 'rotate_angle':manage_drone_imagery_standard_process_raw_images_interactive_bulk_rotate_angle,
783                 'flight_pass_counter':manage_drone_imagery_standard_process_raw_images_interactive_current_pass,
784                 'nir_image_ids':JSON.stringify(manage_drone_imagery_standard_process_raw_images_nir_images)
785             },
786             success: function(response){
787                 console.log(response);
788                 //jQuery('#working_modal').hide();
789             },
790             error: function(response){
791                 //jQuery('#working_modal').hide();
792                 alert('Error rotating GPS images!');
793             }
794         });
796         if (manage_drone_imagery_standard_process_raw_images_interactive_current_pass < manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass) {
797             manage_drone_imagery_standard_process_raw_images_interactive_current_pass = manage_drone_imagery_standard_process_raw_images_interactive_current_pass + 1;
799             console.log("PASS ROTATION COMPLETE");
801             initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div', 'drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_area', 1, 0);
803             jQuery('#drone_imagery_standard_process_interactive_rotate_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
805             window.scrollTo(0,0);
806         }
807         else {
809             jQuery('#drone_imagery_standard_process_interactive_rotate_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1><br/><center><h3>Working <img src='/img/wheel.gif' /></h3></center>");
811             (function checkRawImageRotateProcess (manage_drone_imagery_standard_process_raw_images_interactive_is_rotating) {
812                 setTimeout(function () {
813                     jQuery.ajax({
814                         url : '/api/drone_imagery/check_gps_images_rotation',
815                         type: 'POST',
816                         data : {
817                             'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
818                         },
819                         success: function(response){
820                             console.log(response);
821                             manage_drone_imagery_standard_process_raw_images_interactive_is_rotating = response.is_rotating;
822                             if (manage_drone_imagery_standard_process_raw_images_interactive_is_rotating == 1) {
823                                 checkRawImageRotateProcess(manage_drone_imagery_standard_process_raw_images_interactive_is_rotating);
824                             }
825                             else {
826                                 jQuery('#drone_imagery_standard_process_interactive_rotate_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
828                                 console.log("ROTATION AND MATCHING COMPLETE");
830                                 manage_drone_imagery_standard_process_raw_images_interactive_current_pass = 1;
832                                 jQuery('#drone_imagery_standard_process_interactive_plot_polygons_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
834                                 initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div', 'drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area', 1, 1);
836                                 Workflow.complete("#manage_drone_imagery_standard_process_interactive_rotate_step");
837                                 Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 4);
839                                 window.scrollTo(0,0);
840                             }
841                         },
842                         error: function(response){
843                             alert('Error checking GPS image rotation and matching!');
844                         }
845                     });
846                 }, 10000);
847             })(manage_drone_imagery_standard_process_raw_images_interactive_is_rotating);
848         }
849     });
851     jQuery('#drone_imagery_standard_process_raw_images_interactive_rotate_skip_forward').click(function(){
852         manage_drone_imagery_standard_process_raw_images_interactive_current_pass = 1;
854         jQuery('#drone_imagery_standard_process_interactive_plot_polygons_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
856         initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div', 'drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area', 1, 1);
858         Workflow.complete("#manage_drone_imagery_standard_process_interactive_rotate_step");
859         Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 4);
861         window.scrollTo(0,0);
862     });
864     d3.select("#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_degrees_input").on("input", function() {
865         manage_drone_imagery_standard_process_raw_images_interactive_bulk_rotate_angle = this.value;
866         droneImageryInteractiveRotateImages(manage_drone_imagery_standard_process_raw_images_interactive_bulk_rotate_angle, 1, '#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass);
867         jQuery('#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_degrees_input_text').html(manage_drone_imagery_standard_process_raw_images_interactive_bulk_rotate_angle);
868     });
870     function getRandomColorInteractive() {
871         var letters = '0123456789ABCDEF';
872         var color = '#';
873         for (var i = 0; i < 6; i++) {
874             color += letters[Math.floor(Math.random() * 16)];
875         }
876         return color;
877     }
879     function drawRotateCrosshairsInteractive(color) {
880         var row_line_width = 250;
881         var col_line_width = 250;
882         var number_col_lines = drone_imagery_interactive_total_width/col_line_width;
883         var number_row_lines = drone_imagery_interactive_total_length/row_line_width;
884         var current_row_val = row_line_width;
885         var current_col_val = col_line_width;
886         for (var i=0; i<number_col_lines; i++) {
887             manage_drone_imagery_standard_process_raw_images_interactive_svg.append('line')
888                 .style("stroke", color)
889                 .style("stroke-width", 5)
890                 .attr("x1", current_col_val)
891                 .attr("y1", 0)
892                 .attr("x2", current_col_val)
893                 .attr("y2", drone_imagery_interactive_total_length);
894             current_col_val = current_col_val + col_line_width;
895         }
896         for (var i=0; i<number_col_lines; i++) {
897             manage_drone_imagery_standard_process_raw_images_interactive_svg.append('line')
898                 .style("stroke", color)
899                 .style("stroke-width", 5)
900                 .attr("x1", 0)
901                 .attr("y1", current_row_val)
902                 .attr("x2", drone_imagery_interactive_total_width)
903                 .attr("y2", current_row_val);
904             current_row_val = current_row_val + row_line_width;
905         }
906     }
908     jQuery('#drone_imagery_standard_process_interactive_rotate_crosshairs').click(function(){
909         drawRotateCrosshairsInteractive(getRandomColorInteractive());
910     });
912     jQuery('#drone_imagery_standard_process_raw_images_interactive_match_restart').click(function(){
913         jQuery.ajax({
914             url : '/api/drone_imagery/delete_gps_images',
915             type: 'POST',
916             data : {
917                 'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id
918             },
919             success: function(response){
920                 console.log(response);
921                 location.reload();
922             },
923             error: function(response){
924                 alert('Error deleting GPS images template from match step!')
925             }
926         });
927     });
929     jQuery('#drone_imagery_standard_process_raw_images_interactive_rotate_restart').click(function(){
930         jQuery.ajax({
931             url : '/api/drone_imagery/delete_gps_images',
932             type: 'POST',
933             data : {
934                 'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id
935             },
936             success: function(response){
937                 console.log(response);
938                 location.reload();
939             },
940             error: function(response){
941                 alert('Error deleting GPS images template from rotate step!')
942             }
943         });
944     });
946     jQuery('#drone_imagery_standard_process_raw_images_interactive_match_view').click(function(){
947         jQuery('#drone_imagery_standard_process_raw_images_interactive_match_modal').modal('show');
948     });
950     function droneImageryInteractiveDrawImages(enable_drag, div_id){
951         d3.selectAll(div_id+' > g').remove();
952         d3.selectAll(div_id+' > square').remove();
953         d3.selectAll(div_id+' > image').remove();
954         d3.selectAll(div_id+' > line').remove();
955         //d3.selectAll(div_id+' > circle').remove();
956         d3.selectAll(div_id+' > text').remove();
957         d3.selectAll(div_id+' > rect').remove();
958         manage_drone_imagery_standard_process_raw_images_nir_images = [];
960         for (var i=0; i<manage_drone_imagery_standard_process_interactive_latitudes.length; i++) {
961             var latitude = manage_drone_imagery_standard_process_interactive_latitudes[i];
962             for (var j=0; j<manage_drone_imagery_standard_process_interactive_longitudes.length; j++) {
963                 var longitude = manage_drone_imagery_standard_process_interactive_longitudes[j];
964                 if (manage_drone_imagery_standard_process_interactive_saved_gps_positions && manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude] && manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude] && manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['x_pos'] !== undefined) {
966                     var image_url = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['image_url'];
967                     var nir_image_id = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['nir_image_id'];
968                     var rotated_image_ids = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['rotated_image_ids'];
969                     var x_pos = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['x_pos'];
970                     var y_pos = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['y_pos'];
971                     manage_drone_imagery_standard_process_raw_images_nir_images.push(nir_image_id);
972                     var rotate_angle = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['d3_rotate_angle'] ? manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['d3_rotate_angle'] : 0;
973                     var rotated_bound = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['rotated_bound'];
974                     var match_problem = manage_drone_imagery_standard_process_interactive_saved_gps_positions[latitude][longitude]['match_problem'];
975                     appendDraggableImage(image_url, x_pos, y_pos, latitude, longitude, nir_image_id, JSON.stringify(rotated_image_ids), rotate_angle, enable_drag, rotated_bound, match_problem);
976                 }
977                 else if (manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]) {
979                     var image_url = manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['image_url'];
980                     var nir_image_id = manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['nir_image_id'];
981                     var rotated_image_ids = manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotated_image_ids'];
983                     var x_pos;
984                     var y_pos;
985                     if (manage_drone_imagery_standard_process_raw_images_interactive_north_or_south == 'North') {
986                         y_pos = Math.round((latitude - manage_drone_imagery_standard_process_interactive_min_latitude)*manage_drone_imagery_standard_process_raw_images_interactive_y_factor);
987                     }
988                     else if (manage_drone_imagery_standard_process_raw_images_interactive_north_or_south == 'South') {
989                         y_pos = drone_imagery_interactive_total_length - Math.round((latitude - manage_drone_imagery_standard_process_interactive_min_latitude)*manage_drone_imagery_standard_process_raw_images_interactive_y_factor) - manage_drone_imagery_standard_process_interactive_image_length;
990                     }
991                     if (manage_drone_imagery_standard_process_raw_images_interactive_east_or_west == 'East') {
992                         x_pos = Math.round((longitude - manage_drone_imagery_standard_process_interactive_min_longitude)*manage_drone_imagery_standard_process_raw_images_interactive_x_factor);
993                     }
994                     else if (manage_drone_imagery_standard_process_raw_images_interactive_east_or_west == 'West') {
995                         x_pos = drone_imagery_interactive_total_width - Math.round((longitude - manage_drone_imagery_standard_process_interactive_min_longitude)*manage_drone_imagery_standard_process_raw_images_interactive_x_factor) - manage_drone_imagery_standard_process_interactive_image_width;
996                     }
997                     manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['x_pos'] = x_pos;
998                     manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['y_pos'] = y_pos;
999                     var rotate_angle = manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['d3_rotate_angle'] ? manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['d3_rotate_angle'] : 0;
1000                     manage_drone_imagery_standard_process_raw_images_nir_images.push(nir_image_id);
1001                     var rotated_bound = manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotated_bound'];
1002                     var match_problem = manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['match_problem'];
1003                     appendDraggableImage(image_url, x_pos, y_pos, latitude, longitude, nir_image_id, JSON.stringify(rotated_image_ids), rotate_angle, enable_drag, rotated_bound, match_problem);
1004                 }
1005             }
1006         }
1007         if (!manage_drone_imagery_standard_process_interactive_saved_gps_positions) {
1008             manage_drone_imagery_standard_process_interactive_saved_gps_positions = manage_drone_imagery_standard_process_interactive_gps_images;
1009         }
1010         manage_drone_imagery_standard_process_raw_images_nir_images = manage_drone_imagery_standard_process_raw_images_nir_images.sort();
1011         //console.log(manage_drone_imagery_standard_process_raw_images_nir_images);
1012         //console.log(manage_drone_imagery_standard_process_interactive_saved_gps_positions);
1013         //console.log(manage_drone_imagery_standard_process_interactive_gps_images);
1015         d3.selectAll('g').each(function(d) {
1016             var match_problem = d3.select(this).attr('match_problem');
1017             if (match_problem == 1) {
1018                 d3.select(this).moveToFront();
1019             }
1020         });
1021         d3.selectAll('line').each(function(d) {
1022             var match_problem = d3.select(this).attr('match_problem');
1023             if (match_problem == 1) {
1024                 d3.select(this).moveToFront();
1025             }
1026         });
1028         saveGPSPixelPositions();
1029     }
1031     var droneImageryRotateSavetimeout = null;
1032     function droneImageryInteractiveRotateImages(angle, centered, div_id){
1033         d3.selectAll(div_id+'>g').each(function(d) {
1034             var x_pos = d3.select(this).attr('x_pos');
1035             var y_pos = d3.select(this).attr('y_pos');
1036             if (centered == 1) {
1037                 var rotate_x_pos = manage_drone_imagery_standard_process_interactive_image_width/2;
1038                 var rotate_y_pos = manage_drone_imagery_standard_process_interactive_image_length/2;
1039                 d3.select(this).attr("transform", "translate("+x_pos+","+y_pos+") rotate("+angle+","+rotate_x_pos+","+rotate_y_pos+")");
1040             }
1041             else {
1042                 d3.select(this).attr("transform", "translate("+x_pos+","+y_pos+") rotate("+angle+")");
1043                 d3.select(this).attr("rotate_angle", angle);
1044                 var latitude = d3.select(this).attr('latitude');
1045                 var longitude = d3.select(this).attr('longitude');
1046                 manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotate_angle'] = manage_drone_imagery_standard_process_raw_images_interactive_rotate_angle;
1047             }
1048         });
1049         if (droneImageryRotateSavetimeout !== null) {
1050             clearTimeout(droneImageryRotateSavetimeout);
1051         }
1052         droneImageryRotateSavetimeout = setTimeout(function () {
1053             saveGPSPixelPositions();
1054         }, 900);
1055     }
1057     function manage_drone_imagery_interactive_match_two_images(image_id1, image_id2){
1058         jQuery.ajax({
1059             url : '/api/drone_imagery/match_and_align_two_images',
1060             type: 'POST',
1061             data : {
1062                 'image_id1':image_id1,
1063                 'image_id2':image_id2,
1064                 'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
1065             },
1066             success: function(response){
1067                 console.log(response);
1069                 var angle_radians = parseInt(manage_drone_imagery_standard_process_raw_images_interactive_rotate_angle) * 0.0174533;
1070                 console.log(manage_drone_imagery_standard_process_raw_images_interactive_rotate_angle);
1071                 var x_pos_dst;
1072                 var x_pos_src;
1073                 var y_pos_dst;
1074                 var y_pos_src;
1075                 var src_latitude;
1076                 var src_longitude;
1077                 d3.selectAll('g').each(function(d) {
1078                     var nir_image_id = d3.select(this).attr('nir_image_id');
1079                     var is_rotated_bound = d3.select(this).attr('is_rotated_bound');
1080                     if (!is_rotated_bound) {
1081                         if (nir_image_id == response.image_id_dst) {
1082                             x_pos_dst = d3.select(this).attr('x_pos');
1083                             y_pos_dst = d3.select(this).attr('y_pos');
1084                         }
1085                         if (nir_image_id == response.image_id_src) {
1086                             x_pos_src = d3.select(this).attr('x_pos');
1087                             y_pos_src = d3.select(this).attr('y_pos');
1088                             src_latitude = d3.select(this).attr('latitude');
1089                             src_longitude = d3.select(this).attr('longitude');
1090                         }
1091                     }
1092                 });
1094                 manage_drone_imagery_standard_process_interactive_current_ordinal_latitude_raw = src_latitude;
1095                 manage_drone_imagery_standard_process_interactive_current_ordinal_longitude_raw = src_longitude;
1096                 manage_drone_imagery_standard_process_interactive_current_ordinal_latitude_current = manage_drone_imagery_standard_process_interactive_latitude_rounded_map[src_latitude];
1097                 manage_drone_imagery_standard_process_interactive_current_ordinal_longitude_current = manage_drone_imagery_standard_process_interactive_longitude_rounded_map[src_longitude];
1099                 var src_match = response.match_points_src[0];
1100                 var src_match_x = src_match[0];
1101                 var src_match_y = src_match[1];
1102                 var src_match_x_rotated = src_match_x*Math.cos(angle_radians) - src_match_y*Math.sin(angle_radians);
1103                 var src_match_y_rotated = src_match_x*Math.sin(angle_radians) + src_match_y*Math.cos(angle_radians);
1104                 var x_pos_match_src = parseFloat(x_pos_src) + parseFloat(src_match_x_rotated);
1105                 var y_pos_match_src = parseFloat(y_pos_src) + parseFloat(src_match_y_rotated);
1107                 var dst_match = response.match_points_dst[0];
1108                 var dst_match_x = dst_match[0];
1109                 var dst_match_y = dst_match[1];
1110                 var dst_match_x_rotated = dst_match_x*Math.cos(angle_radians) - dst_match_y*Math.sin(angle_radians);
1111                 var dst_match_y_rotated = dst_match_x*Math.sin(angle_radians) + dst_match_y*Math.cos(angle_radians);
1112                 var x_pos_match_dst = x_pos_match_src - dst_match_x_rotated;
1113                 var y_pos_match_dst = y_pos_match_src - dst_match_y_rotated;
1115                 var x_pos_translation = parseFloat(x_pos_dst) - parseFloat(x_pos_match_dst);
1116                 var y_pos_translation = parseFloat(y_pos_dst) - parseFloat(y_pos_match_dst);
1118                 d3.selectAll('g').each(function(d) {
1119                     var nir_image_id = d3.select(this).attr('nir_image_id');
1120                     if (nir_image_id == response.image_id_dst) {
1122                         var is_rotated_bound = d3.select(this).attr('is_rotated_bound');
1123                         if (is_rotated_bound == 1) {
1124                         } else {
1125                             d3.select(this).attr('x_pos', x_pos_match_dst);
1126                             d3.select(this).attr('y_pos', y_pos_match_dst);
1128                             var rotate_angle = d3.select(this).attr('rotate_angle');
1129                             d3.select(this).attr("transform", "translate("+x_pos_match_dst+","+y_pos_match_dst+") rotate("+rotate_angle+","+manage_drone_imagery_standard_process_raw_images_interactive_image.width/2+","+manage_drone_imagery_standard_process_raw_images_interactive_image.length/2+")");
1131                             var latitude = d3.select(this).attr('latitude');
1132                             var longitude = d3.select(this).attr('longitude');
1133                             manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['x_pos'] = x_pos_match_dst;
1134                             manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['y_pos'] = y_pos_match_dst;
1135                             manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotate_angle'] = rotate_angle;
1136                         }
1137                         d3.select(this).moveToFront();
1138                     }
1139                 });
1141                 d3.selectAll('line').each(function(d) {
1142                     var nir_image_id = d3.select(this).attr('nir_image_id');
1143                     if (nir_image_id == response.image_id_dst) {
1145                         var is_rotated_bound = d3.select(this).attr('is_rotated_bound');
1146                         if (is_rotated_bound == 1) {
1147                             var x_pos_1 = parseInt(d3.select(this).attr('x1')) - x_pos_translation;
1148                             var y_pos_1 = parseInt(d3.select(this).attr('y1')) - y_pos_translation;
1149                             var x_pos_2 = parseInt(d3.select(this).attr('x2')) - x_pos_translation;
1150                             var y_pos_2 = parseInt(d3.select(this).attr('y2')) - y_pos_translation;
1151                             d3.select(this).attr('x1', parseInt(x_pos_1));
1152                             d3.select(this).attr('y1', parseInt(y_pos_1));
1153                             d3.select(this).attr('x2', parseInt(x_pos_2));
1154                             d3.select(this).attr('y2', parseInt(y_pos_2));
1155                             var latitude = d3.select(this).attr('latitude');
1156                             var longitude = d3.select(this).attr('longitude');
1157                             var rotated_bound = manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotated_bound'];
1158                             var bnum = parseInt(d3.select(this).attr('bnum'));
1159                             rotated_bound[bnum] = [x_pos_1, y_pos_1];
1160                             manage_drone_imagery_standard_process_interactive_gps_images[latitude][longitude]['rotated_bound'] = rotated_bound;
1161                         }
1162                         d3.select(this).moveToFront();
1163                     }
1164                 });
1166                 var ordinal_latitude = manage_drone_imagery_standard_process_interactive_latitude_rounded_map[src_latitude];
1167                 var ordinal_longitude = manage_drone_imagery_standard_process_interactive_longitude_rounded_map[src_longitude];
1169                 jQuery('#drone_imagery_standard_process_raw_images_interactive_match_modal_div').html("<img src='"+response.match_image_url+"' >");
1171                 manage_drone_imagery_standard_process_raw_images_nir_image_counter = manage_drone_imagery_standard_process_raw_images_nir_image_counter + 1;
1172                 console.log(manage_drone_imagery_standard_process_interactive_gps_images);
1173                 saveGPSPixelPositions();
1175                 image_id1 = manage_drone_imagery_standard_process_raw_images_nir_images[manage_drone_imagery_standard_process_raw_images_nir_image_counter];
1176                 image_id2 = manage_drone_imagery_standard_process_raw_images_nir_images[manage_drone_imagery_standard_process_raw_images_nir_image_counter+1];
1178                 if (image_id1 != undefined && image_id2 != undefined) {
1179                     manage_drone_imagery_interactive_match_two_images(image_id1, image_id2);
1180                 }
1181                 else {
1182                     alert('No more images to match!');
1183                     return false;
1184                 }
1185             },
1186             error: function(response){
1187                 alert('Error matching and aligning two images!')
1188             }
1189         });
1190     }
1192     jQuery('#drone_imagery_standard_process_raw_images_interactive_match_previous_pass').click(function(){
1193         if (manage_drone_imagery_standard_process_raw_images_interactive_current_pass > 1) {
1194             manage_drone_imagery_standard_process_raw_images_interactive_current_pass = manage_drone_imagery_standard_process_raw_images_interactive_current_pass - 1;
1196             initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div', 'drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area', 1, 1);
1198             jQuery('#drone_imagery_standard_process_interactive_plot_polygons_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
1200             plot_polygons_interactive_display_points = [];
1201             plot_polygons_interactive_ind_4_points = [];
1202             plot_polygons_interactive_generated_polygons = {};
1203             drone_imagery_interactive_plot_polygons_display = {};
1204             plot_polygons_interactive_generated_polygons = [];
1205             drone_imagery_interactive_plot_generated_polygons = [];
1206             drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions = [];
1207             drone_imagery_interactive_plot_polygons_removed_numbers = [];
1208             jQuery('#drone_imagery_interactive_generated_polygons_div').html('');
1210             droneImageryDrawLayoutTableInteractive(drone_imagery_interactive_field_trial_layout_response, {}, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
1211             droneImageryDrawPlotPolygonActiveTemplatesTableInteractive('drone_imagery_plot_polygons_active_templates_raw_images_interactive', drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions);
1212             plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
1214             window.scrollTo(0,0);
1215         }
1216         else {
1217             alert('No previous imaging pass to go to!');
1218             return false;
1219         }
1220     });
1222     jQuery('#drone_imagery_standard_process_raw_images_interactive_match_next_pass').click(function(){
1223         if (manage_drone_imagery_standard_process_raw_images_interactive_current_pass < manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass) {
1224             manage_drone_imagery_standard_process_raw_images_interactive_current_pass = manage_drone_imagery_standard_process_raw_images_interactive_current_pass + 1;
1226             initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div', 'drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area', 1, 1);
1228             jQuery('#drone_imagery_standard_process_interactive_plot_polygons_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
1230             plot_polygons_interactive_display_points = [];
1231             plot_polygons_interactive_ind_4_points = [];
1232             plot_polygons_interactive_generated_polygons = {};
1233             drone_imagery_interactive_plot_polygons_display = {};
1234             plot_polygons_interactive_generated_polygons = [];
1235             drone_imagery_interactive_plot_generated_polygons = [];
1236             drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions = [];
1237             drone_imagery_interactive_plot_polygons_removed_numbers = [];
1238             jQuery('#drone_imagery_interactive_generated_polygons_div').html('');
1240             droneImageryDrawLayoutTableInteractive(drone_imagery_interactive_field_trial_layout_response, {}, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
1241             droneImageryDrawPlotPolygonActiveTemplatesTableInteractive('drone_imagery_plot_polygons_active_templates_raw_images_interactive', drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions);
1242             plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
1244             window.scrollTo(0,0);
1245         }
1246         else {
1247             alert('No next imaging pass to go to!');
1248             return false;
1249         }
1250     });
1252     function matchAndAlignSequential() {
1253         jQuery.ajax({
1254             url : '/api/drone_imagery/match_and_align_images_sequential',
1255             type: 'POST',
1256             //beforeSend: function(){
1257             //    jQuery('#working_modal').modal('show');
1258             //},
1259             data : {
1260                 'nir_image_ids':JSON.stringify(manage_drone_imagery_standard_process_raw_images_nir_images),
1261                 'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
1262                 'flight_pass_counter':manage_drone_imagery_standard_process_raw_images_interactive_current_pass
1263             },
1264             success: function(response){
1265                 console.log(response);
1266             //    jQuery('#working_modal').modal('hide');
1267                 alert(response.message);
1269                 console.log("Match Seq Complete");
1270                 initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div', 'drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area', 1, 1);
1271             },
1272             error: function(response){
1273             //    jQuery('#working_modal').modal('hide');
1274                 alert('Error matching and aligning images sequential!')
1275             }
1276         });
1277     }
1279     jQuery('#drone_imagery_standard_process_raw_images_interactive_match').click(function(){
1280         matchAndAlignSequential();
1281     });
1283     jQuery('#drone_imagery_standard_process_raw_images_interactive_drop_pin').click(function(){
1284         alert('Click on a place in the current imaging event pass to drop a pin');
1286         d3.selectAll("g").on('mousedown.drag', null);
1288         manage_drone_imagery_standard_process_raw_images_interactive_svg.on("click", function(){
1289             var current_pos = d3.mouse(this);
1291             manage_drone_imagery_standard_process_raw_images_interactive_svg.append("circle")
1292                    .attr("cx", current_pos[0])
1293                    .attr("cy", current_pos[1])
1294                    .attr("r", 8)
1295                    .attr("fill", "yellow");
1297             d3.selectAll("g").call(d3.drag()
1298                 .on("start", dragstarted)
1299                 .on("drag", dragged)
1300                 .on("end", dragended));
1301         });
1302     });
1304     function initializeInteractiveSvg(svg_div, svg_div_id, init, enable_drag){
1305         jQuery.ajax({
1306             url : '/api/drone_imagery/get_drone_imagery_gps?drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id+'&flight_pass_counter='+manage_drone_imagery_standard_process_raw_images_interactive_current_pass,
1307             success: function(response){
1308                 console.log(response);
1310                 svg_div = svg_div+"_"+manage_drone_imagery_standard_process_raw_images_interactive_current_pass;
1311                 svg_div_id = svg_div_id+"_"+manage_drone_imagery_standard_process_raw_images_interactive_current_pass;
1313                 manage_drone_imagery_standard_process_interactive_image_width = response.image_width;
1314                 manage_drone_imagery_standard_process_interactive_image_length = response.image_length;
1316                 drone_imagery_interactive_total_width = response.x_range;
1317                 drone_imagery_interactive_total_length = response.y_range;
1319                 manage_drone_imagery_standard_process_raw_images_interactive_image = {
1320                   width: manage_drone_imagery_standard_process_interactive_image_width,
1321                   length: manage_drone_imagery_standard_process_interactive_image_length
1322                 }
1324                 d3.select(svg_div).html("<h1>Imaging Pass Number: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"</h1>");
1326                 manage_drone_imagery_standard_process_raw_images_interactive_svg = d3.select(svg_div).append("svg")
1327                     .attr("width", drone_imagery_interactive_total_width)
1328                     .attr("height", drone_imagery_interactive_total_length)
1329                     .attr("id", svg_div_id)
1330                     .on("click", function(){
1331                         console.log(d3.mouse(this));
1332                     })
1334                 if (init) {
1335                     initializeImagesInteractive(enable_drag, svg_div_id);
1336                 }
1337             },
1338             error: function(response){
1339                 alert('Error init svg!')
1340             }
1341         });
1342     }
1344     function initializeImagesInteractive(enable_drag, svg_div_area){
1345         jQuery.ajax({
1346             url : '/api/drone_imagery/get_drone_imagery_gps?drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id+'&flight_pass_counter='+manage_drone_imagery_standard_process_raw_images_interactive_current_pass,
1347             beforeSend: function() {
1348                 jQuery("#working_modal").modal("show");
1349             },
1350             success: function(response){
1351                 console.log(response);
1352                 jQuery("#working_modal").modal("hide");
1354                 manage_drone_imagery_standard_process_interactive_gps_images = response.gps_images;
1355                 manage_drone_imagery_standard_process_interactive_saved_gps_positions = response.saved_gps_positions;
1356                 if (manage_drone_imagery_standard_process_interactive_saved_gps_positions) {
1357                     manage_drone_imagery_standard_process_interactive_gps_images = manage_drone_imagery_standard_process_interactive_saved_gps_positions;
1358                 }
1359                 manage_drone_imagery_standard_process_interactive_latitudes = response.latitudes;
1360                 manage_drone_imagery_standard_process_interactive_latitudes_rounded = response.latitudes_rounded;
1361                 manage_drone_imagery_standard_process_interactive_longitudes = response.longitudes;
1362                 manage_drone_imagery_standard_process_interactive_longitudes_rounded = response.longitudes_rounded;
1363                 manage_drone_imagery_standard_process_interactive_min_longitude = response.min_longitude;
1364                 manage_drone_imagery_standard_process_interactive_min_latitude = response.min_latitude;
1365                 manage_drone_imagery_standard_process_interactive_latitude_rounded_map = response.latitude_rounded_map;
1366                 manage_drone_imagery_standard_process_interactive_longitude_rounded_map = response.longitude_rounded_map;
1367                 manage_drone_imagery_standard_process_interactive_latitude_ordinal_max = manage_drone_imagery_standard_process_interactive_latitudes_rounded.length;
1368                 manage_drone_imagery_standard_process_interactive_longitude_ordinal_max = manage_drone_imagery_standard_process_interactive_longitudes_rounded.length;
1369                 manage_drone_imagery_standard_process_interactive_image_width = response.image_width;
1370                 manage_drone_imagery_standard_process_interactive_image_length = response.image_length;
1372                 drone_imagery_interactive_total_width = response.x_range;
1373                 drone_imagery_interactive_total_length = response.y_range;
1375                 manage_drone_imagery_standard_process_raw_images_interactive_image = {
1376                   width: manage_drone_imagery_standard_process_interactive_image_width,
1377                   length: manage_drone_imagery_standard_process_interactive_image_length
1378                 };
1380                 droneImageryInteractiveDrawImages(enable_drag, svg_div_area);
1381                 showPlotPolygonTableStartInteractive(manage_drone_imagery_standard_process_raw_images_interactive_field_trial_id);
1382             },
1383             error: function(response){
1384                 jQuery("#working_modal").modal("hide");
1385                 alert('Error retrieving images and gps info!')
1386             }
1387         });
1388     }
1390     jQuery(document).on('click', 'button[name="project_drone_imagery_standard_process_raw_images_interactive"]', function() {
1391         showManageDroneImagerySection('manage_drone_imagery_standard_process_raw_images_interactive_div');
1393         manage_drone_imagery_standard_process_raw_images_interactive_field_trial_id = jQuery(this).data('field_trial_id');
1394         manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id = jQuery(this).data('drone_run_project_id');
1396         get_select_box('drone_imagery_parameter_select','plot_polygons_previously_saved_plot_polygon_templates_raw_images_interactive', {'empty':1, 'field_trial_id':manage_drone_imagery_standard_process_raw_images_interactive_field_trial_id, 'parameter':'plot_polygons_separated', 'id':'manage_drone_imagery_standard_process_interactive_previous_templates', 'name':'manage_drone_imagery_standard_process_interactive_previous_templates' });
1398         jQuery('#manage_drone_imagery_standard_process_interactive_drone_run_bands_table').DataTable({
1399             destroy : true,
1400             ajax : '/api/drone_imagery/drone_run_bands?select_checkbox_name=drone_run_standard_process_interactive_band_select&drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id
1401         });
1403     });
1405     jQuery('#manage_drone_imagery_standard_process_interactive_select_drone_run_band_step').click(function(){
1406         var selected = [];
1407         jQuery('input[name="drone_run_standard_process_interactive_band_select"]:checked').each(function() {
1408             selected.push(jQuery(this).val());
1409         });
1410         if (selected.length > 1 || selected.length == 0) {
1411             alert('Please select one band!');
1412             return false;
1413         }
1414         manage_drone_imagery_standard_process_interactive_drone_run_band_project_id = selected[0];
1416         jQuery.ajax({
1417             url : '/api/drone_imagery/separate_drone_imagery_gps?drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
1418             success: function(response){
1419                 console.log(response);
1421                 var html = '<table class="table table-hover table-bordered"><thead><tr><th>Imaging Pass Number</th><th>Number of Captures</th></tr></thead><tbody>';
1422                 for (var i=0; i<response.results.length; i++) {
1423                     html = html + '<tr><td>'+response.results[i][0]+'</td><td>'+response.results[i][1]+'</td></tr>';
1424                 }
1425                 html = html + '</tbody></table>'
1426                 jQuery('#manage_drone_imagery_standard_process_interactive_separated_passes_info').html(html);
1428                 Workflow.complete("#manage_drone_imagery_standard_process_interactive_select_drone_run_band_step");
1429                 Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 2);
1431                 window.scrollTo(0,0);
1432             },
1433             error: function(response){
1434                 alert('Error separate micasense stacks!');
1435             }
1436         });
1437     });
1439     jQuery('#manage_drone_imagery_standard_process_interactive_separated_passes_step').click(function(){
1440         project_drone_imagery_interactive_ground_control_points_saved_div_table = 'project_drone_imagery_standard_process_interactive_ground_control_points_saved_div';
1442         jQuery.ajax({
1443             url : '/api/drone_imagery/get_drone_imagery_gps?drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id+'&flight_pass_counter='+manage_drone_imagery_standard_process_raw_images_interactive_current_pass,
1444             success: function(response){
1445                 console.log(response);
1447                 get_select_box('drone_runs_with_gcps', 'manage_drone_imagery_standard_process_interactive_ground_control_points_select', {'id':'manage_drone_imagery_standard_process_interactive_ground_control_points_select_id', 'name':'manage_drone_imagery_standard_process_interactive_ground_control_points_select_id', 'field_trial_id':manage_drone_imagery_standard_process_raw_images_interactive_field_trial_id, 'empty':1});
1449                 jQuery.ajax({
1450                     url : '/api/drone_imagery/get_image_for_saving_gcp?drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
1451                     success: function(response){
1452                         console.log(response);
1454                         project_drone_imagery_interactive_ground_control_points_saved = response.saved_gcps_full;
1455                         project_drone_imagery_interactive_ground_control_points_saved_array = response.gcps_array;
1456                         _redraw_ground_control_points_table_interactive();
1457                     },
1458                     error: function(response){
1459                         alert('Error getting standard process interactive gcps!');
1460                     }
1461                 });
1463                 manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass = response.max_flight_pass_counter;
1465                 if (response.all_passes_rotated == 1) {
1466                     console.log("ROTATION COMPLETE SEPARATED STEP");
1468                     manage_drone_imagery_standard_process_raw_images_interactive_current_pass = 1;
1470                     jQuery('#drone_imagery_standard_process_interactive_plot_polygons_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
1472                     initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div', 'drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area', 1, 1);
1474                     Workflow.complete("#manage_drone_imagery_standard_process_interactive_separated_passes_step");
1475                     Workflow.complete("#manage_drone_imagery_standard_process_interactive_rotate_step");
1476                     Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 4);
1477                 }
1478                 else {
1479                     console.log("Initial");
1480                     initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div', 'drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_area', 1, 0);
1482                     manage_drone_imagery_standard_process_raw_images_interactive_current_pass = 1;
1484                     jQuery('#drone_imagery_standard_process_interactive_rotate_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
1486                     Workflow.complete("#manage_drone_imagery_standard_process_interactive_separated_passes_step");
1487                     Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 3);
1488                 }
1489                 window.scrollTo(0,0);
1490             },
1491             error: function(response){
1492                 alert('Error check rotation!');
1493             }
1494         });
1495     });
1497     jQuery('#manage_drone_imagery_standard_process_interactive_ground_control_points_option').change(function(){
1498         if (jQuery(this).val() == 'Yes') {
1499             jQuery('#manage_drone_imagery_standard_process_interactive_ground_control_points_select_div').show();
1501             //Change click type to save ground control points
1502         }
1503         else {
1504             jQuery('#manage_drone_imagery_standard_process_interactive_ground_control_points_select_div').hide();
1505         }
1506     });
1508     function _redraw_ground_control_points_table_interactive() {
1509         var html = "<table class='table table-bordered table-hover'><thead><tr><th>Saved GCP Name</th><th>X Pos</th><th>Y Pos</th><th>Latitude</th><th>Longitude</th><th>Remove</th></thead><tbody>";
1510         for (var i=0; i<project_drone_imagery_interactive_ground_control_points_saved_array.length; i++) {
1511             html = html + "<tr><td>"+project_drone_imagery_interactive_ground_control_points_saved_array[i]['name']+"</td><td>"+project_drone_imagery_interactive_ground_control_points_saved_array[i]['x_pos']+"</td><td>"+project_drone_imagery_interactive_ground_control_points_saved_array[i]['y_pos']+"</td><td>"+project_drone_imagery_interactive_ground_control_points_saved_array[i]['latitude']+"</td><td>"+project_drone_imagery_interactive_ground_control_points_saved_array[i]['longitude']+"</td><td><p style='color:red' name='project_drone_imagery_interactive_ground_control_points_delete_one' data-name='"+project_drone_imagery_interactive_ground_control_points_saved_array[i]['name']+"' data-drone_run_project_id="+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id+" >X</p></td></tr>";
1512         }
1513         html = html + "</tbody></table>";
1514         html = html + "<button class='btn btn-default' name='project_drone_imagery_interactive_ground_control_points_draw_points'>Draw Saved GCPs</button>";
1515         jQuery('#'+project_drone_imagery_interactive_ground_control_points_saved_div_table).html(html);
1516     }
1518     jQuery(document).on('click', 'p[name="project_drone_imagery_interactive_ground_control_points_delete_one"]', function(){
1519         var drone_run_project_id = jQuery(this).data('drone_run_project_id');
1520         var name = jQuery(this).data('name');
1522         if (confirm("Remove this GCP?")) {
1523             jQuery.ajax({
1524                 type: 'POST',
1525                 url: '/api/drone_imagery/remove_one_gcp',
1526                 data: {
1527                     'drone_run_project_id' : drone_run_project_id,
1528                     'name' : name,
1529                 },
1530                 success: function(response){
1531                     console.log(response);
1532                     if (response.error) {
1533                         alert(response.error);
1534                     }
1535                     project_drone_imagery_interactive_ground_control_points_saved = response.saved_gcps_full;
1536                     project_drone_imagery_interactive_ground_control_points_saved_array = response.gcps_array;
1537                     _redraw_ground_control_points_table_interactive();
1538                 },
1539                 error: function(response){
1540                     alert('Error deleting GCP name!');
1541                 }
1542             });
1543         }
1544     });
1546     d3.select("#drone_imagery_standard_process_raw_images_interactive_rotate_degrees_input").on("input", function() {
1547         manage_drone_imagery_standard_process_raw_images_interactive_rotate_angle = this.value;
1548         droneImageryInteractiveRotateImages(manage_drone_imagery_standard_process_raw_images_interactive_rotate_angle, 0, '#drone_imagery_standard_process_raw_images_interactive_bulk_rotate_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass);
1549     });
1551     jQuery('#drone_imagery_standard_process_raw_images_interactive_north_south_input').change(function(){
1552         manage_drone_imagery_standard_process_raw_images_interactive_north_or_south = jQuery(this).val();
1553         jQuery.ajax({
1554             url : '/api/drone_imagery/delete_gps_images',
1555             type: 'POST',
1556             data : {
1557                 'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id
1558             },
1559             success: function(response){
1560                 console.log(response);
1561                 manage_drone_imagery_standard_process_raw_images_nir_image_counter = 0;
1562                 initializeImagesInteractive(1, '#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass);
1563             },
1564             error: function(response){
1565                 alert('Error deleting GPS images template from NS step!')
1566             }
1567         });
1568     });
1570     jQuery('#drone_imagery_standard_process_raw_images_interactive_east_or_west').change(function(){
1571         manage_drone_imagery_standard_process_raw_images_interactive_east_or_west = jQuery(this).val();
1572         jQuery.ajax({
1573             url : '/api/drone_imagery/delete_gps_images',
1574             type: 'POST',
1575             data : {
1576                 'drone_run_project_id':manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id
1577             },
1578             success: function(response){
1579                 console.log(response);
1580                 manage_drone_imagery_standard_process_raw_images_nir_image_counter = 0;
1581                 initializeImagesInteractive(1, '#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass);
1582             },
1583             error: function(response){
1584                 alert('Error deleting GPS images template from EW step!')
1585             }
1586         });
1587     });
1589     d3.select("#drone_imagery_standard_process_raw_images_interactive_rotate_frame_degrees_input").on("input", function() {
1590         manage_drone_imagery_standard_process_raw_images_interactive_rotate_frame_angle = this.value;
1591         d3.select("svg").attr('transform',function(){
1592                 var x1 = d3.select("svg").attr("width")/2;
1593                 var y1 = d3.select("svg").attr("height")/2;
1594                 return `rotate(${manage_drone_imagery_standard_process_raw_images_interactive_rotate_frame_angle}, ${x1}, ${y1})`;
1595             });
1596     });
1598     jQuery('#drone_imagery_plot_polygons_top_left_click_raw_images_interactive').click(function(){
1599         alert('Now click the top left corner of your field on the image below.');
1601         d3.selectAll("g").on('mousedown.drag', null);
1603         manage_drone_imagery_standard_process_raw_images_interactive_svg.on("click", function(){
1604             var current_pos = d3.mouse(this);
1605             jQuery('#drone_imagery_plot_polygons_left_column_top_offset_raw_images_interactive').val(current_pos[1]);
1606             jQuery('#drone_imagery_plot_polygons_top_row_left_offset_raw_images_interactive').val(current_pos[0]);
1607             console.log(current_pos);
1609             d3.selectAll("g").call(d3.drag()
1610                 .on("start", dragstarted)
1611                 .on("drag", dragged)
1612                 .on("end", dragended));
1613         });
1614     });
1615     jQuery('#drone_imagery_plot_polygons_top_right_click_raw_images_interactive').click(function(){
1616         alert('Now click the top right corner of your field on the image below.');
1618         d3.selectAll("g").on('mousedown.drag', null);
1620         manage_drone_imagery_standard_process_raw_images_interactive_svg.on("click", function(){
1621             var current_pos = d3.mouse(this);
1622             jQuery('#drone_imagery_plot_polygons_top_row_right_offset_raw_images_interactive').val(drone_imagery_interactive_total_width-current_pos[0]);
1623             console.log(current_pos);
1625             d3.selectAll("g").call(d3.drag()
1626                 .on("start", dragstarted)
1627                 .on("drag", dragged)
1628                 .on("end", dragended));
1629         });
1630     });
1631     jQuery('#drone_imagery_plot_polygons_bottom_left_click_raw_images_interactive').click(function(){
1632         alert('Now click the bottom left corner of your field on the image below.');
1634         d3.selectAll("g").on('mousedown.drag', null);
1636         manage_drone_imagery_standard_process_raw_images_interactive_svg.on("click", function(){
1637             var current_pos = d3.mouse(this);
1638             jQuery('#drone_imagery_plot_polygons_bottom_row_left_offset_raw_images_interactive').val(current_pos[0]);
1639             jQuery('#drone_imagery_plot_polygons_left_column_bottom_offset_raw_images_interactive').val(drone_imagery_interactive_total_length-current_pos[1]);
1640             console.log(current_pos);
1642             d3.selectAll("g").call(d3.drag()
1643                 .on("start", dragstarted)
1644                 .on("drag", dragged)
1645                 .on("end", dragended));
1646         });
1647     });
1648     jQuery('#drone_imagery_plot_polygons_bottom_right_click_raw_images_interactive').click(function(){
1649         alert('Now click the bottom right corner of your field on the image below.');
1651         d3.selectAll("g").on('mousedown.drag', null);
1653         manage_drone_imagery_standard_process_raw_images_interactive_svg.on("click", function(){
1654             var current_pos = d3.mouse(this);
1655             jQuery('#drone_imagery_plot_polygons_right_col_bottom_offset_raw_images_interactive').val(drone_imagery_interactive_total_length-current_pos[1]);
1656             console.log(current_pos);
1658             d3.selectAll("g").call(d3.drag()
1659                 .on("start", dragstarted)
1660                 .on("drag", dragged)
1661                 .on("end", dragended));
1662         });
1663     });
1665     jQuery('#drone_imagery_plot_polygons_rectangles_apply_raw_images_interactive').click(function() {
1666         plot_polygons_interactive_display_points = [];
1667         plot_polygons_interactive_ind_4_points = [];
1669         var num_rows_val = jQuery('#drone_imagery_plot_polygons_num_rows_raw_images_interactive').val();
1670         var num_cols_val = jQuery('#drone_imagery_plot_polygons_num_cols_raw_images_interactive').val();
1671         var section_top_row_left_offset_val = jQuery('#drone_imagery_plot_polygons_top_row_left_offset_raw_images_interactive').val();
1672         var section_bottom_row_left_offset_val = jQuery('#drone_imagery_plot_polygons_bottom_row_left_offset_raw_images_interactive').val();
1673         var section_left_column_top_offset_val = jQuery('#drone_imagery_plot_polygons_left_column_top_offset_raw_images_interactive').val();
1674         var section_left_column_bottom_offset_val = jQuery('#drone_imagery_plot_polygons_left_column_bottom_offset_raw_images_interactive').val();
1675         var section_top_row_right_offset_val = jQuery('#drone_imagery_plot_polygons_top_row_right_offset_raw_images_interactive').val();
1676         var section_right_column_bottom_offset_val = jQuery('#drone_imagery_plot_polygons_right_col_bottom_offset_raw_images_interactive').val();
1678         plotPolygonsRectanglesApplyInteractive(num_rows_val, num_cols_val, section_top_row_left_offset_val, section_bottom_row_left_offset_val, section_left_column_top_offset_val, section_left_column_bottom_offset_val, section_top_row_right_offset_val, section_right_column_bottom_offset_val, drone_imagery_interactive_total_width, drone_imagery_interactive_total_length, 'drone_imagery_interactive_generated_polygons_div');
1680         plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
1682         jQuery('#drone_imagery_standard_process_interactive_generated_polygons_input_div').show();
1683     });
1685     var drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_counter = 0;
1686     var drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_left_offset_val = 0;
1687     var drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_bottom_row_left_offset_val = 0;
1688     var drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_top_offset_val = 0;
1689     var drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_bottom_offset_val = 0;
1690     var drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_right_offset_val = 0;
1691     var drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_right_column_bottom_offset_val = 0;
1693     jQuery('#drone_imagery_plot_polygons_rectangles_apply_square_average_raw_images_interactive').click(function() {
1694         alert('Click the four corners of 10 single plots at random in the current imaging pass. For each single plot click the top left, then the top right, then the bottom right, then the bottom left.');
1696     });
1698     jQuery('#drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive').click(function() {
1699         plot_polygons_interactive_display_points = [];
1700         plot_polygons_interactive_ind_4_points = [];
1702         var num_rows_val = jQuery('#drone_imagery_plot_polygons_num_rows_raw_images_interactive').val();
1703         var num_cols_val = jQuery('#drone_imagery_plot_polygons_num_cols_raw_images_interactive').val();
1704         var section_top_row_left_offset_val = jQuery('#drone_imagery_plot_polygons_top_row_left_offset_raw_images_interactive').val();
1705         var section_bottom_row_left_offset_val = jQuery('#drone_imagery_plot_polygons_bottom_row_left_offset_raw_images_interactive').val();
1706         var section_left_column_top_offset_val = jQuery('#drone_imagery_plot_polygons_left_column_top_offset_raw_images_interactive').val();
1707         var section_left_column_bottom_offset_val = jQuery('#drone_imagery_plot_polygons_left_column_bottom_offset_raw_images_interactive').val();
1708         var section_top_row_right_offset_val = jQuery('#drone_imagery_plot_polygons_top_row_right_offset_raw_images_interactive').val();
1709         var section_right_column_bottom_offset_val = jQuery('#drone_imagery_plot_polygons_right_col_bottom_offset_raw_images_interactive').val();
1711         if (num_rows_val == ''){
1712             alert('Please give the number of rows!');
1713             return;
1714         }
1715         if (num_cols_val == ''){
1716             alert('Please give the number of columns!');
1717             return;
1718         }
1719         if (section_top_row_left_offset_val == ''){
1720             alert('Please give the top-most rows left margin! This can be 0 if there is no offset.');
1721             return;
1722         }
1723         if (section_bottom_row_left_offset_val == ''){
1724             alert('Please give the bottom-most rows left margin! This can be 0 if there is no offset.');
1725             return;
1726         }
1727         if (section_left_column_top_offset_val == ''){
1728             alert('Please give the left-most columns top margin! This can be 0 if there is no offset.');
1729             return;
1730         }
1731         if (section_left_column_bottom_offset_val == ''){
1732             alert('Please give the left-most columns bottom margin! This can be 0 if there is no offset.');
1733             return;
1734         }
1735         if (section_top_row_right_offset_val == ''){
1736             alert('Please give the top-most rows right margin! This can be 0 if there is no offset.');
1737             return;
1738         }
1739         if (section_right_column_bottom_offset_val == ''){
1740             alert('Please give the right-most columns bottom margin! This can be 0 if there is no offset.');
1741             return;
1742         }
1744         if (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_counter > 0) {
1745             drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_left_offset_val = (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_left_offset_val + parseInt(section_top_row_left_offset_val))/2;
1746             drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_bottom_row_left_offset_val = (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_bottom_row_left_offset_val + parseInt(section_bottom_row_left_offset_val))/2;
1747             drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_top_offset_val = (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_top_offset_val + parseInt(section_left_column_top_offset_val))/2;
1748             drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_bottom_offset_val = (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_bottom_offset_val + parseInt(section_left_column_bottom_offset_val))/2;
1749             drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_right_offset_val = (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_right_offset_val + parseInt(section_top_row_right_offset_val))/2;
1750             drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_right_column_bottom_offset_val = (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_right_column_bottom_offset_val + parseInt(section_right_column_bottom_offset_val))/2;
1751         }
1752         drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_counter = drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_counter + 1;
1754         if (drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_counter < 10) {
1755             alert('Click the boundaries of another plot. You need to click atleast 10 to get a good average. Completed: '+drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_counter);
1756             return false;
1757         }
1759         plotPolygonsRectanglesApplySquareInteractive(num_rows_val, num_cols_val, drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_left_offset_val, drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_bottom_row_left_offset_val, drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_top_offset_val, drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_left_column_bottom_offset_val, drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_top_row_right_offset_val, drone_imagery_plot_polygons_rectangles_apply_square_raw_images_interactive_section_right_column_bottom_offset_val, drone_imagery_interactive_total_width, drone_imagery_interactive_total_length, 'drone_imagery_interactive_generated_polygons_div');
1760     });
1762     function plotPolygonManualAssignPlotNumberTable(div_id, table_id, input_name, generate_assign_button, save_button) {
1763         var html = '<div class="panel panel-default"><div class="panel-body">';
1764         html = html + '<table class="table table-bordered table-hover" id="'+table_id+'"><thead><tr><th>Polygon Number</th><th>Plot Number</th></tr></thead><tbody>';
1765         for(var i=0; i<drone_imagery_interactive_plot_generated_polygons.length; i++) {
1766             html = html + '<tr><td>'+i+'</td><td><input type="number" class="form-control" data-polygon_number="'+i+'" name="'+input_name+'" /></td></tr>';
1767         }
1768         html = html + '</tbody></table><hr>';
1769         html = html + '<button class="btn btn-primary" id="'+generate_assign_button+'">Generate Assignments From Manual Input (Does Not Save)</button>&nbsp;&nbsp;&nbsp;<button class="btn btn-primary" name="'+save_button+'">Finish and Save Polygons To Plots. Go to Next Imaging Pass.</button></div></div>';
1771         jQuery('#'+div_id).html(html);
1772         jQuery('#'+table_id).DataTable({'paging':false});
1773     }
1775     function drawPolylineInteractive(points){
1776         if (points.length == 4) {
1777             points.push(points[0]);
1778         }
1779         for(var i=0;i<points.length-1;i++){
1780             manage_drone_imagery_standard_process_raw_images_interactive_svg.append('line')
1781                 .style("stroke", "blue")
1782                 .style("stroke-width", 5)
1783                 .attr("x1", points[i].x)
1784                 .attr("y1", points[i].y)
1785                 .attr("x2", points[i+1].x)
1786                 .attr("y2", points[i+1].y);
1787         }
1788     }
1790     function drawWaypointsInteractive(points, label, random_factor){
1791         var plot_polygon_random_number = Math.random() * random_factor;
1792         if (points.length > 0 && label != undefined) {
1793             if (drone_imagery_interactive_plot_polygons_removed_numbers.includes(label)) {
1794                 manage_drone_imagery_standard_process_raw_images_interactive_svg.append("text")
1795                     .attr("x", points[0].x + 3)
1796                     .attr("y", points[0].y + 14 + plot_polygon_random_number)
1797                     .text('NA')
1798                     .attr("font-family", "Arial")
1799                     .attr("font-size", "18px")
1800                     .attr("fill", "blue");
1801             } else {
1802                 manage_drone_imagery_standard_process_raw_images_interactive_svg.append("text")
1803                     .attr("x", points[0].x + 3)
1804                     .attr("y", points[0].y + 14 + plot_polygon_random_number)
1805                     .text(label)
1806                     .attr("font-family", "Arial")
1807                     .attr("font-size", "18px")
1808                     .attr("fill", "red");
1809             }
1810         }
1811         //for(var i=0;i<points.length;i++){
1812         //    manage_drone_imagery_standard_process_raw_images_interactive_svg.append("circle")
1813         //        .attr("cx", points[i].x)
1814         //        .attr("cy", points[i].y)
1815         //        .attr("r", 4)
1816         //        .attr("fill", "blue");
1817         //}
1818     }
1820     function droneImageryDrawPlotPolygonActiveTemplatesTableInteractive(div_id, plot_polygons_template_dimensions){
1821         var html = '<table class="table table-bordered table-hover"><thead><tr><th>Template Number</th><th>Rows</th><th>Columns</th><th>Total Polygons</th><th>Options</th></tr></thead><tbody>';
1822         for (var i=0; i<plot_polygons_template_dimensions.length; i++) {
1823             html = html + '<tr><td>'+i+'</td><td>'+plot_polygons_template_dimensions[i]['num_rows']+'</td><td>'+plot_polygons_template_dimensions[i]['num_cols']+'</td><td>'+plot_polygons_template_dimensions[i]['total_plot_polygons']+'</td><td><button class="btn btn-sm btn-primary" name="drone_imagery_plot_polygon_template_options_interactive" data-plot_polygon_template_id="'+i+'" >Options</button></td></tr>';
1824         }
1825         html = html + '</tbody></table>';
1826         jQuery('#'+div_id).html(html);
1827     }
1829     function plotPolygonsRectanglesApplyInteractive(num_rows_val, num_cols_val, section_top_row_left_offset_val, section_bottom_row_left_offset_val, section_left_column_top_offset_val, section_left_column_bottom_offset_val, section_top_row_right_offset_val, section_right_column_bottom_offset_val, section_width, section_height, plot_polygons_assignment_info) {
1830         if (num_rows_val == ''){
1831             alert('Please give the number of rows!');
1832             return;
1833         }
1834         if (num_cols_val == ''){
1835             alert('Please give the number of columns!');
1836             return;
1837         }
1838         if (section_top_row_left_offset_val == ''){
1839             alert('Please give the top-most rows left margin! This can be 0 if there is no offset.');
1840             return;
1841         }
1842         if (section_bottom_row_left_offset_val == ''){
1843             alert('Please give the bottom-most rows left margin! This can be 0 if there is no offset.');
1844             return;
1845         }
1846         if (section_left_column_top_offset_val == ''){
1847             alert('Please give the left-most columns top margin! This can be 0 if there is no offset.');
1848             return;
1849         }
1850         if (section_left_column_bottom_offset_val == ''){
1851             alert('Please give the left-most columns bottom margin! This can be 0 if there is no offset.');
1852             return;
1853         }
1854         if (section_top_row_right_offset_val == ''){
1855             alert('Please give the top-most rows right margin! This can be 0 if there is no offset.');
1856             return;
1857         }
1858         if (section_right_column_bottom_offset_val == ''){
1859             alert('Please give the right-most columns bottom margin! This can be 0 if there is no offset.');
1860             return;
1861         }
1863         plot_polygons_interactive_num_rows_generated = parseInt(num_rows_val);
1864         plot_polygons_interactive_num_cols_generated = parseInt(num_cols_val);
1866         var section_top_row_left_offset = parseInt(section_top_row_left_offset_val);
1867         var section_bottom_row_left_offset = parseInt(section_bottom_row_left_offset_val);
1868         var section_left_column_top_offset = parseInt(section_left_column_top_offset_val);
1869         var section_left_column_bottom_offset = parseInt(section_left_column_bottom_offset_val);
1870         var section_top_row_right_offset = parseInt(section_top_row_right_offset_val);
1871         var section_right_column_bottom_offset = parseInt(section_right_column_bottom_offset_val);
1873         var total_gradual_left_shift = section_bottom_row_left_offset - section_top_row_left_offset;
1874         var col_left_shift_increment = total_gradual_left_shift / plot_polygons_interactive_num_rows_generated;
1876         var total_gradual_vertical_shift = section_right_column_bottom_offset - section_left_column_bottom_offset;
1877         var col_vertical_shift_increment = total_gradual_vertical_shift / plot_polygons_interactive_num_cols_generated;
1879         var col_width = (section_width - section_top_row_left_offset - section_top_row_right_offset) / plot_polygons_interactive_num_cols_generated;
1880         var row_height = (section_height - section_left_column_top_offset - section_left_column_bottom_offset) / plot_polygons_interactive_num_rows_generated;
1882         var x_pos = section_top_row_left_offset;
1883         var y_pos = section_left_column_top_offset;
1885         manage_drone_imagery_standard_process_raw_images_interactive_svg = d3.select('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass);
1887         var row_num = 1;
1888         for (var i=0; i<plot_polygons_interactive_num_rows_generated; i++) {
1889             for (var j=0; j<plot_polygons_interactive_num_cols_generated; j++) {
1890                 var x_pos_val = x_pos;
1891                 var y_pos_val = y_pos;
1892                 plot_polygons_interactive_generated_polygons.push([
1893                     {x:x_pos_val, y:y_pos_val},
1894                     {x:x_pos_val + col_width, y:y_pos_val},
1895                     {x:x_pos_val + col_width, y:y_pos_val + row_height},
1896                     {x:x_pos_val, y:y_pos_val + row_height}
1897                 ]);
1898                 x_pos = x_pos + col_width;
1899                 y_pos = y_pos - col_vertical_shift_increment;
1900             }
1901             x_pos = section_top_row_left_offset + (row_num * col_left_shift_increment);
1902             y_pos = y_pos + row_height + total_gradual_vertical_shift;
1903             row_num = row_num + 1;
1904         }
1905         console.log(plot_polygons_interactive_generated_polygons);
1907         plot_polygons_interactive_total_height_generated = row_height * plot_polygons_interactive_num_rows_generated;
1908         plot_polygons_interactive_number_generated = plot_polygons_interactive_generated_polygons.length;
1910         var drone_imagery_plot_polygons_new = [];
1911         var drone_imagery_plot_polygons_display_new = [];
1913         for (var i=0; i<plot_polygons_interactive_generated_polygons.length; i++) {
1914             plot_polygons_interactive_ind_4_points = plot_polygons_interactive_generated_polygons[i];
1915             plot_polygons_interactive_display_points = plot_polygons_interactive_ind_4_points;
1916             if (plot_polygons_interactive_display_points.length == 4) {
1917                 plot_polygons_interactive_display_points.push(plot_polygons_interactive_ind_4_points[0]);
1918             }
1919             drawPolylineInteractive(plot_polygons_interactive_display_points);
1920             drawWaypointsInteractive(plot_polygons_interactive_display_points, i, 0);
1921             drone_imagery_interactive_plot_generated_polygons[i] = plot_polygons_interactive_ind_4_points;
1922             drone_imagery_plot_polygons_new[i] = plot_polygons_interactive_ind_4_points;
1923             drone_imagery_interactive_plot_polygons_display[i] = plot_polygons_interactive_display_points;
1924             drone_imagery_plot_polygons_display_new[i] = plot_polygons_interactive_display_points;
1925         }
1927         drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions.push({
1928             'num_rows':plot_polygons_interactive_num_rows_generated,
1929             'num_cols':plot_polygons_interactive_num_cols_generated,
1930             'total_plot_polygons':plot_polygons_interactive_num_rows_generated*plot_polygons_interactive_num_cols_generated,
1931             'plot_polygons':drone_imagery_plot_polygons_new,
1932             'plot_polygons_display':drone_imagery_plot_polygons_display_new
1933         });
1935         droneImageryDrawPlotPolygonActiveTemplatesTableInteractive('drone_imagery_plot_polygons_active_templates_raw_images_interactive', drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions);
1937         droneImageryDrawRectangleTableInteractive('drone_imagery_interactive_generated_polygons_div', 'drone_imagery_standard_process_interactive_plot_polygons_generated_assign', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
1938     }
1940     function plotPolygonsRectanglesApplySquareInteractive(num_rows_val, num_cols_val, section_top_row_left_offset_val, section_bottom_row_left_offset_val, section_left_column_top_offset_val, section_left_column_bottom_offset_val, section_top_row_right_offset_val, section_right_column_bottom_offset_val, section_width, section_height, plot_polygons_assignment_info) {
1941         plot_polygons_interactive_num_rows_generated = parseInt(num_rows_val);
1942         plot_polygons_interactive_num_cols_generated = parseInt(num_cols_val);
1944         var section_top_row_left_offset = parseInt(section_top_row_left_offset_val);
1945         var section_bottom_row_left_offset = parseInt(section_bottom_row_left_offset_val);
1946         var section_left_column_top_offset = parseInt(section_left_column_top_offset_val);
1947         var section_left_column_bottom_offset = parseInt(section_left_column_bottom_offset_val);
1948         var section_top_row_right_offset = parseInt(section_top_row_right_offset_val);
1949         var section_right_column_bottom_offset = parseInt(section_right_column_bottom_offset_val);
1951         var total_gradual_left_shift = section_bottom_row_left_offset - section_top_row_left_offset;
1952         var col_left_shift_increment = total_gradual_left_shift / plot_polygons_interactive_num_rows_generated;
1954         var total_gradual_vertical_shift = section_right_column_bottom_offset - section_left_column_bottom_offset;
1955         var col_vertical_shift_increment = total_gradual_vertical_shift / plot_polygons_interactive_num_cols_generated;
1957         var col_width = (section_width - section_top_row_left_offset - section_top_row_right_offset);
1958         var row_height = (section_height - section_left_column_top_offset - section_left_column_bottom_offset);
1960         var x_pos = section_top_row_left_offset;
1961         var y_pos = section_left_column_top_offset;
1963         manage_drone_imagery_standard_process_raw_images_interactive_svg = d3.select('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass);
1965         var row_num = 1;
1966         var plot_polygons_interactive_generated_polygons_intermediate = [];
1967         for (var i=0; i<plot_polygons_interactive_num_rows_generated; i++) {
1968             for (var j=0; j<plot_polygons_interactive_num_cols_generated; j++) {
1969                 var x_pos_val = x_pos;
1970                 var y_pos_val = y_pos;
1971                 plot_polygons_interactive_generated_polygons_intermediate.push([
1972                     {x:x_pos_val, y:y_pos_val},
1973                     {x:x_pos_val + col_width, y:y_pos_val},
1974                     {x:x_pos_val + col_width, y:y_pos_val + row_height},
1975                     {x:x_pos_val, y:y_pos_val + row_height}
1976                 ]);
1977                 x_pos = x_pos + col_width;
1978                 y_pos = y_pos - col_vertical_shift_increment;
1979             }
1980             x_pos = section_top_row_left_offset + (row_num * col_left_shift_increment);
1981             y_pos = y_pos + row_height + total_gradual_vertical_shift;
1982             row_num = row_num + 1;
1983         }
1984         console.log(plot_polygons_interactive_generated_polygons_intermediate);
1986         alert('Click on where the top left corner of the template will be pasted in the current imaging event pass.');
1988         d3.selectAll("g").on('mousedown.drag', null);
1990         d3.select("#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_"+manage_drone_imagery_standard_process_raw_images_interactive_current_pass).on("click", function(){
1991             var current_pos = d3.mouse(this);
1993             d3.selectAll("g").call(d3.drag()
1994                 .on("start", dragstarted)
1995                 .on("drag", dragged)
1996                 .on("end", dragended));
1998             var plot_polygon_top_left_position = plot_polygons_interactive_generated_polygons_intermediate[0][0];
1999             var plot_polygon_template_paste_x_diff = plot_polygon_top_left_position['x'] - current_pos[0];
2000             var plot_polygon_template_paste_y_diff = plot_polygon_top_left_position['y'] - current_pos[1];
2002             for (var i in plot_polygons_interactive_generated_polygons_intermediate) {
2003                 plot_polygons_interactive_generated_polygons.push([
2004                     {x:plot_polygons_interactive_generated_polygons_intermediate[i][0]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_interactive_generated_polygons_intermediate[i][0]['y']- plot_polygon_template_paste_y_diff},
2005                     {x:plot_polygons_interactive_generated_polygons_intermediate[i][1]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_interactive_generated_polygons_intermediate[i][1]['y'] - plot_polygon_template_paste_y_diff},
2006                     {x:plot_polygons_interactive_generated_polygons_intermediate[i][2]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_interactive_generated_polygons_intermediate[i][2]['y'] - plot_polygon_template_paste_y_diff},
2007                     {x:plot_polygons_interactive_generated_polygons_intermediate[i][3]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_interactive_generated_polygons_intermediate[i][3]['y'] - plot_polygon_template_paste_y_diff}
2008                 ]);
2009             }
2010             console.log(plot_polygons_interactive_generated_polygons);
2012             plot_polygons_interactive_total_height_generated = row_height * plot_polygons_interactive_num_rows_generated;
2013             plot_polygons_interactive_number_generated = plot_polygons_interactive_generated_polygons.length;
2015             var drone_imagery_plot_polygons_new = [];
2016             var drone_imagery_plot_polygons_display_new = [];
2018             for (var i=0; i<plot_polygons_interactive_generated_polygons.length; i++) {
2019                 plot_polygons_interactive_ind_4_points = plot_polygons_interactive_generated_polygons[i];
2020                 plot_polygons_interactive_display_points = plot_polygons_interactive_ind_4_points;
2021                 if (plot_polygons_interactive_display_points.length == 4) {
2022                     plot_polygons_interactive_display_points.push(plot_polygons_interactive_ind_4_points[0]);
2023                 }
2024                 drawPolylineInteractive(plot_polygons_interactive_display_points);
2025                 drawWaypointsInteractive(plot_polygons_interactive_display_points, i, 0);
2026                 drone_imagery_interactive_plot_generated_polygons[i] = plot_polygons_interactive_ind_4_points;
2027                 drone_imagery_plot_polygons_new[i] = plot_polygons_interactive_ind_4_points;
2028                 drone_imagery_interactive_plot_polygons_display[i] = plot_polygons_interactive_display_points;
2029                 drone_imagery_plot_polygons_display_new[i] = plot_polygons_interactive_display_points;
2030             }
2032             drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions.push({
2033                 'num_rows':plot_polygons_interactive_num_rows_generated,
2034                 'num_cols':plot_polygons_interactive_num_cols_generated,
2035                 'total_plot_polygons':plot_polygons_interactive_num_rows_generated*plot_polygons_interactive_num_cols_generated,
2036                 'plot_polygons':drone_imagery_plot_polygons_new,
2037                 'plot_polygons_display':drone_imagery_plot_polygons_display_new
2038             });
2040             droneImageryDrawPlotPolygonActiveTemplatesTableInteractive('drone_imagery_plot_polygons_active_templates_raw_images_interactive', drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions);
2042             droneImageryDrawRectangleTableInteractive('drone_imagery_interactive_generated_polygons_div', 'drone_imagery_standard_process_interactive_plot_polygons_generated_assign', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2044             plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2045         });
2046     }
2048     function showPlotPolygonTableStartInteractive(trial_id){
2049         jQuery.ajax({
2050             url : '/ajax/breeders/trial/'+trial_id+'/layout_table',
2051             success: function(response){
2052                 console.log(response);
2053                 drone_imagery_interactive_field_trial_layout_response = response;
2054                 var layout = drone_imagery_interactive_field_trial_layout_response.output;
2055                 for (var i=1; i<layout.length; i++) {
2056                     drone_imagery_interactive_plot_polygons_available_stock_names.push(layout[i][0]);
2057                 }
2059                 droneImageryDrawRectangleTableInteractive('drone_imagery_interactive_generated_polygons_div', 'drone_imagery_standard_process_interactive_plot_polygons_generated_assign', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2061                 droneImageryDrawLayoutTableInteractive(response, {}, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
2062             },
2063             error: function(response){
2064                 alert('Error retrieving trial layout and design!')
2065             }
2066         });
2067     }
2069     function droneImageryDrawLayoutTableInteractive(response, plot_polygons, layout_div_id, layout_table_div_id) {
2070         var output = response.output;
2071         var header = output[0];
2072         var html = '<table class="table table-borders table-hover" id="'+layout_table_div_id+'"><thead><tr>';
2073         for (var i=0; i<header.length; i++){
2074             html = html + '<td>'+header[i]+'</td>';
2075         }
2076         html = html + '<td>Polygon Assigned</td>';
2077         html = html + '</tr></thead><tbody>';
2078         for (var i=1; i<output.length; i++){
2079             html = html + '<tr>';
2080             for (var j=0; j<output[i].length; j++){
2081                 html = html + '<td>'+output[i][j]+'</td>';
2082             }
2083             if (output[i][0] in plot_polygons && plot_polygons[output[i][0]] != undefined){
2084                 html = html + '<td>Yes</td>';
2085             } else {
2086                 html = html + '<td></td>';
2087             }
2088             html = html + '</tr>';
2089         }
2090         html = html + '</tbody></table>';
2091         jQuery('#'+layout_div_id).html(html);
2092         jQuery('#'+layout_table_div_id).DataTable();
2093     }
2095     function droneImageryDrawRectangleTableInteractive(plot_polygons_layout_assignment_info, plot_polygons_generate_assignment_button, plot_polygon_assignment_submit_button) {
2096         var html = '<hr><div class="well well-sm"><h2>Or Auto Assign Plot Polygons to Plot Numbers</h2>';
2097         html = html + '<div class="panel panel-default"><div class="panel-body"><div class="form form-horizontal">';
2098         html = html + '<div class="row"><div class="col-sm-6"><div class="form-group form-group-sm"><label class="col-sm-6 control-label">Location of First Plot (e.g. plot number 1): </label><div class="col-sm-6"><select class="form-control" id="drone_imagery_interactive_plot_polygons_first_plot_start" name="drone_imagery_interactive_plot_polygons_first_plot_start"><option value="top_left">Top Left</option><option value="top_right">Top Right</option><option value="bottom_left" disabled>Bottom Left</option><option value="bottom_right" disabled>Bottom Right</option></select></div></div></div><div class="col-sm-6"><div class="form-group form-group-sm"><label class="col-sm-6 control-label">Second Plot Follows First Plot Going: </label><div class="col-sm-6"><select class="form-control" id="drone_imagery_interactive_plot_polygons_second_plot_follows" name="drone_imagery_interactive_plot_polygons_second_plot_follows"><option value="right">Right</option><option value="up">Up</option><option value="down">Down</option><option value="left">Left</option></select></div></div></div></div>';
2099         html = html + '<div class="row"><div class="col-sm-6"><div class="form-group form-group-sm"><label class="col-sm-6 control-label">Plot Number Orientation: </label><div class="col-sm-6"><select class="form-control" id="drone_imagery_interactive_plot_polygons_plot_orientation" name="drone_imagery_interactive_plot_polygons_plot_orientation"><option value="serpentine">Serpentine</option><option value="zigzag">Zigzag (Not Serpentine)</option></select></div></div></div><div class="col-sm-6"><div class="form-group form-group-sm"><label class="col-sm-6 control-label">Plot Number Start (optional): </label><div class="col-sm-6"><input type="number" class="form-control" id="drone_imagery_interactive_plot_polygons_plot_number_start" name="drone_imagery_interactive_plot_polygons_plot_number_start" placeholder="OPTIONAL" /></div></div></div></div>';
2100         html = html + '<button class="btn btn-primary" id="'+plot_polygons_generate_assignment_button+'">Generate Assignments (Does Not Save)</button>&nbsp;&nbsp;&nbsp;<button class="btn btn-primary" name="'+plot_polygon_assignment_submit_button+'">Finish and Save Polygons To Plots. Go to Next Imaging Pass.</button></div>';
2101         html = html + '</div></div></div></div>';
2103         jQuery('#'+plot_polygons_layout_assignment_info).html(html);
2104     }
2106     var drone_imagery_interactive_current_plot_polygon_index_options_id = '';
2107     jQuery(document).on('click', 'button[name="drone_imagery_plot_polygon_template_options_interactive"]', function(){
2108         jQuery('#drone_imagery_interactive_plot_polygon_template_options_dialog').modal('show');
2109         drone_imagery_interactive_current_plot_polygon_index_options_id = jQuery(this).data('plot_polygon_template_id');
2110     });
2112     jQuery('#drone_imagery_interactive_plot_polygon_template_options_paste_click').click(function(){
2113         jQuery('#drone_imagery_interactive_plot_polygon_template_options_dialog').modal('hide');
2114         alert('Click on where the top left corner of the template will be pasted.');
2116         d3.selectAll("g").on('mousedown.drag', null);
2118         d3.select("#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_"+manage_drone_imagery_standard_process_raw_images_interactive_current_pass).on("click", function(){
2119             var current_pos = d3.mouse(this);
2121             d3.selectAll("g").call(d3.drag()
2122                 .on("start", dragstarted)
2123                 .on("drag", dragged)
2124                 .on("end", dragended));
2126             plotPolygonsTemplatePasteInteractive(current_pos[0], current_pos[1], drone_imagery_interactive_total_width, drone_imagery_interactive_total_length, parseInt(drone_imagery_interactive_current_plot_polygon_index_options_id), 'drone_imagery_interactive_generated_polygons_div');
2128             plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2129         });
2130     });
2132     function plotPolygonsTemplatePasteInteractive(posx, posy, section_width, section_height, plot_polygon_template_id, plot_polygons_assignment_info) {
2133         var plot_polygon_template_to_paste = drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions[plot_polygon_template_id];
2135         var plot_polygons_previous_plot_polygons = plot_polygon_template_to_paste['plot_polygons'];
2136         plot_polygons_interactive_num_rows_generated = plot_polygon_template_to_paste['num_rows'];
2137         plot_polygons_interactive_num_cols_generated = plot_polygon_template_to_paste['num_cols'];
2139         var plot_polygon_top_left_position = plot_polygons_previous_plot_polygons[0][0];
2140         var plot_polygon_template_paste_x_diff = plot_polygon_top_left_position['x'] - posx;
2141         var plot_polygon_template_paste_y_diff = plot_polygon_top_left_position['y'] - posy;
2143         for (var i in plot_polygons_previous_plot_polygons) {
2144             plot_polygons_interactive_generated_polygons.push([
2145                 {x:plot_polygons_previous_plot_polygons[i][0]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_previous_plot_polygons[i][0]['y']- plot_polygon_template_paste_y_diff},
2146                 {x:plot_polygons_previous_plot_polygons[i][1]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_previous_plot_polygons[i][1]['y'] - plot_polygon_template_paste_y_diff},
2147                 {x:plot_polygons_previous_plot_polygons[i][2]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_previous_plot_polygons[i][2]['y'] - plot_polygon_template_paste_y_diff},
2148                 {x:plot_polygons_previous_plot_polygons[i][3]['x'] - plot_polygon_template_paste_x_diff, y:plot_polygons_previous_plot_polygons[i][3]['y'] - plot_polygon_template_paste_y_diff}
2149             ]);
2150         }
2152         plot_polygons_interactive_number_generated = plot_polygons_interactive_generated_polygons.length;
2153         console.log(plot_polygons_interactive_generated_polygons);
2155         var drone_imagery_plot_polygons_new = {};
2156         var drone_imagery_plot_polygons_display_new = {};
2158         for (var i=0; i<plot_polygons_interactive_generated_polygons.length; i++) {
2159             plot_polygons_interactive_ind_4_points = plot_polygons_interactive_generated_polygons[i];
2160             plot_polygons_interactive_display_points = plot_polygons_interactive_ind_4_points;
2161             if (plot_polygons_interactive_display_points.length == 4) {
2162                 plot_polygons_interactive_display_points.push(plot_polygons_interactive_ind_4_points[0]);
2163             }
2164             drawPolylineInteractive(plot_polygons_interactive_display_points);
2165             drawWaypointsInteractive(plot_polygons_interactive_display_points, i, 0);
2166             drone_imagery_interactive_plot_generated_polygons[i] = plot_polygons_interactive_ind_4_points;
2167             drone_imagery_plot_polygons_new[i] = plot_polygons_interactive_ind_4_points;
2168             drone_imagery_interactive_plot_polygons_display[i] = plot_polygons_interactive_display_points;
2169             drone_imagery_plot_polygons_display_new[i] = plot_polygons_interactive_display_points;
2170         }
2172         drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions.push({
2173             'num_rows':plot_polygons_interactive_num_rows_generated,
2174             'num_cols':plot_polygons_interactive_num_cols_generated,
2175             'total_plot_polygons':plot_polygons_interactive_num_rows_generated*plot_polygons_interactive_num_cols_generated,
2176             'plot_polygons':drone_imagery_plot_polygons_new,
2177             'plot_polygons_display':drone_imagery_plot_polygons_display_new
2178         });
2180         droneImageryDrawPlotPolygonActiveTemplatesTableInteractive('drone_imagery_plot_polygons_active_templates_raw_images_interactive', drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions);
2182         droneImageryDrawRectangleTableInteractive('drone_imagery_interactive_generated_polygons_div', 'drone_imagery_standard_process_interactive_plot_polygons_generated_assign', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2183     }
2185     jQuery(document).on('click', '#drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', function(){
2186         generatePlotPolygonAssignmentsInteractiveManual('drone_imagery_standard_process_trial_layout_div', 'drone_imagery_standard_process_layout_table');
2187     });
2189     function generatePlotPolygonAssignmentsInteractiveManual(trial_layout_div, trial_layout_table) {
2190         var plot_polygons_layout = drone_imagery_interactive_field_trial_layout_response.output;
2191         var plot_polygons_plot_numbers = [];
2192         var plot_polygons_plot_numbers_plot_names = {};
2193         for (var i=1; i<plot_polygons_layout.length; i++) {
2194             var plot_polygons_plot_number = parseInt(plot_polygons_layout[i][2]);
2195             plot_polygons_plot_numbers.push(plot_polygons_plot_number);
2196             plot_polygons_plot_numbers_plot_names[plot_polygons_plot_number] = plot_polygons_layout[i][0];
2197         }
2199         var plot_polygon_new_display = {};
2200         jQuery('input[name="drone_imagery_standard_process_interactive_generated_polygons_table_input"]').each(function() {
2201             var plot_number = jQuery(this).val();
2202             var polygon_number = jQuery(this).data('polygon_number');
2204             if (drone_imagery_interactive_plot_polygons_removed_numbers.includes(polygon_number.toString())) {
2205                 console.log("Skipping "+polygon_number);
2206                 plot_polygon_new_display[polygon_number] = drone_imagery_interactive_plot_polygons_display[polygon_number];
2207             } else {
2208                 plot_polygon_new_display[plot_polygons_plot_numbers_plot_names[plot_number]] = drone_imagery_interactive_plot_polygons_display[polygon_number];
2209                 drone_imagery_interactive_plot_polygons[plot_polygons_plot_numbers_plot_names[plot_number]] = drone_imagery_interactive_plot_generated_polygons[polygon_number];
2210             }
2211         });
2213         droneImageryDrawLayoutTableInteractive(drone_imagery_interactive_field_trial_layout_response, drone_imagery_interactive_plot_polygons, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
2215         drone_imagery_interactive_plot_polygons_display = plot_polygon_new_display;
2216         draw_canvas_image_interactive(plot_polygons_interactive_total_height_generated/plot_polygons_interactive_num_rows_generated);
2217     }
2219     jQuery(document).on('click', '#drone_imagery_standard_process_interactive_plot_polygons_generated_assign', function(){
2220         generatePlotPolygonAssignmentsInteractive('drone_imagery_standard_process_trial_layout_div', 'drone_imagery_standard_process_layout_table');
2221     });
2223     function generatePlotPolygonAssignmentsInteractive(trial_layout_div, trial_layout_table) {
2224         var plot_polygons_first_plot_start = jQuery('#drone_imagery_interactive_plot_polygons_first_plot_start').val();
2225         var plot_polygons_second_plot_follows = jQuery('#drone_imagery_interactive_plot_polygons_second_plot_follows').val();
2226         var plot_polygons_plot_orientation = jQuery('#drone_imagery_interactive_plot_polygons_plot_orientation').val();
2227         var plot_polygons_plot_number_start = jQuery('#drone_imagery_interactive_plot_polygons_plot_number_start').val();
2228         var plot_polygons_plot_number_start_int = 0;
2229         if (plot_polygons_plot_number_start != '') {
2230             plot_polygons_plot_number_start_int = parseInt(jQuery('#drone_imagery_interactive_plot_polygons_plot_number_start').val());
2231         }
2233         var plot_polygons_layout = drone_imagery_interactive_field_trial_layout_response.output;
2234         var plot_polygons_plot_numbers = [];
2235         var plot_polygons_plot_numbers_plot_names = {};
2236         for (var i=1; i<plot_polygons_layout.length; i++) {
2237             var plot_polygons_plot_number = parseInt(plot_polygons_layout[i][2]);
2238             if (plot_polygons_plot_number >= plot_polygons_plot_number_start_int) {
2239                 plot_polygons_plot_numbers.push(plot_polygons_plot_number);
2240                 plot_polygons_plot_numbers_plot_names[plot_polygons_plot_number] = plot_polygons_layout[i][0];
2241             }
2242         }
2243         plot_polygons_plot_numbers = plot_polygons_plot_numbers.sort(function (a, b) {  return a - b;  });
2244         var plot_polygons_current_plot_number_index = 0;
2246         var plot_polygons_template_index = 0;
2247         var plot_polygons_template_current = drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions[plot_polygons_template_index];
2248         var plot_polygons_template_current_num_cols = plot_polygons_template_current.num_cols;
2249         var plot_polygons_template_current_num_rows = plot_polygons_template_current.num_rows;
2250         var plot_polygons_template_current_total_plot_polygons = plot_polygons_template_current.total_plot_polygons;
2251         var plot_polygons_template_current_plot_polygon_index = 0;
2253         var plot_polygon_new_display = {};
2254         if (plot_polygons_first_plot_start == 'top_left') {
2255             var generated_polygon_key_first_plot_number = 0;
2256             if (plot_polygons_second_plot_follows == 'left' || plot_polygons_second_plot_follows == 'up') {
2257                 alert('Second plot cannot follow left or up from first plot if the first plot starts at the top left, because that is physically impossible.');
2258                 return;
2259             }
2260             if (plot_polygons_second_plot_follows == 'right') {
2261                 if (plot_polygons_plot_orientation == 'zigzag') {
2262                     var plot_polygon_current_polygon_index = generated_polygon_key_first_plot_number;
2263                     for (var j=generated_polygon_key_first_plot_number; j<plot_polygons_plot_numbers.length + drone_imagery_interactive_plot_polygons_removed_numbers.length; j++){
2264                         if (drone_imagery_interactive_plot_polygons_removed_numbers.includes(plot_polygon_current_polygon_index.toString())) {
2265                             console.log("Skipping "+plot_polygon_current_polygon_index);
2266                             plot_polygon_new_display[plot_polygon_current_polygon_index] = drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2267                         } else {
2268                             plot_polygon_new_display[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] = drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2269                             drone_imagery_interactive_plot_polygons[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] = drone_imagery_interactive_plot_generated_polygons[plot_polygon_current_polygon_index];
2270                             plot_polygons_current_plot_number_index = plot_polygons_current_plot_number_index + 1;
2271                             plot_polygons_template_current_plot_polygon_index = plot_polygons_template_current_plot_polygon_index + 1;
2272                         }
2273                         plot_polygon_current_polygon_index = plot_polygon_current_polygon_index + 1;
2275                         if (plot_polygons_template_current_plot_polygon_index == plot_polygons_template_current_total_plot_polygons) {
2276                             plot_polygons_template_index = plot_polygons_template_index + 1;
2277                             plot_polygons_template_current = drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions[plot_polygons_template_index];
2278                             if (plot_polygons_template_current != undefined) {
2279                                 plot_polygons_template_current_num_cols = plot_polygons_template_current.num_cols;
2280                                 plot_polygons_template_current_num_rows = plot_polygons_template_current.num_rows;
2281                                 plot_polygons_template_current_total_plot_polygons = plot_polygons_template_current.total_plot_polygons;
2282                                 plot_polygons_template_current_plot_polygon_index = 0;
2283                             }
2284                         }
2285                     }
2286                 }
2287                 if (plot_polygons_plot_orientation == 'serpentine') {
2288                     var plot_polygon_current_polygon_index = generated_polygon_key_first_plot_number;
2289                     var plot_polygon_column_count = 0;
2290                     var plot_polygon_zigzig_polygon_index = generated_polygon_key_first_plot_number;
2291                     var going_right = 1;
2292                     var plot_polygon_previous_template_plot_count = 0;
2293                     for (var j=generated_polygon_key_first_plot_number; j<plot_polygons_plot_numbers.length + drone_imagery_interactive_plot_polygons_removed_numbers.length; j++){
2295                         if (going_right == 1) {
2296                             plot_polygon_current_polygon_index = plot_polygon_zigzig_polygon_index;
2297                         }
2298                         if (going_right == 0) {
2299                             plot_polygon_current_polygon_index = plot_polygon_previous_template_plot_count + plot_polygons_template_current_num_cols - plot_polygon_column_count - 1;
2300                         }
2302                         if (drone_imagery_interactive_plot_polygons_removed_numbers.includes(plot_polygon_current_polygon_index.toString())) {
2303                             console.log("Skipping "+plot_polygon_current_polygon_index);
2304                             plot_polygon_new_display[plot_polygon_current_polygon_index] = drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2305                         } else {
2306                             plot_polygon_new_display[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] =  drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2307                             drone_imagery_interactive_plot_polygons[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] = drone_imagery_interactive_plot_generated_polygons[plot_polygon_current_polygon_index];
2308                             plot_polygons_current_plot_number_index = plot_polygons_current_plot_number_index + 1;
2309                             plot_polygons_template_current_plot_polygon_index = plot_polygons_template_current_plot_polygon_index + 1;
2310                         }
2312                         plot_polygon_zigzig_polygon_index = plot_polygon_zigzig_polygon_index + 1;
2313                         plot_polygon_column_count = plot_polygon_column_count + 1;
2315                         if (plot_polygon_column_count == plot_polygons_template_current_num_cols) {
2316                             plot_polygon_column_count = 0;
2317                             if (going_right == 1) {
2318                                 going_right = 0;
2319                             } else {
2320                                 going_right = 1;
2321                             }
2322                             plot_polygon_previous_template_plot_count = plot_polygon_previous_template_plot_count + plot_polygons_template_current_num_cols;
2323                         }
2325                         if (plot_polygons_template_current_plot_polygon_index == plot_polygons_template_current_total_plot_polygons) {
2326                             plot_polygons_template_index = plot_polygons_template_index + 1;
2327                             plot_polygons_template_current = drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions[plot_polygons_template_index];
2328                             if (plot_polygons_template_current != undefined) {
2329                                 plot_polygons_template_current_num_cols = plot_polygons_template_current.num_cols;
2330                                 plot_polygons_template_current_num_rows = plot_polygons_template_current.num_rows;
2331                                 plot_polygons_template_current_total_plot_polygons = plot_polygons_template_current.total_plot_polygons;
2332                                 plot_polygons_template_current_plot_polygon_index = 0;
2333                             }
2334                         }
2335                     }
2336                 }
2337             }
2338             if (plot_polygons_second_plot_follows == 'down') {
2339                 alert('Down not implemented if first plot starts in top left. Please contact us or try rotating your image differently before assigning plot polygons (e.g. rotate image 90 degrees clock-wise, then first plot starts in top right and you can go left for plot assignment).');
2340                 return;
2341             }
2342         }
2343         if (plot_polygons_first_plot_start == 'top_right') {
2344             var generated_polygon_key_first_plot_number = plot_polygons_template_current_num_cols - 1;
2345             if (plot_polygons_second_plot_follows == 'right' || plot_polygons_second_plot_follows == 'up') {
2346                 alert('Second plot cannot follow right or up from first plot if the first plot starts at the top right, because that is physically impossible.');
2347                 return;
2348             }
2349             if (plot_polygons_second_plot_follows == 'left') {
2350                 if (plot_polygons_plot_orientation == 'zigzag') {
2351                     console.log(generated_polygon_key_first_plot_number);
2352                     var plot_polygon_current_polygon_index = generated_polygon_key_first_plot_number;
2353                     var plot_polygon_column_count = 0;
2354                     var plot_polygon_previous_template_plot_count = 0;
2355                     for (var j=generated_polygon_key_first_plot_number; j<generated_polygon_key_first_plot_number + plot_polygons_plot_numbers.length + drone_imagery_interactive_plot_polygons_removed_numbers.length; j++){
2357                         plot_polygon_current_polygon_index = plot_polygon_previous_template_plot_count + plot_polygons_template_current_num_cols - plot_polygon_column_count - 1;
2359                         if (drone_imagery_interactive_plot_polygons_removed_numbers.includes(plot_polygon_current_polygon_index.toString())) {
2360                             console.log("Skipping "+plot_polygon_current_polygon_index);
2361                             plot_polygon_new_display[plot_polygon_current_polygon_index] =  drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2362                         } else {
2363                             plot_polygon_new_display[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] =  drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2364                             drone_imagery_interactive_plot_polygons[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] = drone_imagery_interactive_plot_generated_polygons[plot_polygon_current_polygon_index];
2365                             plot_polygons_current_plot_number_index = plot_polygons_current_plot_number_index + 1;
2366                             plot_polygons_template_current_plot_polygon_index = plot_polygons_template_current_plot_polygon_index + 1;
2367                         }
2369                         plot_polygon_column_count = plot_polygon_column_count + 1;
2371                         if (plot_polygon_column_count == plot_polygons_template_current_num_cols) {
2372                             plot_polygon_column_count = 0;
2373                             plot_polygon_previous_template_plot_count = plot_polygon_previous_template_plot_count + plot_polygons_template_current_num_cols;
2374                         }
2376                         if (plot_polygons_template_current_plot_polygon_index == plot_polygons_template_current_total_plot_polygons) {
2377                             plot_polygons_template_index = plot_polygons_template_index + 1;
2378                             plot_polygons_template_current = drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions[plot_polygons_template_index];
2379                             if (plot_polygons_template_current != undefined) {
2380                                 plot_polygons_template_current_num_cols = plot_polygons_template_current.num_cols;
2381                                 plot_polygons_template_current_num_rows = plot_polygons_template_current.num_rows;
2382                                 plot_polygons_template_current_total_plot_polygons = plot_polygons_template_current.total_plot_polygons;
2383                                 plot_polygons_template_current_plot_polygon_index = 0;
2384                             }
2385                         }
2386                     }
2387                 }
2388                 if (plot_polygons_plot_orientation == 'serpentine') {
2389                     var plot_polygon_current_polygon_index = generated_polygon_key_first_plot_number;
2390                     var plot_polygon_column_count = 0;
2391                     var plot_polygon_zigzig_polygon_index = generated_polygon_key_first_plot_number;
2392                     var going_left = 1;
2393                     var plot_polygon_previous_template_plot_count = 0;
2394                     for (var j=generated_polygon_key_first_plot_number; j<generated_polygon_key_first_plot_number + plot_polygons_plot_numbers.length + drone_imagery_interactive_plot_polygons_removed_numbers.length; j++){
2396                         if (going_left == 0) {
2397                             plot_polygon_current_polygon_index = plot_polygon_previous_template_plot_count + plot_polygon_column_count;
2398                         }
2399                         if (going_left == 1) {
2400                             plot_polygon_current_polygon_index = plot_polygon_previous_template_plot_count + plot_polygons_template_current_num_cols - plot_polygon_column_count - 1;
2401                         }
2403                         if (drone_imagery_interactive_plot_polygons_removed_numbers.includes(plot_polygon_current_polygon_index.toString())) {
2404                             console.log("Skipping "+plot_polygon_current_polygon_index);
2405                             plot_polygon_new_display[plot_polygon_current_polygon_index] = drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2406                         } else {
2407                             plot_polygon_new_display[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] =  drone_imagery_interactive_plot_polygons_display[plot_polygon_current_polygon_index];
2408                             drone_imagery_interactive_plot_polygons[plot_polygons_plot_numbers_plot_names[plot_polygons_plot_numbers[plot_polygons_current_plot_number_index]]] = drone_imagery_interactive_plot_generated_polygons[plot_polygon_current_polygon_index];
2409                             plot_polygons_current_plot_number_index = plot_polygons_current_plot_number_index + 1;
2410                             plot_polygons_template_current_plot_polygon_index = plot_polygons_template_current_plot_polygon_index + 1;
2411                         }
2413                         plot_polygon_zigzig_polygon_index = plot_polygon_zigzig_polygon_index + 1;
2414                         plot_polygon_column_count = plot_polygon_column_count + 1;
2416                         if (plot_polygon_column_count == plot_polygons_template_current_num_cols) {
2417                             plot_polygon_column_count = 0;
2418                             if (going_left == 1) {
2419                                 going_left = 0;
2420                             } else {
2421                                 going_left = 1;
2422                             }
2423                             plot_polygon_previous_template_plot_count = plot_polygon_previous_template_plot_count + plot_polygons_template_current_num_cols;
2424                         }
2426                         if (plot_polygons_template_current_plot_polygon_index == plot_polygons_template_current_total_plot_polygons) {
2427                             plot_polygons_template_index = plot_polygons_template_index + 1;
2428                             plot_polygons_template_current = drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions[plot_polygons_template_index];
2429                             if (plot_polygons_template_current != undefined) {
2430                                 plot_polygons_template_current_num_cols = plot_polygons_template_current.num_cols;
2431                                 plot_polygons_template_current_num_rows = plot_polygons_template_current.num_rows;
2432                                 plot_polygons_template_current_total_plot_polygons = plot_polygons_template_current.total_plot_polygons;
2433                                 plot_polygons_template_current_plot_polygon_index = 0;
2434                             }
2435                         }
2436                     }
2437                 }
2438             }
2439             if (plot_polygons_second_plot_follows == 'down') {
2440                 alert('Down not implemented if your first plot starts in top right. Please contact us or try rotating your image differently before assigning plot polygons (e.g. rotate image 90 degrees clockwise, then first plot starts in bottom right corner and plot assignment can follow going left).');
2441                 return;
2442             }
2443         }
2444         if (plot_polygons_first_plot_start == 'bottom_left') {
2445             alert('Not implemented');
2446             return;
2447         }
2448         if (plot_polygons_first_plot_start == 'bottom_right') {
2449             alert('Not implemented');
2450             return;
2451         }
2453         droneImageryDrawLayoutTableInteractive(drone_imagery_interactive_field_trial_layout_response, drone_imagery_interactive_plot_polygons, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
2455         drone_imagery_interactive_plot_polygons_display = plot_polygon_new_display;
2456         draw_canvas_image_interactive(plot_polygons_interactive_total_height_generated/plot_polygons_interactive_num_rows_generated);
2457     }
2459     jQuery(document).on('click', '#drone_imagery_interactive_plot_polygons_clear', function(){
2460         plot_polygons_interactive_display_points = [];
2461         plot_polygons_interactive_ind_4_points = [];
2462         plot_polygons_interactive_generated_polygons = {};
2463         drone_imagery_interactive_plot_polygons_display = {};
2464         plot_polygons_interactive_generated_polygons = [];
2465         drone_imagery_interactive_plot_generated_polygons = [];
2466         drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions = [];
2467         drone_imagery_interactive_plot_polygons_removed_numbers = [];
2468         d3.selectAll('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+' > text').remove();
2469         d3.selectAll('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+' > line').remove();
2470         //d3.selectAll('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+' > circle').remove();
2471         jQuery('#drone_imagery_interactive_generated_polygons_div').html('');
2473         droneImageryDrawLayoutTableInteractive(drone_imagery_interactive_field_trial_layout_response, {}, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
2474         droneImageryDrawPlotPolygonActiveTemplatesTableInteractive('drone_imagery_plot_polygons_active_templates_raw_images_interactive', drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions);
2475         plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2476     });
2478     jQuery(document).on('click', '#drone_imagery_interactive_plot_polygons_clear_one', function(){
2479         jQuery('#drone_imagery_interactive_plot_polygon_remove_polygon').modal('show');
2480         return false;
2481     });
2483     jQuery('#drone_imagery_interactive_plot_polygon_remove_polygon_submit').click(function(){
2484         var polygon_number = jQuery('#drone_imagery_interactive_plot_polygon_remove_polygon_number').val();
2485         drone_imagery_interactive_plot_polygons_removed_numbers.push(polygon_number);
2486         draw_canvas_image_interactive(plot_polygons_interactive_total_height_generated/plot_polygons_interactive_num_rows_generated);
2487         plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2488         return false;
2489     });
2491     function draw_canvas_image_interactive(random_scaling) {
2492         d3.selectAll('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+' > text').remove();
2493         d3.selectAll('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+' > line').remove();
2494         //d3.selectAll('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area_'+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+' > circle').remove();
2495         console.log("draw_canvas_image_interactive");
2496         console.log(drone_imagery_interactive_plot_polygons_display);
2498         for (key in drone_imagery_interactive_plot_polygons_display) {
2499             var plot_polygons_display_points_again = drone_imagery_interactive_plot_polygons_display[key];
2500             drawPolylineInteractive(plot_polygons_display_points_again);
2501             drawWaypointsInteractive(plot_polygons_display_points_again, key, random_scaling);
2502         }
2503         return false;
2504     }
2506     jQuery(document).on('click', 'button[name="drone_imagery_standard_process_interactive_plot_polygons_submit_bottom"]', function(){
2507         console.log(manage_drone_imagery_standard_process_interactive_saved_gps_positions);
2509         console.log(drone_imagery_interactive_plot_polygons);
2510         console.log(drone_imagery_interactive_plot_polygons_display);
2512         jQuery.ajax({
2513             type: 'POST',
2514             url: '/api/drone_imagery/save_plot_polygons_template_separated',
2515             dataType: "json",
2516             data: {
2517                 'drone_run_band_project_id': manage_drone_imagery_standard_process_interactive_drone_run_band_project_id,
2518                 'stock_polygons': JSON.stringify(drone_imagery_interactive_plot_polygons),
2519                 'flight_pass_counter':manage_drone_imagery_standard_process_raw_images_interactive_current_pass
2520             },
2521             success: function(response){
2522                 console.log(response);
2523                 if(response.error) {
2524                     alert(response.error);
2525                 }
2526                 console.log(manage_drone_imagery_standard_process_raw_images_interactive_current_pass);
2527                 if (manage_drone_imagery_standard_process_raw_images_interactive_current_pass < manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass) {
2528                     manage_drone_imagery_standard_process_raw_images_interactive_current_pass = manage_drone_imagery_standard_process_raw_images_interactive_current_pass + 1;
2530                     console.log("Plot Polygon pass COMPLETE");
2532                     initializeInteractiveSvg('#drone_imagery_standard_process_raw_images_image_id_interactive_select_div', 'drone_imagery_standard_process_raw_images_image_id_interactive_select_div_area', 1, 1);
2534                     jQuery('#drone_imagery_standard_process_interactive_plot_polygons_flight_pass').html("<h1><b>Current Imaging Event Pass: "+manage_drone_imagery_standard_process_raw_images_interactive_current_pass+"/"+manage_drone_imagery_standard_process_raw_images_interactive_maximum_pass+"</b></h1>");
2536                     plot_polygons_interactive_display_points = [];
2537                     plot_polygons_interactive_ind_4_points = [];
2538                     plot_polygons_interactive_generated_polygons = {};
2539                     drone_imagery_interactive_plot_polygons_display = {};
2540                     plot_polygons_interactive_generated_polygons = [];
2541                     drone_imagery_interactive_plot_generated_polygons = [];
2542                     drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions = [];
2543                     drone_imagery_interactive_plot_polygons_removed_numbers = [];
2544                     jQuery('#drone_imagery_interactive_generated_polygons_div').html('');
2546                     droneImageryDrawLayoutTableInteractive(drone_imagery_interactive_field_trial_layout_response, {}, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
2547                     droneImageryDrawPlotPolygonActiveTemplatesTableInteractive('drone_imagery_plot_polygons_active_templates_raw_images_interactive', drone_imagery_standard_process_raw_images_interactive_plot_polygons_template_dimensions);
2548                     plotPolygonManualAssignPlotNumberTable('drone_imagery_standard_process_interactive_generated_polygons_table', 'drone_imagery_standard_process_interactive_generated_polygons_table_id', 'drone_imagery_standard_process_interactive_generated_polygons_table_input', 'drone_imagery_standard_process_interactive_generated_polygons_table_input_generate_button', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2550                     window.scrollTo(0,0);
2551                 }
2552                 else {
2553                     console.log("Plot polygon COMPLETE");
2555                     manage_drone_imagery_standard_process_raw_images_interactive_current_pass = 1;
2557                     jQuery('#manage_drone_imagery_standard_process_interactive_drone_run_bands_apply_table').DataTable({
2558                         destroy : true,
2559                         ajax : '/api/drone_imagery/drone_run_bands?select_checkbox_name=drone_run_standard_process_interactive_band_apply_select&drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id+'&select_all=1&disable=1'
2560                     });
2562                     Workflow.complete("#drone_imagery_standard_process_raw_images_interactive_match_previous_pass");
2563                     Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 5);
2564                 }
2565             },
2566             error: function(response){
2567                 //alert('Error saving standard process assigned plot polygons!')
2568             }
2569         });
2570     });
2572     jQuery('#manage_drone_imagery_standard_process_interactive_drone_run_band_apply_step').click(function(){
2573         manage_drone_imagery_standard_process_interactive_apply_drone_run_band_project_ids = [];
2574         jQuery('input[name="drone_run_standard_process_interactive_band_apply_select"]:checked').each(function() {
2575             manage_drone_imagery_standard_process_interactive_apply_drone_run_band_project_ids.push(jQuery(this).val());
2576         });
2577         if (manage_drone_imagery_standard_process_interactive_apply_drone_run_band_project_ids.length < 1){
2578             alert('Please select at least one other drone run band!');
2579             return false;
2580         } else {
2581             Workflow.complete("#manage_drone_imagery_standard_process_interactive_drone_run_band_apply_step");
2582             Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 6);
2583         }
2584     });
2586     jQuery('#manage_drone_imagery_standard_interactive_process_indices_step').click(function(){
2587         manage_drone_imagery_standard_process_interactive_apply_drone_run_band_vegetative_indices = [];
2588         jQuery('input[name="drone_imagery_standard_process_interactive_apply_indices_select"]:checked').each(function() {
2589             manage_drone_imagery_standard_process_interactive_apply_drone_run_band_vegetative_indices.push(jQuery(this).val());
2590         });
2591         if (manage_drone_imagery_standard_process_interactive_apply_drone_run_band_vegetative_indices.length < 1){
2592             alert('Please select at least one vegetative index!');
2593             return false;
2594         } else {
2595             jQuery.ajax({
2596                 type: 'GET',
2597                 url: '/api/drone_imagery/get_weeks_after_planting_date?drone_run_project_id='+manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
2598                 dataType: "json",
2599                 beforeSend: function (){
2600                     jQuery('#working_modal').modal('show');
2601                 },
2602                 success: function(response){
2603                     jQuery('#working_modal').modal('hide');
2604                     console.log(response);
2605                     if (response.error) {
2606                         alert(response.error);
2607                     }
2609                     var html = "<center><b>Field Trial Planting Date</b>: "+response.planting_date+"<br/><b>Drone Run Date</b>: "+response.drone_run_date+"<br/><b>Number of Weeks</b>: "+response.rounded_time_difference_weeks+"<br/><b>Number of Weeks Ontology Term</b>: "+response.time_ontology_week_term+"<br/><b>Number of Days</b>:"+response.time_difference_days+"<br/><b>Number of Days Ontology Term</b>: "+response.time_ontology_day_term+"<br/><br/></center>";
2610                     jQuery('#drone_imagery_standard_process_interactive_week_term_div').html(html);
2612                     manage_drone_imagery_standard_process_interactive_phenotype_time = response.time_ontology_day_cvterm_id;
2613                 },
2614                 error: function(response){
2615                     alert('Error getting time terms!');
2616                     jQuery('#working_modal').modal('hide');
2617                 }
2618             });
2620             Workflow.complete("#manage_drone_imagery_standard_interactive_process_indices_step");
2621             Workflow.focus('#manage_drone_imagery_standard_process_raw_images_interactive_workflow', 7);
2622         }
2623     });
2625     jQuery('#manage_drone_imagery_standard_process_interactive_phenotypes_step').click(function(){
2626         var selected = [];
2628         if (manage_drone_imagery_standard_process_interactive_phenotype_time == '') {
2629             alert('Time of phenotype not set! This should not happen! Please contact us.');
2630             return false;
2631         }
2633         jQuery('input[name="drone_imagery_standard_process_interactive_phenotypes_select"]:checked').each(function() {
2634             selected.push(jQuery(this).val());
2635         });
2636         if (selected.length < 1){
2637             alert('Please select at least one phenotype!');
2638             return false;
2639         } else {
2640             jQuery.ajax({
2641                 type: 'POST',
2642                 url: '/api/drone_imagery/standard_process_apply_raw_images_interactive',
2643                 dataType: "json",
2644                 data: {
2645                     'drone_run_project_id': manage_drone_imagery_standard_process_raw_images_interactive_drone_run_id,
2646                     'drone_run_band_project_id': manage_drone_imagery_standard_process_interactive_drone_run_band_project_id,
2647                     'apply_drone_run_band_project_ids': JSON.stringify(manage_drone_imagery_standard_process_interactive_apply_drone_run_band_project_ids),
2648                     'vegetative_indices': JSON.stringify(manage_drone_imagery_standard_process_interactive_apply_drone_run_band_vegetative_indices),
2649                     'phenotype_types': JSON.stringify(selected),
2650                     'time_cvterm_id': manage_drone_imagery_standard_process_interactive_phenotype_time,
2651                     'standard_process_type': 'minimal'
2652                 },
2653                 success: function(response){
2654                     console.log(response);
2655                     if(response.error) {
2656                         alert(response.error);
2657                     }
2658                 },
2659                 error: function(response){
2660                     //alert('Error saving standard process assigned plot polygons!')
2661                 }
2662             });
2664             Workflow.complete("#manage_drone_imagery_standard_process_interactive_phenotypes_step");
2665             //jQuery('#drone_imagery_standard_process_interactive_complete_dialog').modal('show');
2666         }
2667     });
2669     jQuery('#drone_imagery_standard_process_interactive_complete_dialog').on('hidden.bs.modal', function () {
2670         location.reload();
2671     })
2673     jQuery('#plot_polygons_use_previously_saved_template_raw_images_interactive').click(function(){
2674         var plot_polygons_use_previously_saved_template = jQuery('#manage_drone_imagery_standard_process_interactive_previous_templates').val();
2675         if (plot_polygons_use_previously_saved_template == '') {
2676             alert('Please select a previously saved template before trying to apply it. If there is not a template listed, then you can create one using the templating tool above.');
2677             return;
2678         }
2680         jQuery.ajax({
2681             url : '/api/drone_imagery/retrieve_parameter_template?plot_polygons_template_projectprop_id='+plot_polygons_use_previously_saved_template,
2682             success: function(response){
2683                 console.log(response);
2684                 var p = response.parameter;
2685                 drone_imagery_interactive_plot_polygons_display = p[manage_drone_imagery_standard_process_raw_images_interactive_current_pass];
2686                 drone_imagery_interactive_plot_polygons = p[manage_drone_imagery_standard_process_raw_images_interactive_current_pass];
2688                 droneImageryDrawLayoutTableInteractive(drone_imagery_interactive_field_trial_layout_response, drone_imagery_interactive_plot_polygons, 'drone_imagery_interactive_trial_layout_div', 'drone_imagery_interactive_trial_layout_table');
2689                 droneImageryDrawRectangleTableInteractive('drone_imagery_interactive_generated_polygons_div', 'drone_imagery_standard_process_interactive_plot_polygons_generated_assign', 'drone_imagery_standard_process_interactive_plot_polygons_submit_bottom');
2691                 draw_canvas_image_interactive(0);
2692             },
2693             error: function(response){
2694                 alert('Error retrieving plot polygons template!');
2695             }
2696         });
2697         return;
2698     });
2700     function showManageDroneImagerySection(section_div_id) {
2701         console.log(section_div_id);
2702         if (section_div_id == 'manage_drone_imagery_crop_div') {
2703             jQuery('#manage_drone_imagery_crop_div').show();
2704             jQuery('#manage_drone_imagery_top_div').hide();
2705             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2706             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2707             jQuery('#manage_drone_imagery_remove_background_div').hide();
2708             jQuery('#manage_drone_imagery_rotate_div').hide();
2709             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2710             jQuery('#manage_drone_imagery_standard_process_div').hide();
2711             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2712             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2713             jQuery('#manage_drone_imagery_loading_div').hide();
2714         } else if (section_div_id == 'manage_drone_imagery_top_div'){
2715             jQuery('#manage_drone_imagery_crop_div').hide();
2716             jQuery('#manage_drone_imagery_top_div').show();
2717             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2718             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2719             jQuery('#manage_drone_imagery_remove_background_div').hide();
2720             jQuery('#manage_drone_imagery_rotate_div').hide();
2721             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2722             jQuery('#manage_drone_imagery_standard_process_div').hide();
2723             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2724             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2725             jQuery('#manage_drone_imagery_loading_div').hide();
2726         } else if (section_div_id == 'manage_drone_imagery_plot_polygons_div'){
2727             jQuery('#manage_drone_imagery_crop_div').hide();
2728             jQuery('#manage_drone_imagery_top_div').hide();
2729             jQuery('#manage_drone_imagery_plot_polygons_div').show();
2730             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2731             jQuery('#manage_drone_imagery_remove_background_div').hide();
2732             jQuery('#manage_drone_imagery_rotate_div').hide();
2733             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2734             jQuery('#manage_drone_imagery_standard_process_div').hide();
2735             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2736             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2737             jQuery('#manage_drone_imagery_loading_div').hide();
2738         } else if (section_div_id == 'manage_drone_imagery_calculate_phenotypes_div'){
2739             jQuery('#manage_drone_imagery_crop_div').hide();
2740             jQuery('#manage_drone_imagery_top_div').hide();
2741             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2742             jQuery('#manage_drone_imagery_calculate_phenotypes_div').show();
2743             jQuery('#manage_drone_imagery_remove_background_div').hide();
2744             jQuery('#manage_drone_imagery_rotate_div').hide();
2745             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2746             jQuery('#manage_drone_imagery_standard_process_div').hide();
2747             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2748             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2749             jQuery('#manage_drone_imagery_loading_div').hide();
2750         } else if (section_div_id == 'manage_drone_imagery_remove_background_div'){
2751             jQuery('#manage_drone_imagery_crop_div').hide();
2752             jQuery('#manage_drone_imagery_top_div').hide();
2753             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2754             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2755             jQuery('#manage_drone_imagery_remove_background_div').show();
2756             jQuery('#manage_drone_imagery_rotate_div').hide();
2757             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2758             jQuery('#manage_drone_imagery_standard_process_div').hide();
2759             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2760             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2761             jQuery('#manage_drone_imagery_loading_div').hide();
2762         } else if (section_div_id == 'manage_drone_imagery_rotate_div'){
2763             jQuery('#manage_drone_imagery_crop_div').hide();
2764             jQuery('#manage_drone_imagery_top_div').hide();
2765             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2766             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2767             jQuery('#manage_drone_imagery_remove_background_div').hide();
2768             jQuery('#manage_drone_imagery_rotate_div').show();
2769             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2770             jQuery('#manage_drone_imagery_standard_process_div').hide();
2771             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2772             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2773             jQuery('#manage_drone_imagery_loading_div').hide();
2774         } else if (section_div_id == 'manage_drone_imagery_vegetative_index_div'){
2775             jQuery('#manage_drone_imagery_crop_div').hide();
2776             jQuery('#manage_drone_imagery_top_div').hide();
2777             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2778             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2779             jQuery('#manage_drone_imagery_remove_background_div').hide();
2780             jQuery('#manage_drone_imagery_rotate_div').hide();
2781             jQuery('#manage_drone_imagery_vegetative_index_div').show();
2782             jQuery('#manage_drone_imagery_standard_process_div').hide();
2783             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2784             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2785             jQuery('#manage_drone_imagery_loading_div').hide();
2786         } else if (section_div_id == 'manage_drone_imagery_standard_process_div'){
2787             jQuery('#manage_drone_imagery_crop_div').hide();
2788             jQuery('#manage_drone_imagery_top_div').hide();
2789             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2790             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2791             jQuery('#manage_drone_imagery_remove_background_div').hide();
2792             jQuery('#manage_drone_imagery_rotate_div').hide();
2793             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2794             jQuery('#manage_drone_imagery_standard_process_div').show();
2795             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2796             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2797             jQuery('#manage_drone_imagery_loading_div').hide();
2798         } else if (section_div_id == 'manage_drone_imagery_standard_process_raw_images_div'){
2799             jQuery('#manage_drone_imagery_crop_div').hide();
2800             jQuery('#manage_drone_imagery_top_div').hide();
2801             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2802             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2803             jQuery('#manage_drone_imagery_remove_background_div').hide();
2804             jQuery('#manage_drone_imagery_rotate_div').hide();
2805             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2806             jQuery('#manage_drone_imagery_standard_process_div').hide();
2807             jQuery('#manage_drone_imagery_standard_process_raw_images_div').show();
2808             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2809             jQuery('#manage_drone_imagery_loading_div').hide();
2810         } else if (section_div_id == 'manage_drone_imagery_standard_process_raw_images_interactive_div'){
2811             jQuery('#manage_drone_imagery_crop_div').hide();
2812             jQuery('#manage_drone_imagery_top_div').hide();
2813             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2814             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2815             jQuery('#manage_drone_imagery_remove_background_div').hide();
2816             jQuery('#manage_drone_imagery_rotate_div').hide();
2817             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2818             jQuery('#manage_drone_imagery_standard_process_div').hide();
2819             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2820             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').show();
2821             jQuery('#manage_drone_imagery_loading_div').hide();
2822         } else if (section_div_id == 'manage_drone_imagery_loading_div'){
2823             jQuery('#manage_drone_imagery_crop_div').hide();
2824             jQuery('#manage_drone_imagery_top_div').hide();
2825             jQuery('#manage_drone_imagery_plot_polygons_div').hide();
2826             jQuery('#manage_drone_imagery_calculate_phenotypes_div').hide();
2827             jQuery('#manage_drone_imagery_remove_background_div').hide();
2828             jQuery('#manage_drone_imagery_rotate_div').hide();
2829             jQuery('#manage_drone_imagery_vegetative_index_div').hide();
2830             jQuery('#manage_drone_imagery_standard_process_div').hide();
2831             jQuery('#manage_drone_imagery_standard_process_raw_images_div').hide();
2832             jQuery('#manage_drone_imagery_standard_process_raw_images_interactive_div').hide();
2833             jQuery('#manage_drone_imagery_loading_div').show();
2834         }
2835         window.scrollTo(0,0);
2836     }
2838 </script>