Skip to content

Commit

Permalink
Added visualisation part
Browse files Browse the repository at this point in the history
  • Loading branch information
SinghCoder committed Jul 3, 2019
1 parent 718fc81 commit ce092b4
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 121 deletions.
Binary file modified myproject/db.sqlite3
Binary file not shown.
Binary file modified myproject/myapp/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified myproject/myapp/__pycache__/views.cpython-36.pyc
Binary file not shown.
13 changes: 5 additions & 8 deletions myproject/myapp/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="stylesheet" href="{% static '/css/loader.css' %}"/>
<link rel="stylesheet" href="https://unpkg.com/leaflet.pm@latest/dist/leaflet.pm.css" />
<link rel="stylesheet" type="text/css" href="https://cdn-geoweb.s3.amazonaws.com/esri-leaflet-geocoder/0.0.1-beta.5/esri-leaflet-geocoder.css">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" type="text/css">
<script src="{% static '/leaflet/leaflet.js' %}"></script>
<script src="{% static 'js/calc.js' %}"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
Expand All @@ -17,10 +17,12 @@
<!-- <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Promise"></script> -->
<!-- <script src="{% static 'js/leaflet-bing-layer.min.js' %}"></script> -->
<script src="{% static 'js/Bing.js' %}"></script>
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://cdn-geoweb.s3.amazonaws.com/esri-leaflet/0.0.1-beta.5/esri-leaflet.js"></script>
<script src="https://cdn-geoweb.s3.amazonaws.com/esri-leaflet-geocoder/0.0.1-beta.5/esri-leaflet-geocoder.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="{% static 'js/SliderControl.js' %}"></script>
<script>
function CheckIndex(val){
console.log(val);
Expand Down Expand Up @@ -53,14 +55,9 @@
}
function loaded(){
populateIndices();
initializeLeaflet();
var element = document.getElementById('showGraphLink');
element.click();
sendRequest("/myapp/loadCube/","GET")
.then(function (response) {
console.log('cube loaded');
}).catch(function(e){
console.log('error');
});
}
function closeIndexDiv(){
document.getElementById('indexInputField').style.display = 'none';
Expand Down
1 change: 0 additions & 1 deletion myproject/myapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
url(r'^register/$',views.register,name='register'),
url(r'^user_login/$',views.user_login,name='user_login'),
url(r'^getElevations/',myapp.views.getElevations, name = 'getElevations'),
url(r'^loadCube/$',myapp.views.loadCube,name='loadCube'),
url(r'^getFootprints/$',myapp.views.getFootprints,name='getFootprints'),
]
33 changes: 9 additions & 24 deletions myproject/myapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,6 @@ def home(request):
def login(request):
return render(request,'login.html')

dc = 0
measurements = 0
products = 0

@login_required
def loadCube(request):
global dc
global measurements
global products
dc = datacube.Datacube()
products = ['ls7_level1_usgs', 'ls5_level1_usgs']
measurements = set(dc.index.products.get_by_name(products[0]).measurements.keys())
for prod in products[1:]:
measurements.intersection(dc.index.products.get_by_name(products[0]).measurements.keys())
res = {}
return JsonResponse(res)


'''
Called for acquiring band arrays for the clicked lat/long from the framed datacube
Expand All @@ -163,9 +145,13 @@ def loadCube(request):
'''
@login_required
def getUTM(request):
global dc
global measurements
global products

dc = datacube.Datacube()
products = ['ls7_level1_usgs', 'ls5_level1_usgs']
measurements = set(dc.index.products.get_by_name(products[0]).measurements.keys())
for prod in products[1:]:
measurements.intersection(dc.index.products.get_by_name(products[0]).measurements.keys())

