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" &>
16 <center class = "col-md-offset-2 col-md-8">
17 <div id="trialList" class="col-sm-12 col-md-12 col-lg-12">
18 <label for="select_trial_for_selection_index">Trial: </label>
19 <select class="form-control" autofocus="autofocus" id="select_trial_for_selection_index"></select>
24 <form id="formOptions" class="form-inline" style="padding:10px;">
25 <a class="btn btn-default" onclick="load()">Load plots</a>
26 <a class="btn btn-default" onclick="update()">Save Geo coordinates</a>
30 <div id="map" style="width: 780px; height: 600px"></div>
34 jQuery('#map').width(jQuery('#map').parent().width());
35 jQuery('#map').height(jQuery('#map').parent().width()*0.7);
36 document.getElementById("trialList").style.display="none";
38 jQuery(document).ready(function() {
39 jQuery('#ranking_formula').html("<center><i>Select a trial.</i></center>");
40 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 });
41 jQuery('#select_trial_for_selection_index').change(load);
44 document.getElementById("formOptions").style.display="none";
46 var brapi_endpoint = "/brapi/v2";
48 var require_login = "<% $c->get_conf('brapi_require_login') %>";
49 if (require_login === '1'){
50 auth_token = "<% CXGN::Login->new($c->dbc->dbh)->get_login_cookie() %>";
52 alert("Login required to display field map");
56 function setupBrAPI() {
57 fieldMap.brapi_endpoint = brapi_endpoint;
58 fieldMap.opts.brapi_pageSize = 1000;
59 fieldMap.opts.brapi_auth = auth_token;
63 var trialId = getStudyId();
64 var studyDbId = '<% $trial_id %>' || trialId; // jQuery('#select_trial_for_selection_index').val();
68 fieldMap.load(studyDbId)
70 if (!value) return setLocation(studyDbId);
71 else { jQuery("#select_trial_for_selection_index option[value="+studyDbId+"]").attr('selected', 'selected'); }
73 document.getElementById("formOptions").style.display="block";
74 } else alert("Invalid trial!");
77 function setLocation(studyDbId) {
78 jQuery("#select_trial_for_selection_index option[value="+studyDbId+"]").attr('selected', 'selected');
79 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!"));
84 fieldMap.update().then((resp)=>alert(resp), (resp)=>alert(resp));
87 var fieldMap = new BrAPIFieldmap("#map",brapi_endpoint);
89 function getStudyId() {
90 const queryString = window.location.search;
91 const urlParams = new URLSearchParams(queryString);
92 return urlParams.get('trial_id');