diff --git a/js/map2gpx.babel.js b/js/map2gpx.babel.js index 1bfa99b..cad835c 100644 --- a/js/map2gpx.babel.js +++ b/js/map2gpx.babel.js @@ -2355,6 +2355,9 @@ window.onload = function () { type: 'waypoint' }); + // Ignore this marker if same as previous + if ($.Track.hasMarkers() && $.Track.getLastMarker().getLatLng().equals(marker.getLatLng())) return; + marker.add().progress($.State.updateComputing).done(function () { marker.setOpacity(1); }); diff --git a/js/map2gpx.min.js b/js/map2gpx.min.js index c3b1035..23ba1dd 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,a={tilematrix:16,tilerow:e,tilecol:t,lon:"",lat:"",x:"",y:""};$.each(n,function(t,e){t>0&&(a.lon+="|",a.lat+="|",a.x+="|",a.y+="|"),a.lon+=e.lng.toString(),a.lat+=e.lat.toString(),a.x+=e.x.toString(),a.y+=e.y.toString()}),$.getJSON("slope.php",a,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 r=e.indexOf(this);null!==t.localStorage.get("tutorial"+r)&&(a=parseInt(t.localStorage.get("tutorial"+r)))}return a>=0&&at}}(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 a=t.latLngToPoint(this,e).floor(),r=a.divideBy(n).floor(),i=r.multiplyBy(n).subtract(o);return{tile:r,tilePixel:a.subtract(o).subtract(i)}},L.LatLng.prototype.getDestinationAlong=function(t,e){var n=6378137,o=Math.radians(t),a=Math.radians(this.lat),r=Math.radians(this.lng),i=Math.asin(Math.sin(a)*Math.cos(e/n)+Math.cos(a)*Math.sin(e/n)*Math.cos(o)),s=r+Math.atan2(Math.sin(o)*Math.sin(e/n)*Math.cos(a),Math.cos(e/n)-Math.sin(a)*Math.sin(i));return i=Math.degrees(i),s=Math.degrees(s),L.latLng(Math.roundE8(i),Math.roundE8(s))},L.LatLng.prototype.bearingTo=function(t){var e=Math.radians(this.lat),n=Math.radians(this.lng),o=Math.radians(t.lat),a=Math.radians(t.lng),r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),i=a-n;return Math.abs(i)>Math.PI&&(i=i>0?-(2*Math.PI-i):2*Math.PI+i),(Math.degrees(Math.atan2(i,r))+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()}}),function(t){var e=0;t.fn.clearCompute=function(){return this.each(function(){e-=t(this).queue().length,t(this).clearQueue()})},t.fn.startCompute=function(n){return this.each(function(){t.State.setComputing(!0),e++,t(this).queue(n)})},t.fn.endCompute=function(n){return this.each(function(){e--,n(),0==e&&t.State.setComputing(!1)})},t.Queue={size:function(){return e}}}(jQuery),function(t){var e=null,n=!1,o=0,a=0,r=t("#data-computing h2"),i=t("#data-computing-progress"),s=t("#data-computing-progressbar"),l=t("#data-computing-status");t("#data-computing-pending");t.State={},t.State.setMode=function(o){e=o,t("body").trigger(t.Event("map2gpx:modechange",{mode:e,computing:n}))},t.State.setComputing=function(r){r&&!n&&(o=0,a=0),n=r,t("body").trigger(t.Event("map2gpx:computingchange",{mode:e,computing:n}))},t.State.updateComputing=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(Array.isArray(e))return t.each(e,function(){t.State.updateComputing(this,!1)}),void t.State.displayComputing();e.start?a+=e.total:e.end?o=a:o++,"status"in e&&e.status&&l.text(e.status),"step"in e&&e.step&&t("
"+e.step+"
").insertAfter(r).fadeOut(400,function(){t(this).remove()}),n&&t.State.displayComputing()},t.State.displayComputing=function(){var e=1;a>0&&(e=o/a),i.text(Math.round(100*e)+"%"),s.css("width",Math.round(100*e)+"%"),42==Math.round(100*e)&&t("
La grande question sur la vie, l'univers et le reste répondue
").insertAfter(r).fadeOut(400,function(){t(this).remove()})},t.State.triggerMarkersChanged=function(){t("body").trigger(t.Event("map2gpx:markerschange",{mode:e,computing:n}))},t.State.getMode=function(){return e},t.State.getComputing=function(){return n}}(jQuery),function(t){var e={},n={};t.Cache={};var o=function(t){return t.lng+"/"+t.lat};t.Cache.addAltitude=function(t,n,o){e[n+"/"+t]=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[e+"/"+t]=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 a=o(t);return{z:a in e?e[a]:null,slope:a in n?n[a]:null}},t.Cache.lengthOfMarkers=function(){return t.Track.lengthOfMarkers()},t.Cache.hasMarkers=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t.Track.hasMarkers(e)},t.Cache.getMarker=function(t){},t.Cache.indexOfMarker=function(t){},t.Cache.eachMarker=function(t){},t.Cache.addMarker=function(t){},t.Cache.removeMarkerAt=function(t){},t.Cache.resetMarkers=function(){},t.Cache.lengthOfRoutes=function(){},t.Cache.hasRoutes=function(t){},t.Cache.getRoute=function(t){},t.Cache.getRouteMode=function(t){},t.Cache.eachRoute=function(t){},t.Cache.addRoute=function(t,e){},t.Cache.setRouteAt=function(t,e,n){},t.Cache.removeRouteAt=function(t){},t.Cache.resetRoutes=function(){}}(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("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.getLatLngs(),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;n10&&(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.getLatLngs(),function(e,o){if(!$.Cache.hasSlope(o)){var a=o.toTilePixel(n.options.crs,16,256,n.getPixelOrigin()),r=a.tile,i=a.tilePixel;r.x in t||(t[r.x]={}),r.y in t[r.x]||(t[r.x][r.y]=[[]]),t[r.x][r.y][t[r.x][r.y].length-1].length>50&&t[r.x][r.y].push([]),t[r.x][r.y][t[r.x][r.y].length-1].push({lat:o.lat,lng:o.lng,x:i.x,y:i.y})}}),$.each(t,function(t,n){$.each(n,function(n,o){$.each(o,function(o,a){e.push(fetchSlope(t,n,a))})})}),e},setPopupContentWith:function(t,e){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
')}}),L.GeoJSON.include({getLatLngs:function(){var t=[];return this.eachLayer(function(e){$.each(e.feature.geometry.coordinates,function(e,n){t.push(L.latLng(n[1],n[0]))})}),t}}),function(t){var e,n,o,a,r=null,i={icon:L.AwesomeMarkers.icon({icon:"area-chart",markerColor:"cadetblue",prefix:"fa"}),draggable:!1,clickable:!1,zIndexOffset:1e3},s=null;t.Chart={init:function(l,u,c,d,p){e=u,n=c,o=d,(a=p)?t("#"+u).remove():s=new Chart(t("#"+u),{type:"line",data:{datasets:[{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"},{label:"Pente de l'itinéraire",data:[],fill:!0,pointRadius:0,yAxisID:"slope"},{label:"Pente du terrain",data:[],fill:!0,pointRadius:0,yAxisID:"slope2",hidden:!0}]},options:{maintainAspectRatio:!1,onClick:function(t,e){if(e&&e.length>0){var n=e[0]._index,o=s.config.data.datasets[0].data[n];o.route&&o.route.openPopup(L.latLng(o.lat,o.lng))}},hover:{mode:"index",intersect:!1,onHover:function(t,e){if("mousemove"==t.type)if(e&&e.length>0){var n=e[0]._index,o=s.config.data.datasets[0].data[n];null==r?(r=L.marker(L.latLng(o.lat,o.lng),i)).addTo(l):(r.setLatLng(L.latLng(o.lat,o.lng)),r.update())}else r&&(l.removeLayer(r),r=null);else"mouseout"==t.type&&r&&(l.removeLayer(r),r=null)}},scales:{xAxes:[{id:"distance",type:"linear",position:"bottom",ticks:{min:0}}],yAxes:[{id:"alt",type:"linear",position:"left",beginAtZero:!1},{id:"slope",type:"linear",position:"right"},{id:"slope2",type:"linear",position:"right",ticks:{min:0,max:45}}]},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:[]}}})},_replotSmallScreen:function(t){t.size>0?n.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
"):n.empty()},_replotWideScreen:function(t){if(t.size>0){for(var n=[],o=[],a=[],r=0,i=0,l=0;l3&&lr&&(r=u),u=45&&d.addColorStop((r-45)/p,"purple"),r>=40&&d.addColorStop((r-40)/p,"red"),r>=35&&d.addColorStop((r-35)/p,"orange"),r>=30&&d.addColorStop((r-30)/p,"yellow"),d.addColorStop(r/p,"grey"),i<=-30&&d.addColorStop((r+30)/p,"yellow"),i<=-35&&d.addColorStop((r+35)/p,"orange"),i<=-40&&d.addColorStop((r+40)/p,"red"),i<=-45&&d.addColorStop((r+45)/p,"purple"),s.config.data.datasets[1].backgroundColor=d);var h=document.getElementById(e).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"),s.config.data.datasets[2].backgroundColor=h,s.options.annotation={},s.update(),s.options.annotation={annotations:t.annotations},s.update()}else s.options.scales.xAxes[0].ticks.max=1,s.config.data.datasets[0].data=[],s.config.data.datasets[1].data=[],s.config.data.datasets[2].data=[]},replot:function(){var t=this._compute();t.annotations=[{id:"altmax",type:"line",mode:"horizontal",scaleID:"alt",value:0,borderColor:"rgba(12, 173, 98, 0.5)",borderWidth:1,label:{enabled:!0,position:"left",backgroundColor:"rgba(0,0,0,0.4)",fontSize:10,fontStyle:"normal",yAdjust:10}},{id:"altmin",type:"line",mode:"horizontal",scaleID:"alt",value:0,borderColor:"rgba(12, 173, 98, 0.5)",borderWidth:1,label:{enabled:!0,position:"left",backgroundColor:"rgba(0,0,0,0.4)",fontSize:10,fontStyle:"normal",yAdjust:-10}},{id:"distance",type:"line",mode:"vertical",scaleID:"distance",value:0,borderColor:"rgba(0, 0, 0, 0.5)",borderWidth:1,label:{enabled:!0,position:"left",backgroundColor:"rgba(0,0,0,0.4)",fontSize:10,fontStyle:"normal",xAdjust:-50}}].concat(t.annotations),a?this._replotSmallScreen(t):this._replotWideScreen(t),t.size>0?o.slideUp():o.slideDown()},_initStats:function(){return{distance:0,altMin:Number.MAX_VALUE,altMax:Number.MIN_VALUE,slopeMax:0,slopeMin:0,denivPos:0,denivNeg:0}},_compute:function(){var e=this,n=[],o=[],a=this._initStats(),r=this._initStats();if(t.Track.eachMarker(function(t,i){if("step"==i.getType()){n.push({id:"distance-"+t,type:"line",mode:"vertical",scaleID:"distance",value:a.distance,borderColor:"rgba(0, 0, 0, 0.5)",borderWidth:1});for(var s=i;s&&s.hasRouteToHere()&&(s.getRouteToHere().setPopupContentWith(s._previousMarker.getColorCode(),r),"step"!=(s=s._previousMarker).getType()););r=e._initStats()}var l=i.getRouteFromHere(),u=l?l.getElevations():[];if(u.length>0){for(var c=0;c0)for(var i=t.Track.getLastMarker();i&&i.hasRouteToHere()&&(i.getRouteToHere().setPopupContentWith(i._previousMarker.getColorCode(),r),"step"!=(i=i._previousMarker).getType()););return{size:o.length,elevations:o,total:a,annotations:n}}}}(jQuery),function(t){t.Route={bindTo:function(t){this.map=t},find:function(e,n,o){var a=this;return"straight"==(arguments.length>3&&void 0!==arguments[3]?arguments[3]:"auto")?this._findStraight(e,n,o):t.Deferred(function(){var r=this;a._findAuto(e,n,o).done(r.resolve).progress(r.notify).fail(function(){console.log(this.error),console.log("Trying straight line...");var i=new Drop({target:t(".awesome-marker").eq(o+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é."});i.open(),t(i.content).on("click",function(){i.destroy()}),a._findStraight(e,n,o).done(r.resolve).fail(r.reject)})})},_add:function(e,n,o,a,r){var i=this;return t.Deferred(function(){var a=this;e.prepareForMap(i.map,n,o),e.computeStats().progress(a.notify).then(function(){e.addTo(i.map),e.bindPopup("Calculs en cours..."),e.on("popupopen",function(o){t(".marker-add-button:visible").click(function(){if(!t.State.getComputing()){t.State.setComputing(!0);var a=L.Marker.routed(o.popup.getLatLng().roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:n.getColorIndex(),type:"waypoint"});a.insert(e).progress(t.State.updateComputing).done(function(){a.setOpacity(1),t.State.setComputing(!1)}).fail(function(){t.State.setComputing(!1)})}})}),e.snakeIn(),n.setOpacity(1),o.setOpacity(1),a.resolveWith({route:e})}).fail(function(){a.rejectWith({error:"Impossible d'obtenir les données de la route"})})})},_findAuto:function(e,n,o){var a=this;return t.Deferred(function(){var r=this,i=e.getLatLng(),s=n.getLatLng(),l={distanceUnit:"m",endPoint:{x:s.lng,y:s.lat},exclusions:[],geometryInInstructions:!0,graph:"Pieton",routePreferences:"fastest",startPoint:{x:i.lng,y:i.lat},viaPoints:[],apiKey:keyIgn,onSuccess:function(i){if(i){var s=L.geoJSON([],{color:e.getColorRgb(),weight:5,opacity:.75,snakingPause:0,snakingSpeed:1e3}),l={type:"FeatureCollection",features:[]},u=1;t.each(i.routeInstructions,function(t,e){u++,l.features.push({id:u,type:"Feature",geometry:e.geometry})}),s.addData(l),a._add(s,e,n,o,"auto").progress(r.notify).done(r.resolve).fail(r.reject),r.notify({step:"Route calculée"})}else r.rejectWith({error:"Impossible d'obtenir la route: pas de résultats fournis"})},onFailure:function(t){r.rejectWith({error:"Impossible d'obtenir la route: "+t.message})}};r.notify({start:!0,total:1,status:"Calcul de la route..."}),Gp.Services.route(l)})},_findStraight:function(e,n,o){var a=this;return t.Deferred(function(){var t=this;t.notify({start:!0,total:1,status:"Calcul de la route..."});for(var r=e.getLatLng().roundE8(),i=n.getLatLng().roundE8(),s=r.distanceTo(i),l=r.bearingTo(i),u=[r],c=10;c0&&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)}),t.State.triggerMarkersChanged()},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=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return void 0===this.firstMarker&&(this.firstMarker=e),void 0!==this.lastMarker&&o&&(n=this.lastMarker.computeRouteTo(e,t.State.getMode())),this.lastMarker=e,this.markersLength++,e.addTo(this.map),n||t.Deferred(function(){this.resolve()})},moveMarker:function(e){return t.Deferred(function(){var n=this,o=[];t.State.getMode()||e.getRouteModeFromHere();if(e.hasRouteFromHere()){o.length;o.push(e.recomputeRouteFromHere(t.State.getMode()).progress(n.notify))}if(e.hasRouteToHere()){o.length;o.push(e.recomputeRouteToHere(t.State.getMode()).progress(n.notify))}t.when.apply(t,o).done(n.resolve).fail(n.fail)})},insertMarker:function(e,n){var o=this;return t.Deferred(function(){var a=this,r=[];t.State.getMode()||e.getRouteModeFromHere();r.push(n.getStartMarker().computeRouteTo(e,t.State.getMode()).progress(a.notify)),r.push(e.computeRouteTo(n.getEndMarker(),t.State.getMode()).progress(a.notify)),o.markersLength++,e.addTo(o.map),t.when.apply(t,r).done(a.resolve).fail(a.fail)})},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,a){a.hasRouteFromHere()&&("step"==a.getType()&&(o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n"),t.each(a.getRouteFromHere().getLatLngs(),function(e,n){o+=' ',t.Cache.hasAltitude(n)&&(o+=""+t.Cache.getAltitude(n)+""),o+="\n"}))}),o+=" \n",o+=" \n",o+="\n";var a=new Blob([o],{type:"application/gpx+xml;charset=utf-8"});return saveAs(a,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,a){a.hasRouteFromHere()&&("step"==a.getType()&&(o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n",o+=" 1\n",o+=" \n",o+=" "),t.each(a.getRouteFromHere().getLatLngs(),function(t,e){o+=e.lng+","+e.lat+",0 "}))}),o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+="\n";var a=new Blob([o],{type:"text/plain;charset=utf-8"});return saveAs(a,e+".kml"),!0},_removeMarker:function(t){this.firstMarker===t&&(this.firstMarker=t._nextMarker),this.lastMarker===t&&(this.lastMarker=t._previousMarker),this.markersLength--}},L.Marker.Routed=L.Marker.extend({options:{type:"waypoint",color:0},initialize:function(t,e){L.Marker.prototype.initialize.call(this,t,e),L.setOptions(this,e),this.setType(this.options.type)},getColorCode:function(){return n[this.options.color]},getColorRgb:function(){return e[n[this.options.color]]},getColorIndex:function(){return this.options.color},setColorIndex:function(t){this.options.color=t,this.setType(this.options.type),this.routeFrom&&this.routeFrom.setStyle({color:this.getColorRgb()})},getType:function(){return this.options.type},setType:function(t){this.options.type=t,"waypoint"==t?this.setIcon(L.AwesomeMarkers.icon({icon:"circle",markerColor:this.getColorCode(),prefix:"fa"})):this.setIcon(L.AwesomeMarkers.icon({icon:"asterisk",markerColor:this.getColorCode(),prefix:"fa"}))},promoteToStep:function(){for(var e=t.Track.nextColor(),n=this;n&&"step"!=n.options.type;)n.setColorIndex(e),n=n._nextMarker;this.setType("step"),t.State.triggerMarkersChanged()},demoteToWaypoint:function(){if(this.setType("waypoint"),this.hasRouteToHere())for(var e=this._previousMarker.getColorIndex(),n=this;n&&"step"!=n.options.type;)n.setColorIndex(e),n=n._nextMarker;t.State.triggerMarkersChanged()},hasRouteToHere:function(){return this._previousMarker&&this._previousMarker.hasRouteFromHere()},getRouteToHere:function(){return this._previousMarker.routeFrom},hasRouteFromHere:function(){return!!this.routeFrom},getRouteFromHere:function(){return this.routeFrom},getRouteModeFromHere:function(){return this._mode},deleteRouteFromHere:function(){this._nextMarker&&(this._nextMarker._previousMarker=void 0),this.routeFrom&&this.routeFrom.remove(),this.attachRouteFrom(void 0,null,void 0)},computeRouteTo:function(e,n){var o=this;return t.Deferred(function(){var a=this;o.routeFrom&&o.routeFrom.setStyle({opacity:.5}),t(o).clearCompute(),t(o).startCompute(function(r){n=n||o._mode||"auto",t.Route.find(o,e,0,n).progress(a.notify).done(function(){o.deleteRouteFromHere(),o.attachRouteFrom(e,this.route,n),a.resolve()}).fail(a.reject).always(function(){return t(o).endCompute(r)})})})},recomputeRouteFromHere:function(t){return this.computeRouteTo(this._nextMarker,t)},recomputeRouteToHere:function(t){return this._previousMarker.computeRouteTo(this,t)},attachRouteFrom:function(t,e,n){this._nextMarker=t,t&&(t._previousMarker=this),this.routeFrom=e,this._mode=n},_bindEvents:function(){var e=this;this.bindPopup(' '),this.on("popupopen",function(){t(".marker-delete-button:visible").click(function(){t.State.getComputing()||(t.State.setComputing(!0),e.remove().progress(t.State.updateComputing).done(function(){t.State.setComputing(!1)}).fail(function(){t.State.setComputing(!1)}))}),t(".marker-promote-button:visible").click(function(){t.State.setComputing(!0),e.closePopup(),e.setPopupContent(''),e.promoteToStep(),t.State.setComputing(!1)})}),this.on("moveend",function(n){t.State.setComputing(!0),e.setOpacity(.5),t.Track.moveMarker(e).progress(t.State.updateComputing).done(function(){t.State.setComputing(!1),n.target.setOpacity(1)}).fail(function(){t.State.setComputing(!1)})})},add:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this._bindEvents(),t.Track.addMarker(this,e)},insert:function(e){return this._bindEvents(),t.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,a=this._nextMarker;if(t.Track._removeMarker(this),this.routeFrom&&this.deleteRouteFromHere(),o&&(o.deleteRouteFromHere(),a&&n)){var r=t.State.getMode()||this._mode||"auto";e=o.computeRouteTo(a,r)}return L.Marker.prototype.remove.call(this),e||t.Deferred(function(){this.resolve()})}}),L.Marker.routed=function(t,e){return new L.Marker.Routed(t,e)}}(jQuery);var isSmallScreen=window.innerWidth<=800&&window.innerHeight<=600;$("
Observation des faucons crécerelle...
").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()}),window.onload=function(){$("
Localisation des chamois...
").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()});var t=L.map("map",{});t.initView().done(function(){function e(t){if(null!==$.State.getMode()){var e=L.Marker.routed(t.latlng.roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:$.Track.hasMarkers()?$.Track.getLastMarker().getColorIndex():$.Track.getCurrentColor(),type:"waypoint"});e.add().progress($.State.updateComputing).done(function(){e.setOpacity(1)}),isSmallScreen||($.Track.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(),$.Track.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 t=$.Track.getFirstMarker().getRouteFromHere(),e=t.getLatLngs(),n=e[Math.floor(e.length/2)];t.openPopup(n),this.resolve()}).promise()},text:$("#help-steps2")[0]}).start())}}$("
Suivi des renards roux...
").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()}),isSmallScreen&&$("#mobile-warning").show().find("button").click(function(){popup.hide()}),$.Route.bindTo(t),$.Track.bindTo(t),$("body").on("map2gpx:modechange",function(e){t.doubleClickZoom.setEnabled(null===e.mode)});var n=[],o=L.geoportalLayer.WMTS({layer:"ORTHOIMAGERY.ORTHOPHOTOS",apiKey:keyIgn}).addTo(t);n.push($.Deferred(function(){o.once("load",this.resolve)}));var a=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.SLOPES.MOUNTAIN",apiKey:keyIgn},{opacity:.25}).addTo(t),r=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.MAPS",apiKey:keyIgn},{opacity:.25}).addTo(t);if(n.push($.Deferred(function(){r.once("load",this.resolve)})),L.geoportalControl.SearchEngine({displayAdvancedSearch:!1}).addTo(t),!isSmallScreen){var i=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.MAPS",apiKey:keyIgn});n.push($.Deferred(function(){i.once("load",this.resolve)}));new L.Control.MiniMap(i,{position:"bottomleft",zoomLevelOffset:-4}).addTo(t)}var s=L.geoportalControl.LayerSwitcher({collapsed:isSmallScreen});t.addControl(s),s.setVisibility(a,!1),$(".GPlayerRemove").remove(),isSmallScreen||t.addControl(L.control.scale({imperial:!1,position:"bottomright"}));var l=L.easyButton({id:"btn-autotrace",states:[{stateName:"loaded",icon:"fa-map-signs",title:"Tracer automatiquement l'itinéraire",onClick:function(t,e){$.State.setMode("auto")}},{stateName:"active",icon:"fa-map-signs",title:"Tracer automatiquement l'itinéraire",onClick:function(t,e){$.State.setMode(null)}}]});$("body").on("map2gpx:modechange map2gpx:markerschange",function(t){"auto"==t.mode?(l.state("active"),l.enable()):(l.state("loaded"),l.setEnabled(!$.Track.isImport()))});var u=L.easyButton({id:"btn-straighttrace",states:[{stateName:"loaded",icon:"fa-location-arrow",title:"Tracer l'itinéraire en ligne droite",onClick:function(t,e){$.State.setMode("straight")}},{stateName:"active",icon:"fa-location-arrow",title:"Tracer l'itinéraire en ligne droite",onClick:function(t,e){$.State.setMode(null)}}]});$("body").on("map2gpx:modechange map2gpx:markerschange",function(t){"straight"==t.mode?(u.state("active"),u.enable()):(u.state("loaded"),u.setEnabled(!$.Track.isImport()))});var c=L.easyButton({id:"btn-closeloop",states:[{stateName:"loaded",icon:"fa-magic",title:"Fermer la boucle",onClick:function(t,n){$.Track.hasMarkers(1)&&e({latlng:$.Track.getFirstMarker().getLatLng()})}}]});$("body").on("map2gpx:modechange map2gpx:computingchange map2gpx:markerschange",function(t){c.setEnabled(null!==t.mode&&$.Track.hasRoutes()&&!$.Track.isImport()&&!$.Track.isLoop())}),L.easyBar([l,u,c]).addTo(t);var d=L.popup().setContent(L.DomUtil.get("form-export")),p=L.easyButton({id:"btn-export",states:[{stateName:"loaded",icon:"fa-cloud-download",title:"Exporter",onClick:function(t,e){var n=$.Track.getBounds();e.flyToBounds(n,{padding:[50,50]}),d.setLatLng(n.getCenter()).openOn(e),$(".export-gpx-button:visible").click(function(){var t=$(this);t.attr("disabled","disabled"),$.Track.exportGpx($(".export-filename:visible").val()),t.removeAttr("disabled")}),$(".export-kml-button:visible").click(function(){var t=$(this);t.attr("disabled","disabled"),$.Track.exportKml($(".export-filename:visible").val()),t.removeAttr("disabled")})}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Exporter (calcul en cours...)"}]}).addTo(t);$("body").on("map2gpx:computingchange map2gpx:markerschange",function(t){t.computing?(p.state("computing"),p.disable()):(p.state("loaded"),p.setEnabled($.Track.hasRoutes()))});var h=L.popup().setContent(L.DomUtil.get("form-import")),g=L.easyButton({id:"btn-import",states:[{stateName:"loaded",icon:"fa-cloud-upload",title:"Importer",onClick:function(t,e){h.setLatLng(e.getCenter()).openOn(e),$.Track.hasRoutes()?$(".import-gpx-status:visible").html("Attention: l'import va effacer l'itinéraire existant!"):$(".import-gpx-status:visible").text(""),$(".import-gpx-button:visible").click(function(){var t=$(this),n=$(".import-gpx-file:visible")[0].files[0];if(void 0!=n){t.attr("disabled","disabled"),$.State.setComputing(!0),$.State.updateComputing({start:!0,total:1,status:"Importation en cours..."});var o=new FileReader;o.onload=function(n){var o=[];new L.GPX(n.target.result,{async:!0,onFail:function(){console.log("Failed to retrieve track"),$(".import-gpx-status:visible").text("Impossible de traiter ce fichier"),t.removeAttr("disabled"),$.State.setComputing(!1)},onSuccess:function(n){$.State.updateComputing([{step:"Fichier traité"},{start:!0,total:o.length,status:"Récupération des données géographiques en cours..."}]),$.Track.clear();var a=n.getBounds();e.fitBounds(a,{padding:[50,50]}),h.setLatLng(a.getCenter()),n.addTo(e);var r,i=function(){$(".track-delete-button:visible").click(function(){$.State.setComputing(!0),$.Track.clear(),e.removeLayer(n),$.State.setComputing(!1)})},s=[];$.each(o,function(t,e){if(0==t){var n=e.getLatLngs()[0];r=L.Marker.routed(n,{draggable:!1,opacity:.5,color:$.Track.getCurrentColor(),type:"waypoint"}),$.Track.addMarker(r,!1),r.bindPopup(''),r.on("popupopen",i)}var o=e.getLatLngs()[e.getLatLngs().length-1],a=L.Marker.routed(o,{draggable:!1,opacity:.5,color:$.Track.nextColor(),type:"step"});$.Track.addMarker(a,!1),r.attachRouteFrom(a,e,"import"),e.setStyle({weight:5,color:r.getColorRgb(),opacity:.5}),e.bindPopup("Calculs en cours..."),e.on("popupopen",function(t){$(".marker-add-button:visible").remove()}),a.bindPopup(''),a.on("popupopen",i),s.push(e.computeStats().progress($.State.updateComputing)),r=a}),$.each(s,function(){this.done(function(){return $.State.updateComputing({})})}),$.when.apply($,s).done(function(){$.Track.eachRoute(function(t,e){e.setStyle({opacity:.75})}),$.Track.eachMarker(function(t,e){e.setOpacity(1)}),t.removeAttr("disabled"),h.remove(),$.State.triggerMarkersChanged(),$.State.setMode(null),$.State.setComputing(!1)}).fail(function(){console.log("Fail"),$(".import-gpx-status:visible").text("Impossible de récupérer les données géographiques de ce parcours"),t.removeAttr("disabled"),$.State.setComputing(!1)})}}).on("addline",function(t){o.push(t.line)})},o.readAsText(n)}else $(".import-gpx-status:visible").text("Veuillez sélectionner un fichier")})}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Importer (calcul en cours...)"}]}),m=L.easyButton({id:"btn-reset",states:[{stateName:"loaded",icon:"fa-trash",title:"Effacer l'itinéraire",onClick:function(t,e){$.Track.clear(),$.State.triggerMarkersChanged(),$.State.setComputing(!1)}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Effacer l'itinéraire (calcul en cours...)"}]});if(L.easyBar([g,m]).addTo(t),$("body").on("map2gpx:computingchange",function(t){g.state(t.computing?"computing":"loaded"),m.state(t.computing?"computing":"loaded"),g.setEnabled(!t.computing),m.setEnabled(!t.computing)}),!isSmallScreen){var f=L.popup().setContent(L.DomUtil.get("about")),v=L.easyButton({position:"bottomright",states:[{icon:"fa-info-circle",onClick:function(t,e){f.setLatLng(e.getCenter()).openOn(e)},title:"A propos & crédits"}]}),k=L.easyButton({position:"bottomright",states:[{icon:"fa-question-circle",onClick:function(t,e){$.Shepherd.get(0).start(!0)},title:"Aide"}]});L.easyBar([v,k],{position:"bottomright"}).addTo(t)}t.on("dblclick",e);var M;t.on("zoomend",function(){var e=void 0,n=void 0;(o.options.minZoom>t.getZoom()||o.options.maxZoomt.getZoom()||r.options.maxZoomt.getZoom()||a.options.maxZoomAlignement des satellites...").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()}),$.Chart.init(t,"chart",$("#data"),$("#data-empty"),isSmallScreen),$.State.setMode(null),$.State.triggerMarkersChanged(),$.State.setComputing(!1),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(),$.when.apply($,n).done(function(){clearInterval(interval),$("#loading").fadeOut()})})}; \ 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,a={tilematrix:16,tilerow:e,tilecol:t,lon:"",lat:"",x:"",y:""};$.each(n,function(t,e){t>0&&(a.lon+="|",a.lat+="|",a.x+="|",a.y+="|"),a.lon+=e.lng.toString(),a.lat+=e.lat.toString(),a.x+=e.x.toString(),a.y+=e.y.toString()}),$.getJSON("slope.php",a,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 r=e.indexOf(this);null!==t.localStorage.get("tutorial"+r)&&(a=parseInt(t.localStorage.get("tutorial"+r)))}return a>=0&&at}}(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 a=t.latLngToPoint(this,e).floor(),r=a.divideBy(n).floor(),i=r.multiplyBy(n).subtract(o);return{tile:r,tilePixel:a.subtract(o).subtract(i)}},L.LatLng.prototype.getDestinationAlong=function(t,e){var n=6378137,o=Math.radians(t),a=Math.radians(this.lat),r=Math.radians(this.lng),i=Math.asin(Math.sin(a)*Math.cos(e/n)+Math.cos(a)*Math.sin(e/n)*Math.cos(o)),s=r+Math.atan2(Math.sin(o)*Math.sin(e/n)*Math.cos(a),Math.cos(e/n)-Math.sin(a)*Math.sin(i));return i=Math.degrees(i),s=Math.degrees(s),L.latLng(Math.roundE8(i),Math.roundE8(s))},L.LatLng.prototype.bearingTo=function(t){var e=Math.radians(this.lat),n=Math.radians(this.lng),o=Math.radians(t.lat),a=Math.radians(t.lng),r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),i=a-n;return Math.abs(i)>Math.PI&&(i=i>0?-(2*Math.PI-i):2*Math.PI+i),(Math.degrees(Math.atan2(i,r))+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()}}),function(t){var e=0;t.fn.clearCompute=function(){return this.each(function(){e-=t(this).queue().length,t(this).clearQueue()})},t.fn.startCompute=function(n){return this.each(function(){t.State.setComputing(!0),e++,t(this).queue(n)})},t.fn.endCompute=function(n){return this.each(function(){e--,n(),0==e&&t.State.setComputing(!1)})},t.Queue={size:function(){return e}}}(jQuery),function(t){var e=null,n=!1,o=0,a=0,r=t("#data-computing h2"),i=t("#data-computing-progress"),s=t("#data-computing-progressbar"),l=t("#data-computing-status");t("#data-computing-pending");t.State={},t.State.setMode=function(o){e=o,t("body").trigger(t.Event("map2gpx:modechange",{mode:e,computing:n}))},t.State.setComputing=function(r){r&&!n&&(o=0,a=0),n=r,t("body").trigger(t.Event("map2gpx:computingchange",{mode:e,computing:n}))},t.State.updateComputing=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(Array.isArray(e))return t.each(e,function(){t.State.updateComputing(this,!1)}),void t.State.displayComputing();e.start?a+=e.total:e.end?o=a:o++,"status"in e&&e.status&&l.text(e.status),"step"in e&&e.step&&t("
"+e.step+"
").insertAfter(r).fadeOut(400,function(){t(this).remove()}),n&&t.State.displayComputing()},t.State.displayComputing=function(){var e=1;a>0&&(e=o/a),i.text(Math.round(100*e)+"%"),s.css("width",Math.round(100*e)+"%"),42==Math.round(100*e)&&t("
La grande question sur la vie, l'univers et le reste répondue
").insertAfter(r).fadeOut(400,function(){t(this).remove()})},t.State.triggerMarkersChanged=function(){t("body").trigger(t.Event("map2gpx:markerschange",{mode:e,computing:n}))},t.State.getMode=function(){return e},t.State.getComputing=function(){return n}}(jQuery),function(t){var e={},n={};t.Cache={};var o=function(t){return t.lng+"/"+t.lat};t.Cache.addAltitude=function(t,n,o){e[n+"/"+t]=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[e+"/"+t]=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 a=o(t);return{z:a in e?e[a]:null,slope:a in n?n[a]:null}},t.Cache.lengthOfMarkers=function(){return t.Track.lengthOfMarkers()},t.Cache.hasMarkers=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return t.Track.hasMarkers(e)},t.Cache.getMarker=function(t){},t.Cache.indexOfMarker=function(t){},t.Cache.eachMarker=function(t){},t.Cache.addMarker=function(t){},t.Cache.removeMarkerAt=function(t){},t.Cache.resetMarkers=function(){},t.Cache.lengthOfRoutes=function(){},t.Cache.hasRoutes=function(t){},t.Cache.getRoute=function(t){},t.Cache.getRouteMode=function(t){},t.Cache.eachRoute=function(t){},t.Cache.addRoute=function(t,e){},t.Cache.setRouteAt=function(t,e,n){},t.Cache.removeRouteAt=function(t){},t.Cache.resetRoutes=function(){}}(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("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.getLatLngs(),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;n10&&(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.getLatLngs(),function(e,o){if(!$.Cache.hasSlope(o)){var a=o.toTilePixel(n.options.crs,16,256,n.getPixelOrigin()),r=a.tile,i=a.tilePixel;r.x in t||(t[r.x]={}),r.y in t[r.x]||(t[r.x][r.y]=[[]]),t[r.x][r.y][t[r.x][r.y].length-1].length>50&&t[r.x][r.y].push([]),t[r.x][r.y][t[r.x][r.y].length-1].push({lat:o.lat,lng:o.lng,x:i.x,y:i.y})}}),$.each(t,function(t,n){$.each(n,function(n,o){$.each(o,function(o,a){e.push(fetchSlope(t,n,a))})})}),e},setPopupContentWith:function(t,e){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
')}}),L.GeoJSON.include({getLatLngs:function(){var t=[];return this.eachLayer(function(e){$.each(e.feature.geometry.coordinates,function(e,n){t.push(L.latLng(n[1],n[0]))})}),t}}),function(t){var e,n,o,a,r=null,i={icon:L.AwesomeMarkers.icon({icon:"area-chart",markerColor:"cadetblue",prefix:"fa"}),draggable:!1,clickable:!1,zIndexOffset:1e3},s=null;t.Chart={init:function(l,u,c,d,p){e=u,n=c,o=d,(a=p)?t("#"+u).remove():s=new Chart(t("#"+u),{type:"line",data:{datasets:[{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"},{label:"Pente de l'itinéraire",data:[],fill:!0,pointRadius:0,yAxisID:"slope"},{label:"Pente du terrain",data:[],fill:!0,pointRadius:0,yAxisID:"slope2",hidden:!0}]},options:{maintainAspectRatio:!1,onClick:function(t,e){if(e&&e.length>0){var n=e[0]._index,o=s.config.data.datasets[0].data[n];o.route&&o.route.openPopup(L.latLng(o.lat,o.lng))}},hover:{mode:"index",intersect:!1,onHover:function(t,e){if("mousemove"==t.type)if(e&&e.length>0){var n=e[0]._index,o=s.config.data.datasets[0].data[n];null==r?(r=L.marker(L.latLng(o.lat,o.lng),i)).addTo(l):(r.setLatLng(L.latLng(o.lat,o.lng)),r.update())}else r&&(l.removeLayer(r),r=null);else"mouseout"==t.type&&r&&(l.removeLayer(r),r=null)}},scales:{xAxes:[{id:"distance",type:"linear",position:"bottom",ticks:{min:0}}],yAxes:[{id:"alt",type:"linear",position:"left",beginAtZero:!1},{id:"slope",type:"linear",position:"right"},{id:"slope2",type:"linear",position:"right",ticks:{min:0,max:45}}]},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:[]}}})},_replotSmallScreen:function(t){t.size>0?n.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
"):n.empty()},_replotWideScreen:function(t){if(t.size>0){for(var n=[],o=[],a=[],r=0,i=0,l=0;l3&&lr&&(r=u),u=45&&d.addColorStop((r-45)/p,"purple"),r>=40&&d.addColorStop((r-40)/p,"red"),r>=35&&d.addColorStop((r-35)/p,"orange"),r>=30&&d.addColorStop((r-30)/p,"yellow"),d.addColorStop(r/p,"grey"),i<=-30&&d.addColorStop((r+30)/p,"yellow"),i<=-35&&d.addColorStop((r+35)/p,"orange"),i<=-40&&d.addColorStop((r+40)/p,"red"),i<=-45&&d.addColorStop((r+45)/p,"purple"),s.config.data.datasets[1].backgroundColor=d);var h=document.getElementById(e).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"),s.config.data.datasets[2].backgroundColor=h,s.options.annotation={},s.update(),s.options.annotation={annotations:t.annotations},s.update()}else s.options.scales.xAxes[0].ticks.max=1,s.config.data.datasets[0].data=[],s.config.data.datasets[1].data=[],s.config.data.datasets[2].data=[]},replot:function(){var t=this._compute();t.annotations=[{id:"altmax",type:"line",mode:"horizontal",scaleID:"alt",value:0,borderColor:"rgba(12, 173, 98, 0.5)",borderWidth:1,label:{enabled:!0,position:"left",backgroundColor:"rgba(0,0,0,0.4)",fontSize:10,fontStyle:"normal",yAdjust:10}},{id:"altmin",type:"line",mode:"horizontal",scaleID:"alt",value:0,borderColor:"rgba(12, 173, 98, 0.5)",borderWidth:1,label:{enabled:!0,position:"left",backgroundColor:"rgba(0,0,0,0.4)",fontSize:10,fontStyle:"normal",yAdjust:-10}},{id:"distance",type:"line",mode:"vertical",scaleID:"distance",value:0,borderColor:"rgba(0, 0, 0, 0.5)",borderWidth:1,label:{enabled:!0,position:"left",backgroundColor:"rgba(0,0,0,0.4)",fontSize:10,fontStyle:"normal",xAdjust:-50}}].concat(t.annotations),a?this._replotSmallScreen(t):this._replotWideScreen(t),t.size>0?o.slideUp():o.slideDown()},_initStats:function(){return{distance:0,altMin:Number.MAX_VALUE,altMax:Number.MIN_VALUE,slopeMax:0,slopeMin:0,denivPos:0,denivNeg:0}},_compute:function(){var e=this,n=[],o=[],a=this._initStats(),r=this._initStats();if(t.Track.eachMarker(function(t,i){if("step"==i.getType()){n.push({id:"distance-"+t,type:"line",mode:"vertical",scaleID:"distance",value:a.distance,borderColor:"rgba(0, 0, 0, 0.5)",borderWidth:1});for(var s=i;s&&s.hasRouteToHere()&&(s.getRouteToHere().setPopupContentWith(s._previousMarker.getColorCode(),r),"step"!=(s=s._previousMarker).getType()););r=e._initStats()}var l=i.getRouteFromHere(),u=l?l.getElevations():[];if(u.length>0){for(var c=0;c0)for(var i=t.Track.getLastMarker();i&&i.hasRouteToHere()&&(i.getRouteToHere().setPopupContentWith(i._previousMarker.getColorCode(),r),"step"!=(i=i._previousMarker).getType()););return{size:o.length,elevations:o,total:a,annotations:n}}}}(jQuery),function(t){t.Route={bindTo:function(t){this.map=t},find:function(e,n,o){var a=this;return"straight"==(arguments.length>3&&void 0!==arguments[3]?arguments[3]:"auto")?this._findStraight(e,n,o):t.Deferred(function(){var r=this;a._findAuto(e,n,o).done(r.resolve).progress(r.notify).fail(function(){console.log(this.error),console.log("Trying straight line...");var i=new Drop({target:t(".awesome-marker").eq(o+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é."});i.open(),t(i.content).on("click",function(){i.destroy()}),a._findStraight(e,n,o).done(r.resolve).fail(r.reject)})})},_add:function(e,n,o,a,r){var i=this;return t.Deferred(function(){var a=this;e.prepareForMap(i.map,n,o),e.computeStats().progress(a.notify).then(function(){e.addTo(i.map),e.bindPopup("Calculs en cours..."),e.on("popupopen",function(o){t(".marker-add-button:visible").click(function(){if(!t.State.getComputing()){t.State.setComputing(!0);var a=L.Marker.routed(o.popup.getLatLng().roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:n.getColorIndex(),type:"waypoint"});a.insert(e).progress(t.State.updateComputing).done(function(){a.setOpacity(1),t.State.setComputing(!1)}).fail(function(){t.State.setComputing(!1)})}})}),e.snakeIn(),n.setOpacity(1),o.setOpacity(1),a.resolveWith({route:e})}).fail(function(){a.rejectWith({error:"Impossible d'obtenir les données de la route"})})})},_findAuto:function(e,n,o){var a=this;return t.Deferred(function(){var r=this,i=e.getLatLng(),s=n.getLatLng(),l={distanceUnit:"m",endPoint:{x:s.lng,y:s.lat},exclusions:[],geometryInInstructions:!0,graph:"Pieton",routePreferences:"fastest",startPoint:{x:i.lng,y:i.lat},viaPoints:[],apiKey:keyIgn,onSuccess:function(i){if(i){var s=L.geoJSON([],{color:e.getColorRgb(),weight:5,opacity:.75,snakingPause:0,snakingSpeed:1e3}),l={type:"FeatureCollection",features:[]},u=1;t.each(i.routeInstructions,function(t,e){u++,l.features.push({id:u,type:"Feature",geometry:e.geometry})}),s.addData(l),a._add(s,e,n,o,"auto").progress(r.notify).done(r.resolve).fail(r.reject),r.notify({step:"Route calculée"})}else r.rejectWith({error:"Impossible d'obtenir la route: pas de résultats fournis"})},onFailure:function(t){r.rejectWith({error:"Impossible d'obtenir la route: "+t.message})}};r.notify({start:!0,total:1,status:"Calcul de la route..."}),Gp.Services.route(l)})},_findStraight:function(e,n,o){var a=this;return t.Deferred(function(){var t=this;t.notify({start:!0,total:1,status:"Calcul de la route..."});for(var r=e.getLatLng().roundE8(),i=n.getLatLng().roundE8(),s=r.distanceTo(i),l=r.bearingTo(i),u=[r],c=10;c0&&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)}),t.State.triggerMarkersChanged()},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=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return void 0===this.firstMarker&&(this.firstMarker=e),void 0!==this.lastMarker&&o&&(n=this.lastMarker.computeRouteTo(e,t.State.getMode())),this.lastMarker=e,this.markersLength++,e.addTo(this.map),n||t.Deferred(function(){this.resolve()})},moveMarker:function(e){return t.Deferred(function(){var n=this,o=[];t.State.getMode()||e.getRouteModeFromHere();if(e.hasRouteFromHere()){o.length;o.push(e.recomputeRouteFromHere(t.State.getMode()).progress(n.notify))}if(e.hasRouteToHere()){o.length;o.push(e.recomputeRouteToHere(t.State.getMode()).progress(n.notify))}t.when.apply(t,o).done(n.resolve).fail(n.fail)})},insertMarker:function(e,n){var o=this;return t.Deferred(function(){var a=this,r=[];t.State.getMode()||e.getRouteModeFromHere();r.push(n.getStartMarker().computeRouteTo(e,t.State.getMode()).progress(a.notify)),r.push(e.computeRouteTo(n.getEndMarker(),t.State.getMode()).progress(a.notify)),o.markersLength++,e.addTo(o.map),t.when.apply(t,r).done(a.resolve).fail(a.fail)})},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,a){a.hasRouteFromHere()&&("step"==a.getType()&&(o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n"),t.each(a.getRouteFromHere().getLatLngs(),function(e,n){o+=' ',t.Cache.hasAltitude(n)&&(o+=""+t.Cache.getAltitude(n)+""),o+="\n"}))}),o+=" \n",o+=" \n",o+="\n";var a=new Blob([o],{type:"application/gpx+xml;charset=utf-8"});return saveAs(a,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,a){a.hasRouteFromHere()&&("step"==a.getType()&&(o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+=" "+e+"-"+n+"\n",o+=" \n",o+=" 1\n",o+=" \n",o+=" "),t.each(a.getRouteFromHere().getLatLngs(),function(t,e){o+=e.lng+","+e.lat+",0 "}))}),o+="\n \n",o+=" \n",o+=" \n",o+=" \n",o+="\n";var a=new Blob([o],{type:"text/plain;charset=utf-8"});return saveAs(a,e+".kml"),!0},_removeMarker:function(t){this.firstMarker===t&&(this.firstMarker=t._nextMarker),this.lastMarker===t&&(this.lastMarker=t._previousMarker),this.markersLength--}},L.Marker.Routed=L.Marker.extend({options:{type:"waypoint",color:0},initialize:function(t,e){L.Marker.prototype.initialize.call(this,t,e),L.setOptions(this,e),this.setType(this.options.type)},getColorCode:function(){return n[this.options.color]},getColorRgb:function(){return e[n[this.options.color]]},getColorIndex:function(){return this.options.color},setColorIndex:function(t){this.options.color=t,this.setType(this.options.type),this.routeFrom&&this.routeFrom.setStyle({color:this.getColorRgb()})},getType:function(){return this.options.type},setType:function(t){this.options.type=t,"waypoint"==t?this.setIcon(L.AwesomeMarkers.icon({icon:"circle",markerColor:this.getColorCode(),prefix:"fa"})):this.setIcon(L.AwesomeMarkers.icon({icon:"asterisk",markerColor:this.getColorCode(),prefix:"fa"}))},promoteToStep:function(){for(var e=t.Track.nextColor(),n=this;n&&"step"!=n.options.type;)n.setColorIndex(e),n=n._nextMarker;this.setType("step"),t.State.triggerMarkersChanged()},demoteToWaypoint:function(){if(this.setType("waypoint"),this.hasRouteToHere())for(var e=this._previousMarker.getColorIndex(),n=this;n&&"step"!=n.options.type;)n.setColorIndex(e),n=n._nextMarker;t.State.triggerMarkersChanged()},hasRouteToHere:function(){return this._previousMarker&&this._previousMarker.hasRouteFromHere()},getRouteToHere:function(){return this._previousMarker.routeFrom},hasRouteFromHere:function(){return!!this.routeFrom},getRouteFromHere:function(){return this.routeFrom},getRouteModeFromHere:function(){return this._mode},deleteRouteFromHere:function(){this._nextMarker&&(this._nextMarker._previousMarker=void 0),this.routeFrom&&this.routeFrom.remove(),this.attachRouteFrom(void 0,null,void 0)},computeRouteTo:function(e,n){var o=this;return t.Deferred(function(){var a=this;o.routeFrom&&o.routeFrom.setStyle({opacity:.5}),t(o).clearCompute(),t(o).startCompute(function(r){n=n||o._mode||"auto",t.Route.find(o,e,0,n).progress(a.notify).done(function(){o.deleteRouteFromHere(),o.attachRouteFrom(e,this.route,n),a.resolve()}).fail(a.reject).always(function(){return t(o).endCompute(r)})})})},recomputeRouteFromHere:function(t){return this.computeRouteTo(this._nextMarker,t)},recomputeRouteToHere:function(t){return this._previousMarker.computeRouteTo(this,t)},attachRouteFrom:function(t,e,n){this._nextMarker=t,t&&(t._previousMarker=this),this.routeFrom=e,this._mode=n},_bindEvents:function(){var e=this;this.bindPopup(' '),this.on("popupopen",function(){t(".marker-delete-button:visible").click(function(){t.State.getComputing()||(t.State.setComputing(!0),e.remove().progress(t.State.updateComputing).done(function(){t.State.setComputing(!1)}).fail(function(){t.State.setComputing(!1)}))}),t(".marker-promote-button:visible").click(function(){t.State.setComputing(!0),e.closePopup(),e.setPopupContent(''),e.promoteToStep(),t.State.setComputing(!1)})}),this.on("moveend",function(n){t.State.setComputing(!0),e.setOpacity(.5),t.Track.moveMarker(e).progress(t.State.updateComputing).done(function(){t.State.setComputing(!1),n.target.setOpacity(1)}).fail(function(){t.State.setComputing(!1)})})},add:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this._bindEvents(),t.Track.addMarker(this,e)},insert:function(e){return this._bindEvents(),t.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,a=this._nextMarker;if(t.Track._removeMarker(this),this.routeFrom&&this.deleteRouteFromHere(),o&&(o.deleteRouteFromHere(),a&&n)){var r=t.State.getMode()||this._mode||"auto";e=o.computeRouteTo(a,r)}return L.Marker.prototype.remove.call(this),e||t.Deferred(function(){this.resolve()})}}),L.Marker.routed=function(t,e){return new L.Marker.Routed(t,e)}}(jQuery);var isSmallScreen=window.innerWidth<=800&&window.innerHeight<=600;$("
Observation des faucons crécerelle...
").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()}),window.onload=function(){$("
Localisation des chamois...
").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()});var t=L.map("map",{});t.initView().done(function(){function e(t){if(null!==$.State.getMode()){var e=L.Marker.routed(t.latlng.roundE8(),{riseOnHover:!0,draggable:!0,opacity:.5,color:$.Track.hasMarkers()?$.Track.getLastMarker().getColorIndex():$.Track.getCurrentColor(),type:"waypoint"});$.Track.hasMarkers()&&$.Track.getLastMarker().getLatLng().equals(e.getLatLng())||(e.add().progress($.State.updateComputing).done(function(){e.setOpacity(1)}),isSmallScreen||($.Track.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(),$.Track.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 t=$.Track.getFirstMarker().getRouteFromHere(),e=t.getLatLngs(),n=e[Math.floor(e.length/2)];t.openPopup(n),this.resolve()}).promise()},text:$("#help-steps2")[0]}).start()))}}$("
Suivi des renards roux...
").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()}),isSmallScreen&&$("#mobile-warning").show().find("button").click(function(){popup.hide()}),$.Route.bindTo(t),$.Track.bindTo(t),$("body").on("map2gpx:modechange",function(e){t.doubleClickZoom.setEnabled(null===e.mode)});var n=[],o=L.geoportalLayer.WMTS({layer:"ORTHOIMAGERY.ORTHOPHOTOS",apiKey:keyIgn}).addTo(t);n.push($.Deferred(function(){o.once("load",this.resolve)}));var a=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.SLOPES.MOUNTAIN",apiKey:keyIgn},{opacity:.25}).addTo(t),r=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.MAPS",apiKey:keyIgn},{opacity:.25}).addTo(t);if(n.push($.Deferred(function(){r.once("load",this.resolve)})),L.geoportalControl.SearchEngine({displayAdvancedSearch:!1}).addTo(t),!isSmallScreen){var i=L.geoportalLayer.WMTS({layer:"GEOGRAPHICALGRIDSYSTEMS.MAPS",apiKey:keyIgn});n.push($.Deferred(function(){i.once("load",this.resolve)}));new L.Control.MiniMap(i,{position:"bottomleft",zoomLevelOffset:-4}).addTo(t)}var s=L.geoportalControl.LayerSwitcher({collapsed:isSmallScreen});t.addControl(s),s.setVisibility(a,!1),$(".GPlayerRemove").remove(),isSmallScreen||t.addControl(L.control.scale({imperial:!1,position:"bottomright"}));var l=L.easyButton({id:"btn-autotrace",states:[{stateName:"loaded",icon:"fa-map-signs",title:"Tracer automatiquement l'itinéraire",onClick:function(t,e){$.State.setMode("auto")}},{stateName:"active",icon:"fa-map-signs",title:"Tracer automatiquement l'itinéraire",onClick:function(t,e){$.State.setMode(null)}}]});$("body").on("map2gpx:modechange map2gpx:markerschange",function(t){"auto"==t.mode?(l.state("active"),l.enable()):(l.state("loaded"),l.setEnabled(!$.Track.isImport()))});var u=L.easyButton({id:"btn-straighttrace",states:[{stateName:"loaded",icon:"fa-location-arrow",title:"Tracer l'itinéraire en ligne droite",onClick:function(t,e){$.State.setMode("straight")}},{stateName:"active",icon:"fa-location-arrow",title:"Tracer l'itinéraire en ligne droite",onClick:function(t,e){$.State.setMode(null)}}]});$("body").on("map2gpx:modechange map2gpx:markerschange",function(t){"straight"==t.mode?(u.state("active"),u.enable()):(u.state("loaded"),u.setEnabled(!$.Track.isImport()))});var c=L.easyButton({id:"btn-closeloop",states:[{stateName:"loaded",icon:"fa-magic",title:"Fermer la boucle",onClick:function(t,n){$.Track.hasMarkers(1)&&e({latlng:$.Track.getFirstMarker().getLatLng()})}}]});$("body").on("map2gpx:modechange map2gpx:computingchange map2gpx:markerschange",function(t){c.setEnabled(null!==t.mode&&$.Track.hasRoutes()&&!$.Track.isImport()&&!$.Track.isLoop())}),L.easyBar([l,u,c]).addTo(t);var d=L.popup().setContent(L.DomUtil.get("form-export")),p=L.easyButton({id:"btn-export",states:[{stateName:"loaded",icon:"fa-cloud-download",title:"Exporter",onClick:function(t,e){var n=$.Track.getBounds();e.flyToBounds(n,{padding:[50,50]}),d.setLatLng(n.getCenter()).openOn(e),$(".export-gpx-button:visible").click(function(){var t=$(this);t.attr("disabled","disabled"),$.Track.exportGpx($(".export-filename:visible").val()),t.removeAttr("disabled")}),$(".export-kml-button:visible").click(function(){var t=$(this);t.attr("disabled","disabled"),$.Track.exportKml($(".export-filename:visible").val()),t.removeAttr("disabled")})}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Exporter (calcul en cours...)"}]}).addTo(t);$("body").on("map2gpx:computingchange map2gpx:markerschange",function(t){t.computing?(p.state("computing"),p.disable()):(p.state("loaded"),p.setEnabled($.Track.hasRoutes()))});var h=L.popup().setContent(L.DomUtil.get("form-import")),g=L.easyButton({id:"btn-import",states:[{stateName:"loaded",icon:"fa-cloud-upload",title:"Importer",onClick:function(t,e){h.setLatLng(e.getCenter()).openOn(e),$.Track.hasRoutes()?$(".import-gpx-status:visible").html("Attention: l'import va effacer l'itinéraire existant!"):$(".import-gpx-status:visible").text(""),$(".import-gpx-button:visible").click(function(){var t=$(this),n=$(".import-gpx-file:visible")[0].files[0];if(void 0!=n){t.attr("disabled","disabled"),$.State.setComputing(!0),$.State.updateComputing({start:!0,total:1,status:"Importation en cours..."});var o=new FileReader;o.onload=function(n){var o=[];new L.GPX(n.target.result,{async:!0,onFail:function(){console.log("Failed to retrieve track"),$(".import-gpx-status:visible").text("Impossible de traiter ce fichier"),t.removeAttr("disabled"),$.State.setComputing(!1)},onSuccess:function(n){$.State.updateComputing([{step:"Fichier traité"},{start:!0,total:o.length,status:"Récupération des données géographiques en cours..."}]),$.Track.clear();var a=n.getBounds();e.fitBounds(a,{padding:[50,50]}),h.setLatLng(a.getCenter()),n.addTo(e);var r,i=function(){$(".track-delete-button:visible").click(function(){$.State.setComputing(!0),$.Track.clear(),e.removeLayer(n),$.State.setComputing(!1)})},s=[];$.each(o,function(t,e){if(0==t){var n=e.getLatLngs()[0];r=L.Marker.routed(n,{draggable:!1,opacity:.5,color:$.Track.getCurrentColor(),type:"waypoint"}),$.Track.addMarker(r,!1),r.bindPopup(''),r.on("popupopen",i)}var o=e.getLatLngs()[e.getLatLngs().length-1],a=L.Marker.routed(o,{draggable:!1,opacity:.5,color:$.Track.nextColor(),type:"step"});$.Track.addMarker(a,!1),r.attachRouteFrom(a,e,"import"),e.setStyle({weight:5,color:r.getColorRgb(),opacity:.5}),e.bindPopup("Calculs en cours..."),e.on("popupopen",function(t){$(".marker-add-button:visible").remove()}),a.bindPopup(''),a.on("popupopen",i),s.push(e.computeStats().progress($.State.updateComputing)),r=a}),$.each(s,function(){this.done(function(){return $.State.updateComputing({})})}),$.when.apply($,s).done(function(){$.Track.eachRoute(function(t,e){e.setStyle({opacity:.75})}),$.Track.eachMarker(function(t,e){e.setOpacity(1)}),t.removeAttr("disabled"),h.remove(),$.State.triggerMarkersChanged(),$.State.setMode(null),$.State.setComputing(!1)}).fail(function(){console.log("Fail"),$(".import-gpx-status:visible").text("Impossible de récupérer les données géographiques de ce parcours"),t.removeAttr("disabled"),$.State.setComputing(!1)})}}).on("addline",function(t){o.push(t.line)})},o.readAsText(n)}else $(".import-gpx-status:visible").text("Veuillez sélectionner un fichier")})}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Importer (calcul en cours...)"}]}),m=L.easyButton({id:"btn-reset",states:[{stateName:"loaded",icon:"fa-trash",title:"Effacer l'itinéraire",onClick:function(t,e){$.Track.clear(),$.State.triggerMarkersChanged(),$.State.setComputing(!1)}},{stateName:"computing",icon:"fa-spinner fa-pulse",title:"Effacer l'itinéraire (calcul en cours...)"}]});if(L.easyBar([g,m]).addTo(t),$("body").on("map2gpx:computingchange",function(t){g.state(t.computing?"computing":"loaded"),m.state(t.computing?"computing":"loaded"),g.setEnabled(!t.computing),m.setEnabled(!t.computing)}),!isSmallScreen){var f=L.popup().setContent(L.DomUtil.get("about")),v=L.easyButton({position:"bottomright",states:[{icon:"fa-info-circle",onClick:function(t,e){f.setLatLng(e.getCenter()).openOn(e)},title:"A propos & crédits"}]}),k=L.easyButton({position:"bottomright",states:[{icon:"fa-question-circle",onClick:function(t,e){$.Shepherd.get(0).start(!0)},title:"Aide"}]});L.easyBar([v,k],{position:"bottomright"}).addTo(t)}t.on("dblclick",e);var M;t.on("zoomend",function(){var e=void 0,n=void 0;(o.options.minZoom>t.getZoom()||o.options.maxZoomt.getZoom()||r.options.maxZoomt.getZoom()||a.options.maxZoomAlignement des satellites...").insertAfter($("#loading h2")).fadeOut(2e3,function(){$(this).remove()}),$.Chart.init(t,"chart",$("#data"),$("#data-empty"),isSmallScreen),$.State.setMode(null),$.State.triggerMarkersChanged(),$.State.setComputing(!1),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(),$.when.apply($,n).done(function(){clearInterval(interval),$("#loading").fadeOut()})})}; \ No newline at end of file diff --git a/js/map2gpx.src.js b/js/map2gpx.src.js index 2e40a19..4de6dff 100644 --- a/js/map2gpx.src.js +++ b/js/map2gpx.src.js @@ -2467,6 +2467,10 @@ window.onload = function () { type: 'waypoint', }); + // Ignore this marker if same as previous + if ($.Track.hasMarkers() && $.Track.getLastMarker().getLatLng().equals(marker.getLatLng())) + return; + marker.add().progress($.State.updateComputing).done(function () { marker.setOpacity(1); }); diff --git a/src/js/script.js b/src/js/script.js index cf293f5..94297f2 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -487,6 +487,10 @@ window.onload = function () { type: 'waypoint', }); + // Ignore this marker if same as previous + if ($.Track.hasMarkers() && $.Track.getLastMarker().getLatLng().equals(marker.getLatLng())) + return; + marker.add().progress($.State.updateComputing).done(function () { marker.setOpacity(1); });