Changes in src/webapp/webclient/js/main.js [f03591a:4972eea]
- File:
-
- 1 edited
-
src/webapp/webclient/js/main.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webclient/js/main.js
rf03591a r4972eea 20 20 */ 21 21 22 var map = null; 23 var mapLayerCurrent = null; 24 // var mapControl = null; 25 var mapsMetadata = null; 26 var polyline = null; 22 var map; 23 var polyline; 27 24 28 function openLink(target) 29 { 25 function openLink(target){ 30 26 window.location=target; 31 27 } 32 28 33 function displayDataSet(data) 34 { 29 function displayDataSet(data){ 35 30 if(!Array.isArray(data) && !(data instanceof Object)){ 36 31 console.log("No data array returned!"); … … 64 59 } 65 60 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"])); 68 65 } 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); 74 69 } 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); 83 72 } 73 map.fitBounds(polyline.getBounds()); 84 74 } 85 75 } 86 76 } 87 77 88 function displayDataGet() 89 { 78 function displayDataGet() { 90 79 var gnuboatApi = "../webservice/"; 91 80 $.getJSON( gnuboatApi, displayDataSet); 92 81 } 93 82 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]; 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]; 106 89 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"]; 114 92 115 93 var latitudeCenter = (latitudeTop - latitudeBottom)/2 + latitudeBottom; … … 121 99 new L.LatLng(latitudeTop, longitudeRight)); 122 100 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); 128 102 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', { 134 104 minZoom: mapZoomMin, maxZoom: mapZoomMax, 135 105 bounds: mapBounds, 136 attribution: mapMetadata["name"], 137 opacity: 0.85 106 attribution: 'undefined',opacity: 0.85 138 107 }).addTo(map); 139 108 } 140 109 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 { 110 function shutdown(){ 163 111 $.getJSON("../webservice/?request=shutdown", function(data){ 164 112 var shutdownTime = data["shutdownstart"]; … … 175 123 function uploadMap(form) 176 124 { 177 var formData = new FormData($("#mapTileUpload")[0]);178 // formData.append("mapFile", $("#mapFileInput")[0].files[0]);179 180 $("#mapFileInput").hide();181 $("#mapTileUploadProgress").show();182 125 $.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(), 188 129 success: function(data){ 189 130 if(("error" in data) && data["error"] == 1){ 190 131 alert("Failed to upload map: "+ data["errormessage"]); 191 $("#mapTileUploadProgress").hide();192 $("#mapFileInput").show();193 132 return; 194 133 } 195 134 alert("Map upload successfully"); 196 $("#mapTileUploadProgress").hide();197 $("#mapFileInput").show();198 getMapInfos();199 135 }, 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); } 207 137 }); 208 138 } … … 210 140 211 141 $(document).ready(function() { 212 $("#mapTileUploadProgress").hide(); 142 displayDataGet(); 143 setInterval(displayDataGet, 10000); 144 145 $.getJSON("../webservice/tileserver.php?/map.json", mapSetup); 146 213 147 $("shutdown").click(shutdown); 214 215 $("#mapTileUpload").validate({148 149 $("#mapTileUpload").validate({ 216 150 rules: { 217 151 mapFile: { … … 223 157 } 224 158 }); 225 226 getMapInfos();227 displayDataGet();228 setInterval(displayDataGet, 10000);229 159 });
Note:
See TracChangeset
for help on using the changeset viewer.
