-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for pmtiles * Generate pmtiles in upload task
- Loading branch information
1 parent
ac5bf35
commit 351618c
Showing
9 changed files
with
217 additions
and
125 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# coding=utf-8 | ||
"""Cloud Native GIS.""" | ||
import os | ||
import re | ||
|
||
from django.http import FileResponse, Http404, HttpResponse | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from cloud_native_gis.models import Layer | ||
|
||
|
||
def serve_pmtiles(request, layer_uuid): | ||
"""Serve pmtiles.""" | ||
layer = get_object_or_404(Layer, unique_id=layer_uuid) | ||
|
||
if not layer.pmtile: | ||
raise Http404("PMTile file not found for this layer.") | ||
|
||
full_path = layer.pmtile.path | ||
|
||
if not os.path.exists(full_path): | ||
raise Http404("PMTile file does not exist.") | ||
|
||
range_header = request.headers.get('Range') | ||
if range_header: | ||
range_match = re.match( | ||
r'bytes=(\d+)-(\d*)', range_header) | ||
if range_match: | ||
start_byte = int(range_match.group(1)) | ||
end_byte = int( | ||
range_match.group(2)) if ( | ||
range_match.group(2)) else ( | ||
os.path.getsize(full_path) - 1) | ||
|
||
file_size = os.path.getsize(full_path) | ||
content_length = end_byte - start_byte + 1 | ||
content_range = f'bytes {start_byte}-{end_byte}/{file_size}' | ||
|
||
file = open(full_path, 'rb') | ||
file.seek(start_byte) | ||
|
||
response = HttpResponse( | ||
file.read(content_length), | ||
status=206, | ||
content_type='application/octet-stream') | ||
response['Content-Length'] = content_length | ||
response['Content-Range'] = content_range | ||
response['Accept-Ranges'] = 'bytes' | ||
return response | ||
|
||
return FileResponse( | ||
open(full_path, 'rb'), | ||
content_type='application/octet-stream') |
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
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
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
232 changes: 116 additions & 116 deletions
232
...static/cloud_native_gis/index-DRZ64yjZ.js → ...static/cloud_native_gis/index-yKDiDp5s.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ic/cloud_native_gis/index-DRZ64yjZ.js.map → ...ic/cloud_native_gis/index-yKDiDp5s.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
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
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