diff --git a/index.html b/index.html index d5efb76..51b05a2 100644 --- a/index.html +++ b/index.html @@ -163,8 +163,9 @@


Rien à montre Commencez à tracer votre itinéraire pour voir les données le concernant.
-


Tracé invalide !

- Le tracé est invalide: l'itinéraire n'a pas pu être calculé avec le dernier marqueur. Déplacez le marqueur translucide pour ré-essayer un nouvel itinéraire. +


Oups

+ L'itinéraire n'a pas pu être calculé... Vous pouvez ré-essayer en déplacer le marqueur.
+
diff --git a/js/map2gpx.babel.js b/js/map2gpx.babel.js index fe36135..5c07ccd 100644 --- a/js/map2gpx.babel.js +++ b/js/map2gpx.babel.js @@ -528,6 +528,12 @@ L.polyline_interpolate = function (coords) { $.each(listeners, function () { this.progress('update', progress); }); + }, + + failed: function failed(error) { + $.each(listeners, function () { + this.progress('failed', error); + }); } }; })(jQuery); @@ -639,6 +645,14 @@ L.polyline_interpolate = function (coords) { if (_started) this.start();else this.stop(); }, + failed: function failed(error) { + this.$status.text('Une erreur est survenue'); + $('
' + error + '
').insertAfter(this.$h2).fadeOut(10000, function () { + $(this).remove(); + }); + this._trigger('failed', null, { error: error }); + }, + update: function update(progress) { if (Array.isArray(progress)) { var _this = this; @@ -916,9 +930,11 @@ L.Layer.include({ computeStats: function computeStats() { var _this = this; + var latlngs = _this.getLatLngsFlatten(); + return $.Deferred(function () { var deferred = this; // jscs:ignore safeContextKeyword - var promises = _this._fetchAltitude().concat(_this._fetchSlope()); + var promises = _this._fetchAltitude(latlngs).concat(_this._fetchSlope(latlngs)); var total = promises.length; deferred.notify({ start: true, total: total, status: 'Récupération des données géographiques...' }); @@ -929,17 +945,30 @@ L.Layer.include({ }); }); - $.when.apply($, promises).fail(deferred.reject).then(function () { - _this._computeStats(); + $.when.apply($, promises).fail(deferred.reject).done(function () { + // Sanity checks + $.each(latlngs, function (j, coords) { + if (!$.Cache.hasAltitude(coords)) { + console.log('Could not find altitude for coordinates', coords); + deferred.rejectWith({ error: 'Impossible d\'obtenir les données d\'altitude' }); + } + + if (!$.Cache.hasSlope(coords)) { + console.log('Could not find slope for coordinates', coords); + deferred.rejectWith({ error: 'Impossible d\'obtenir les données de pente' }); + } + }); + + _this._computeStats(latlngs); deferred.resolve(); }); }); }, - _computeStats: function _computeStats() { + _computeStats: function _computeStats(latlngs) { var elevations = []; - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { var values = $.extend({}, { lat: coords.lat, lng: coords.lng }, $.Cache.getInfos(coords)); elevations.push(values); }); @@ -982,11 +1011,11 @@ L.Layer.include({ return true; }, - _fetchAltitude: function _fetchAltitude() { + _fetchAltitude: function _fetchAltitude(latlngs) { var geometry = []; // Batch var promises = []; - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { if (!$.Cache.hasAltitude(coords)) { // Skip already cached values geometry.push({ @@ -1009,12 +1038,12 @@ L.Layer.include({ return promises; }, - _fetchSlope: function _fetchSlope() { + _fetchSlope: function _fetchSlope(latlngs) { var tiles = {}; var promises = []; var map = this._map || this._mapToAdd; - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { if (!$.Cache.hasSlope(coords)) { // Skip already cached values var _coords$toTilePixel = coords.toTilePixel(map.options.crs, 16, 256, map.getPixelOrigin()), @@ -1589,7 +1618,7 @@ L.Layer.include({ $.when.apply($, promises).done(function () { _this.fire('markerschanged'); deferred.resolve(); - }).fail(deferred.fail); + }).fail(deferred.reject); }); }, @@ -1609,7 +1638,7 @@ L.Layer.include({ $.when.apply($, promises).done(function () { _this.fire('markerschanged'); deferred.resolve(); - }).fail(deferred.fail); + }).fail(deferred.reject); }); }, @@ -2086,7 +2115,8 @@ L.Layer.include({ _this.attachRouteFrom(to, geojson, mode); $(_this).startCompute(function (next) { - geojson.computeStats().progress($.Queue.notify).then(deferred.resolve).fail(function () { + geojson.computeStats().progress($.Queue.notify).done(deferred.resolve).fail(function () { + $.Queue.failed('Impossible d\'obtenir les données de la route'); deferred.rejectWith({ error: 'Impossible d\'obtenir les données de la route' }); }).always(function () { return $(_this).endCompute(next); @@ -2108,7 +2138,13 @@ L.Layer.include({ }); }); - geojson.snakeIn(); + try { + geojson.snakeIn(); + } catch (e) { + // With some weird tracks, snakeIn can fail (don't know why) + geojson._snakeEnd(); + } + _this.setOpacity(1); to.setOpacity(1); }); @@ -2726,13 +2762,18 @@ window.onload = function () { $('#data-computing').progress().on('progressstatechanged', function (e, data) { if (data.started) { + $('#data-invalid').fadeOut(); $('#data-computing').fadeIn(); } else { $('#data').data('map2gpx-chart').replot($map.map('getTrack').computeStats()); $('#data-computing').fadeOut(); } + }).on('progressfailed', function (e, data) { + $('#data-invalid-status').text(data.error); + $('#data-invalid').fadeIn(); }); $.Queue.bindTo($('#data-computing')); + $.BlockingQueue.bindTo({ start: function start() { return $('#pending').fadeIn(); diff --git a/js/map2gpx.min.js b/js/map2gpx.min.js index ea931b2..42e30f4 100644 --- a/js/map2gpx.min.js +++ b/js/map2gpx.min.js @@ -1 +1 @@ -"use strict";function fetchAltitude(t){return $.Deferred(function(){var e=this,n={apiKey:keyIgn,sampling:t.length,positions:t,onSuccess:function(t){t?($.each(t.elevations,function(t,e){$.Cache.addAltitude(e.lat,e.lon,e.z)}),e.resolveWith({size:t.elevations.length})):(console.log("Impossible d'obtenir les données d'altitude: résultats invalides"),e.reject())},onFailure:function(t){console.log("Impossible d'obtenir les données d'altitude: ",t.message),e.reject()}};Gp.Services.getAltitude(n)})}function fetchSlope(t,e,n){return $.Deferred(function(){var o=this,i={tilematrix:16,tilerow:e,tilecol:t,lon:"",lat:"",x:"",y:""};$.each(n,function(t,e){t>0&&(i.lon+="|",i.lat+="|",i.x+="|",i.y+="|"),i.lon+=e.lng.toString(),i.lat+=e.lat.toString(),i.x+=e.x.toString(),i.y+=e.y.toString()}),$.getJSON("slope.php",i,function(t){t.results?($.each(t.results,function(t,e){$.Cache.addSlope(e.lat,e.lon,e.slope)}),o.resolveWith({size:t.results.length})):(console.log("Impossible d'obtenir les données de pente: résultats invalides"),o.reject())}).fail(function(t,e,n){console.log("Impossible d'obtenir les données de pente: ",e,n),o.reject()})})}!function(t){var e=function(t){var e;try{var n="__storage_test__";return(e=window[t]).setItem(n,n),e.removeItem(n),!0}catch(t){return t instanceof DOMException&&(22===t.code||1014===t.code||"QuotaExceededError"===t.name||"NS_ERROR_DOM_QUOTA_REACHED"===t.name)&&0!==e.length}}("localStorage");t.localStorage={get:function(t){return e?localStorage.getItem(t):null},getAsJSON:function(t){return e&&null!==localStorage.getItem(t)?JSON.parse(localStorage.getItem(t)):null},set:function(t,n){e&&localStorage.setItem(t,n)},setAsJSON:function(t,e){this.set(t,JSON.stringify(e))}}}(jQuery),jQuery.QueryString=function(t){for(var e={},n=0;n=0&&n0&&void 0!==arguments[0]&&arguments[0])){var a=e.indexOf(this);null!==t.localStorage.get("tutorial"+a)&&(i=parseInt(t.localStorage.get("tutorial"+a)))}return i>=0&&it}}(jQuery),Math.roundE8=function(t){return Math.round(t*Math.pow(10,8))/Math.pow(10,8)},Math.radians=function(t){return t*Math.PI/180},Math.degrees=function(t){return 180*t/Math.PI},L.LatLng.prototype.roundE8=function(){return L.latLng(Math.roundE8(this.lat),Math.roundE8(this.lng))},L.LatLng.prototype.toTilePixel=function(t,e,n,o){var i=t.latLngToPoint(this,e).floor(),a=i.divideBy(n).floor(),r=a.multiplyBy(n).subtract(o);return{tile:a,tilePixel:i.subtract(o).subtract(r)}},L.LatLng.prototype.getDestinationAlong=function(t,e){var n=Math.radians(t),o=Math.radians(this.lat),i=Math.radians(this.lng),a=Math.asin(Math.sin(o)*Math.cos(e/6378137)+Math.cos(o)*Math.sin(e/6378137)*Math.cos(n)),r=i+Math.atan2(Math.sin(n)*Math.sin(e/6378137)*Math.cos(o),Math.cos(e/6378137)-Math.sin(o)*Math.sin(a));return a=Math.degrees(a),r=Math.degrees(r),L.latLng(Math.roundE8(a),Math.roundE8(r))},L.LatLng.prototype.bearingTo=function(t){var e=Math.radians(this.lat),n=Math.radians(this.lng),o=Math.radians(t.lat),i=Math.radians(t.lng),a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),r=i-n;return Math.abs(r)>Math.PI&&(r=r>0?-(2*Math.PI-r):2*Math.PI+r),(Math.degrees(Math.atan2(r,a))+360)%360},L.Handler.include({setEnabled:function(t){t?this.enable():this.disable()}}),L.Control.EasyButton.include({setEnabled:function(t){t?this.enable():this.disable()}}),L.Polyline.include({getLatLngsFlatten:function(){var t=this.getLatLngs();if(t.length>0&&Array.isArray(t[0])){var e=[];return $.each(t,function(t,n){e=e.concat(n)}),e}return t}}),L.polyline_findAuto=function(t,e){return $.Deferred(function(){var n=this,o={distanceUnit:"m",endPoint:{x:e.lng,y:e.lat},exclusions:[],geometryInInstructions:!0,graph:"Pieton",routePreferences:"fastest",startPoint:{x:t.lng,y:t.lat},viaPoints:[],apiKey:keyIgn,onSuccess:function(t){if(t){var e=[];$.each(t.routeInstructions,function(t,n){$.each(n.geometry.coordinates,function(t,n){e.push(L.latLng(n[1],n[0]))})});var o=L.polyline(e);n.resolve(o)}else n.rejectWith({error:"Impossible d'obtenir la route: pas de résultats fournis"})},onFailure:function(t){n.rejectWith({error:"Impossible d'obtenir la route: "+t.message})}};Gp.Services.route(o)})},L.polyline_findStraight=function(t,e){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,o=t.roundE8(),i=e.roundE8(),a=o.distanceTo(i),r=o.bearingTo(i),s=[o],l=n;lr&&(r=u)}for(var h=0;hs&&(s=p)}return Math.max(r,s)}});var _interpolateTrackData=function t(e,n,o,i){if(n.length>500)return $.Deferred(function(){var a=n.slice(0,500),r=n.slice(499);t(e,a,r.concat(o.slice(1)),i+1).done(this.resolve).fail(this.reject)});var a=new L.Polyline(n);if(n.length<=4){var r=L.polyline_findStraight(n[0],n[n.length-1]);return e.notify({line:r,count:n.length-1}),$.Deferred(function(){this.resolve({line:r,mode:"straight",coordsLeft:o,count:n.length})})}return $.Deferred(function(){var r=this;L.polyline_findAuto(n[0],n[n.length-1]).done(function(s){var l=!1,u=n[0].distanceTo(n[n.length-1]),c=Math.max(10,2*u/100);if(a.distanceTo(s)0){var i=Math.min(3*o.count,o.coordsLeft.length),a=o.coordsLeft.slice(0,i+1),r=o.coordsLeft.slice(i);_interpolateTrackData(e,a,r,0).done(t).fail(e.reject)}else e.resolve(n)}).fail(this.reject)})},function(t){var e=0,n=[];t.fn.clearCompute=function(){return this.each(function(){e-=t(this).queue().length,t(this).clearQueue(),t.Queue.stop()})},t.fn.startCompute=function(n){return this.each(function(){t.Queue.start(),e++,t(this).queue(n)})},t.fn.endCompute=function(n){return this.each(function(){e--,n(),t.Queue.stop()})},t.Queue={size:function(){return e},bindTo:function(t){return n.push(t)},start:function(){0==e&&t.each(n,function(){this.progress("start")})},stop:function(){0==e&&t.each(n,function(){this.progress("stop")})},notify:function(e){t.each(n,function(){this.progress("update",e)})}}}(jQuery),function(t){var e=0,n=[];t.fn.clearBlockingCompute=function(){return this.each(function(){e-=t(this).queue().length,t(this).clearQueue(),t.BlockingQueue.stop()})},t.fn.startBlockingCompute=function(n){return this.each(function(){t.BlockingQueue.start(),e++,t(this).queue(n)})},t.fn.endBlockingCompute=function(n){return this.each(function(){e--,n(),t.BlockingQueue.stop()})},t.BlockingQueue={size:function(){return e},bindTo:function(t){return n.push(t)},start:function(){0==e&&t.each(n,function(){this.start()})},stop:function(){0==e&&t.each(n,function(){this.stop()})}}}(jQuery),function(t){t.widget("map2gpx.progress",{options:{progress:0,total:0,started:!1},_create:function(){this.element.append('


- Calculs en cours...

'),this.$h2=this.element.find("h2"),this.$progress=this.element.find(".data-computing-progress"),this.$progressbar=this.element.find(".data-computing-progressbar"),this.$status=this.element.find(".data-computing-status"),this.options.started&&this.start()},_buildEventData:function(){return{started:this.options.started}},start:function(){this.options.started||(this.options.progress=0,this.options.total=0),this.options.started=!0,this.update({start:!0,total:1,status:"Calculs en cours..."}),this._trigger("statechanged",null,this._buildEventData()),this._trigger("started",null,{})},stop:function(){this.options.started=!1,this.update({end:!0,status:"Finalisation..."}),this._trigger("statechanged",null,this._buildEventData()),this._trigger("stopped",null,{})},started:function(t){if(void 0===t)return this.options.started;t?this.start():this.stop()},update:function(e){if(Array.isArray(e)){var n=this;t.each(e,function(){n._update(this)})}else this._update(e);this._display()},_update:function(e){e.start?this.options.total+=e.total:e.end?this.options.progress=this.options.total:e.count?this.options.progress+=e.count:this.options.progress++,"status"in e&&e.status&&this.$status.text(e.status),"step"in e&&e.step&&t("
"+e.step+"
").insertAfter(this.$h2).fadeOut(400,function(){t(this).remove()})},_display:function(){var e=1;this.options.total>0&&(e=this.options.progress/this.options.total),this.$progress.text(Math.floor(100*e)+"%"),this.$progressbar.css("width",Math.floor(100*e)+"%"),42==Math.round(100*e)&&t("
La grande question sur la vie, l'univers et le reste répondue
").insertAfter(this.$h2).fadeOut(400,function(){t(this).remove()})}})}(jQuery),function(t){var e={},n={};t.Cache={};var o=function(t){return i(t.lat,t.lng)},i=function(t,e){return Math.roundE8(e)+"/"+Math.roundE8(t)};t.Cache.addAltitude=function(t,n,o){e[i(t,n)]=o},t.Cache.getAltitude=function(t){var n=o(t);return n in e?e[n]:null},t.Cache.hasAltitude=function(t){return o(t)in e},t.Cache.addSlope=function(t,e,o){n[i(t,e)]=o},t.Cache.getSlope=function(t){var e=o(t);return e in n?n[e]:null},t.Cache.hasSlope=function(t){return o(t)in n},t.Cache.getInfos=function(t){var i=o(t);return{z:i in e?e[i]:null,slope:i in n?n[i]:null}}}(jQuery),L.Map.include({_bindViewEvents:function(){this.on("zoomend",function(){console.log("Zoomed to ",this.getZoom()),$.localStorage.set("view",[this.getCenter().lat,this.getCenter().lng,this.getZoom()])}),this.on("moveend",function(){console.log("Moved to ",this.getCenter()),$.localStorage.setAsJSON("view",[this.getCenter().lat,this.getCenter().lng,this.getZoom()])})},_setView:function(t){this.setView([t[0],t[1]],t[2])},initView:function(){var t=this;return $.Deferred(function(){var e=this,n=$.localStorage.getAsJSON("view")||[44.96777356135154,6.06822967529297,13];if(n[2]>17&&(n[2]=17),"lat"in $.QueryString&&"lng"in $.QueryString&&(n=[$.QueryString.lat,$.QueryString.lng,15]),"loc"in $.QueryString){var o={text:$.QueryString.loc,filterOptions:{type:["StreetAddress","PositionOfInterest"]},apiKey:keyIgn,onSuccess:function(o){o&&"suggestedLocations"in o&&o.suggestedLocations.length>0?(t._setView([o.suggestedLocations[0].position.y,o.suggestedLocations[0].position.x,15]),e.resolveWith(t)):(console.log("No results?"),t._setView(n),e.resolveWith(t))},onFailure:function(o){console.log(o),t._setView(n),e.resolveWith(t)}};Gp.Services.autoComplete(o)}else t._setView(n),e.resolveWith(t)}).done(this._bindViewEvents)}}),L.Layer.include({_elevations:[],_distance:0,_altMin:0,_altMax:0,_denivPos:0,_denivNeg:0,prepareForMap:function(t,e,n){this._mapToAdd=t,this._start=e,this._end=n},getStartMarker:function(){return this._start},getEndMarker:function(){return this._end},getElevations:function(){return JSON.parse(JSON.stringify(this._elevations))},getDistance:function(){return this._distance},getAltMin:function(){return this._altMin},getAltMax:function(){return this._altMax},getDenivPos:function(){return this._denivPos},getDenivNeg:function(){return this._denivNeg},computeStats:function(){var t=this;return $.Deferred(function(){var e=this,n=t._fetchAltitude().concat(t._fetchSlope()),o=n.length;e.notify({start:!0,total:o,status:"Récupération des données géographiques..."}),$.each(n,function(){this.done(function(){e.notify({step:this.size+" points récupérés"})})}),$.when.apply($,n).fail(e.reject).then(function(){t._computeStats(),e.resolve()})})},_computeStats:function(){var t=[];if($.each(this.getLatLngsFlatten(),function(e,n){var o=$.extend({},{lat:n.lat,lng:n.lng},$.Cache.getInfos(n));t.push(o)}),0==t.length)return!1;this._distance=0,this._altMin=t[0].z,this._altMax=t[0].z,this._denivPos=0,this._denivNeg=0,t[0].dist=0,t[0].slopeOnTrack=0,this._elevations=[t[0]];for(var e=0,n=1;n0&&(this._distance+=o/1e3,e++,this._elevations[e]=t[n],this._elevations[e].dist=this._distance,this._elevations[e].slopeOnTrack=Math.degrees(Math.atan((Math.round(this._elevations[e].z)-Math.round(this._elevations[e-1].z))/o)),this._elevations[e].zthis._altMax&&(this._altMax=this._elevations[e].z),this._elevations[e].z0&&e.push(fetchAltitude(t)),e},_fetchSlope:function(){var t={},e=[],n=this._map||this._mapToAdd;return $.each(this.getLatLngsFlatten(),function(e,o){if(!$.Cache.hasSlope(o)){var i=o.toTilePixel(n.options.crs,16,256,n.getPixelOrigin()),a=i.tile,r=i.tilePixel;a.x in t||(t[a.x]={}),a.y in t[a.x]||(t[a.x][a.y]=[[]]),t[a.x][a.y][t[a.x][a.y].length-1].length>50&&t[a.x][a.y].push([]),t[a.x][a.y][t[a.x][a.y].length-1].push({lat:o.lat,lng:o.lng,x:r.x,y:r.y})}}),$.each(t,function(t,n){$.each(n,function(n,o){$.each(o,function(o,i){e.push(fetchSlope(t,n,i))})})}),e},setPopupContentWith:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];this.setPopupContent('
  • Altitude max: '+Math.round(e.altMax)+"m
  • D+: "+Math.round(e.denivPos)+"m
  • Altitude min: "+Math.round(e.altMin)+"m
  • D-: "+Math.round(e.denivNeg)+"m
  • Distance: "+Math.round(100*e.distance)/100+"km
"+(n?'':""))}}),function(t){t.widget("map2gpx.chart",{options:{map:void 0,dataEmpty:"#data-empty",isSmallScreen:!1,showMarker:!0,plotMarkerOptions:{icon:L.AwesomeMarkers.icon({icon:"area-chart",markerColor:"cadetblue",prefix:"fa"}),draggable:!1,clickable:!1,zIndexOffset:1e3},showSlope:!0,showTerrainSlope:!0},_create:function(){var e=this;if(void 0===this.options.map)throw'"map" option cannot be undefined';if(this.$emptyElement=t(this.options.dataEmpty),!this.options.isSmallScreen){this.$chart=t('').appendTo(this.element);var n=[{label:"Altitude",data:[],fill:!1,borderColor:"rgba(12, 98, 173, 0.8)",backgroundColor:"rgba(12, 98, 173, 0.8)",lineTension:0,pointRadius:0,yAxisId:"alt"}],o=[{id:"alt",type:"linear",position:"left",beginAtZero:!1}];this.options.showSlope&&(this.slopeIdx=n.length,n.push({label:"Pente de l'itinéraire",data:[],fill:!0,pointRadius:0,yAxisID:"slope"}),o.push({id:"slope",type:"linear",position:"right"})),this.options.showTerrainSlope&&(this.slopeTerrainIdx=n.length,n.push({label:"Pente du terrain",data:[],fill:!0,pointRadius:0,yAxisID:"slope2",hidden:!0}),o.push({id:"slope2",type:"linear",position:"right",ticks:{min:0,max:45}}));var i={};this.options.showMarker&&(i={mode:"index",intersect:!1,onHover:function(t,n){return e._onHover(t,n)}}),this.chartjs=new Chart(this.$chart,{type:"line",data:{datasets:n},options:{maintainAspectRatio:!1,onClick:function(t,n){return e._onClick(t,n)},hover:i,scales:{xAxes:[{id:"distance",type:"linear",position:"bottom",ticks:{min:0}}],yAxes:o},legend:{position:"left"},tooltips:{mode:"index",intersect:!1,callbacks:{title:function(t,e){return"Distance: "+Math.floor(100*t[0].xLabel)/100+"km"},label:function(t,e){return e.datasets[t.datasetIndex].label+": "+(0==t.datasetIndex?Math.round(100*t.yLabel)/100+"m":Math.round(t.yLabel)+"°")}}},annotation:{annotations:[]}}})}},_onClick:function(t,e){if(e&&e.length>0){var n=e[0]._index,o=this.chartjs.config.data.datasets[0].data[n];o.route&&o.route.openPopup(L.latLng(o.lat,o.lng))}},_onHover:function(t,e){if("mousemove"==t.type)if(e&&e.length>0){var n=e[0]._index,o=this.chartjs.config.data.datasets[0].data[n];null==this.plotMarker?(this.plotMarker=L.marker(L.latLng(o.lat,o.lng),this.options.plotMarkerOptions),this.plotMarker.addTo(this.options.map)):(this.plotMarker.setLatLng(L.latLng(o.lat,o.lng)),this.plotMarker.update())}else this.plotMarker&&(this.options.map.removeLayer(this.plotMarker),this.plotMarker=null);else"mouseout"==t.type&&this.plotMarker&&(this.options.map.removeLayer(this.plotMarker),this.plotMarker=null)},_replotSmallScreen:function(t){t.size>0?this.element.html("
  • Altitude max: "+Math.round(t.total.altMax)+"m; D+: "+Math.round(t.total.denivPos)+"m
  • Altitude min: "+Math.round(t.total.altMin)+"m; D-: "+Math.round(t.total.denivNeg)+"m
  • Distance: "+Math.round(100*t.elevations[t.size-1].dist)/100+"km
"):this.element.empty()},_replotWideScreen:function(t){if(t.size>0){for(var e=[],n=[],o=[],i=0,a=0,r=0;r3&&ri&&(i=s),s=45&&u.addColorStop((i-45)/c,"purple"),i>=40&&u.addColorStop((i-40)/c,"red"),i>=35&&u.addColorStop((i-35)/c,"orange"),i>=30&&u.addColorStop((i-30)/c,"yellow"),u.addColorStop(i/c,"grey"),a<=-30&&u.addColorStop((i+30)/c,"yellow"),a<=-35&&u.addColorStop((i+35)/c,"orange"),a<=-40&&u.addColorStop((i+40)/c,"red"),a<=-45&&u.addColorStop((i+45)/c,"purple"),this.chartjs.config.data.datasets[this.slopeIdx].backgroundColor=u)}if(this.options.showTerrainSlope){this.chartjs.config.data.datasets[this.slopeTerrainIdx].data=o;var h=this.$chart[0].getContext("2d").createLinearGradient(0,0,0,120);h.addColorStop(0,"purple"),h.addColorStop(1-40/45,"red"),h.addColorStop(1-35/45,"orange"),h.addColorStop(1-30/45,"yellow"),h.addColorStop(1,"grey"),this.chartjs.config.data.datasets[this.slopeTerrainIdx].backgroundColor=h}this.chartjs.options.annotation={},this.chartjs.update(),this.chartjs.options.annotation={annotations:t.annotations},this.chartjs.update()}else{this.chartjs.options.scales.xAxes[0].ticks.max=1;for(var p=0;p0?this.$emptyElement.slideUp():this.$emptyElement.slideDown()}})}(jQuery),function(t){function e(e,o,i,a){var r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"auto";return t.Deferred(function(){var s=this;"straight"==r?n(e,o,i,a).progress(s.notify).done(s.resolve).fail(s.reject):function(t,e,n,o){return L.polyline_findAuto(e.getLatLng(),n.getLatLng())}(0,o,i).progress(s.notify).done(s.resolve).fail(function(){console.log(this.error),console.log("Trying straight line...");var r=new Drop({target:t(".awesome-marker").eq(a+1)[0],classes:"drop-theme-arrows",position:"right middle",constrainToWindow:!1,constrainToScrollParent:!1,openOn:null,content:"Impossible d'obtenir le tracé en mode automatique. Le mode ligne droite va être utilisé."});r.open(),t(r.content).on("click",function(){r.destroy()}),n(e,o,i,a).progress(s.notify).done(s.resolve).fail(s.reject)})})}function n(e,n,o,i){var a=L.polyline_findStraight(n.getLatLng(),o.getLatLng());return t.Deferred(function(){this.resolve(a)})}var o={red:"#D63E2A",orange:"#F59630",green:"#72B026",blue:"#38AADD",purple:"#D252B9",darkred:"#A23336",darkblue:"#0067A3",darkgreen:"#728224",darkpurple:"#5B396B",cadetblue:"#436978",lightred:"#FF8E7F",beige:"#FFCB92",lightgreen:"#BBF970",lightblue:"#8ADAFF",pink:"#FF91EA",white:"#FBFBFB",lightgray:"#A3A3A3",gray:"#575757",black:"#303030"},i=["blue","green","orange","purple","red","darkblue","darkpurple","lightblue","lightgreen","beige","pink","lightred"];L.Track=L.Evented.extend({options:{map:void 0},initialize:function(t){L.setOptions(this,t),this.Lmap=this.options.map.map("getMap"),this.$map=this.options.map,this.currentColor=0,this.markersLength=0},getCurrentColor:function(){return this.currentColor},nextColor:function(){return this.currentColor=(this.currentColor+1)%i.length,this.currentColor},lengthOfMarkers:function(){return this.markersLength},hasMarkers:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.markersLength>=t},hasRoutes:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.markersLength-1>=t},isImport:function(){return this.hasRoutes()&&"import"==this.getFirstMarker().getRouteModeFromHere()},getBounds:function(){var t=L.latLngBounds(this.getFirstMarker(0).getLatLng(),this.getLastMarker().getLatLng());return this.eachRoute(function(e,n){t.extend(n.getBounds())}),t},getFirstMarker:function(){return this.firstMarker},getLastMarker:function(){return this.lastMarker},isLoop:function(){return!!this.firstMarker&&!!this.lastMarker&&this.firstMarker.getLatLng().distanceTo(this.lastMarker.getLatLng())<10},clear:function(){this.eachMarker(function(t,e){e.remove(!1)}),this.fire("markerschanged")},eachMarker:function(t){for(var e=this.firstMarker,n=0;e;){var o=e._nextMarker;t.call(e,n,e),e=o,n++}},eachRoute:function(t){for(var e=this.firstMarker,n=0;e;){var o=e.getRouteFromHere();o&&(t.call(o,n,o),n++),e=e._nextMarker}},addMarker:function(e){var n,o=this,i=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return void 0===this.firstMarker&&(this.firstMarker=e),void 0!==this.lastMarker&&i&&(n=this.lastMarker.computeRouteTo(e,this.$map.map("getMode"))),this.lastMarker=e,this.markersLength++,e.track=this,e.addTo(this.Lmap),n||(n=t.Deferred(function(){this.resolve()})),n.done(function(){return o.fire("markerschanged")})},moveMarker:function(e){var n=this;return t.Deferred(function(){var o=this,i=[];if(e.hasRouteFromHere()){i.length;i.push(e.recomputeRouteFromHere(n.$map.map("getMode")))}if(e.hasRouteToHere()){i.length;i.push(e.recomputeRouteToHere(n.$map.map("getMode")))}t.when.apply(t,i).done(function(){n.fire("markerschanged"),o.resolve()}).fail(o.fail)})},insertMarker:function(e,n){var o=this;return t.Deferred(function(){var i=this,a=[];a.push(n.getStartMarker().computeRouteTo(e,o.$map.map("getMode"))),a.push(e.computeRouteTo(n.getEndMarker(),o.$map.map("getMode"))),o.markersLength++,e.addTo(o.Lmap),t.when.apply(t,a).done(function(){o.fire("markerschanged"),i.resolve()}).fail(i.fail)})},_initStats:function(){return{distance:0,altMin:Number.MAX_VALUE,altMax:Number.MIN_VALUE,denivPos:0,denivNeg:0}},computeStats:function(){var t=this,e=[],n=[],o=this._initStats(),i=this._initStats();if(this.eachMarker(function(a,r){if("step"==r.getType()){e.push(o.distance);for(var s=r;s&&s.hasRouteToHere()&&(s.getRouteToHere().setPopupContentWith(s._previousMarker.getColorCode(),i,"import"!=s._previousMarker.getRouteModeFromHere()),"step"!=(s=s._previousMarker).getType()););i=t._initStats()}var l=r.getRouteFromHere(),u=l?l.getElevations():[];if(u.length>0){for(var c=0;c0)for(var a=this.getLastMarker();a&&a.hasRouteToHere()&&(a.getRouteToHere().setPopupContentWith(a._previousMarker.getColorCode(),i,"import"!=a._previousMarker.getRouteModeFromHere()),"step"!=(a=a._previousMarker).getType()););return{size:n.length,elevations:n,total:o,steps:e}},exportGpx:function(e){var n=!1;try{n=!!new Blob}catch(t){}if(!n)return!1;var o='\n';o+='\n",o+=" \n",this.eachMarker(function(n,i){i.hasRouteFromHere()&&("step"==i.getType()&&(o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n"),t.each(i.getRouteFromHere().getLatLngsFlatten(),function(e,n){o+=' ',t.Cache.hasAltitude(n)&&(o+=""+t.Cache.getAltitude(n)+""),o+="\n"}))}),o+=" \n",o+=" \n",o+="\n";var i=new Blob([o],{type:"application/gpx+xml;charset=utf-8"});return saveAs(i,e+".gpx"),!0},exportKml:function(e){var n=!1;try{n=!!new Blob}catch(t){}if(!n)return!1;var o='\n';o+='\n",o+=" \n",o+=" "+e+"\n",o+=" \n",o+=" 1\n",o+=" \n",o+=" ",this.eachMarker(function(n,i){i.hasRouteFromHere()&&("step"==i.getType()&&(o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n",o+=" 1\n",o+=" \n",o+=" "),t.each(i.getRouteFromHere().getLatLngsFlatten(),function(t,e){o+=e.lng+","+e.lat+",0 "}))}),o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+="\n";var i=new Blob([o],{type:"text/plain;charset=utf-8"});return saveAs(i,e+".kml"),!0},importGpx:function(e,n){var o=this;return t.Deferred(function(){var i=this,a=new FileReader;t(o).startBlockingCompute(function(r){a.onload=function(e){var a=[];new L.GPX(e.target.result,{async:!0,onFail:function(){t(o).endBlockingCompute(r),i.rejectWith({error:"Impossible de traiter ce fichier"})},onSuccess:function(e){i.notify({step:"Fichier traité"}),i.notify({start:!0,total:a.length,status:n?"Interpolation en cours...":"Traitement en cours..."}),o.clear();var s=e.getBounds();o.Lmap.fitBounds(s,{padding:[50,50]});var l=[],u=[];t.each(a,function(e,a){if(n){var r=a.getLatLngsFlatten();i.notify({start:!0,total:r.length}),a.prepareForMap(o.Lmap,null,null),a.setStyle({weight:5,color:"#81197f",opacity:.2,snakingPause:0,snakingSpeed:1e3}),a.addTo(o.Lmap),l.push(L.polyline_interpolate(r).progress(function(t){i.notify({count:t.count,step:t.count+" points trouvés"}),t.line.prepareForMap(o.Lmap,null,null),t.line.setStyle({weight:5,color:"#81197f",opacity:.5,snakingPause:0,snakingSpeed:1e3}),t.line.addTo(o.Lmap),u.push(t.line.computeStats().progress(i.notify))}).done(function(){return a.remove()}))}else a.prepareForMap(o.Lmap,null,null),a.setStyle({weight:5,color:"#81197f",opacity:.5,snakingPause:0,snakingSpeed:1e3}),a.addTo(o.Lmap),l.push(t.Deferred(function(){this.resolve([{line:a,mode:"import"}])})),u.push(a.computeStats().progress(i.notify))}),t.when.apply(t,l).done(function(){for(var e,a=arguments,s=function(i){var r=a[i],s=r.length;t.each(r,function(i,a){var r=a.line.getLatLngsFlatten();if(void 0===e){var l=r[0];e=L.Marker.routed(l,{riseOnHover:!0,draggable:n,opacity:1,color:o.getCurrentColor(),type:"waypoint"}),n?e.add(o,!1):o.addMarker(e,!1)}var u=r[r.length-1],c=L.Marker.routed(u,{riseOnHover:!0,draggable:n,opacity:1,color:i==s-1?o.nextColor():o.getCurrentColor(),type:i==s-1?"step":"waypoint"});if(n?c.add(o,!1):o.addMarker(c,!1),a.line.prepareForMap(o.Lmap,e,c),a.line.setStyle({weight:5,color:e.getColorRgb(),opacity:.75}),a.line.bindPopup("Calculs en cours..."),n){var h=e;a.line.on("popupopen",function(e){t(".marker-add-button:visible").click(function(){L.Marker.routed(e.popup.getLatLng().roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:h.getColorIndex(),type:"waypoint"}).insert(a.line)})})}e.attachRouteFrom(c,a.line,a.mode),e=c})},l=0;l Marquer comme étape '),this.on("popupopen",function(){t(".marker-delete-button:visible").click(function(){e.remove()}),t(".marker-promote-button:visible").click(function(){e.closePopup(),e.setPopupContent(''),e.promoteToStep()})}),this.on("moveend",function(t){e.track.moveMarker(e)})},add:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.track=t,this._bindEvents(),this.track.addMarker(this,e)},insert:function(e){return this.track=t("#map").map("getTrack"),this._bindEvents(),this.track.insertMarker(this,e)},remove:function(){var e,n=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];"step"==this.options.type&&n&&this.demoteToWaypoint();var o=this._previousMarker,i=this._nextMarker;if(this.track._removeMarker(this),this.routeFrom&&this.deleteRouteFromHere(),o&&(o.deleteRouteFromHere(),i))if(o.getLatLng().equals(i.getLatLng()))o.attachRouteFrom(i,null,void 0),e="step"==o.options.type?i.remove(n):o.remove(n);else if(n){var a=this.track.$map.map("getMode")||this._mode||"auto";e=o.computeRouteTo(i,a)}return e||(e=t.Deferred(function(){this.resolve()})),L.Marker.prototype.remove.call(this),this.track.fire("markerschanged"),e}}),L.Marker.routed=function(t,e){return new L.Marker.Routed(t,e)}}(jQuery),function(t){t.widget("map2gpx.map",{options:{leafletOptions:{},controls:{searchEngine:{show:!0,leafletOptions:{displayAdvancedSearch:!1}},minimap:{show:!0,leafletOptions:{position:"bottomleft",zoomLevelOffset:-4}},layerSwitcher:{show:!0,showAll:!0,leafletOptions:{collapsed:!1}},scale:{show:!0,leafletOptions:{imperial:!1,position:"bottomright"}},help:{show:!0}}},getMap:function(){return this.map},getTrack:function(){return this.track},getMode:function(){return this.mode},_buildEventData:function(){return{mode:this.mode}},_setMode:function(t){this.mode=t,this._trigger("modechanged",null,this._buildEventData())},_onCreated:function(){var e=this;this.element.on("mapmodechanged",function(t){e.map.doubleClickZoom.setEnabled(null===e.mode)}),this.map.on("dblclick",function(t){return e._addMarker.call(e,t)}),this._initializeLayers(),this.options.controls.searchEngine.show&&this._initializeSearchEngine(),this.options.controls.minimap.show&&this._initializeMinimap(),this.options.controls.layerSwitcher.show&&this._initializeLayerSwitcher(),this.options.controls.scale.show&&this._initializeScale(),this._initializeTraceButtons(),this._initializeExportButtons(),this._initializeImportButtons(),this.options.controls.help.show&&this._initializeHelpButtons(),this._trigger("created",null,{}),this._trigger("statechanged",null,this._buildEventData()),t.when.apply(t,this.layers.promises).done(function(){e._trigger("loaded",null,{})})},_initializeLayers:function(){var e=this,n=this;this.layers.photos=L.geoportalLayer.WMTS({layer:"ORTHOIMAGERY.ORTHOPHOTOS",apiKey:keyIgn}).addTo(this.map),this.options.controls.layerSwitcher.showAll&&this.layers.promises.push(t.Deferred(function(){n.layers.photos.once("load",this.resolve)})),this.layers.slopes=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.SLOPES.MOUNTAIN",apiKey:keyIgn},{opacity:.25}).addTo(this.map),this.layers.maps=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.MAPS",apiKey:keyIgn},{opacity:this.options.controls.layerSwitcher.showAll?.25:1}).addTo(this.map),this.layers.promises.push(t.Deferred(function(){n.layers.maps.once("load",this.resolve)}));var o=void 0;this.map.on("zoomend",function(){var n=e.map.getZoom(),i=void 0,a=void 0;e.map.hasLayer(e.layers.photos)&&(e.layers.photos.options.minZoom>n||e.layers.photos.options.maxZoomn||e.layers.maps.options.maxZoomn||e.layers.slopes.options.maxZoomAttention: l'import va effacer l'itinéraire existant!"):t("#import-gpx-status").text("")}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Importer (calcul en cours...)"}]});t("#import-gpx-button").click(function(){var e=t(this),i=t("#import-gpx-file")[0].files[0],a=t("#import-gpx-interpolate").is(":checked");void 0!=i?(e.attr("disabled","disabled"),t("body").startCompute(function(r){t.Queue.notify({start:!0,total:1,status:"Importation en cours..."}),n.track.importGpx(i,a).done(function(){e.removeAttr("disabled"),n._setMode(null)}).fail(function(){t("#import-gpx-status").text(this.error),e.removeAttr("disabled")}).progress(function(e){t.Queue.notify(e),o.isOpen()&&n.map.closePopup()}).always(function(){return t("body").endCompute(r)})})):t("#import-gpx-status").text("Veuillez sélectionner un fichier")});var a=L.easyButton({id:"btn-reset",states:[{stateName:"loaded",icon:"fa-trash",title:"Effacer l'itinéraire",onClick:function(t,n){e.track.clear()}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Effacer l'itinéraire (calcul en cours...)"}]});L.easyBar([i,a]).addTo(this.map),this.element.on("mapcomputingchanged mapstatechanged",function(t){i.state(e.computing?"computing":"loaded"),a.state(e.computing?"computing":"loaded"),i.setEnabled(!e.computing),a.setEnabled(!e.computing&&e.track.hasMarkers())})},_initializeHelpButtons:function(){var e=this,n=window.innerWidth-t(".leaflet-control-minimap").width()-t(".leaflet-top.leaflet-right .GPpanel").width(),o=L.popup({maxWidth:n}).setContent(L.DomUtil.get("about")),i=L.easyButton({position:"bottomright",states:[{icon:"fa-info-circle",onClick:function(t,n){o.setLatLng(e.map.getCenter()).openOn(e.map)},title:"A propos & crédits"}]}),a=L.easyButton({position:"bottomright",states:[{icon:"fa-question-circle",onClick:function(e,n){t.Shepherd.get(0).start(!0)},title:"Aide"}]});L.easyBar([i,a],{position:"bottomright"}).addTo(this.map)},_create:function(){var t=this;this.element.uniqueId(),this.layers={},this.layers.promises=[],this.mode=null,this.map=L.map(this.element.attr("id"),this.options.leafletOptions),this.track=L.track({map:this.element}),this.track.on("markerschanged",function(){return t._trigger("statechanged",null,t._buildEventData())}),this.map.initView().done(function(){return t._onCreated()})},_addMarker:function(t){if(null!==this.mode){var e=L.Marker.routed(t.latlng.roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:this.track.hasMarkers()?this.track.getLastMarker().getColorIndex():this.track.getCurrentColor(),type:"waypoint"});this.track.hasMarkers()&&this.track.getLastMarker().getLatLng().equals(e.getLatLng())||e.add(this.track)}}})}(jQuery);var isSmallScreen=window.innerWidth<=800&&window.innerHeight<=600;showLoadingMessage("Observation des faucons crécerelle..."),isSmallScreen&&$("#mobile-warning").show().find("button").click(function(){$("#mobile-warning").hide()}),window.onload=function(){try{showLoadingMessage("Localisation des chamois..."),$("#data-computing").progress().on("progressstatechanged",function(e,n){n.started?$("#data-computing").fadeIn():($("#data").data("map2gpx-chart").replot(t.map("getTrack").computeStats()),$("#data-computing").fadeOut())}),$.Queue.bindTo($("#data-computing")),$.BlockingQueue.bindTo({start:function(){return $("#pending").fadeIn()},stop:function(){return $("#pending").fadeOut()}});var t=$("#map").map({controls:{minimap:{show:!isSmallScreen},layerSwitcher:{showAll:!isSmallScreen,leafletOptions:{collapsed:isSmallScreen}},scale:{show:!isSmallScreen},help:{show:!isSmallScreen}},created:function(){showLoadingMessage("Suivi des renards roux..."),isSmallScreen||$.Shepherd.tour().add("welcome",{text:$("#help-welcome")[0]}).add("layers",{text:$("#help-layers")[0],attachTo:{element:$(".GPlayerName").closest(".GPwidget")[0],on:"left"}}).add("search",{text:$("#help-search")[0],attachTo:{element:$(".GPshowAdvancedToolOpen").closest(".GPwidget")[0],on:"right"}}).add("autotrace",{text:$("#help-autotrace")[0],attachTo:{element:$("#btn-autotrace")[0],on:"right"}}).add("straighttrace",{text:$("#help-straighttrace")[0],attachTo:{element:$("#btn-straighttrace")[0],on:"right"}}).start()},loaded:function(){showLoadingMessage("Alignement des satellites..."),clearInterval(interval),$("#loading").fadeOut()}}).on("mapmarkerschanged",function(e){isSmallScreen||(t.map("getTrack").hasMarkers(2)&&!$.Shepherd.has(1)&&$.Shepherd.tour().add("data",{text:$("#help-data")[0],attachTo:{element:$("#data")[0],on:"top"}}).add("closeloop",{text:$("#help-closeloop")[0],attachTo:{element:$("#btn-closeloop")[0],on:"right"}}).add("export",{text:$("#help-export")[0],attachTo:{element:$("#btn-export")[0],on:"right"}}).start(),t.map("getTrack").hasMarkers(3)&&!$.Shepherd.has(2)&&$.Shepherd.tour().add("movemarker",{text:$("#help-movemarker")[0],attachTo:{element:$(".awesome-marker").last()[0],on:"bottom"}}).add("movemarker2",{text:$("#help-movemarker2")[0],attachTo:{element:$(".awesome-marker").eq(-2)[0],on:"bottom"}}).add("steps",{text:$("#help-steps")[0],attachTo:{element:$(".awesome-marker").last()[0],on:"bottom"}}).add("steps2",{beforeShowPromise:function(){return $.Deferred(function(){var e=t.map("getTrack").getFirstMarker().getRouteFromHere(),n=e.getLatLngsFlatten(),o=n[Math.floor(n.length/2)];e.openPopup(o),this.resolve()}).promise()},text:$("#help-steps2")[0]}).start())}).on("mapstatechanged",function(e){$("#data").data("map2gpx-chart").replot(t.map("getTrack").computeStats())});$("#data").chart({map:t.map("getMap"),dataEmpty:"#data-empty",isSmallScreen:isSmallScreen})}catch(t){gotError=!0,console.log("Got exception",t),$("#loading").animate({backgroundColor:"#A23336",color:"#FFFFFF"}),$("#loading h2 i.fa").removeClass("fa-spinner fa-pulse").addClass("fa-bug"),$("#loading h2 span").html("Une erreur s'est produite: ""+t+""."),$("#loading h3").html($('
N\'hésitez pas à ouvrir un ticket sur Github ou à m\'envoyer un mail à hi@tmuguet.me.
').hide().slideDown()),clearInterval(interval)}}; \ No newline at end of file +"use strict";function fetchAltitude(t){return $.Deferred(function(){var e=this,n={apiKey:keyIgn,sampling:t.length,positions:t,onSuccess:function(t){t?($.each(t.elevations,function(t,e){$.Cache.addAltitude(e.lat,e.lon,e.z)}),e.resolveWith({size:t.elevations.length})):(console.log("Impossible d'obtenir les données d'altitude: résultats invalides"),e.reject())},onFailure:function(t){console.log("Impossible d'obtenir les données d'altitude: ",t.message),e.reject()}};Gp.Services.getAltitude(n)})}function fetchSlope(t,e,n){return $.Deferred(function(){var o=this,i={tilematrix:16,tilerow:e,tilecol:t,lon:"",lat:"",x:"",y:""};$.each(n,function(t,e){t>0&&(i.lon+="|",i.lat+="|",i.x+="|",i.y+="|"),i.lon+=e.lng.toString(),i.lat+=e.lat.toString(),i.x+=e.x.toString(),i.y+=e.y.toString()}),$.getJSON("slope.php",i,function(t){t.results?($.each(t.results,function(t,e){$.Cache.addSlope(e.lat,e.lon,e.slope)}),o.resolveWith({size:t.results.length})):(console.log("Impossible d'obtenir les données de pente: résultats invalides"),o.reject())}).fail(function(t,e,n){console.log("Impossible d'obtenir les données de pente: ",e,n),o.reject()})})}!function(t){var e=function(t){var e;try{var n="__storage_test__";return(e=window[t]).setItem(n,n),e.removeItem(n),!0}catch(t){return t instanceof DOMException&&(22===t.code||1014===t.code||"QuotaExceededError"===t.name||"NS_ERROR_DOM_QUOTA_REACHED"===t.name)&&0!==e.length}}("localStorage");t.localStorage={get:function(t){return e?localStorage.getItem(t):null},getAsJSON:function(t){return e&&null!==localStorage.getItem(t)?JSON.parse(localStorage.getItem(t)):null},set:function(t,n){e&&localStorage.setItem(t,n)},setAsJSON:function(t,e){this.set(t,JSON.stringify(e))}}}(jQuery),jQuery.QueryString=function(t){for(var e={},n=0;n=0&&n0&&void 0!==arguments[0]&&arguments[0])){var a=e.indexOf(this);null!==t.localStorage.get("tutorial"+a)&&(i=parseInt(t.localStorage.get("tutorial"+a)))}return i>=0&&it}}(jQuery),Math.roundE8=function(t){return Math.round(t*Math.pow(10,8))/Math.pow(10,8)},Math.radians=function(t){return t*Math.PI/180},Math.degrees=function(t){return 180*t/Math.PI},L.LatLng.prototype.roundE8=function(){return L.latLng(Math.roundE8(this.lat),Math.roundE8(this.lng))},L.LatLng.prototype.toTilePixel=function(t,e,n,o){var i=t.latLngToPoint(this,e).floor(),a=i.divideBy(n).floor(),r=a.multiplyBy(n).subtract(o);return{tile:a,tilePixel:i.subtract(o).subtract(r)}},L.LatLng.prototype.getDestinationAlong=function(t,e){var n=Math.radians(t),o=Math.radians(this.lat),i=Math.radians(this.lng),a=Math.asin(Math.sin(o)*Math.cos(e/6378137)+Math.cos(o)*Math.sin(e/6378137)*Math.cos(n)),r=i+Math.atan2(Math.sin(n)*Math.sin(e/6378137)*Math.cos(o),Math.cos(e/6378137)-Math.sin(o)*Math.sin(a));return a=Math.degrees(a),r=Math.degrees(r),L.latLng(Math.roundE8(a),Math.roundE8(r))},L.LatLng.prototype.bearingTo=function(t){var e=Math.radians(this.lat),n=Math.radians(this.lng),o=Math.radians(t.lat),i=Math.radians(t.lng),a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),r=i-n;return Math.abs(r)>Math.PI&&(r=r>0?-(2*Math.PI-r):2*Math.PI+r),(Math.degrees(Math.atan2(r,a))+360)%360},L.Handler.include({setEnabled:function(t){t?this.enable():this.disable()}}),L.Control.EasyButton.include({setEnabled:function(t){t?this.enable():this.disable()}}),L.Polyline.include({getLatLngsFlatten:function(){var t=this.getLatLngs();if(t.length>0&&Array.isArray(t[0])){var e=[];return $.each(t,function(t,n){e=e.concat(n)}),e}return t}}),L.polyline_findAuto=function(t,e){return $.Deferred(function(){var n=this,o={distanceUnit:"m",endPoint:{x:e.lng,y:e.lat},exclusions:[],geometryInInstructions:!0,graph:"Pieton",routePreferences:"fastest",startPoint:{x:t.lng,y:t.lat},viaPoints:[],apiKey:keyIgn,onSuccess:function(t){if(t){var e=[];$.each(t.routeInstructions,function(t,n){$.each(n.geometry.coordinates,function(t,n){e.push(L.latLng(n[1],n[0]))})});var o=L.polyline(e);n.resolve(o)}else n.rejectWith({error:"Impossible d'obtenir la route: pas de résultats fournis"})},onFailure:function(t){n.rejectWith({error:"Impossible d'obtenir la route: "+t.message})}};Gp.Services.route(o)})},L.polyline_findStraight=function(t,e){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,o=t.roundE8(),i=e.roundE8(),a=o.distanceTo(i),r=o.bearingTo(i),s=[o],l=n;lr&&(r=u)}for(var h=0;hs&&(s=p)}return Math.max(r,s)}});var _interpolateTrackData=function t(e,n,o,i){if(n.length>500)return $.Deferred(function(){var a=n.slice(0,500),r=n.slice(499);t(e,a,r.concat(o.slice(1)),i+1).done(this.resolve).fail(this.reject)});var a=new L.Polyline(n);if(n.length<=4){var r=L.polyline_findStraight(n[0],n[n.length-1]);return e.notify({line:r,count:n.length-1}),$.Deferred(function(){this.resolve({line:r,mode:"straight",coordsLeft:o,count:n.length})})}return $.Deferred(function(){var r=this;L.polyline_findAuto(n[0],n[n.length-1]).done(function(s){var l=!1,u=n[0].distanceTo(n[n.length-1]),c=Math.max(10,2*u/100);if(a.distanceTo(s)0){var i=Math.min(3*o.count,o.coordsLeft.length),a=o.coordsLeft.slice(0,i+1),r=o.coordsLeft.slice(i);_interpolateTrackData(e,a,r,0).done(t).fail(e.reject)}else e.resolve(n)}).fail(this.reject)})},function(t){var e=0,n=[];t.fn.clearCompute=function(){return this.each(function(){e-=t(this).queue().length,t(this).clearQueue(),t.Queue.stop()})},t.fn.startCompute=function(n){return this.each(function(){t.Queue.start(),e++,t(this).queue(n)})},t.fn.endCompute=function(n){return this.each(function(){e--,n(),t.Queue.stop()})},t.Queue={size:function(){return e},bindTo:function(t){return n.push(t)},start:function(){0==e&&t.each(n,function(){this.progress("start")})},stop:function(){0==e&&t.each(n,function(){this.progress("stop")})},notify:function(e){t.each(n,function(){this.progress("update",e)})},failed:function(e){t.each(n,function(){this.progress("failed",e)})}}}(jQuery),function(t){var e=0,n=[];t.fn.clearBlockingCompute=function(){return this.each(function(){e-=t(this).queue().length,t(this).clearQueue(),t.BlockingQueue.stop()})},t.fn.startBlockingCompute=function(n){return this.each(function(){t.BlockingQueue.start(),e++,t(this).queue(n)})},t.fn.endBlockingCompute=function(n){return this.each(function(){e--,n(),t.BlockingQueue.stop()})},t.BlockingQueue={size:function(){return e},bindTo:function(t){return n.push(t)},start:function(){0==e&&t.each(n,function(){this.start()})},stop:function(){0==e&&t.each(n,function(){this.stop()})}}}(jQuery),function(t){t.widget("map2gpx.progress",{options:{progress:0,total:0,started:!1},_create:function(){this.element.append('


- Calculs en cours...

'),this.$h2=this.element.find("h2"),this.$progress=this.element.find(".data-computing-progress"),this.$progressbar=this.element.find(".data-computing-progressbar"),this.$status=this.element.find(".data-computing-status"),this.options.started&&this.start()},_buildEventData:function(){return{started:this.options.started}},start:function(){this.options.started||(this.options.progress=0,this.options.total=0),this.options.started=!0,this.update({start:!0,total:1,status:"Calculs en cours..."}),this._trigger("statechanged",null,this._buildEventData()),this._trigger("started",null,{})},stop:function(){this.options.started=!1,this.update({end:!0,status:"Finalisation..."}),this._trigger("statechanged",null,this._buildEventData()),this._trigger("stopped",null,{})},started:function(t){if(void 0===t)return this.options.started;t?this.start():this.stop()},failed:function(e){this.$status.text("Une erreur est survenue"),t("
"+e+"
").insertAfter(this.$h2).fadeOut(1e4,function(){t(this).remove()}),this._trigger("failed",null,{error:e})},update:function(e){if(Array.isArray(e)){var n=this;t.each(e,function(){n._update(this)})}else this._update(e);this._display()},_update:function(e){e.start?this.options.total+=e.total:e.end?this.options.progress=this.options.total:e.count?this.options.progress+=e.count:this.options.progress++,"status"in e&&e.status&&this.$status.text(e.status),"step"in e&&e.step&&t("
"+e.step+"
").insertAfter(this.$h2).fadeOut(400,function(){t(this).remove()})},_display:function(){var e=1;this.options.total>0&&(e=this.options.progress/this.options.total),this.$progress.text(Math.floor(100*e)+"%"),this.$progressbar.css("width",Math.floor(100*e)+"%"),42==Math.round(100*e)&&t("
La grande question sur la vie, l'univers et le reste répondue
").insertAfter(this.$h2).fadeOut(400,function(){t(this).remove()})}})}(jQuery),function(t){var e={},n={};t.Cache={};var o=function(t){return i(t.lat,t.lng)},i=function(t,e){return Math.roundE8(e)+"/"+Math.roundE8(t)};t.Cache.addAltitude=function(t,n,o){e[i(t,n)]=o},t.Cache.getAltitude=function(t){var n=o(t);return n in e?e[n]:null},t.Cache.hasAltitude=function(t){return o(t)in e},t.Cache.addSlope=function(t,e,o){n[i(t,e)]=o},t.Cache.getSlope=function(t){var e=o(t);return e in n?n[e]:null},t.Cache.hasSlope=function(t){return o(t)in n},t.Cache.getInfos=function(t){var i=o(t);return{z:i in e?e[i]:null,slope:i in n?n[i]:null}}}(jQuery),L.Map.include({_bindViewEvents:function(){this.on("zoomend",function(){console.log("Zoomed to ",this.getZoom()),$.localStorage.set("view",[this.getCenter().lat,this.getCenter().lng,this.getZoom()])}),this.on("moveend",function(){console.log("Moved to ",this.getCenter()),$.localStorage.setAsJSON("view",[this.getCenter().lat,this.getCenter().lng,this.getZoom()])})},_setView:function(t){this.setView([t[0],t[1]],t[2])},initView:function(){var t=this;return $.Deferred(function(){var e=this,n=$.localStorage.getAsJSON("view")||[44.96777356135154,6.06822967529297,13];if(n[2]>17&&(n[2]=17),"lat"in $.QueryString&&"lng"in $.QueryString&&(n=[$.QueryString.lat,$.QueryString.lng,15]),"loc"in $.QueryString){var o={text:$.QueryString.loc,filterOptions:{type:["StreetAddress","PositionOfInterest"]},apiKey:keyIgn,onSuccess:function(o){o&&"suggestedLocations"in o&&o.suggestedLocations.length>0?(t._setView([o.suggestedLocations[0].position.y,o.suggestedLocations[0].position.x,15]),e.resolveWith(t)):(console.log("No results?"),t._setView(n),e.resolveWith(t))},onFailure:function(o){console.log(o),t._setView(n),e.resolveWith(t)}};Gp.Services.autoComplete(o)}else t._setView(n),e.resolveWith(t)}).done(this._bindViewEvents)}}),L.Layer.include({_elevations:[],_distance:0,_altMin:0,_altMax:0,_denivPos:0,_denivNeg:0,prepareForMap:function(t,e,n){this._mapToAdd=t,this._start=e,this._end=n},getStartMarker:function(){return this._start},getEndMarker:function(){return this._end},getElevations:function(){return JSON.parse(JSON.stringify(this._elevations))},getDistance:function(){return this._distance},getAltMin:function(){return this._altMin},getAltMax:function(){return this._altMax},getDenivPos:function(){return this._denivPos},getDenivNeg:function(){return this._denivNeg},computeStats:function(){var t=this,e=t.getLatLngsFlatten();return $.Deferred(function(){var n=this,o=t._fetchAltitude(e).concat(t._fetchSlope(e)),i=o.length;n.notify({start:!0,total:i,status:"Récupération des données géographiques..."}),$.each(o,function(){this.done(function(){n.notify({step:this.size+" points récupérés"})})}),$.when.apply($,o).fail(n.reject).done(function(){$.each(e,function(t,e){$.Cache.hasAltitude(e)||(console.log("Could not find altitude for coordinates",e),n.rejectWith({error:"Impossible d'obtenir les données d'altitude"})),$.Cache.hasSlope(e)||(console.log("Could not find slope for coordinates",e),n.rejectWith({error:"Impossible d'obtenir les données de pente"}))}),t._computeStats(e),n.resolve()})})},_computeStats:function(t){var e=[];if($.each(t,function(t,n){var o=$.extend({},{lat:n.lat,lng:n.lng},$.Cache.getInfos(n));e.push(o)}),0==e.length)return!1;this._distance=0,this._altMin=e[0].z,this._altMax=e[0].z,this._denivPos=0,this._denivNeg=0,e[0].dist=0,e[0].slopeOnTrack=0,this._elevations=[e[0]];for(var n=0,o=1;o0&&(this._distance+=i/1e3,n++,this._elevations[n]=e[o],this._elevations[n].dist=this._distance,this._elevations[n].slopeOnTrack=Math.degrees(Math.atan((Math.round(this._elevations[n].z)-Math.round(this._elevations[n-1].z))/i)),this._elevations[n].zthis._altMax&&(this._altMax=this._elevations[n].z),this._elevations[n].z0&&n.push(fetchAltitude(e)),n},_fetchSlope:function(t){var e={},n=[],o=this._map||this._mapToAdd;return $.each(t,function(t,n){if(!$.Cache.hasSlope(n)){var i=n.toTilePixel(o.options.crs,16,256,o.getPixelOrigin()),a=i.tile,r=i.tilePixel;a.x in e||(e[a.x]={}),a.y in e[a.x]||(e[a.x][a.y]=[[]]),e[a.x][a.y][e[a.x][a.y].length-1].length>50&&e[a.x][a.y].push([]),e[a.x][a.y][e[a.x][a.y].length-1].push({lat:n.lat,lng:n.lng,x:r.x,y:r.y})}}),$.each(e,function(t,e){$.each(e,function(e,o){$.each(o,function(o,i){n.push(fetchSlope(t,e,i))})})}),n},setPopupContentWith:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];this.setPopupContent('
  • Altitude max: '+Math.round(e.altMax)+"m
  • D+: "+Math.round(e.denivPos)+"m
  • Altitude min: "+Math.round(e.altMin)+"m
  • D-: "+Math.round(e.denivNeg)+"m
  • Distance: "+Math.round(100*e.distance)/100+"km
"+(n?'':""))}}),function(t){t.widget("map2gpx.chart",{options:{map:void 0,dataEmpty:"#data-empty",isSmallScreen:!1,showMarker:!0,plotMarkerOptions:{icon:L.AwesomeMarkers.icon({icon:"area-chart",markerColor:"cadetblue",prefix:"fa"}),draggable:!1,clickable:!1,zIndexOffset:1e3},showSlope:!0,showTerrainSlope:!0},_create:function(){var e=this;if(void 0===this.options.map)throw'"map" option cannot be undefined';if(this.$emptyElement=t(this.options.dataEmpty),!this.options.isSmallScreen){this.$chart=t('').appendTo(this.element);var n=[{label:"Altitude",data:[],fill:!1,borderColor:"rgba(12, 98, 173, 0.8)",backgroundColor:"rgba(12, 98, 173, 0.8)",lineTension:0,pointRadius:0,yAxisId:"alt"}],o=[{id:"alt",type:"linear",position:"left",beginAtZero:!1}];this.options.showSlope&&(this.slopeIdx=n.length,n.push({label:"Pente de l'itinéraire",data:[],fill:!0,pointRadius:0,yAxisID:"slope"}),o.push({id:"slope",type:"linear",position:"right"})),this.options.showTerrainSlope&&(this.slopeTerrainIdx=n.length,n.push({label:"Pente du terrain",data:[],fill:!0,pointRadius:0,yAxisID:"slope2",hidden:!0}),o.push({id:"slope2",type:"linear",position:"right",ticks:{min:0,max:45}}));var i={};this.options.showMarker&&(i={mode:"index",intersect:!1,onHover:function(t,n){return e._onHover(t,n)}}),this.chartjs=new Chart(this.$chart,{type:"line",data:{datasets:n},options:{maintainAspectRatio:!1,onClick:function(t,n){return e._onClick(t,n)},hover:i,scales:{xAxes:[{id:"distance",type:"linear",position:"bottom",ticks:{min:0}}],yAxes:o},legend:{position:"left"},tooltips:{mode:"index",intersect:!1,callbacks:{title:function(t,e){return"Distance: "+Math.floor(100*t[0].xLabel)/100+"km"},label:function(t,e){return e.datasets[t.datasetIndex].label+": "+(0==t.datasetIndex?Math.round(100*t.yLabel)/100+"m":Math.round(t.yLabel)+"°")}}},annotation:{annotations:[]}}})}},_onClick:function(t,e){if(e&&e.length>0){var n=e[0]._index,o=this.chartjs.config.data.datasets[0].data[n];o.route&&o.route.openPopup(L.latLng(o.lat,o.lng))}},_onHover:function(t,e){if("mousemove"==t.type)if(e&&e.length>0){var n=e[0]._index,o=this.chartjs.config.data.datasets[0].data[n];null==this.plotMarker?(this.plotMarker=L.marker(L.latLng(o.lat,o.lng),this.options.plotMarkerOptions),this.plotMarker.addTo(this.options.map)):(this.plotMarker.setLatLng(L.latLng(o.lat,o.lng)),this.plotMarker.update())}else this.plotMarker&&(this.options.map.removeLayer(this.plotMarker),this.plotMarker=null);else"mouseout"==t.type&&this.plotMarker&&(this.options.map.removeLayer(this.plotMarker),this.plotMarker=null)},_replotSmallScreen:function(t){t.size>0?this.element.html("
  • Altitude max: "+Math.round(t.total.altMax)+"m; D+: "+Math.round(t.total.denivPos)+"m
  • Altitude min: "+Math.round(t.total.altMin)+"m; D-: "+Math.round(t.total.denivNeg)+"m
  • Distance: "+Math.round(100*t.elevations[t.size-1].dist)/100+"km
"):this.element.empty()},_replotWideScreen:function(t){if(t.size>0){for(var e=[],n=[],o=[],i=0,a=0,r=0;r3&&ri&&(i=s),s=45&&u.addColorStop((i-45)/c,"purple"),i>=40&&u.addColorStop((i-40)/c,"red"),i>=35&&u.addColorStop((i-35)/c,"orange"),i>=30&&u.addColorStop((i-30)/c,"yellow"),u.addColorStop(i/c,"grey"),a<=-30&&u.addColorStop((i+30)/c,"yellow"),a<=-35&&u.addColorStop((i+35)/c,"orange"),a<=-40&&u.addColorStop((i+40)/c,"red"),a<=-45&&u.addColorStop((i+45)/c,"purple"),this.chartjs.config.data.datasets[this.slopeIdx].backgroundColor=u)}if(this.options.showTerrainSlope){this.chartjs.config.data.datasets[this.slopeTerrainIdx].data=o;var h=this.$chart[0].getContext("2d").createLinearGradient(0,0,0,120);h.addColorStop(0,"purple"),h.addColorStop(1-40/45,"red"),h.addColorStop(1-35/45,"orange"),h.addColorStop(1-30/45,"yellow"),h.addColorStop(1,"grey"),this.chartjs.config.data.datasets[this.slopeTerrainIdx].backgroundColor=h}this.chartjs.options.annotation={},this.chartjs.update(),this.chartjs.options.annotation={annotations:t.annotations},this.chartjs.update()}else{this.chartjs.options.scales.xAxes[0].ticks.max=1;for(var p=0;p0?this.$emptyElement.slideUp():this.$emptyElement.slideDown()}})}(jQuery),function(t){function e(e,o,i,a){var r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"auto";return t.Deferred(function(){var s=this;"straight"==r?n(e,o,i,a).progress(s.notify).done(s.resolve).fail(s.reject):function(t,e,n,o){return L.polyline_findAuto(e.getLatLng(),n.getLatLng())}(0,o,i).progress(s.notify).done(s.resolve).fail(function(){console.log(this.error),console.log("Trying straight line...");var r=new Drop({target:t(".awesome-marker").eq(a+1)[0],classes:"drop-theme-arrows",position:"right middle",constrainToWindow:!1,constrainToScrollParent:!1,openOn:null,content:"Impossible d'obtenir le tracé en mode automatique. Le mode ligne droite va être utilisé."});r.open(),t(r.content).on("click",function(){r.destroy()}),n(e,o,i,a).progress(s.notify).done(s.resolve).fail(s.reject)})})}function n(e,n,o,i){var a=L.polyline_findStraight(n.getLatLng(),o.getLatLng());return t.Deferred(function(){this.resolve(a)})}var o={red:"#D63E2A",orange:"#F59630",green:"#72B026",blue:"#38AADD",purple:"#D252B9",darkred:"#A23336",darkblue:"#0067A3",darkgreen:"#728224",darkpurple:"#5B396B",cadetblue:"#436978",lightred:"#FF8E7F",beige:"#FFCB92",lightgreen:"#BBF970",lightblue:"#8ADAFF",pink:"#FF91EA",white:"#FBFBFB",lightgray:"#A3A3A3",gray:"#575757",black:"#303030"},i=["blue","green","orange","purple","red","darkblue","darkpurple","lightblue","lightgreen","beige","pink","lightred"];L.Track=L.Evented.extend({options:{map:void 0},initialize:function(t){L.setOptions(this,t),this.Lmap=this.options.map.map("getMap"),this.$map=this.options.map,this.currentColor=0,this.markersLength=0},getCurrentColor:function(){return this.currentColor},nextColor:function(){return this.currentColor=(this.currentColor+1)%i.length,this.currentColor},lengthOfMarkers:function(){return this.markersLength},hasMarkers:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.markersLength>=t},hasRoutes:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.markersLength-1>=t},isImport:function(){return this.hasRoutes()&&"import"==this.getFirstMarker().getRouteModeFromHere()},getBounds:function(){var t=L.latLngBounds(this.getFirstMarker(0).getLatLng(),this.getLastMarker().getLatLng());return this.eachRoute(function(e,n){t.extend(n.getBounds())}),t},getFirstMarker:function(){return this.firstMarker},getLastMarker:function(){return this.lastMarker},isLoop:function(){return!!this.firstMarker&&!!this.lastMarker&&this.firstMarker.getLatLng().distanceTo(this.lastMarker.getLatLng())<10},clear:function(){this.eachMarker(function(t,e){e.remove(!1)}),this.fire("markerschanged")},eachMarker:function(t){for(var e=this.firstMarker,n=0;e;){var o=e._nextMarker;t.call(e,n,e),e=o,n++}},eachRoute:function(t){for(var e=this.firstMarker,n=0;e;){var o=e.getRouteFromHere();o&&(t.call(o,n,o),n++),e=e._nextMarker}},addMarker:function(e){var n,o=this,i=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return void 0===this.firstMarker&&(this.firstMarker=e),void 0!==this.lastMarker&&i&&(n=this.lastMarker.computeRouteTo(e,this.$map.map("getMode"))),this.lastMarker=e,this.markersLength++,e.track=this,e.addTo(this.Lmap),n||(n=t.Deferred(function(){this.resolve()})),n.done(function(){return o.fire("markerschanged")})},moveMarker:function(e){var n=this;return t.Deferred(function(){var o=this,i=[];if(e.hasRouteFromHere()){i.length;i.push(e.recomputeRouteFromHere(n.$map.map("getMode")))}if(e.hasRouteToHere()){i.length;i.push(e.recomputeRouteToHere(n.$map.map("getMode")))}t.when.apply(t,i).done(function(){n.fire("markerschanged"),o.resolve()}).fail(o.reject)})},insertMarker:function(e,n){var o=this;return t.Deferred(function(){var i=this,a=[];a.push(n.getStartMarker().computeRouteTo(e,o.$map.map("getMode"))),a.push(e.computeRouteTo(n.getEndMarker(),o.$map.map("getMode"))),o.markersLength++,e.addTo(o.Lmap),t.when.apply(t,a).done(function(){o.fire("markerschanged"),i.resolve()}).fail(i.reject)})},_initStats:function(){return{distance:0,altMin:Number.MAX_VALUE,altMax:Number.MIN_VALUE,denivPos:0,denivNeg:0}},computeStats:function(){var t=this,e=[],n=[],o=this._initStats(),i=this._initStats();if(this.eachMarker(function(a,r){if("step"==r.getType()){e.push(o.distance);for(var s=r;s&&s.hasRouteToHere()&&(s.getRouteToHere().setPopupContentWith(s._previousMarker.getColorCode(),i,"import"!=s._previousMarker.getRouteModeFromHere()),"step"!=(s=s._previousMarker).getType()););i=t._initStats()}var l=r.getRouteFromHere(),u=l?l.getElevations():[];if(u.length>0){for(var c=0;c0)for(var a=this.getLastMarker();a&&a.hasRouteToHere()&&(a.getRouteToHere().setPopupContentWith(a._previousMarker.getColorCode(),i,"import"!=a._previousMarker.getRouteModeFromHere()),"step"!=(a=a._previousMarker).getType()););return{size:n.length,elevations:n,total:o,steps:e}},exportGpx:function(e){var n=!1;try{n=!!new Blob}catch(t){}if(!n)return!1;var o='\n';o+='\n",o+=" \n",this.eachMarker(function(n,i){i.hasRouteFromHere()&&("step"==i.getType()&&(o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n"),t.each(i.getRouteFromHere().getLatLngsFlatten(),function(e,n){o+=' ',t.Cache.hasAltitude(n)&&(o+=""+t.Cache.getAltitude(n)+""),o+="\n"}))}),o+=" \n",o+=" \n",o+="\n";var i=new Blob([o],{type:"application/gpx+xml;charset=utf-8"});return saveAs(i,e+".gpx"),!0},exportKml:function(e){var n=!1;try{n=!!new Blob}catch(t){}if(!n)return!1;var o='\n';o+='\n",o+=" \n",o+=" "+e+"\n",o+=" \n",o+=" 1\n",o+=" \n",o+=" ",this.eachMarker(function(n,i){i.hasRouteFromHere()&&("step"==i.getType()&&(o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n",o+=" 1\n",o+=" \n",o+=" "),t.each(i.getRouteFromHere().getLatLngsFlatten(),function(t,e){o+=e.lng+","+e.lat+",0 "}))}),o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+="\n";var i=new Blob([o],{type:"text/plain;charset=utf-8"});return saveAs(i,e+".kml"),!0},importGpx:function(e,n){var o=this;return t.Deferred(function(){var i=this,a=new FileReader;t(o).startBlockingCompute(function(r){a.onload=function(e){var a=[];new L.GPX(e.target.result,{async:!0,onFail:function(){t(o).endBlockingCompute(r),i.rejectWith({error:"Impossible de traiter ce fichier"})},onSuccess:function(e){i.notify({step:"Fichier traité"}),i.notify({start:!0,total:a.length,status:n?"Interpolation en cours...":"Traitement en cours..."}),o.clear();var s=e.getBounds();o.Lmap.fitBounds(s,{padding:[50,50]});var l=[],u=[];t.each(a,function(e,a){if(n){var r=a.getLatLngsFlatten();i.notify({start:!0,total:r.length}),a.prepareForMap(o.Lmap,null,null),a.setStyle({weight:5,color:"#81197f",opacity:.2,snakingPause:0,snakingSpeed:1e3}),a.addTo(o.Lmap),l.push(L.polyline_interpolate(r).progress(function(t){i.notify({count:t.count,step:t.count+" points trouvés"}),t.line.prepareForMap(o.Lmap,null,null),t.line.setStyle({weight:5,color:"#81197f",opacity:.5,snakingPause:0,snakingSpeed:1e3}),t.line.addTo(o.Lmap),u.push(t.line.computeStats().progress(i.notify))}).done(function(){return a.remove()}))}else a.prepareForMap(o.Lmap,null,null),a.setStyle({weight:5,color:"#81197f",opacity:.5,snakingPause:0,snakingSpeed:1e3}),a.addTo(o.Lmap),l.push(t.Deferred(function(){this.resolve([{line:a,mode:"import"}])})),u.push(a.computeStats().progress(i.notify))}),t.when.apply(t,l).done(function(){for(var e,a=arguments,s=function(i){var r=a[i],s=r.length;t.each(r,function(i,a){var r=a.line.getLatLngsFlatten();if(void 0===e){var l=r[0];e=L.Marker.routed(l,{riseOnHover:!0,draggable:n,opacity:1,color:o.getCurrentColor(),type:"waypoint"}),n?e.add(o,!1):o.addMarker(e,!1)}var u=r[r.length-1],c=L.Marker.routed(u,{riseOnHover:!0,draggable:n,opacity:1,color:i==s-1?o.nextColor():o.getCurrentColor(),type:i==s-1?"step":"waypoint"});if(n?c.add(o,!1):o.addMarker(c,!1),a.line.prepareForMap(o.Lmap,e,c),a.line.setStyle({weight:5,color:e.getColorRgb(),opacity:.75}),a.line.bindPopup("Calculs en cours..."),n){var h=e;a.line.on("popupopen",function(e){t(".marker-add-button:visible").click(function(){L.Marker.routed(e.popup.getLatLng().roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:h.getColorIndex(),type:"waypoint"}).insert(a.line)})})}e.attachRouteFrom(c,a.line,a.mode),e=c})},l=0;l Marquer comme étape '),this.on("popupopen",function(){t(".marker-delete-button:visible").click(function(){e.remove()}),t(".marker-promote-button:visible").click(function(){e.closePopup(),e.setPopupContent(''),e.promoteToStep()})}),this.on("moveend",function(t){e.track.moveMarker(e)})},add:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.track=t,this._bindEvents(),this.track.addMarker(this,e)},insert:function(e){return this.track=t("#map").map("getTrack"),this._bindEvents(),this.track.insertMarker(this,e)},remove:function(){var e,n=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];"step"==this.options.type&&n&&this.demoteToWaypoint();var o=this._previousMarker,i=this._nextMarker;if(this.track._removeMarker(this),this.routeFrom&&this.deleteRouteFromHere(),o&&(o.deleteRouteFromHere(),i))if(o.getLatLng().equals(i.getLatLng()))o.attachRouteFrom(i,null,void 0),e="step"==o.options.type?i.remove(n):o.remove(n);else if(n){var a=this.track.$map.map("getMode")||this._mode||"auto";e=o.computeRouteTo(i,a)}return e||(e=t.Deferred(function(){this.resolve()})),L.Marker.prototype.remove.call(this),this.track.fire("markerschanged"),e}}),L.Marker.routed=function(t,e){return new L.Marker.Routed(t,e)}}(jQuery),function(t){t.widget("map2gpx.map",{options:{leafletOptions:{},controls:{searchEngine:{show:!0,leafletOptions:{displayAdvancedSearch:!1}},minimap:{show:!0,leafletOptions:{position:"bottomleft",zoomLevelOffset:-4}},layerSwitcher:{show:!0,showAll:!0,leafletOptions:{collapsed:!1}},scale:{show:!0,leafletOptions:{imperial:!1,position:"bottomright"}},help:{show:!0}}},getMap:function(){return this.map},getTrack:function(){return this.track},getMode:function(){return this.mode},_buildEventData:function(){return{mode:this.mode}},_setMode:function(t){this.mode=t,this._trigger("modechanged",null,this._buildEventData())},_onCreated:function(){var e=this;this.element.on("mapmodechanged",function(t){e.map.doubleClickZoom.setEnabled(null===e.mode)}),this.map.on("dblclick",function(t){return e._addMarker.call(e,t)}),this._initializeLayers(),this.options.controls.searchEngine.show&&this._initializeSearchEngine(),this.options.controls.minimap.show&&this._initializeMinimap(),this.options.controls.layerSwitcher.show&&this._initializeLayerSwitcher(),this.options.controls.scale.show&&this._initializeScale(),this._initializeTraceButtons(),this._initializeExportButtons(),this._initializeImportButtons(),this.options.controls.help.show&&this._initializeHelpButtons(),this._trigger("created",null,{}),this._trigger("statechanged",null,this._buildEventData()),t.when.apply(t,this.layers.promises).done(function(){e._trigger("loaded",null,{})})},_initializeLayers:function(){var e=this,n=this;this.layers.photos=L.geoportalLayer.WMTS({layer:"ORTHOIMAGERY.ORTHOPHOTOS",apiKey:keyIgn}).addTo(this.map),this.options.controls.layerSwitcher.showAll&&this.layers.promises.push(t.Deferred(function(){n.layers.photos.once("load",this.resolve)})),this.layers.slopes=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.SLOPES.MOUNTAIN",apiKey:keyIgn},{opacity:.25}).addTo(this.map),this.layers.maps=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.MAPS",apiKey:keyIgn},{opacity:this.options.controls.layerSwitcher.showAll?.25:1}).addTo(this.map),this.layers.promises.push(t.Deferred(function(){n.layers.maps.once("load",this.resolve)}));var o=void 0;this.map.on("zoomend",function(){var n=e.map.getZoom(),i=void 0,a=void 0;e.map.hasLayer(e.layers.photos)&&(e.layers.photos.options.minZoom>n||e.layers.photos.options.maxZoomn||e.layers.maps.options.maxZoomn||e.layers.slopes.options.maxZoomAttention: l'import va effacer l'itinéraire existant!"):t("#import-gpx-status").text("")}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Importer (calcul en cours...)"}]});t("#import-gpx-button").click(function(){var e=t(this),i=t("#import-gpx-file")[0].files[0],a=t("#import-gpx-interpolate").is(":checked");void 0!=i?(e.attr("disabled","disabled"),t("body").startCompute(function(r){t.Queue.notify({start:!0,total:1,status:"Importation en cours..."}),n.track.importGpx(i,a).done(function(){e.removeAttr("disabled"),n._setMode(null)}).fail(function(){t("#import-gpx-status").text(this.error),e.removeAttr("disabled")}).progress(function(e){t.Queue.notify(e),o.isOpen()&&n.map.closePopup()}).always(function(){return t("body").endCompute(r)})})):t("#import-gpx-status").text("Veuillez sélectionner un fichier")});var a=L.easyButton({id:"btn-reset",states:[{stateName:"loaded",icon:"fa-trash",title:"Effacer l'itinéraire",onClick:function(t,n){e.track.clear()}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Effacer l'itinéraire (calcul en cours...)"}]});L.easyBar([i,a]).addTo(this.map),this.element.on("mapcomputingchanged mapstatechanged",function(t){i.state(e.computing?"computing":"loaded"),a.state(e.computing?"computing":"loaded"),i.setEnabled(!e.computing),a.setEnabled(!e.computing&&e.track.hasMarkers())})},_initializeHelpButtons:function(){var e=this,n=window.innerWidth-t(".leaflet-control-minimap").width()-t(".leaflet-top.leaflet-right .GPpanel").width(),o=L.popup({maxWidth:n}).setContent(L.DomUtil.get("about")),i=L.easyButton({position:"bottomright",states:[{icon:"fa-info-circle",onClick:function(t,n){o.setLatLng(e.map.getCenter()).openOn(e.map)},title:"A propos & crédits"}]}),a=L.easyButton({position:"bottomright",states:[{icon:"fa-question-circle",onClick:function(e,n){t.Shepherd.get(0).start(!0)},title:"Aide"}]});L.easyBar([i,a],{position:"bottomright"}).addTo(this.map)},_create:function(){var t=this;this.element.uniqueId(),this.layers={},this.layers.promises=[],this.mode=null,this.map=L.map(this.element.attr("id"),this.options.leafletOptions),this.track=L.track({map:this.element}),this.track.on("markerschanged",function(){return t._trigger("statechanged",null,t._buildEventData())}),this.map.initView().done(function(){return t._onCreated()})},_addMarker:function(t){if(null!==this.mode){var e=L.Marker.routed(t.latlng.roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:this.track.hasMarkers()?this.track.getLastMarker().getColorIndex():this.track.getCurrentColor(),type:"waypoint"});this.track.hasMarkers()&&this.track.getLastMarker().getLatLng().equals(e.getLatLng())||e.add(this.track)}}})}(jQuery);var isSmallScreen=window.innerWidth<=800&&window.innerHeight<=600;showLoadingMessage("Observation des faucons crécerelle..."),isSmallScreen&&$("#mobile-warning").show().find("button").click(function(){$("#mobile-warning").hide()}),window.onload=function(){try{showLoadingMessage("Localisation des chamois..."),$("#data-computing").progress().on("progressstatechanged",function(e,n){n.started?($("#data-invalid").fadeOut(),$("#data-computing").fadeIn()):($("#data").data("map2gpx-chart").replot(t.map("getTrack").computeStats()),$("#data-computing").fadeOut())}).on("progressfailed",function(t,e){$("#data-invalid-status").text(e.error),$("#data-invalid").fadeIn()}),$.Queue.bindTo($("#data-computing")),$.BlockingQueue.bindTo({start:function(){return $("#pending").fadeIn()},stop:function(){return $("#pending").fadeOut()}});var t=$("#map").map({controls:{minimap:{show:!isSmallScreen},layerSwitcher:{showAll:!isSmallScreen,leafletOptions:{collapsed:isSmallScreen}},scale:{show:!isSmallScreen},help:{show:!isSmallScreen}},created:function(){showLoadingMessage("Suivi des renards roux..."),isSmallScreen||$.Shepherd.tour().add("welcome",{text:$("#help-welcome")[0]}).add("layers",{text:$("#help-layers")[0],attachTo:{element:$(".GPlayerName").closest(".GPwidget")[0],on:"left"}}).add("search",{text:$("#help-search")[0],attachTo:{element:$(".GPshowAdvancedToolOpen").closest(".GPwidget")[0],on:"right"}}).add("autotrace",{text:$("#help-autotrace")[0],attachTo:{element:$("#btn-autotrace")[0],on:"right"}}).add("straighttrace",{text:$("#help-straighttrace")[0],attachTo:{element:$("#btn-straighttrace")[0],on:"right"}}).start()},loaded:function(){showLoadingMessage("Alignement des satellites..."),clearInterval(interval),$("#loading").fadeOut()}}).on("mapmarkerschanged",function(e){isSmallScreen||(t.map("getTrack").hasMarkers(2)&&!$.Shepherd.has(1)&&$.Shepherd.tour().add("data",{text:$("#help-data")[0],attachTo:{element:$("#data")[0],on:"top"}}).add("closeloop",{text:$("#help-closeloop")[0],attachTo:{element:$("#btn-closeloop")[0],on:"right"}}).add("export",{text:$("#help-export")[0],attachTo:{element:$("#btn-export")[0],on:"right"}}).start(),t.map("getTrack").hasMarkers(3)&&!$.Shepherd.has(2)&&$.Shepherd.tour().add("movemarker",{text:$("#help-movemarker")[0],attachTo:{element:$(".awesome-marker").last()[0],on:"bottom"}}).add("movemarker2",{text:$("#help-movemarker2")[0],attachTo:{element:$(".awesome-marker").eq(-2)[0],on:"bottom"}}).add("steps",{text:$("#help-steps")[0],attachTo:{element:$(".awesome-marker").last()[0],on:"bottom"}}).add("steps2",{beforeShowPromise:function(){return $.Deferred(function(){var e=t.map("getTrack").getFirstMarker().getRouteFromHere(),n=e.getLatLngsFlatten(),o=n[Math.floor(n.length/2)];e.openPopup(o),this.resolve()}).promise()},text:$("#help-steps2")[0]}).start())}).on("mapstatechanged",function(e){$("#data").data("map2gpx-chart").replot(t.map("getTrack").computeStats())});$("#data").chart({map:t.map("getMap"),dataEmpty:"#data-empty",isSmallScreen:isSmallScreen})}catch(t){gotError=!0,console.log("Got exception",t),$("#loading").animate({backgroundColor:"#A23336",color:"#FFFFFF"}),$("#loading h2 i.fa").removeClass("fa-spinner fa-pulse").addClass("fa-bug"),$("#loading h2 span").html("Une erreur s'est produite: ""+t+""."),$("#loading h3").html($('
N\'hésitez pas à ouvrir un ticket sur Github ou à m\'envoyer un mail à hi@tmuguet.me.
').hide().slideDown()),clearInterval(interval)}}; \ No newline at end of file diff --git a/js/map2gpx.src.js b/js/map2gpx.src.js index d3d0318..bca08aa 100644 --- a/js/map2gpx.src.js +++ b/js/map2gpx.src.js @@ -558,6 +558,12 @@ L.polyline_interpolate = function (coords) { this.progress('update', progress); }); }, + + failed: function (error) { + $.each(listeners, function () { + this.progress('failed', error); + }); + }, }; })(jQuery); @@ -672,6 +678,12 @@ L.polyline_interpolate = function (coords) { this.stop(); }, + failed: function (error) { + this.$status.text('Une erreur est survenue'); + $('
' + error + '
').insertAfter(this.$h2).fadeOut(10000, function () {$(this).remove();}); + this._trigger('failed', null, { error }); + }, + update: function (progress) { if (Array.isArray(progress)) { const _this = this; @@ -939,9 +951,11 @@ L.Layer.include({ computeStats: function () { const _this = this; + const latlngs = _this.getLatLngsFlatten(); + return $.Deferred(function () { const deferred = this; // jscs:ignore safeContextKeyword - const promises = _this._fetchAltitude().concat(_this._fetchSlope()); + const promises = _this._fetchAltitude(latlngs).concat(_this._fetchSlope(latlngs)); const total = promises.length; deferred.notify({ start: true, total: total, status: 'Récupération des données géographiques...' }); @@ -954,17 +968,30 @@ L.Layer.include({ $.when.apply($, promises) .fail(deferred.reject) - .then(function () { - _this._computeStats(); + .done(function () { + // Sanity checks + $.each(latlngs, function (j, coords) { + if (!$.Cache.hasAltitude(coords)) { + console.log('Could not find altitude for coordinates', coords); + deferred.rejectWith({ error: 'Impossible d\'obtenir les données d\'altitude' }); + } + + if (!$.Cache.hasSlope(coords)) { + console.log('Could not find slope for coordinates', coords); + deferred.rejectWith({ error: 'Impossible d\'obtenir les données de pente' }); + } + }); + + _this._computeStats(latlngs); deferred.resolve(); }); }); }, - _computeStats: function () { + _computeStats: function (latlngs) { const elevations = []; - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { const values = $.extend({}, { lat: coords.lat, lng: coords.lng }, $.Cache.getInfos(coords)); elevations.push(values); }); @@ -1014,11 +1041,11 @@ L.Layer.include({ return true; }, - _fetchAltitude: function () { + _fetchAltitude: function (latlngs) { var geometry = []; // Batch const promises = []; - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { if (!$.Cache.hasAltitude(coords)) { // Skip already cached values geometry.push({ lon: coords.lng, @@ -1040,12 +1067,12 @@ L.Layer.include({ return promises; }, - _fetchSlope: function () { + _fetchSlope: function (latlngs) { const tiles = {}; const promises = []; const map = (this._map || this._mapToAdd); - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { if (!$.Cache.hasSlope(coords)) { // Skip already cached values const { tile, tilePixel } = coords.toTilePixel(map.options.crs, 16, 256, map.getPixelOrigin()); @@ -1655,7 +1682,7 @@ L.Layer.include({ $.when.apply($, promises).done(() => { _this.fire('markerschanged'); deferred.resolve(); - }).fail(deferred.fail); + }).fail(deferred.reject); }); }, @@ -1679,7 +1706,7 @@ L.Layer.include({ $.when.apply($, promises).done(() => { _this.fire('markerschanged'); deferred.resolve(); - }).fail(deferred.fail); + }).fail(deferred.reject); }); }, @@ -2154,7 +2181,8 @@ L.Layer.include({ _this.attachRouteFrom(to, geojson, mode); $(_this).startCompute((next) => { - geojson.computeStats().progress($.Queue.notify).then(deferred.resolve).fail(function () { + geojson.computeStats().progress($.Queue.notify).done(deferred.resolve).fail(function () { + $.Queue.failed('Impossible d\'obtenir les données de la route'); deferred.rejectWith({ error: 'Impossible d\'obtenir les données de la route' }); }).always(() => $(_this).endCompute(next)); @@ -2174,7 +2202,13 @@ L.Layer.include({ }); }); - geojson.snakeIn(); + try { + geojson.snakeIn(); + } catch (e) { + // With some weird tracks, snakeIn can fail (don't know why) + geojson._snakeEnd(); + } + _this.setOpacity(1); to.setOpacity(1); }); @@ -2786,13 +2820,18 @@ window.onload = function () { $('#data-computing').progress().on('progressstatechanged', (e, data) => { if (data.started) { + $('#data-invalid').fadeOut(); $('#data-computing').fadeIn(); } else { $('#data').data('map2gpx-chart').replot($map.map('getTrack').computeStats()); $('#data-computing').fadeOut(); } + }).on('progressfailed', (e, data) => { + $('#data-invalid-status').text(data.error); + $('#data-invalid').fadeIn(); }); $.Queue.bindTo($('#data-computing')); + $.BlockingQueue.bindTo({ start: () => $('#pending').fadeIn(), stop: () => $('#pending').fadeOut(), diff --git a/package-lock.json b/package-lock.json index 53cb601..f25aef8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "map2gpx", - "version": "1.3.4", + "version": "1.3.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3e17299..88e2ad7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "map2gpx", - "version": "1.3.4", + "version": "1.3.5", "description": "map2gpx is a web application that lets you trace paths on maps (for hiking for instance) and export them to GPX or KML formats.\\n", "main": "n/a", "private": true, diff --git a/src/js/progress.js b/src/js/progress.js index fdb79f1..c2fff14 100644 --- a/src/js/progress.js +++ b/src/js/progress.js @@ -57,6 +57,12 @@ this.stop(); }, + failed: function (error) { + this.$status.text('Une erreur est survenue'); + $('
' + error + '
').insertAfter(this.$h2).fadeOut(10000, function () {$(this).remove();}); + this._trigger('failed', null, { error }); + }, + update: function (progress) { if (Array.isArray(progress)) { const _this = this; diff --git a/src/js/queue.js b/src/js/queue.js index 08cd2bf..74c9af3 100644 --- a/src/js/queue.js +++ b/src/js/queue.js @@ -51,6 +51,12 @@ this.progress('update', progress); }); }, + + failed: function (error) { + $.each(listeners, function () { + this.progress('failed', error); + }); + }, }; })(jQuery); diff --git a/src/js/script.js b/src/js/script.js index 3f696f5..14bae0c 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -15,13 +15,18 @@ window.onload = function () { $('#data-computing').progress().on('progressstatechanged', (e, data) => { if (data.started) { + $('#data-invalid').fadeOut(); $('#data-computing').fadeIn(); } else { $('#data').data('map2gpx-chart').replot($map.map('getTrack').computeStats()); $('#data-computing').fadeOut(); } + }).on('progressfailed', (e, data) => { + $('#data-invalid-status').text(data.error); + $('#data-invalid').fadeIn(); }); $.Queue.bindTo($('#data-computing')); + $.BlockingQueue.bindTo({ start: () => $('#pending').fadeIn(), stop: () => $('#pending').fadeOut(), diff --git a/src/js/stats.js b/src/js/stats.js index 7c75636..d0c8634 100644 --- a/src/js/stats.js +++ b/src/js/stats.js @@ -103,9 +103,11 @@ L.Layer.include({ computeStats: function () { const _this = this; + const latlngs = _this.getLatLngsFlatten(); + return $.Deferred(function () { const deferred = this; // jscs:ignore safeContextKeyword - const promises = _this._fetchAltitude().concat(_this._fetchSlope()); + const promises = _this._fetchAltitude(latlngs).concat(_this._fetchSlope(latlngs)); const total = promises.length; deferred.notify({ start: true, total: total, status: 'Récupération des données géographiques...' }); @@ -118,17 +120,30 @@ L.Layer.include({ $.when.apply($, promises) .fail(deferred.reject) - .then(function () { - _this._computeStats(); + .done(function () { + // Sanity checks + $.each(latlngs, function (j, coords) { + if (!$.Cache.hasAltitude(coords)) { + console.log('Could not find altitude for coordinates', coords); + deferred.rejectWith({ error: 'Impossible d\'obtenir les données d\'altitude' }); + } + + if (!$.Cache.hasSlope(coords)) { + console.log('Could not find slope for coordinates', coords); + deferred.rejectWith({ error: 'Impossible d\'obtenir les données de pente' }); + } + }); + + _this._computeStats(latlngs); deferred.resolve(); }); }); }, - _computeStats: function () { + _computeStats: function (latlngs) { const elevations = []; - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { const values = $.extend({}, { lat: coords.lat, lng: coords.lng }, $.Cache.getInfos(coords)); elevations.push(values); }); @@ -178,11 +193,11 @@ L.Layer.include({ return true; }, - _fetchAltitude: function () { + _fetchAltitude: function (latlngs) { var geometry = []; // Batch const promises = []; - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { if (!$.Cache.hasAltitude(coords)) { // Skip already cached values geometry.push({ lon: coords.lng, @@ -204,12 +219,12 @@ L.Layer.include({ return promises; }, - _fetchSlope: function () { + _fetchSlope: function (latlngs) { const tiles = {}; const promises = []; const map = (this._map || this._mapToAdd); - $.each(this.getLatLngsFlatten(), function (j, coords) { + $.each(latlngs, function (j, coords) { if (!$.Cache.hasSlope(coords)) { // Skip already cached values const { tile, tilePixel } = coords.toTilePixel(map.options.crs, 16, 256, map.getPixelOrigin()); diff --git a/src/js/track.js b/src/js/track.js index 54e9379..f5e0db9 100644 --- a/src/js/track.js +++ b/src/js/track.js @@ -205,7 +205,7 @@ $.when.apply($, promises).done(() => { _this.fire('markerschanged'); deferred.resolve(); - }).fail(deferred.fail); + }).fail(deferred.reject); }); }, @@ -229,7 +229,7 @@ $.when.apply($, promises).done(() => { _this.fire('markerschanged'); deferred.resolve(); - }).fail(deferred.fail); + }).fail(deferred.reject); }); }, @@ -704,7 +704,8 @@ _this.attachRouteFrom(to, geojson, mode); $(_this).startCompute((next) => { - geojson.computeStats().progress($.Queue.notify).then(deferred.resolve).fail(function () { + geojson.computeStats().progress($.Queue.notify).done(deferred.resolve).fail(function () { + $.Queue.failed('Impossible d\'obtenir les données de la route'); deferred.rejectWith({ error: 'Impossible d\'obtenir les données de la route' }); }).always(() => $(_this).endCompute(next)); @@ -724,7 +725,13 @@ }); }); - geojson.snakeIn(); + try { + geojson.snakeIn(); + } catch (e) { + // With some weird tracks, snakeIn can fail (don't know why) + geojson._snakeEnd(); + } + _this.setOpacity(1); to.setOpacity(1); });