Created
November 6, 2014 10:37
-
-
Save Kalimaha/42a9be348acca9b2e415 to your computer and use it in GitHub Desktop.
Process JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var process_step = function(tab_id, steps, current_step, band_index, band_label, source_folder, target_folder, callback) { | |
steps[current_step].source_path = source_folder; | |
steps[current_step].output_path = target_folder; | |
steps[current_step].band = band_index; | |
$.ajax({ | |
url: CONFIG.url_process + CONFIG.data_provider + '/', | |
type: 'POST', | |
dataType: 'json', | |
data: JSON.stringify(steps[current_step]), | |
contentType: 'application/json', | |
success: function (response) { | |
var json = response; | |
if (typeof json == 'string') | |
json = $.parseJSON(response); | |
// for (var i = 0 ; i < json.length ; i++) | |
// $('#result_list_' + tab_id).append('<li>Step result: ' + json[i] + '</li>'); | |
if (parseInt(1 + current_step) < steps.length) { | |
callback(tab_id, steps, parseInt(1 + current_step), band_index, band_label, json, target_folder, callback); | |
} else { | |
var s = '<li>'; | |
s += '<b>Layer band "' + band_label + '" successfully downloaded an processed. ('; | |
s += '<a target="_blank" href="http://168.202.28.57:5005/distribution/downloadraster/'; | |
s += json[json.length - 1].split('/').join(':'); | |
s += '">'; | |
s += 'open'; | |
s += ')</b></a></li>'; | |
$('#result_list_' + tab_id).append(s); | |
var uid = 'fnx_' + parseInt(1000000 * Math.random()).toString(); | |
var style = 'ndvi'; | |
var map_box_title = 'NDVI'; | |
if (json[json.length - 1].indexOf('_EVI') > -1) { | |
map_box_title = 'EVI'; | |
style = 'evi'; | |
} | |
$.ajax({ | |
url: CONFIG.url_publish + uid + '/' + style + '/' + json[json.length - 1].split('/').join(':') + '/', | |
type: 'POST', | |
dataType: 'json', | |
contentType: 'application/json', | |
success: function (response) { | |
var map_container = ''; | |
map_container += '<div class="row">'; | |
map_container += '<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">'; | |
map_container += '<h2>' + map_box_title + '</h2>'; | |
map_container += '</div>'; | |
map_container += '</div>'; | |
map_container += '<div class="row">'; | |
map_container += '<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">'; | |
map_container += '<div style="height: 300px;" id="' + uid + '"></div>'; | |
map_container += '</div>'; | |
map_container += '</div>'; | |
$('#result_list_' + tab_id).append('<br>'); | |
$('#result_list_' + tab_id).append(map_container); | |
console.log(uid); | |
console.log(json[json.length - 1]); | |
var map = L.map(uid).setView([0, 0], 1); | |
map.attributionControl.setPrefix(""); | |
map.attributionControl.addAttribution("FAO ESS 2014"); | |
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map); | |
var wmsFootprint = new L.tileLayer.wms("http://168.202.28.57:9090/geoserver/wms", { | |
layers: uid, | |
format: 'image/png', | |
transparent: true | |
}).addTo(map); | |
var wmsFootprint = new L.tileLayer.wms("http://fenixapps2.fao.org/geoserver-demo/wms", { | |
layers: 'fenix:gaul0_line_3857', | |
format: 'image/png', | |
transparent: true | |
}).addTo(map); | |
} | |
}); | |
} | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment