6 <& /util/import_css.mas, paths => ['fieldmap/leaflet-search.min.css', 'fieldmap/leaflet.css'] &>
8 <& '/util/import_javascript.mas',
9 classes => ['jquery', 'd3.d3v4Min', 'brapi.fieldmap.leaflet', 'brapi.fieldmap.L-Path-Transform', 'brapi.fieldmap.leaflet-search', 'brapi.fieldmap.turf', 'brapi.BrAPI', 'brapi.BrAPIFieldmap']
13 <& '/page/page_title.mas', title => "Fieldmap app" &>
15 <&| /page/info_section.mas, title=>'Instructions', subtitle=>'Steps for saving plot boundaries', collapsible=>1, collapsed=>1 &>
17 <div class="well well-sm">
18 <p>This tool can be used to add the geo coordinates of individual plot boundaries to plots in a trial.</p>
19 <p><strong>To create and save the plot boundaries:</strong></p>
21 <li>Move and zoom the map to the location of the trial</li>
22 <li>Use the <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAsCAYAAAATmipGAAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAAtdEVYdENyZWF0aW9uIFRpbWUARnJpIDA4IE1hciAyMDI0IDAzOjM4OjUzIFBNIEVTVEVVfAkAAAWgSURBVFiFxVlNiB1FEP6qumffbrKbDYaQhEAQL3rx4CV4UwkEFTRHBX8OInrw5Fnw5tWDeDNegngx4EEPiSKKF70k5BrUU5CAJtH87O7Mm+4qD/0zPfPec/fB5r1a+s3O9HT1N1XVVdXVdP7Dt1RV4b2Hcw5t20JUQcwgJjAziMI1tXRPRJhGRAQigqpCROC9h/ceIgJVharmsemqqr1ryZ+IYBPzCaZQIAIyxky0xLAEm56JSriXwDO1EmTZyvFlf8nfMnN+yXsPZobzHt4LFApjTB6Q3i2lNqQ0WWolyFJSpXaG46bxt9ba3iQiElVP0MjYGANrbZbmNLWnsaUKp01MhZZKMGmsiEyoHhSBljanqnCieDD2qJs2MGMG07hjnBiUklOFFkATL4V2WkBh68aUbKAiGK1YrB8YYXWlyu9liYaJO9U6Vdy6uwUyDFtZUL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wnSUu6cYzQaI22Psjy+huVLshLSJJmaGAmLhvl8Dgje7+FHjrEfISqE0BBCQxMCYCighZzWZVXx47RusEjIhbwZvt23nViaN7CqprKv9Vip91j2WCDEwGK+YD6bMZ1OiRFGLhLGBhGcU2IMxBiwEBAVFMGLIlUWUiJKRBBCCz4RZfwNm4qZSrAzroUAAAAASUVORK5CYII=" /> buttons to draw a polygon on the map outlining the entire trial</li>
23 <li>If necessary, reshape or move the polygon by clicking and dragging the white boxes along the edge of the polygon</li>
24 <li>Click the <strong>Load plots</strong> button to load the individual plots into the trial polygon</li>
25 <li>You can check the orientation of the trial by hovering over one of the plots and checking the plot number displayed in the bottom left corner of the map</li>
26 <li>If necessary, make any final rotations or adjustments to the trial polygon.</li>
27 <li><strong>Save the plot coordinates by clicking the "Save Geo coordinates" button</strong></li>
30 <&| /page/info_section.mas, title=>'Demonstration', collapsible=>1, collapsed=>1 &>
31 <img src="https://raw.githubusercontent.com/solgenomics/brapi-fieldmap/704a1f55cdafc3ad1a17f403cbf4ba2654fcdc70/images/preview.gif" />
38 <center class = "col-md-offset-2 col-md-8">
39 <div id="trialList" class="col-sm-12 col-md-12 col-lg-12">
40 <label for="select_trial_for_selection_index">Trial: </label>
41 <select class="form-control" autofocus="autofocus" id="select_trial_for_selection_index"></select>
46 <div id="formOptions" class="form-inline" style="padding:10px;">
47 <button id="btn-load-plots" class="btn btn-default" onclick="load()">Load plots</button>
48 <button id="btn-save-geo-coordinates" class="btn btn-default" onclick="update()">Save Geo coordinates</button>
52 <div id="map" style="width: 780px; height: 600px"></div>
56 jQuery('#map').width(jQuery('#map').parent().width());
57 jQuery('#map').height(jQuery('#map').parent().width()*0.7);
58 document.getElementById("trialList").style.display="none";
60 jQuery(document).ready(function() {
61 jQuery('#ranking_formula').html("<center><i>Select a trial.</i></center>");
62 get_select_box('trials', 'select_trial_for_selection_index', { 'name' : 'html_select_trial_for_selection_index', 'id' : 'html_select_trial_for_selection_index' , 'empty' : 1 });
63 jQuery('#select_trial_for_selection_index').change(load);
66 document.getElementById("formOptions").style.display="none";
68 var brapi_endpoint = "/brapi/v2";
71 function setupBrAPI(update=false) {
72 var require_login = "<% $c->get_conf('brapi_require_login') %>";
73 if (require_login === '1' || update){
74 auth_token = "<% CXGN::Login->new($c->dbc->dbh)->get_login_cookie() %>";
76 alert("Login required to display and/or update field map");
79 fieldMap.brapi_endpoint = brapi_endpoint;
80 fieldMap.opts.brapi_pageSize = 1000;
81 fieldMap.opts.brapi_auth = auth_token;
85 var trialId = getStudyId();
86 var studyDbId = '<% $trial_id %>' || trialId; // jQuery('#select_trial_for_selection_index').val();
90 jQuery("#btn-load-plots, #btn-save-geo-coordinates").prop("disabled", true);
91 jQuery("#btn-load-plots").html("Loading...");
92 fieldMap.load(studyDbId)
94 if (!value) return setLocation(studyDbId);
95 else { jQuery("#select_trial_for_selection_index option[value="+studyDbId+"]").attr('selected', 'selected'); }
98 jQuery("#btn-load-plots, #btn-save-geo-coordinates").prop("disabled", false);
99 jQuery("#btn-load-plots").html("Load plots");
101 document.getElementById("formOptions").style.display="block";
102 } else alert("Invalid trial!");
105 function setLocation(studyDbId) {
106 jQuery("#select_trial_for_selection_index option[value="+studyDbId+"]").attr('selected', 'selected');
107 fieldMap.setLocation(studyDbId).then(()=>alert("Please select an area over the field and click 'Load plots'."), ()=>alert("No geo reference for location in this trial!"));
112 jQuery("#btn-load-plots, #btn-save-geo-coordinates").prop("disabled", true);
113 jQuery("#btn-save-geo-coordinates").html("Saving...");
115 .then((resp)=>alert(resp), (resp)=>alert(resp))
117 jQuery("#btn-load-plots, #btn-save-geo-coordinates").prop("disabled", false);
118 jQuery("#btn-save-geo-coordinates").html("Save Geo coordinates");
122 var fieldMap = new BrAPIFieldmap("#map",brapi_endpoint);
124 function getStudyId() {
125 const queryString = window.location.search;
126 const urlParams = new URLSearchParams(queryString);
127 return urlParams.get('trial_id');