Replace Leaftlet Elevation with HeightGraph

This commit is contained in:
franzz committed 2020-04-20 11:57:53 +02:00
1 parent 0c5edb862b
commit ead9cf3a49
15 files changed
+359 -957

No files matched your search

+2 -2
View File
@@ -1,2 +1,2 @@
// https://d3js.org v5.9.1 Copyright 2019 Mike Bostock
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})}(this,function(t){"use strict";function n(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function e(t){var e;return 1===t.length&&(e=t,t=function(t,r){return n(e(t),r)}),{left:function(n,e,r,i){for(null==r&&(r=0),null==i&&(i=n.length);r<i;){var o=r+i>>>1;t(n[o],e)<0?r=o+1:i=o}return r},right:function(n,e,r,i){for(null==r&&(r=0),null==i&&(i=n.length);r<i;){var o=r+i>>>1;t(n[o],e)>0?i=o:r=o+1}return r}}}var r=e(n),i=r.right,o=r.left;function a(t,n){return[t,n]}function u(t){return null===t?NaN:+t}function c(t,n){var e,r,i=t.length,o=0,a=-1,c=0,f=0;if(null==n)for(;++a<i;)isNaN(e=u(t[a]))||(f+=(r=e-c)*(e-(c+=r/++o)));else for(;++a<i;)isNaN(e=u(n(t[a],a,t)))||(f+=(r=e-c)*(e-(c+=r/++o)));if(o>1)return f/(o-1)}function f(t,n){var e=c(t,n);return e?Math.sqrt(e):e}function s(t,n){var e,r,i,o=t.length,a=-1;if(null==n){for(;++a<o;)if(null!=(e=t[a])&&e>=e)for(r=i=e;++a<o;)null!=(e=t[a])&&(r>e&&(r=e),i<e&&(i=e))}else for(;++a<o;)if(null!=(e=n(t[a],a,t))&&e>=e)for(r=i=e;++a<o;)null!=(e=n(t[a],a,t))&&(r>e&&(r=e),i<e&&(i=e));return[r,i]}var l=Array.prototype,h=l.slice,d=l.map;function p(t){return function(){return t}}function v(t){return t}function g(t,n,e){t=+t,n=+n,e=(i=arguments.length)<2?(n=t,t=0,1):i<3?1:+e;for(var r=-1,i=0|Math.max(0,Math.ceil((n-t)/e)),o=new Array(i);++r<i;)o[r]=t+r*e;return o}var y=Math.sqrt(50),_=Math.sqrt(10),b=Math.sqrt(2);function m(t,n,e){var r,i,o,a,u=-1;if(e=+e,(t=+t)===(n=+n)&&e>0)return[t];if((r=n<t)&&(i=t,t=n,n=i),0===(a=x(t,n,e))||!isFinite(a))return[];if(a>0)for(t=Math.ceil(t/a),n=Math.floor(n/a),o=new Array(i=Math.ceil(n-t+1));++u<i;)o[u]=(t+u)*a;else for(t=Math.floor(t*a),n=Math.ceil(n*a),o=new Array(i=Math.ceil(t-n+1));++u<i;)o[u]=(t-u)/a;return r&&o.reverse(),o}function x(t,n,e){var r=(n-t)/Math.max(0,e),i=Math.floor(Math.log(r)/Math.LN10),o=r/Math.pow(10,i);return i>=0?(o>=y?10:o>=_?5:o>=b?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(o>=y?10:o>=_?5:o>=b?2:1)}function w(t,n,e){var r=Math.abs(n-t)/Math.max(0,e),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),o=r/i;return o>=y?i*=10:o>=_?i*=5:o>=b&&(i*=2),n<t?-i:i}function M(t){return Math.ceil(Math.log(t.length)/Math.LN2)+1}function N(t,n,e){if(null==e&&(e=u),r=t.length){if((n=+n)<=0||r<2)return+e(t[0],0,t);if(n>=1)return+e(t[r-1],r-1,t);var r,i=(r-1)*n,o=Math.floor(i),a=+e(t[o],o,t);return a+(+e(t[o+1],o+1,t)-a)*(i-o)}}function A(t,n){var e,r,i=t.length,o=-1;if(null==n){for(;++o<i;)if(null!=(e=t[o])&&e>=e)for(r=e;++o<i;)null!=(e=t[o])&&e>r&&(r=e)}else for(;++o<i;)if(null!=(e=n(t[o],o,t))&&e>=e)for(r=e;++o<i;)null!=(e=n(t[o],o,t))&&e>r&&(r=e);return r}function T(t){for(var n,e,r,i=t.length,o=-1,a=0;++o<i;)a+=t[o].length;for(e=new Array(a);--i>=0;)for(n=(r=t[i]).length;--n>=0;)e[--a]=r[n];return e}function S(t,n){var e,r,i=t.length,o=-1;if(null==n){for(;++o<i;)if(null!=(e=t[o])&&e>=e)for(r=e;++o<i;)null!=(e=t[o])&&r>e&&(r=e)}else for(;++o<i;)if(null!=(e=n(t[o],o,t))&&e>=e)for(r=e;++o<i;)null!=(e=n(t[o],o,t))&&r>e&&(r=e);return r}function k(t){if(!(i=t.length))return[];for(var n=-1,e=S(t,E),r=new Array(e);++n<e;)for(var i,o=-1,a=r[n]=new Array(i);++o<i;)a[o]=t[o][n];return r}function E(t){return t.length}var C=Array.prototype.slice;function P(t){return t}var z=1,R=2,D=3,q=4,L=1e-6;function U(t){return"translate("+(t+.5)+",0)"}function O(t){return"translate(0,"+(t+.5)+")"}function B(){return!this.__axis}function Y(t,n){var e=[],r=null,i=null,o=6,a=6,u=3,c=t===z||t===q?-1:1,f=t===q||t===R?"x":"y",s=t===z||t===D?U:O;function l(l){var h=null==r?n.ticks?n.ticks.apply(n,e):n.domain():r,d=null==i?n.tickFormat?n.tickFormat.apply(n,e):P:i,p=Math.max(o,0)+u,v=n.range(),g=+v[0]+.5,y=+v[v.length-1]+.5,_=(n.bandwidth?function(t){var n=Math.max(0,t.bandwidth()-1)/2;return t.round()&&(n=Math.round(n)),function(e){return+t(e)+n}}:function(t){return function(n){return+t(n)}})(n.copy()),b=l.selection?l.selection():l,m=b.selectAll(".domain").data([null]),x=b.selectAll(".tick").data(h,n).order(),w=x.exit(),M=x.enter().append("g").attr("class","tick"),N=x.select("line"),A=x.select("text");m=m.merge(m.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),x=x.merge(M),N=N.merge(M.append("line").attr("stroke","currentColor").attr(f+"2",c*o)),A=A.merge(M.append("text").attr("fill","currentColor").attr(f,c*p).attr("dy",t===z?"0em":t===D?"0.71em":"0.32em")),l!==b&&(m=m.transition(l),x=x.transition(l),N=N.transition(l),A=A.transition(l),w=w.transition(l).attr("opacity",L).attr("transform",function(t){return isFinite(t=_(t))?s(t):this.getAttribute("transform")}),M.attr("opacity",L).attr("transform",function(t){var n=this.parentNode.__axis;return s(n&&isFinite(n=n(t))?n:_(t))})),w.remove(),m.attr("d",t===q||t==R?a?"M"+c*a+","+g+"H0.5V"+y+"H"+c*a:"M0.5,"+g+"V"+y:a?"M"+g+","+c*a+"V0.5H"+y+"V"+c*a:"M"+g+",0.5H"+y),x.attr("opacity",1).attr("transform",function(t){return s(_(t))}),N.attr(f+"2",c*o),A.aLine truncated
// https://d3js.org v5.15.1 Copyright 2020 Mike Bostock
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).d3=t.d3||{})}(this,function(t){"use strict";function n(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function e(t){var e;return 1===t.length&&(e=t,t=function(t,r){return n(e(t),r)}),{left:function(n,e,r,i){for(null==r&&(r=0),null==i&&(i=n.length);r<i;){var o=r+i>>>1;t(n[o],e)<0?r=o+1:i=o}return r},right:function(n,e,r,i){for(null==r&&(r=0),null==i&&(i=n.length);r<i;){var o=r+i>>>1;t(n[o],e)>0?i=o:r=o+1}return r}}}var r=e(n),i=r.right,o=r.left;function a(t,n){return[t,n]}function u(t){return null===t?NaN:+t}function c(t,n){var e,r,i=t.length,o=0,a=-1,c=0,f=0;if(null==n)for(;++a<i;)isNaN(e=u(t[a]))||(f+=(r=e-c)*(e-(c+=r/++o)));else for(;++a<i;)isNaN(e=u(n(t[a],a,t)))||(f+=(r=e-c)*(e-(c+=r/++o)));if(o>1)return f/(o-1)}function f(t,n){var e=c(t,n);return e?Math.sqrt(e):e}function s(t,n){var e,r,i,o=t.length,a=-1;if(null==n){for(;++a<o;)if(null!=(e=t[a])&&e>=e)for(r=i=e;++a<o;)null!=(e=t[a])&&(r>e&&(r=e),i<e&&(i=e))}else for(;++a<o;)if(null!=(e=n(t[a],a,t))&&e>=e)for(r=i=e;++a<o;)null!=(e=n(t[a],a,t))&&(r>e&&(r=e),i<e&&(i=e));return[r,i]}var l=Array.prototype,h=l.slice,d=l.map;function p(t){return function(){return t}}function v(t){return t}function g(t,n,e){t=+t,n=+n,e=(i=arguments.length)<2?(n=t,t=0,1):i<3?1:+e;for(var r=-1,i=0|Math.max(0,Math.ceil((n-t)/e)),o=new Array(i);++r<i;)o[r]=t+r*e;return o}var y=Math.sqrt(50),_=Math.sqrt(10),b=Math.sqrt(2);function m(t,n,e){var r,i,o,a,u=-1;if(e=+e,(t=+t)===(n=+n)&&e>0)return[t];if((r=n<t)&&(i=t,t=n,n=i),0===(a=x(t,n,e))||!isFinite(a))return[];if(a>0)for(t=Math.ceil(t/a),n=Math.floor(n/a),o=new Array(i=Math.ceil(n-t+1));++u<i;)o[u]=(t+u)*a;else for(t=Math.floor(t*a),n=Math.ceil(n*a),o=new Array(i=Math.ceil(t-n+1));++u<i;)o[u]=(t-u)/a;return r&&o.reverse(),o}function x(t,n,e){var r=(n-t)/Math.max(0,e),i=Math.floor(Math.log(r)/Math.LN10),o=r/Math.pow(10,i);return i>=0?(o>=y?10:o>=_?5:o>=b?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(o>=y?10:o>=_?5:o>=b?2:1)}function w(t,n,e){var r=Math.abs(n-t)/Math.max(0,e),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),o=r/i;return o>=y?i*=10:o>=_?i*=5:o>=b&&(i*=2),n<t?-i:i}function M(t){return Math.ceil(Math.log(t.length)/Math.LN2)+1}function N(t,n,e){if(null==e&&(e=u),r=t.length){if((n=+n)<=0||r<2)return+e(t[0],0,t);if(n>=1)return+e(t[r-1],r-1,t);var r,i=(r-1)*n,o=Math.floor(i),a=+e(t[o],o,t);return a+(+e(t[o+1],o+1,t)-a)*(i-o)}}function T(t,n){var e,r,i=t.length,o=-1;if(null==n){for(;++o<i;)if(null!=(e=t[o])&&e>=e)for(r=e;++o<i;)null!=(e=t[o])&&e>r&&(r=e)}else for(;++o<i;)if(null!=(e=n(t[o],o,t))&&e>=e)for(r=e;++o<i;)null!=(e=n(t[o],o,t))&&e>r&&(r=e);return r}function A(t){for(var n,e,r,i=t.length,o=-1,a=0;++o<i;)a+=t[o].length;for(e=new Array(a);--i>=0;)for(n=(r=t[i]).length;--n>=0;)e[--a]=r[n];return e}function S(t,n){var e,r,i=t.length,o=-1;if(null==n){for(;++o<i;)if(null!=(e=t[o])&&e>=e)for(r=e;++o<i;)null!=(e=t[o])&&r>e&&(r=e)}else for(;++o<i;)if(null!=(e=n(t[o],o,t))&&e>=e)for(r=e;++o<i;)null!=(e=n(t[o],o,t))&&r>e&&(r=e);return r}function k(t){if(!(i=t.length))return[];for(var n=-1,e=S(t,E),r=new Array(e);++n<e;)for(var i,o=-1,a=r[n]=new Array(i);++o<i;)a[o]=t[o][n];return r}function E(t){return t.length}var C=Array.prototype.slice;function P(t){return t}var z=1,R=2,D=3,q=4,L=1e-6;function U(t){return"translate("+(t+.5)+",0)"}function O(t){return"translate(0,"+(t+.5)+")"}function B(){return!this.__axis}function F(t,n){var e=[],r=null,i=null,o=6,a=6,u=3,c=t===z||t===q?-1:1,f=t===q||t===R?"x":"y",s=t===z||t===D?U:O;function l(l){var h=null==r?n.ticks?n.ticks.apply(n,e):n.domain():r,d=null==i?n.tickFormat?n.tickFormat.apply(n,e):P:i,p=Math.max(o,0)+u,v=n.range(),g=+v[0]+.5,y=+v[v.length-1]+.5,_=(n.bandwidth?function(t){var n=Math.max(0,t.bandwidth()-1)/2;return t.round()&&(n=Math.round(n)),function(e){return+t(e)+n}}:function(t){return function(n){return+t(n)}})(n.copy()),b=l.selection?l.selection():l,m=b.selectAll(".domain").data([null]),x=b.selectAll(".tick").data(h,n).order(),w=x.exit(),M=x.enter().append("g").attr("class","tick"),N=x.select("line"),T=x.select("text");m=m.merge(m.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),x=x.merge(M),N=N.merge(M.append("line").attr("stroke","currentColor").attr(f+"2",c*o)),T=T.merge(M.append("text").attr("fill","currentColor").attr(f,c*p).attr("dy",t===z?"0em":t===D?"0.71em":"0.32em")),l!==b&&(m=m.transition(l),x=x.transition(l),N=N.transition(l),T=T.transition(l),w=w.transition(l).attr("opacity",L).attr("transform",function(t){return isFinite(t=_(t))?s(t):this.getAttribute("transform")}),M.attr("opacity",L).attr("transform",function(t){var n=this.parentNode.__axis;return s(n&&isFinite(n=n(t))?n:_(t))})),w.remove(),m.attr("d",t===q||t==R?a?"M"+c*a+","+g+"H0.5V"+y+"H"+c*a:"M0.5,"+g+"V"+y:a?"M"+g+","+c*a+"V0.5H"+y+"V"+c*a:"M"+g+",0.5H"+y),x.attr("opacity",1).attr("transform",function(t){return s(_(t))}),N.attr(f+"2Line truncated
+4 -822
View File
@@ -4,9 +4,12 @@
*/
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i(t.L={})}(this,function(t){"use strict";var i=Object.freeze;function h(t){var i,e,n,o;for(e=1,n=arguments.length;e<n;e++)for(i in o=arguments[e])t[i]=o[i];return t}Object.freeze=function(t){return t};var s=Object.create||function(t){return e.prototype=t,new e};function e(){}function a(t,i){var e=Array.prototype.slice;if(t.bind)return t.bind.apply(t,e.call(arguments,1));var n=e.call(arguments,2);return function(){return t.apply(i,n.length?n.concat(e.call(arguments)):arguments)}}var n=0;function u(t){return t._leaflet_id=t._leaflet_id||++n,t._leaflet_id}function o(t,i,e){var n,o,s,r;return r=function(){n=!1,o&&(s.apply(e,o),o=!1)},s=function(){n?o=arguments:(t.apply(e,arguments),setTimeout(r,i),n=!0)}}function r(t,i,e){var n=i[1],o=i[0],s=n-o;return t===n&&e?t:((t-o)%s+s)%s+o}function l(){return!1}function c(t,i){var e=Math.pow(10,void 0===i?6:i);return Math.round(t*e)/e}function _(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function d(t){return _(t).split(/\s+/)}function p(t,i){for(var e in t.hasOwnProperty("options")||(t.options=t.options?s(t.options):{}),i)t.options[e]=i[e];return t.options}function m(t,i,e){var n=[];for(var o in t)n.push(encodeURIComponent(e?o.toUpperCase():o)+"="+encodeURIComponent(t[o]));return(i&&-1!==i.indexOf("?")?"&":"?")+n.join("&")}var f=/\{ *([\w_-]+) *\}/g;function g(t,n){return t.replace(f,function(t,i){var e=n[i];if(void 0===e)throw new Error("No value provided for variable "+t);return"function"==typeof e&&(e=e(n)),e})}var v=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function y(t,i){for(var e=0;e<t.length;e++)if(t[e]===i)return e;return-1}var x="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";function w(t){return window["webkit"+t]||window["moz"+t]||window["ms"+t]}var P=0;function b(t){var i=+new Date,e=Math.max(0,16-(i-P));return P=i+e,window.setTimeout(t,e)}var T=window.requestAnimationFrame||w("RequestAnimationFrame")||b,z=window.cancelAnimationFrame||w("CancelAnimationFrame")||w("CancelRequestAnimationFrame")||function(t){window.clearTimeout(t)};function M(t,i,e){if(!e||T!==b)return T.call(window,a(t,i));t.call(i)}function C(t){t&&z.call(window,t)}var E=(Object.freeze||Object)({freeze:i,extend:h,create:s,bind:a,lastId:n,stamp:u,throttle:o,wrapNum:r,falseFn:l,formatNum:c,trim:_,splitWords:d,setOptions:p,getParamString:m,template:g,isArray:v,indexOf:y,emptyImageUrl:x,requestFn:T,cancelFn:z,requestAnimFrame:M,cancelAnimFrame:C});function S(){}S.extend=function(t){function i(){this.initialize&&this.initialize.apply(this,arguments),this.callInitHooks()}var e=i.__super__=this.prototype,n=s(e);for(var o in(n.constructor=i).prototype=n,this)this.hasOwnProperty(o)&&"prototype"!==o&&"__super__"!==o&&(i[o]=this[o]);return t.statics&&(h(i,t.statics),delete t.statics),t.includes&&(function(t){if("undefined"==typeof L||!L||!L.Mixin)return;t=v(t)?t:[t];for(var i=0;i<t.length;i++)t[i]===L.Mixin.Events&&console.warn("Deprecated include of L.Mixin.Events: this property will be removed in future releases, please inherit from L.Evented instead.",(new Error).stack)}(t.includes),h.apply(null,[n].concat(t.includes)),delete t.includes),n.options&&(t.options=h(s(n.options),t.options)),h(n,t),n._initHooks=[],n.callInitHooks=function(){if(!this._initHooksCalled){e.callInitHooks&&e.callInitHooks.call(this),this._initHooksCalled=!0;for(var t=0,i=n._initHooks.length;t<i;t++)n._initHooks[t].call(this)}},i},S.include=function(t){return h(this.prototype,t),this},S.mergeOptions=function(t){return h(this.prototype.options,t),this},S.addInitHook=function(t){var i=Array.prototype.slice.call(arguments,1),e="function"==typeof t?t:function(){this[t].apply(this,i)};return this.prototype._initHooks=this.prototype._initHooks||[],this.prototype._initHooks.push(e),this};var Z={on:function(t,i,e){if("object"==typeof t)for(var n in t)this._on(n,t[n],i);else for(var o=0,s=(t=d(t)).length;o<s;o++)this._on(t[o],i,e);return this},off:function(t,i,e){if(t)if("object"==typeof t)for(var n in t)this._off(n,t[n],i);else for(var o=0,s=(t=d(t)).length;o<s;o++)this._off(t[o],i,e);else delete this._events;return this},_on:function(t,i,e){this._events=this._events||{};var n=this._events[t];n||(n=[],this._events[t]=n),e===this&&(e=void 0);for(var o={fn:i,ctx:e},s=n,r=0,a=s.length;r<a;r++)if(s[r].fn===i&&s[r].ctx===e)return;s.push(o)},_off:function(t,i,e){var n,o,s;if(this._events&&(n=this._events[t]))if(i){if(e===this&&(e=void 0),n)for(o=0,s=n.length;o<s;o++){var r=n[o];if(r.ctx===e&&r.fn===i)return r.fn=l,this._firingCount&&(this._events[t]=n=n.slice()),void n.splice(o,1)}}else{for(o=0,s=n.length;o<s;o++)n[o].fn=l;delete this._events[t]}},fire:function(t,i,e){if(!this.listens(t,e))return this;var n=h({},i,{type:t,target:this,sourceTarget:i&&i.sourceTarget||this});if(this._events){var o=this._events[t];if(o){this._firingCount=this.Line truncated
/*Leaflet.GeometryUtil - v0.9.1 - https://github.com/makinacorpus/Leaflet.GeometryUtil/blob/master/src/leaflet.geometryutil.js - */
/* Leaflet.GeometryUtil - v0.9.1 - https://github.com/makinacorpus/Leaflet.GeometryUtil/blob/master/src/leaflet.geometryutil.js - BSD 3-Clause "New" or "Revised" License */
!function(t){var e;if("function"==typeof define&&define.amd)define(["leaflet"],t);else if("undefined"!=typeof module)e=require("leaflet"),module.exports=t(e);else{if(void 0===window.L)throw"Leaflet must be loaded first";t(window.L)}}(function(t){"use strict";return t.Polyline._flat=t.LineUtil.isFlat||t.Polyline._flat||function(e){return!t.Util.isArray(e[0])||"object"!=typeof e[0][0]&&void 0!==e[0][0]},t.GeometryUtil=t.extend(t.GeometryUtil||{},{distance:function(t,e,n){return t.latLngToLayerPoint(e).distanceTo(t.latLngToLayerPoint(n))},distanceSegment:function(e,n,r,a){var i=e.latLngToLayerPoint(n),o=e.latLngToLayerPoint(r),l=e.latLngToLayerPoint(a);return t.LineUtil.pointToSegmentDistance(i,o,l)},readableDistance:function(t,e){return"imperial"!==e?t>1e3?(t/1e3).toFixed(2)+" km":Math.ceil(t)+" m":(t*=1.09361)>1760?(t/1760).toFixed(2)+" miles":Math.ceil(t)+" yd"},belongsSegment:function(t,e,n,r){r=void 0===r?.2:r;var a=e.distanceTo(n);return(e.distanceTo(t)+t.distanceTo(n)-a)/a<r},length:function(e){var n=t.GeometryUtil.accumulatedLengths(e);return n.length>0?n[n.length-1]:0},accumulatedLengths:function(t){if("function"==typeof t.getLatLngs&&(t=t.getLatLngs()),0===t.length)return[];for(var e=0,n=[0],r=0,a=t.length-1;r<a;r++)e+=t[r].distanceTo(t[r+1]),n.push(e);return n},closestOnSegment:function(e,n,r,a){var i=e.getMaxZoom();i===1/0&&(i=e.getZoom());var o=e.project(n,i),l=e.project(r,i),s=e.project(a,i),c=t.LineUtil.closestPointOnSegment(o,l,s);return e.unproject(c,i)},closest:function(e,n,r,a){var i,o,l,s,c,u=1/0,g=null;if(n instanceof Array){if(n[0]instanceof Array&&"number"!=typeof n[0][0]){for(o=0;o<n.length;o++)(c=t.GeometryUtil.closest(e,n[o],r,a))&&c.distance<u&&(u=c.distance,g=c);return g}if(!(n[0]instanceof t.LatLng||"number"==typeof n[0][0]||"number"==typeof n[0].lat))return g;n=t.polyline(n)}if(!(n instanceof t.Polyline))return g;if(i=JSON.parse(JSON.stringify(n.getLatLngs().slice(0))),n instanceof t.Polygon){var f=function(e){if(t.Polyline._flat(e))e.push(e[0]);else for(var n=0;n<e.length;n++)f(e[n])};f(i)}if(t.Polyline._flat(i)){if(a){for(o=0,l=i.length;o<l;o++){var y=i[o];(s=t.GeometryUtil.distance(e,r,y))<u&&(u=s,(g=y).distance=s)}return g}for(o=0,l=i.length;o<l-1;o++){var L=i[o],h=i[o+1];(s=t.GeometryUtil.distanceSegment(e,r,L,h))<=u&&(u=s,(g=t.GeometryUtil.closestOnSegment(e,r,L,h)).distance=s)}return g}for(o=0;o<i.length;o++)(c=t.GeometryUtil.closest(e,i[o],r,a)).distance<u&&(u=c.distance,g=c);return g},closestLayer:function(e,n,r){for(var a=1/0,i=null,o=null,l=1/0,s=0,c=n.length;s<c;s++){var u=n[s];if(u instanceof t.LayerGroup){var g=t.GeometryUtil.closestLayer(e,u.getLayers(),r);g.distance<a&&(a=g.distance,i=g)}else"function"==typeof u.getLatLng?(o=u.getLatLng(),l=t.GeometryUtil.distance(e,r,o)):(o=t.GeometryUtil.closest(e,u,r))&&(l=o.distance),l<a&&(a=l,i={layer:u,latlng:o,distance:l})}return i},nClosestLayers:function(e,n,r,a){if((a="number"==typeof a?a:n.length)<1||n.length<1)return null;for(var i,o,l=[],s=0,c=n.length;s<c;s++){var u=n[s];if(u instanceof t.LayerGroup){var g=t.GeometryUtil.closestLayer(e,u.getLayers(),r);l.push(g)}else"function"==typeof u.getLatLng?(o=u.getLatLng(),i=t.GeometryUtil.distance(e,r,o)):(o=t.GeometryUtil.closest(e,u,r))&&(i=o.distance),l.push({layer:u,latlng:o,distance:i})}return l.sort(function(t,e){return t.distance-e.distance}),l.length>a?l.slice(0,a):l},layersWithin:function(e,n,r,a){a="number"==typeof a?a:1/0;for(var i=[],o=null,l=0,s=0,c=n.length;s<c;s++){var u=n[s];"function"==typeof u.getLatLng?(o=u.getLatLng(),l=t.GeometryUtil.distance(e,r,o)):(o=t.GeometryUtil.closest(e,u,r))&&(l=o.distance),o&&l<a&&i.push({layer:u,latlng:o,distance:l})}return i.sort(function(t,e){return t.distance-e.distance})},closestLayerSnap:function(e,n,r,a,i){a="number"==typeof a?a:1/0,i="boolean"!=typeof i||i;var o=t.GeometryUtil.closestLayer(e,n,r);if(!o||o.distance>a)return null;if(i&&"function"==typeof o.layer.getLatLngs){var l=t.GeometryUtil.closest(e,o.layer,o.latlng,!0);l.distance<a&&(o.latlng=l,o.distance=t.GeometryUtil.distance(e,l,r))}return o},interpolateOnPointSegment:function(e,n,r){return t.point(e.x*(1-r)+r*n.x,e.y*(1-r)+r*n.y)},interpolateOnLine:function(e,n,r){var a=(n=n instanceof t.Polyline?n.getLatLngs():n).length;if(a<2)return null;if(0===(r=Math.max(Math.min(r,1),0)))return{latLng:n[0]instanceof t.LatLng?n[0]:t.latLng(n[0]),predecessor:-1};if(1==r)return{latLng:n[n.length-1]instanceof t.LatLng?n[n.length-1]:t.latLng(n[n.length-1]),predecessor:n.length-2};var i=e.getMaxZoom();i===1/0&&(i=e.getZoom());for(var o=[],l=0,s=0;s<a;s++)o[s]=e.project(n[s],i),s>0&&(l+=o[s-1].distanceTo(o[s]));var c=l*r,u=0,g=0;for(s=0;g<c;s++){var f=o[s],y=o[s+1];u=g,g+=f.distanceTo(y)}if(null==f&&null==y)f=o[0],y=o[1],s=1;var L=g-u!=0?(c-u)/(g-u):0,h=t.GeometryUtil.interpolateOnPointSegment(f,y,L);return{latLng:e.unproject(h,i),predecessor:s-1}},locateOnLine:function(e,n,r){var a=n.getLatLngs();if(r.equals(a[0]))return 0;if(r.equals(a[a.length-1]))return 1;for(var i=t.GeometryULine truncated
/* Leaflet.Heightgraph - v0.4.1 - https://github.com/GIScience/Leaflet.Heightgraph/blob/master/dist/L.Control.Heightgraph.min.js - MIT License */
"use strict";L.Control.Heightgraph=L.Control.extend({options:{position:"bottomright",width:800,height:280,margins:{top:10,right:30,bottom:55,left:50},mappings:void 0,expand:!0,translation:{},expandCallback:void 0,xTicks:void 0,yTicks:void 0,highlightStyle:void 0},_defaultTranslation:{distance:"Distance",elevation:"Elevation",segment_length:"Segment length",type:"Type",legend:"Legend"},_init_options:function(){this._margin=this.options.margins,this._width=this.options.width,this._height=this.options.height,this._mappings=this.options.mappings,this._svgWidth=this._width-this._margin.left-this._margin.right,this._svgHeight=this._height-this._margin.top-this._margin.bottom,this._selectedOption=0,this._highlightStyle=this.options.highlightStyle||{color:"red"}},onAdd:function(){var t=this._container=L.DomUtil.create("div","heightgraph");L.DomEvent.disableClickPropagation(t);var e=this._button=L.DomUtil.create("div","heightgraph-toggle",t);L.DomUtil.create("a","heightgraph-toggle-icon",e),this._closeButton=L.DomUtil.create("a","heightgraph-close-icon",t);this._showState=!1,this._initToggle(),this._init_options();this._svg=d3.select(this._container).append("svg").attr("class","heightgraph-container").attr("width",this._svgWidth+this._margin.left+this._margin.right).attr("height",this._svgHeight+this._margin.top+this._margin.bottom).append("g").attr("transform","translate("+this._margin.left+","+this._margin.top+")");return t},onRemove:function(){this._removeMarkedSegmentsOnMap(),this._container=null,this._svg=void 0},addData:function(t){void 0!==this._svg&&this._svg.selectAll("*").remove(),this._data=t,this._init_options(),this._prepareData(),this._computeStats(),this._appendScales(),this._appendGrid(),this._createChart(this._selectedOption),1<this._data.length&&this._createSelectionBox(),this.options.expand&&this._expand()},_initToggle:function(){L.Browser.touch?L.DomEvent.on(this._container,"click",L.DomEvent.stopPropagation):L.DomEvent.disableClickPropagation(this._container),L.DomEvent.on(this._button,"click",this._expand,this),L.DomEvent.on(this._closeButton,"click",this._expand,this)},_dragHandler:function(){d3.event.preventDefault(),d3.event.stopPropagation(),this._gotDragged=!0,this._drawDragRectangle()},_drawDragRectangle:function(){if(this._dragStartCoords){var t=this._dragCurrentCoords=d3.mouse(this._background.node()),e=Math.min(this._dragStartCoords[0],t[0]),i=Math.max(this._dragStartCoords[0],t[0]);if(this._dragRectangle||this._dragRectangleG)this._dragRectangle.attr("width",i-e).attr("x",e);else{var s=d3.select(this._container).select("svg").select("g");this._dragRectangleG=s.append("g"),this._dragRectangle=this._dragRectangleG.append("rect").attr("width",i-e).attr("height",this._svgHeight).attr("x",e).attr("class","mouse-drag").style("fill","grey").style("opacity",.5).style("pointer-events","none")}}},_resetDrag:function(){this._dragRectangleG&&(this._dragRectangleG.remove(),this._dragRectangleG=null,this._dragRectangle=null)},_dragEndHandler:function(){if(!this._dragStartCoords||!this._gotDragged)return this._dragStartCoords=null,this._gotDragged=!1,void this._resetDrag();var t=this._findItemForX(this._dragStartCoords[0]),e=this._findItemForX(this._dragCurrentCoords[0]);this._fitSection(t,e),this._dragStartCoords=null,this._gotDragged=!1},_dragStartHandler:function(){d3.event.preventDefault(),d3.event.stopPropagation(),this._gotDragged=!1,this._dragStartCoords=d3.mouse(this._background.node())},_calculateFullExtent:function(t){if(!t||t.length<1)throw new Error("no data in parameters");var e=new L.latLngBounds(t[0].latlng,t[0].latlng);return t.forEach(function(t){e.contains(t.latlng)||e.extend(t.latlng)}),e},_fitSection:function(t,e){var i,s=Math.min(t,e),a=Math.max(t,e);i=s!==a?this._calculateFullExtent(this._areasFlattended.slice(s,a+1)):[this._areasFlattended[s].latlng,this._areasFlattended[a].latlng],this._map.fitBounds(i)},_expand:function(){this._showState?(d3.select(this._button).style("display","block"),d3.select(this._container).selectAll("svg").style("display","none"),d3.select(this._closeButton).style("display","none")):(d3.select(this._button).style("display","none"),d3.select(this._container).selectAll("svg").style("display","block"),d3.select(this._closeButton).style("display","block")),this._showState=!this._showState,"function"==typeof this.options.expandCallback&&this.options.expandCallback(this._showState)},_removeChart:function(){void 0!==this._svg&&(this._svg.selectAll("path.area").remove(),this._svg.selectAll("path.border-top").remove(),this._svg.selectAll(".legend").remove(),this._svg.selectAll(".lineSelection").remove(),this._svg.selectAll(".horizontalLine").remove(),this._svg.selectAll(".horizontalLineText").remove())},_randomNumber:function(t){return Math.round(Math.random()*(t-0))},_d3ColorCategorical:[{name:"schemeAccent"},{name:"schemeDark2"},{name:"schemeSet2"},{name:"schemeSet1"},{name:"schemeCategory10"},{name:"schemeSet3"},{name:"schemePaired"},{name:"schemeCategory2Line truncated
/* Additional Leaflet functions */
L.Map.include({
setOffsetView: function (iOffsetRatioX, oCenter, iZoomLevel) {
@@ -20,824 +23,3 @@ L.Map.include({
this.setView(oCenter, iZoomLevel);
}
});
/* leaflet.elevation - https://github.com/HostedDinner/Leaflet.Elevation/tree/master/dist */
L.Control.Elevation = L.Control.extend({
options: {
position: "topright",
theme: "lime-theme",
width: 600,
height: 175,
margins: {
top: 10,
right: 20,
bottom: 30,
left: 60
},
useHeightIndicator: true,
interpolation: d3.curveLinear,
hoverNumber: {
decimalsX: 3,
decimalsY: 0,
formatter: undefined
},
xTicks: undefined,
yTicks: undefined,
collapsed: false,
yAxisMin: undefined,
yAxisMax: undefined,
forceAxisBounds: false,
controlButton: {
iconCssClass: "elevation-toggle-icon",
title: "Elevation"
},
imperial: false,
onExpand: function() {},
onCollapse: function() {},
},
__mileFactor: 0.621371,
__footFactor: 3.28084,
onRemove: function(map) {
this._container = null;
},
onAdd: function(map) {
this._map = map;
var opts = this.options;
var margin = opts.margins;
opts.xTicks = opts.xTicks || Math.round(this._width() / 75);
opts.yTicks = opts.yTicks || Math.round(this._height() / 30);
opts.hoverNumber.formatter = opts.hoverNumber.formatter || this._formatter;
var x = this._x = d3.scaleLinear()
.range([0, this._width()]);
var y = this._y = d3.scaleLinear()
.range([this._height(), 0]);
var area = this._area = d3.area()
.curve(opts.interpolation)
.x(function(d) {
var xDiagCoord = x(d.dist);
d.xDiagCoord = xDiagCoord;
return xDiagCoord;
})
.y0(this._height())
.y1(function(d) {
return y(d.altitude);
});
var container = this._container = L.DomUtil.create("div", "elevation");
L.DomUtil.addClass(container, opts.theme); //append theme to control
this._initToggle();
var cont = d3.select(container);
cont.attr("width", opts.width);
var svg = cont.append("svg");
svg.attr("width", opts.width)
.attr("class", "background")
.attr("height", opts.height)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var line = d3.line();
line = line
.x(function(d) {
return d3.mouse(svg.select("g"))[0];
})
.y(function(d) {
return this._height();
});
var g = d3.select(this._container).select("svg").select("g");
this._areapath = g.append("path")
.attr("class", "area");
var background = this._background = g.append("rect")
.attr("width", this._width())
.attr("height", this._height())
.style("fill", "none")
.style("stroke", "none")
.style("pointer-events", "all");
if (L.Browser.mobile) { //https://github.com/MrMufflon/Leaflet.Elevation/commit/971d6b81cf2993c0333b30eee58fa48183478593
background.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);
}
background.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 = g.append("g");
this._yaxisgraphicnode = g.append("g");
this._appendXaxis(this._xaxisgraphicnode);
this._appendYaxis(this._yaxisgraphicnode);
var focusG = this._focusG = g.append("g");
this._mousefocus = focusG.append('svg:line')
.attr('class', 'mouse-focus-line')
.attr('x2', '0')
.attr('y2', '0')
.attr('x1', '0')
.attr('y1', '0');
this._focuslabelX = focusG.append("svg:text")
.style("pointer-events", "none")
.attr("class", "mouse-focus-label-x");
this._focuslabelY = focusG.append("svg:text")
.style("pointer-events", "none")
.attr("class", "mouse-focus-label-y");
if (this._data) {
this._applyData();
}
var detailsG = this._detailsG = g.append("g").attr('class', 'details');
this._details = detailsG.append("svg:text").attr('x', this._width()/2).attr('y', this._height() - 5 - 10 - 5).style('text-anchor', 'middle');
return container;
},
_dragHandler: function() {
//we don´t want map events to occur here
d3.event.preventDefault();
d3.event.stopPropagation();
this._gotDragged = true;
this._drawDragRectangle();
},
/*
* Draws the currently dragged rectangle over the chart.
*/
_drawDragRectangle: function() {
if (!this._dragStartCoords) {
return;
}
var dragEndCoords = this._dragCurrentCoords = d3.mouse(this._background.node());
var x1 = Math.min(this._dragStartCoords[0], dragEndCoords[0]),
x2 = Math.max(this._dragStartCoords[0], dragEndCoords[0]);
if (!this._dragRectangle && !this._dragRectangleG) {
var g = d3.select(this._container).select("svg").select("g");
this._dragRectangleG = g.append("g");
this._dragRectangle = this._dragRectangleG.append("rect")
.attr("width", x2 - x1)
.attr("height", this._height())
.attr("x", x1)
.attr('class', 'mouse-drag')
.style("pointer-events", "none");
} else {
this._dragRectangle.attr("width", x2 - x1)
.attr("x", x1);
}
},
/*
* Removes the drag rectangle and zoms back to the total extent of the data.
*/
_resetDrag: function() {
if (this._dragRectangleG) {
this._dragRectangleG.remove();
this._dragRectangleG = null;
this._dragRectangle = null;
this._hidePositionMarker();
this._map.fitBounds(this._fullExtent);
}
},
/*
* Handles end of dragg operations. Zooms the map to the selected items extent.
*/
_dragEndHandler: function() {
if (!this._dragStartCoords || !this._gotDragged) {
this._dragStartCoords = null;
this._gotDragged = false;
this._resetDrag();
return;
}
this._hidePositionMarker();
var item1 = this._findItemForX(this._dragStartCoords[0]),
item2 = this._findItemForX(this._dragCurrentCoords[0]);
this._fitSection(item1, item2);
this._dragStartCoords = null;
this._gotDragged = false;
},
_dragStartHandler: function() {
d3.event.preventDefault();
d3.event.stopPropagation();
this._gotDragged = false;
this._dragStartCoords = d3.mouse(this._background.node());
},
/*
* Finds a data entry for a given x-coordinate of the diagram
*/
_findItemForX: function(x) {
var bisect = d3.bisector(function(d) {
return d.dist;
}).left;
var xinvert = this._x.invert(x);
return bisect(this._data, xinvert);
},
/*
* Finds an item with the smallest delta in distance to the given latlng coords
*/
_findItemForLatLng: function(latlng) {
var result = null,
d = Infinity;
this._data.forEach(function(item) {
var dist = latlng.distanceTo(item.latlng);
if (dist < d) {
d = dist;
result = item;
}
});
return result;
},
/** Make the map fit the route section between given indexes. */
_fitSection: function(index1, index2) {
var start = Math.min(index1, index2),
end = Math.max(index1, index2);
var ext = this._calculateFullExtent(this._data.slice(start, end));
this._map.fitBounds(ext);
},
_initToggle: function() {
/* inspired by L.Control.Layers */
var container = this._container;
//Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
container.setAttribute('aria-haspopup', true);
L.DomEvent
.disableClickPropagation(container);
//.disableScrollPropagation(container);
if (L.Browser.mobile) {
L.DomEvent.on(container, 'click', L.DomEvent.stopPropagation);
}
if (this.options.collapsed) {
this._collapse();
if (!L.Browser.android) {
L.DomEvent
.on(container, 'mouseover', this._expand, this)
.on(container, 'mouseout', this._collapse, this);
}
var link = this._button = L.DomUtil.create('a', "elevation-toggle " + this.options.controlButton
.iconCssClass, container);
link.href = '#';
link.title = this.options.controlButton.title;
if (L.Browser.mobile) {
L.DomEvent
.on(link, 'click', L.DomEvent.stop)
.on(link, 'click', this._expand, this);
}
L.DomEvent.on(link, 'focus', this._expand, this);
this._map.on('click', this._collapse, this);
// TODO keyboard accessibility
}
},
_expand: function() {
this._container.className = this._container.className.replace(' elevation-collapsed', '');
this.options.onExpand();
},
_collapse: function() {
L.DomUtil.addClass(this._container, 'elevation-collapsed');
this.options.onCollapse();
},
_width: function() {
var opts = this.options;
return opts.width - opts.margins.left - opts.margins.right;
},
_height: function() {
var opts = this.options;
return opts.height - opts.margins.top - opts.margins.bottom;
},
/*
* Fromatting funciton using the given decimals and seperator
*/
_formatter: function(num, dec, sep) {
var res;
if (dec === 0) {
res = Math.round(num) + "";
} else {
res = L.Util.formatNum(num, dec) + "";
}
var numbers = res.split(".");
if (numbers[1]) {
var d = dec - numbers[1].length;
for (; d > 0; d--) {
numbers[1] += "0";
}
res = numbers.join(sep || ".");
}
return res;
},
_appendYaxis: function(y) {
var opts = this.options;
if (opts.imperial) {
y.attr("class", "y axis")
.call(d3.axisLeft()
.scale(this._y)
.ticks(this.options.yTicks))
.append("text")
.attr("x", -37)
.attr("y", 3)
.style("text-anchor", "end")
.style("fill", "currentColor")
.text("ft");
} else {
y.attr("class", "y axis")
.call(d3.axisLeft()
.scale(this._y)
.ticks(this.options.yTicks))
.append("text")
.attr("x", -10)
.attr("y", 3)
.style("text-anchor", "end")
.style("fill", "currentColor")
.text("m");
}
},
_appendXaxis: function(x) {
var opts = this.options;
if (opts.imperial) {
x.attr("class", "x axis")
.attr("transform", "translate(0," + this._height() + ")")
.call(d3.axisBottom()
.scale(this._x)
.ticks(this.options.xTicks))
.append("text")
.attr("x", this._width() + 10)
.attr("y", 15)
.style("text-anchor", "end")
.style("fill", "currentColor")
.text("mi");
} else {
x.attr("class", "x axis")
.attr("transform", "translate(0," + this._height() + ")")
.call(d3.axisBottom()
.scale(this._x)
.ticks(this.options.xTicks))
.append("text")
.attr("x", this._width() + 10)
.attr("y", 15)
.style("text-anchor", "end")
.style("fill", "currentColor")
.text("km");
}
},
_updateAxis: function() {
this._xaxisgraphicnode.selectAll("g").remove();
this._xaxisgraphicnode.selectAll("path").remove();
this._xaxisgraphicnode.selectAll("text").remove();
this._yaxisgraphicnode.selectAll("g").remove();
this._yaxisgraphicnode.selectAll("path").remove();
this._yaxisgraphicnode.selectAll("text").remove();
this._appendXaxis(this._xaxisgraphicnode);
this._appendYaxis(this._yaxisgraphicnode);
},
_mouseoutHandler: function() {
this._hidePositionMarker();
},
/*
* Hides the position-/heigth indication marker drawn onto the map
*/
_hidePositionMarker: function() {
if (this._marker) {
this._map.removeLayer(this._marker);
this._marker = null;
}
if (this._mouseHeightFocus) {
this._mouseHeightFocus.style("visibility", "hidden");
this._mouseHeightFocusLabel.style("visibility", "hidden");
}
if (this._pointG) {
this._pointG.style("visibility", "hidden");
}
this._focusG.style("visibility", "hidden");
},
/*
* Handles the moueseover the chart and displays distance and altitude level
*/
_mousemoveHandler: function(d, i, ctx) {
if (!this._data || this._data.length === 0) {
return;
}
var coords = d3.mouse(this._background.node());
var opts = this.options;
var item = this._data[this._findItemForX(coords[0])];
if(!item) return;
var alt = item.altitude,
dist = item.dist,
ll = item.latlng,
numY = opts.hoverNumber.formatter(alt, opts.hoverNumber.decimalsY),
numX = opts.hoverNumber.formatter(dist, opts.hoverNumber.decimalsX);
this._showDiagramIndicator(item, coords[0]);
var layerpoint = this._map.latLngToLayerPoint(ll);
//if we use a height indicator we create one with SVG
//otherwise we show a marker
if (opts.useHeightIndicator) {
if (!this._mouseHeightFocus) {
var heightG = d3.select(this._map.getContainer())
.select(".leaflet-overlay-pane svg") //https://github.com/MrMufflon/Leaflet.Elevation/commit/bb4ea158b87f99c4a8f50af50d7ccf6f8ed45661
.append("g");
this._mouseHeightFocus = heightG.append('svg:line')
.attr("class", opts.theme + " height-focus line")
.attr("x2", 0)
.attr("y2", 0)
.attr("x1", 0)
.attr("y1", 0);
var pointG = this._pointG = heightG.append("g");
pointG.append("svg:circle")
.attr("r", 4)
.attr("cx", 0)
.attr("cy", 0)
.attr("class", opts.theme + " height-focus circle-lower");
this._mouseHeightFocusLabel = heightG.append("svg:text")
.attr("class", opts.theme + " height-focus-label")
.style("pointer-events", "none");
}
var normalizedAlt = this._height() / this._maxElevation * alt;
var normalizedY = layerpoint.y - normalizedAlt;
var compY = Math.max(3 - normalizedAlt, 0) + 3;
this._mouseHeightFocus.attr("x1", layerpoint.x)
.attr("x2", layerpoint.x)
.attr("y1", layerpoint.y)
.attr("y2", normalizedY)
.style("visibility", "visible");
this._pointG.attr("transform", "translate(" + layerpoint.x + "," + layerpoint.y + ")")
.style("visibility", "visible");
if (opts.imperial) {
this._mouseHeightFocusLabel.attr("x", layerpoint.x)
.attr("y", normalizedY - compY)
.text(numY + " ft")
.style("visibility", "visible");
} else {
this._mouseHeightFocusLabel.attr("x", layerpoint.x)
.attr("y", normalizedY - compY)
.text(numY + " m")
.style("visibility", "visible");
}
} else {
if (!this._marker) {
this._marker = new L.Marker(ll).addTo(this._map);
} else {
this._marker.setLatLng(ll);
}
}
},
/*
* Parsing of GeoJSON data lines and their elevation in z-coordinate
*/
_addGeoJSONData: function(coords) {
var opts = this.options;
if (coords) {
var data = this._data || [];
var dist = this._dist || 0;
var ele = this._maxElevation || 0;
var eleDrop = this._elevationDrop || 0;
var eleGain = this._elevationGain || 0;
for (var i = 0; i < coords.length; i++) {
var s = new L.LatLng(coords[i][1], coords[i][0]);
var e = new L.LatLng(coords[i ? i - 1 : 0][1], coords[i ? i - 1 : 0][0]);
var newdist = opts.imperial ? s.distanceTo(e) * this.__mileFactor : s.distanceTo(e);
dist = dist + Math.round(newdist / 1000 * 100000) / 100000;
ele = ele < coords[i][2] ? coords[i][2] : ele;
if(i > 0) {
var eleDelta = coords[i][2] - coords[i - 1][2];
eleDrop += Math.min(eleDelta, 0);
eleGain += Math.max(eleDelta, 0);
}
data.push({
dist: dist,
altitude: opts.imperial ? coords[i][2] * this.__footFactor : coords[i][2],
x: coords[i][0],
y: coords[i][1],
latlng: s
});
}
this._dist = dist;
this._data = data;
ele = opts.imperial ? ele * this.__footFactor : ele;
this._maxElevation = ele;
this._elevationDrop = eleDrop;
this._elevationGain = eleGain;
}
},
/*
* Parsing function for GPX data as used by https://github.com/mpetazzoni/leaflet-gpx
*/
_addGPXdata: function(coords) {
var opts = this.options;
if (coords) {
var data = this._data || [];
var dist = this._dist || 0;
var ele = this._maxElevation || 0;
var eleDrop = this._elevationDrop || 0;
var eleGain = this._elevationGain || 0;
for (var i = 0; i < coords.length; i++) {
var s = coords[i];
var e = coords[i ? i - 1 : 0];
var newdist = opts.imperial ? s.distanceTo(e) * this.__mileFactor : s.distanceTo(e);
dist = dist + Math.round(newdist / 1000 * 100000) / 100000;
ele = ele < s.meta.ele ? s.meta.ele : ele;
var eleDelta = s.meta.ele - e.meta.ele;
eleDrop += Math.min(eleDelta, 0);
eleGain += Math.max(eleDelta, 0);
data.push({
dist: dist,
altitude: opts.imperial ? s.meta.ele * this.__footFactor : s.meta.ele,
x: s.lng,
y: s.lat,
latlng: s
});
}
this._dist = dist;
this._data = data;
ele = opts.imperial ? ele * this.__footFactor : ele;
this._maxElevation = ele;
this._elevationDrop = eleDrop;
this._elevationGain = eleGain;
}
},
_addData: function(d) {
var geom = d && d.geometry && d.geometry;
var i;
if (geom) {
switch (geom.type) {
case 'LineString':
this._addGeoJSONData(geom.coordinates);
break;
case 'MultiLineString':
for (i = 0; i < geom.coordinates.length; i++) {
this._addGeoJSONData(geom.coordinates[i]);
}
break;
default:
throw new Error('Invalid GeoJSON object.');
}
}
var feat = d && d.type === "FeatureCollection";
if (feat) {
for (i = 0; i < d.features.length; i++) {
this._addData(d.features[i]);
}
}
if (d && d._latlngs) {
this._addGPXdata(d._latlngs);
}
var asMetaData = this.getMetaData();
this._details.text(Math.round(asMetaData.distance)+(this.options.imperial?'mi':'km')+' / +'+asMetaData.elevation_gain+(this.options.imperial?'ft':'m'));
},
/*
* Calculates the full extent of the data array
*/
_calculateFullExtent: function(data) {
if (!data || data.length < 1) {
throw new Error("no data in parameters");
}
var ext = new L.latLngBounds(data[0].latlng, data[0].latlng);
data.forEach(function(item) {
ext.extend(item.latlng);
});
return ext;
},
/*
* Add data to the diagram either from GPX or GeoJSON and
* update the axis domain and data
*/
addData: function(d, layer) {
this._addData(d);
if (this._container) {
this._applyData();
}
if (layer === null && d.on) {
layer = d;
}
if (layer) {
layer.on("mousemove", this._handleLayerMouseOver.bind(this));
}
},
/*
* Handles mouseover events of the data layers on the map.
*/
_handleLayerMouseOver: function(evt) {
if (!this._data || this._data.length === 0) {
return;
}
var latlng = evt.latlng;
var item = this._findItemForLatLng(latlng);
if (item) {
var x = item.xDiagCoord;
this._showDiagramIndicator(item, x);
}
},
_showDiagramIndicator: function(item, xCoordinate) {
var opts = this.options;
this._focusG.style("visibility", "visible");
this._mousefocus.attr('x1', xCoordinate)
.attr('y1', 3)
.attr('x2', xCoordinate)
.attr('y2', this._height())
.classed('hidden', false);
var alt = item.altitude,
dist = item.dist,
ll = item.latlng,
numY = opts.hoverNumber.formatter(alt, opts.hoverNumber.decimalsY),
numX = opts.hoverNumber.formatter(dist, opts.hoverNumber.decimalsX);
this._focuslabelX
.attr("x", xCoordinate)
.text(numY + " " + (opts.imperial?"ft":"m"));
var bLeftSide = (xCoordinate < this._width() / 2);
this._focuslabelY
.attr("y", this._height() - 5)
.style('text-anchor', bLeftSide?'start':'end')
.attr("x", xCoordinate + 3 * (bLeftSide?1:-1))
.text(numX + " " + (opts.imperial?"mi":"km"));
},
_applyData: function() {
var xdomain = d3.extent(this._data, function(d) {
return d.dist;
});
var ydomain = d3.extent(this._data, function(d) {
return d.altitude;
});
var opts = this.options;
if (opts.yAxisMin !== undefined && (opts.yAxisMin < ydomain[0] || opts.forceAxisBounds)) {
ydomain[0] = opts.yAxisMin;
}
if (opts.yAxisMax !== undefined && (opts.yAxisMax > ydomain[1] || opts.forceAxisBounds)) {
ydomain[1] = opts.yAxisMax;
}
this._x.domain(xdomain);
this._y.domain(ydomain);
this._areapath.datum(this._data)
.attr("d", this._area);
this._updateAxis();
this._fullExtent = this._calculateFullExtent(this._data);
},
/*
* Reset data
*/
_clearData: function() {
this._data = null;
this._dist = null;
this._elevationDrop = null;
this._elevationGain = null;
this._maxElevation = null;
},
/*
* Reset data and display
*/
clear: function() {
this._clearData();
if (!this._areapath) {
return;
}
// workaround for 'Error: Problem parsing d=""' in Webkit when empty data
// https://groups.google.com/d/msg/d3-js/7rFxpXKXFhI/HzIO_NPeDuMJ
//this._areapath.datum(this._data).attr("d", this._area);
this._areapath.attr("d", "M0 0");
this._x.domain([0, 1]);
this._y.domain([0, 1]);
this._updateAxis();
},
hide: function() {
this._container.style.display = "none";
},
show: function() {
this._container.style.display = "block";
},
getMetaData: function() {
return {'distance': this._dist, 'elevation_drop': this._elevationDrop, 'elevation_gain': this._elevationGain, 'elevation_max': this._maxElevation};
}
});
L.control.elevation = function(options) {
return new L.Control.Elevation(options);
};
-10
View File
@@ -355,13 +355,3 @@ $.prototype.onSwipe = function(fCallBack){
fCallBack({x:iDeltaX, y:iDeltaY});
});
};
function isIE() {
var sUA = window.navigator.userAgent;
//IE 10: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)
//IE 11: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
//Edge 12 (Spartan): Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0
//Edge 13: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586
//Edge 18: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363
return (sUA.indexOf('MSIE ') > 0 || sUA.indexOf('Trident/') > 0 || sUA.indexOf('Edge/') > 0);
}