diff --git a/backend/promis/backend_api/serializer.py b/backend/promis/backend_api/serializer.py index cfbc616..cc03b73 100644 --- a/backend/promis/backend_api/serializer.py +++ b/backend/promis/backend_api/serializer.py @@ -294,6 +294,10 @@ def gen_selection(): # Intersection of search polygon and the orbit isect = obj.session.geo_line.intersection(poly) + #django docs say that GEOSGeometry.dims returns -1 for empty GeometryCollection + if isect.dims == -1: + return + # Making sure isect is a collection of geolines, not a single one if type(isect) is not MultiLineString: isect = [ isect ] diff --git a/backend/promis/backend_api/views.py b/backend/promis/backend_api/views.py index beeb8a5..a11cd93 100644 --- a/backend/promis/backend_api/views.py +++ b/backend/promis/backend_api/views.py @@ -30,6 +30,7 @@ import datetime from rest_framework.decorators import permission_classes +from django.contrib.gis.geos import GEOSGeometry class PromisViewSet(viewsets.ReadOnlyModelViewSet): '''Collects most commonly used View stuff''' @@ -297,13 +298,17 @@ def get_queryset(self): if space_project: filter_opts['channel__device__space_project'] = int(space_project) - poly = self.request.query_params.get('polygon') - - if poly: - try: - filter_opts['session__geo_line__intersects'] = poly - except ValueError: - raise NotFound("Invalid WKT for polygon selection") + # This code doesn't work because poly is a 3d polygon (geography), + # while geo_line is 2d (geometry) + # and it seems like it's not needed anyway, + # because this work is already done in DataSerializer.get_selection. + # + # poly = self.request.query_params.get('polygon') + # if poly: + # try: + # filter_opts['session__geo_line__intersects'] = poly + # except ValueError: + # raise NotFound("Invalid WKT for polygon selection") # Applying the filter return models.Measurement.objects.filter(**filter_opts) diff --git a/backend/requirements.txt b/backend/requirements.txt index 10209af..50d942c 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -12,7 +12,6 @@ dj-database-url==0.4.2 django-hvad==1.8.0 djangorestframework-gis==0.11 djangorestframework-filters==0.9.1 -django-filters==0.2.1 pytz==2017.2 # for datetime conversions django_loaddata_stdin==0.1.0 # for loading test data from the host pytest-django==3.5.1 diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 4ad3cbe..890c090 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -13,6 +13,7 @@ ADD package.json /usr/src/promis/ # Install packages needed RUN npm install ADD webpack.config.js /usr/src/promis/ +RUN npm i canvg # Add the post install script ADD postinstall.sh /usr/src/promis diff --git a/frontend/app/components/Quicklook.js b/frontend/app/components/Quicklook.js index 656b2f0..a415b61 100644 --- a/frontend/app/components/Quicklook.js +++ b/frontend/app/components/Quicklook.js @@ -6,6 +6,7 @@ import { saveAs } from 'file-saver'; import { dataURLToBlob } from 'blob-util'; import Modal from './Modal'; import { strings } from "../localizations/localization"; +import Canvg from 'canvg'; export default class Quicklook extends Component { constructor(props) { @@ -22,7 +23,7 @@ export default class Quicklook extends Component { this.data = this.formatData(this.props.data, this.props.time); } - componentDidUpdate() { + componentDidMount() { /* get rendered SVG graph element */ if(this.el) { this.svg = findDOMNode(this.el).querySelector('svg'); @@ -58,7 +59,6 @@ export default class Quicklook extends Component { if(this.svg) { var canvas = null, context = null; var imageData = null, image = null; - /* setup offscreen canvas */ canvas = document.createElement('canvas'); canvas.width = this.props.graphWidth; @@ -71,21 +71,28 @@ export default class Quicklook extends Component { /* create new image from svg */ imageData = 'data:image/svg+xml,' + new XMLSerializer().serializeToString(this.svg); - image = new Image(); + image = new Image() - /* draw image callback */ + /* draw image callback */ image.onload = function() { context.drawImage(image, 0, 0); - this.makeWatermark(canvas, context); - dataURLToBlob(canvas.toDataURL('image/png')).then(function(blob) { - saveAs(blob, this.makeFilename()); - }.bind(this)); + var dataURL = canvas.toDataURL('image/png'); + var data = atob(dataURL.substring('data:image/png;base64,'.length)), asArray = new Uint8Array(data.length); + + for (var i = 0, len = data.length; i < len; ++i) + { + asArray[i] = data.charCodeAt(i); + } + + var blob = new Blob([asArray.buffer], {type: 'image/png'}); + saveAs(blob, this.makeFilename()); }.bind(this); /* set image data and trigger callback when done */ image.src = imageData; + } else window.alert(strings.alert); } diff --git a/frontend/app/constants/Selection.js b/frontend/app/constants/Selection.js index 5d93a5a..e03373d 100644 --- a/frontend/app/constants/Selection.js +++ b/frontend/app/constants/Selection.js @@ -60,11 +60,20 @@ export function selectionToPolygon(selection) { case Types.Rect: let bounds = Leaflet.latLngBounds(selection.data[0], selection.data[1]); //let center = bounds.getCenter(); - points.push(bounds.getSouthWest()); points.push(bounds.getSouthEast()); + // had to add these two intermidiate points to overcome the bug + // "Antipodal (180 degrees long) edge detected!" + if (selection.data[0][0] == -90 && selection.data[1][0] == 90) + { + points.push({lat: 0, lng: bounds.getSouthEast().lng}) + } points.push(bounds.getNorthEast()); points.push(bounds.getNorthWest()); + if (selection.data[0][0] == -90 && selection.data[1][0] == 90) + { + points.push({lat: 0, lng: bounds.getNorthWest().lng}) + } break; case Types.Circle: @@ -84,8 +93,8 @@ export function selectionToPolygon(selection) { points.push(points[0]); points.forEach(function(point) { - let lat = fixedPoint(point.lat ? point.lat : point[0]); - let lng = fixedPoint(point.lng ? point.lng : point[1]); + let lat = fixedPoint(selection.type == Types.Polygon ? point[0] : point.lat); + let lng = fixedPoint(selection.type == Types.Polygon ? point[1] : point.lng); coords.push(new Array(lng, lat)); }); diff --git a/frontend/package.json b/frontend/package.json index 2f15fc1..967115b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -19,7 +19,7 @@ "axios": "^0.19.0", "blob-util": "^1.2.1", "bootstrap": "^3.3.7", - "cesium": "^1.33.0", + "cesium": "1.33.0", "d3": "^3.5.17", "document-ready": "^2.0.1", "es6-promise-promise": "^1.0.0",