nc-gpxedit/js/Leaflet.Elevation-0.0.2.min.js

2 lines
9.6 KiB
JavaScript
Raw Normal View History

2016-11-30 19:00:03 +00:00
/*! Leaflet.Elevation 21-02-2014 */
L.Control.Elevation=L.Control.extend({options:{position:"topright",theme:"lime-theme",width:600,height:175,margins:{top:10,right:20,bottom:30,left:50},useHeightIndicator:!0,interpolation:"linear",hoverNumber:{decimalsX:3,decimalsY:0,formatter:void 0},xTicks:void 0,yTicks:void 0,collapsed:!1},onRemove:function(){this._container=null,this._data=null,this._dist=null},onAdd:function(a){this._map=a;var b=this.options,c=b.margins;b.width=b.width-c.left-c.right,b.height=b.height-c.top-c.bottom,b.xTicks=b.xTicks||Math.round(b.width/75),b.yTicks=b.yTicks||Math.round(b.height/30),b.hoverNumber.formatter=b.hoverNumber.formatter||this._formatter,d3.select("body").classed(b.theme,!0);var d=this._x=d3.scale.linear().range([0,b.width]),e=this._y=d3.scale.linear().range([b.height,0]),f=(this._area=d3.svg.area().interpolate(b.interpolation).x(function(a){return d(a.dist)}).y0(b.height).y1(function(a){return e(a.altitude)}),this._container=L.DomUtil.create("div","elevation"));this._initToggle();var g=b.width+c.left+c.right,h=d3.select(f);h.attr("width",g);var i=h.append("svg");i.attr("width",g).attr("class","background").attr("height",b.height+c.top+c.bottom).append("g").attr("transform","translate("+c.left+","+c.top+")");var j=d3.svg.line();j=j.x(function(){return d3.mouse(i.select("g"))[0]}).y(function(){return b.height});var k=d3.select(this._container).select("svg").select("g");this._areapath=k.append("path").attr("class","area");var l=this._background=k.append("rect").attr("width",b.width).attr("height",b.height).style("fill","none").style("stroke","none").style("pointer-events","all");L.Browser.touch?(l.on("touchmove.drag",this._dragHandler.bind(this)).on("touchstart.drag",this._dragStartHandler.bind(this)).on("touchstart.focus",this._mousemoveHandler.bind(this)),L.DomEvent.on(this._container,"touchend",this._dragEndHandler,this)):(l.on("mousemove.focus",this._mousemoveHandler.bind(this)).on("mouseout.focus",this._mouseoutHandler.bind(this)).on("mousedown.drag",this._dragStartHandler.bind(this)).on("mousemove.drag",this._dragHandler.bind(this)),L.DomEvent.on(this._container,"mouseup",this._dragEndHandler,this)),this._xaxisgraphicnode=k.append("g"),this._yaxisgraphicnode=k.append("g"),this._appendXaxis(this._xaxisgraphicnode),this._appendYaxis(this._yaxisgraphicnode);var m=this._focusG=k.append("g");return this._mousefocus=m.append("svg:line").attr("class","mouse-focus-line").attr("x2","0").attr("y2","0").attr("x1","0").attr("y1","0"),this._focuslabelX=m.append("svg:text").style("pointer-events","none").attr("class","mouse-focus-label-x"),this._focuslabelY=m.append("svg:text").style("pointer-events","none").attr("class","mouse-focus-label-y"),f},_dragHandler:function(){d3.event.preventDefault(),d3.event.stopPropagation(),this._gotDragged=!0,this._drawDragRectangle()},_drawDragRectangle:function(){if(this._dragStartCoords){var a=this._dragCurrentCoords=d3.mouse(this._background.node()),b=Math.min(this._dragStartCoords[0],a[0]),c=Math.max(this._dragStartCoords[0],a[0]);if(this._dragRectangle||this._dragRectangleG)this._dragRectangle.attr("width",c-b).attr("x",b);else{var d=d3.select(this._container).select("svg").select("g");this._dragRectangleG=d.append("g"),this._dragRectangle=this._dragRectangleG.append("rect").attr("width",c-b).attr("height",this.options.height).attr("x",b).attr("class","mouse-drag").style("pointer-events","none")}}},_resetDrag:function(){if(this._dragRectangleG){this._dragRectangleG.remove(),this._dragRectangleG=null,this._dragRectangle=null,this._hidePositionMarker();var a=L.latLngBounds(this._data[0].latlng,this._data[0].latlng);a.extend(this._data[this._data.length-1].latlng),this._map.fitBounds(a)}},_dragEndHandler:function(){if(!this._dragStartCoords||!this._gotDragged)return this._dragStartCoords=null,this._gotDragged=!1,void this._resetDrag();this._hidePositionMarker();var a=this._findItemForX(this._dragStartCoords[0]),b=this._findItemForX(this._dragCurrentCoords[0]),c=L.latLngBounds(a.latlng,a.latlng);c.extend(b.latlng),this._map.fitBounds(c),this._dragStartCoords=null,this._gotDragged=!1},_dragStartHandl