From bf6c42b3f7b2410ec199e656d112f45ec72b6b42 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 6 Dec 2016 15:12:40 +0100 Subject: [PATCH] close #4 add custom tile server management --- CHANGELOG.md | 2 + appinfo/database.xml | 62 +++++++++++++++++++++++++++ appinfo/info.xml | 2 +- appinfo/routes.php | 2 + controller/pagecontroller.php | 17 ++++++++ js/gpxedit.js | 80 +++++++++++++++++++++++++++++++++++ templates/gpxcontent.php | 37 ++++++++++++++++ 7 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 appinfo/database.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ad43b5..3497435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). [#1](https://gitlab.com/eneiluj/gpxedit-oc/issues/1) @eneiluj - ability to load jpg files as markers, conversion with gpsbabel like kml and csv [#3](https://gitlab.com/eneiluj/gpxedit-oc/issues/3) @eneiluj +- custom tile server management + [#4](https://gitlab.com/eneiluj/gpxedit-oc/issues/3) @eneiluj ### Fixed - remove $.parseXML, apparently useless and producing errors diff --git a/appinfo/database.xml b/appinfo/database.xml new file mode 100644 index 0000000..7615539 --- /dev/null +++ b/appinfo/database.xml @@ -0,0 +1,62 @@ + + + *dbname* + true + false + utf8 + + *dbprefix*gpxedit_tile_servers + + + id + integer + 0 + true + 1 + 4 + + + user + text + true + 64 + + + servername + text + true + 300 + + + url + text + true + 300 + + +
+ + *dbprefix*gpxedit_options_values + + + id + integer + 0 + true + 1 + 4 + + + user + text + true + 64 + + + jsonvalues + clob + true + + +
+
diff --git a/appinfo/info.xml b/appinfo/info.xml index 13fb21f..d70c484 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -40,7 +40,7 @@ Any feedback will be appreciated. AGPL Simple GPX file editor Julien Veyssier - 0.0.1 + 0.0.2 GpxEdit https://gitlab.com/eneiluj/gpxedit-oc/wikis/userdoc diff --git a/appinfo/routes.php b/appinfo/routes.php index 801e43b..00b688c 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -24,5 +24,7 @@ return [ ['name' => 'page#savegpx', 'url' => '/savegpx', 'verb' => 'POST'], ['name' => 'page#getdircontent', 'url' => '/getdircontent', 'verb' => 'POST'], ['name' => 'page#getdircontentdir', 'url' => '/getdircontentdir', 'verb' => 'POST'], + ['name' => 'utils#addTileServer', 'url' => '/addTileServer', 'verb' => 'POST'], + ['name' => 'utils#deleteTileServer', 'url' => '/deleteTileServer', 'verb' => 'POST'], ] ]; diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index d8e8515..38f3bf8 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -160,12 +160,15 @@ class PageController extends Controller { } } + $tss = $this->getUserTileServers(); + // PARAMS to view sort($alldirs); $params = [ 'dirs'=>$alldirs, 'username'=>$this->userId, + 'tileservers'=>$tss, 'gpxedit_version'=>$this->appVersion ]; $response = new TemplateResponse('gpxedit', 'main', $params); @@ -424,4 +427,18 @@ class PageController extends Controller { return $response; } + private function getUserTileServers(){ + // custom tile servers management + $sqlts = 'SELECT servername, url FROM *PREFIX*gpxedit_tile_servers '; + $sqlts .= 'WHERE '.$this->dbdblquotes.'user'.$this->dbdblquotes.'=\''.$this->userId.'\';'; + $req = $this->dbconnection->prepare($sqlts); + $req->execute(); + $tss = Array(); + while ($row = $req->fetch()){ + $tss[$row["servername"]] = $row["url"]; + } + $req->closeCursor(); + return $tss; + } + } diff --git a/js/gpxedit.js b/js/gpxedit.js index d0fbf6b..7857851 100644 --- a/js/gpxedit.js +++ b/js/gpxedit.js @@ -127,6 +127,13 @@ function load_map() { 'Watercolor' : watercolor, 'OpenStreetMap France': osmfr }; + // add custom layers + $('#tileserverlist li').each(function(){ + var sname = $(this).attr('name'); + var surl = $(this).attr('title'); + baseLayers[sname] = new L.TileLayer(surl, + {maxZoom: 18, attribution: 'custom tile server'}); + }); gpxedit.baseLayers = baseLayers; var baseOverlays = { 'OsmFr Route500': route, @@ -512,6 +519,71 @@ function loadFile(file){ }); } +function deleteTileServer(li){ + var sname = li.attr('name'); + var req = { + servername : sname + } + var url = OC.generateUrl('/apps/gpxedit/deleteTileServer'); + $.ajax({ + type:'POST', + url:url, + data:req, + async:true + }).done(function (response) { + //alert(response.done); + if (response.done){ + li.remove(); + var activeLayerName = gpxedit.activeLayers.getActiveBaseLayer().name; + // if we delete the active layer, first select another + if (activeLayerName === sname){ + $('input.leaflet-control-layers-selector').first().click(); + } + gpxedit.activeLayers.removeLayer(gpxedit.baseLayers[sname]); + delete gpxedit.baseLayers[sname]; + } + }).always(function(){ + }); +} + +function addTileServer(){ + var sname = $('#tileservername').val(); + var surl = $('#tileserverurl').val(); + if (sname === '' || surl === ''){ + alert('Server name or server url should not be empty'); + return; + } + $('#tileservername').val(''); + $('#tileserverurl').val(''); + + var req = { + servername : sname, + serverurl : surl + } + var url = OC.generateUrl('/apps/gpxedit/addTileServer'); + $.ajax({ + type:'POST', + url:url, + data:req, + async:true + }).done(function (response) { + //alert(response.done); + if (response.done){ + $('#tileserverlist ul').prepend( + '
  • '+sname+'
  • ' + ); + // add tile server in leaflet control + var newlayer = new L.TileLayer(surl, + {maxZoom: 18, attribution: 'custom tile server'}); + gpxedit.activeLayers.addBaseLayer(newlayer, sname); + gpxedit.baseLayers[sname] = newlayer; + } + }).always(function(){ + }); +} + $(document).ready(function(){ gpxedit.username = $('p#username').html(); load_map(); @@ -625,6 +697,14 @@ $(document).ready(function(){ } }); + // Custom tile server management + $('body').on('click','#tileserverlist button', function(e) { + deleteTileServer($(this).parent()); + }); + $('#addtileserver').click(function(){ + addTileServer(); + }); + }); })(jQuery, OC); diff --git a/templates/gpxcontent.php b/templates/gpxcontent.php index 0a19897..de9849a 100644 --- a/templates/gpxcontent.php +++ b/templates/gpxcontent.php @@ -2,6 +2,7 @@ @@ -59,6 +60,42 @@ p($_['username']); echo '

    '."\n"; ?> + +