Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim UI and bug fixes #1

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v4
with:
name: tobara8/map-tiles-downloader
name: tblauer/map-tiles-downloader
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: "latest"
- name: Scan image
id: scan
uses: anchore/scan-action@v3
with:
image: "tobara8/map-tiles-downloader:latest"
image: "tblauer/map-tiles-downloader:latest"
fail-build: false
acs-report-enable: true
- name: upload Anchore scan SARIF report
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Map Tiles Downloader
[![Docker Image CI](https://github.com/tobara8/MapTilesDownloader/actions/workflows/docker-image.yml/badge.svg?branch=master)](https://github.com/tobara8/MapTilesDownloader/actions/workflows/docker-image.yml)
<img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Ftobara8%2Fmap-tiles-downloader%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/tobara8/map-tiles-downloader">
[![Docker Image Size](https://img.shields.io/docker/image-size/tobara8/map-tiles-downloader?logo=Docker)](https://hub.docker.com/r/jokobsk/pi.alert)
<img src="https://img.shields.io/docker/pulls/tobara8/map-tiles-downloader?logo=docker&color=0aa8d2&logoColor=fff" alt="Docker Pulls">
[![Docker Image CI](https://github.com/tblauer/MapTilesDownloader/actions/workflows/docker-image.yml/badge.svg?branch=master)](https://github.com/tblauer/MapTilesDownloader/actions/workflows/docker-image.yml)
<img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Ftblauer%2Fmap-tiles-downloader%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/tobara8/map-tiles-downloader">
[![Docker Image Size](https://img.shields.io/docker/image-size/tblauer/map-tiles-downloader?logo=Docker)](https://hub.docker.com/r/jokobsk/pi.alert)
<img src="https://img.shields.io/docker/pulls/tblauer/map-tiles-downloader?logo=docker&color=0aa8d2&logoColor=fff" alt="Docker Pulls">

**A super easy to use GUI for downloading map tiles**

<p align="center">
<img src="gif/map-tiles-downloader.gif">
</p>

## This is a fork of a fork

The original project is https://github.com/AliFlux/MapTilesDownloader
It was forked by tobara8 to add attribution https://github.com/tobara-va/MapTilesDownloader
I forked tobara8 version and:
- Removed some UI functionality, the drawing of individual map tile squares, and some logging to help improve performance.
- Fixed a crash and memory issue as described here https://github.com/AliFlux/MapTilesDownloader/issues/12


## So what does it do?

This tiny python based script allows you to download map tiles from Google, Bing, Open Street Maps, ESRI, NASA, and other providers. This script comes with an easy to use web based map UI for selecting the area and previewing tiles.
Expand All @@ -31,15 +40,8 @@ Needs **Python 3.0+**, [Pillow](https://pypi.org/project/Pillow/) library, and a
Docker is a pretty simple way to install and contain applications. [Install Docker on your system](https://www.docker.com/products/docker-desktop), and paste this on your command line:

```sh
docker run -v $PWD/output:/app/output/ -p 8080:8080 -it tobara8/map-tiles-downloader
docker run -v $PWD/output:/app/output/ -p 8080:8080 -it tblauer/map-tiles-downloader
```
or for a faster but less verbose UI

```sh
docker run -v $PWD/output:/app/output/ -p 8080:8080 -it tobara8/map-tiles-downloader:quiet-ui
```

Now open the browser and head over to `http://localhost:8080`. The downloaded maps will be stored in the `output` directory.

## Purpose

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
map-downloader:
image: tobara/map-tiles-downloader
image: tblauer/map-tiles-downloader
ports:
- 8080:8080
restart: unless-stopped
Expand Down
67 changes: 42 additions & 25 deletions src/UI/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $(function() {
});

geocoder = new MapboxGeocoder({ accessToken: mapboxgl.accessToken });
var control = map.addControl(geocoder);
map.addControl(geocoder);
}

function initializeMaterialize() {
Expand All @@ -76,7 +76,7 @@ $(function() {
for(var key in sources) {
var url = sources[key];

if(url == "") {
if(url === "") {
dropdown.append("<hr/>");
continue;
}
Expand Down Expand Up @@ -139,11 +139,11 @@ $(function() {
var outputFileBox = $("#output-file-box")
$("#output-type").change(function() {
var outputType = $("#output-type").val();
if(outputType == "mbtiles") {
if(outputType === "mbtiles") {
outputFileBox.val("tiles.mbtiles")
} else if(outputType == "repo") {
} else if(outputType === "repo") {
outputFileBox.val("tiles.repo")
} else if(outputType == "directory") {
} else if(outputType === "directory") {
outputFileBox.val("{z}/{x}/{y}.png")
}
})
Expand Down Expand Up @@ -243,7 +243,7 @@ $(function() {

function getArrayByBounds(bounds) {

var tileArray = [
let tileArray = [
[ bounds.getSouthWest().lng, bounds.getNorthEast().lat ],
[ bounds.getNorthEast().lng, bounds.getNorthEast().lat ],
[ bounds.getNorthEast().lng, bounds.getSouthWest().lat ],
Expand All @@ -269,7 +269,7 @@ $(function() {

var areaPolygon = draw.getAll().features[0];

if(turf.booleanDisjoint(polygon, areaPolygon) == false) {
if(turf.booleanDisjoint(polygon, areaPolygon) === false) {
return true;
}

Expand All @@ -293,7 +293,7 @@ $(function() {

var rects = [];

var outputScale = $("#output-scale").val();
//var outputScale = $("#output-scale").val();
//var thisZoom = zoomLevel - (outputScale-1)
var thisZoom = zoomLevel

Expand All @@ -302,10 +302,10 @@ $(function() {
var BY = lat2tile(bounds.getSouthWest().lat, thisZoom);
var RX = long2tile(bounds.getNorthEast().lng, thisZoom);

for(var y = TY; y <= BY; y++) {
for(var x = LX; x <= RX; x++) {
for(let y = TY; y <= BY; y++) {
for(let x = LX; x <= RX; x++) {

var rect = getTileRect(x, y, thisZoom);
const rect = getTileRect(x, y, thisZoom);

if(isTileInSelection(rect)) {
rects.push({
Expand Down Expand Up @@ -407,10 +407,10 @@ $(function() {
for (var i = z; i > 0; i--) {
var digit = '0';
var mask = 1 << (i - 1);
if ((x & mask) != 0) {
if ((x & mask) !== 0) {
digit++;
}
if ((y & mask) != 0) {
if ((y & mask) !== 0) {
digit++;
digit++;
}
Expand Down Expand Up @@ -438,7 +438,7 @@ $(function() {
$("#download-button").click(startDownloading)
$("#stop-button").click(stopDownloading)

var timestamp = Date.now().toString();
//var timestamp = Date.now().toString();
//$("#output-directory-box").val(timestamp)
}

Expand All @@ -457,7 +457,7 @@ $(function() {

async function startDownloading() {

if(draw.getAll().features.length == 0) {
if(draw.getAll().features.length === 0) {
M.toast({html: 'You need to select a region first.', displayLength: 3000})
return;
}
Expand Down Expand Up @@ -521,7 +521,8 @@ $(function() {
return;
}

var boxLayer = previewRect(item);
// TB - Commenting out for performance, no need to draw box
// var boxLayer = previewRect(item);

var url = "/download-tile";

Expand Down Expand Up @@ -554,9 +555,13 @@ $(function() {
return;
}

if(data.code == 200) {
showTinyTile(data.image)
logItem(item.x, item.y, item.z, data.message);
if(data.code === 200) {
// TB - Commenting out for performance, no need to draw box
// showTinyTile(data.image)
// Only log every 100th item, try to improve performance
if (i % 100 === 0) {
logItem(item.x, item.y, item.z, data.message);
}
} else {
logItem(item.x, item.y, item.z, data.code + " Error downloading tile");
}
Expand All @@ -573,11 +578,22 @@ $(function() {
}).always(function(data) {
i++;

removeLayer(boxLayer);
updateProgress(i, allTiles.length);
// TB - Layer was not added for performance, no need to remove
// removeLayer(boxLayer);
// Only update progress on every 100th download, performance
if (i % 100 === 0) {
updateProgress(i, allTiles.length);
}

done();


// TB Added to avoid out of memory crash that happened after downloading lots of tiles
// Remove the completed request from the array, avoid out of memory crash
let removeIndex = requests.indexOf(request);
if (removeIndex >= 0) {
requests.splice(removeIndex, 1);
}

if(cancellationToken) {
return;
}
Expand Down Expand Up @@ -622,9 +638,10 @@ $(function() {
function logItemRaw(text) {

var logger = $('#log-view');
logger.val(logger.val() + '\n' + text);

logger.scrollTop(logger[0].scrollHeight);
// TB - Just replace current value, don't keep a running log for performance & memory saving
//logger.val(logger.val() + '\n' + text);
logger.val('\n' + text);
//logger.scrollTop(logger[0].scrollHeight);
}

function clearLogs() {
Expand Down
6 changes: 3 additions & 3 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def do_POST(self):

filePath = os.path.join("output", outputDirectory, outputFile)

print("\n")
#print("\n")

if self.writerByType(outputType).exists(filePath, x, y, z):
result["code"] = 200
Expand All @@ -102,7 +102,7 @@ def do_POST(self):

result["code"] = Utils.downloadFileScaled(source, tempFilePath, x, y, z, outputScale)

print("HIT: " + source + "\n" + "RETURN: " + str(result["code"]))
#print("HIT: " + source + "\n" + "RETURN: " + str(result["code"]))

if os.path.isfile(tempFilePath):
self.writerByType(outputType).addTile(lock, filePath, tempFilePath, x, y, z, outputScale)
Expand All @@ -113,7 +113,7 @@ def do_POST(self):
os.remove(tempFilePath)

result["message"] = 'Tile Downloaded'
print("SAVE: " + filePath)
#print("SAVE: " + filePath)

else:
result["message"] = 'Download failed'
Expand Down
Loading