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