Ignore:
File:
1 edited

Legend:

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

    rf03591a r4972eea  
    2020*/
    2121
    22 var map = null;
    23 var mapLayerCurrent = null;
    24 // var mapControl = null;
    25 var mapsMetadata = null;
    26 var polyline = null;
     22var map;
     23var polyline;
    2724
    28 function openLink(target)
    29 {
     25function openLink(target){
    3026        window.location=target;
    3127}
    3228
    33 function displayDataSet(data)
    34 {
     29function displayDataSet(data){
    3530        if(!Array.isArray(data) && !(data instanceof Object)){
    3631                console.log("No data array returned!");
    … …  
    6459        }
    6560        else{
    66                 if(map == null){
    67                         console.log("No map in use");
     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"]));
    6865                }
    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"]));
     66                if(points.length > 0){
     67                        if(!polyline){
     68                                polyline = L.polyline(points, {color: 'red'}).addTo(map);
    7469                        }
    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());
     70                        else{
     71                                polyline.setLatLngs(points);
    8372                        }
     73                        map.fitBounds(polyline.getBounds());
    8474                }
    8575        }
    8676}
    8777
    88 function displayDataGet()
    89 {
     78function displayDataGet() {
    9079        var gnuboatApi = "../webservice/";
    9180        $.getJSON( gnuboatApi, displayDataSet);
    9281}
    9382
    94 function 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];
     83function 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];
    10689       
    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"];
     90        var mapZoomMin = data["minzoom"];
     91        var mapZoomMax = data["maxzoom"];
    11492       
    11593        var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom;
    … …  
    12199              new L.LatLng(latitudeTop, longitudeRight));
    122100       
    123         if(map == null){
    124                 // only initialize the map (viewport) once
    125                 map = L.map('mapViewport');
    126         }
    127         map.setView([latitudeCenter, longitudeCenter], mapZoomStart);
     101        map = L.map('map').setView([latitudeCenter, longitudeCenter], mapZoomStart);
    128102       
    129         if(mapLayerCurrent != null){
    130                 map.removeLayer(mapLayerCurrent);
    131                 mapLayerCurrent = null;
    132         }
    133         mapLayerCurrent = L.tileLayer(mapMetadata["tiles"][0], {
     103        overlay = L.tileLayer('../webservice/tileserver.php?/index.json?/map/{z}/{x}/{y}.png', {
    134104                minZoom: mapZoomMin, maxZoom: mapZoomMax,
    135105                bounds: mapBounds,
    136                 attribution: mapMetadata["name"],
    137                 opacity: 0.85
     106                attribution: 'undefined',opacity: 0.85
    138107                }).addTo(map);
    139108}
    140109
    141 function getMapInfos()
    142 {
    143         $.getJSON("../webservice/tileserver.php?/index.json", mapInfos);
    144 }
    145 
    146 function 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 
    161 function shutdown()
    162 {
     110function shutdown(){
    163111        $.getJSON("../webservice/?request=shutdown", function(data){
    164112                var shutdownTime = data["shutdownstart"];
    … …  
    175123function uploadMap(form)
    176124{
    177         var formData = new FormData($("#mapTileUpload")[0]);
    178 //      formData.append("mapFile", $("#mapFileInput")[0].files[0]);
    179        
    180         $("#mapFileInput").hide();
    181         $("#mapTileUploadProgress").show();
    182125        $.ajax({
    183                 type: 'POST',
    184                 url: '../webservice/mapupload.php',
    185                 data: formData,
    186                 contentType: false,
    187                 processData: false,
     126                type: "POST",
     127                url: "../webservice/mapupload.php",
     128                data: $(form).serialize(),
    188129                success: function(data){
    189130                        if(("error" in data) && data["error"] == 1){
    190131                                alert("Failed to upload map: "+ data["errormessage"]);
    191                                 $("#mapTileUploadProgress").hide();
    192                                 $("#mapFileInput").show();
    193132                                return;
    194133                        }
    195134                        alert("Map upload successfully");
    196                         $("#mapTileUploadProgress").hide();
    197                         $("#mapFileInput").show();
    198                         getMapInfos();
    199135                },
    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});
     136                error: function(jqXHR, exception, errorThrown){ alert("Failed to upload map: "+ exception); }
    207137        });
    208138}
    … …  
    210140
    211141$(document).ready(function() {
    212         $("#mapTileUploadProgress").hide();
     142        displayDataGet();
     143        setInterval(displayDataGet, 10000);
     144
     145        $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
     146       
    213147        $("shutdown").click(shutdown);
    214 
    215                 $("#mapTileUpload").validate({
     148       
     149        $("#mapTileUpload").validate({
    216150                rules: {
    217151                        mapFile: {
    … …  
    223157                }
    224158        });
    225 
    226         getMapInfos();
    227         displayDataGet();
    228         setInterval(displayDataGet, 10000);
    229159});
Note: See TracChangeset for help on using the changeset viewer.