diff --git a/app/Http/Controllers/DownloadController.php b/app/Http/Controllers/DownloadController.php index 5c109e7dede310ed5e263888a0a037b94a1e2aa6..c1deeed2d6e4f26785a887d256109d95518eca00 100644 --- a/app/Http/Controllers/DownloadController.php +++ b/app/Http/Controllers/DownloadController.php @@ -25,6 +25,9 @@ public function listFiles($minLon, $minLat, $maxLon, $maxLat){ } socket_close($socket); + if($content == "") + abort(404, "File not found"); + $response = Response::make($content, 200); $response->header('Content-Type', 'application/json'); $response->header('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate'); @@ -53,7 +56,7 @@ public function downloadFiles($minLon, $minLat, $maxLon, $maxLat){ socket_close($socket); # The result is a path to the Zip File that will get downloaded - if(file_exists($file)){ + if(file_exists($file) && filesize($file) > 0){ return response()->download($file, "offline-data.tar", [ "Content-Type" => "application/tar", diff --git a/resources/assets/js/map.js b/resources/assets/js/map.js index 7f8d474b0b3b7af202bb82151610f570b0da55da..fac315fb99ef52d2d41f5841b1b85d41f48d94b3 100644 --- a/resources/assets/js/map.js +++ b/resources/assets/js/map.js @@ -41,6 +41,7 @@ InteractiveMap.prototype.initMap = function() { return ol.proj.transform(point, 'EPSG:3857', 'EPSG:4326'); } var source = null; + var labels = null; if(typeof android === "undefined"){ // We are not serving this for the app so we'll use our regular Tile-Serve source = new ol.source.OSM({ @@ -57,7 +58,23 @@ InteractiveMap.prototype.initMap = function() { ol.source.OSM.ATTRIBUTION, ], //url: 'https://tiles.metager.de/{z}/{x}/{y}.png' - url: '/tile_cache/{z}/{x}/{y}.png' + url: '/tiles/tile/{z}/{x}/{y}.png' + }); + labels = new ol.source.OSM({ + attributions: [ + new ol.Attribution({ + html: '© ' + '<a href="https://metager.de/">MetaGer.de</a>' + }), + new ol.Attribution({ + html: '| <a href="https://metager.de/impressum">Impressum</a>' + }), + new ol.Attribution({ + html: '| © ' + '<a href="http://nominatim.openstreetmap.org/">Nominatim</a>' + }), + ol.source.OSM.ATTRIBUTION, + ], + //url: 'https://tiles.metager.de/{z}/{x}/{y}.png' + url: '/tiles/label/{z}/{x}/{y}.png' }); }else{ // This is for our Android App we'll use another Tile-Server that has it's cache Disabled @@ -88,19 +105,25 @@ InteractiveMap.prototype.initMap = function() { zoom = null; this.updateMapPositionOnGps = false; } - var map = new ol.Map({ - layers: [ + var layers = []; + if(source != null){ + layers.push( new ol.layer.Tile({ preload: 0, source: source - }),/* + }) + ) + } + if(labels != null){ + layers.push( new ol.layer.Tile({ - source: new ol.source.TileDebug({ - projection: 'EPSG:3857', - tileGrid: source.getTileGrid() - }) - })*/ - ], + preload: 0, + source: labels + }) + ) + } + var map = new ol.Map({ + layers: layers, target: 'map', controls: ol.control.defaults({ attributionOptions: /** @type {olx.control.AttributionOptions} */ ({ diff --git a/routes/web.php b/routes/web.php index e23f206be01e997802b3df5f262b9d1db534f813..40a812f221266b605f518815e0f6b90bff214c60 100644 --- a/routes/web.php +++ b/routes/web.php @@ -27,6 +27,67 @@ Route::group(['prefix' => 'download'], function(){ Route::get('{minx}/{miny}/{maxx}/{maxy}/{zoomstart}/{zoomend}', 'DownloadController@downloadArea'); }); +Route::get('tile_cache/{z}/{x}/{y}.png', function($z, $x, $y){ + $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT")); + + socket_write($socket, "generate-tile;$z;$x;$y\n", strlen("generate-tile;$z;$x,$y\n")); + + $content = ""; + while(true){ + $tmp = socket_read($socket, 4096); + if($tmp == "") break; + else $content .= $tmp; + } + $response = Response::make($content, 200); + $response->header('Content-Type', 'image/png'); + $response->header('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate'); + $response->header('Pragma', 'no-cache'); + $response->header('Expires', 'Wed, 11 Jan 1984 05:00:00 GMT'); + return $response; +}); + +Route::group(['prefix' => 'tiles'], function(){ + Route::get('tile/{z}/{x}/{y}.png', function($z, $x, $y){ + $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT")); + + socket_write($socket, "tile-tile;$z;$x;$y\n", strlen("generate-tile;$z;$x,$y\n")); + + $content = ""; + while(true){ + $tmp = socket_read($socket, 4096); + if($tmp == "") break; + else $content .= $tmp; + } + $response = Response::make($content, 200); + $response->header('Content-Type', 'image/png'); + $response->header('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate'); + $response->header('Pragma', 'no-cache'); + $response->header('Expires', 'Wed, 11 Jan 1984 05:00:00 GMT'); + return $response; + }); + Route::get('label/{z}/{x}/{y}.png', function($z, $x, $y){ + $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT")); + + socket_write($socket, "tile-label;$z;$x;$y\n", strlen("generate-tile;$z;$x,$y\n")); + + $content = ""; + while(true){ + $tmp = socket_read($socket, 4096); + if($tmp == "") break; + else $content .= $tmp; + } + $response = Response::make($content, 200); + $response->header('Content-Type', 'image/png'); + $response->header('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate'); + $response->header('Pragma', 'no-cache'); + $response->header('Expires', 'Wed, 11 Jan 1984 05:00:00 GMT'); + return $response; + }); +}); + Route::group(['prefix' => 'map'], function () { Route::get('/', function () { return view('map')->with('css', [elixir('css/general.css'), elixir('css/mapSearch.css'), elixir('css/routing.css')]); @@ -121,24 +182,6 @@ Route::group(['prefix' => 'metager'], function () { Route::get('{search}', 'SearchController@iframeSearch'); }); -Route::get('tile_cache/{z}/{x}/{y}.png', function($z, $x, $y){ - $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT")); - - socket_write($socket, "generate-tile;$z;$x;$y\n", strlen("generate-tile;$z;$x,$y\n")); - $content = ""; - while(true){ - $tmp = socket_read($socket, 4096); - if($tmp == "") break; - else $content .= $tmp; - } - $response = Response::make($content, 200); - $response->header('Content-Type', 'image/png'); - $response->header('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate'); - $response->header('Pragma', 'no-cache'); - $response->header('Expires', 'Wed, 11 Jan 1984 05:00:00 GMT'); - return $response; -});