Skip to content

Commit

Permalink
static tile exporter wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sylae committed Jun 30, 2021
1 parent 224a115 commit 830a9be
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.qgs~
export/*
export-tiles/*

# pywikibot nonsense
logs/*
Expand Down
22 changes: 22 additions & 0 deletions renderTiles.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# this is designed to run on keira's computer in particular. it shouldn't be *too* difficult to change, however.
# note that to export... i think all you'll need tbh is uhhh the Roadgeek 2005 fonts, plus probably changing a few env vars somewhere

Remove-Item "export-tiles" -Recurse -ErrorAction Ignore
mkdir "export-tiles" | out-null

$env:devilfishGitRev = $(git describe --tags --dirty --always)

Measure-Command { python-qgis .\renderTiles.py devilfish.qgs | Out-Default }

php renderTilesHTMLFixer.php

Measure-Command {
Get-ChildItem "export-tiles" -recurse -Filter *.png | Foreach-Object -Parallel {
optipng $_.FullName
} -ThrottleLimit 8
}

Measure-Command {
scp export-tiles/map.cdn.html syl.ae:~/public_html/wormrpmap.php
aws s3 sync export-tiles/ s3://cdn.syl.ae/wormrp/map/ --acl public-read
}
23 changes: 23 additions & 0 deletions renderTiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from qgis.core import *
from qgis import processing
from osgeo import gdal
import os
import sys
from PyQt5.QtGui import QColor

gdal.PushErrorHandler('CPLQuietErrorHandler')
qgs = QgsApplication([], False)
qgs.initQgis()

sys.path.append('H:\\OSGeo4W\\apps\\qgis\\python\\plugins')

import processing
from processing.core.Processing import Processing
Processing.initialize()

project = QgsProject.instance()
project.read(sys.argv[1])

processing.run("qgis:tilesxyzdirectory", {'EXTENT':'-91.145624973,-89.211017226,47.356527267,48.282137008 [EPSG:4326]','ZOOM_MIN':11,'ZOOM_MAX':15,'DPI':96,'BACKGROUND_COLOR':QColor(0, 0, 0, 0),'TILE_FORMAT':0,'QUALITY':75,'METATILESIZE':4,'TILE_WIDTH':256,'TILE_HEIGHT':256,'TMS_CONVENTION':False,'OUTPUT_DIRECTORY':'export-tiles','OUTPUT_HTML':'export-tiles/map.tpl.html'})

qgs.exitQgis()
22 changes: 22 additions & 0 deletions renderTilesHTMLFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// this entire script is a hack lmao

$version = $_SERVER['devilfishGitRev'] ?? "unknown";
$tpl = file_get_contents("export-tiles/map.tpl.html");

$tpl = str_replace(
"Generated by TilesXYZ",
'devilfish.qgs // renderTiles.ps1 | tag <a href="https://github.com/sylae/devilfish-map" target="_blank">'.$version.'</a> | '.date(DATE_ATOM),
$tpl
);
$tpl = str_replace(
"Leaflet Preview",
'Devilfish, Minnesota',
$tpl
);

$local = str_replace("file:///export-tiles", ".", $tpl);
$cdn = str_replace("file:///export-tiles", "https://cdn.syl.ae/wormrp/map", $tpl);

file_put_contents("export-tiles/map.local.html", $local);
file_put_contents("export-tiles/map.cdn.html", $cdn);

0 comments on commit 830a9be

Please sign in to comment.