|
30 | 30 | <!-- <script type="text/javascript"
|
31 | 31 | src="https://maps.googleapis.com/maps/api/js?sensor=false®ion=FR">
|
32 | 32 | </script> -->
|
33 |
| - <script src="../lib/jquery.ui/js/jquery.js" type="text/javascript"></script> |
34 | 33 | <script type="text/javascript" src="js/apphome.js"></script>
|
35 | 34 | <script type="text/javascript">
|
36 | 35 |
|
|
72 | 71 |
|
73 | 72 | function translateResult(element, status) {
|
74 | 73 | var url = getAppHome() + "/ws/map/translation/" + "MapRest." + status;
|
75 |
| - $.get(url) |
76 |
| - .done(function(data) { |
77 |
| - element.innerHTML = data.translation; |
78 |
| - }) |
79 |
| - .fail(function (jqXHR, textStatus, errorThrown) { |
80 |
| - console.log(jqXHR); |
81 |
| - console.log(textStatus); |
82 |
| - console.log(errorThrown ); |
83 |
| - element.innerHTML = status; |
84 |
| - }); |
| 74 | + fetch(url) |
| 75 | + .then(function(response) { |
| 76 | + return response.json(); |
| 77 | + }) |
| 78 | + .then(function(data) { |
| 79 | + element.innerHTML = data.translation; |
| 80 | + }); |
85 | 81 | }
|
86 | 82 |
|
87 | 83 | function initialize() {
|
88 |
| - var directionsDisplay; |
89 |
| - var directionsService = new google.maps.DirectionsService(); |
90 |
| - var map; |
91 |
| - var dx = getQueryVariable("dx"); |
92 |
| - var dy = getQueryVariable("dy"); |
93 |
| - var ax = getQueryVariable("ax"); |
94 |
| - var ay = getQueryVariable("ay"); |
95 |
| - |
96 |
| - var rendererOptions = { |
97 |
| - draggable: true |
98 |
| - }; |
99 |
| - |
100 |
| - directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions); |
101 |
| - var start = new google.maps.LatLng(dx, dy); |
102 |
| - var end = new google.maps.LatLng(ax, ay); |
103 |
| - var request = { |
104 |
| - origin:start, |
105 |
| - destination:end, |
106 |
| - travelMode: google.maps.DirectionsTravelMode.DRIVING |
107 |
| - }; |
108 |
| - directionsService.route(request, function(response, status) { |
109 |
| - if (status == google.maps.DirectionsStatus.OK) { |
110 |
| - directionsDisplay.setDirections(response); |
111 |
| - } else { |
112 |
| - translateResult(document.getElementById('directionsPanel') , status); |
113 |
| - } |
114 |
| - }); |
115 |
| - var mapOptions = { |
116 |
| - zoom:7, |
117 |
| - mapTypeId: google.maps.MapTypeId.ROADMAP, |
118 |
| - center: start |
119 |
| - } |
120 |
| - map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); |
121 |
| - directionsDisplay.setMap(map); |
122 |
| - directionsDisplay.setPanel(document.getElementById('directionsPanel')); |
123 |
| - |
124 |
| - google.maps.event.addListener(directionsDisplay, 'directions_changed', function() { |
125 |
| - computeTotalDistance(directionsDisplay.directions); |
126 |
| - }); |
127 |
| - |
| 84 | + var url = getAppHome() + "/ws/map/" + getQueryVariable("object"); |
| 85 | + var id = getQueryVariable("id"); |
| 86 | + if (id) { |
| 87 | + url += "/" + id; |
| 88 | + } |
| 89 | + fetch(url, { |
| 90 | + method: 'GET', |
| 91 | + headers: { |
| 92 | + 'Content-Type': 'application/json' |
| 93 | + } |
| 94 | + }) |
| 95 | + .then(function (response) { |
| 96 | + return response.json(); |
| 97 | + }) |
| 98 | + .then(function (result) { |
| 99 | + if (result.status == 0) { |
| 100 | + var directionsDisplay; |
| 101 | + var directionsService = new google.maps.DirectionsService(); |
| 102 | + var map; |
| 103 | + var locations = []; |
| 104 | + var errors = []; |
| 105 | + for (var i = 0; i < result.data.length; i++) { |
| 106 | + var { latit, longit ,address, errorMsg} = result.data[i]; |
| 107 | + if (errorMsg){ |
| 108 | + errors.push("\u2022 " +errorMsg); |
| 109 | + continue; |
| 110 | + } |
| 111 | + locations.push(new google.maps.LatLng(latit, longit)); |
| 112 | + } |
| 113 | + if (errors.length > 0) { |
| 114 | + alert(errors.join("\n")); |
| 115 | + } |
| 116 | + var waypoints = locations.slice(1, -1).map(function (location) { |
| 117 | + return { |
| 118 | + location: location, |
| 119 | + stopover: true |
| 120 | + }; |
| 121 | + }); |
| 122 | + |
| 123 | + var rendererOptions = { |
| 124 | + draggable: true |
| 125 | + }; |
| 126 | + |
| 127 | + directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions); |
| 128 | + var start = locations[0]; |
| 129 | + var end = locations[locations.length - 1]; |
| 130 | + var request = { |
| 131 | + origin: start, |
| 132 | + destination: end, |
| 133 | + waypoints: waypoints, |
| 134 | + optimizeWaypoints: false, |
| 135 | + travelMode: google.maps.DirectionsTravelMode.DRIVING |
| 136 | + }; |
| 137 | + directionsService.route(request, function(response, status) { |
| 138 | + if (status == google.maps.DirectionsStatus.OK) { |
| 139 | + directionsDisplay.setDirections(response); |
| 140 | + } else { |
| 141 | + translateResult(document.getElementById('directionsPanel'), status); |
| 142 | + } |
| 143 | + }); |
| 144 | + var mapOptions = { |
| 145 | + zoom: 7, |
| 146 | + mapTypeId: google.maps.MapTypeId.ROADMAP, |
| 147 | + center: start |
| 148 | + } |
| 149 | + map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); |
| 150 | + directionsDisplay.setMap(map); |
| 151 | + directionsDisplay.setPanel(document.getElementById('directionsPanel')); |
| 152 | + |
| 153 | + google.maps.event.addListener(directionsDisplay, 'directions_changed', function() { |
| 154 | + computeTotalDistance(directionsDisplay.directions); |
| 155 | + }); |
| 156 | + } |
| 157 | + }) |
| 158 | + .catch(function (error) { |
| 159 | + alert('Request failed: ' + error.message); |
| 160 | + }); |
128 | 161 | }
|
129 | 162 |
|
130 | 163 | window.onload = function() {
|
|
0 commit comments