@raruto/leaflet-elevation 2.2.5 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -674
- package/dist/leaflet-elevation.css +337 -337
- package/dist/leaflet-elevation.js +281 -280
- package/dist/leaflet-elevation.js.map +1 -1
- package/dist/leaflet-elevation.min.js +1 -1
- package/dist/leaflet-elevation.min.js.map +1 -1
- package/images/elevation-position.svg +1 -1
- package/images/elevation-pushpin.svg +1 -1
- package/images/elevation.svg +1 -1
- package/libs/leaflet-distance-marker.css +8 -8
- package/libs/leaflet-distance-marker.js +314 -314
- package/package.json +71 -71
- package/src/components/chart.js +783 -783
- package/src/components/d3.js +641 -641
- package/src/components/marker.js +96 -96
- package/src/components/summary.js +43 -43
- package/src/control.js +3 -2
- package/src/handlers/acceleration.js +64 -64
- package/src/handlers/heart.js +52 -52
- package/src/handlers/pace.js +65 -65
- package/src/handlers/slope.js +79 -79
- package/src/handlers/speed.js +66 -66
- package/src/handlers/time.js +102 -102
- package/src/index.css +329 -329
- package/src/index.js +42 -42
- package/src/options.js +85 -85
- package/src/utils.js +158 -158
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t){"function"==typeof define&&define.amd?define(t):t()}((function(){"use strict";const t={lightblue:{area:"#3366CC",alpha:.45,stroke:"#3366CC"},magenta:{area:"#FF005E"},yellow:{area:"#FF0"},purple:{area:"#732C7B"},steelblue:{area:"#4682B4"},red:{area:"#F00"},lime:{area:"#9CC222",line:"#566B13"}},e=6e4,i=60*e,a=24*i;function o(t,e){let i=p("a","",{href:t,target:"_new",download:e||"",style:"display:none;"}),a=document.body;a.appendChild(i),i.click(),a.removeChild(i)}function s(t,e,i){return t&&(({props:a,point:o,id:s,isMulti:r})=>{if(a)for(const h of t)if(h in a){o.meta[e]=(i||n).call(this,r?a[h][r]:a[h],s);break}})}const n=(t,e)=>parseInt("object"==typeof t?t[e]:t),r=(t,e)=>t&&e.split(" ").every((e=>e&&L.DomUtil.addClass(t,e))),h=(t,e)=>t&&e.split(" ").every((e=>e&&L.DomUtil.removeClass(t,e))),l=(t,e,i)=>(i?r:h)(t,e),d=(t,e,i)=>e&&h(t,e)||i&&r(t,i),c=(t,e,i)=>void 0===i&&L.DomUtil.getStyle(t,e)||t.style.setProperty(e,i),_=(t,e)=>{for(let i in e)t.setAttribute(i,e[i])},m=(t,e,i,a)=>t[a?"on":"off"](e,i),p=(t,e,i,a)=>{let o=L.DomUtil.create(t,e||"");return i&&_(o,i),a&&u(a,o),o},u=(t,e)=>t.appendChild(e),f=(t,e,i)=>t.insertAdjacentElement(i,e),g=(t,e)=>(e||document).querySelector(t),y=(t,e)=>{for(let i in t)e(t[i],i)},k=()=>Math.random().toString(36).substr(2,9),{on:v,off:M}=L.DomEvent,{throttle:w,wrapNum:S}=L.Util,{hasClass:C}=L.DomUtil,b=L.Util.formatNum,x=(t,e)=>e?t<e[0]?e[0]:t>e[1]?e[1]:t:t,D=(t,e,i)=>Math.abs(t-e)>i?e+i*Math.sign(t-e):t;var E=Object.freeze({__proto__:null,Colors:t,formatTime:function(t){let o=Math.floor(t/a),s=Math.floor((t-o*a)/i),n=Math.floor((t-o*a-s*i)/e),r=Math.round((t-o*a-s*i-n*e)/1e3);return 60===r&&(n++,r=0),60===n&&(s++,n=0),24===s&&(o++,s=0),(o?o+"d ":"")+s.toString().padStart(2,0)+":"+n.toString().padStart(2,0)+"'"+r.toString().padStart(2,0)+'"'},formatDate:function(t){return t?"time"==t?t=>new Date(t).toLocaleTimeString():"date"==t?t=>new Date(t).toLocaleDateString():e=>t(e):t=>new Date(t).toLocaleString().replaceAll("/","-").replaceAll(","," ")},saveFile:o,drawCanvas:function(t,e){e.classed("canvas-path",!0),t.beginPath(),t.moveTo(0,0);let i=new Path2D(e.attr("d"));t.strokeStyle=e.attr("stroke"),t.fillStyle=e.attr("fill"),t.lineWidth=1.25,t.globalCompositeOperation="source-over",t.globalAlpha=e.attr("stroke-opacity")||.3,t.stroke(i),t.globalAlpha=e.attr("fill-opacity")||.45,t.fill(i),t.globalAlpha=1,t.closePath()},coordPropsToMeta:s,parseNumeric:n,parseDate:(t,e)=>new Date(Date.parse("object"==typeof t?t[e]:t)),addClass:r,removeClass:h,toggleClass:l,replaceClass:d,style:c,toggleStyle:(t,e,i,a)=>c(t,e,a?i:""),setAttributes:_,toggleEvent:m,create:p,append:u,insert:f,select:g,each:y,randomId:k,iMax:(t,e=-1/0)=>t>e?t:e,iMin:(t,e=1/0)=>t<e?t:e,iAvg:(t,e=0,i=1)=>(t+e*(i-1))/i,iSum:(t,e=0)=>t+e,on:v,off:M,throttle:w,wrapNum:S,hasClass:C,round:b,clamp:x,wrapDelta:D}),N={autofitBounds:!0,autohide:!1,autohideMarker:!0,almostover:!0,altitude:!0,closeBtn:!0,collapsed:!1,detached:!0,distance:!0,distanceMarkers:{lazy:!0,distance:!0,direction:!0},dragging:!L.Browser.mobile,downloadLink:"link",elevationDiv:"#elevation-div",followMarker:!0,imperial:!1,legend:!0,handlers:["Distance","Time","Altitude","Slope","Speed","Acceleration"],hotline:"elevation",marker:"elevation-line",markerIcon:L.divIcon({className:"elevation-position-marker",html:'<i class="elevation-position-icon"></i>',iconSize:[32,32],iconAnchor:[16,16]}),position:"topright",polyline:{className:"elevation-polyline",color:"#000",opacity:.75,weight:5,lineCap:"round"},polylineSegments:{className:"elevation-polyline-segments",color:"#F00",interactive:!1},preferCanvas:!1,reverseCoords:!1,ruler:!0,theme:"lightblue-theme",summary:"inline",slope:!1,speed:!1,time:!0,timeFactor:3600,timestamps:!1,trkStart:L.circleMarker([0,0],{className:"start-marker",radius:6,weight:2,color:"#fff",fillColor:"#00d800",fillOpacity:1,interactive:!1}),trkEnd:L.circleMarker([0,0],{className:"end-marker",radius:6,weight:2,color:"#fff",fillColor:"#ff0606",fillOpacity:1,interactive:!1}),waypoints:!0,wptIcons:{"":L.divIcon({className:"elevation-waypoint-marker",html:'<i class="elevation-waypoint-icon default"></i>',iconSize:[30,30],iconAnchor:[8,30]})},wptLabels:!0,xAttr:"dist",xLabel:"km",yAttr:"z",yLabel:"m",zFollow:!1,zooming:!L.Browser.Mobile,margins:{top:30,right:30,bottom:30,left:40},height:.3*screen.height||200,width:.6*screen.width||600,xTicks:void 0,yTicks:void 0,decimalsX:2,decimalsY:0,forceAxisBounds:!1,interpolation:"curveLinear",skipNullZCoords:!1,yAxisMax:void 0,yAxisMin:void 0};L._&&L.i18n||(L._=L.i18n=(t,e)=>t);const O=(document.currentScript&&document.currentScript.src||{url:"undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("leaflet-elevation.min.js",document.baseURI).href}&&("undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("leaflet-elevation.min.js",document.baseURI).href)).split("/").slice(0,-1).join("/")+"/",A=L.Control.Elevation=L.Control.extend({includes:L.Evented?L.Evented.prototype:L.Mixin.Events,options:N,__mileFactor:.621371,__footFactor:3.28084,__D3:"https://unpkg.com/d3@6.5.0/dist/d3.min.js",__TOGEOJSON:"https://unpkg.com/@tmcw/togeojson@4.6.0/dist/togeojson.umd.js",__LGEOMUTIL:"https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js",__LALMOSTOVER:"https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js",__LHOTLINE:"../libs/leaflet-hotline.min.js",__LDISTANCEM:"../libs/leaflet-distance-marker.min.js",__LCHART:"../src/components/chart.js",__LMARKER:"../src/components/marker.js",__LSUMMARY:"../src/components/summary.js",__modulesFolder:"../src/handlers/",__btnIcon:"../images/elevation.svg",addData:function(t,e){this.import(this.__D3).then((()=>{this._modulesLoaded?(e=e??(t.on&&t),this._addData(t),this._addLayer(e),this._fireEvt("eledata_added",{data:t,layer:e,track_info:this.track_info})):this.once("modules_loaded",(()=>this.addData(t,e)))}))},addTo:function(t){if(this.options.detached){let e=g(this.options.elevationDiv),i=this.onAdd(t);e?u(e,i):f(t.getContainer(),i,"afterend")}else L.Control.prototype.addTo.call(this,t);return this},clear:function(){this._marker&&this._marker.remove(),this._chart&&this._clearChart(),this._layers&&this._clearLayers(this._layers),this._markers&&this._clearLayers(this._markers),this._circleMarkers&&this._circleMarkers.remove(),this._hotline&&this._clearLayers(this._hotline),this._data=[],this.track_info={},this._fireEvt("eledata_clear"),this._updateChart()},_clearChart:function(){this._events&&this._events.elechart_updated&&this._events.elechart_updated.forEach((({fn:t,ctx:e})=>this.off("elechart_updated",t,e))),this._chart&&this._chart._container&&(this._chart._container.selectAll("g.point .point").remove(),this._chart.clear())},_clearLayers:function(t){(t=t||this._layers)&&t.eachLayer&&(t.eachLayer((t=>t.remove())),t.clearLayers())},disableBrush:function(){this._chart._brushEnabled=!1,this._resetDrag()},enableBrush:function(){this._chart._brushEnabled=!0},disableZoom:function(){this._chart._zoomEnabled=!1,this._chart._resetZoom()},enableZoom:function(){this._chart._zoomEnabled=!0},fitBounds:function(t){t=t||this.getBounds(),this._map&&t.isValid()&&this._map.fitBounds(t)},getBounds:function(t){return L.latLngBounds((t||this._data).map((t=>t.latlng)))},getZFollow:function(){return this.options.zFollow},hide:function(){c(this._container,"display","none")},initialize:function(e){e=L.setOptions(this,e),this._data=[],this._layers=L.featureGroup(),this._markers=L.featureGroup(),this._hotline=L.featureGroup(),this._circleMarkers=L.featureGroup(),this._markedSegments=L.polyline([]),this._start=e.trkStart||N.trkStart,this._end=e.trkEnd||N.trkEnd,this._chartEnabled=!0,this._yCoordMax=-1/0,this.track_info={},e.followMarker&&(this._setMapView=w(this._setMapView,300,this)),e.legend&&(e.margins.bottom+=30),e.theme&&(e.polylineSegments.className+=" "+e.theme),!0===e.wptIcons&&(e.wptIcons=N.wptIcons),!0===e.distanceMarkers&&(e.distanceMarkers=N.distanceMarkers),e.trkStart&&this._start.addTo(this._circleMarkers),e.trkEnd&&this._end.addTo(this._circleMarkers),this._markedSegments.setStyle(e.polylineSegments),L.extend(t,e.colors||{}),this._fixCanvasPaths(),this._fixTooltipSize()},import:function(t,e){switch(t){case this.__D3:e="object"!=typeof d3;break;case this.__TOGEOJSON:e="object"!=typeof toGeoJSON;break;case this.__LGEOMUTIL:e="object"!=typeof L.GeometryUtil;break;case this.__LALMOSTOVER:e="function"!=typeof L.Handler.AlmostOver;break;case this.__LDISTANCEM:e="function"!=typeof L.DistanceMarkers;break;case this.__LHOTLINE:e="function"!=typeof L.Hotline}return t=(t.startsWith("../")||t.startsWith("./")?O:"")+t,!1!==e?import(t):Promise.resolve()},load:function(t){this._parseFromString(t).then((e=>e?this._loadLayer(e):this._loadFile(t)))},onAdd:function(t){this._map=t;let e=this._container=p("div","elevation-control "+this.options.theme+" "+(this.options.detached?"elevation-detached":"leaflet-control"),this.options.detached?{id:"elevation-"+k()}:{});return this.eleDiv||(this.eleDiv=e),this._loadModules(this.options.handlers).then((()=>{this._initChart(e),this._initButton(e),this._initSummary(e),this._initMarker(t),this._initLayer(t),this._modulesLoaded=!0,this.fire("modules_loaded")})),this.fire("add"),e},onRemove:function(t){this._container=null,t.off("zoom viewreset zoomanim",this._hideMarker,this).off("resize",this._resetView,this).off("resize",this._resizeChart,this).off("mousedown",this._resetDrag,this),M(t.getContainer(),"mousewheel",this._resetDrag,this),M(t.getContainer(),"touchstart",this._resetDrag,this),M(document,"keydown",this._onKeyDown,this),this.off("eledata_added eledata_loaded",this._updateChart,this).off("eledata_added eledata_loaded",this._updateSummary,this),this.fire("remove")},redraw:function(){this._resizeChart()},setZFollow:function(t){this.options.zFollow=t},show:function(){c(this._container,"display","block")},_addData:function(t){if(t){if("FeatureCollection"===t.type)return y(t.features,(t=>this._addData(t)));if("Feature"===t.type){let e=t.geometry;if(e)switch(e.type){case"LineString":return this._addGeoJSONData(e.coordinates,t.properties);case"MultiLineString":return y(e.coordinates,((e,i)=>this._addGeoJSONData(e,t.properties,i)));case"Point":default:return console.warn("Unsopperted GeoJSON feature geometry type:"+e.type)}}return t._latlngs?this._addGeoJSONData(t._latlngs,t.feature&&t.feature.properties):void 0}},_addGeoJSONData:function(t,e,i){let a=e&&e.coordinateProperties||e;t.forEach(((t,e)=>{t.meta=t.meta??{time:null,ele:null},t.prev=t=>t?this._data[e>0?e-1:0][t]:this._data[e>0?e-1:0],this.fire("elepoint_init",{point:t,props:a,id:e,isMulti:i}),this._addPoint(t.lat??t[1],t.lng??t[0],t.alt??t.meta.ele??t[2]),this.fire("elepoint_added",{point:t,index:this._data.length-1}),this._yCoordMax<this._data[this._data.length-1][this.options.yAttr]&&(this._yCoordMax=this._data[this._data.length-1][this.options.yAttr])})),this.fire("eletrack_added",{coords:t,index:this._data.length-1})},_addPoint:function(t,e,i){this.options.reverseCoords&&([t,e]=[e,t]),this._data.push({x:t,y:e,z:i,latlng:L.latLng(t,e,i)}),this.fire("eledata_updated",{index:this._data.length-1})},_addLayer:function(t){return t&&this._layers.addLayer(t),t&&this.options.distanceMarkers&&this.options.distanceMarkers.lazy&&t.on("add remove",(({target:t,type:e})=>L.DistanceMarkers&&t instanceof L.Polyline&&t[e+"DistanceMarkers"]())),t},_addMarker:function(t){return t&&this._markers.addLayer(t),t},_initAlmostOverHandler:function(t,e){return t&&this.options.almostOver&&!L.Browser.mobile?Promise.all([this.import(this.__LGEOMUTIL),this.import(this.__LALMOSTOVER)]).then((()=>{t.addHandler("almostOver",L.Handler.AlmostOver),L.GeometryUtil&&t.almostOver&&t.almostOver.enabled()&&(t.almostOver.addLayer(e),t.on("almost:move",(t=>this._onMouseMoveLayer(t))).on("almost:out",(t=>this._onMouseOut(t))))})):Promise.resolve()},_initDistanceMarkers:function(){return this.options.distanceMarkers?Promise.all([this.import(this.__LGEOMUTIL),this.import(this.__LDISTANCEM)]):Promise.resolve()},_initHotLine:function(t){let e="string"==typeof this.options.hotline?this.options.hotline:"elevation";return this.options.hotline?this.import(this.__LHOTLINE).then((()=>{t.eachLayer((t=>{if("Point"!=t.feature.geometry.type){let i=L.geoJson(t.toGeoJSON(),{coordsToLatLng:t=>L.latLng(t[0],t[1],t[2]*(this.options.altitudeFactor||1))}),a=L.hotline(i.toGeoJSON().features[0].geometry.coordinates,{min:isFinite(this.track_info[e+"_min"])?this.track_info[e+"_min"]:0,max:isFinite(this.track_info[e+"_max"])?this.track_info[e+"_max"]:1,palette:{0:"#008800",.5:"#ffff00",1:"#ff0000"},weight:5,outlineColor:"#000000",outlineWidth:1}).addTo(this._hotline),o=t.options.style&&t.options.style.opacity||1;t.on("add remove",(({type:e})=>{t.setStyle({opacity:"add"==e?0:o}),a["add"==e?"addTo":"removeFrom"](t._map),a._renderer&&a._renderer._container.parentElement.insertBefore(a._renderer._container,a._renderer._container.parentElement.firstChild)}))}}))})):Promise.resolve()},_initMapIntegrations:function(t){let e=this._map;e?(this._data.length&&(this._start.setLatLng(this._data[0].latlng),this._end.setLatLng(this._data[this._data.length-1].latlng)),Promise.all([this._initHotLine(t),this._initAlmostOverHandler(e,t),this._initDistanceMarkers()]).then((()=>{this.options.polyline&&(t.addTo(e),this._circleMarkers.addTo(e)),this.options.autofitBounds&&this.fitBounds(t.getBounds()),e.invalidateSize()}))):this.once("add",(()=>this._initMapIntegrations(t)))},_collapse:function(){d(this._container,"elevation-expanded","elevation-collapsed"),this._map&&this._map.invalidateSize()},_expand:function(){d(this._container,"elevation-collapsed","elevation-expanded"),this._map&&this._map.invalidateSize()},_fixCanvasPaths:function(){let e=L.Canvas.prototype._fillStroke,i=this,a=this.options.theme.split(" ")[0].replace("-theme",""),o=t[a]||{};L.Canvas.include({_fillStroke:function(t,s){if(i._layers.hasLayer(s)){let i=s.options;if(i.color=o.line||o.area||a,i.stroke=!!i.color,e.call(this,t,s),i.stroke&&0!==i.weight){let e=t.globalCompositeOperation||"source-over";t.globalCompositeOperation="destination-over",t.strokeStyle=o.outline||"#FFF",t.lineWidth=1.75*i.weight,t.stroke(),t.globalCompositeOperation=e}}else e.call(this,t,s)}})},_fixTooltipSize:function(){this.on("elechart_init",(()=>this.once("elechart_change elechart_hover",(({data:t,xCoord:e})=>{this._chartEnabled&&(this._chart._showDiagramIndicator(t,e),this._chart._showDiagramIndicator(t,e)),this._updateMarker(t)}))))},_findItemForLatLng:function(t){return this._data[this._chart._findIndexForLatLng(t)]},_findItemForX:function(t){return this._data[this._chart._findIndexForXCoord(t)]},_fireEvt:function(t,e,i){this.fire&&this.fire(t,e,i),this._map&&this._map.fire(t,e,i)},_hideMarker:function(){this.options.autohideMarker&&this._marker.remove()},_initChart:function(t){let e=this.options,i=this._map;if(e.detached){let{offsetWidth:t,offsetHeight:i}=this.eleDiv;t>0&&(e.width=t),i>20&&(e.height=i-20)}else{let{clientWidth:t}=i.getContainer();e._maxWidth=e._maxWidth>e.width?e._maxWidth:e.width,this._container.style.maxWidth=e._maxWidth+"px",e._maxWidth>t&&(e.width=t-30)}Promise.all([this.import(this.__D3),this.import(this.__LCHART)]).then((a=>{let o=this._chart=new(a[1]||A).Chart(e,this);this._x=this._chart._x,this._y=this._chart._y,d3.select(t).call(o.render()),o.on("reset_drag",this._hideMarker,this).on("mouse_enter",this._onMouseEnter,this).on("dragged",this._onDragEnd,this).on("mouse_move",this._onMouseMove,this).on("mouse_out",this._onMouseOut,this).on("ruler_filter",this._onRulerFilter,this).on("zoom",this._updateChart,this).on("elepath_toggle",this._onToggleChart,this).on("margins_updated",this._resizeChart,this),this.fire("elechart_init"),i.on("zoom viewreset zoomanim",this._hideMarker,this).on("resize",this._resetView,this).on("resize",this._resizeChart,this).on("rotate",this._rotateMarker,this).on("mousedown",this._resetDrag,this),v(i.getContainer(),"mousewheel",this._resetDrag,this),v(i.getContainer(),"touchstart",this._resetDrag,this),v(document,"keydown",this._onKeyDown,this),this.on("eledata_added eledata_loaded",this._updateChart,this).on("eledata_added eledata_loaded",this._updateSummary,this),this._updateChart(),this._updateSummary()}))},_initLayer:function(){this._layers.on("layeradd layerremove",(({layer:t,type:e})=>{let i=t.getElement&&t.getElement();l(i,this.options.polyline.className+" "+this.options.theme,"layeradd"==e),m(t,"mousemove",this._onMouseMoveLayer.bind(this),"layeradd"==e),m(t,"mouseout",this._onMouseOut.bind(this),"layeradd"==e)}))},_initMarker:function(t){let e=t.getPane("elevationPane");e||(e=this._pane=t.createPane("elevationPane",t.getPane("norotatePane")||t.getPane("mapPane")),e.style.zIndex=625,e.style.pointerEvents="none"),this._renderer&&this._renderer.remove(),this._renderer=L.svg({pane:"elevationPane"}).addTo(this._map),Promise.all([this.import(this.__D3),this.import(this.__LMARKER)]).then((t=>{this._marker=new(t[1]||A).Marker(this.options,this),this.fire("elechart_marker")}))},_initButton:function(t){if(L.DomEvent.disableClickPropagation(t).disableScrollPropagation(t),this.options.collapsed?this._collapse():this._expand(),this.options.autohide&&(v(t,"mouseover",this._expand,this),v(t,"mouseout",this._collapse,this),this._map.on("click",this._collapse,this)),this.options.closeBtn){let e=this._button=p("a","elevation-toggle-icon",{href:"#",title:L._("Elevation")},t);v(e,"click",L.DomEvent.stop),v(e,"click",this._toggle,this),v(e,"focus",this._toggle,this),fetch(this.__btnIcon).then((t=>t.ok&&t.text().then((t=>e.innerHTML=t))))}},_initSummary:function(t){this.import(this.__LSUMMARY).then((e=>{this._summary=new(e||A).Summary({summary:this.options.summary},this),this.on("elechart_init",(()=>{d3.select(t).call(this._summary.render())}))}))},_loadFile:function(t){fetch(t).then((t=>t.text())).then((e=>{this._downloadURL=t,this._parseFromString(e).then((t=>t&&this._loadLayer(t)))})).catch((t=>console.warn(t)))},_loadModules:function(t){let e=(t=t.map((t=>"string"==typeof t&&void 0!==A[t]?A[t]:t))).map((t=>"string"==typeof t&&this.import(this.__modulesFolder+t.toLowerCase()+".js")||t instanceof Promise&&t||Promise.resolve()));return Promise.all(e).then((e=>{y(e,((e,i)=>{let a=e&&Object.keys(e)[0];a&&(t[i]=A[a]=A[a]??e[a])})),y(t,(t=>["function","object"].includes(typeof t)&&this._registerHandler(t)))}))},_loadLayer:function(t){let{polyline:e,theme:i,waypoints:a,wptIcons:o,wptLabels:s,distanceMarkers:n}=this.options,r=L.extend({},e);i&&(r.className+=" "+i),t.name&&(this.track_info.name=t.name);let h=L.geoJson(t,{distanceMarkers:n,style:r,pointToLayer:(t,e)=>{if(a){let{desc:i,name:n,sym:r}=t.properties;if(i=i||"",n=n||"",[!0,"dots"].includes(a)&&this._registerCheckPoint({latlng:e,label:[!0,"dots"].includes(s)?n:""}),[!0,"markers"].includes(a)&&0!=o)return this._registerMarker({latlng:e,sym:(r??n).replace(" ","-").replace('"',"").replace("'","").toLowerCase(),content:[!0,"markers"].includes(s)&&(n||i)&&decodeURI("<b>"+n+"</b>"+(i.length>0?"<br>"+i:""))})}},onEachFeature:(t,e)=>t.geometry&&"Point"!=t.geometry.type&&this.addData(t,e)});return this.import(this.__D3).then((()=>{this._initMapIntegrations(h),this._fireEvt("eledata_loaded",{data:t,layer:h,name:this.track_info.name,track_info:this.track_info})})),h},_onDragEnd:function({dragstart:t,dragend:e}){this._hideMarker(),this.fitBounds(L.latLngBounds([t.latlng,e.latlng])),this.fire("elechart_dragged")},_onKeyDown:function({key:t}){this.options.detached||"Escape"!==t||this._collapse()},_onMouseEnter:function(){this.fire("elechart_enter")},_onMouseMove:function({xCoord:t}){if(this._chartEnabled&&this._data.length){let e=this._findItemForX(t);e&&(this._chartEnabled&&this._chart._showDiagramIndicator(e,t),this._updateMarker(e),this._setMapView(e),this._map&&r(this._map.getContainer(),"elechart-hover"),this.fire("elechart_change",{data:e,xCoord:t}),this.fire("elechart_hover",{data:e,xCoord:t}))}},_onMouseMoveLayer:function({latlng:t}){if(this._data.length){let e=this._findItemForLatLng(t);if(e){let t=e.xDiagCoord;this._chartEnabled&&this._chart._showDiagramIndicator(e,t),this._updateMarker(e),this.fire("elechart_change",{data:e,xCoord:t})}}},_onMouseOut:function(){this.options.detached||(this._hideMarker(),this._chart._hideDiagramIndicator()),this._map&&h(this._map.getContainer(),"elechart-hover"),this.fire("elechart_leave")},_onRulerFilter:function({coords:t}){this._updateMapSegments(t)},_onToggleChart:function({name:t,enabled:e}){this._chartEnabled=this._chart._hasActiveLayers(),this._layers.eachLayer((t=>l(t.getElement&&t.getElement(),this.options.polyline.className+" "+this.options.theme,this._chartEnabled))),this.options[t]=e||"disabled"!=this.options[t]?"disabled":"enabled",this._chartEnabled||(this._chart._hideDiagramIndicator(),this._marker.remove())},_parseFromGeoJSONString:function(t){try{return JSON.parse(t)}catch(t){}},_parseFromString:function(t){return new Promise((e=>this.import(this.__TOGEOJSON).then((()=>{let i;try{i=this._parseFromXMLString(t.trim())}catch(e){i=this._parseFromGeoJSONString(t.toString())}i&&(i.name=i.name||(this._downloadURL||"").split("/").pop().split("#")[0].split("?")[0]),e(i)}))))},_parseFromXMLString:function(t){if(0!=t.indexOf("<"))throw"Invalid XML";let e=(new DOMParser).parseFromString(t,"text/xml"),i=e.documentElement.tagName.toLowerCase(),a=e.getElementsByTagName("name");if(e.getElementsByTagName("parsererror").length)throw"Invalid XML";i in toGeoJSON||(i="TrainingCenterDatabase"==e.documentElement.tagName?"tcx":"gpx");let o=toGeoJSON[i](e);return o.name=a.length>0?(Array.from(a).find((t=>"trk"==t.parentElement.tagName))??a[0]).textContent:"",o},_registerAreaPath:function(t){this.on("elechart_init",(()=>this._chart._registerAreaPath(t)))},_registerAxisGrid:function(t){this.on("elechart_axis",(()=>this._chart._registerAxisGrid(t)))},_registerAxisScale:function(t){this.on("elechart_axis",(()=>this._chart._registerAxisScale(t)))},_registerCheckPoint:function(t){this.on("elechart_updated",(()=>this._chart._registerCheckPoint(t)))},_registerDataAttribute:function(t){let e,i,a,o;t.coordPropsToMeta&&this.on("elepoint_init",(e=>t.coordPropsToMeta.call(this,e)));let s=null;this.on("elepoint_added",(({index:n,point:r})=>{if(e=n,a=i??this._data[e],i=this._data[e],o=t.attr||t.name,!1===t.skipNull){let t=this._data[e][o];if(e>0){let i=this._data[e-1][o];if(isNaN(i)){if(isNaN(s)||isNaN(t)?isNaN(s)?isNaN(t)||(i=t):i=s:i=(s+t)/2,!isNaN(i))return this._data.splice(e-1,1);this._data[e-1][o]=i}}isNaN(t)||(s=t)}if(i[o]=t.pointToAttr.call(this,r,e),t.stats)for(const e in t.stats){let a=(t.statsName||o)+(""!=e?"_":"");this.track_info[a+e]=t.stats[e].call(this,i[o],this.track_info[a+e],this._data.length)}t.deltaMax&&(i[o]=D(i[o],a[o],t.deltaMax)),t.clampRange&&(i[o]=x(i[o],t.clampRange)),isNaN(t.decimals)||(i[o]=b(i[o],t.decimals)),t.onPointAdded&&t.onPointAdded.call(this,i[o],e,r)}))},_registerHandler:function(t){if("function"==typeof t)return this._registerHandler(t.call(this));let{name:e,attr:i,required:a,skipNull:o,deltaMax:n,clampRange:r,decimals:h,meta:l,unit:d,coordinateProperties:c,coordPropsToMeta:_,pointToAttr:m,onPointAdded:p,stats:u,statsName:f,grid:g,scale:k,path:v,tooltip:M,summary:w}=t;(this.options[e]||a)&&(this._registerDataAttribute({name:e,attr:i,skipNull:o,deltaMax:n,clampRange:r,decimals:h,coordPropsToMeta:s(c,l||e,_),pointToAttr:m,onPointAdded:p,stats:u,statsName:f}),g&&this._registerAxisGrid(L.extend({name:e},g)),"summary"!==this.options[e]&&(k&&this._registerAxisScale(L.extend({name:e,label:d},k)),v&&this._registerAreaPath(L.extend({name:e},v))),(M||t.tooltips)&&y([M,...t.tooltips||[]],(t=>t&&this._registerTooltip(L.extend({name:e},t)))),w&&(y(w,((t,e)=>w[e]=L.extend({unit:d},t))),this._registerSummary(w)))},_registerMarker({latlng:t,sym:e,content:i}){let{wptIcons:a}=this.options;a.hasOwnProperty(e)||(a[e]=L.divIcon(L.extend({},a[""].options,{html:'<i class="elevation-waypoint-icon '+e+'"></i>'})));let o=L.marker(t,{icon:a[e]});return i&&(o.bindPopup(i,{className:"elevation-popup",keepInView:!0}).openPopup(),o.bindTooltip(i,{className:"elevation-tooltip",direction:"auto",sticky:!0,opacity:1}).openTooltip()),this._addMarker(o)},_registerTooltip:function(t){t.chart&&this.on("elechart_init",(()=>this._chart._registerTooltip(L.extend({},t,{value:t.chart})))),t.marker&&this.on("elechart_marker",(()=>this._marker._registerTooltip(L.extend({},t,{value:t.marker}))))},_registerSummary:function(t){this.on("elechart_summary",(()=>this._summary._registerSummary(t)))},_resetDrag:function(){this._chart._resetDrag(),this._hideMarker()},_resetView:function(){this._map&&this._map._isFullscreen||(this._resetDrag(),this._hideMarker(),this.options.autofitBounds&&this.fitBounds())},_resizeChart:function(){if(this._container&&"none"!=c(this._container,"display")){let t=this.options,e=t.detached?(this.eleDiv||this._container).offsetWidth:x(t._maxWidth,[0,this._map.getContainer().clientWidth-30]);e&&(t.width=e,this._chart&&this._chart._chart&&(this._chart._chart._resize(t),this._updateChart())),this._updateMapSegments()}},_toggle:function(){C(this._container,"elevation-expanded")?this._collapse():this._expand()},_setMapView:function(t){if(this._map&&this.options.followMarker){let e=this._map.getZoom(),i=this.options.zFollow;"number"==typeof i?this._map.setView(t.latlng,e<i?i:e,{animate:!0,duration:.25}):this._map.getBounds().contains(t.latlng)||this._map.setView(t.latlng,e,{animate:!0,duration:.25})}},_updateChart:function(){this._chart&&this._container&&(this.fire("elechart_axis"),this._chart.update({data:this._data,options:this.options}),this._x=this._chart._x,this._y=this._chart._y,this.fire("elechart_updated"))},_updateMarker:function(t){this._marker&&this._marker.update({map:this._map,item:t,yCoordMax:this._yCoordMax||0,options:this.options})},_rotateMarker:function(){this._marker&&this._marker.update()},_updateMapSegments:function(t){this._markedSegments.setLatLngs(t||[]),t&&this._map&&!this._map.hasLayer(this._markedSegments)&&this._markedSegments.addTo(this._map)},_updateSummary:function(){this._summary&&(this._summary.reset(),this.options.summary&&(this.fire("elechart_summary"),this._summary.update()),this.options.downloadLink&&this._downloadURL&&(this._summary._container.innerHTML+='<span class="download"><a href="#">'+L._("Download")+"</a></span>",g(".download a",this._summary._container).onclick=t=>{t.preventDefault();let e={downloadLink:this.options.downloadLink,confirm:o.bind(this,this._downloadURL)};"modal"==this.options.downloadLink&&"function"==typeof CustomEvent?document.dispatchEvent(new CustomEvent("eletrack_download",{detail:e})):"link"!=this.options.downloadLink&&!0!==this.options.downloadLink||e.confirm(),this.fire("eletrack_download",e)}))},_width:function(){if(this._chart)return this._chart._width();const{width:t,margins:e}=this.options;return t-e.left-e.right},_height:function(){if(this._chart)return this._chart._height();const{height:t,margins:e}=this.options;return t-e.top-e.bottom}});A.Utils=E,L.control.elevation=t=>new A(t)}));
|
|
1
|
+
!function(t){"function"==typeof define&&define.amd?define(t):t()}((function(){"use strict";const t={lightblue:{area:"#3366CC",alpha:.45,stroke:"#3366CC"},magenta:{area:"#FF005E"},yellow:{area:"#FF0"},purple:{area:"#732C7B"},steelblue:{area:"#4682B4"},red:{area:"#F00"},lime:{area:"#9CC222",line:"#566B13"}},e=6e4,i=60*e,a=24*i;function o(t,e){let i=p("a","",{href:t,target:"_new",download:e||"",style:"display:none;"}),a=document.body;a.appendChild(i),i.click(),a.removeChild(i)}function s(t,e,i){return t&&(({props:a,point:o,id:s,isMulti:r})=>{if(a)for(const h of t)if(h in a){o.meta[e]=(i||n).call(this,r?a[h][r]:a[h],s);break}})}const n=(t,e)=>parseInt("object"==typeof t?t[e]:t),r=(t,e)=>t&&e.split(" ").every((e=>e&&L.DomUtil.addClass(t,e))),h=(t,e)=>t&&e.split(" ").every((e=>e&&L.DomUtil.removeClass(t,e))),l=(t,e,i)=>(i?r:h)(t,e),d=(t,e,i)=>e&&h(t,e)||i&&r(t,i),c=(t,e,i)=>void 0===i&&L.DomUtil.getStyle(t,e)||t.style.setProperty(e,i),_=(t,e)=>{for(let i in e)t.setAttribute(i,e[i])},m=(t,e,i,a)=>t[a?"on":"off"](e,i),p=(t,e,i,a)=>{let o=L.DomUtil.create(t,e||"");return i&&_(o,i),a&&u(a,o),o},u=(t,e)=>t.appendChild(e),f=(t,e,i)=>t.insertAdjacentElement(i,e),g=(t,e)=>(e||document).querySelector(t),y=(t,e)=>{for(let i in t)e(t[i],i)},k=()=>Math.random().toString(36).substr(2,9),{on:v,off:M}=L.DomEvent,{throttle:w,wrapNum:S}=L.Util,{hasClass:C}=L.DomUtil,b=L.Util.formatNum,x=(t,e)=>e?t<e[0]?e[0]:t>e[1]?e[1]:t:t,D=(t,e,i)=>Math.abs(t-e)>i?e+i*Math.sign(t-e):t;var E=Object.freeze({__proto__:null,Colors:t,formatTime:function(t){let o=Math.floor(t/a),s=Math.floor((t-o*a)/i),n=Math.floor((t-o*a-s*i)/e),r=Math.round((t-o*a-s*i-n*e)/1e3);return 60===r&&(n++,r=0),60===n&&(s++,n=0),24===s&&(o++,s=0),(o?o+"d ":"")+s.toString().padStart(2,0)+":"+n.toString().padStart(2,0)+"'"+r.toString().padStart(2,0)+'"'},formatDate:function(t){return t?"time"==t?t=>new Date(t).toLocaleTimeString():"date"==t?t=>new Date(t).toLocaleDateString():e=>t(e):t=>new Date(t).toLocaleString().replaceAll("/","-").replaceAll(","," ")},saveFile:o,drawCanvas:function(t,e){e.classed("canvas-path",!0),t.beginPath(),t.moveTo(0,0);let i=new Path2D(e.attr("d"));t.strokeStyle=e.attr("stroke"),t.fillStyle=e.attr("fill"),t.lineWidth=1.25,t.globalCompositeOperation="source-over",t.globalAlpha=e.attr("stroke-opacity")||.3,t.stroke(i),t.globalAlpha=e.attr("fill-opacity")||.45,t.fill(i),t.globalAlpha=1,t.closePath()},coordPropsToMeta:s,parseNumeric:n,parseDate:(t,e)=>new Date(Date.parse("object"==typeof t?t[e]:t)),addClass:r,removeClass:h,toggleClass:l,replaceClass:d,style:c,toggleStyle:(t,e,i,a)=>c(t,e,a?i:""),setAttributes:_,toggleEvent:m,create:p,append:u,insert:f,select:g,each:y,randomId:k,iMax:(t,e=-1/0)=>t>e?t:e,iMin:(t,e=1/0)=>t<e?t:e,iAvg:(t,e=0,i=1)=>(t+e*(i-1))/i,iSum:(t,e=0)=>t+e,on:v,off:M,throttle:w,wrapNum:S,hasClass:C,round:b,clamp:x,wrapDelta:D}),N={autofitBounds:!0,autohide:!1,autohideMarker:!0,almostover:!0,altitude:!0,closeBtn:!0,collapsed:!1,detached:!0,distance:!0,distanceMarkers:{lazy:!0,distance:!0,direction:!0},dragging:!L.Browser.mobile,downloadLink:"link",elevationDiv:"#elevation-div",followMarker:!0,imperial:!1,legend:!0,handlers:["Distance","Time","Altitude","Slope","Speed","Acceleration"],hotline:"elevation",marker:"elevation-line",markerIcon:L.divIcon({className:"elevation-position-marker",html:'<i class="elevation-position-icon"></i>',iconSize:[32,32],iconAnchor:[16,16]}),position:"topright",polyline:{className:"elevation-polyline",color:"#000",opacity:.75,weight:5,lineCap:"round"},polylineSegments:{className:"elevation-polyline-segments",color:"#F00",interactive:!1},preferCanvas:!1,reverseCoords:!1,ruler:!0,theme:"lightblue-theme",summary:"inline",slope:!1,speed:!1,time:!0,timeFactor:3600,timestamps:!1,trkStart:{className:"start-marker",radius:6,weight:2,color:"#fff",fillColor:"#00d800",fillOpacity:1,interactive:!1},trkEnd:{className:"end-marker",radius:6,weight:2,color:"#fff",fillColor:"#ff0606",fillOpacity:1,interactive:!1},waypoints:!0,wptIcons:{"":L.divIcon({className:"elevation-waypoint-marker",html:'<i class="elevation-waypoint-icon default"></i>',iconSize:[30,30],iconAnchor:[8,30]})},wptLabels:!0,xAttr:"dist",xLabel:"km",yAttr:"z",yLabel:"m",zFollow:!1,zooming:!L.Browser.Mobile,margins:{top:30,right:30,bottom:30,left:40},height:.3*screen.height||200,width:.6*screen.width||600,xTicks:void 0,yTicks:void 0,decimalsX:2,decimalsY:0,forceAxisBounds:!1,interpolation:"curveLinear",skipNullZCoords:!1,yAxisMax:void 0,yAxisMin:void 0};L._&&L.i18n||(L._=L.i18n=(t,e)=>t);const O=(document.currentScript&&document.currentScript.src||{url:"undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("leaflet-elevation.min.js",document.baseURI).href}&&("undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("leaflet-elevation.min.js",document.baseURI).href)).split("/").slice(0,-1).join("/")+"/",A=L.Control.Elevation=L.Control.extend({includes:L.Evented?L.Evented.prototype:L.Mixin.Events,options:N,__mileFactor:.621371,__footFactor:3.28084,__D3:"https://unpkg.com/d3@6.5.0/dist/d3.min.js",__TOGEOJSON:"https://unpkg.com/@tmcw/togeojson@4.6.0/dist/togeojson.umd.js",__LGEOMUTIL:"https://unpkg.com/leaflet-geometryutil@0.9.3/src/leaflet.geometryutil.js",__LALMOSTOVER:"https://unpkg.com/leaflet-almostover@1.0.1/src/leaflet.almostover.js",__LHOTLINE:"../libs/leaflet-hotline.min.js",__LDISTANCEM:"../libs/leaflet-distance-marker.min.js",__LCHART:"../src/components/chart.js",__LMARKER:"../src/components/marker.js",__LSUMMARY:"../src/components/summary.js",__modulesFolder:"../src/handlers/",__btnIcon:"../images/elevation.svg",addData:function(t,e){this.import(this.__D3).then((()=>{this._modulesLoaded?(e=e??(t.on&&t),this._addData(t),this._addLayer(e),this._fireEvt("eledata_added",{data:t,layer:e,track_info:this.track_info})):this.once("modules_loaded",(()=>this.addData(t,e)))}))},addTo:function(t){if(this.options.detached){let e=g(this.options.elevationDiv),i=this.onAdd(t);e?u(e,i):f(t.getContainer(),i,"afterend")}else L.Control.prototype.addTo.call(this,t);return this},clear:function(){this._marker&&this._marker.remove(),this._chart&&this._clearChart(),this._layers&&this._clearLayers(this._layers),this._markers&&this._clearLayers(this._markers),this._circleMarkers&&this._circleMarkers.remove(),this._hotline&&this._clearLayers(this._hotline),this._data=[],this.track_info={},this._fireEvt("eledata_clear"),this._updateChart()},_clearChart:function(){this._events&&this._events.elechart_updated&&this._events.elechart_updated.forEach((({fn:t,ctx:e})=>this.off("elechart_updated",t,e))),this._chart&&this._chart._container&&(this._chart._container.selectAll("g.point .point").remove(),this._chart.clear())},_clearLayers:function(t){(t=t||this._layers)&&t.eachLayer&&(t.eachLayer((t=>t.remove())),t.clearLayers())},disableBrush:function(){this._chart._brushEnabled=!1,this._resetDrag()},enableBrush:function(){this._chart._brushEnabled=!0},disableZoom:function(){this._chart._zoomEnabled=!1,this._chart._resetZoom()},enableZoom:function(){this._chart._zoomEnabled=!0},fitBounds:function(t){t=t||this.getBounds(),this._map&&t.isValid()&&this._map.fitBounds(t)},getBounds:function(t){return L.latLngBounds((t||this._data).map((t=>t.latlng)))},getZFollow:function(){return this.options.zFollow},hide:function(){c(this._container,"display","none")},initialize:function(e){e=L.setOptions(this,e),this._data=[],this._layers=L.featureGroup(),this._markers=L.featureGroup(),this._hotline=L.featureGroup(),this._circleMarkers=L.featureGroup(),this._markedSegments=L.polyline([]),this._start=L.circleMarker([0,0],e.trkStart||N.trkStart),this._end=L.circleMarker([0,0],e.trkEnd||N.trkEnd),this._chartEnabled=!0,this._yCoordMax=-1/0,this.track_info={},e.followMarker&&(this._setMapView=w(this._setMapView,300,this)),e.legend&&(e.margins.bottom+=30),e.theme&&(e.polylineSegments.className+=" "+e.theme),!0===e.wptIcons&&(e.wptIcons=N.wptIcons),!0===e.distanceMarkers&&(e.distanceMarkers=N.distanceMarkers),e.trkStart&&this._start.addTo(this._circleMarkers),e.trkEnd&&this._end.addTo(this._circleMarkers),this._markedSegments.setStyle(e.polylineSegments),L.extend(t,e.colors||{}),this._fixCanvasPaths(),this._fixTooltipSize()},import:function(t,e){switch(t){case this.__D3:e="object"!=typeof d3;break;case this.__TOGEOJSON:e="object"!=typeof toGeoJSON;break;case this.__LGEOMUTIL:e="object"!=typeof L.GeometryUtil;break;case this.__LALMOSTOVER:e="function"!=typeof L.Handler.AlmostOver;break;case this.__LDISTANCEM:e="function"!=typeof L.DistanceMarkers;break;case this.__LHOTLINE:e="function"!=typeof L.Hotline}return t=(t.startsWith("../")||t.startsWith("./")?O:"")+t,!1!==e?import(t):Promise.resolve()},load:function(t){this._parseFromString(t).then((e=>e?this._loadLayer(e):this._loadFile(t)))},onAdd:function(t){this._map=t;let e=this._container=p("div","elevation-control "+this.options.theme+" "+(this.options.detached?"elevation-detached":"leaflet-control"),this.options.detached?{id:"elevation-"+k()}:{});return this.eleDiv||(this.eleDiv=e),this._loadModules(this.options.handlers).then((()=>{this._initChart(e),this._initButton(e),this._initSummary(e),this._initMarker(t),this._initLayer(t),this._modulesLoaded=!0,this.fire("modules_loaded")})),this.fire("add"),e},onRemove:function(t){this._container=null,t.off("zoom viewreset zoomanim",this._hideMarker,this).off("resize",this._resetView,this).off("resize",this._resizeChart,this).off("mousedown",this._resetDrag,this),M(t.getContainer(),"mousewheel",this._resetDrag,this),M(t.getContainer(),"touchstart",this._resetDrag,this),M(document,"keydown",this._onKeyDown,this),this.off("eledata_added eledata_loaded",this._updateChart,this).off("eledata_added eledata_loaded",this._updateSummary,this),this.fire("remove")},redraw:function(){this._resizeChart()},setZFollow:function(t){this.options.zFollow=t},show:function(){c(this._container,"display","block")},_addData:function(t){if(t){if("FeatureCollection"===t.type)return y(t.features,(t=>this._addData(t)));if("Feature"===t.type){let e=t.geometry;if(e)switch(e.type){case"LineString":return this._addGeoJSONData(e.coordinates,t.properties);case"MultiLineString":return y(e.coordinates,((e,i)=>this._addGeoJSONData(e,t.properties,i)));case"Point":default:return console.warn("Unsopperted GeoJSON feature geometry type:"+e.type)}}return t._latlngs?this._addGeoJSONData(t._latlngs,t.feature&&t.feature.properties):void 0}},_addGeoJSONData:function(t,e,i){let a=e&&e.coordinateProperties||e;t.forEach(((t,e)=>{t.meta=t.meta??{time:null,ele:null},t.prev=t=>t?this._data[e>0?e-1:0][t]:this._data[e>0?e-1:0],this.fire("elepoint_init",{point:t,props:a,id:e,isMulti:i}),this._addPoint(t.lat??t[1],t.lng??t[0],t.alt??t.meta.ele??t[2]),this.fire("elepoint_added",{point:t,index:this._data.length-1}),this._yCoordMax<this._data[this._data.length-1][this.options.yAttr]&&(this._yCoordMax=this._data[this._data.length-1][this.options.yAttr])})),this.fire("eletrack_added",{coords:t,index:this._data.length-1})},_addPoint:function(t,e,i){this.options.reverseCoords&&([t,e]=[e,t]),this._data.push({x:t,y:e,z:i,latlng:L.latLng(t,e,i)}),this.fire("eledata_updated",{index:this._data.length-1})},_addLayer:function(t){return t&&this._layers.addLayer(t),t&&this.options.distanceMarkers&&this.options.distanceMarkers.lazy&&t.on("add remove",(({target:t,type:e})=>L.DistanceMarkers&&t instanceof L.Polyline&&t[e+"DistanceMarkers"]())),t},_addMarker:function(t){return t&&this._markers.addLayer(t),t},_initAlmostOverHandler:function(t,e){return t&&this.options.almostOver&&!L.Browser.mobile?Promise.all([this.import(this.__LGEOMUTIL),this.import(this.__LALMOSTOVER)]).then((()=>{t.addHandler("almostOver",L.Handler.AlmostOver),L.GeometryUtil&&t.almostOver&&t.almostOver.enabled()&&(t.almostOver.addLayer(e),t.on("almost:move",(t=>this._onMouseMoveLayer(t))).on("almost:out",(t=>this._onMouseOut(t))))})):Promise.resolve()},_initDistanceMarkers:function(){return this.options.distanceMarkers?Promise.all([this.import(this.__LGEOMUTIL),this.import(this.__LDISTANCEM)]):Promise.resolve()},_initHotLine:function(t){let e="string"==typeof this.options.hotline?this.options.hotline:"elevation";return this.options.hotline?this.import(this.__LHOTLINE).then((()=>{t.eachLayer((t=>{if("Point"!=t.feature.geometry.type){let i=L.geoJson(t.toGeoJSON(),{coordsToLatLng:t=>L.latLng(t[0],t[1],t[2]*(this.options.altitudeFactor||1))}),a=L.hotline(i.toGeoJSON().features[0].geometry.coordinates,{renderer:L.Hotline.renderer(),min:isFinite(this.track_info[e+"_min"])?this.track_info[e+"_min"]:0,max:isFinite(this.track_info[e+"_max"])?this.track_info[e+"_max"]:1,palette:{0:"#008800",.5:"#ffff00",1:"#ff0000"},weight:5,outlineColor:"#000000",outlineWidth:1}).addTo(this._hotline),o=t.options.style&&t.options.style.opacity||1;t.on("add remove",(({type:e})=>{t.setStyle({opacity:"add"==e?0:o}),a["add"==e?"addTo":"removeFrom"](t._map),a._renderer&&a._renderer._container.parentElement.insertBefore(a._renderer._container,a._renderer._container.parentElement.firstChild)}))}}))})):Promise.resolve()},_initMapIntegrations:function(t){let e=this._map;e?(this._data.length&&(this._start.setLatLng(this._data[0].latlng),this._end.setLatLng(this._data[this._data.length-1].latlng)),Promise.all([this._initHotLine(t),this._initAlmostOverHandler(e,t),this._initDistanceMarkers()]).then((()=>{this.options.polyline&&(t.addTo(e),this._circleMarkers.addTo(e)),this.options.autofitBounds&&this.fitBounds(t.getBounds()),e.invalidateSize()}))):this.once("add",(()=>this._initMapIntegrations(t)))},_collapse:function(){d(this._container,"elevation-expanded","elevation-collapsed"),this._map&&this._map.invalidateSize()},_expand:function(){d(this._container,"elevation-collapsed","elevation-expanded"),this._map&&this._map.invalidateSize()},_fixCanvasPaths:function(){let e=L.Canvas.prototype._fillStroke,i=this,a=this.options.theme.split(" ")[0].replace("-theme",""),o=t[a]||{};L.Canvas.include({_fillStroke:function(t,s){if(i._layers.hasLayer(s)){let i=s.options;if(i.color=o.line||o.area||a,i.stroke=!!i.color,e.call(this,t,s),i.stroke&&0!==i.weight){let e=t.globalCompositeOperation||"source-over";t.globalCompositeOperation="destination-over",t.strokeStyle=o.outline||"#FFF",t.lineWidth=1.75*i.weight,t.stroke(),t.globalCompositeOperation=e}}else e.call(this,t,s)}})},_fixTooltipSize:function(){this.on("elechart_init",(()=>this.once("elechart_change elechart_hover",(({data:t,xCoord:e})=>{this._chartEnabled&&(this._chart._showDiagramIndicator(t,e),this._chart._showDiagramIndicator(t,e)),this._updateMarker(t)}))))},_findItemForLatLng:function(t){return this._data[this._chart._findIndexForLatLng(t)]},_findItemForX:function(t){return this._data[this._chart._findIndexForXCoord(t)]},_fireEvt:function(t,e,i){this.fire&&this.fire(t,e,i),this._map&&this._map.fire(t,e,i)},_hideMarker:function(){this.options.autohideMarker&&this._marker.remove()},_initChart:function(t){let e=this.options,i=this._map;if(e.detached){let{offsetWidth:t,offsetHeight:i}=this.eleDiv;t>0&&(e.width=t),i>20&&(e.height=i-20)}else{let{clientWidth:t}=i.getContainer();e._maxWidth=e._maxWidth>e.width?e._maxWidth:e.width,this._container.style.maxWidth=e._maxWidth+"px",e._maxWidth>t&&(e.width=t-30)}Promise.all([this.import(this.__D3),this.import(this.__LCHART)]).then((a=>{let o=this._chart=new(a[1]||A).Chart(e,this);this._x=this._chart._x,this._y=this._chart._y,d3.select(t).call(o.render()),o.on("reset_drag",this._hideMarker,this).on("mouse_enter",this._onMouseEnter,this).on("dragged",this._onDragEnd,this).on("mouse_move",this._onMouseMove,this).on("mouse_out",this._onMouseOut,this).on("ruler_filter",this._onRulerFilter,this).on("zoom",this._updateChart,this).on("elepath_toggle",this._onToggleChart,this).on("margins_updated",this._resizeChart,this),this.fire("elechart_init"),i.on("zoom viewreset zoomanim",this._hideMarker,this).on("resize",this._resetView,this).on("resize",this._resizeChart,this).on("rotate",this._rotateMarker,this).on("mousedown",this._resetDrag,this),v(i.getContainer(),"mousewheel",this._resetDrag,this),v(i.getContainer(),"touchstart",this._resetDrag,this),v(document,"keydown",this._onKeyDown,this),this.on("eledata_added eledata_loaded",this._updateChart,this).on("eledata_added eledata_loaded",this._updateSummary,this),this._updateChart(),this._updateSummary()}))},_initLayer:function(){this._layers.on("layeradd layerremove",(({layer:t,type:e})=>{let i=t.getElement&&t.getElement();l(i,this.options.polyline.className+" "+this.options.theme,"layeradd"==e),m(t,"mousemove",this._onMouseMoveLayer.bind(this),"layeradd"==e),m(t,"mouseout",this._onMouseOut.bind(this),"layeradd"==e)}))},_initMarker:function(t){let e=t.getPane("elevationPane");e||(e=this._pane=t.createPane("elevationPane",t.getPane("norotatePane")||t.getPane("mapPane")),e.style.zIndex=625,e.style.pointerEvents="none"),this._renderer&&this._renderer.remove(),this._renderer=L.svg({pane:"elevationPane"}).addTo(this._map),Promise.all([this.import(this.__D3),this.import(this.__LMARKER)]).then((t=>{this._marker=new(t[1]||A).Marker(this.options,this),this.fire("elechart_marker")}))},_initButton:function(t){if(L.DomEvent.disableClickPropagation(t).disableScrollPropagation(t),this.options.collapsed?this._collapse():this._expand(),this.options.autohide&&(v(t,"mouseover",this._expand,this),v(t,"mouseout",this._collapse,this),this._map.on("click",this._collapse,this)),this.options.closeBtn){let e=this._button=p("a","elevation-toggle-icon",{href:"#",title:L._("Elevation")},t);v(e,"click",L.DomEvent.stop),v(e,"click",this._toggle,this),v(e,"focus",this._toggle,this),fetch(this.__btnIcon).then((t=>t.ok&&t.text().then((t=>e.innerHTML=t))))}},_initSummary:function(t){this.import(this.__LSUMMARY).then((e=>{this._summary=new(e||A).Summary({summary:this.options.summary},this),this.on("elechart_init",(()=>{d3.select(t).call(this._summary.render())}))}))},_loadFile:function(t){fetch(t).then((t=>t.text())).then((e=>{this._downloadURL=t,this._parseFromString(e).then((t=>t&&this._loadLayer(t)))})).catch((t=>console.warn(t)))},_loadModules:function(t){let e=(t=t.map((t=>"string"==typeof t&&void 0!==A[t]?A[t]:t))).map((t=>"string"==typeof t&&this.import(this.__modulesFolder+t.toLowerCase()+".js")||t instanceof Promise&&t||Promise.resolve()));return Promise.all(e).then((e=>{y(e,((e,i)=>{let a=e&&Object.keys(e)[0];a&&(t[i]=A[a]=A[a]??e[a])})),y(t,(t=>["function","object"].includes(typeof t)&&this._registerHandler(t)))}))},_loadLayer:function(t){let{polyline:e,theme:i,waypoints:a,wptIcons:o,wptLabels:s,distanceMarkers:n}=this.options,r=L.extend({},e);i&&(r.className+=" "+i),t.name&&(this.track_info.name=t.name);let h=L.geoJson(t,{distanceMarkers:n,style:r,pointToLayer:(t,e)=>{if(a){let{desc:i,name:n,sym:r}=t.properties;if(i=i||"",n=n||"",[!0,"dots"].includes(a)&&this._registerCheckPoint({latlng:e,label:[!0,"dots"].includes(s)?n:""}),[!0,"markers"].includes(a)&&0!=o)return this._registerMarker({latlng:e,sym:(r??n).replace(" ","-").replace('"',"").replace("'","").toLowerCase(),content:[!0,"markers"].includes(s)&&(n||i)&&decodeURI("<b>"+n+"</b>"+(i.length>0?"<br>"+i:""))})}},onEachFeature:(t,e)=>t.geometry&&"Point"!=t.geometry.type&&this.addData(t,e)});return this.import(this.__D3).then((()=>{this._initMapIntegrations(h),this._fireEvt("eledata_loaded",{data:t,layer:h,name:this.track_info.name,track_info:this.track_info})})),h},_onDragEnd:function({dragstart:t,dragend:e}){this._hideMarker(),this.fitBounds(L.latLngBounds([t.latlng,e.latlng])),this.fire("elechart_dragged")},_onKeyDown:function({key:t}){this.options.detached||"Escape"!==t||this._collapse()},_onMouseEnter:function(){this.fire("elechart_enter")},_onMouseMove:function({xCoord:t}){if(this._chartEnabled&&this._data.length){let e=this._findItemForX(t);e&&(this._chartEnabled&&this._chart._showDiagramIndicator(e,t),this._updateMarker(e),this._setMapView(e),this._map&&r(this._map.getContainer(),"elechart-hover"),this.fire("elechart_change",{data:e,xCoord:t}),this.fire("elechart_hover",{data:e,xCoord:t}))}},_onMouseMoveLayer:function({latlng:t}){if(this._data.length){let e=this._findItemForLatLng(t);if(e){let t=e.xDiagCoord;this._chartEnabled&&this._chart._showDiagramIndicator(e,t),this._updateMarker(e),this.fire("elechart_change",{data:e,xCoord:t})}}},_onMouseOut:function(){this.options.detached||(this._hideMarker(),this._chart._hideDiagramIndicator()),this._map&&h(this._map.getContainer(),"elechart-hover"),this.fire("elechart_leave")},_onRulerFilter:function({coords:t}){this._updateMapSegments(t)},_onToggleChart:function({name:t,enabled:e}){this._chartEnabled=this._chart._hasActiveLayers(),this._layers.eachLayer((t=>l(t.getElement&&t.getElement(),this.options.polyline.className+" "+this.options.theme,this._chartEnabled))),this.options[t]=e||"disabled"!=this.options[t]?"disabled":"enabled",this._chartEnabled||(this._chart._hideDiagramIndicator(),this._marker.remove())},_parseFromGeoJSONString:function(t){try{return JSON.parse(t)}catch(t){}},_parseFromString:function(t){return new Promise((e=>this.import(this.__TOGEOJSON).then((()=>{let i;try{i=this._parseFromXMLString(t.trim())}catch(e){i=this._parseFromGeoJSONString(t.toString())}i&&(i.name=i.name||(this._downloadURL||"").split("/").pop().split("#")[0].split("?")[0]),e(i)}))))},_parseFromXMLString:function(t){if(0!=t.indexOf("<"))throw"Invalid XML";let e=(new DOMParser).parseFromString(t,"text/xml"),i=e.documentElement.tagName.toLowerCase(),a=e.getElementsByTagName("name");if(e.getElementsByTagName("parsererror").length)throw"Invalid XML";i in toGeoJSON||(i="TrainingCenterDatabase"==e.documentElement.tagName?"tcx":"gpx");let o=toGeoJSON[i](e);return o.name=a.length>0?(Array.from(a).find((t=>"trk"==t.parentElement.tagName))??a[0]).textContent:"",o},_registerAreaPath:function(t){this.on("elechart_init",(()=>this._chart._registerAreaPath(t)))},_registerAxisGrid:function(t){this.on("elechart_axis",(()=>this._chart._registerAxisGrid(t)))},_registerAxisScale:function(t){this.on("elechart_axis",(()=>this._chart._registerAxisScale(t)))},_registerCheckPoint:function(t){this.on("elechart_updated",(()=>this._chart._registerCheckPoint(t)))},_registerDataAttribute:function(t){let e,i,a,o;t.coordPropsToMeta&&this.on("elepoint_init",(e=>t.coordPropsToMeta.call(this,e)));let s=null;this.on("elepoint_added",(({index:n,point:r})=>{if(e=n,a=i??this._data[e],i=this._data[e],o=t.attr||t.name,!1===t.skipNull){let t=this._data[e][o];if(e>0){let i=this._data[e-1][o];if(isNaN(i)){if(isNaN(s)||isNaN(t)?isNaN(s)?isNaN(t)||(i=t):i=s:i=(s+t)/2,!isNaN(i))return this._data.splice(e-1,1);this._data[e-1][o]=i}}isNaN(t)||(s=t)}if(i[o]=t.pointToAttr.call(this,r,e),t.stats)for(const e in t.stats){let a=(t.statsName||o)+(""!=e?"_":"");this.track_info[a+e]=t.stats[e].call(this,i[o],this.track_info[a+e],this._data.length)}t.deltaMax&&(i[o]=D(i[o],a[o],t.deltaMax)),t.clampRange&&(i[o]=x(i[o],t.clampRange)),isNaN(t.decimals)||(i[o]=b(i[o],t.decimals)),t.onPointAdded&&t.onPointAdded.call(this,i[o],e,r)}))},_registerHandler:function(t){if("function"==typeof t)return this._registerHandler(t.call(this));let{name:e,attr:i,required:a,skipNull:o,deltaMax:n,clampRange:r,decimals:h,meta:l,unit:d,coordinateProperties:c,coordPropsToMeta:_,pointToAttr:m,onPointAdded:p,stats:u,statsName:f,grid:g,scale:k,path:v,tooltip:M,summary:w}=t;(this.options[e]||a)&&(this._registerDataAttribute({name:e,attr:i,skipNull:o,deltaMax:n,clampRange:r,decimals:h,coordPropsToMeta:s(c,l||e,_),pointToAttr:m,onPointAdded:p,stats:u,statsName:f}),g&&this._registerAxisGrid(L.extend({name:e},g)),"summary"!==this.options[e]&&(k&&this._registerAxisScale(L.extend({name:e,label:d},k)),v&&this._registerAreaPath(L.extend({name:e},v))),(M||t.tooltips)&&y([M,...t.tooltips||[]],(t=>t&&this._registerTooltip(L.extend({name:e},t)))),w&&(y(w,((t,e)=>w[e]=L.extend({unit:d},t))),this._registerSummary(w)))},_registerMarker({latlng:t,sym:e,content:i}){let{wptIcons:a}=this.options;a.hasOwnProperty(e)||(a[e]=L.divIcon(L.extend({},a[""].options,{html:'<i class="elevation-waypoint-icon '+e+'"></i>'})));let o=L.marker(t,{icon:a[e]});return i&&(o.bindPopup(i,{className:"elevation-popup",keepInView:!0}).openPopup(),o.bindTooltip(i,{className:"elevation-tooltip",direction:"auto",sticky:!0,opacity:1}).openTooltip()),this._addMarker(o)},_registerTooltip:function(t){t.chart&&this.on("elechart_init",(()=>this._chart._registerTooltip(L.extend({},t,{value:t.chart})))),t.marker&&this.on("elechart_marker",(()=>this._marker._registerTooltip(L.extend({},t,{value:t.marker}))))},_registerSummary:function(t){this.on("elechart_summary",(()=>this._summary._registerSummary(t)))},_resetDrag:function(){this._chart._resetDrag(),this._hideMarker()},_resetView:function(){this._map&&this._map._isFullscreen||(this._resetDrag(),this._hideMarker(),this.options.autofitBounds&&this.fitBounds())},_resizeChart:function(){if(this._container&&"none"!=c(this._container,"display")){let t=this.options,e=t.detached?(this.eleDiv||this._container).offsetWidth:x(t._maxWidth,[0,this._map.getContainer().clientWidth-30]);e&&(t.width=e,this._chart&&this._chart._chart&&(this._chart._chart._resize(t),this._updateChart())),this._updateMapSegments()}},_toggle:function(){C(this._container,"elevation-expanded")?this._collapse():this._expand()},_setMapView:function(t){if(this._map&&this.options.followMarker){let e=this._map.getZoom(),i=this.options.zFollow;"number"==typeof i?this._map.setView(t.latlng,e<i?i:e,{animate:!0,duration:.25}):this._map.getBounds().contains(t.latlng)||this._map.setView(t.latlng,e,{animate:!0,duration:.25})}},_updateChart:function(){this._chart&&this._container&&(this.fire("elechart_axis"),this._chart.update({data:this._data,options:this.options}),this._x=this._chart._x,this._y=this._chart._y,this.fire("elechart_updated"))},_updateMarker:function(t){this._marker&&this._marker.update({map:this._map,item:t,yCoordMax:this._yCoordMax||0,options:this.options})},_rotateMarker:function(){this._marker&&this._marker.update()},_updateMapSegments:function(t){this._markedSegments.setLatLngs(t||[]),t&&this._map&&!this._map.hasLayer(this._markedSegments)&&this._markedSegments.addTo(this._map)},_updateSummary:function(){this._summary&&(this._summary.reset(),this.options.summary&&(this.fire("elechart_summary"),this._summary.update()),this.options.downloadLink&&this._downloadURL&&(this._summary._container.innerHTML+='<span class="download"><a href="#">'+L._("Download")+"</a></span>",g(".download a",this._summary._container).onclick=t=>{t.preventDefault();let e={downloadLink:this.options.downloadLink,confirm:o.bind(this,this._downloadURL)};"modal"==this.options.downloadLink&&"function"==typeof CustomEvent?document.dispatchEvent(new CustomEvent("eletrack_download",{detail:e})):"link"!=this.options.downloadLink&&!0!==this.options.downloadLink||e.confirm(),this.fire("eletrack_download",e)}))},_width:function(){if(this._chart)return this._chart._width();const{width:t,margins:e}=this.options;return t-e.left-e.right},_height:function(){if(this._chart)return this._chart._height();const{height:t,margins:e}=this.options;return t-e.top-e.bottom}});A.Utils=E,L.control.elevation=t=>new A(t)}));
|
|
2
2
|
//# sourceMappingURL=leaflet-elevation.min.js.map
|