res = {}
if request.method == 'POST':
latlng = json.loads( request.body.decode('utf-8') )
Expand Down Expand Up @@ -324,10 +310,8 @@ def getIndices(request):
Called for drawing the terrain profiles
Request has the array of lat/long covered by the poly-line pointers
returns an array of elevation at all the above acquired points
'''

@login_required
def getElevations(request):
SAMPLES = 3601
Expand All @@ -347,6 +331,7 @@ def getElevations(request):
lngLowerBound = int(hgt_file[4:7])
lngUpperBound = lngLowerBound + 1

print([latLowerBound,latUpperBound,lngLowerBound,lngUpperBound])
res = {}
for i in latLngs:
lat = i['lat']
Expand Down
193 changes: 193 additions & 0 deletions myproject/static/js/SliderControl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
L.Control.SliderControl = L.Control.extend({
options: {
position: 'topright',
layers: null,
timeAttribute: 'time',
isEpoch: false, // whether the time attribute is seconds elapsed from epoch
startTimeIdx: 0, // where to start looking for a timestring
timeStrLength: 19, // the size of yyyy-mm-dd hh:mm:ss - if millis are present this will be larger
maxValue: -1,
minValue: 0,
showAllOnStart: false,
markers: null,
range: false,
follow: false,
sameDate: false,
alwaysShowDate : false,
rezoom: null
},

initialize: function (options) {
L.Util.setOptions(this, options);
this._layer = this.options.layer;

},

extractTimestamp: function(time, options) {
if (options.isEpoch) {
time = (new Date(parseInt(time))).toString(); // this is local time
}
return time.substr(options.startTimeIdx, options.startTimeIdx + options.timeStrLength);
},

setPosition: function (position) {
var map = this._map;

if (map) {
map.removeControl(this);
}

this.options.position = position;

if (map) {
map.addControl(this);
}
this.startSlider();
return this;
},

onAdd: function (map) {
this.options.map = map;

// Create a control sliderContainer with a jquery ui slider
var sliderContainer = L.DomUtil.create('div', 'slider', this._container);
$(sliderContainer).append('<div id="leaflet-slider" style="width:200px"><div class="ui-slider-handle"></div><div id="slider-timestamp" style="width:200px; margin-top:13px; background-color:#FFFFFF; text-align:center; border-radius:5px;"></div></div>');
//Prevent map panning/zooming while using the slider
$(sliderContainer).mousedown(function () {
map.dragging.disable();
});
$(document).mouseup(function () {
map.dragging.enable();
//Hide the slider timestamp if not range and option alwaysShowDate is set on false
if (options.range || !options.alwaysShowDate) {
$('#slider-timestamp').html('');
}
});

var options = this.options;
this.options.markers = [];

//If a layer has been provided: calculate the min and max values for the slider
if (this._layer) {
var index_temp = 0;
this._layer.eachLayer(function (layer) {
options.markers[index_temp] = layer;
++index_temp;
});
options.maxValue = index_temp - 1;
this.options = options;
} else {
console.log("Error: You have to specify a layer via new SliderControl({layer: your_layer});");
}
return sliderContainer;
},

onRemove: function (map) {
//Delete all markers which where added via the slider and remove the slider div
for (i = this.options.minValue; i <= this.options.maxValue; i++) {
map.removeLayer(this.options.markers[i]);
}
$('#leaflet-slider').remove();

// unbind listeners to prevent memory leaks
$(document).off("mouseup");
$(".slider").off("mousedown");
},

startSlider: function () {
_options = this.options;
_extractTimestamp = this.extractTimestamp
var index_start = _options.minValue;
if(_options.showAllOnStart){
index_start = _options.maxValue;
if(_options.range) _options.values = [_options.minValue,_options.maxValue];
else _options.value = _options.maxValue;
}
$("#leaflet-slider").slider({
range: _options.range,
value: _options.value,
values: _options.values,
min: _options.minValue,
max: _options.maxValue,
sameDate: _options.sameDate,
step: 1,
slide: function (e, ui) {
var map = _options.map;
var fg = L.featureGroup();
if(!!_options.markers[ui.value]) {
// If there is no time property, this line has to be removed (or exchanged with a different property)
if(_options.markers[ui.value].feature !== undefined) {
if(_options.markers[ui.value].feature.properties[_options.timeAttribute]){
if(_options.markers[ui.value]) $('#slider-timestamp').html(
_extractTimestamp(_options.markers[ui.value].feature.properties[_options.timeAttribute], _options));
}else {
console.error("Time property "+ _options.timeAttribute +" not found in data");
}
}else {
// set by leaflet Vector Layers
if(_options.markers [ui.value].options[_options.timeAttribute]){
if(_options.markers[ui.value]) $('#slider-timestamp').html(
_extractTimestamp(_options.markers[ui.value].options[_options.timeAttribute], _options));
}else {
console.error("Time property "+ _options.timeAttribute +" not found in data");
}
}

var i;
// clear markers
for (i = _options.minValue; i <= _options.maxValue; i++) {
if(_options.markers[i]) map.removeLayer(_options.markers[i]);
}
if(_options.range){
// jquery ui using range
for (i = ui.values[0]; i <= ui.values[1]; i++){
if(_options.markers[i]) {
map.addLayer(_options.markers[i]);
fg.addLayer(_options.markers[i]);
}
}
}else if(_options.follow){
for (i = ui.value - _options.follow + 1; i <= ui.value ; i++) {
if(_options.markers[i]) {
map.addLayer(_options.markers[i]);
fg.addLayer(_options.markers[i]);
}
}
}else if(_options.sameDate){
var currentTime;
if (_options.markers[ui.value].feature !== undefined) {
currentTime = _options.markers[ui.value].feature.properties.time;
} else {
currentTime = _options.markers[ui.value].options.time;
}
for (i = _options.minValue; i <= _options.maxValue; i++) {
if(_options.markers[i].options.time == currentTime) map.addLayer(_options.markers[i]);
}
}else{
for (i = _options.minValue; i <= ui.value ; i++) {
if(_options.markers[i]) {
map.addLayer(_options.markers[i]);
fg.addLayer(_options.markers[i]);
}
}
}
};
if(_options.rezoom) {
map.fitBounds(fg.getBounds(), {
maxZoom: _options.rezoom
});
}
}
});
if (!_options.range && _options.alwaysShowDate) {
$('#slider-timestamp').html(_extractTimeStamp(_options.markers[index_start].feature.properties[_options.timeAttribute], _options));
}
for (i = _options.minValue; i <= index_start; i++) {
_options.map.addLayer(_options.markers[i]);
}
}
});

L.control.sliderControl = function (options) {
return new L.Control.SliderControl(options);
};
Loading

0 comments on commit ce092b4

Please sign in to comment.