Ignore:
Timestamp:
Aug 9, 2017, 3:34:04 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, app-cordova, debian/bullseye, debian/jessie, master
Children:
4f36e07, ba861c4
Parents:
24d4504
git-author:
Joachim Langenbach <joachim.langenbach@…> (08/08/17 18:29:49)
git-committer:
Joachim Langenbach <joachim.langenbach@…> (08/09/17 15:34:04)
Message:
  • Improved webclient file uploading
  • Improvded webservice
    • Map uploading
    • tileserver searches it's maps under maps now
  • Maps have spoken names now (set by the user during upload)
  • Moved to leaflet 1.1.0
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webclient/js/main.js

    r24d4504 rf03591a  
    2020*/
    2121
    22 var map;
    23 var polyline;
    24 
    25 function openLink(target){
     22var map = null;
     23var mapLayerCurrent = null;
     24// var mapControl = null;
     25var mapsMetadata = null;
     26var polyline = null;
     27
     28function openLink(target)
     29{
    2630        window.location=target;
    2731}
    2832
    29 function displayDataSet(data){
     33function displayDataSet(data)
     34{
    3035        if(!Array.isArray(data) && !(data instanceof Object)){
    3136                console.log("No data array returned!");
    … …  
    5964        }
    6065        else{
    61                 var track = data["track"];
    62                 var points = [];
    63                 for(var time in track){
    64                         points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
    65                 }
    66                 if(points.length > 0){
    67                         if(!polyline){
    68                                 polyline = L.polyline(points, {color: 'red'}).addTo(map);
    69                         }
    70                         else{
    71                                 polyline.setLatLngs(points);
    72                         }
    73                         map.fitBounds(polyline.getBounds());
    74                 }
    75         }
    76 }
    77 
    78 function displayDataGet() {
     66                if(map == null){
     67                        console.log("No map in use");
     68                }
     69                else{
     70                        var track = data["track"];
     71                        var points = [];
     72                        for(var time in track){
     73                                points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
     74                        }
     75                        if(points.length > 0){
     76                                if(!polyline){
     77                                        polyline = L.polyline(points, {color: 'red'}).addTo(map);
     78                                }
     79                                else{
     80                                        polyline.setLatLngs(points);
     81                                }
     82                                map.fitBounds(polyline.getBounds());
     83                        }
     84                }
     85        }
     86}
     87
     88function displayDataGet()
     89{
    7990        var gnuboatApi = "../webservice/";
    8091        $.getJSON( gnuboatApi, displayDataSet);
    8192}
    8293
    83 function mapSetup(data){
    84         var overlay;
    85         var latitudeTop = data["bounds"][3];
    86         var latitudeBottom = data["bounds"][1];
    87         var longitudeLeft = data["bounds"][0];
    88         var longitudeRight = data["bounds"][2];
    89        
    90         var mapZoomMin = data["minzoom"];
    91         var mapZoomMax = data["maxzoom"];
     94function mapSetup()
     95{
     96        var mapMetadataIndex = $("#mapSelect").val();
     97        if(mapsMetadata == null){
     98                console.log("No mapsMetadata set");
     99        }
     100        if(mapMetadataIndex < 0 || mapMetadataIndex >= mapsMetadata.length){
     101                console.log("Map metadata is outside of range :"+ mapMetadataIndex.toString());
     102                console.log(mapsMetadata);
     103                return;
     104        }
     105        var mapMetadata = mapsMetadata[mapMetadataIndex];
     106       
     107        var latitudeTop = mapMetadata["bounds"][3];
     108        var latitudeBottom = mapMetadata["bounds"][1];
     109        var longitudeLeft = mapMetadata["bounds"][0];
     110        var longitudeRight = mapMetadata["bounds"][2];
     111       
     112        var mapZoomMin = mapMetadata["minzoom"];
     113        var mapZoomMax = mapMetadata["maxzoom"];
    92114       
    93115        var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
    … …  
    99121              new L.LatLng(latitudeTop, longitudeRight));
    100122       
    101         map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
    102        
    103         overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
     123        if(map == null){
     124                // only initialize the map (viewport) once
     125                map = L.map('mapViewport');
     126        }
     127        map.setView([latitudeCenter, longitudeCenter], mapZoomStart);
     128       
     129        if(mapLayerCurrent != null){
     130                map.removeLayer(mapLayerCurrent);
     131                mapLayerCurrent = null;
     132        }
     133        mapLayerCurrent = L.tileLayer(mapMetadata["tiles"][0], {
    104134                minZoom: mapZoomMin, maxZoom: mapZoomMax,
    105135                bounds: mapBounds,
    106                 attribution: 'undefined',opacity: 0.85
     136                attribution: mapMetadata["name"],
     137                opacity: 0.85
    107138                }).addTo(map);
    108139}
    109140
    110 function shutdown(){
     141function getMapInfos()
     142{
     143        $.getJSON("../webservice/tileserver.php?/index.json", mapInfos);
     144}
     145
     146function mapInfos(data)
     147{
     148        mapsMetadata = data;
     149       
     150        $("#mapSelect").empty();
     151        var selected = "selected";
     152        data.forEach(function(value, index){
     153                $("<option value=\""+ index.toString() +"\" "+ selected +">"+ value["name"] +"</option>").appendTo("#mapSelect");
     154                selected = "";
     155        });
     156       
     157        mapSetup();
     158        $("#mapSelect").change(function(){ mapSetup(); });
     159}
     160
     161function shutdown()
     162{
    111163        $.getJSON("../webservice/?request=shutdown", function(data){
    112164                var shutdownTime = data["shutdownstart"];
    … …  
    123175function uploadMap(form)
    124176{
     177        var formData = new FormData($("#mapTileUpload")[0]);
     178//      formData.append("mapFile", $("#mapFileInput")[0].files[0]);
     179       
     180        $("#mapFileInput").hide();
     181        $("#mapTileUploadProgress").show();
    125182        $.ajax({
    126                 type: "POST",
    127                 url: "../webservice/mapupload.php",
    128                 data: $(form).serialize(),
     183                type: 'POST',
     184                url: '../webservice/mapupload.php',
     185                data: formData,
     186                contentType: false,
     187                processData: false,
    129188                success: function(data){
    130189                        if(("error" in data) && data["error"] == 1){
    131190                                alert("Failed to upload map: "+ data["errormessage"]);
     191                                $("#mapTileUploadProgress").hide();
     192                                $("#mapFileInput").show();
    132193                                return;
    133194                        }
    134195                        alert("Map upload successfully");
     196                        $("#mapTileUploadProgress").hide();
     197                        $("#mapFileInput").show();
     198                        getMapInfos();
    135199                },
    136                 error: function(jqXHR, exception, errorThrown){ alert("Failed to upload map: "+ exception); }
     200                error: function(jqXHR, exception, errorThrown){
     201                        alert("Failed to upload map (XHR): "+ exception);
     202                        $("#mapTileUploadProgress").hide();
     203                        $("#mapFileInput").show();
     204                }
     205        }).progress(function(e){
     206                $("#mapTileUploadProgress").attr({value: e.oloaded, max: e.total});
    137207        });
    138208}
    … …  
    140210
    141211$(document).ready(function() {
    142         displayDataGet();
    143         setInterval(displayDataGet, 10000);
    144 
    145         $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
    146        
     212        $("#mapTileUploadProgress").hide();
    147213        $("shutdown").click(shutdown);
    148        
    149         $("#mapTileUpload").validate({
     214
     215                $("#mapTileUpload").validate({
    150216                rules: {
    151217                        mapFile: {
    … …  
    157223                }
    158224        });
     225
     226        getMapInfos();
     227        displayDataGet();
     228        setInterval(displayDataGet, 10000);
    159229});
Note: See TracChangeset for help on using the changeset viewer.