diff options
| author | Dennis Fink | 2026-11-03 23:18:23 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-03 23:18:23 +0100 |
| commit | ebe123a6d40bf17ab2a35f331fb08c8c0fc76a3a (patch) | |
| tree | 441d3a817736e9db25d5c14aa3938c0392166160 | |
| parent | 7f4de25eb8abca76a619bc70bb0fce7e8be36561 (diff) | |
| download | dennisfink.me-ebe123a6d40bf17ab2a35f331fb08c8c0fc76a3a.tar.gz dennisfink.me-ebe123a6d40bf17ab2a35f331fb08c8c0fc76a3a.zip | |
Update vendored Leaflet Elevation and map dependencies
40 files changed, 3195 insertions, 3608 deletions
diff --git a/assets/static/vendor/leaflet-elevation/images/elevation-position.svg b/assets/static/vendor/leaflet-elevation/images/elevation-position.svg index 9a3b180..a12d0b7 100644 --- a/assets/static/vendor/leaflet-elevation/images/elevation-position.svg +++ b/assets/static/vendor/leaflet-elevation/images/elevation-position.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 8.5 8.5"><defs><filter id="shadow"><feDropShadow dx="0" dy="0" stdDeviation="0.3" flood-color="#000000"/></filter></defs><circle cx="4.2" cy="4.2" r="2.2" fill="#ffffff" fill-opacity="1" filter="url(#shadow)"/><circle cx="4.2" cy="4.2" r="1.85" fill="none" stroke="#333333" stroke-linejoin="round" stroke-width="0.45"/><circle cx="4.2" cy="4.2" r="1.25" fill="none" stroke="#333333" stroke-linejoin="round" stroke-width="0.25"/><circle cx="4.2" cy="4.2" r="0.55" fill="#333333"/></svg>
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 8.5 8.5"><defs><filter id="shadow"><feDropShadow dx="0" dy="0" stdDeviation="0.3" flood-color="#000000"/></filter></defs><circle cx="4.2" cy="4.2" r="2.2" fill="#ffffff" fill-opacity="1" filter="url(#shadow)"/><circle cx="4.2" cy="4.2" r="1.85" fill="none" stroke="#333333" stroke-linejoin="round" stroke-width="0.45"/><circle cx="4.2" cy="4.2" r="1.25" fill="none" stroke="#333333" stroke-linejoin="round" stroke-width="0.25"/><circle cx="4.2" cy="4.2" r="0.55" fill="#333333"/></svg> diff --git a/assets/static/vendor/leaflet-elevation/images/elevation-pushpin.svg b/assets/static/vendor/leaflet-elevation/images/elevation-pushpin.svg index fcc5a01..e4acb61 100644 --- a/assets/static/vendor/leaflet-elevation/images/elevation-pushpin.svg +++ b/assets/static/vendor/leaflet-elevation/images/elevation-pushpin.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64"><path fill="silver" d="M24.474 45.368c-.515.178-.44.974-.708 1.39-1.242 3.712-2.686 7.37-3.648 11.168-.336 1.367-.087 2.775.139 4.136 2.405-3.417 3.762-7.419 4.878-11.407.407-1.45.898-2.884 1.213-4.358-.353-.521-1.104-.623-1.652-.884-.072-.02-.146-.046-.222-.045z"/><path fill="#f08d8d" d="M17.193 27.237c-.95.368-1.645 1.228-2.399 1.893-.987 1.082-2.01 2.222-2.597 3.572.16.615.942.116 1.348.052 1.485-.443 2.408-1.797 3.013-3.141.299-.72.84-1.4.911-2.186a.286.286 0 00-.276-.19z"/><path fill="#fd6d6d" d="M28.156 9.549c-.495.55-.53 1.423-.83 2.096-1.487 4.598-2.669 9.299-4.36 13.825-.786.406-1.764.381-2.616.667-1.045.29-2.192.508-3.113 1.023-.986 1.725-1.497 4.038-3.446 4.975-.547.365-1.61.195-1.703 1.056-.333 2.283.656 4.608 2.23 6.229.584.012.966-.7 1.443-1.005 1.856-1.744 4.143-3.3 6.735-3.476 2.277-.23 4.602-.181 6.912-.262-2.39-1.27-5.13-2.41-6.595-4.809a10.078 10.078 0 0 1-.827-1.63l2.478 2.533c1.635-6.38 3.92-12.578 5.438-18.99.438-.742-.42-1.107-.823-1.602-.286-.202-.539-.703-.923-.63z"/><path fill="#fd6464" d="M28.454 1.686c-1.119.01-2.246.095-3.32.43-.22 1.754-.389 3.745.781 5.228.356.51.78.965 1.188 1.432l2.531-.955-3.087-3.15c5.929 2.954 12.037 5.904 18.664 6.842a63.84 63.84 0 0 0 6.017.304c.453-.288.3-.998.177-1.439-.947-1.112-2.273-1.856-3.486-2.651-4.678-2.746-9.907-4.441-15.185-5.6a17.269 17.269 0 0 0-4.28-.44z"/><path fill="#de5858" d="M39.98 31.987c-1.243.923-2.227 2.377-3.794 2.765-3.644.288-7.329-.682-11.008-.484-2.629.107-5.445.39-7.588 2.08-1.116.896-2.323 1.744-3.24 2.847-.028.554.75.78 1.05 1.172.934.712 1.8 1.54 2.807 2.145.631-.556.757-1.53 1.402-2.108 1.309-1.205 3.158-1.63 4.798-2.092 4.486-.97 9.147-.67 13.614-1.776l4.655-1.001c.228-.57-.531-1.012-.751-1.491-.567-.756-1.156-1.494-1.74-2.238l-.204.18z"/><path fill="#ba4a4a" d="M29.26 7.5c-.708.334-1.563.461-2.186.942-.088.523.64.855.93 1.258 1.125 1.108 2.793 1.326 4.185 1.95 3.774 1.357 7.6 2.604 11.521 3.459-1.481.707-3.154.576-4.69.111a27.13 27.13 0 01-9.328-4.253c-1.515 6.366-3.744 12.564-5.422 18.907-.925-.754-1.593-1.813-2.582-2.48-.63.004-.206.767-.084 1.083.924 2.59 3.198 4.371 5.605 5.516.88.504 1.783.926 2.82.9 2.14.174 4.337.67 6.472.23 1.558-.586 2.628-1.97 3.906-2.97-.622-.693-.914-1.662-.51-2.537 1.539-4.633 3.45-9.225 5.05-13.875 2.082-.496 4.585-.89 5.875-2.816.222-.448.876-.945.583-1.477-1.876-.164-3.784-.192-5.664-.177-1.12.095.824.692 1.252.859.607.229 1.395.497 1.865.74-5.345.176-10.525-1.763-15.445-3.74-1.386-.51-2.768-1.239-4.152-1.63zm13.334 27.608c-4.09.913-8.185 1.857-12.386 2.008-3.385.247-6.856.652-9.903 2.263-.695.262-1.269.742-1.54 1.449-.172.55-1.03 1.307-.633 1.698 3.447 2.002 7.05 4.007 11.082 4.457 3.591.551 7.35.802 10.888-.19 2.478-.72 3.861-3.344 3.927-5.792.132-2.046-.35-4.095-1.226-5.938l-.126.027-.083.018z"/><path fill="#9b3d3d" d="M38.85 15.362c-2.985-.756-5.734-1.923-7.866-3.34-.978-.65-2.28-1.868-1.815-1.698l1.997.756c3.254 1.239 7.48 2.592 10.3 3.299l2.804.702-.69.258c-1.679.628-2.329.631-4.73.023zM27.768 6.308l-.293-.333.333.293c.183.162.332.311.332.333 0 .095-.098.018-.372-.293z"/><path fill="#8b3838" d="M45.566 12.918c-3.393-.389-7.22-1.563-13.493-4.138L29.29 7.638l-1.236-1.172c-.68-.645-1.464-1.446-1.744-1.78l-.51-.608 2.471 1.237c6.623 3.316 10.796 4.868 15.754 5.86 1.76.351 3.485.878 4.807 1.467l.909.405-1.634-.012a31.11 31.11 0 0 1-2.54-.117z"/><path fill="#383838" d="M19.003 63.365c-.744-1.63-.854-3.21-.355-5.13.17-.656 1.096-3.554 2.057-6.44a677.285 677.285 0 0 0 1.748-5.284c0-.02-.695-.404-1.543-.853-5.16-2.729-8.047-5.216-9.541-8.22-.675-1.357-.866-2.392-.664-3.611.495-3 3.118-6.364 6.12-7.851.871-.431 2.212-.896 3.866-1.341l1.442-.388 1.069-3.51c2.17-7.125 3.13-10.477 3.044-10.621a14.91 14.91 0 0 0-.665-.843c-1.946-2.35-2.697-5.018-1.9-6.747.398-.864.8-1.33 1.623-1.875l.67-.445C26.621.046 28.556 0 28.556 0s1.819.038 2.67.304l3.085.794c5.906 1.521 10.247 3.17 14.022 5.327 2.07 1.358 3.377 2.396 4.686 3.895.207.242.368.543.35.729 0 0-.042.39-.144.549 0 0-1.71 2.613-2.17 3.077-.453.456-1.606 1.061-3.493 1.834-.917.376-1.891 1.178-2.092 1.723l-1.477 4.08a472.53 472.53 0 0 1-2.197 5.958l-.84 2.206.89 1.182c1.884 2.496 2.781 4.129 3.245 5.9.357 1.366.355 3.946-.005 5.325-.633 2.426-1.742 3.793-3.925 4.836-3.113 1.487-6.85 1.672-12.16.602-.825-.167-1.512-.287-1.527-.268s-.67 1.967-1.453 4.33c-1.745 5.258-2.49 7.318-2.994 8.279-.257.49-.819 1.172-1.678 2.037C20.25 63.807 20.003 64 19.676 64c-.344 0-.412-.064-.673-.635zm2.226-3.061c1.468-2.444 2.544-5.264 4.084-10.702l.947-3.245c.021-.021 1.012.124 2.2.323 3.1.52 4.94.666 7.352.583 3.419-.118 5.077-.61 6.331-1.882.72-.73 1.27-1.775 1.542-2.932.24-1.018.238-3.14-.005-4.32-.379-1.844-.808-2.621-2.958-5.35-.957-1.215-1.207-1.667-1.207-2.19 0-.456.52-2.005 1.845-5.494l2.21-5.99 1.247-3.45.647-.155c3.433-.826 4.365-1.336 5.442-2.98.404-.616.514-1.066.514-1.066s.182-.738-.045-1.014l-.817-.669C46.78 6.681 39.943 3.8 32.875 2.323c-1.923-.402-2.323-.447-4.07-.454-1.238-.006-2.208.052-2.694.16-.918.203-.927.223-.932 2.191-.003 1.273.025 1.453.333 2.11.379.809.89 1.488 1.925 2.555l.71.733-.193.538c-.105.296-.948 3.043-1.872 6.105l-2.33 7.495-.647 1.928-1.506.323c-2.972.637-4.066 1.023-5.152 1.816-1.395 1.02-2.882 2.715-3.859 4.398-.318.549-.343.684-.342 1.876 0 1.37.154 2.067.682 3.108a9.37 9.37 0 0 0 2.164 2.722c2.53 2.107 4.779 3.541 7.672 4.893l1.581.74-.884 2.473-2.035 5.934c-1.25 3.757-1.441 4.723-1.26 6.342a21.83 21.83 0 0 1 .102 1.059c.012.41.201.2.96-1.064z"/></svg>
+<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64"><path fill="silver" d="M24.474 45.368c-.515.178-.44.974-.708 1.39-1.242 3.712-2.686 7.37-3.648 11.168-.336 1.367-.087 2.775.139 4.136 2.405-3.417 3.762-7.419 4.878-11.407.407-1.45.898-2.884 1.213-4.358-.353-.521-1.104-.623-1.652-.884-.072-.02-.146-.046-.222-.045z"/><path fill="#f08d8d" d="M17.193 27.237c-.95.368-1.645 1.228-2.399 1.893-.987 1.082-2.01 2.222-2.597 3.572.16.615.942.116 1.348.052 1.485-.443 2.408-1.797 3.013-3.141.299-.72.84-1.4.911-2.186a.286.286 0 00-.276-.19z"/><path fill="#fd6d6d" d="M28.156 9.549c-.495.55-.53 1.423-.83 2.096-1.487 4.598-2.669 9.299-4.36 13.825-.786.406-1.764.381-2.616.667-1.045.29-2.192.508-3.113 1.023-.986 1.725-1.497 4.038-3.446 4.975-.547.365-1.61.195-1.703 1.056-.333 2.283.656 4.608 2.23 6.229.584.012.966-.7 1.443-1.005 1.856-1.744 4.143-3.3 6.735-3.476 2.277-.23 4.602-.181 6.912-.262-2.39-1.27-5.13-2.41-6.595-4.809a10.078 10.078 0 0 1-.827-1.63l2.478 2.533c1.635-6.38 3.92-12.578 5.438-18.99.438-.742-.42-1.107-.823-1.602-.286-.202-.539-.703-.923-.63z"/><path fill="#fd6464" d="M28.454 1.686c-1.119.01-2.246.095-3.32.43-.22 1.754-.389 3.745.781 5.228.356.51.78.965 1.188 1.432l2.531-.955-3.087-3.15c5.929 2.954 12.037 5.904 18.664 6.842a63.84 63.84 0 0 0 6.017.304c.453-.288.3-.998.177-1.439-.947-1.112-2.273-1.856-3.486-2.651-4.678-2.746-9.907-4.441-15.185-5.6a17.269 17.269 0 0 0-4.28-.44z"/><path fill="#de5858" d="M39.98 31.987c-1.243.923-2.227 2.377-3.794 2.765-3.644.288-7.329-.682-11.008-.484-2.629.107-5.445.39-7.588 2.08-1.116.896-2.323 1.744-3.24 2.847-.028.554.75.78 1.05 1.172.934.712 1.8 1.54 2.807 2.145.631-.556.757-1.53 1.402-2.108 1.309-1.205 3.158-1.63 4.798-2.092 4.486-.97 9.147-.67 13.614-1.776l4.655-1.001c.228-.57-.531-1.012-.751-1.491-.567-.756-1.156-1.494-1.74-2.238l-.204.18z"/><path fill="#ba4a4a" d="M29.26 7.5c-.708.334-1.563.461-2.186.942-.088.523.64.855.93 1.258 1.125 1.108 2.793 1.326 4.185 1.95 3.774 1.357 7.6 2.604 11.521 3.459-1.481.707-3.154.576-4.69.111a27.13 27.13 0 01-9.328-4.253c-1.515 6.366-3.744 12.564-5.422 18.907-.925-.754-1.593-1.813-2.582-2.48-.63.004-.206.767-.084 1.083.924 2.59 3.198 4.371 5.605 5.516.88.504 1.783.926 2.82.9 2.14.174 4.337.67 6.472.23 1.558-.586 2.628-1.97 3.906-2.97-.622-.693-.914-1.662-.51-2.537 1.539-4.633 3.45-9.225 5.05-13.875 2.082-.496 4.585-.89 5.875-2.816.222-.448.876-.945.583-1.477-1.876-.164-3.784-.192-5.664-.177-1.12.095.824.692 1.252.859.607.229 1.395.497 1.865.74-5.345.176-10.525-1.763-15.445-3.74-1.386-.51-2.768-1.239-4.152-1.63zm13.334 27.608c-4.09.913-8.185 1.857-12.386 2.008-3.385.247-6.856.652-9.903 2.263-.695.262-1.269.742-1.54 1.449-.172.55-1.03 1.307-.633 1.698 3.447 2.002 7.05 4.007 11.082 4.457 3.591.551 7.35.802 10.888-.19 2.478-.72 3.861-3.344 3.927-5.792.132-2.046-.35-4.095-1.226-5.938l-.126.027-.083.018z"/><path fill="#9b3d3d" d="M38.85 15.362c-2.985-.756-5.734-1.923-7.866-3.34-.978-.65-2.28-1.868-1.815-1.698l1.997.756c3.254 1.239 7.48 2.592 10.3 3.299l2.804.702-.69.258c-1.679.628-2.329.631-4.73.023zM27.768 6.308l-.293-.333.333.293c.183.162.332.311.332.333 0 .095-.098.018-.372-.293z"/><path fill="#8b3838" d="M45.566 12.918c-3.393-.389-7.22-1.563-13.493-4.138L29.29 7.638l-1.236-1.172c-.68-.645-1.464-1.446-1.744-1.78l-.51-.608 2.471 1.237c6.623 3.316 10.796 4.868 15.754 5.86 1.76.351 3.485.878 4.807 1.467l.909.405-1.634-.012a31.11 31.11 0 0 1-2.54-.117z"/><path fill="#383838" d="M19.003 63.365c-.744-1.63-.854-3.21-.355-5.13.17-.656 1.096-3.554 2.057-6.44a677.285 677.285 0 0 0 1.748-5.284c0-.02-.695-.404-1.543-.853-5.16-2.729-8.047-5.216-9.541-8.22-.675-1.357-.866-2.392-.664-3.611.495-3 3.118-6.364 6.12-7.851.871-.431 2.212-.896 3.866-1.341l1.442-.388 1.069-3.51c2.17-7.125 3.13-10.477 3.044-10.621a14.91 14.91 0 0 0-.665-.843c-1.946-2.35-2.697-5.018-1.9-6.747.398-.864.8-1.33 1.623-1.875l.67-.445C26.621.046 28.556 0 28.556 0s1.819.038 2.67.304l3.085.794c5.906 1.521 10.247 3.17 14.022 5.327 2.07 1.358 3.377 2.396 4.686 3.895.207.242.368.543.35.729 0 0-.042.39-.144.549 0 0-1.71 2.613-2.17 3.077-.453.456-1.606 1.061-3.493 1.834-.917.376-1.891 1.178-2.092 1.723l-1.477 4.08a472.53 472.53 0 0 1-2.197 5.958l-.84 2.206.89 1.182c1.884 2.496 2.781 4.129 3.245 5.9.357 1.366.355 3.946-.005 5.325-.633 2.426-1.742 3.793-3.925 4.836-3.113 1.487-6.85 1.672-12.16.602-.825-.167-1.512-.287-1.527-.268s-.67 1.967-1.453 4.33c-1.745 5.258-2.49 7.318-2.994 8.279-.257.49-.819 1.172-1.678 2.037C20.25 63.807 20.003 64 19.676 64c-.344 0-.412-.064-.673-.635zm2.226-3.061c1.468-2.444 2.544-5.264 4.084-10.702l.947-3.245c.021-.021 1.012.124 2.2.323 3.1.52 4.94.666 7.352.583 3.419-.118 5.077-.61 6.331-1.882.72-.73 1.27-1.775 1.542-2.932.24-1.018.238-3.14-.005-4.32-.379-1.844-.808-2.621-2.958-5.35-.957-1.215-1.207-1.667-1.207-2.19 0-.456.52-2.005 1.845-5.494l2.21-5.99 1.247-3.45.647-.155c3.433-.826 4.365-1.336 5.442-2.98.404-.616.514-1.066.514-1.066s.182-.738-.045-1.014l-.817-.669C46.78 6.681 39.943 3.8 32.875 2.323c-1.923-.402-2.323-.447-4.07-.454-1.238-.006-2.208.052-2.694.16-.918.203-.927.223-.932 2.191-.003 1.273.025 1.453.333 2.11.379.809.89 1.488 1.925 2.555l.71.733-.193.538c-.105.296-.948 3.043-1.872 6.105l-2.33 7.495-.647 1.928-1.506.323c-2.972.637-4.066 1.023-5.152 1.816-1.395 1.02-2.882 2.715-3.859 4.398-.318.549-.343.684-.342 1.876 0 1.37.154 2.067.682 3.108a9.37 9.37 0 0 0 2.164 2.722c2.53 2.107 4.779 3.541 7.672 4.893l1.581.74-.884 2.473-2.035 5.934c-1.25 3.757-1.441 4.723-1.26 6.342a21.83 21.83 0 0 1 .102 1.059c.012.41.201.2.96-1.064z"/></svg> diff --git a/assets/static/vendor/leaflet-elevation/images/elevation.svg b/assets/static/vendor/leaflet-elevation/images/elevation.svg index 43c0e25..dccf6d7 100644 --- a/assets/static/vendor/leaflet-elevation/images/elevation.svg +++ b/assets/static/vendor/leaflet-elevation/images/elevation.svg @@ -1 +1 @@ -<svg viewBox="0 0 36 36" style="display: var(--ele-toggle-bg, inline-block);"><path fill="var(--ele-area, #addb55)" fill-opacity=".8" opacity=".9" d="m 28.3,23.9 -4.2,-8 -3.9,-0.2 -2.7,1.8 -2.4,-5.5 -5.2,6.2 0,5.7" /><path fill="none" stroke="var(--ele-line, var(--ele-stroke, #000))" stroke-width="1.5" d="m 9.9,17.9 1.1,0 4.3,-6.2 2.5,5.6 2.5,-2.3 3.7,0.2 4,8.3 0,0.4" /><path fill="none" stroke="#737373" stroke-linecap="square" d="m 8.6,8.1 0,19.8 m 21.3,-2.4 -23.8,0" /></svg>
+<svg viewBox="0 0 36 36" style="display: var(--ele-toggle-bg, inline-block);"><path fill="var(--ele-area, #addb55)" fill-opacity=".8" opacity=".9" d="m 28.3,23.9 -4.2,-8 -3.9,-0.2 -2.7,1.8 -2.4,-5.5 -5.2,6.2 0,5.7" /><path fill="none" stroke="var(--ele-line, var(--ele-stroke, #000))" stroke-width="1.5" d="m 9.9,17.9 1.1,0 4.3,-6.2 2.5,5.6 2.5,-2.3 3.7,0.2 4,8.3 0,0.4" /><path fill="none" stroke="#737373" stroke-linecap="square" d="m 8.6,8.1 0,19.8 m 21.3,-2.4 -23.8,0" /></svg> diff --git a/assets/static/vendor/leaflet-elevation/libs/fullpage.css b/assets/static/vendor/leaflet-elevation/libs/fullpage.css index c2b8539..d1343d6 100644 --- a/assets/static/vendor/leaflet-elevation/libs/fullpage.css +++ b/assets/static/vendor/leaflet-elevation/libs/fullpage.css @@ -1,13 +1,13 @@ -html,
-body,
-.leaflet-map {
- height: 100%;
- width: 100%;
- padding: 0px;
- margin: 0px;
-}
-
-body {
- display: flex;
- flex-direction: column;
-}
+html, +body, +.leaflet-map { + height: 100%; + width: 100%; + padding: 0px; + margin: 0px; +} + +body { + display: flex; + flex-direction: column; +} diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.css b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.css index fcf9a40..d0fb08c 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.css +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.css @@ -1,8 +1,8 @@ -.dist-marker {
- font-size: 9px;
- border: 1px solid #777;
- border-radius: 10px;
- text-align: center;
- color: #000;
- background: #fff;
-}
+.dist-marker { + font-size: 9px; + border: 1px solid #777; + border-radius: 10px; + text-align: center; + color: #000; + background: #fff; +} diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.js index 43beb77..4f09aff 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.js @@ -1,314 +1,322 @@ -/*
- * Copyright (c) 2022, GPL-3.0+ Project, Raruto
- *
- * This file is free software: you may copy, redistribute and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 2 of the License, or (at your
- * option) any later version.
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * This file incorporates work covered by the following copyright and
- * permission notice:
- *
- * Copyright (c) 2014- Doroszlai Attila, 2016- Phil Whitehurst
- *
- * Permission to use, copy, modify, and/or distribute this software
- * for any purpose with or without fee is hereby granted, provided
- * that the above copyright notice and this permission notice appear
- * in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-// TODO: the "L.DistanceMarker" (canvas marker) class could be alternatively provided by "leaflet-rotate"?
-
-L.DistanceMarker = L.CircleMarker.extend({
- _updatePath: function () {
- let ctx = this._renderer._ctx;
- let p = this._point;
-
- // Calculate image direction (rotation)
- this.options.rotation = this.options.rotation || 0;
-
- // Draw circle marker (canvas point)
- if (this.options.radius && this._renderer._updateCircle) {
- this._renderer._updateCircle(this);
- }
-
- // Draw image over circle (distance marker)
- if (this.options.icon && this.options.icon.url) {
- if (!this.options.icon.element) {
- const icon = document.createElement('img');
- this.options.icon = L.extend({ rotate: 0, size: [40, 40], offset: { x: 0, y: 0 } }, this.options.icon);
- this.options.icon.rotate += this.options.rotation;
- this.options.icon.element = icon;
- icon.src = this.options.icon.url;
- icon.onload = () => this.redraw();
- icon.onerror = () => this.options.icon = null;
- } else {
- const icon = this.options.icon;
- let cx = p.x + icon.offset.x;
- let cy = p.y + icon.offset.y;
- ctx.save();
- if (icon.rotate) {
- ctx.translate(p.x, p.y);
- ctx.rotate(icon.rotate);
- cx = 0;
- cy = 0;
- }
- ctx.drawImage(icon.element, cx - icon.size[0] / 2, cy - icon.size[1] / 2, icon.size[0], icon.size[1]);
- ctx.restore();
- }
- }
-
- // Add a label inside the circle (distance marker)
- if (this.options.label) {
- let cx = p.x, cy = p.y;
- ctx.save();
-
- ctx.font = this.options.font || 'normal 7pt "Helvetica Neue", Arial, Helvetica, sans-serif';
- ctx.textAlign = "center";
- ctx.textBaseline = "middle";
- ctx.fillStyle = this.options.fillStyle || 'black';
-
- // TODO rescale circle to fit text
- // let fontSize = Number(/[0-9\.]+/.exec(ctx.font)[0]);
- // let fontWidth = ctx.measureText(this.options.html).width;
-
- if (this.options.rotation) {
- ctx.translate(p.x, p.y);
- ctx.rotate(this.options.rotation);
- cx = 0;
- cy = 0;
- }
-
- // Temporary fix to prevent stroke blurs at higher zoom levels
- if (this._map.getZoom() > 17) {
- ctx.fillStyle = this.options.strokeStyle || 'black';
- }
-
- ctx.fillText(this.options.label, cx, cy);
-
- if (this.options.strokeStyle && this._map.getZoom() <= 17) {
- ctx.strokeStyle = this.options.strokeStyle;
- ctx.strokeText(this.options.label, cx, cy);
- }
-
- ctx.restore();
- }
- }
-});
-
-L.DistanceMarkers = L.LayerGroup.extend({
- options: {
- cssClass: 'dist-marker',
- iconSize: [12, 12],
- arrowSize: [10, 10],
- arrowUrl: "data:image/svg+xml,%3Csvg transform='rotate(90)' xmlns='http://www.w3.org/2000/svg' width='560px' height='560px' viewBox='0 0 560 560'%3E%3Cpath stroke-width='35' fill='%23000' stroke='%23FFF' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E",
- offset: 1000,
- showAll: 12,
- textFunction: (distance, i, offset) => i,
- distance: true,
- direction: true,
- },
- initialize: function (line, map, options) {
-
- this._layers = {};
- this._zoomLayers = {};
-
- options = L.setOptions(this, options);
-
- let preferCanvas = map.options.preferCanvas;
- let showAll = Math.min(map.getMaxZoom(), options.showAll);
-
- // You should use "leaflet-rotate" to show rotated arrow markers (preferCanvas: false)
- if (!preferCanvas && !map.options.rotate) {
- console.warn('Missing dependency: "leaflet-rotate"');
- }
-
- // Get line coords as an array
- let coords = typeof line.getLatLngs == 'function' ? line.getLatLngs() : line;
-
- // Handle "MultiLineString" features
- coords = L.LineUtil.isFlat(coords) ? [coords] : coords;
-
- coords.forEach(latlngs => {
- // Get accumulated line lengths as well as overall length
- let accumulated = L.GeometryUtil.accumulatedLengths(latlngs);
- let length = accumulated.length > 0 ? accumulated[accumulated.length - 1] : 0;
-
- // count = Number of distance markers to be added
- // j = Position in accumulated line length array
- for (let i = 1, count = Math.floor(length / options.offset), j = 0; i <= count; ++i) {
-
- let distance = options.offset * i;
-
- // Find the first accumulated distance that is greater than the distance of this marker
- while (j < accumulated.length - 1 && accumulated[j] < distance) ++j;
-
- // Grab two nearest points either side marker position
- let p1 = latlngs[j - 1];
- let p2 = latlngs[j];
- let m_line = L.polyline([p1, p2]);
-
- // and create a simple line to interpolate on
- let ratio = (distance - accumulated[j - 1]) / (accumulated[j] - accumulated[j - 1]);
- let position = L.GeometryUtil.interpolateOnLine(map, m_line, ratio);
- let delta = map.project(p2).subtract(map.project(p1));
- let angle = Math.atan2(delta.y, delta.x);
-
- // Generate distance marker label
- let text = options.textFunction.call(this, distance, i, options.offset);
-
- // Grouping layer of visible layers at zoom level (arrow + distance)
- let zoom = this._minimumZoomLevelForItem(i, showAll);
- let markers = this._zoomLayers[zoom] = this._zoomLayers[zoom] || L.layerGroup()
-
- // create arrow markers
- if (options.direction && ((options.distance && i % 2 == 1) || !options.distance)) {
- if (preferCanvas) {
- markers.addLayer(
- new L.DistanceMarker(p1, {
- radius: 0,
- icon: {
- url: options.arrowUrl, //image link
- size: options.arrowSize, //image size ( default [40, 40] )
- rotate: 0, //image base rotate ( default 0 )
- offset: { x: 0, y: 0 }, //image offset ( default { x: 0, y: 0 } )
- },
- rotation: angle,
- interactive: false,
- // label: '⮞', //'➜',
- // font: 'normal 20pt "Helvetica Neue", Arial, Helvetica, sans-serif',
- // fillStyle: 'white',//'#3366CC',
- // strokeStyle: 'black',
- })
- );
- } else {
- markers.addLayer(
- L.marker(position.latLng, {
- icon: L.icon({
- iconUrl: options.arrowUrl,
- iconSize: options.arrowSize,
- }),
- // NB the following option is added by "leaflet-rotate"
- rotation: angle,
- interactive: false,
- })
- );
- }
- }
-
- // create distance markers
- if (options.distance && i % 2 == 0) {
- if (preferCanvas) {
- markers.addLayer(
- new L.DistanceMarker(position.latLng, {
- label: text, // TODO: handle text rotation (leaflet-rotate)
- radius: 7,
- fillColor: '#fff',
- fillOpacity: 1,
- fillStyle: 'black',
- color: '#777',
- weight: 1,
- interactive: false,
- })
- );
- } else {
- markers.addLayer(
- L.marker(position.latLng, {
- title: text,
- icon: L.divIcon({
- className: options.cssClass,
- html: text,
- iconSize: options.iconSize
- }),
- interactive: false,
- })
- );
- }
- }
- }
- });
-
- const updateMarkerVisibility = () => {
- let oldZoom = this._lastZoomLevel || 0;
- let newZoom = map.getZoom();
- if (newZoom > oldZoom) {
- for (let i = oldZoom + 1; i <= newZoom; ++i) {
- if (this._zoomLayers[i] !== undefined) {
- this.addLayer(this._zoomLayers[i]);
- }
- }
- } else if (newZoom < oldZoom) {
- for (let i = oldZoom; i > newZoom; --i) {
- if (this._zoomLayers[i] !== undefined) {
- this.removeLayer(this._zoomLayers[i]);
- }
- }
- }
- this._lastZoomLevel = newZoom;
- };
- map.on('zoomend', updateMarkerVisibility);
- updateMarkerVisibility();
- },
-
- _minimumZoomLevelForItem: function (i, zoom) {
- while (i > 0 && i % 2 === 0) {
- --zoom;
- i = Math.floor(i / 2);
- }
- return zoom;
- },
-
-});
-
-L.Polyline.include({
-
- _originalOnAdd: L.Polyline.prototype.onAdd,
- _originalOnRemove: L.Polyline.prototype.onRemove,
-
- addDistanceMarkers: function () {
- if (this._map && this._distanceMarkers) {
- this._map.addLayer(this._distanceMarkers);
- }
- },
-
- removeDistanceMarkers: function () {
- if (this._map && this._distanceMarkers) {
- this._map.removeLayer(this._distanceMarkers);
- }
- },
-
- onAdd: function (map) {
- this._originalOnAdd(map);
-
- let opts = this.options.distanceMarkers || {};
- if (this.options.distanceMarkers) {
- this._distanceMarkers = this._distanceMarkers || new L.DistanceMarkers(this, map, opts);
- }
- if (opts.lazy === undefined || opts.lazy === false) {
- this.addDistanceMarkers();
- }
- },
-
- onRemove: function (map) {
- this.removeDistanceMarkers();
- this._originalOnRemove(map);
- }
-
-});
+/* + * Copyright (c) 2022, GPL-3.0+ Project, Raruto + * + * This file is free software: you may copy, redistribute and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 2 of the License, or (at your + * option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (c) 2014- Doroszlai Attila, 2016- Phil Whitehurst + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose with or without fee is hereby granted, provided + * that the above copyright notice and this permission notice appear + * in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +// TODO: the "L.DistanceMarker" (canvas marker) class could be alternatively provided by "leaflet-rotate"? + +L.DistanceMarker = L.CircleMarker.extend({ + _updatePath () { + let ctx = this._renderer._ctx; + let p = this._point; + + // Calculate image direction (rotation) + this.options.rotation = this.options.rotation || 0; + + // Draw circle marker (canvas point) + if (this.options.radius && this._renderer._updateCircle) { + this._renderer._updateCircle(this); + } + + // Draw image over circle (distance marker) + if (this.options.icon && this.options.icon.url) { + if (!this.options.icon.element) { + const icon = document.createElement('img'); + this.options.icon = Object.assign({ rotate: 0, size: [40, 40], offset: { x: 0, y: 0 } }, this.options.icon); + this.options.icon.rotate += this.options.rotation; + this.options.icon.element = icon; + icon.src = this.options.icon.url; + icon.onload = () => this.redraw(); + icon.onerror = () => this.options.icon = null; + } else { + const icon = this.options.icon; + let cx = p.x + icon.offset.x; + let cy = p.y + icon.offset.y; + ctx.save(); + if (icon.rotate) { + ctx.translate(p.x, p.y); + ctx.rotate(icon.rotate); + cx = 0; + cy = 0; + } + ctx.drawImage(icon.element, cx - icon.size[0] / 2, cy - icon.size[1] / 2, icon.size[0], icon.size[1]); + ctx.restore(); + } + } + + // Add a label inside the circle (distance marker) + if (this.options.label) { + let cx = p.x, cy = p.y; + ctx.save(); + + ctx.font = this.options.font || 'normal 7pt "Helvetica Neue", Arial, Helvetica, sans-serif'; + ctx.textAlign = "center"; + ctx.textBaseline = "middle"; + ctx.fillStyle = this.options.fillStyle || 'black'; + + // TODO rescale circle to fit text + // let fontSize = Number(/[0-9\.]+/.exec(ctx.font)[0]); + // let fontWidth = ctx.measureText(this.options.html).width; + + if (this.options.rotation) { + ctx.translate(p.x, p.y); + ctx.rotate(this.options.rotation); + cx = 0; + cy = 0; + } + + // Temporary fix to prevent stroke blurs at higher zoom levels + if (this._map.getZoom() > 17) { + ctx.fillStyle = this.options.strokeStyle || 'black'; + } + + ctx.fillText(this.options.label, cx, cy); + + if (this.options.strokeStyle && this._map.getZoom() <= 17) { + ctx.strokeStyle = this.options.strokeStyle; + ctx.strokeText(this.options.label, cx, cy); + } + + ctx.restore(); + } + } +}); + +L.DistanceMarkers = L.LayerGroup.extend({ + options: { + cssClass: 'dist-marker', + iconSize: [12, 12], + arrowSize: [10, 10], + arrowUrl: "data:image/svg+xml,%3Csvg transform='rotate(90)' xmlns='http://www.w3.org/2000/svg' width='560px' height='560px' viewBox='0 0 560 560'%3E%3Cpath stroke-width='35' fill='%23000' stroke='%23FFF' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E", + offset: 1000, + showAll: 12, + textFunction: (distance, i, offset) => i, + distance: true, + direction: true, + }, + initialize (line, map, options) { + + this._layers = {}; + this._zoomLayers = {}; + + options = L.Util.setOptions(this, options); + + let preferCanvas = map.options.preferCanvas; + let showAll = Math.min(map.getMaxZoom(), options.showAll); + + // You should use "leaflet-rotate" to show rotated arrow markers (preferCanvas: false) + if (!preferCanvas && !map.options.rotate) { + console.warn('Missing dependency: "leaflet-rotate"'); + } + + // Get line coords as an array + let coords = typeof line.getLatLngs == 'function' ? line.getLatLngs() : line; + + // Handle "MultiLineString" features + coords = L.LineUtil.isFlat(coords) ? [coords] : coords; + + coords.forEach(latlngs => { + // Get accumulated line lengths as well as overall length + let totalLength = 0; + let accumulated = latlngs.map((latlng, index) => { + if (index) totalLength += latlngs[index - 1].distanceTo(latlng); + return totalLength; + }); + let length = accumulated.length > 0 ? accumulated[accumulated.length - 1] : 0; + + // count = Number of distance markers to be added + // j = Position in accumulated line length array + for (let i = 1, count = Math.floor(length / options.offset), j = 0; i <= count; ++i) { + + let distance = options.offset * i; + + // Find the first accumulated distance that is greater than the distance of this marker + while (j < accumulated.length - 1 && accumulated[j] < distance) ++j; + + // Grab two nearest points either side marker position + let p1 = latlngs[j - 1]; + let p2 = latlngs[j]; + let ratio = (distance - accumulated[j - 1]) / (accumulated[j] - accumulated[j - 1]); + let from = map.project(p1); + let to = map.project(p2); + let position = { + latLng: map.unproject(new L.Point( + from.x + (to.x - from.x) * ratio, + from.y + (to.y - from.y) * ratio + )), + }; + let delta = map.project(p2).subtract(map.project(p1)); + let angle = Math.atan2(delta.y, delta.x); + + // Generate distance marker label + let text = options.textFunction.call(this, distance, i, options.offset); + + // Grouping layer of visible layers at zoom level (arrow + distance) + let zoom = this._minimumZoomLevelForItem(i, showAll); + let markers = this._zoomLayers[zoom] = this._zoomLayers[zoom] || new L.LayerGroup() + + // create arrow markers + if (options.direction && ((options.distance && i % 2 == 1) || !options.distance)) { + if (preferCanvas) { + markers.addLayer( + new L.DistanceMarker(p1, { + radius: 0, + icon: { + url: options.arrowUrl, //image link + size: options.arrowSize, //image size ( default [40, 40] ) + rotate: 0, //image base rotate ( default 0 ) + offset: { x: 0, y: 0 }, //image offset ( default { x: 0, y: 0 } ) + }, + rotation: angle, + interactive: false, + // label: '⮞', //'➜', + // font: 'normal 20pt "Helvetica Neue", Arial, Helvetica, sans-serif', + // fillStyle: 'white',//'#3366CC', + // strokeStyle: 'black', + }) + ); + } else { + markers.addLayer( + new L.Marker(position.latLng, { + icon: new L.Icon({ + iconUrl: options.arrowUrl, + iconSize: options.arrowSize, + }), + // NB the following option is added by "leaflet-rotate" + rotation: angle, + interactive: false, + }) + ); + } + } + + // create distance markers + if (options.distance && i % 2 == 0) { + if (preferCanvas) { + markers.addLayer( + new L.DistanceMarker(position.latLng, { + label: text, // TODO: handle text rotation (leaflet-rotate) + radius: 7, + fillColor: '#fff', + fillOpacity: 1, + fillStyle: 'black', + color: '#777', + weight: 1, + interactive: false, + }) + ); + } else { + markers.addLayer( + new L.Marker(position.latLng, { + title: text, + icon: new L.DivIcon({ + className: options.cssClass, + html: text, + iconSize: options.iconSize + }), + interactive: false, + }) + ); + } + } + } + }); + + const updateMarkerVisibility = () => { + let oldZoom = this._lastZoomLevel || 0; + let newZoom = map.getZoom(); + if (newZoom > oldZoom) { + for (let i = oldZoom + 1; i <= newZoom; ++i) { + if (this._zoomLayers[i] !== undefined) { + this.addLayer(this._zoomLayers[i]); + } + } + } else if (newZoom < oldZoom) { + for (let i = oldZoom; i > newZoom; --i) { + if (this._zoomLayers[i] !== undefined) { + this.removeLayer(this._zoomLayers[i]); + } + } + } + this._lastZoomLevel = newZoom; + }; + map.on('zoomend', updateMarkerVisibility); + updateMarkerVisibility(); + }, + + _minimumZoomLevelForItem (i, zoom) { + while (i > 0 && i % 2 === 0) { + --zoom; + i = Math.floor(i / 2); + } + return zoom; + }, + +}); + +L.Polyline.include({ + + _originalOnAdd: L.Polyline.prototype.onAdd, + _originalOnRemove: L.Polyline.prototype.onRemove, + + addDistanceMarkers () { + if (this._map && this._distanceMarkers) { + this._map.addLayer(this._distanceMarkers); + } + }, + + removeDistanceMarkers () { + if (this._map && this._distanceMarkers) { + this._map.removeLayer(this._distanceMarkers); + } + }, + + onAdd (map) { + this._originalOnAdd(map); + + let opts = this.options.distanceMarkers || {}; + if (this.options.distanceMarkers) { + this._distanceMarkers = this._distanceMarkers || new L.DistanceMarkers(this, map, opts); + } + if (opts.lazy === undefined || opts.lazy === false) { + this.addDistanceMarkers(); + } + }, + + onRemove (map) { + this.removeDistanceMarkers(); + this._originalOnRemove(map); + } + +}); diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.css b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.css index 473e8f3..3887d3d 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.css +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.css @@ -1 +1 @@ -.dist-marker{font-size:9px;border:1px solid #777;border-radius:10px;text-align:center;color:#000;background:#fff}
\ No newline at end of file +.dist-marker{font-size:9px;border:1px solid #777;border-radius:10px;text-align:center;color:#000;background:#fff} diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.js index b8bc58b..1b669ed 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-distance-marker.min.js @@ -1 +1 @@ -L.DistanceMarker=L.CircleMarker.extend({_updatePath:function(){let ctx=this._renderer._ctx,p=this._point;if(this.options.rotation=this.options.rotation||0,this.options.radius&&this._renderer._updateCircle&&this._renderer._updateCircle(this),this.options.icon&&this.options.icon.url)if(this.options.icon.element){const icon=this.options.icon;let cx=p.x+icon.offset.x,cy=p.y+icon.offset.y;ctx.save(),icon.rotate&&(ctx.translate(p.x,p.y),ctx.rotate(icon.rotate),cx=0,cy=0),ctx.drawImage(icon.element,cx-icon.size[0]/2,cy-icon.size[1]/2,icon.size[0],icon.size[1]),ctx.restore()}else{const icon=document.createElement("img");this.options.icon=L.extend({rotate:0,size:[40,40],offset:{x:0,y:0}},this.options.icon),this.options.icon.rotate+=this.options.rotation,this.options.icon.element=icon,icon.src=this.options.icon.url,icon.onload=()=>this.redraw(),icon.onerror=()=>this.options.icon=null}if(this.options.label){let cx=p.x,cy=p.y;ctx.save(),ctx.font=this.options.font||'normal 7pt "Helvetica Neue", Arial, Helvetica, sans-serif',ctx.textAlign="center",ctx.textBaseline="middle",ctx.fillStyle=this.options.fillStyle||"black",this.options.rotation&&(ctx.translate(p.x,p.y),ctx.rotate(this.options.rotation),cx=0,cy=0),this._map.getZoom()>17&&(ctx.fillStyle=this.options.strokeStyle||"black"),ctx.fillText(this.options.label,cx,cy),this.options.strokeStyle&&this._map.getZoom()<=17&&(ctx.strokeStyle=this.options.strokeStyle,ctx.strokeText(this.options.label,cx,cy)),ctx.restore()}}}),L.DistanceMarkers=L.LayerGroup.extend({options:{cssClass:"dist-marker",iconSize:[12,12],arrowSize:[10,10],arrowUrl:"data:image/svg+xml,%3Csvg transform='rotate(90)' xmlns='http://www.w3.org/2000/svg' width='560px' height='560px' viewBox='0 0 560 560'%3E%3Cpath stroke-width='35' fill='%23000' stroke='%23FFF' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E",offset:1e3,showAll:12,textFunction:(distance,i,offset)=>i,distance:!0,direction:!0},initialize:function(line,map,options){this._layers={},this._zoomLayers={},options=L.setOptions(this,options);let preferCanvas=map.options.preferCanvas,showAll=Math.min(map.getMaxZoom(),options.showAll);preferCanvas||map.options.rotate||console.warn('Missing dependency: "leaflet-rotate"');let coords="function"==typeof line.getLatLngs?line.getLatLngs():line;coords=L.LineUtil.isFlat(coords)?[coords]:coords,coords.forEach(latlngs=>{let accumulated=L.GeometryUtil.accumulatedLengths(latlngs),length=accumulated.length>0?accumulated[accumulated.length-1]:0;for(let i=1,count=Math.floor(length/options.offset),j=0;i<=count;++i){let distance=options.offset*i;for(;j<accumulated.length-1&&accumulated[j]<distance;)++j;let p1=latlngs[j-1],p2=latlngs[j],m_line=L.polyline([p1,p2]),ratio=(distance-accumulated[j-1])/(accumulated[j]-accumulated[j-1]),position=L.GeometryUtil.interpolateOnLine(map,m_line,ratio),delta=map.project(p2).subtract(map.project(p1)),angle=Math.atan2(delta.y,delta.x),text=options.textFunction.call(this,distance,i,options.offset),zoom=this._minimumZoomLevelForItem(i,showAll),markers=this._zoomLayers[zoom]=this._zoomLayers[zoom]||L.layerGroup();options.direction&&(options.distance&&i%2==1||!options.distance)&&(preferCanvas?markers.addLayer(new L.DistanceMarker(p1,{radius:0,icon:{url:options.arrowUrl,size:options.arrowSize,rotate:0,offset:{x:0,y:0}},rotation:angle,interactive:!1})):markers.addLayer(L.marker(position.latLng,{icon:L.icon({iconUrl:options.arrowUrl,iconSize:options.arrowSize}),rotation:angle,interactive:!1}))),options.distance&&i%2==0&&(preferCanvas?markers.addLayer(new L.DistanceMarker(position.latLng,{label:text,radius:7,fillColor:"#fff",fillOpacity:1,fillStyle:"black",color:"#777",weight:1,interactive:!1})):markers.addLayer(L.marker(position.latLng,{title:text,icon:L.divIcon({className:options.cssClass,html:text,iconSize:options.iconSize}),interactive:!1})))}});const updateMarkerVisibility=()=>{let oldZoom=this._lastZoomLevel||0,newZoom=map.getZoom();if(newZoom>oldZoom)for(let i=oldZoom+1;i<=newZoom;++i)void 0!==this._zoomLayers[i]&&this.addLayer(this._zoomLayers[i]);else if(newZoom<oldZoom)for(let i=oldZoom;i>newZoom;--i)void 0!==this._zoomLayers[i]&&this.removeLayer(this._zoomLayers[i]);this._lastZoomLevel=newZoom};map.on("zoomend",updateMarkerVisibility),updateMarkerVisibility()},_minimumZoomLevelForItem:function(i,zoom){for(;i>0&&i%2==0;)--zoom,i=Math.floor(i/2);return zoom}}),L.Polyline.include({_originalOnAdd:L.Polyline.prototype.onAdd,_originalOnRemove:L.Polyline.prototype.onRemove,addDistanceMarkers:function(){this._map&&this._distanceMarkers&&this._map.addLayer(this._distanceMarkers)},removeDistanceMarkers:function(){this._map&&this._distanceMarkers&&this._map.removeLayer(this._distanceMarkers)},onAdd:function(map){this._originalOnAdd(map);let opts=this.options.distanceMarkers||{};this.options.distanceMarkers&&(this._distanceMarkers=this._distanceMarkers||new L.DistanceMarkers(this,map,opts)),void 0!==opts.lazy&&!1!==opts.lazy||this.addDistanceMarkers()},onRemove:function(map){this.removeDistanceMarkers(),this._originalOnRemove(map)}});
\ No newline at end of file +L.DistanceMarker=L.CircleMarker.extend({_updatePath(){let t=this._renderer._ctx,i=this._point;if(this.options.rotation=this.options.rotation||0,this.options.radius&&this._renderer._updateCircle&&this._renderer._updateCircle(this),this.options.icon&&this.options.icon.url)if(this.options.icon.element){const e=this.options.icon;let s=i.x+e.offset.x,h=i.y+e.offset.y;t.save(),e.rotate&&(t.translate(i.x,i.y),t.rotate(e.rotate),s=0,h=0),t.drawImage(e.element,s-e.size[0]/2,h-e.size[1]/2,e.size[0],e.size[1]),t.restore()}else{const e=document.createElement("img");this.options.icon=Object.assign({rotate:0,size:[40,40],offset:{x:0,y:0}},this.options.icon),this.options.icon.rotate+=this.options.rotation,this.options.icon.element=e,e.src=this.options.icon.url,e.onload=()=>this.redraw(),e.onerror=()=>this.options.icon=null}if(this.options.label){let e=i.x,s=i.y;t.save(),t.font=this.options.font||'normal 7pt "Helvetica Neue", Arial, Helvetica, sans-serif',t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.options.fillStyle||"black",this.options.rotation&&(t.translate(i.x,i.y),t.rotate(this.options.rotation),e=0,s=0),this._map.getZoom()>17&&(t.fillStyle=this.options.strokeStyle||"black"),t.fillText(this.options.label,e,s),this.options.strokeStyle&&this._map.getZoom()<=17&&(t.strokeStyle=this.options.strokeStyle,t.strokeText(this.options.label,e,s)),t.restore()}}}),L.DistanceMarkers=L.LayerGroup.extend({options:{cssClass:"dist-marker",iconSize:[12,12],arrowSize:[10,10],arrowUrl:"data:image/svg+xml,%3Csvg transform='rotate(90)' xmlns='http://www.w3.org/2000/svg' width='560px' height='560px' viewBox='0 0 560 560'%3E%3Cpath stroke-width='35' fill='%23000' stroke='%23FFF' d='M280,40L522,525L280,420L38,525z'/%3E%3C/svg%3E",offset:1e3,showAll:12,textFunction:(t,i,e)=>i,distance:!0,direction:!0},initialize(t,i,e){this._layers={},this._zoomLayers={},e=L.Util.setOptions(this,e);let s=i.options.preferCanvas,h=Math.min(i.getMaxZoom(),e.showAll);!s&&!i.options.rotate&&console.warn('Missing dependency: "leaflet-rotate"');let c=typeof t.getLatLngs=="function"?t.getLatLngs():t;c=L.LineUtil.isFlat(c)?[c]:c,c.forEach(r=>{let n=0,o=r.map((a,d)=>(d&&(n+=r[d-1].distanceTo(a)),n)),S=o.length>0?o[o.length-1]:0;for(let a=1,d=Math.floor(S/e.offset),l=0;a<=d;++a){let y=e.offset*a;for(;l<o.length-1&&o[l]<y;)++l;let p=r[l-1],g=r[l],w=(y-o[l-1])/(o[l]-o[l-1]),f=i.project(p),x=i.project(g),_={latLng:i.unproject(new L.Point(f.x+(x.x-f.x)*w,f.y+(x.y-f.y)*w))},v=i.project(g).subtract(i.project(p)),M=Math.atan2(v.y,v.x),k=e.textFunction.call(this,y,a,e.offset),z=this._minimumZoomLevelForItem(a,h),m=this._zoomLayers[z]=this._zoomLayers[z]||new L.LayerGroup;e.direction&&(e.distance&&a%2==1||!e.distance)&&(s?m.addLayer(new L.DistanceMarker(p,{radius:0,icon:{url:e.arrowUrl,size:e.arrowSize,rotate:0,offset:{x:0,y:0}},rotation:M,interactive:!1})):m.addLayer(new L.Marker(_.latLng,{icon:new L.Icon({iconUrl:e.arrowUrl,iconSize:e.arrowSize}),rotation:M,interactive:!1}))),e.distance&&a%2==0&&(s?m.addLayer(new L.DistanceMarker(_.latLng,{label:k,radius:7,fillColor:"#fff",fillOpacity:1,fillStyle:"black",color:"#777",weight:1,interactive:!1})):m.addLayer(new L.Marker(_.latLng,{title:k,icon:new L.DivIcon({className:e.cssClass,html:k,iconSize:e.iconSize}),interactive:!1})))}});const u=()=>{let r=this._lastZoomLevel||0,n=i.getZoom();if(n>r)for(let o=r+1;o<=n;++o)this._zoomLayers[o]!==void 0&&this.addLayer(this._zoomLayers[o]);else if(n<r)for(let o=r;o>n;--o)this._zoomLayers[o]!==void 0&&this.removeLayer(this._zoomLayers[o]);this._lastZoomLevel=n};i.on("zoomend",u),u()},_minimumZoomLevelForItem(t,i){for(;t>0&&t%2===0;)--i,t=Math.floor(t/2);return i}}),L.Polyline.include({_originalOnAdd:L.Polyline.prototype.onAdd,_originalOnRemove:L.Polyline.prototype.onRemove,addDistanceMarkers(){this._map&&this._distanceMarkers&&this._map.addLayer(this._distanceMarkers)},removeDistanceMarkers(){this._map&&this._distanceMarkers&&this._map.removeLayer(this._distanceMarkers)},onAdd(t){this._originalOnAdd(t);let i=this.options.distanceMarkers||{};this.options.distanceMarkers&&(this._distanceMarkers=this._distanceMarkers||new L.DistanceMarkers(this,t,i)),(i.lazy===void 0||i.lazy===!1)&&this.addDistanceMarkers()},onRemove(t){this.removeDistanceMarkers(),this._originalOnRemove(t)}}); diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.js index 74c672d..764c227 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.js @@ -1,636 +1,636 @@ -/*
- * Copyright (c) 2023, GPL-3.0+ Project, Raruto
- *
- * This file is free software: you may copy, redistribute and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 2 of the License, or (at your
- * option) any later version.
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * This file incorporates work covered by the following copyright and
- * permission notice:
- *
- * Copyright (c) GPL-3.0+ Project - 2018- Dražen Tutić - https://github.com/dtutic/Leaflet.EdgeScaleBar
- * Copyright (c) MIT License (MIT) - 2015- Xisco Guaita - https://github.com/xguaita/Leaflet.MapCenterCoord
- */
-
-/**
- * Original source: https://github.com/xguaita/Leaflet.MapCenterCoord
- */
-L.Control.EdgeScale = L.Control.extend({
-
- // Defaults
- options: {
- position: 'bottomleft',
- icon: true,
- coords: true,
- bar: true,
- onMove: true,
- template: '{y} | {x}', // https://en.wikipedia.org/wiki/ISO_6709
- projected: false,
- formatProjected: '#.##0,000',
- latlngFormat: 'DD', // DD, DM, DMS
- latlngDesignators: true,
- latLngFormatter: undefined,
- iconStyle: {
- background: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 100 100'%3E%3Cg stroke='%23fff'%3E%3Ccircle cx='50' cy='50.2' r='3.9' stroke-width='2' /%3E%3Cpath stroke-width='3' d='M5 54h32a4 4 0 1 0 0-8H5a4 4 0 1 0 0 8z M54 5a4 4 0 1 0-8 0v32a4 4 0 1 0 8 0V5z M99 50c0-2-2-4-4-4H63a4 4 0 1 0 0 8h32c2 0 4-1 4-4zM46 95a4 4 0 1 0 8 0V64a4 4 0 1 0-8 0v31z'/%3E%3C/g%3E%3C/svg%3E%0A")`,
- width: '24px',
- height: '24px',
- left: 'calc(50% - 12px)',
- top: 'calc(50% - 12px)',
- content: '',
- display: 'block',
- position: 'absolute',
- zIndex: 999,
- pointerEvents: 'none',
- },
- containerStyle: {
- backgroundColor: 'rgba(255, 255, 255, 0.7)',
- boxShadow: '0 0 5px #bbb',
- borderRadius: '3px',
- padding: '3px 2px',
- color: '#333',
- font: '11px/1.5 Consolas, monaco, monospace',
- writingMode: 'vertical-lr',
- },
- },
-
- initialize: function(options) {
- L.setOptions(this, options);
- },
-
- onAdd: function (map) {
-
- if (this.options.bar) {
- this._scaleBar = (new L.Control.EdgeScale.Layer(true === this.options.bar ? {} : this.options.bar)).addTo(map);
- }
-
- // create a DOM element and put it into overlayPane
- if (this.options.icon) {
- this._icon = L.DomUtil.create('div', 'leaflet-crosshair');
- Object.assign(this._icon.style, this.options.iconStyle);
- map.getContainer().insertBefore(this._icon, map.getContainer().firstChild);
- }
-
- // Control container
- this._container = L.DomUtil.create('div', 'leaflet-control-mapcentercoord');
-
- Object.assign(this._container.style, this.options.containerStyle);
-
- if (!this.options.coords) {
- this._container.style.display = 'none';
- }
-
- L.DomEvent.disableClickPropagation(this._container);
-
- this._container.innerHTML = this._getMapCenterCoord();
-
- // Add events listeners for updating coordinates & icon's position
- map.on('move', this._onMapMove, this);
- map.on('moveend', this._onMapMove, this);
-
- return this._container;
- },
-
- onRemove: function (map) {
- if (this.options.bar) {
- this._scaleBar.remove();
- }
-
- // remove icon's DOM elements and listeners
- if (this.options.icon) {
- map.getContainer().removeChild(this._icon);
- }
- map.off('move', this._onMapMove, this);
- map.off('moveend', this._onMapMove, this);
- },
-
- // update coordinates
- _onMapMove: function (e) {
- if (this.options.onMove || 'moveend' === e.type) {
- this._container.innerHTML = this._getMapCenterCoord();
- }
- },
-
- _getMapCenterCoord: function () {
- const center = this._map.getCenter();
- return this.options.projected
- ? this._getProjectedCoord(this._map.options.crs.project(center))
- : this._getLatLngCoord(center);
- },
-
- _getProjectedCoord: function (center) {
- return L.Util.template(
- this.options.template,
- {
- x: this._format(this.options.formatProjected, center.x),
- y: this._format(this.options.formatProjected, center.y)
- }
- );
- },
-
- _getLatLngCoord: function (latLng) {
-
- const { latLngFormatter, latlngFormat, latlngDesignators: designators } = this.options;
-
- if (undefined !== latLngFormatter ) {
- return latLngFormatter(latLng.lat, latLng.lng);
- }
-
- let lat, lng, deg, min;
-
- // make a copy of center so we aren't affecting leaflet's internal state
- let center = {
- lat: latLng.lat,
- lng: latLng.lng,
- lng_neg: latLng.lng < 0,
- lat_neg: latLng.lat < 0,
- };
-
- // 180 degrees & negative
- if (center.lng < 0) {
- center.lng = Math.abs(center.lng);
- }
- if (center.lng > 180) {
- center.lng = 360 - center.lng;
- center.lng_neg = !center.lng_neg;
- }
- if (center.lat < 0) {
- center.lat = Math.abs(center.lat);
- }
-
- // format
- if ('DM' === latlngFormat) {
- deg = parseInt(center.lng);
- lng = deg + 'º ' + this._format('00.000', (center.lng - deg) * 60) + "'";
- deg = parseInt(center.lat);
- lat = deg + 'º ' + this._format('00.000', (center.lat - deg) * 60) + "'";
- } else if ('DMS' === latlngFormat) {
- deg = parseInt(center.lng);
- min = (center.lng - deg) * 60;
- lng = deg + 'º ' + this._format('00', parseInt(min)) + "' " + this._format('00.0', (min - parseInt(min)) * 60) + "''";
- deg = parseInt(center.lat);
- min = (center.lat - deg) * 60;
- lat = deg + 'º ' + this._format('00', parseInt(min)) + "' " + this._format('00.0', (min - parseInt(min)) * 60) + "''";
- } else { // 'DD'
- lng = this._format('#0.00000', center.lng) + 'º';
- lat = this._format('##0.00000', center.lat) + 'º';
- }
-
- return L.Util.template(this.options.template, {
- x: (!designators && center.lng_neg ? '-' : '') + lng + (designators ? (center.lng_neg ? ' W' : ' E') : ''),
- y: (!designators && center.lat_neg ? '-' : '') + lat + (designators ? (center.lat_neg ? ' S' : ' N') : '')
- });
- },
-
- /**
- * IntegraXor Web SCADA - JavaScript Number Formatter
- *
- * @see https://code.google.com/p/javascript-number-formatter
- * @authors KPL, KHL
- */
- _format: function (m, v) {
- if (!m || isNaN(+v)) {
- return v; // return as it is.
- }
-
- v = m.charAt(0) == '-' ? -v : +v; // convert any string to number according to formation sign.
- let isNegative = v < 0 ? v = -v : 0; // process only abs(), and turn on flag.
-
- let result = m.match(/[^\d\-\+#]/g); // search for separator for grp & decimal, anything not digit, not +/- sign, not #.
- let Decimal = (result && result[result.length - 1]) || '.'; // treat the right most symbol as decimal
- let Group = (result && result[1] && result[0]) || ','; // treat the left most symbol as group separator
-
- m = m.split(Decimal); // split the decimal for the format string if any.
- v = v.toFixed(m[1] && m[1].length); // Fix the decimal first, toFixed will auto fill trailing zero.
- v = +(v) + ''; // convert number to string to trim off *all* trailing decimal zero(es)
-
- let pos_trail_zero = m[1] && m[1].lastIndexOf('0'); // fill back any trailing zero according to format (look for last zero in format)
- let part = v.split('.');
-
- if (!part[1] || part[1] && part[1].length <= pos_trail_zero) { // integer will get !part[1]
- v = (+v).toFixed(pos_trail_zero + 1);
- }
- let szSep = m[0].split(Group); // look for separator
- m[0] = szSep.join(''); // join back without separator for counting the pos of any leading 0.
-
- let pos_lead_zero = m[0] && m[0].indexOf('0');
- if (pos_lead_zero > -1) {
- while (part[0].length < (m[0].length - pos_lead_zero)) {
- part[0] = '0' + part[0];
- }
- } else if (+part[0] == 0) {
- part[0] = '';
- }
- v = v.split('.');
- v[0] = part[0];
-
- var pos_separator = (szSep[1] && szSep[szSep.length - 1].length); // process the first group separator from decimal (.) only, the rest ignore. Get the length of the last slice of split result.
- if (pos_separator) {
- let integer = v[0];
- let str = '';
- let offset = integer.length % pos_separator;
- for (let i = 0, l = integer.length; i < l; i++) {
- str += integer.charAt(i); // ie6 only support charAt for sz.
- if (
- !((i - offset + 1) % pos_separator) &&
- i < l - pos_separator // -pos_separator so that won't trail separator on full length
- ) {
- str += Group;
- }
- }
- v[0] = str;
- }
-
- v[1] = (m[1] && v[1]) ? Decimal + v[1] : "";
- return (isNegative ? '-' : '') + v[0] + v[1]; // put back any negation and combine integer and fraction.
- }
-
-});
-
-/**
- * Original Source: https://github.com/dtutic/Leaflet.EdgeScaleBar
- *
- * Draws the metric scale bars in Web Mercator map along top and right edges.
- * Authors: Dražen Tutić (dtutic@geof.hr), Ana Kuveždić Divjak (akuvezdic@geof.hr)
- * University of Zagreb, Faculty of Geodesy, GEOF-OSGL Lab
- * Inspired by LatLonGraticule Leaflet plugin by: lanwei@cloudybay.com.tw
- */
-L.Control.EdgeScale.Layer = L.Layer.extend({
-
- includes: L.Evented ? L.Evented.prototype : L.Mixin.Events,
-
- options: {
- opacity: 1,
- weight: 0.8,
- gradient: {
- size: 10,
- opacity: 0.5,
- },
- color: '#000',
- font: '11px Arial',
- zoomInterval: [
- {start: 0, end: 2, interval: 5000000},
- {start: 3, end: 3, interval: 2000000},
- {start: 4, end: 4, interval: 1000000},
- {start: 5, end: 5, interval: 500000},
- {start: 6, end: 7, interval: 200000},
- {start: 8, end: 8, interval: 100000},
- {start: 9, end: 9, interval: 50000},
- {start: 10, end: 10, interval: 20000},
- {start: 11, end: 11, interval: 10000},
- {start: 12, end: 12, interval: 5000},
- {start: 13, end: 13, interval: 2000},
- {start: 14, end: 14, interval: 1000},
- {start: 15, end: 15, interval: 500},
- {start: 16, end: 16, interval: 200},
- {start: 17, end: 17, interval: 100},
- {start: 18, end: 18, interval: 50},
- {start: 19, end: 19, interval: 20},
- {start: 20, end: 20, interval: 10}
- ],
- pane: 'edgescalePane'
- },
-
- initialize: function (options) {
-
- L.setOptions(this, options);
-
- // Constants of the WGS84 ellipsoid needed to calculate meridian length or latitute
- const a = this._a = 6378137.0;
- const b = this._b = 6356752.3142;
- const n = this._n = (a - b)/(a + b);
- const a2 = a * a;
- const b2 = b * b;
- const n2 = n * n;
- const n3 = n2 * n;
- const n4 = n3 * n;
- const n5 = n4 * n;
- this._A = a * (1.0 - n) * (1.0 - n2) * (1.0 + 9.0/4.0 * n2 + 225.0/64.0 * n4);
- this._e2 = (a2 - b2) / a2;
- this._ic1 = 1.5 * n - 29.0/12.0 * n3 + 553.0/80.0 * n5;
- this._ic2 = 21.0/8.0 * n2 - 1537.0/128.0 * n4;
- this._ic3 = 151.0/24.0 * n3 - 32373.0/640.0 * n5;
- this._ic4 = 1097.0/64.0 * n4;
- this._ic5 = 8011.0/150.0 * n5;
- this._c1 = -1.5 * n + 31.0/24.0 * n3 - 669.0/640.0 * n5;
- this._c2 = 15.0/18.0 * n2 - 435.0/128.0 * n4;
- this._c3 = -35.0/12.0 * n3 + 651.0/80.0 * n5;
- this._c4 = 315.0/64.0 * n4;
- this._c5 = -693.0/80.0 * n5;
-
- // Latitude limit of the Web Mercator projection
- this._LIMIT_PHI = 1.484419982;
- },
-
- onAdd: function (map) {
- this._map = map;
-
- let pane = map.getPane(this.options.pane);
- if (!pane) {
- pane = this._pane = map.createPane('edgescalePane', map.getPane('norotatePane') || map.getPane('mapPane'));
- pane.style.zIndex = 625; // This pane is above markers but below popups.
- pane.style.pointerEvents = 'none';
- }
-
- this._pane = pane;
-
- // if (this._renderer) this._renderer.remove()
- // this._renderer = L.canvas({ pane: "edgescalePane" }).addTo(this._map); // default leaflet svg renderer
-
- if (!this._canvas) {
- this._initCanvas();
- }
-
- this._pane.appendChild(this._canvas);
-
- map.on('viewreset', this._reset, this);
- map.on('move', this._reset, this);
- map.on('moveend', this._reset, this);
- map.on('rotate', this._reset, this);
-
- this._reset();
- },
-
- onRemove: function (map) {
- this._pane.removeChild(this._canvas);
-
- map.off('viewreset', this._reset, this);
- map.off('move', this._reset, this);
- map.off('moveend', this._reset, this);
- },
-
- addTo: function (map) {
- map.addLayer(this);
- return this;
- },
-
- setOpacity: function (opacity) {
- this.options.opacity = opacity;
- L.DomUtil.setOpacity(this._canvas, this.options.opacity);
- return this;
- },
-
- bringToFront: function () {
- if (this._canvas) {
- this._pane.appendChild(this._canvas);
- }
- return this;
- },
-
- bringToBack: function () {
- if (this._canvas) {
- this._pane.insertBefore(this._canvas, pane.firstChild);
- }
- return this;
- },
-
- _initCanvas: function () {
- this._canvas = L.DomUtil.create('canvas', '');
- this._ctx = this._canvas.getContext('2d');
-
- this.setOpacity();
-
- L.extend(this._canvas, {
- onselectstart: L.Util.falseFn,
- onmousemove: L.Util.falseFn,
- onload: L.bind(this._onCanvasLoad, this)
- });
- },
-
- _reset: function () {
- var canvas = this._canvas,
- size = this._map.getSize();
-
- this._setCanvasPosition();
-
- canvas.width = size.x;
- canvas.height = size.y;
- canvas.style.width = size.x + 'px';
- canvas.style.height = size.y + 'px';
-
- /**
- * @TODO add support for "leaflet-rotate"
- */
- if (this._map._bearing) {
- return;
- }
-
- const { gradient } = this.options;
-
- // horizontal gradient
- if (!this._hor_gradient) {
- this._hor_gradient = this._ctx.createLinearGradient(0, 0, 0, gradient.size);
- this._hor_gradient.addColorStop(0,"rgba(255, 255, 255, " + gradient.opacity + ")");
- this._hor_gradient.addColorStop(1,"rgba(255, 255, 255, 0)");
- }
- this._ctx.fillStyle = this._hor_gradient;
- this._ctx.fillRect(0, 0, size.x, gradient.size);
-
- // vertical gradient
- if (!this._vert_gradient) {
- this._vert_gradient = this._ctx.createLinearGradient(0, 0, gradient.size, 0);
- this._vert_gradient.addColorStop(0,"rgba(255, 255, 255, " + gradient.opacity + ")");
- this._vert_gradient.addColorStop(1,"rgba(255, 255, 255, 0)");
- }
- this._ctx.fillStyle = this._vert_gradient;
- this._ctx.fillRect(0, 0, gradient.size, size.y);
-
- this._ctx.beginPath();
- this._ctx.moveTo(0,0);
- this._ctx.lineTo(size.x,0);
- this._ctx.lineTo(size.x,size.y);
- this._ctx.stroke();
-
- this._calcInterval();
- this._draw();
- },
-
- _onCanvasLoad: function () {
- this.fire('load');
- },
-
- _calcInterval: function() {
- const { zoomInterval } = this.options;
- const zoom = this._map.getZoom();
-
- if (undefined !== zoomInterval) {
- // Manually set scale using a custom this.options.zoomInterval object
- for (const idx in zoomInterval) {
- const dict = zoomInterval[idx];
- if (dict.start <= zoom && dict.end && dict.end >= zoom) {
- this._interval = dict.interval;
- break;
- }
- }
- } else {
- // Autamatically get current scale using L.Control.Scale
- // Source: https://gis.stackexchange.com/a/198444
- this._interval = L.Control.Scale.prototype._getRoundNum(
- this._map
- .containerPointToLatLng([0, this._map.getSize().y / 2 ])
- .distanceTo(
- this._map.containerPointToLatLng([L.Control.Scale.prototype.options.maxWidth, this._map.getSize().y / 2 ]
- )
- )
- );
- }
-
- this._currZoom = zoom;
-
- },
-
- _draw: function() {
- this._ctx.strokeStyle = this.options.color;
- this._create_lat_ticks();
- this._create_lon_ticks();
-
- this._ctx.fillStyle = this.options.color;
- this._ctx.font = this.options.font;
-
- const size = this._map.getSize();
- const text = this._interval >= 1000 ? (this._interval / 1000 + ' km') : this._interval + ' m';
-
- this._ctx.textAlign = 'left';
- this._ctx.textBaseline = 'middle';
- this._ctx.fillText(text, +12, size.y / 2);
-
- this._ctx.textAlign = 'center';
- this._ctx.textBaseline = 'top';
- this._ctx.fillText(text, size.x / 2, 12);
- },
-
- _create_lat_ticks: function() {
- const { weight } = this.options;
- const size = this._map.getSize();
- const to_rad = Math.PI/180.0;
- const center = this._merLength(this._map.containerPointToLatLng(L.point(0, size.y / 2)).lat * to_rad);
- const top = this._merLength(this._map.containerPointToLatLng(L.point(0,0)).lat * to_rad);
- const bottom = this._merLength(this._map.containerPointToLatLng(L.point(0, size.y)).lat * to_rad);
-
- // draw major ticks
- for (let i = center + this._interval / 2; i < top; i = i + this._interval) {
- const phi = this._invmerLength(i);
- if ((phi < this._LIMIT_PHI) && (phi > -this._LIMIT_PHI)) {
- this._draw_lat_tick(phi, 10, weight * 1.5);
- }
- }
- for (let i = center - this._interval / 2; i > bottom; i = i - this._interval) {
- const phi = this._invmerLength(i);
- if ((phi > -this._LIMIT_PHI) && (phi < this._LIMIT_PHI)) {
- this._draw_lat_tick(phi, 10, weight * 1.5);
- }
- }
-
- // draw minor ticks
- for (let i = center; i < top; i = i + this._interval / 10.0) {
- const phi = this._invmerLength(i);
- if ((phi < this._LIMIT_PHI) && (phi > -this._LIMIT_PHI)) {
- this._draw_lat_tick(phi, 4, weight);
- }
- }
- for (let i = center - this._interval / 10; i > bottom; i = i - this._interval / 10.0) {
- const phi = this._invmerLength(i);
- if ((phi > -this._LIMIT_PHI) && (phi < this._LIMIT_PHI)) {
- this._draw_lat_tick(phi, 4, weight);
- }
- }
- },
-
- _create_lon_ticks: function() {
- const { weight } = this.options;
- const size = this._map.getSize();
- const to_rad = Math.PI/180.0;
- const to_deg = 180.0/Math.PI;
- const center = this._map.containerPointToLatLng(L.point(size.x / 2, 0));
- const left = this._map.containerPointToLatLng(L.point(0, 0));
- const right = this._map.containerPointToLatLng(L.point(size.x, 0));
- const sinPhi2 = Math.pow(Math.sin(center.lat * to_rad), 2);
- const N = this._a / Math.sqrt(1.0 - this._e2 * sinPhi2);
- const dl = this._interval / (N * Math.cos(center.lat * to_rad)) * to_deg;
-
- // draw major ticks
- for (let i = center.lng + dl / 2; i < right.lng; i = i + dl) this._draw_lon_tick(i, 10, weight * 1.5);
- for (let i = center.lng - dl / 2; i > left.lng; i = i - dl) this._draw_lon_tick(i, 10, weight * 1.5);
-
- // draw minor ticks
- for (let i = center.lng; i < right.lng; i = i + dl / 10) this._draw_lon_tick(i, 4, weight);
- for (let i = center.lng - dl / 10; i > left.lng; i = i - dl / 10) this._draw_lon_tick(i, 4, weight);
- },
-
- _setCanvasPosition: function() {
- let lt = this._map.containerPointToLayerPoint([0, 0]);
- /**
- * @TODO add support for "leaflet-rotate"
- */
- if (this._map._bearing) {
- lt = this._map.rotatedPointToMapPanePoint(
- this._map.containerPointToLayerPoint(L.point(this._map._container.getBoundingClientRect()))
- );
- }
- L.DomUtil.setPosition(this._canvas, lt);
- },
-
- _latLngToCanvasPoint: function (latlng) {
- return L.point(
- this._map
- .project(L.latLng(latlng))
- ._subtract(this._map.getPixelOrigin())
- ).add(this._map._getMapPanePos());
- },
-
- _draw_lat_tick: function (phi, lenght, weight) {
- const to_deg = 180.0/Math.PI;
- const size = this._map.getSize();
- const y = this._latLngToCanvasPoint(L.latLng(phi * to_deg, 0.0)).y;
- this._ctx.lineWidth = weight;
- this._ctx.beginPath();
- this._ctx.moveTo(0, y);
- this._ctx.lineTo(+ lenght, y);
- this._ctx.stroke();
- },
-
- _draw_lon_tick: function(lam, lenght, weight) {
- const x = this._latLngToCanvasPoint(L.latLng(0.0, lam)).x;
- this._ctx.lineWidth = weight;
- this._ctx.beginPath();
- this._ctx.moveTo(x, 0);
- this._ctx.lineTo(x, lenght);
- this._ctx.stroke();
- },
-
- _merLength: function(phi) {
- const cos2 = Math.cos(2.0 * phi);
- const sin2 = Math.sin(2.0 * phi);
- return this._A * (phi + sin2 * (this._c1 + (this._c2 + (this._c3 + (this._c4 + this._c5 * cos2) * cos2) *cos2) * cos2));
- },
-
- _invmerLength: function(s) {
- const psi = s/this._A;
- const cos2 = Math.cos(2.0 * psi);
- const sin2 = Math.sin(2.0 * psi);
- return psi + sin2 * (this._ic1 + (this._ic2 + (this._ic3 + (this._ic4 + this._ic5 * cos2) * cos2) * cos2) * cos2);
- },
-});
-
-L.control.edgeScale = function (options) {
- return new L.Control.EdgeScale(options);
-};
-
-L.Map.mergeOptions({
- edgeScaleControl: false
-});
-
-L.Map.addInitHook(function () {
- if (this.options.edgeScaleControl) {
- this.edgeScaleControl = new L.Control.EdgeScale();
- this.addControl(this.edgeScaleControl);
- }
+/* + * Copyright (c) 2023, GPL-3.0+ Project, Raruto + * + * This file is free software: you may copy, redistribute and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 2 of the License, or (at your + * option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (c) GPL-3.0+ Project - 2018- Dražen Tutić - https://github.com/dtutic/Leaflet.EdgeScaleBar + * Copyright (c) MIT License (MIT) - 2015- Xisco Guaita - https://github.com/xguaita/Leaflet.MapCenterCoord + */ + +/** + * Original source: https://github.com/xguaita/Leaflet.MapCenterCoord + */ +L.Control.EdgeScale = L.Control.extend({ + + // Defaults + options: { + position: 'bottomleft', + icon: true, + coords: true, + bar: true, + onMove: true, + template: '{y} | {x}', // https://en.wikipedia.org/wiki/ISO_6709 + projected: false, + formatProjected: '#.##0,000', + latlngFormat: 'DD', // DD, DM, DMS + latlngDesignators: true, + latLngFormatter: undefined, + iconStyle: { + background: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 100 100'%3E%3Cg stroke='%23fff'%3E%3Ccircle cx='50' cy='50.2' r='3.9' stroke-width='2' /%3E%3Cpath stroke-width='3' d='M5 54h32a4 4 0 1 0 0-8H5a4 4 0 1 0 0 8z M54 5a4 4 0 1 0-8 0v32a4 4 0 1 0 8 0V5z M99 50c0-2-2-4-4-4H63a4 4 0 1 0 0 8h32c2 0 4-1 4-4zM46 95a4 4 0 1 0 8 0V64a4 4 0 1 0-8 0v31z'/%3E%3C/g%3E%3C/svg%3E%0A")`, + width: '24px', + height: '24px', + left: 'calc(50% - 12px)', + top: 'calc(50% - 12px)', + content: '', + display: 'block', + position: 'absolute', + zIndex: 999, + pointerEvents: 'none', + }, + containerStyle: { + backgroundColor: 'rgba(255, 255, 255, 0.7)', + boxShadow: '0 0 5px #bbb', + borderRadius: '3px', + padding: '3px 2px', + color: '#333', + font: '11px/1.5 Consolas, monaco, monospace', + writingMode: 'vertical-lr', + }, + }, + + initialize(options) { + L.Util.setOptions(this, options); + }, + + onAdd (map) { + + if (this.options.bar) { + this._scaleBar = (new L.Control.EdgeScale.Layer(true === this.options.bar ? {} : this.options.bar)).addTo(map); + } + + // create a DOM element and put it into overlayPane + if (this.options.icon) { + this._icon = L.DomUtil.create('div', 'leaflet-crosshair'); + Object.assign(this._icon.style, this.options.iconStyle); + map.getContainer().insertBefore(this._icon, map.getContainer().firstChild); + } + + // Control container + this._container = L.DomUtil.create('div', 'leaflet-control-mapcentercoord'); + + Object.assign(this._container.style, this.options.containerStyle); + + if (!this.options.coords) { + this._container.style.display = 'none'; + } + + L.DomEvent.disableClickPropagation(this._container); + + this._container.innerHTML = this._getMapCenterCoord(); + + // Add events listeners for updating coordinates & icon's position + map.on('move', this._onMapMove, this); + map.on('moveend', this._onMapMove, this); + + return this._container; + }, + + onRemove (map) { + if (this.options.bar) { + this._scaleBar.remove(); + } + + // remove icon's DOM elements and listeners + if (this.options.icon) { + map.getContainer().removeChild(this._icon); + } + map.off('move', this._onMapMove, this); + map.off('moveend', this._onMapMove, this); + }, + + // update coordinates + _onMapMove (e) { + if (this.options.onMove || 'moveend' === e.type) { + this._container.innerHTML = this._getMapCenterCoord(); + } + }, + + _getMapCenterCoord () { + const center = this._map.getCenter(); + return this.options.projected + ? this._getProjectedCoord(this._map.options.crs.project(center)) + : this._getLatLngCoord(center); + }, + + _getProjectedCoord (center) { + return L.Util.template( + this.options.template, + { + x: this._format(this.options.formatProjected, center.x), + y: this._format(this.options.formatProjected, center.y) + } + ); + }, + + _getLatLngCoord (latLng) { + + const { latLngFormatter, latlngFormat, latlngDesignators: designators } = this.options; + + if (undefined !== latLngFormatter ) { + return latLngFormatter(latLng.lat, latLng.lng); + } + + let lat, lng, deg, min; + + // make a copy of center so we aren't affecting leaflet's internal state + let center = { + lat: latLng.lat, + lng: latLng.lng, + lng_neg: latLng.lng < 0, + lat_neg: latLng.lat < 0, + }; + + // 180 degrees & negative + if (center.lng < 0) { + center.lng = Math.abs(center.lng); + } + if (center.lng > 180) { + center.lng = 360 - center.lng; + center.lng_neg = !center.lng_neg; + } + if (center.lat < 0) { + center.lat = Math.abs(center.lat); + } + + // format + if ('DM' === latlngFormat) { + deg = parseInt(center.lng); + lng = deg + 'º ' + this._format('00.000', (center.lng - deg) * 60) + "'"; + deg = parseInt(center.lat); + lat = deg + 'º ' + this._format('00.000', (center.lat - deg) * 60) + "'"; + } else if ('DMS' === latlngFormat) { + deg = parseInt(center.lng); + min = (center.lng - deg) * 60; + lng = deg + 'º ' + this._format('00', parseInt(min)) + "' " + this._format('00.0', (min - parseInt(min)) * 60) + "''"; + deg = parseInt(center.lat); + min = (center.lat - deg) * 60; + lat = deg + 'º ' + this._format('00', parseInt(min)) + "' " + this._format('00.0', (min - parseInt(min)) * 60) + "''"; + } else { // 'DD' + lng = this._format('#0.00000', center.lng) + 'º'; + lat = this._format('##0.00000', center.lat) + 'º'; + } + + return L.Util.template(this.options.template, { + x: (!designators && center.lng_neg ? '-' : '') + lng + (designators ? (center.lng_neg ? ' W' : ' E') : ''), + y: (!designators && center.lat_neg ? '-' : '') + lat + (designators ? (center.lat_neg ? ' S' : ' N') : '') + }); + }, + + /** + * IntegraXor Web SCADA - JavaScript Number Formatter + * + * @see https://code.google.com/p/javascript-number-formatter + * @authors KPL, KHL + */ + _format (m, v) { + if (!m || isNaN(+v)) { + return v; // return as it is. + } + + v = m.charAt(0) == '-' ? -v : +v; // convert any string to number according to formation sign. + let isNegative = v < 0 ? v = -v : 0; // process only abs(), and turn on flag. + + let result = m.match(/[^\d\-\+#]/g); // search for separator for grp & decimal, anything not digit, not +/- sign, not #. + let Decimal = (result && result[result.length - 1]) || '.'; // treat the right most symbol as decimal + let Group = (result && result[1] && result[0]) || ','; // treat the left most symbol as group separator + + m = m.split(Decimal); // split the decimal for the format string if any. + v = v.toFixed(m[1] && m[1].length); // Fix the decimal first, toFixed will auto fill trailing zero. + v = +(v) + ''; // convert number to string to trim off *all* trailing decimal zero(es) + + let pos_trail_zero = m[1] && m[1].lastIndexOf('0'); // fill back any trailing zero according to format (look for last zero in format) + let part = v.split('.'); + + if (!part[1] || part[1] && part[1].length <= pos_trail_zero) { // integer will get !part[1] + v = (+v).toFixed(pos_trail_zero + 1); + } + let szSep = m[0].split(Group); // look for separator + m[0] = szSep.join(''); // join back without separator for counting the pos of any leading 0. + + let pos_lead_zero = m[0] && m[0].indexOf('0'); + if (pos_lead_zero > -1) { + while (part[0].length < (m[0].length - pos_lead_zero)) { + part[0] = '0' + part[0]; + } + } else if (+part[0] == 0) { + part[0] = ''; + } + v = v.split('.'); + v[0] = part[0]; + + var pos_separator = (szSep[1] && szSep[szSep.length - 1].length); // process the first group separator from decimal (.) only, the rest ignore. Get the length of the last slice of split result. + if (pos_separator) { + let integer = v[0]; + let str = ''; + let offset = integer.length % pos_separator; + for (let i = 0, l = integer.length; i < l; i++) { + str += integer.charAt(i); // ie6 only support charAt for sz. + if ( + !((i - offset + 1) % pos_separator) && + i < l - pos_separator // -pos_separator so that won't trail separator on full length + ) { + str += Group; + } + } + v[0] = str; + } + + v[1] = (m[1] && v[1]) ? Decimal + v[1] : ""; + return (isNegative ? '-' : '') + v[0] + v[1]; // put back any negation and combine integer and fraction. + } + +}); + +/** + * Original Source: https://github.com/dtutic/Leaflet.EdgeScaleBar + * + * Draws the metric scale bars in Web Mercator map along top and right edges. + * Authors: Dražen Tutić (dtutic@geof.hr), Ana Kuveždić Divjak (akuvezdic@geof.hr) + * University of Zagreb, Faculty of Geodesy, GEOF-OSGL Lab + * Inspired by LatLonGraticule Leaflet plugin by: lanwei@cloudybay.com.tw + */ +L.Control.EdgeScale.Layer = L.Layer.extend({ + + options: { + opacity: 1, + weight: 0.8, + gradient: { + size: 10, + opacity: 0.5, + }, + color: '#000', + font: '11px Arial', + zoomInterval: [ + {start: 0, end: 2, interval: 5000000}, + {start: 3, end: 3, interval: 2000000}, + {start: 4, end: 4, interval: 1000000}, + {start: 5, end: 5, interval: 500000}, + {start: 6, end: 7, interval: 200000}, + {start: 8, end: 8, interval: 100000}, + {start: 9, end: 9, interval: 50000}, + {start: 10, end: 10, interval: 20000}, + {start: 11, end: 11, interval: 10000}, + {start: 12, end: 12, interval: 5000}, + {start: 13, end: 13, interval: 2000}, + {start: 14, end: 14, interval: 1000}, + {start: 15, end: 15, interval: 500}, + {start: 16, end: 16, interval: 200}, + {start: 17, end: 17, interval: 100}, + {start: 18, end: 18, interval: 50}, + {start: 19, end: 19, interval: 20}, + {start: 20, end: 20, interval: 10} + ], + pane: 'edgescalePane' + }, + + initialize (options) { + + L.Util.setOptions(this, options); + + // Constants of the WGS84 ellipsoid needed to calculate meridian length or latitute + const a = this._a = 6378137.0; + const b = this._b = 6356752.3142; + const n = this._n = (a - b)/(a + b); + const a2 = a * a; + const b2 = b * b; + const n2 = n * n; + const n3 = n2 * n; + const n4 = n3 * n; + const n5 = n4 * n; + this._A = a * (1.0 - n) * (1.0 - n2) * (1.0 + 9.0/4.0 * n2 + 225.0/64.0 * n4); + this._e2 = (a2 - b2) / a2; + this._ic1 = 1.5 * n - 29.0/12.0 * n3 + 553.0/80.0 * n5; + this._ic2 = 21.0/8.0 * n2 - 1537.0/128.0 * n4; + this._ic3 = 151.0/24.0 * n3 - 32373.0/640.0 * n5; + this._ic4 = 1097.0/64.0 * n4; + this._ic5 = 8011.0/150.0 * n5; + this._c1 = -1.5 * n + 31.0/24.0 * n3 - 669.0/640.0 * n5; + this._c2 = 15.0/18.0 * n2 - 435.0/128.0 * n4; + this._c3 = -35.0/12.0 * n3 + 651.0/80.0 * n5; + this._c4 = 315.0/64.0 * n4; + this._c5 = -693.0/80.0 * n5; + + // Latitude limit of the Web Mercator projection + this._LIMIT_PHI = 1.484419982; + }, + + onAdd (map) { + this._map = map; + + let pane = map.getPane(this.options.pane); + if (!pane) { + pane = this._pane = map.createPane('edgescalePane', map.getPane('norotatePane') || map.getPane('mapPane')); + pane.style.zIndex = 625; // This pane is above markers but below popups. + pane.style.pointerEvents = 'none'; + } + + this._pane = pane; + + // if (this._renderer) this._renderer.remove() + // this._renderer = L.canvas({ pane: "edgescalePane" }).addTo(this._map); // default leaflet svg renderer + + if (!this._canvas) { + this._initCanvas(); + } + + this._pane.appendChild(this._canvas); + + map.on('viewreset', this._reset, this); + map.on('move', this._reset, this); + map.on('moveend', this._reset, this); + map.on('rotate', this._reset, this); + + this._reset(); + }, + + onRemove (map) { + this._pane.removeChild(this._canvas); + + map.off('viewreset', this._reset, this); + map.off('move', this._reset, this); + map.off('moveend', this._reset, this); + }, + + addTo (map) { + map.addLayer(this); + return this; + }, + + setOpacity (opacity) { + this.options.opacity = opacity; + this._canvas.style.opacity = this.options.opacity; + return this; + }, + + bringToFront () { + if (this._canvas) { + this._pane.appendChild(this._canvas); + } + return this; + }, + + bringToBack () { + if (this._canvas) { + this._pane.insertBefore(this._canvas, pane.firstChild); + } + return this; + }, + + _initCanvas () { + this._canvas = L.DomUtil.create('canvas', ''); + this._ctx = this._canvas.getContext('2d'); + + this.setOpacity(); + + Object.assign(this._canvas, { + onselectstart: L.Util.falseFn, + onmousemove: L.Util.falseFn, + onload: this._onCanvasLoad.bind(this) + }); + }, + + _reset () { + var canvas = this._canvas, + size = this._map.getSize(); + + this._setCanvasPosition(); + + canvas.width = size.x; + canvas.height = size.y; + canvas.style.width = size.x + 'px'; + canvas.style.height = size.y + 'px'; + + /** + * @TODO add support for "leaflet-rotate" + */ + if (this._map._bearing) { + return; + } + + const { gradient } = this.options; + + // horizontal gradient + if (!this._hor_gradient) { + this._hor_gradient = this._ctx.createLinearGradient(0, 0, 0, gradient.size); + this._hor_gradient.addColorStop(0,"rgba(255, 255, 255, " + gradient.opacity + ")"); + this._hor_gradient.addColorStop(1,"rgba(255, 255, 255, 0)"); + } + this._ctx.fillStyle = this._hor_gradient; + this._ctx.fillRect(0, 0, size.x, gradient.size); + + // vertical gradient + if (!this._vert_gradient) { + this._vert_gradient = this._ctx.createLinearGradient(0, 0, gradient.size, 0); + this._vert_gradient.addColorStop(0,"rgba(255, 255, 255, " + gradient.opacity + ")"); + this._vert_gradient.addColorStop(1,"rgba(255, 255, 255, 0)"); + } + this._ctx.fillStyle = this._vert_gradient; + this._ctx.fillRect(0, 0, gradient.size, size.y); + + this._ctx.beginPath(); + this._ctx.moveTo(0,0); + this._ctx.lineTo(size.x,0); + this._ctx.lineTo(size.x,size.y); + this._ctx.stroke(); + + this._calcInterval(); + this._draw(); + }, + + _onCanvasLoad () { + this.fire('load'); + }, + + _calcInterval() { + const { zoomInterval } = this.options; + const zoom = this._map.getZoom(); + + if (undefined !== zoomInterval) { + // Manually set scale using a custom this.options.zoomInterval object + for (const idx in zoomInterval) { + const dict = zoomInterval[idx]; + if (dict.start <= zoom && dict.end && dict.end >= zoom) { + this._interval = dict.interval; + break; + } + } + } else { + // Autamatically get current scale using L.Control.Scale + // Source: https://gis.stackexchange.com/a/198444 + this._interval = L.Control.Scale.prototype._getRoundNum( + this._map + .containerPointToLatLng([0, this._map.getSize().y / 2 ]) + .distanceTo( + this._map.containerPointToLatLng([L.Control.Scale.prototype.options.maxWidth, this._map.getSize().y / 2 ] + ) + ) + ); + } + + this._currZoom = zoom; + + }, + + _draw() { + this._ctx.strokeStyle = this.options.color; + this._create_lat_ticks(); + this._create_lon_ticks(); + + this._ctx.fillStyle = this.options.color; + this._ctx.font = this.options.font; + + const size = this._map.getSize(); + const text = this._interval >= 1000 ? (this._interval / 1000 + ' km') : this._interval + ' m'; + + this._ctx.textAlign = 'left'; + this._ctx.textBaseline = 'middle'; + this._ctx.fillText(text, +12, size.y / 2); + + this._ctx.textAlign = 'center'; + this._ctx.textBaseline = 'top'; + this._ctx.fillText(text, size.x / 2, 12); + }, + + _create_lat_ticks() { + const { weight } = this.options; + const size = this._map.getSize(); + const to_rad = Math.PI/180.0; + const center = this._merLength(this._map.containerPointToLatLng(new L.Point(0, size.y / 2)).lat * to_rad); + const top = this._merLength(this._map.containerPointToLatLng(new L.Point(0,0)).lat * to_rad); + const bottom = this._merLength(this._map.containerPointToLatLng(new L.Point(0, size.y)).lat * to_rad); + + // draw major ticks + for (let i = center + this._interval / 2; i < top; i = i + this._interval) { + const phi = this._invmerLength(i); + if ((phi < this._LIMIT_PHI) && (phi > -this._LIMIT_PHI)) { + this._draw_lat_tick(phi, 10, weight * 1.5); + } + } + for (let i = center - this._interval / 2; i > bottom; i = i - this._interval) { + const phi = this._invmerLength(i); + if ((phi > -this._LIMIT_PHI) && (phi < this._LIMIT_PHI)) { + this._draw_lat_tick(phi, 10, weight * 1.5); + } + } + + // draw minor ticks + for (let i = center; i < top; i = i + this._interval / 10.0) { + const phi = this._invmerLength(i); + if ((phi < this._LIMIT_PHI) && (phi > -this._LIMIT_PHI)) { + this._draw_lat_tick(phi, 4, weight); + } + } + for (let i = center - this._interval / 10; i > bottom; i = i - this._interval / 10.0) { + const phi = this._invmerLength(i); + if ((phi > -this._LIMIT_PHI) && (phi < this._LIMIT_PHI)) { + this._draw_lat_tick(phi, 4, weight); + } + } + }, + + _create_lon_ticks() { + const { weight } = this.options; + const size = this._map.getSize(); + const to_rad = Math.PI/180.0; + const to_deg = 180.0/Math.PI; + const center = this._map.containerPointToLatLng(new L.Point(size.x / 2, 0)); + const left = this._map.containerPointToLatLng(new L.Point(0, 0)); + const right = this._map.containerPointToLatLng(new L.Point(size.x, 0)); + const sinPhi2 = Math.pow(Math.sin(center.lat * to_rad), 2); + const N = this._a / Math.sqrt(1.0 - this._e2 * sinPhi2); + const dl = this._interval / (N * Math.cos(center.lat * to_rad)) * to_deg; + + // draw major ticks + for (let i = center.lng + dl / 2; i < right.lng; i = i + dl) this._draw_lon_tick(i, 10, weight * 1.5); + for (let i = center.lng - dl / 2; i > left.lng; i = i - dl) this._draw_lon_tick(i, 10, weight * 1.5); + + // draw minor ticks + for (let i = center.lng; i < right.lng; i = i + dl / 10) this._draw_lon_tick(i, 4, weight); + for (let i = center.lng - dl / 10; i > left.lng; i = i - dl / 10) this._draw_lon_tick(i, 4, weight); + }, + + _setCanvasPosition() { + let lt = this._map.containerPointToLayerPoint([0, 0]); + /** + * @TODO add support for "leaflet-rotate" + */ + if (this._map._bearing) { + lt = this._map.rotatedPointToMapPanePoint( + this._map.containerPointToLayerPoint(new L.Point(this._map._container.getBoundingClientRect())) + ); + } + L.DomUtil.setPosition(this._canvas, lt); + }, + + _latLngToCanvasPoint (latlng) { + return new L.Point( + this._map + .project(latlng) + ._subtract(this._map.getPixelOrigin()) + ).add(this._map._getMapPanePos()); + }, + + _draw_lat_tick (phi, lenght, weight) { + const to_deg = 180.0/Math.PI; + const size = this._map.getSize(); + const y = this._latLngToCanvasPoint(new L.LatLng(phi * to_deg, 0.0)).y; + this._ctx.lineWidth = weight; + this._ctx.beginPath(); + this._ctx.moveTo(0, y); + this._ctx.lineTo(+ lenght, y); + this._ctx.stroke(); + }, + + _draw_lon_tick(lam, lenght, weight) { + const x = this._latLngToCanvasPoint(new L.LatLng(0.0, lam)).x; + this._ctx.lineWidth = weight; + this._ctx.beginPath(); + this._ctx.moveTo(x, 0); + this._ctx.lineTo(x, lenght); + this._ctx.stroke(); + }, + + _merLength(phi) { + const cos2 = Math.cos(2.0 * phi); + const sin2 = Math.sin(2.0 * phi); + return this._A * (phi + sin2 * (this._c1 + (this._c2 + (this._c3 + (this._c4 + this._c5 * cos2) * cos2) *cos2) * cos2)); + }, + + _invmerLength(s) { + const psi = s/this._A; + const cos2 = Math.cos(2.0 * psi); + const sin2 = Math.sin(2.0 * psi); + return psi + sin2 * (this._ic1 + (this._ic2 + (this._ic3 + (this._ic4 + this._ic5 * cos2) * cos2) * cos2) * cos2); + }, +}); + +// backcomps for leaflet v1 +L.control = L.control || {}; +L.control.edgeScale = function (options) { + return new L.Control.EdgeScale(options); +}; + +L.Map.mergeOptions({ + edgeScaleControl: false +}); + +L.Map.addInitHook(function () { + if (this.options.edgeScaleControl) { + this.edgeScaleControl = new L.Control.EdgeScale(); + this.addControl(this.edgeScaleControl); + } });
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.min.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.min.js index 81237d5..6e36f21 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.min.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-edgescale.min.js @@ -1 +1 @@ -L.Control.EdgeScale=L.Control.extend({options:{position:"bottomleft",icon:!0,coords:!0,bar:!0,onMove:!0,template:"{y} | {x}",projected:!1,formatProjected:"#.##0,000",latlngFormat:"DD",latlngDesignators:!0,latLngFormatter:void 0,iconStyle:{background:"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 100 100'%3E%3Cg stroke='%23fff'%3E%3Ccircle cx='50' cy='50.2' r='3.9' stroke-width='2' /%3E%3Cpath stroke-width='3' d='M5 54h32a4 4 0 1 0 0-8H5a4 4 0 1 0 0 8z M54 5a4 4 0 1 0-8 0v32a4 4 0 1 0 8 0V5z M99 50c0-2-2-4-4-4H63a4 4 0 1 0 0 8h32c2 0 4-1 4-4zM46 95a4 4 0 1 0 8 0V64a4 4 0 1 0-8 0v31z'/%3E%3C/g%3E%3C/svg%3E%0A\")",width:"24px",height:"24px",left:"calc(50% - 12px)",top:"calc(50% - 12px)",content:"",display:"block",position:"absolute",zIndex:999,pointerEvents:"none"},containerStyle:{backgroundColor:"rgba(255, 255, 255, 0.7)",boxShadow:"0 0 5px #bbb",borderRadius:"3px",padding:"3px 2px",color:"#333",font:"11px/1.5 Consolas, monaco, monospace",writingMode:"vertical-lr"}},initialize:function(options){L.setOptions(this,options)},onAdd:function(map){return this.options.bar&&(this._scaleBar=new L.Control.EdgeScale.Layer(!0===this.options.bar?{}:this.options.bar).addTo(map)),this.options.icon&&(this._icon=L.DomUtil.create("div","leaflet-crosshair"),Object.assign(this._icon.style,this.options.iconStyle),map.getContainer().insertBefore(this._icon,map.getContainer().firstChild)),this._container=L.DomUtil.create("div","leaflet-control-mapcentercoord"),Object.assign(this._container.style,this.options.containerStyle),this.options.coords||(this._container.style.display="none"),L.DomEvent.disableClickPropagation(this._container),this._container.innerHTML=this._getMapCenterCoord(),map.on("move",this._onMapMove,this),map.on("moveend",this._onMapMove,this),this._container},onRemove:function(map){this.options.bar&&this._scaleBar.remove(),this.options.icon&&map.getContainer().removeChild(this._icon),map.off("move",this._onMapMove,this),map.off("moveend",this._onMapMove,this)},_onMapMove:function(e){(this.options.onMove||"moveend"===e.type)&&(this._container.innerHTML=this._getMapCenterCoord())},_getMapCenterCoord:function(){const center=this._map.getCenter();return this.options.projected?this._getProjectedCoord(this._map.options.crs.project(center)):this._getLatLngCoord(center)},_getProjectedCoord:function(center){return L.Util.template(this.options.template,{x:this._format(this.options.formatProjected,center.x),y:this._format(this.options.formatProjected,center.y)})},_getLatLngCoord:function(latLng){const{latLngFormatter:latLngFormatter,latlngFormat:latlngFormat,latlngDesignators:designators}=this.options;if(void 0!==latLngFormatter)return latLngFormatter(latLng.lat,latLng.lng);let lat,lng,deg,min,center={lat:latLng.lat,lng:latLng.lng,lng_neg:latLng.lng<0,lat_neg:latLng.lat<0};return center.lng<0&&(center.lng=Math.abs(center.lng)),center.lng>180&&(center.lng=360-center.lng,center.lng_neg=!center.lng_neg),center.lat<0&&(center.lat=Math.abs(center.lat)),"DM"===latlngFormat?(deg=parseInt(center.lng),lng=deg+"º "+this._format("00.000",60*(center.lng-deg))+"'",deg=parseInt(center.lat),lat=deg+"º "+this._format("00.000",60*(center.lat-deg))+"'"):"DMS"===latlngFormat?(deg=parseInt(center.lng),min=60*(center.lng-deg),lng=deg+"º "+this._format("00",parseInt(min))+"' "+this._format("00.0",60*(min-parseInt(min)))+"''",deg=parseInt(center.lat),min=60*(center.lat-deg),lat=deg+"º "+this._format("00",parseInt(min))+"' "+this._format("00.0",60*(min-parseInt(min)))+"''"):(lng=this._format("#0.00000",center.lng)+"º",lat=this._format("##0.00000",center.lat)+"º"),L.Util.template(this.options.template,{x:(!designators&¢er.lng_neg?"-":"")+lng+(designators?center.lng_neg?" W":" E":""),y:(!designators&¢er.lat_neg?"-":"")+lat+(designators?center.lat_neg?" S":" N":"")})},_format:function(m,v){if(!m||isNaN(+v))return v;let isNegative=(v="-"==m.charAt(0)?-v:+v)<0?v=-v:0,result=m.match(/[^\d\-\+#]/g),Decimal=result&&result[result.length-1]||".",Group=result&&result[1]&&result[0]||",";m=m.split(Decimal),v=+(v=v.toFixed(m[1]&&m[1].length))+"";let pos_trail_zero=m[1]&&m[1].lastIndexOf("0"),part=v.split(".");(!part[1]||part[1]&&part[1].length<=pos_trail_zero)&&(v=(+v).toFixed(pos_trail_zero+1));let szSep=m[0].split(Group);m[0]=szSep.join("");let pos_lead_zero=m[0]&&m[0].indexOf("0");if(pos_lead_zero>-1)for(;part[0].length<m[0].length-pos_lead_zero;)part[0]="0"+part[0];else 0==+part[0]&&(part[0]="");(v=v.split("."))[0]=part[0];var pos_separator=szSep[1]&&szSep[szSep.length-1].length;if(pos_separator){let integer=v[0],str="",offset=integer.length%pos_separator;for(let i=0,l=integer.length;i<l;i++)str+=integer.charAt(i),!((i-offset+1)%pos_separator)&&i<l-pos_separator&&(str+=Group);v[0]=str}return v[1]=m[1]&&v[1]?Decimal+v[1]:"",(isNegative?"-":"")+v[0]+v[1]}}),L.Control.EdgeScale.Layer=L.Layer.extend({includes:L.Evented?L.Evented.prototype:L.Mixin.Events,options:{opacity:1,weight:.8,gradient:{size:10,opacity:.5},color:"#000",font:"11px Arial",zoomInterval:[{start:0,end:2,interval:5e6},{start:3,end:3,interval:2e6},{start:4,end:4,interval:1e6},{start:5,end:5,interval:5e5},{start:6,end:7,interval:2e5},{start:8,end:8,interval:1e5},{start:9,end:9,interval:5e4},{start:10,end:10,interval:2e4},{start:11,end:11,interval:1e4},{start:12,end:12,interval:5e3},{start:13,end:13,interval:2e3},{start:14,end:14,interval:1e3},{start:15,end:15,interval:500},{start:16,end:16,interval:200},{start:17,end:17,interval:100},{start:18,end:18,interval:50},{start:19,end:19,interval:20},{start:20,end:20,interval:10}],pane:"edgescalePane"},initialize:function(options){L.setOptions(this,options);const a=this._a=6378137,b=this._b=6356752.3142,n=this._n=(a-b)/(a+b),a2=a*a,b2=b*b,n2=n*n,n3=n2*n,n4=n3*n,n5=n4*n;this._A=a*(1-n)*(1-n2)*(1+9/4*n2+225/64*n4),this._e2=(a2-b2)/a2,this._ic1=1.5*n-29/12*n3+6.9125*n5,this._ic2=21/8*n2-1537/128*n4,this._ic3=151/24*n3-32373/640*n5,this._ic4=1097/64*n4,this._ic5=8011/150*n5,this._c1=-1.5*n+31/24*n3-669/640*n5,this._c2=15/18*n2-435/128*n4,this._c3=-35/12*n3+8.1375*n5,this._c4=315/64*n4,this._c5=-8.6625*n5,this._LIMIT_PHI=1.484419982},onAdd:function(map){this._map=map;let pane=map.getPane(this.options.pane);pane||(pane=this._pane=map.createPane("edgescalePane",map.getPane("norotatePane")||map.getPane("mapPane")),pane.style.zIndex=625,pane.style.pointerEvents="none"),this._pane=pane,this._canvas||this._initCanvas(),this._pane.appendChild(this._canvas),map.on("viewreset",this._reset,this),map.on("move",this._reset,this),map.on("moveend",this._reset,this),map.on("rotate",this._reset,this),this._reset()},onRemove:function(map){this._pane.removeChild(this._canvas),map.off("viewreset",this._reset,this),map.off("move",this._reset,this),map.off("moveend",this._reset,this)},addTo:function(map){return map.addLayer(this),this},setOpacity:function(opacity){return this.options.opacity=opacity,L.DomUtil.setOpacity(this._canvas,this.options.opacity),this},bringToFront:function(){return this._canvas&&this._pane.appendChild(this._canvas),this},bringToBack:function(){return this._canvas&&this._pane.insertBefore(this._canvas,pane.firstChild),this},_initCanvas:function(){this._canvas=L.DomUtil.create("canvas",""),this._ctx=this._canvas.getContext("2d"),this.setOpacity(),L.extend(this._canvas,{onselectstart:L.Util.falseFn,onmousemove:L.Util.falseFn,onload:L.bind(this._onCanvasLoad,this)})},_reset:function(){var canvas=this._canvas,size=this._map.getSize();if(this._setCanvasPosition(),canvas.width=size.x,canvas.height=size.y,canvas.style.width=size.x+"px",canvas.style.height=size.y+"px",this._map._bearing)return;const{gradient:gradient}=this.options;this._hor_gradient||(this._hor_gradient=this._ctx.createLinearGradient(0,0,0,gradient.size),this._hor_gradient.addColorStop(0,"rgba(255, 255, 255, "+gradient.opacity+")"),this._hor_gradient.addColorStop(1,"rgba(255, 255, 255, 0)")),this._ctx.fillStyle=this._hor_gradient,this._ctx.fillRect(0,0,size.x,gradient.size),this._vert_gradient||(this._vert_gradient=this._ctx.createLinearGradient(0,0,gradient.size,0),this._vert_gradient.addColorStop(0,"rgba(255, 255, 255, "+gradient.opacity+")"),this._vert_gradient.addColorStop(1,"rgba(255, 255, 255, 0)")),this._ctx.fillStyle=this._vert_gradient,this._ctx.fillRect(0,0,gradient.size,size.y),this._ctx.beginPath(),this._ctx.moveTo(0,0),this._ctx.lineTo(size.x,0),this._ctx.lineTo(size.x,size.y),this._ctx.stroke(),this._calcInterval(),this._draw()},_onCanvasLoad:function(){this.fire("load")},_calcInterval:function(){const{zoomInterval:zoomInterval}=this.options,zoom=this._map.getZoom();if(void 0!==zoomInterval)for(const idx in zoomInterval){const dict=zoomInterval[idx];if(dict.start<=zoom&&dict.end&&dict.end>=zoom){this._interval=dict.interval;break}}else this._interval=L.Control.Scale.prototype._getRoundNum(this._map.containerPointToLatLng([0,this._map.getSize().y/2]).distanceTo(this._map.containerPointToLatLng([L.Control.Scale.prototype.options.maxWidth,this._map.getSize().y/2])));this._currZoom=zoom},_draw:function(){this._ctx.strokeStyle=this.options.color,this._create_lat_ticks(),this._create_lon_ticks(),this._ctx.fillStyle=this.options.color,this._ctx.font=this.options.font;const size=this._map.getSize(),text=this._interval>=1e3?this._interval/1e3+" km":this._interval+" m";this._ctx.textAlign="left",this._ctx.textBaseline="middle",this._ctx.fillText(text,12,size.y/2),this._ctx.textAlign="center",this._ctx.textBaseline="top",this._ctx.fillText(text,size.x/2,12)},_create_lat_ticks:function(){const{weight:weight}=this.options,size=this._map.getSize(),to_rad=Math.PI/180,center=this._merLength(this._map.containerPointToLatLng(L.point(0,size.y/2)).lat*to_rad),top=this._merLength(this._map.containerPointToLatLng(L.point(0,0)).lat*to_rad),bottom=this._merLength(this._map.containerPointToLatLng(L.point(0,size.y)).lat*to_rad);for(let i=center+this._interval/2;i<top;i+=this._interval){const phi=this._invmerLength(i);phi<this._LIMIT_PHI&&phi>-this._LIMIT_PHI&&this._draw_lat_tick(phi,10,1.5*weight)}for(let i=center-this._interval/2;i>bottom;i-=this._interval){const phi=this._invmerLength(i);phi>-this._LIMIT_PHI&&phi<this._LIMIT_PHI&&this._draw_lat_tick(phi,10,1.5*weight)}for(let i=center;i<top;i+=this._interval/10){const phi=this._invmerLength(i);phi<this._LIMIT_PHI&&phi>-this._LIMIT_PHI&&this._draw_lat_tick(phi,4,weight)}for(let i=center-this._interval/10;i>bottom;i-=this._interval/10){const phi=this._invmerLength(i);phi>-this._LIMIT_PHI&&phi<this._LIMIT_PHI&&this._draw_lat_tick(phi,4,weight)}},_create_lon_ticks:function(){const{weight:weight}=this.options,size=this._map.getSize(),to_rad=Math.PI/180,to_deg=180/Math.PI,center=this._map.containerPointToLatLng(L.point(size.x/2,0)),left=this._map.containerPointToLatLng(L.point(0,0)),right=this._map.containerPointToLatLng(L.point(size.x,0)),sinPhi2=Math.pow(Math.sin(center.lat*to_rad),2),N=this._a/Math.sqrt(1-this._e2*sinPhi2),dl=this._interval/(N*Math.cos(center.lat*to_rad))*to_deg;for(let i=center.lng+dl/2;i<right.lng;i+=dl)this._draw_lon_tick(i,10,1.5*weight);for(let i=center.lng-dl/2;i>left.lng;i-=dl)this._draw_lon_tick(i,10,1.5*weight);for(let i=center.lng;i<right.lng;i+=dl/10)this._draw_lon_tick(i,4,weight);for(let i=center.lng-dl/10;i>left.lng;i-=dl/10)this._draw_lon_tick(i,4,weight)},_setCanvasPosition:function(){let lt=this._map.containerPointToLayerPoint([0,0]);this._map._bearing&&(lt=this._map.rotatedPointToMapPanePoint(this._map.containerPointToLayerPoint(L.point(this._map._container.getBoundingClientRect())))),L.DomUtil.setPosition(this._canvas,lt)},_latLngToCanvasPoint:function(latlng){return L.point(this._map.project(L.latLng(latlng))._subtract(this._map.getPixelOrigin())).add(this._map._getMapPanePos())},_draw_lat_tick:function(phi,lenght,weight){const to_deg=180/Math.PI,size=this._map.getSize(),y=this._latLngToCanvasPoint(L.latLng(phi*to_deg,0)).y;this._ctx.lineWidth=weight,this._ctx.beginPath(),this._ctx.moveTo(0,y),this._ctx.lineTo(+lenght,y),this._ctx.stroke()},_draw_lon_tick:function(lam,lenght,weight){const x=this._latLngToCanvasPoint(L.latLng(0,lam)).x;this._ctx.lineWidth=weight,this._ctx.beginPath(),this._ctx.moveTo(x,0),this._ctx.lineTo(x,lenght),this._ctx.stroke()},_merLength:function(phi){const cos2=Math.cos(2*phi),sin2=Math.sin(2*phi);return this._A*(phi+sin2*(this._c1+(this._c2+(this._c3+(this._c4+this._c5*cos2)*cos2)*cos2)*cos2))},_invmerLength:function(s){const psi=s/this._A,cos2=Math.cos(2*psi),sin2=Math.sin(2*psi);return psi+sin2*(this._ic1+(this._ic2+(this._ic3+(this._ic4+this._ic5*cos2)*cos2)*cos2)*cos2)}}),L.control.edgeScale=function(options){return new L.Control.EdgeScale(options)},L.Map.mergeOptions({edgeScaleControl:!1}),L.Map.addInitHook((function(){this.options.edgeScaleControl&&(this.edgeScaleControl=new L.Control.EdgeScale,this.addControl(this.edgeScaleControl))}));
\ No newline at end of file +L.Control.EdgeScale=L.Control.extend({options:{position:"bottomleft",icon:!0,coords:!0,bar:!0,onMove:!0,template:"{y} | {x}",projected:!1,formatProjected:"#.##0,000",latlngFormat:"DD",latlngDesignators:!0,latLngFormatter:void 0,iconStyle:{background:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 100 100'%3E%3Cg stroke='%23fff'%3E%3Ccircle cx='50' cy='50.2' r='3.9' stroke-width='2' /%3E%3Cpath stroke-width='3' d='M5 54h32a4 4 0 1 0 0-8H5a4 4 0 1 0 0 8z M54 5a4 4 0 1 0-8 0v32a4 4 0 1 0 8 0V5z M99 50c0-2-2-4-4-4H63a4 4 0 1 0 0 8h32c2 0 4-1 4-4zM46 95a4 4 0 1 0 8 0V64a4 4 0 1 0-8 0v31z'/%3E%3C/g%3E%3C/svg%3E%0A")`,width:"24px",height:"24px",left:"calc(50% - 12px)",top:"calc(50% - 12px)",content:"",display:"block",position:"absolute",zIndex:999,pointerEvents:"none"},containerStyle:{backgroundColor:"rgba(255, 255, 255, 0.7)",boxShadow:"0 0 5px #bbb",borderRadius:"3px",padding:"3px 2px",color:"#333",font:"11px/1.5 Consolas, monaco, monospace",writingMode:"vertical-lr"}},initialize(t){L.Util.setOptions(this,t)},onAdd(t){return this.options.bar&&(this._scaleBar=new L.Control.EdgeScale.Layer(this.options.bar===!0?{}:this.options.bar).addTo(t)),this.options.icon&&(this._icon=L.DomUtil.create("div","leaflet-crosshair"),Object.assign(this._icon.style,this.options.iconStyle),t.getContainer().insertBefore(this._icon,t.getContainer().firstChild)),this._container=L.DomUtil.create("div","leaflet-control-mapcentercoord"),Object.assign(this._container.style,this.options.containerStyle),this.options.coords||(this._container.style.display="none"),L.DomEvent.disableClickPropagation(this._container),this._container.innerHTML=this._getMapCenterCoord(),t.on("move",this._onMapMove,this),t.on("moveend",this._onMapMove,this),this._container},onRemove(t){this.options.bar&&this._scaleBar.remove(),this.options.icon&&t.getContainer().removeChild(this._icon),t.off("move",this._onMapMove,this),t.off("moveend",this._onMapMove,this)},_onMapMove(t){(this.options.onMove||t.type==="moveend")&&(this._container.innerHTML=this._getMapCenterCoord())},_getMapCenterCoord(){const t=this._map.getCenter();return this.options.projected?this._getProjectedCoord(this._map.options.crs.project(t)):this._getLatLngCoord(t)},_getProjectedCoord(t){return L.Util.template(this.options.template,{x:this._format(this.options.formatProjected,t.x),y:this._format(this.options.formatProjected,t.y)})},_getLatLngCoord(t){const{latLngFormatter:i,latlngFormat:a,latlngDesignators:s}=this.options;if(i!==void 0)return i(t.lat,t.lng);let h,l,e,n,o={lat:t.lat,lng:t.lng,lng_neg:t.lng<0,lat_neg:t.lat<0};return o.lng<0&&(o.lng=Math.abs(o.lng)),o.lng>180&&(o.lng=360-o.lng,o.lng_neg=!o.lng_neg),o.lat<0&&(o.lat=Math.abs(o.lat)),a==="DM"?(e=parseInt(o.lng),l=e+"\xBA "+this._format("00.000",(o.lng-e)*60)+"'",e=parseInt(o.lat),h=e+"\xBA "+this._format("00.000",(o.lat-e)*60)+"'"):a==="DMS"?(e=parseInt(o.lng),n=(o.lng-e)*60,l=e+"\xBA "+this._format("00",parseInt(n))+"' "+this._format("00.0",(n-parseInt(n))*60)+"''",e=parseInt(o.lat),n=(o.lat-e)*60,h=e+"\xBA "+this._format("00",parseInt(n))+"' "+this._format("00.0",(n-parseInt(n))*60)+"''"):(l=this._format("#0.00000",o.lng)+"\xBA",h=this._format("##0.00000",o.lat)+"\xBA"),L.Util.template(this.options.template,{x:(!s&&o.lng_neg?"-":"")+l+(s?o.lng_neg?" W":" E":""),y:(!s&&o.lat_neg?"-":"")+h+(s?o.lat_neg?" S":" N":"")})},_format(t,i){if(!t||isNaN(+i))return i;i=t.charAt(0)=="-"?-i:+i;let a=i<0?i=-i:0,s=t.match(/[^\d\-\+#]/g),h=s&&s[s.length-1]||".",l=s&&s[1]&&s[0]||",";t=t.split(h),i=i.toFixed(t[1]&&t[1].length),i=+i+"";let e=t[1]&&t[1].lastIndexOf("0"),n=i.split(".");(!n[1]||n[1]&&n[1].length<=e)&&(i=(+i).toFixed(e+1));let o=t[0].split(l);t[0]=o.join("");let _=t[0]&&t[0].indexOf("0");if(_>-1)for(;n[0].length<t[0].length-_;)n[0]="0"+n[0];else+n[0]==0&&(n[0]="");i=i.split("."),i[0]=n[0];var r=o[1]&&o[o.length-1].length;if(r){let d=i[0],g="",f=d.length%r;for(let c=0,p=d.length;c<p;c++)g+=d.charAt(c),!((c-f+1)%r)&&c<p-r&&(g+=l);i[0]=g}return i[1]=t[1]&&i[1]?h+i[1]:"",(a?"-":"")+i[0]+i[1]}}),L.Control.EdgeScale.Layer=L.Layer.extend({options:{opacity:1,weight:.8,gradient:{size:10,opacity:.5},color:"#000",font:"11px Arial",zoomInterval:[{start:0,end:2,interval:5e6},{start:3,end:3,interval:2e6},{start:4,end:4,interval:1e6},{start:5,end:5,interval:5e5},{start:6,end:7,interval:2e5},{start:8,end:8,interval:1e5},{start:9,end:9,interval:5e4},{start:10,end:10,interval:2e4},{start:11,end:11,interval:1e4},{start:12,end:12,interval:5e3},{start:13,end:13,interval:2e3},{start:14,end:14,interval:1e3},{start:15,end:15,interval:500},{start:16,end:16,interval:200},{start:17,end:17,interval:100},{start:18,end:18,interval:50},{start:19,end:19,interval:20},{start:20,end:20,interval:10}],pane:"edgescalePane"},initialize(t){L.Util.setOptions(this,t);const i=this._a=6378137,a=this._b=63567523142e-4,s=this._n=(i-a)/(i+a),h=i*i,l=a*a,e=s*s,n=e*s,o=n*s,_=o*s;this._A=i*(1-s)*(1-e)*(1+9/4*e+225/64*o),this._e2=(h-l)/h,this._ic1=1.5*s-29/12*n+553/80*_,this._ic2=21/8*e-1537/128*o,this._ic3=151/24*n-32373/640*_,this._ic4=1097/64*o,this._ic5=8011/150*_,this._c1=-1.5*s+31/24*n-669/640*_,this._c2=15/18*e-435/128*o,this._c3=-35/12*n+651/80*_,this._c4=315/64*o,this._c5=-693/80*_,this._LIMIT_PHI=1.484419982},onAdd(t){this._map=t;let i=t.getPane(this.options.pane);i||(i=this._pane=t.createPane("edgescalePane",t.getPane("norotatePane")||t.getPane("mapPane")),i.style.zIndex=625,i.style.pointerEvents="none"),this._pane=i,this._canvas||this._initCanvas(),this._pane.appendChild(this._canvas),t.on("viewreset",this._reset,this),t.on("move",this._reset,this),t.on("moveend",this._reset,this),t.on("rotate",this._reset,this),this._reset()},onRemove(t){this._pane.removeChild(this._canvas),t.off("viewreset",this._reset,this),t.off("move",this._reset,this),t.off("moveend",this._reset,this)},addTo(t){return t.addLayer(this),this},setOpacity(t){return this.options.opacity=t,this._canvas.style.opacity=this.options.opacity,this},bringToFront(){return this._canvas&&this._pane.appendChild(this._canvas),this},bringToBack(){return this._canvas&&this._pane.insertBefore(this._canvas,pane.firstChild),this},_initCanvas(){this._canvas=L.DomUtil.create("canvas",""),this._ctx=this._canvas.getContext("2d"),this.setOpacity(),Object.assign(this._canvas,{onselectstart:L.Util.falseFn,onmousemove:L.Util.falseFn,onload:this._onCanvasLoad.bind(this)})},_reset(){var t=this._canvas,i=this._map.getSize();if(this._setCanvasPosition(),t.width=i.x,t.height=i.y,t.style.width=i.x+"px",t.style.height=i.y+"px",this._map._bearing)return;const{gradient:a}=this.options;this._hor_gradient||(this._hor_gradient=this._ctx.createLinearGradient(0,0,0,a.size),this._hor_gradient.addColorStop(0,"rgba(255, 255, 255, "+a.opacity+")"),this._hor_gradient.addColorStop(1,"rgba(255, 255, 255, 0)")),this._ctx.fillStyle=this._hor_gradient,this._ctx.fillRect(0,0,i.x,a.size),this._vert_gradient||(this._vert_gradient=this._ctx.createLinearGradient(0,0,a.size,0),this._vert_gradient.addColorStop(0,"rgba(255, 255, 255, "+a.opacity+")"),this._vert_gradient.addColorStop(1,"rgba(255, 255, 255, 0)")),this._ctx.fillStyle=this._vert_gradient,this._ctx.fillRect(0,0,a.size,i.y),this._ctx.beginPath(),this._ctx.moveTo(0,0),this._ctx.lineTo(i.x,0),this._ctx.lineTo(i.x,i.y),this._ctx.stroke(),this._calcInterval(),this._draw()},_onCanvasLoad(){this.fire("load")},_calcInterval(){const{zoomInterval:t}=this.options,i=this._map.getZoom();if(t!==void 0)for(const a in t){const s=t[a];if(s.start<=i&&s.end&&s.end>=i){this._interval=s.interval;break}}else this._interval=L.Control.Scale.prototype._getRoundNum(this._map.containerPointToLatLng([0,this._map.getSize().y/2]).distanceTo(this._map.containerPointToLatLng([L.Control.Scale.prototype.options.maxWidth,this._map.getSize().y/2])));this._currZoom=i},_draw(){this._ctx.strokeStyle=this.options.color,this._create_lat_ticks(),this._create_lon_ticks(),this._ctx.fillStyle=this.options.color,this._ctx.font=this.options.font;const t=this._map.getSize(),i=this._interval>=1e3?this._interval/1e3+" km":this._interval+" m";this._ctx.textAlign="left",this._ctx.textBaseline="middle",this._ctx.fillText(i,12,t.y/2),this._ctx.textAlign="center",this._ctx.textBaseline="top",this._ctx.fillText(i,t.x/2,12)},_create_lat_ticks(){const{weight:t}=this.options,i=this._map.getSize(),a=Math.PI/180,s=this._merLength(this._map.containerPointToLatLng(new L.Point(0,i.y/2)).lat*a),h=this._merLength(this._map.containerPointToLatLng(new L.Point(0,0)).lat*a),l=this._merLength(this._map.containerPointToLatLng(new L.Point(0,i.y)).lat*a);for(let e=s+this._interval/2;e<h;e=e+this._interval){const n=this._invmerLength(e);n<this._LIMIT_PHI&&n>-this._LIMIT_PHI&&this._draw_lat_tick(n,10,t*1.5)}for(let e=s-this._interval/2;e>l;e=e-this._interval){const n=this._invmerLength(e);n>-this._LIMIT_PHI&&n<this._LIMIT_PHI&&this._draw_lat_tick(n,10,t*1.5)}for(let e=s;e<h;e=e+this._interval/10){const n=this._invmerLength(e);n<this._LIMIT_PHI&&n>-this._LIMIT_PHI&&this._draw_lat_tick(n,4,t)}for(let e=s-this._interval/10;e>l;e=e-this._interval/10){const n=this._invmerLength(e);n>-this._LIMIT_PHI&&n<this._LIMIT_PHI&&this._draw_lat_tick(n,4,t)}},_create_lon_ticks(){const{weight:t}=this.options,i=this._map.getSize(),a=Math.PI/180,s=180/Math.PI,h=this._map.containerPointToLatLng(new L.Point(i.x/2,0)),l=this._map.containerPointToLatLng(new L.Point(0,0)),e=this._map.containerPointToLatLng(new L.Point(i.x,0)),n=Math.pow(Math.sin(h.lat*a),2),o=this._a/Math.sqrt(1-this._e2*n),_=this._interval/(o*Math.cos(h.lat*a))*s;for(let r=h.lng+_/2;r<e.lng;r=r+_)this._draw_lon_tick(r,10,t*1.5);for(let r=h.lng-_/2;r>l.lng;r=r-_)this._draw_lon_tick(r,10,t*1.5);for(let r=h.lng;r<e.lng;r=r+_/10)this._draw_lon_tick(r,4,t);for(let r=h.lng-_/10;r>l.lng;r=r-_/10)this._draw_lon_tick(r,4,t)},_setCanvasPosition(){let t=this._map.containerPointToLayerPoint([0,0]);this._map._bearing&&(t=this._map.rotatedPointToMapPanePoint(this._map.containerPointToLayerPoint(new L.Point(this._map._container.getBoundingClientRect())))),L.DomUtil.setPosition(this._canvas,t)},_latLngToCanvasPoint(t){return new L.Point(this._map.project(t)._subtract(this._map.getPixelOrigin())).add(this._map._getMapPanePos())},_draw_lat_tick(t,i,a){const s=180/Math.PI,h=this._map.getSize(),l=this._latLngToCanvasPoint(new L.LatLng(t*s,0)).y;this._ctx.lineWidth=a,this._ctx.beginPath(),this._ctx.moveTo(0,l),this._ctx.lineTo(+i,l),this._ctx.stroke()},_draw_lon_tick(t,i,a){const s=this._latLngToCanvasPoint(new L.LatLng(0,t)).x;this._ctx.lineWidth=a,this._ctx.beginPath(),this._ctx.moveTo(s,0),this._ctx.lineTo(s,i),this._ctx.stroke()},_merLength(t){const i=Math.cos(2*t),a=Math.sin(2*t);return this._A*(t+a*(this._c1+(this._c2+(this._c3+(this._c4+this._c5*i)*i)*i)*i))},_invmerLength(t){const i=t/this._A,a=Math.cos(2*i),s=Math.sin(2*i);return i+s*(this._ic1+(this._ic2+(this._ic3+(this._ic4+this._ic5*a)*a)*a)*a)}}),L.control=L.control||{},L.control.edgeScale=function(t){return new L.Control.EdgeScale(t)},L.Map.mergeOptions({edgeScaleControl:!1}),L.Map.addInitHook(function(){this.options.edgeScaleControl&&(this.edgeScaleControl=new L.Control.EdgeScale,this.addControl(this.edgeScaleControl))}); diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.js index c7a9dd6..0f66f9e 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.js @@ -23,10 +23,8 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -L.Mixin.Selectable = { - includes: L.Mixin.Events, - - setSelected: function(s) { +const selectable = { + setSelected(s) { var selected = !!s; if (this._selected !== selected) { this._selected = selected; @@ -34,19 +32,17 @@ L.Mixin.Selectable = { } }, - isSelected: function() { + isSelected() { return !!this._selected; }, }; -L.Mixin.Selection = { - includes: L.Mixin.Events, - - getSelection: function() { +const selection = { + getSelection() { return this._selected; }, - setSelection: function(item) { + setSelection(item) { if (this._selected === item) { if (item !== null) { item.setSelected(!item.isSelected()); @@ -68,12 +64,12 @@ L.Mixin.Selection = { }; L.Control.LayersLegend = L.Control.Layers.extend({ - _onInputClick: function() { + _onInputClick() { this._handlingClick = true; this._layerControlInputs.reduceRight((_,input) => { if (input.checked) { - this._map.fireEvent("legend_selected", { + this._map.fire("legend_selected", { layer: this._getLayer(input.layerId).layer, input: input, }, true); @@ -87,11 +83,14 @@ L.Control.LayersLegend = L.Control.Layers.extend({ } }); +// backcomps for leaflet v1 +L.control = L.control || {}; L.control.layersLegend = (baseLayers, overlays, options) => new L.Control.LayersLegend(baseLayers, overlays, options); -L.GeoJSON.include(L.Mixin.Selectable); +L.GeoJSON.include(selectable); -L.GpxGroup = L.Class.extend({ +L.GpxGroup = L.Evented.extend({ + ...selection, options: { highlight: { color: '#ff0', @@ -122,31 +121,30 @@ L.GpxGroup = L.Class.extend({ }, }, - initialize: function(tracks, options) { + initialize(tracks, options) { L.Util.setOptions(this, options); this._count = 0; this._loadedCount = 0; this._tracks = tracks; - this._layers = L.featureGroup(); - this._markers = L.featureGroup(); + this._layers = new L.FeatureGroup(); + this._markers = new L.FeatureGroup(); this._elevation = L.control.elevation(this.options.elevation_options); this._legend = L.control.layersLegend(null, null, this.options.legend_options); this.options.points.forEach((poi) => - L - .marker(poi.latlng, { icon: L.icon(this.options.points_options.icon) }) + new L.Marker(poi.latlng, { icon: new L.Icon(this.options.points_options.icon) }) .bindTooltip(poi.name, { direction: 'auto' }).addTo(this._markers) ); }, - getBounds: function() { + getBounds() { return this._layers.getBounds(); }, - addTo: function(map) { + addTo(map) { this._layers.addTo(map); this._markers.addTo(map); @@ -158,7 +156,7 @@ L.GpxGroup = L.Class.extend({ }, - addTrack: function(track) { + addTrack(track) { if (track instanceof Object) { this._loadGeoJSON(track); } else { @@ -169,14 +167,14 @@ L.GpxGroup = L.Class.extend({ } }, - _loadGeoJSON: function(geojson, fallbackName) { + _loadGeoJSON(geojson, fallbackName) { if (geojson) { geojson.name = geojson.name || (geojson[0] && geojson[0].properties.name) || fallbackName; this._loadRoute(geojson); } }, - _loadRoute: function(data) { + _loadRoute(data) { if (!data) return; var line_style = { @@ -186,7 +184,7 @@ L.GpxGroup = L.Class.extend({ distanceMarkers: this.options.distanceMarkers_options, }; - var route = L.geoJson(data, { + var route = new L.GeoJSON(data, { name: data.name || '', style: (feature) => line_style, distanceMarkers: line_style.distanceMarkers, @@ -194,29 +192,27 @@ L.GpxGroup = L.Class.extend({ filter: feature => feature.geometry.type != "Point", }); - - this._elevation.import(this._elevation.__LGEOMUTIL).then(() => { - route.addTo(this._layers); + route.addTo(this._layers); - route.eachLayer((layer) => this._onEachRouteLayer(route, layer)); - this._onEachRouteLoaded(route); - }); + route.eachLayer((layer) => this._onEachRouteLayer(route, layer)); + this._onEachRouteLoaded(route); }, - _onEachRouteLayer: function(route, layer) { + _onEachRouteLayer(route, layer) { var polyline = layer; + var hoverEvents = L.version.startsWith('2.') ? ['pointerover', 'pointerout'] : ['mouseover', 'mouseout']; - route.on('selected', L.bind(this._onRouteSelected, this, route, polyline)); + route.on('selected', this._onRouteSelected.bind(this, route, polyline)); - polyline.on('mouseover', L.bind(this._onRouteMouseOver, this, route, polyline)); - polyline.on('mouseout', L.bind(this._onRouteMouseOut, this, route, polyline)); - polyline.on('click', L.bind(this._onRouteClick, this, route, polyline)); + polyline.on(hoverEvents[0], this._onRouteMouseOver.bind(this, route, polyline)); + polyline.on(hoverEvents[1], this._onRouteMouseOut.bind(this, route, polyline)); + polyline.on('click', this._onRouteClick.bind(this, route, polyline)); polyline.bindTooltip(route.options.name, { direction: 'auto', sticky: true, }); }, - _onEachRouteLoaded: function(route) { + _onEachRouteLoaded(route) { if (this.options.legend) { this._legend.addBaseLayer(route, '<svg id="legend_' + route._leaflet_id + '" width="25" height="10" version="1.1" xmlns="http://www.w3.org/2000/svg">' + '<line x1="0" x2="50" y1="5" y2="5" stroke="' + route.options.originalStyle.color + '" fill="transparent" stroke-width="5" /></svg>' + ' ' + route.options.name); } @@ -234,21 +230,21 @@ L.GpxGroup = L.Class.extend({ } }, - highlight: function(route, polyline) { + highlight(route, polyline) { polyline.setStyle(this.options.highlight); if (this.options.distanceMarkers) { polyline.addDistanceMarkers(); } }, - unhighlight: function(route, polyline) { + unhighlight(route, polyline) { polyline.setStyle(route.options.originalStyle); if (this.options.distanceMarkers) { polyline.removeDistanceMarkers(); } }, - _onRouteMouseOver: function(route, polyline) { + _onRouteMouseOver(route, polyline) { if (!route.isSelected()) { this.highlight(route, polyline); if (this.options.legend) { @@ -259,24 +255,24 @@ L.GpxGroup = L.Class.extend({ this.fire('route_mouseover', { route: route, polyline: polyline }); }, - _onRouteMouseOut: function(route, polyline) { + _onRouteMouseOut(route, polyline) { if (!route.isSelected()) { this.unhighlight(route, polyline); } this.fire('route_mouseout', { route: route, polyline: polyline }); }, - _onRouteClick: function(route, polyline) { + _onRouteClick(route, polyline) { this.setSelection(route); }, - _onRouteSelected: function(route, polyline) { + _onRouteSelected(route, polyline) { if (!route.isSelected()) { this.unhighlight(route, polyline); } }, - _onSelectionChanged: function(e) { + _onSelectionChanged(e) { var elevation = this._elevation; var eleDiv = elevation.getContainer(); var route = this.getSelection(); @@ -300,7 +296,7 @@ L.GpxGroup = L.Class.extend({ } }, - _onLegendSelected: function(e) { + _onLegendSelected(e) { var parent = e.input.closest('.leaflet-control-layers-list'); var route = e.layer; @@ -321,11 +317,11 @@ L.GpxGroup = L.Class.extend({ }); }, - _uniqueColors: function(count) { + _uniqueColors(count) { return count === 1 ? ['#0000ff'] : new Array(count).fill(null).map((_,i) => this._hsvToHex(i * (1 / count), 1, 0.7)); }, - _hsvToHex: function(h, s, v) { + _hsvToHex(h, s, v) { var i = Math.floor(h * 6); var f = h * 6 - i; var p = v * (1 - s); @@ -335,13 +331,10 @@ L.GpxGroup = L.Class.extend({ return rgb.map(d => d * 255).reduce((hex, byte) => hex + ((byte >> 4) & 0x0F).toString(16) + (byte & 0x0F).toString(16), "#"); }, - removeFrom: function(map) { + removeFrom(map) { this._layers.removeFrom(map); }, }); -L.GpxGroup.include(L.Mixin.Events); -L.GpxGroup.include(L.Mixin.Selection); - L.gpxGroup = (tracks, options) => new L.GpxGroup(tracks, options);
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.min.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.min.js index 5b30fb0..5663a42 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.min.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-gpxgroup.min.js @@ -1 +1 @@ -L.Mixin.Selectable={includes:L.Mixin.Events,setSelected:function(s){var selected=!!s;this._selected!==selected&&(this._selected=selected,this.fire("selected"))},isSelected:function(){return!!this._selected}},L.Mixin.Selection={includes:L.Mixin.Events,getSelection:function(){return this._selected},setSelection:function(item){this._selected===item?null!==item&&(item.setSelected(!item.isSelected()),item.isSelected()||(this._selected=null)):(this._selected&&this._selected.setSelected(!1),this._selected=item,this._selected&&this._selected.setSelected(!0)),this.fire("selection_changed")}},L.Control.LayersLegend=L.Control.Layers.extend({_onInputClick:function(){this._handlingClick=!0,this._layerControlInputs.reduceRight((_,input)=>{if(input.checked)return this._map.fireEvent("legend_selected",{layer:this._getLayer(input.layerId).layer,input:input},!0),input},0),this._handlingClick=!1,this._refocusOnMap()}}),L.control.layersLegend=(baseLayers,overlays,options)=>new L.Control.LayersLegend(baseLayers,overlays,options),L.GeoJSON.include(L.Mixin.Selectable),L.GpxGroup=L.Class.extend({options:{highlight:{color:"#ff0",opacity:1},points:[],points_options:{icon:{iconUrl:"../images/elevation-poi.png",iconSize:[12,12]}},flyToBounds:!0,legend:!1,legend_options:{position:"topright",collapsed:!1},elevation:!0,elevation_options:{theme:"yellow-theme",detached:!0,elevationDiv:"#elevation-div"},distanceMarkers:!0,distanceMarkers_options:{lazy:!0}},initialize:function(tracks,options){L.Util.setOptions(this,options),this._count=0,this._loadedCount=0,this._tracks=tracks,this._layers=L.featureGroup(),this._markers=L.featureGroup(),this._elevation=L.control.elevation(this.options.elevation_options),this._legend=L.control.layersLegend(null,null,this.options.legend_options),this.options.points.forEach(poi=>L.marker(poi.latlng,{icon:L.icon(this.options.points_options.icon)}).bindTooltip(poi.name,{direction:"auto"}).addTo(this._markers))},getBounds:function(){return this._layers.getBounds()},addTo:function(map){this._layers.addTo(map),this._markers.addTo(map),this._map=map,this.on("selection_changed",this._onSelectionChanged,this),this._map.on("legend_selected",this._onLegendSelected,this),this._tracks.forEach(this.addTrack,this)},addTrack:function(track){track instanceof Object?this._loadGeoJSON(track):fetch(track).then(response=>response.ok&&response.text()).then(text=>this._elevation._parseFromString(text)).then(geojson=>this._loadGeoJSON(geojson,track.split("/").pop().split("#")[0].split("?")[0]))},_loadGeoJSON:function(geojson,fallbackName){geojson&&(geojson.name=geojson.name||geojson[0]&&geojson[0].properties.name||fallbackName,this._loadRoute(geojson))},_loadRoute:function(data){if(data){var line_style={color:this._uniqueColors(this._tracks.length)[this._count++],opacity:.75,weight:5,distanceMarkers:this.options.distanceMarkers_options},route=L.geoJson(data,{name:data.name||"",style:feature=>line_style,distanceMarkers:line_style.distanceMarkers,originalStyle:line_style,filter:feature=>"Point"!=feature.geometry.type});this._elevation.import(this._elevation.__LGEOMUTIL).then(()=>{route.addTo(this._layers),route.eachLayer(layer=>this._onEachRouteLayer(route,layer)),this._onEachRouteLoaded(route)})}},_onEachRouteLayer:function(route,layer){var polyline=layer;route.on("selected",L.bind(this._onRouteSelected,this,route,polyline)),polyline.on("mouseover",L.bind(this._onRouteMouseOver,this,route,polyline)),polyline.on("mouseout",L.bind(this._onRouteMouseOut,this,route,polyline)),polyline.on("click",L.bind(this._onRouteClick,this,route,polyline)),polyline.bindTooltip(route.options.name,{direction:"auto",sticky:!0})},_onEachRouteLoaded:function(route){this.options.legend&&this._legend.addBaseLayer(route,'<svg id="legend_'+route._leaflet_id+'" width="25" height="10" version="1.1" xmlns="http://www.w3.org/2000/svg"><line x1="0" x2="50" y1="5" y2="5" stroke="'+route.options.originalStyle.color+'" fill="transparent" stroke-width="5" /></svg> '+route.options.name),this.fire("route_loaded",{route:route}),++this._loadedCount===this._tracks.length&&(this.fire("loaded"),this.options.flyToBounds&&this._map.flyToBounds(this.getBounds(),{duration:.25,easeLinearity:.25,noMoveStart:!0}),this.options.legend&&this._legend.addTo(this._map))},highlight:function(route,polyline){polyline.setStyle(this.options.highlight),this.options.distanceMarkers&&polyline.addDistanceMarkers()},unhighlight:function(route,polyline){polyline.setStyle(route.options.originalStyle),this.options.distanceMarkers&&polyline.removeDistanceMarkers()},_onRouteMouseOver:function(route,polyline){route.isSelected()||(this.highlight(route,polyline),this.options.legend&&(this.setSelection(route),L.DomUtil.get("legend_"+route._leaflet_id).parentNode.previousSibling.click())),this.fire("route_mouseover",{route:route,polyline:polyline})},_onRouteMouseOut:function(route,polyline){route.isSelected()||this.unhighlight(route,polyline),this.fire("route_mouseout",{route:route,polyline:polyline})},_onRouteClick:function(route,polyline){this.setSelection(route)},_onRouteSelected:function(route,polyline){route.isSelected()||this.unhighlight(route,polyline)},_onSelectionChanged:function(e){var elevation=this._elevation,eleDiv=elevation.getContainer(),route=this.getSelection();elevation.clear(),route&&route.isSelected()?(eleDiv||elevation.addTo(this._map),route.getLayers().forEach((function(layer){layer instanceof L.Polyline&&(elevation.addData(layer,!1),layer.bringToFront())}))):eleDiv&&elevation.remove()},_onLegendSelected:function(e){var parent=e.input.closest(".leaflet-control-layers-list"),route=e.layer;if(!route.isSelected()){for(var i in this.setSelection(route),route._layers)this.highlight(route,route._layers[i]);this._map.flyToBounds(e.layer.getBounds())}parent.scroll({top:e.input.offsetTop-parent.offsetTop||0,behavior:"smooth"}),this._layers.eachLayer(layer=>{var legend=L.DomUtil.get("legend_"+layer._leaflet_id);legend.querySelector("line").style.stroke=layer.isSelected()?this.options.highlight.color:"",legend.parentNode.style.fontWeight=layer.isSelected()?"700":""})},_uniqueColors:function(count){return 1===count?["#0000ff"]:new Array(count).fill(null).map((_,i)=>this._hsvToHex(i*(1/count),1,.7))},_hsvToHex:function(h,s,v){var i=Math.floor(6*h),f=6*h-i,p=v*(1-s),q=v*(1-f*s),t=v*(1-(1-f)*s),rgb;return{0:[v,t,p],1:[q,v,p],2:[p,v,t],3:[p,q,v],4:[t,p,v],5:[v,p,q]}[i%6].map(d=>255*d).reduce((hex,byte)=>hex+(byte>>4&15).toString(16)+(15&byte).toString(16),"#")},removeFrom:function(map){this._layers.removeFrom(map)}}),L.GpxGroup.include(L.Mixin.Events),L.GpxGroup.include(L.Mixin.Selection),L.gpxGroup=(tracks,options)=>new L.GpxGroup(tracks,options);
\ No newline at end of file +const selectable={setSelected(e){var t=!!e;this._selected!==t&&(this._selected=t,this.fire("selected"))},isSelected(){return!!this._selected}},selection={getSelection(){return this._selected},setSelection(e){this._selected===e?e!==null&&(e.setSelected(!e.isSelected()),e.isSelected()||(this._selected=null)):(this._selected&&this._selected.setSelected(!1),this._selected=e,this._selected&&this._selected.setSelected(!0)),this.fire("selection_changed")}};L.Control.LayersLegend=L.Control.Layers.extend({_onInputClick(){this._handlingClick=!0,this._layerControlInputs.reduceRight((e,t)=>{if(t.checked)return this._map.fire("legend_selected",{layer:this._getLayer(t.layerId).layer,input:t},!0),t},0),this._handlingClick=!1,this._refocusOnMap()}}),L.control=L.control||{},L.control.layersLegend=(e,t,i)=>new L.Control.LayersLegend(e,t,i),L.GeoJSON.include(selectable),L.GpxGroup=L.Evented.extend({...selection,options:{highlight:{color:"#ff0",opacity:1},points:[],points_options:{icon:{iconUrl:"../images/elevation-poi.png",iconSize:[12,12]}},flyToBounds:!0,legend:!1,legend_options:{position:"topright",collapsed:!1},elevation:!0,elevation_options:{theme:"yellow-theme",detached:!0,elevationDiv:"#elevation-div"},distanceMarkers:!0,distanceMarkers_options:{lazy:!0}},initialize(e,t){L.Util.setOptions(this,t),this._count=0,this._loadedCount=0,this._tracks=e,this._layers=new L.FeatureGroup,this._markers=new L.FeatureGroup,this._elevation=L.control.elevation(this.options.elevation_options),this._legend=L.control.layersLegend(null,null,this.options.legend_options),this.options.points.forEach(i=>new L.Marker(i.latlng,{icon:new L.Icon(this.options.points_options.icon)}).bindTooltip(i.name,{direction:"auto"}).addTo(this._markers))},getBounds(){return this._layers.getBounds()},addTo(e){this._layers.addTo(e),this._markers.addTo(e),this._map=e,this.on("selection_changed",this._onSelectionChanged,this),this._map.on("legend_selected",this._onLegendSelected,this),this._tracks.forEach(this.addTrack,this)},addTrack(e){e instanceof Object?this._loadGeoJSON(e):fetch(e).then(t=>t.ok&&t.text()).then(t=>this._elevation._parseFromString(t)).then(t=>this._loadGeoJSON(t,e.split("/").pop().split("#")[0].split("?")[0]))},_loadGeoJSON(e,t){e&&(e.name=e.name||e[0]&&e[0].properties.name||t,this._loadRoute(e))},_loadRoute(e){if(e){var t={color:this._uniqueColors(this._tracks.length)[this._count++],opacity:.75,weight:5,distanceMarkers:this.options.distanceMarkers_options},i=new L.GeoJSON(e,{name:e.name||"",style:o=>t,distanceMarkers:t.distanceMarkers,originalStyle:t,filter:o=>o.geometry.type!="Point"});i.addTo(this._layers),i.eachLayer(o=>this._onEachRouteLayer(i,o)),this._onEachRouteLoaded(i)}},_onEachRouteLayer(e,t){var i=t,o=L.version.startsWith("2.")?["pointerover","pointerout"]:["mouseover","mouseout"];e.on("selected",this._onRouteSelected.bind(this,e,i)),i.on(o[0],this._onRouteMouseOver.bind(this,e,i)),i.on(o[1],this._onRouteMouseOut.bind(this,e,i)),i.on("click",this._onRouteClick.bind(this,e,i)),i.bindTooltip(e.options.name,{direction:"auto",sticky:!0})},_onEachRouteLoaded(e){this.options.legend&&this._legend.addBaseLayer(e,'<svg id="legend_'+e._leaflet_id+'" width="25" height="10" version="1.1" xmlns="http://www.w3.org/2000/svg"><line x1="0" x2="50" y1="5" y2="5" stroke="'+e.options.originalStyle.color+'" fill="transparent" stroke-width="5" /></svg> '+e.options.name),this.fire("route_loaded",{route:e}),++this._loadedCount===this._tracks.length&&(this.fire("loaded"),this.options.flyToBounds&&this._map.flyToBounds(this.getBounds(),{duration:.25,easeLinearity:.25,noMoveStart:!0}),this.options.legend&&this._legend.addTo(this._map))},highlight(e,t){t.setStyle(this.options.highlight),this.options.distanceMarkers&&t.addDistanceMarkers()},unhighlight(e,t){t.setStyle(e.options.originalStyle),this.options.distanceMarkers&&t.removeDistanceMarkers()},_onRouteMouseOver(e,t){e.isSelected()||(this.highlight(e,t),this.options.legend&&(this.setSelection(e),L.DomUtil.get("legend_"+e._leaflet_id).parentNode.previousSibling.click())),this.fire("route_mouseover",{route:e,polyline:t})},_onRouteMouseOut(e,t){e.isSelected()||this.unhighlight(e,t),this.fire("route_mouseout",{route:e,polyline:t})},_onRouteClick(e,t){this.setSelection(e)},_onRouteSelected(e,t){e.isSelected()||this.unhighlight(e,t)},_onSelectionChanged(e){var t=this._elevation,i=t.getContainer(),o=this.getSelection();t.clear(),o&&o.isSelected()?(i||t.addTo(this._map),o.getLayers().forEach(function(s){s instanceof L.Polyline&&(t.addData(s,!1),s.bringToFront())})):i&&t.remove()},_onLegendSelected(e){var t=e.input.closest(".leaflet-control-layers-list"),i=e.layer;if(!i.isSelected()){this.setSelection(i);for(var o in i._layers)this.highlight(i,i._layers[o]);this._map.flyToBounds(e.layer.getBounds())}t.scroll({top:e.input.offsetTop-t.offsetTop||0,behavior:"smooth"}),this._layers.eachLayer(s=>{var n=L.DomUtil.get("legend_"+s._leaflet_id);n.querySelector("line").style.stroke=s.isSelected()?this.options.highlight.color:"",n.parentNode.style.fontWeight=s.isSelected()?"700":""})},_uniqueColors(e){return e===1?["#0000ff"]:new Array(e).fill(null).map((t,i)=>this._hsvToHex(i*(1/e),1,.7))},_hsvToHex(e,t,i){var o=Math.floor(e*6),s=e*6-o,n=i*(1-t),l=i*(1-s*t),r=i*(1-(1-s)*t),d={0:[i,r,n],1:[l,i,n],2:[n,i,r],3:[n,l,i],4:[r,n,i],5:[i,n,l]}[o%6];return d.map(a=>a*255).reduce((a,h)=>a+(h>>4&15).toString(16)+(h&15).toString(16),"#")},removeFrom(e){this._layers.removeFrom(e)}}),L.gpxGroup=(e,t)=>new L.GpxGroup(e,t); diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.js index 1684560..29cf5f2 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.js @@ -67,7 +67,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the width of the canvas. Used when clearing the canvas. * @param {number} width - Width of the canvas. */ - width: function (width) { + width(width) { this._width = width; return this; }, @@ -76,7 +76,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the height of the canvas. Used when clearing the canvas. * @param {number} height - Height of the canvas. */ - height: function (height) { + height(height) { this._height = height; return this; }, @@ -85,7 +85,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the weight of the path. * @param {number} weight - Weight of the path in px. */ - weight: function (weight) { + weight(weight) { this._weight = weight; return this; }, @@ -94,7 +94,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the width of the outline around the path. * @param {number} outlineWidth - Width of the outline in px. */ - outlineWidth: function (outlineWidth) { + outlineWidth(outlineWidth) { this._outlineWidth = outlineWidth; return this; }, @@ -103,7 +103,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the color of the outline around the path. * @param {string} outlineColor - A CSS color value. */ - outlineColor: function (outlineColor) { + outlineColor(outlineColor) { this._outlineColor = outlineColor; return this; }, @@ -113,7 +113,7 @@ https://github.com/iosphere/Leaflet.hotline/ * @param {Object.<number, string>} palette - Gradient definition. * e.g. { 0.0: 'white', 1.0: 'black' } */ - palette: function (palette) { + palette(palette) { var canvas = document.createElement('canvas'), ctx = canvas.getContext('2d'), gradient = ctx.createLinearGradient(0, 0, 0, 256); @@ -137,7 +137,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the value used at the start of the palette gradient. * @param {number} min */ - min: function (min) { + min(min) { this._min = min; return this; }, @@ -146,7 +146,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the value used at the end of the palette gradient. * @param {number} max */ - max: function (max) { + max(max) { this._max = max; return this; }, @@ -160,7 +160,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Sets the data that gets drawn on the canvas. * @param {(Path|Path[])} data - A single path or an array of paths. */ - data: function (data) { + data(data) { this._data = data; return this; }, @@ -169,7 +169,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Adds a path to the list of paths. * @param {Path} path */ - add: function (path) { + add(path) { this._data.push(path); return this; }, @@ -177,7 +177,7 @@ https://github.com/iosphere/Leaflet.hotline/ /** * Draws the currently set paths. */ - draw: function () { + draw() { var ctx = this._ctx; ctx.globalCompositeOperation = 'source-over'; @@ -194,8 +194,8 @@ https://github.com/iosphere/Leaflet.hotline/ * @param {number} value - Value to get the color for, should be between min and max. * @returns {Array.<number>} The RGB values as an array [r, g, b] */ - getRGBForValue: function (value) { - var valueRelative = Math.min(Math.max((value - this._min) / (this._max - this._min), 0), 0.999); + getRGBForValue(value) { + var valueRelative = this._max === this._min ? 0 : Math.min(Math.max((value - this._min) / (this._max - this._min), 0), 0.999); var paletteIndex = Math.floor(valueRelative * 256) * 4; return [ @@ -209,7 +209,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Draws the outline of the graphs. * @private */ - _drawOutline: function (ctx) { + _drawOutline(ctx) { var i, j, dataLength, path, pathLength, pointStart, pointEnd; if (this._outlineWidth) { @@ -235,7 +235,7 @@ https://github.com/iosphere/Leaflet.hotline/ * Draws the color encoded hotline of the graphs. * @private */ - _drawHotline: function (ctx) { + _drawHotline(ctx) { var i, j, dataLength, path, pathLength, pointStart, pointEnd, gradient, gradientStartRGB, gradientEndRGB; @@ -248,6 +248,11 @@ https://github.com/iosphere/Leaflet.hotline/ pointStart = path[j - 1]; pointEnd = path[j]; + // Keep only the outline where elevation is unknown, rather than treating it as zero. + if (!Number.isFinite(pointStart.z) || !Number.isFinite(pointEnd.z)) { + continue; + } + // Create a gradient for each segment, pick start end end colors from palette gradient gradient = ctx.createLinearGradient(pointStart.x, pointStart.y, pointEnd.x, pointEnd.y); gradientStartRGB = this.getRGBForValue(pointStart.z); @@ -267,18 +272,18 @@ https://github.com/iosphere/Leaflet.hotline/ var Renderer = L.Canvas.extend({ - _initContainer: function () { + _initContainer() { L.Canvas.prototype._initContainer.call(this); this._hotline = new Hotline(this._container); }, - _update: function () { + _update() { L.Canvas.prototype._update.call(this); this._hotline.width(this._container.width); this._hotline.height(this._container.height); }, - _updatePoly: function (layer) { + _updatePoly(layer) { if (!this._drawing) { return; } var parts = layer._parts; @@ -292,7 +297,7 @@ https://github.com/iosphere/Leaflet.hotline/ .draw(); }, - _updateOptions: function (layer) { + _updateOptions(layer) { if (layer.options.min != null) { this._hotline.min(layer.options.min); } @@ -315,7 +320,7 @@ https://github.com/iosphere/Leaflet.hotline/ }); var renderer = function (options) { - return L.Browser.canvas ? new Renderer(options) : null; + return document.createElement('canvas').getContext ? new Renderer(options) : null; }; @@ -324,7 +329,7 @@ https://github.com/iosphere/Leaflet.hotline/ * This is just a copy of the original Leaflet version that support a third z coordinate. * @see {@link http://leafletjs.com/reference.html#lineutil-clipsegment|Leaflet} */ - clipSegment: function (a, b, bounds, useLastCode, round) { + clipSegment(a, b, bounds, useLastCode, round) { var codeA = useLastCode ? this._lastCode : L.LineUtil._getBitCode(a, bounds), codeB = L.LineUtil._getBitCode(b, bounds), codeOut, p, newCode; @@ -380,14 +385,14 @@ https://github.com/iosphere/Leaflet.hotline/ outlineWidth: 1 }, - getRGBForValue: function (value) { + getRGBForValue(value) { return this._renderer._hotline.getRGBForValue(value); }, /** * Just like the Leaflet version, but with support for a z coordinate. */ - _projectLatlngs: function (latlngs, result, projectedBounds) { + _projectLatlngs(latlngs, result, projectedBounds) { var flat = latlngs[0] instanceof L.LatLng, len = latlngs.length, i, ring; @@ -411,7 +416,7 @@ https://github.com/iosphere/Leaflet.hotline/ /** * Just like the Leaflet version, but uses `Util.clipSegment()`. */ - _clipPoints: function () { + _clipPoints() { if (this.options.noClip) { this._parts = this._rings; return; @@ -443,7 +448,7 @@ https://github.com/iosphere/Leaflet.hotline/ } }, - _clickTolerance: function () { + _clickTolerance() { return this.options.weight / 2 + this.options.outlineWidth + (L.Browser.touch ? 10 : 0); } }); diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.min.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.min.js index a1466b8..b102d9a 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.min.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-hotline.min.js @@ -1 +1 @@ -!function(root,plugin){"function"==typeof define&&define.amd?define(["leaflet"],plugin):"object"==typeof exports?module.exports=plugin:plugin(root.L)}(window,(function(L){if(L.Hotline)return L;var Hotline=function(canvas){if(!(this instanceof Hotline))return new Hotline(canvas);var defaultPalette={0:"green",.5:"yellow",1:"red"};this._canvas=canvas="string"==typeof canvas?document.getElementById(canvas):canvas,this._ctx=canvas.getContext("2d"),this._width=canvas.width,this._height=canvas.height,this._weight=5,this._outlineWidth=1,this._outlineColor="black",this._min=0,this._max=1,this._data=[],this.palette(defaultPalette)};Hotline.prototype={width:function(width){return this._width=width,this},height:function(height){return this._height=height,this},weight:function(weight){return this._weight=weight,this},outlineWidth:function(outlineWidth){return this._outlineWidth=outlineWidth,this},outlineColor:function(outlineColor){return this._outlineColor=outlineColor,this},palette:function(palette){var canvas=document.createElement("canvas"),ctx=canvas.getContext("2d"),gradient=ctx.createLinearGradient(0,0,0,256);for(var i in canvas.width=1,canvas.height=256,palette)gradient.addColorStop(i,palette[i]);return ctx.fillStyle=gradient,ctx.fillRect(0,0,1,256),this._palette=ctx.getImageData(0,0,1,256).data,this},min:function(min){return this._min=min,this},max:function(max){return this._max=max,this},data:function(data){return this._data=data,this},add:function(path){return this._data.push(path),this},draw:function(){var ctx=this._ctx;return ctx.globalCompositeOperation="source-over",ctx.lineCap="round",this._drawOutline(ctx),this._drawHotline(ctx),this},getRGBForValue:function(value){var valueRelative=Math.min(Math.max((value-this._min)/(this._max-this._min),0),.999),paletteIndex=4*Math.floor(256*valueRelative);return[this._palette[paletteIndex],this._palette[paletteIndex+1],this._palette[paletteIndex+2]]},_drawOutline:function(ctx){var i,j,dataLength,path,pathLength,pointStart,pointEnd;if(this._outlineWidth)for(i=0,dataLength=this._data.length;i<dataLength;i++)for(path=this._data[i],ctx.lineWidth=this._weight+2*this._outlineWidth,j=1,pathLength=path.length;j<pathLength;j++)pointStart=path[j-1],pointEnd=path[j],ctx.strokeStyle=this._outlineColor,ctx.beginPath(),ctx.moveTo(pointStart.x,pointStart.y),ctx.lineTo(pointEnd.x,pointEnd.y),ctx.stroke()},_drawHotline:function(ctx){var i,j,dataLength,path,pathLength,pointStart,pointEnd,gradient,gradientStartRGB,gradientEndRGB;for(ctx.lineWidth=this._weight,i=0,dataLength=this._data.length;i<dataLength;i++)for(j=1,pathLength=(path=this._data[i]).length;j<pathLength;j++)pointStart=path[j-1],pointEnd=path[j],gradient=ctx.createLinearGradient(pointStart.x,pointStart.y,pointEnd.x,pointEnd.y),gradientStartRGB=this.getRGBForValue(pointStart.z),gradientEndRGB=this.getRGBForValue(pointEnd.z),gradient.addColorStop(0,"rgb("+gradientStartRGB.join(",")+")"),gradient.addColorStop(1,"rgb("+gradientEndRGB.join(",")+")"),ctx.strokeStyle=gradient,ctx.beginPath(),ctx.moveTo(pointStart.x,pointStart.y),ctx.lineTo(pointEnd.x,pointEnd.y),ctx.stroke()}};var Renderer=L.Canvas.extend({_initContainer:function(){L.Canvas.prototype._initContainer.call(this),this._hotline=new Hotline(this._container)},_update:function(){L.Canvas.prototype._update.call(this),this._hotline.width(this._container.width),this._hotline.height(this._container.height)},_updatePoly:function(layer){if(this._drawing){var parts=layer._parts;parts.length&&(this._updateOptions(layer),this._hotline.data(parts).draw())}},_updateOptions:function(layer){null!=layer.options.min&&this._hotline.min(layer.options.min),null!=layer.options.max&&this._hotline.max(layer.options.max),null!=layer.options.weight&&this._hotline.weight(layer.options.weight),null!=layer.options.outlineWidth&&this._hotline.outlineWidth(layer.options.outlineWidth),null!=layer.options.outlineColor&&this._hotline.outlineColor(layer.options.outlineColor),layer.options.palette&&this._hotline.palette(layer.options.palette)}}),renderer=function(options){return L.Browser.canvas?new Renderer(options):null},Util={clipSegment:function(a,b,bounds,useLastCode,round){var codeA=useLastCode?this._lastCode:L.LineUtil._getBitCode(a,bounds),codeB=L.LineUtil._getBitCode(b,bounds),codeOut,p,newCode;for(this._lastCode=codeB;;){if(!(codeA|codeB))return[a,b];if(codeA&codeB)return!1;codeOut=codeA||codeB,p=L.LineUtil._getEdgeIntersection(a,b,codeOut,bounds,round),newCode=L.LineUtil._getBitCode(p,bounds),codeOut===codeA?(p.z=a.z,a=p,codeA=newCode):(p.z=b.z,b=p,codeB=newCode)}}};return L.Hotline=L.Polyline.extend({statics:{Renderer:Renderer,renderer:renderer},options:{renderer:renderer(),min:0,max:1,palette:{0:"green",.5:"yellow",1:"red"},weight:5,outlineColor:"black",outlineWidth:1},getRGBForValue:function(value){return this._renderer._hotline.getRGBForValue(value)},_projectLatlngs:function(latlngs,result,projectedBounds){var flat=latlngs[0]instanceof L.LatLng,len=latlngs.length,i,ring;if(flat){for(ring=[],i=0;i<len;i++)ring[i]=this._map.latLngToLayerPoint(latlngs[i]),ring[i].z=latlngs[i].alt,projectedBounds.extend(ring[i]);result.push(ring)}else for(i=0;i<len;i++)this._projectLatlngs(latlngs[i],result,projectedBounds)},_clipPoints:function(){if(this.options.noClip)this._parts=this._rings;else{this._parts=[];var parts=this._parts,bounds=this._renderer._bounds,i,j,k,len,len2,segment,points;for(i=0,k=0,len=this._rings.length;i<len;i++)for(j=0,len2=(points=this._rings[i]).length;j<len2-1;j++)(segment=Util.clipSegment(points[j],points[j+1],bounds,j,!0))&&(parts[k]=parts[k]||[],parts[k].push(segment[0]),segment[1]===points[j+1]&&j!==len2-2||(parts[k].push(segment[1]),k++))}},_clickTolerance:function(){return this.options.weight/2+this.options.outlineWidth+(L.Browser.touch?10:0)}}),L.hotline=function(latlngs,options){return new L.Hotline(latlngs,options)},L}));
\ No newline at end of file +(function(l,d){typeof define=="function"&&define.amd?define(["leaflet"],d):typeof exports=="object"?module.exports=d:d(l.L)})(window,function(l){if(l.Hotline)return l;var d=function(t){if(!(this instanceof d))return new d(t);var i={0:"green",.5:"yellow",1:"red"};this._canvas=t=typeof t=="string"?document.getElementById(t):t,this._ctx=t.getContext("2d"),this._width=t.width,this._height=t.height,this._weight=5,this._outlineWidth=1,this._outlineColor="black",this._min=0,this._max=1,this._data=[],this.palette(i)};d.prototype={width(t){return this._width=t,this},height(t){return this._height=t,this},weight(t){return this._weight=t,this},outlineWidth(t){return this._outlineWidth=t,this},outlineColor(t){return this._outlineColor=t,this},palette(t){var i=document.createElement("canvas"),e=i.getContext("2d"),r=e.createLinearGradient(0,0,0,256);i.width=1,i.height=256;for(var h in t)r.addColorStop(h,t[h]);return e.fillStyle=r,e.fillRect(0,0,1,256),this._palette=e.getImageData(0,0,1,256).data,this},min(t){return this._min=t,this},max(t){return this._max=t,this},data(t){return this._data=t,this},add(t){return this._data.push(t),this},draw(){var t=this._ctx;return t.globalCompositeOperation="source-over",t.lineCap="round",this._drawOutline(t),this._drawHotline(t),this},getRGBForValue(t){var i=this._max===this._min?0:Math.min(Math.max((t-this._min)/(this._max-this._min),0),.999),e=Math.floor(i*256)*4;return[this._palette[e],this._palette[e+1],this._palette[e+2]]},_drawOutline(t){var i,e,r,h,n,o,s;if(this._outlineWidth)for(i=0,r=this._data.length;i<r;i++)for(h=this._data[i],t.lineWidth=this._weight+2*this._outlineWidth,e=1,n=h.length;e<n;e++)o=h[e-1],s=h[e],t.strokeStyle=this._outlineColor,t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(s.x,s.y),t.stroke()},_drawHotline(t){var i,e,r,h,n,o,s,a,_,g;for(t.lineWidth=this._weight,i=0,r=this._data.length;i<r;i++)for(h=this._data[i],e=1,n=h.length;e<n;e++)o=h[e-1],s=h[e],!(!Number.isFinite(o.z)||!Number.isFinite(s.z))&&(a=t.createLinearGradient(o.x,o.y,s.x,s.y),_=this.getRGBForValue(o.z),g=this.getRGBForValue(s.z),a.addColorStop(0,"rgb("+_.join(",")+")"),a.addColorStop(1,"rgb("+g.join(",")+")"),t.strokeStyle=a,t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(s.x,s.y),t.stroke())}};var u=l.Canvas.extend({_initContainer(){l.Canvas.prototype._initContainer.call(this),this._hotline=new d(this._container)},_update(){l.Canvas.prototype._update.call(this),this._hotline.width(this._container.width),this._hotline.height(this._container.height)},_updatePoly(t){if(this._drawing){var i=t._parts;i.length&&(this._updateOptions(t),this._hotline.data(i).draw())}},_updateOptions(t){t.options.min!=null&&this._hotline.min(t.options.min),t.options.max!=null&&this._hotline.max(t.options.max),t.options.weight!=null&&this._hotline.weight(t.options.weight),t.options.outlineWidth!=null&&this._hotline.outlineWidth(t.options.outlineWidth),t.options.outlineColor!=null&&this._hotline.outlineColor(t.options.outlineColor),t.options.palette&&this._hotline.palette(t.options.palette)}}),p=function(t){return document.createElement("canvas").getContext?new u(t):null},f={clipSegment(t,i,e,r,h){var n=r?this._lastCode:l.LineUtil._getBitCode(t,e),o=l.LineUtil._getBitCode(i,e),s,a,_;for(this._lastCode=o;;)if(n|o){if(n&o)return!1;s=n||o,a=l.LineUtil._getEdgeIntersection(t,i,s,e,h),_=l.LineUtil._getBitCode(a,e),s===n?(a.z=t.z,t=a,n=_):(a.z=i.z,i=a,o=_)}else return[t,i]}};return l.Hotline=l.Polyline.extend({statics:{Renderer:u,renderer:p},options:{renderer:p(),min:0,max:1,palette:{0:"green",.5:"yellow",1:"red"},weight:5,outlineColor:"black",outlineWidth:1},getRGBForValue(t){return this._renderer._hotline.getRGBForValue(t)},_projectLatlngs(t,i,e){var r=t[0]instanceof l.LatLng,h=t.length,n,o;if(r){for(o=[],n=0;n<h;n++)o[n]=this._map.latLngToLayerPoint(t[n]),o[n].z=t[n].alt,e.extend(o[n]);i.push(o)}else for(n=0;n<h;n++)this._projectLatlngs(t[n],i,e)},_clipPoints(){if(this.options.noClip){this._parts=this._rings;return}this._parts=[];var t=this._parts,i=this._renderer._bounds,e,r,h,n,o,s,a;for(e=0,h=0,n=this._rings.length;e<n;e++)for(a=this._rings[e],r=0,o=a.length;r<o-1;r++)s=f.clipSegment(a[r],a[r+1],i,r,!0),s&&(t[h]=t[h]||[],t[h].push(s[0]),(s[1]!==a[r+1]||r===o-2)&&(t[h].push(s[1]),h++))},_clickTolerance(){return this.options.weight/2+this.options.outlineWidth+(l.Browser.touch?10:0)}}),l.hotline=function(t,i){return new l.Hotline(t,i)},l}); diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.css b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.css index e59d69b..e83f4c1 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.css +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.css @@ -1,42 +1,42 @@ -.leaflet-ruler {
- height: 35px;
- width: 35px;
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAACx0lEQVRIS52VWahOURTHXRSJzBkiJcpYxgeS4oUi90GR4VK6DzcUD3gQIQ8UCXkwlCJRkjJEpqT7oGTMeHONmacyRRl/v9ve2n2d7/vOtevXPmefff5r7bXXXruiSf42gKkToTu0hY/wEk7CnWIyFWX0B/N9OkyF1tANdsEz6AIL4Sl8h8NwEK6nmsUMNGPSalgePFxLfwl2hrG39O1hM8yFobAKpsAGWAE/NJRloBfj++ErnIYesDj1qsjzRsYN2VhwdTPgUaGBkUF0e/D0TxDrRD8ehsFw6AcP4FrgCL17EpsrWAKDUgNtwuQP9FehJsyeSb8FbsOV8O0efVeYHOZV0h8N8w3dWXBOVWpgDwO/oBqc1BxciV7Pg3OJhz66ivPB+PoM8TnqRQPTeNkKfeALtAQ39QYsgE85xNsFz+voFe8AldFALS8DYU3waAd9b5gAv3OKn2HefagK4q64VgPm9k0we0wtN9pN6w+mY9qywqLnWeKXGa/WwHwYFSwrZtw/w9Ic4p5oxesLPG8Qd/UacMf13IE38ArGwN3EQJbnintOHsJsMOaG5Z+4/2vAY282eALd4FvQqoj4Aca3gQfPw1hSPBr4xoNH3bz1EO0D428r9LwpY3vB+nSolOfRQVeg1yOCgXH01pu+GeL+Y1hOwWOYBZlhieJxBU94eA2Lwo9WRw+X8fUEx0PUaPFowKW6Cg+UBc6M6AzrMsR1xtJR1vO4CkNk1TMLJoXBlcHQpvAePW+0eFyBRe45jAbL7fskhqm4MbdGmYruUU94l8zNfIyl4hhfLQteHqaiLYq7J4YlipvnXkgWRotgyRYNWB4st6bpizLiHsiO4H1gMrhnRVtarpcxy0vd+9eLPMvzhuMf1E7QmyC78xrQmDk+BC6Am98CLoKXi/dvWll1xjvjeAkD9YVXpkJ6ae7/BOPus4b+p9X9BdB/zv8zawwXAAAAAElFTkSuQmCC"); /* <div>Icons made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div> */
- background-repeat: no-repeat;
- background-position: center;
-}
-.leaflet-ruler-clicked,
-.leaflet-ruler:hover {
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAE/ElEQVRIS6WVeWwUVRzHfzOzs7Pdi+7Rdq/ubrH0sNaKBFMCSEvBQLivFkhAE8GDYAyHATWgETUoMZ7BGCMBNKYiQbTKpYQKBqKlWmBbadmW7bbbFjv0mu2eM298M5SlpS3U+LL/zL6Zz/f7vr/3e4+AsQ6j80EgxTkKhGwkQRqQiLp5UtEOSDwOXf660TDEPfkGR75RTT8VF1EpJRJ6LsbrVuaZg2YtrWND8WD5FVajV9IcTyCOoYhv2QgcgE5fzWDmaAKU0eHa3RMStszNMqIdM+zUY3YdPFvRCG+VOCFFQ0N3mIfNJ3ywb3Em/BHgYNeZFnTc20OOU1Efd7eZtwBUxyWh4QLJGS6jFv04MU2bNWeCQRnoi8L7czPuG+RLJ31g0Smhsqk3dqGVa7wZZOZBb/31oQKm8ZMZRbxyU6FV9XaJmyQGZsNxBD/Ud8FXNWy/rzci9ER4Spqa5tYrit3jmNI8M2DnCRNvnm1Bu35tjcR4lH1HIDtbp+2NNuSmqCyTrBr4dMEDuH4A754LCLvOtQo44zouKp7hQagGIK+CIFgoipqPEHru6OocWJhtlAWk6GZ8cSXs64sd49qbSxMCaenu7+ZkGuftW5JJSy/FBARlh+vDF1tDfWEerYWullNDcjK5c9Q0Or/jcad++3SbbP8ueBn+S7glkOIsNTDUQf+mRxmtkoIIj6Bgb024hYtVhGPK9dDl7RsJvhPDtw3AcWzYuSd8vTcqOS8DrcUIKsUiWcDgyKghRLFgZ1E6vFhohfXfN8YP1bFVfW3N0/E0Ggu8CMNxfY9z7b5SCU4o6dMkhc4RYM61aulwU8fWSSqaIqEqEIRZBzzBSCg+HoIdncPglHgBG9ENdj4inEAXhZuBdQSYXBuWZOnfOLI61yTB1ld4Y1/+xe6Ndvo33Q+ON5Rc0GHOB+DS6gmF2XF6dkZy0eeLM8lU3EDGd6qiQRAnQnvz3wkBXFANdr5jkHMJXrS/NtTIRk5yN3wrErEMgsuNpkp13ViRZ0zdOtUOWiUJ2R/WxPibfmYk+Mp8E/XCT01y4y0/1HBfuCygMDljVzYW0DnmJKhuC8Lsg7WB7kCzQxa4y7nUF08euQblHlZMoqij93J+2yBBpzgjlzcUMJLAmeu9sOjrq+1cR7PtNvzVYrv+5WkOUvpAiqUYx+JlI6cwfPlosQyuHcGYnYECq9r2AV62O5mB9PcuItxjj2ho6uz/hcsRESbH4TX5qQv3LsigNbjJ7Huq+tkIT75enM4Mdx76mbvhXzYW54mIwOBeNd2l+eTs03nyYYIPqrhaSVGbC213xfLf4fIKAB9yqp4IW/VMvtKqVYJJrUhEeCdzGS5lbki22Wu5btYg0IwV2hrYIb0ywoN8VCTbXadDUTRz/9IJsCrfLL82CP7LQCyGcVab56HColQkCKL3ctWxTs/5+WMSAHwPGBih0rNxotqGL42R4DqLpebhKTNta7fvgWBfN7yybIoQjYdzoLPVey+RxHFtdrhfy05J2laxKjep5EAd3oqhhHNtqrm6YOoT6RKcIOXSwEdb1ojXLv35fDRQ99mYBKR6GOyu3zBhcowXTvR3+JdCWhqjVhk9FEW7Z5Wtw1vuFlwatb9XQmuD51J/MFQ+qgAheIdemSl5FoDgOuhs3o0/4vWOKcZkh/4bEJFKxAMA/6QhgsjzAvrH3+SXn0YZAinU/wuTosgK53+p+wAAAABJRU5ErkJggg=="); /* <div>Icons made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div> */
-}
-.leaflet-ruler-clicked {
- height: 35px;
- width: 35px;
- background-repeat: no-repeat;
- background-position: center;
- border-color: chartreuse !important;
-}
-.leaflet-bar.leaflet-ruler {
- background-color: #ffffff;
-}
-.leaflet-control.leaflet-ruler {
- cursor: pointer;
-}
-.result-tooltip {
- background-color: white;
- border-width: medium;
- border-color: #de0000;
- font-size: smaller;
-}
-.moving-tooltip {
- background-color: rgba(255, 255, 255, .7);
- background-clip: padding-box;
- opacity: 0.5;
- border: dotted;
- border-color: red;
- font-size: smaller;
-}
-.plus-length {
- padding-left: 45px;
-}
+.leaflet-ruler { + height: 35px; + width: 35px; + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAACx0lEQVRIS52VWahOURTHXRSJzBkiJcpYxgeS4oUi90GR4VK6DzcUD3gQIQ8UCXkwlCJRkjJEpqT7oGTMeHONmacyRRl/v9ve2n2d7/vOtevXPmefff5r7bXXXruiSf42gKkToTu0hY/wEk7CnWIyFWX0B/N9OkyF1tANdsEz6AIL4Sl8h8NwEK6nmsUMNGPSalgePFxLfwl2hrG39O1hM8yFobAKpsAGWAE/NJRloBfj++ErnIYesDj1qsjzRsYN2VhwdTPgUaGBkUF0e/D0TxDrRD8ehsFw6AcP4FrgCL17EpsrWAKDUgNtwuQP9FehJsyeSb8FbsOV8O0efVeYHOZV0h8N8w3dWXBOVWpgDwO/oBqc1BxciV7Pg3OJhz66ivPB+PoM8TnqRQPTeNkKfeALtAQ39QYsgE85xNsFz+voFe8AldFALS8DYU3waAd9b5gAv3OKn2HefagK4q64VgPm9k0we0wtN9pN6w+mY9qywqLnWeKXGa/WwHwYFSwrZtw/w9Ic4p5oxesLPG8Qd/UacMf13IE38ArGwN3EQJbnintOHsJsMOaG5Z+4/2vAY282eALd4FvQqoj4Aca3gQfPw1hSPBr4xoNH3bz1EO0D428r9LwpY3vB+nSolOfRQVeg1yOCgXH01pu+GeL+Y1hOwWOYBZlhieJxBU94eA2Lwo9WRw+X8fUEx0PUaPFowKW6Cg+UBc6M6AzrMsR1xtJR1vO4CkNk1TMLJoXBlcHQpvAePW+0eFyBRe45jAbL7fskhqm4MbdGmYruUU94l8zNfIyl4hhfLQteHqaiLYq7J4YlipvnXkgWRotgyRYNWB4st6bpizLiHsiO4H1gMrhnRVtarpcxy0vd+9eLPMvzhuMf1E7QmyC78xrQmDk+BC6Am98CLoKXi/dvWll1xjvjeAkD9YVXpkJ6ae7/BOPus4b+p9X9BdB/zv8zawwXAAAAAElFTkSuQmCC"); /* <div>Icons made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div> */ + background-repeat: no-repeat; + background-position: center; +} +.leaflet-ruler-clicked, +.leaflet-ruler:hover { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAE/ElEQVRIS6WVeWwUVRzHfzOzs7Pdi+7Rdq/ubrH0sNaKBFMCSEvBQLivFkhAE8GDYAyHATWgETUoMZ7BGCMBNKYiQbTKpYQKBqKlWmBbadmW7bbbFjv0mu2eM298M5SlpS3U+LL/zL6Zz/f7vr/3e4+AsQ6j80EgxTkKhGwkQRqQiLp5UtEOSDwOXf660TDEPfkGR75RTT8VF1EpJRJ6LsbrVuaZg2YtrWND8WD5FVajV9IcTyCOoYhv2QgcgE5fzWDmaAKU0eHa3RMStszNMqIdM+zUY3YdPFvRCG+VOCFFQ0N3mIfNJ3ywb3Em/BHgYNeZFnTc20OOU1Efd7eZtwBUxyWh4QLJGS6jFv04MU2bNWeCQRnoi8L7czPuG+RLJ31g0Smhsqk3dqGVa7wZZOZBb/31oQKm8ZMZRbxyU6FV9XaJmyQGZsNxBD/Ud8FXNWy/rzci9ER4Spqa5tYrit3jmNI8M2DnCRNvnm1Bu35tjcR4lH1HIDtbp+2NNuSmqCyTrBr4dMEDuH4A754LCLvOtQo44zouKp7hQagGIK+CIFgoipqPEHru6OocWJhtlAWk6GZ8cSXs64sd49qbSxMCaenu7+ZkGuftW5JJSy/FBARlh+vDF1tDfWEerYWullNDcjK5c9Q0Or/jcad++3SbbP8ueBn+S7glkOIsNTDUQf+mRxmtkoIIj6Bgb024hYtVhGPK9dDl7RsJvhPDtw3AcWzYuSd8vTcqOS8DrcUIKsUiWcDgyKghRLFgZ1E6vFhohfXfN8YP1bFVfW3N0/E0Ggu8CMNxfY9z7b5SCU4o6dMkhc4RYM61aulwU8fWSSqaIqEqEIRZBzzBSCg+HoIdncPglHgBG9ENdj4inEAXhZuBdQSYXBuWZOnfOLI61yTB1ld4Y1/+xe6Ndvo33Q+ON5Rc0GHOB+DS6gmF2XF6dkZy0eeLM8lU3EDGd6qiQRAnQnvz3wkBXFANdr5jkHMJXrS/NtTIRk5yN3wrErEMgsuNpkp13ViRZ0zdOtUOWiUJ2R/WxPibfmYk+Mp8E/XCT01y4y0/1HBfuCygMDljVzYW0DnmJKhuC8Lsg7WB7kCzQxa4y7nUF08euQblHlZMoqij93J+2yBBpzgjlzcUMJLAmeu9sOjrq+1cR7PtNvzVYrv+5WkOUvpAiqUYx+JlI6cwfPlosQyuHcGYnYECq9r2AV62O5mB9PcuItxjj2ho6uz/hcsRESbH4TX5qQv3LsigNbjJ7Huq+tkIT75enM4Mdx76mbvhXzYW54mIwOBeNd2l+eTs03nyYYIPqrhaSVGbC213xfLf4fIKAB9yqp4IW/VMvtKqVYJJrUhEeCdzGS5lbki22Wu5btYg0IwV2hrYIb0ywoN8VCTbXadDUTRz/9IJsCrfLL82CP7LQCyGcVab56HColQkCKL3ctWxTs/5+WMSAHwPGBih0rNxotqGL42R4DqLpebhKTNta7fvgWBfN7yybIoQjYdzoLPVey+RxHFtdrhfy05J2laxKjep5EAd3oqhhHNtqrm6YOoT6RKcIOXSwEdb1ojXLv35fDRQ99mYBKR6GOyu3zBhcowXTvR3+JdCWhqjVhk9FEW7Z5Wtw1vuFlwatb9XQmuD51J/MFQ+qgAheIdemSl5FoDgOuhs3o0/4vWOKcZkh/4bEJFKxAMA/6QhgsjzAvrH3+SXn0YZAinU/wuTosgK53+p+wAAAABJRU5ErkJggg=="); /* <div>Icons made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div> */ +} +.leaflet-ruler-clicked { + height: 35px; + width: 35px; + background-repeat: no-repeat; + background-position: center; + border-color: chartreuse !important; +} +.leaflet-bar.leaflet-ruler { + background-color: #ffffff; +} +.leaflet-control.leaflet-ruler { + cursor: pointer; +} +.result-tooltip { + background-color: white; + border-width: medium; + border-color: #de0000; + font-size: smaller; +} +.moving-tooltip { + background-color: rgba(255, 255, 255, .7); + background-clip: padding-box; + opacity: 0.5; + border: dotted; + border-color: red; + font-size: smaller; +} +.plus-length { + padding-left: 45px; +}
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.js index 847f9b8..9435815 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.js @@ -1,183 +1,186 @@ -/*
- * Copyright (c) 2022, GPL-3.0+ Project, Raruto
- *
- * This file is free software: you may copy, redistribute and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 2 of the License, or (at your
- * option) any later version.
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * This file incorporates work covered by the following copyright and
- * permission notice:
- *
- * Copyright (c) 2017 Goker Tanrisever
- *
- * Permission to use, copy, modify, and/or distribute this software
- * for any purpose with or without fee is hereby granted, provided
- * that the above copyright notice and this permission notice appear
- * in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-L.Control.Ruler = L.Control.extend({
- options: {
- position: 'topright',
- circleMarker: {
- color: 'red',
- radius: 2,
- },
- lineStyle: {
- color: 'red',
- dashArray: '1,6'
- },
- lengthUnit: {
- display: 'km',
- decimal: 2,
- factor: 0.001, // meters -> kilometers
- label: 'Distance:'
- },
- angleUnit: {
- display: '°',
- decimal: 2,
- factor: 360,
- label: 'Bearing:'
- }
- },
- initialize: function (options) {
- L.setOptions(this, options);
- this._layers = L.layerGroup();
- this._enabled = false;
- },
- onAdd: function (map) {
- this._defaultCursor = map._container.style.cursor;
- this._map = map;
- let container = L.DomUtil.create('div', 'leaflet-bar');
- container.classList.add('leaflet-ruler');
- L.DomEvent.disableClickPropagation(container);
- L.DomEvent.on(container, 'click', this._toggleMeasure, this);
- return this._container = container;
- },
- onRemove: function () {
- L.DomEvent.off(this._container, 'click', this._toggleMeasure, this);
- },
- _attachMouseEvents: function () {
- let map = this._map;
- map.doubleClickZoom.disable();
- L.DomEvent.on(map._container, 'keydown', this._escape, this);
- L.DomEvent.on(map._container, 'dblclick', this._closePath, this);
- map._container.style.cursor = 'crosshair';
- map.on('click', this._addPoint, this);
- map.on('mousemove', this._moving, this);
- },
- _removeMouseEvents: function () {
- let map = this._map;
- map.doubleClickZoom.enable();
- L.DomEvent.off(map._container, 'keydown', this._escape, this);
- L.DomEvent.off(map._container, 'dblclick', this._closePath, this);
- map._container.style.cursor = this._defaultCursor;
- map.off('click', this._addPoint, this);
- map.off('mousemove', this._moving, this);
- },
- _disable: function () {
- this._enabled = false;
- this._container.classList.remove("leaflet-ruler-clicked");
- this._layers.remove().clearLayers();
- this._latlngs = [];
- this._totalLength = 0;
- this._removeMouseEvents();
- },
- _enable: function () {
- this._enabled = true;
- this._container.classList.add("leaflet-ruler-clicked");
- this._circles = L.featureGroup().addTo(this._layers);
- this._polyline = L.polyline([], this.options.lineStyle).addTo(this._layers);
- this._layers.addTo(this._map);
- this._latlngs = [];
- this._totalLength = 0;
- this._attachMouseEvents();
- },
- _toggleMeasure: function () {
- this._enabled ? this._disable() : this._enable();
- },
- _drawTooltip: function (latlng, layer, incremental) {
- let lastClick = this._latlngs[this._latlngs.length - 1] ?? latlng;
- let bearing = this._calculateBearing(lastClick, latlng);
- let distance = lastClick.distanceTo(latlng) * this.options.lengthUnit.factor;
- let accumulated = this._totalLength + distance;
- let totalLength = accumulated.toFixed(this.options.lengthUnit.decimal);
- let plusLength = incremental ? '<br><div class="plus-length">(+' + distance.toFixed(this.options.lengthUnit.decimal) + ')</div>' : '';
- this._totalLength = incremental ? this._totalLength : accumulated;
- if (!layer.getTooltip()) layer.bindTooltip('', incremental ? { direction: "auto", sticky: true, offset: L.point(0, -40), className: 'moving-tooltip' } : { permanent: true, className: 'result-tooltip' }).openTooltip();
- layer.setLatLng(latlng).setTooltipContent('<b>' + this.options.angleUnit.label + '</b> ' + bearing.toFixed(this.options.angleUnit.decimal) + ' ' + this.options.angleUnit.display + '<br><b>' + this.options.lengthUnit.label + '</b> ' + totalLength + ' ' + this.options.lengthUnit.display + plusLength);
- },
- _addPoint: function (e) {
- let latlng = e.latlng || e;
- let point = L.circleMarker(latlng, this.options.circleMarker).addTo(this._circles);
- this._polyline.addLatLng(latlng);
- if(this._latlngs.length && !latlng.equals(this._latlngs[this._latlngs.length - 1])){
- this._drawTooltip(latlng, point, false);
- }
- this._latlngs.push(latlng);
- },
- _moving: function (e) {
- if (this._latlngs.length) {
- let lastCLick = this._latlngs[this._latlngs.length - 1];
- if (!this._tempLine) this._tempLine = L.polyline([], this.options.lineStyle).addTo(this._map);
- if (!this._tempPoint) this._tempPoint = L.circleMarker(e.latlng, this.options.circleMarker).addTo(this._map);
- this._tempLine.setLatLngs([lastCLick, e.latlng]);
- this._drawTooltip(e.latlng, this._tempPoint, true);
- L.DomEvent.off(this._container, 'click', this._toggleMeasure, this);
- }
- },
- _escape: function (e) {
- if (e.keyCode === 27) {
- if (this._latlngs.length) {
- this._closePath();
- } else {
- this._enabled = true;
- this._toggleMeasure();
- }
- }
- },
- _calculateBearing: function (start, end) {
- const toRad = L.DomUtil.DEG_TO_RAD;
- const toDeg = (this.options.angleUnit.factor / 2) / Math.PI;
- let y = Math.sin((end.lng - start.lng) * toRad) * Math.cos(end.lat * toRad);
- let x = Math.cos(start.lat * toRad) * Math.sin(end.lat * toRad) - Math.sin(start.lat * toRad) * Math.cos(end.lat * toRad) * Math.cos((end.lng - start.lng) * toRad);
- return (Math.atan2(y, x) * toDeg + this.options.angleUnit.factor) % this.options.angleUnit.factor;
- },
- _closePath: function () {
- if (this._tempLine) {
- this._tempLine.remove();
- this._tempLine = null;
- }
- if (this._tempPoint) {
- this._tempPoint.remove();
- this._tempLine = null;
- }
- if (this._latlngs.length <= 1) {
- this._circles.remove();
- }
- this._enabled = false;
- L.DomEvent.on(this._container, 'click', this._toggleMeasure, this);
- this._toggleMeasure();
- },
-});
-L.control.ruler = function (options) {
- return new L.Control.Ruler(options);
+/* + * Copyright (c) 2022, GPL-3.0+ Project, Raruto + * + * This file is free software: you may copy, redistribute and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 2 of the License, or (at your + * option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (c) 2017 Goker Tanrisever + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose with or without fee is hereby granted, provided + * that the above copyright notice and this permission notice appear + * in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +L.Control.Ruler = L.Control.extend({ + options: { + position: 'topright', + circleMarker: { + color: 'red', + radius: 2, + }, + lineStyle: { + color: 'red', + dashArray: '1,6' + }, + lengthUnit: { + display: 'km', + decimal: 2, + factor: 0.001, // meters -> kilometers + label: 'Distance:' + }, + angleUnit: { + display: '°', + decimal: 2, + factor: 360, + label: 'Bearing:' + } + }, + initialize(options) { + L.Util.setOptions(this, options); + this._layers = new L.LayerGroup(); + this._enabled = false; + }, + onAdd(map) { + this._defaultCursor = map._container.style.cursor; + this._map = map; + let container = L.DomUtil.create('div', 'leaflet-bar'); + container.classList.add('leaflet-ruler'); + L.DomEvent.disableClickPropagation(container); + L.DomEvent.on(container, 'click', this._toggleMeasure, this); + return this._container = container; + }, + onRemove() { + L.DomEvent.off(this._container, 'click', this._toggleMeasure, this); + }, + _attachMouseEvents() { + let map = this._map; + map.doubleClickZoom.disable(); + L.DomEvent.on(map._container, 'keydown', this._escape, this); + L.DomEvent.on(map._container, 'dblclick', this._closePath, this); + map._container.style.cursor = 'crosshair'; + map.on('click', this._addPoint, this); + map.on(L.version.startsWith('2') ? 'pointermove' : 'mousemove', this._moving, this); + }, + _removeMouseEvents() { + let map = this._map; + map.doubleClickZoom.enable(); + L.DomEvent.off(map._container, 'keydown', this._escape, this); + L.DomEvent.off(map._container, 'dblclick', this._closePath, this); + map._container.style.cursor = this._defaultCursor; + map.off('click', this._addPoint, this); + map.off(L.version.startsWith('2') ? 'pointermove' : 'mousemove', this._moving, this); + }, + _disable() { + this._enabled = false; + this._container.classList.remove("leaflet-ruler-clicked"); + this._layers.remove().clearLayers(); + this._latlngs = []; + this._totalLength = 0; + this._removeMouseEvents(); + }, + _enable() { + this._enabled = true; + this._container.classList.add("leaflet-ruler-clicked"); + this._circles = new L.FeatureGroup().addTo(this._layers); + this._polyline = new L.Polyline([], this.options.lineStyle).addTo(this._layers); + this._layers.addTo(this._map); + this._latlngs = []; + this._totalLength = 0; + this._attachMouseEvents(); + }, + _toggleMeasure() { + this._enabled ? this._disable() : this._enable(); + }, + _drawTooltip(latlng, layer, incremental) { + let lastClick = this._latlngs[this._latlngs.length - 1] ?? latlng; + let bearing = this._calculateBearing(lastClick, latlng); + let distance = lastClick.distanceTo(latlng) * this.options.lengthUnit.factor; + let accumulated = this._totalLength + distance; + let totalLength = accumulated.toFixed(this.options.lengthUnit.decimal); + let plusLength = incremental ? '<br><div class="plus-length">(+' + distance.toFixed(this.options.lengthUnit.decimal) + ')</div>' : ''; + this._totalLength = incremental ? this._totalLength : accumulated; + if (!layer.getTooltip()) layer.bindTooltip('', incremental ? { direction: "auto", sticky: true, offset: new L.Point(0, -40), className: 'moving-tooltip' } : { permanent: true, className: 'result-tooltip' }).openTooltip(); + layer.setLatLng(latlng).setTooltipContent('<b>' + this.options.angleUnit.label + '</b> ' + bearing.toFixed(this.options.angleUnit.decimal) + ' ' + this.options.angleUnit.display + '<br><b>' + this.options.lengthUnit.label + '</b> ' + totalLength + ' ' + this.options.lengthUnit.display + plusLength); + }, + _addPoint(e) { + let latlng = e.latlng || e; + let point = new L.CircleMarker(latlng, this.options.circleMarker).addTo(this._circles); + this._polyline.addLatLng(latlng); + if(this._latlngs.length && !latlng.equals(this._latlngs[this._latlngs.length - 1])){ + this._drawTooltip(latlng, point, false); + } + this._latlngs.push(latlng); + }, + _moving(e) { + if (this._latlngs.length) { + let lastCLick = this._latlngs[this._latlngs.length - 1]; + if (!this._tempLine) this._tempLine = new L.Polyline([], this.options.lineStyle).addTo(this._map); + if (!this._tempPoint) this._tempPoint = new L.CircleMarker(e.latlng, this.options.circleMarker).addTo(this._map); + this._tempLine.setLatLngs([lastCLick, e.latlng]); + this._drawTooltip(e.latlng, this._tempPoint, true); + L.DomEvent.off(this._container, 'click', this._toggleMeasure, this); + } + }, + _escape(e) { + if (e.keyCode === 27) { + if (this._latlngs.length) { + this._closePath(); + } else { + this._enabled = true; + this._toggleMeasure(); + } + } + }, + _calculateBearing(start, end) { + const toRad = Math.PI / 180; + const toDeg = (this.options.angleUnit.factor / 2) / Math.PI; + let y = Math.sin((end.lng - start.lng) * toRad) * Math.cos(end.lat * toRad); + let x = Math.cos(start.lat * toRad) * Math.sin(end.lat * toRad) - Math.sin(start.lat * toRad) * Math.cos(end.lat * toRad) * Math.cos((end.lng - start.lng) * toRad); + return (Math.atan2(y, x) * toDeg + this.options.angleUnit.factor) % this.options.angleUnit.factor; + }, + _closePath() { + if (this._tempLine) { + this._tempLine.remove(); + this._tempLine = null; + } + if (this._tempPoint) { + this._tempPoint.remove(); + this._tempLine = null; + } + if (this._latlngs.length <= 1) { + this._circles.remove(); + } + this._enabled = false; + L.DomEvent.on(this._container, 'click', this._toggleMeasure, this); + this._toggleMeasure(); + }, +}); + +// backcomps for leaflet v1 +L.control = L.control || {}; +L.control.ruler = function (options) { + return new L.Control.Ruler(options); };
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.css b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.css index 9532825..045425e 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.css +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.css @@ -1 +1 @@ -.leaflet-ruler{height:35px;width:35px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAACx0lEQVRIS52VWahOURTHXRSJzBkiJcpYxgeS4oUi90GR4VK6DzcUD3gQIQ8UCXkwlCJRkjJEpqT7oGTMeHONmacyRRl/v9ve2n2d7/vOtevXPmefff5r7bXXXruiSf42gKkToTu0hY/wEk7CnWIyFWX0B/N9OkyF1tANdsEz6AIL4Sl8h8NwEK6nmsUMNGPSalgePFxLfwl2hrG39O1hM8yFobAKpsAGWAE/NJRloBfj++ErnIYesDj1qsjzRsYN2VhwdTPgUaGBkUF0e/D0TxDrRD8ehsFw6AcP4FrgCL17EpsrWAKDUgNtwuQP9FehJsyeSb8FbsOV8O0efVeYHOZV0h8N8w3dWXBOVWpgDwO/oBqc1BxciV7Pg3OJhz66ivPB+PoM8TnqRQPTeNkKfeALtAQ39QYsgE85xNsFz+voFe8AldFALS8DYU3waAd9b5gAv3OKn2HefagK4q64VgPm9k0we0wtN9pN6w+mY9qywqLnWeKXGa/WwHwYFSwrZtw/w9Ic4p5oxesLPG8Qd/UacMf13IE38ArGwN3EQJbnintOHsJsMOaG5Z+4/2vAY282eALd4FvQqoj4Aca3gQfPw1hSPBr4xoNH3bz1EO0D428r9LwpY3vB+nSolOfRQVeg1yOCgXH01pu+GeL+Y1hOwWOYBZlhieJxBU94eA2Lwo9WRw+X8fUEx0PUaPFowKW6Cg+UBc6M6AzrMsR1xtJR1vO4CkNk1TMLJoXBlcHQpvAePW+0eFyBRe45jAbL7fskhqm4MbdGmYruUU94l8zNfIyl4hhfLQteHqaiLYq7J4YlipvnXkgWRotgyRYNWB4st6bpizLiHsiO4H1gMrhnRVtarpcxy0vd+9eLPMvzhuMf1E7QmyC78xrQmDk+BC6Am98CLoKXi/dvWll1xjvjeAkD9YVXpkJ6ae7/BOPus4b+p9X9BdB/zv8zawwXAAAAAElFTkSuQmCC);background-repeat:no-repeat;background-position:center}.leaflet-ruler-clicked,.leaflet-ruler:hover{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAE/ElEQVRIS6WVeWwUVRzHfzOzs7Pdi+7Rdq/ubrH0sNaKBFMCSEvBQLivFkhAE8GDYAyHATWgETUoMZ7BGCMBNKYiQbTKpYQKBqKlWmBbadmW7bbbFjv0mu2eM298M5SlpS3U+LL/zL6Zz/f7vr/3e4+AsQ6j80EgxTkKhGwkQRqQiLp5UtEOSDwOXf660TDEPfkGR75RTT8VF1EpJRJ6LsbrVuaZg2YtrWND8WD5FVajV9IcTyCOoYhv2QgcgE5fzWDmaAKU0eHa3RMStszNMqIdM+zUY3YdPFvRCG+VOCFFQ0N3mIfNJ3ywb3Em/BHgYNeZFnTc20OOU1Efd7eZtwBUxyWh4QLJGS6jFv04MU2bNWeCQRnoi8L7czPuG+RLJ31g0Smhsqk3dqGVa7wZZOZBb/31oQKm8ZMZRbxyU6FV9XaJmyQGZsNxBD/Ud8FXNWy/rzci9ER4Spqa5tYrit3jmNI8M2DnCRNvnm1Bu35tjcR4lH1HIDtbp+2NNuSmqCyTrBr4dMEDuH4A754LCLvOtQo44zouKp7hQagGIK+CIFgoipqPEHru6OocWJhtlAWk6GZ8cSXs64sd49qbSxMCaenu7+ZkGuftW5JJSy/FBARlh+vDF1tDfWEerYWullNDcjK5c9Q0Or/jcad++3SbbP8ueBn+S7glkOIsNTDUQf+mRxmtkoIIj6Bgb024hYtVhGPK9dDl7RsJvhPDtw3AcWzYuSd8vTcqOS8DrcUIKsUiWcDgyKghRLFgZ1E6vFhohfXfN8YP1bFVfW3N0/E0Ggu8CMNxfY9z7b5SCU4o6dMkhc4RYM61aulwU8fWSSqaIqEqEIRZBzzBSCg+HoIdncPglHgBG9ENdj4inEAXhZuBdQSYXBuWZOnfOLI61yTB1ld4Y1/+xe6Ndvo33Q+ON5Rc0GHOB+DS6gmF2XF6dkZy0eeLM8lU3EDGd6qiQRAnQnvz3wkBXFANdr5jkHMJXrS/NtTIRk5yN3wrErEMgsuNpkp13ViRZ0zdOtUOWiUJ2R/WxPibfmYk+Mp8E/XCT01y4y0/1HBfuCygMDljVzYW0DnmJKhuC8Lsg7WB7kCzQxa4y7nUF08euQblHlZMoqij93J+2yBBpzgjlzcUMJLAmeu9sOjrq+1cR7PtNvzVYrv+5WkOUvpAiqUYx+JlI6cwfPlosQyuHcGYnYECq9r2AV62O5mB9PcuItxjj2ho6uz/hcsRESbH4TX5qQv3LsigNbjJ7Huq+tkIT75enM4Mdx76mbvhXzYW54mIwOBeNd2l+eTs03nyYYIPqrhaSVGbC213xfLf4fIKAB9yqp4IW/VMvtKqVYJJrUhEeCdzGS5lbki22Wu5btYg0IwV2hrYIb0ywoN8VCTbXadDUTRz/9IJsCrfLL82CP7LQCyGcVab56HColQkCKL3ctWxTs/5+WMSAHwPGBih0rNxotqGL42R4DqLpebhKTNta7fvgWBfN7yybIoQjYdzoLPVey+RxHFtdrhfy05J2laxKjep5EAd3oqhhHNtqrm6YOoT6RKcIOXSwEdb1ojXLv35fDRQ99mYBKR6GOyu3zBhcowXTvR3+JdCWhqjVhk9FEW7Z5Wtw1vuFlwatb9XQmuD51J/MFQ+qgAheIdemSl5FoDgOuhs3o0/4vWOKcZkh/4bEJFKxAMA/6QhgsjzAvrH3+SXn0YZAinU/wuTosgK53+p+wAAAABJRU5ErkJggg==)}.leaflet-ruler-clicked{height:35px;width:35px;background-repeat:no-repeat;background-position:center;border-color:#7fff00!important}.leaflet-bar.leaflet-ruler{background-color:#fff}.leaflet-control.leaflet-ruler{cursor:pointer}.result-tooltip{background-color:#fff;border-width:medium;border-color:#de0000;font-size:smaller}.moving-tooltip{background-color:rgba(255,255,255,.7);background-clip:padding-box;opacity:.5;border:dotted;border-color:red;font-size:smaller}.plus-length{padding-left:45px}
\ No newline at end of file +.leaflet-ruler{height:35px;width:35px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAACx0lEQVRIS52VWahOURTHXRSJzBkiJcpYxgeS4oUi90GR4VK6DzcUD3gQIQ8UCXkwlCJRkjJEpqT7oGTMeHONmacyRRl/v9ve2n2d7/vOtevXPmefff5r7bXXXruiSf42gKkToTu0hY/wEk7CnWIyFWX0B/N9OkyF1tANdsEz6AIL4Sl8h8NwEK6nmsUMNGPSalgePFxLfwl2hrG39O1hM8yFobAKpsAGWAE/NJRloBfj++ErnIYesDj1qsjzRsYN2VhwdTPgUaGBkUF0e/D0TxDrRD8ehsFw6AcP4FrgCL17EpsrWAKDUgNtwuQP9FehJsyeSb8FbsOV8O0efVeYHOZV0h8N8w3dWXBOVWpgDwO/oBqc1BxciV7Pg3OJhz66ivPB+PoM8TnqRQPTeNkKfeALtAQ39QYsgE85xNsFz+voFe8AldFALS8DYU3waAd9b5gAv3OKn2HefagK4q64VgPm9k0we0wtN9pN6w+mY9qywqLnWeKXGa/WwHwYFSwrZtw/w9Ic4p5oxesLPG8Qd/UacMf13IE38ArGwN3EQJbnintOHsJsMOaG5Z+4/2vAY282eALd4FvQqoj4Aca3gQfPw1hSPBr4xoNH3bz1EO0D428r9LwpY3vB+nSolOfRQVeg1yOCgXH01pu+GeL+Y1hOwWOYBZlhieJxBU94eA2Lwo9WRw+X8fUEx0PUaPFowKW6Cg+UBc6M6AzrMsR1xtJR1vO4CkNk1TMLJoXBlcHQpvAePW+0eFyBRe45jAbL7fskhqm4MbdGmYruUU94l8zNfIyl4hhfLQteHqaiLYq7J4YlipvnXkgWRotgyRYNWB4st6bpizLiHsiO4H1gMrhnRVtarpcxy0vd+9eLPMvzhuMf1E7QmyC78xrQmDk+BC6Am98CLoKXi/dvWll1xjvjeAkD9YVXpkJ6ae7/BOPus4b+p9X9BdB/zv8zawwXAAAAAElFTkSuQmCC);background-repeat:no-repeat;background-position:center}.leaflet-ruler-clicked,.leaflet-ruler:hover{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAE/ElEQVRIS6WVeWwUVRzHfzOzs7Pdi+7Rdq/ubrH0sNaKBFMCSEvBQLivFkhAE8GDYAyHATWgETUoMZ7BGCMBNKYiQbTKpYQKBqKlWmBbadmW7bbbFjv0mu2eM298M5SlpS3U+LL/zL6Zz/f7vr/3e4+AsQ6j80EgxTkKhGwkQRqQiLp5UtEOSDwOXf660TDEPfkGR75RTT8VF1EpJRJ6LsbrVuaZg2YtrWND8WD5FVajV9IcTyCOoYhv2QgcgE5fzWDmaAKU0eHa3RMStszNMqIdM+zUY3YdPFvRCG+VOCFFQ0N3mIfNJ3ywb3Em/BHgYNeZFnTc20OOU1Efd7eZtwBUxyWh4QLJGS6jFv04MU2bNWeCQRnoi8L7czPuG+RLJ31g0Smhsqk3dqGVa7wZZOZBb/31oQKm8ZMZRbxyU6FV9XaJmyQGZsNxBD/Ud8FXNWy/rzci9ER4Spqa5tYrit3jmNI8M2DnCRNvnm1Bu35tjcR4lH1HIDtbp+2NNuSmqCyTrBr4dMEDuH4A754LCLvOtQo44zouKp7hQagGIK+CIFgoipqPEHru6OocWJhtlAWk6GZ8cSXs64sd49qbSxMCaenu7+ZkGuftW5JJSy/FBARlh+vDF1tDfWEerYWullNDcjK5c9Q0Or/jcad++3SbbP8ueBn+S7glkOIsNTDUQf+mRxmtkoIIj6Bgb024hYtVhGPK9dDl7RsJvhPDtw3AcWzYuSd8vTcqOS8DrcUIKsUiWcDgyKghRLFgZ1E6vFhohfXfN8YP1bFVfW3N0/E0Ggu8CMNxfY9z7b5SCU4o6dMkhc4RYM61aulwU8fWSSqaIqEqEIRZBzzBSCg+HoIdncPglHgBG9ENdj4inEAXhZuBdQSYXBuWZOnfOLI61yTB1ld4Y1/+xe6Ndvo33Q+ON5Rc0GHOB+DS6gmF2XF6dkZy0eeLM8lU3EDGd6qiQRAnQnvz3wkBXFANdr5jkHMJXrS/NtTIRk5yN3wrErEMgsuNpkp13ViRZ0zdOtUOWiUJ2R/WxPibfmYk+Mp8E/XCT01y4y0/1HBfuCygMDljVzYW0DnmJKhuC8Lsg7WB7kCzQxa4y7nUF08euQblHlZMoqij93J+2yBBpzgjlzcUMJLAmeu9sOjrq+1cR7PtNvzVYrv+5WkOUvpAiqUYx+JlI6cwfPlosQyuHcGYnYECq9r2AV62O5mB9PcuItxjj2ho6uz/hcsRESbH4TX5qQv3LsigNbjJ7Huq+tkIT75enM4Mdx76mbvhXzYW54mIwOBeNd2l+eTs03nyYYIPqrhaSVGbC213xfLf4fIKAB9yqp4IW/VMvtKqVYJJrUhEeCdzGS5lbki22Wu5btYg0IwV2hrYIb0ywoN8VCTbXadDUTRz/9IJsCrfLL82CP7LQCyGcVab56HColQkCKL3ctWxTs/5+WMSAHwPGBih0rNxotqGL42R4DqLpebhKTNta7fvgWBfN7yybIoQjYdzoLPVey+RxHFtdrhfy05J2laxKjep5EAd3oqhhHNtqrm6YOoT6RKcIOXSwEdb1ojXLv35fDRQ99mYBKR6GOyu3zBhcowXTvR3+JdCWhqjVhk9FEW7Z5Wtw1vuFlwatb9XQmuD51J/MFQ+qgAheIdemSl5FoDgOuhs3o0/4vWOKcZkh/4bEJFKxAMA/6QhgsjzAvrH3+SXn0YZAinU/wuTosgK53+p+wAAAABJRU5ErkJggg==)}.leaflet-ruler-clicked{height:35px;width:35px;background-repeat:no-repeat;background-position:center;border-color:#7fff00!important}.leaflet-bar.leaflet-ruler{background-color:#fff}.leaflet-control.leaflet-ruler{cursor:pointer}.result-tooltip{background-color:#fff;border-width:medium;border-color:#de0000;font-size:smaller}.moving-tooltip{background-color:#ffffffb3;background-clip:padding-box;opacity:.5;border:dotted;border-color:red;font-size:smaller}.plus-length{padding-left:45px} diff --git a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.js b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.js index e732020..f88d334 100644 --- a/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.js +++ b/assets/static/vendor/leaflet-elevation/libs/leaflet-ruler.min.js @@ -1 +1 @@ -L.Control.Ruler=L.Control.extend({options:{position:"topright",circleMarker:{color:"red",radius:2},lineStyle:{color:"red",dashArray:"1,6"},lengthUnit:{display:"km",decimal:2,factor:.001,label:"Distance:"},angleUnit:{display:"°",decimal:2,factor:360,label:"Bearing:"}},initialize:function(options){L.setOptions(this,options),this._layers=L.layerGroup(),this._enabled=!1},onAdd:function(map){this._defaultCursor=map._container.style.cursor,this._map=map;let container=L.DomUtil.create("div","leaflet-bar");return container.classList.add("leaflet-ruler"),L.DomEvent.disableClickPropagation(container),L.DomEvent.on(container,"click",this._toggleMeasure,this),this._container=container},onRemove:function(){L.DomEvent.off(this._container,"click",this._toggleMeasure,this)},_attachMouseEvents:function(){let map=this._map;map.doubleClickZoom.disable(),L.DomEvent.on(map._container,"keydown",this._escape,this),L.DomEvent.on(map._container,"dblclick",this._closePath,this),map._container.style.cursor="crosshair",map.on("click",this._addPoint,this),map.on("mousemove",this._moving,this)},_removeMouseEvents:function(){let map=this._map;map.doubleClickZoom.enable(),L.DomEvent.off(map._container,"keydown",this._escape,this),L.DomEvent.off(map._container,"dblclick",this._closePath,this),map._container.style.cursor=this._defaultCursor,map.off("click",this._addPoint,this),map.off("mousemove",this._moving,this)},_disable:function(){this._enabled=!1,this._container.classList.remove("leaflet-ruler-clicked"),this._map.removeLayer(this._layers),this._layers=L.layerGroup(),this._latlngs=[],this._totalLength=0,this._removeMouseEvents()},_enable:function(){this._enabled=!0,this._container.classList.add("leaflet-ruler-clicked"),this._circles=L.featureGroup().addTo(this._layers),this._polyline=L.polyline([],this.options.lineStyle).addTo(this._layers),this._layers.addTo(this._map),this._latlngs=[],this._totalLength=0,this._attachMouseEvents()},_toggleMeasure:function(){this._enabled?this._disable():this._enable()},_drawTooltip:function(latlng,layer,incremental){let clickCount=this._latlngs.length,lastClick=clickCount?this._latlngs[clickCount-1]:latlng,bearing=this._calculateBearing(lastClick,latlng),distance=lastClick.distanceTo(latlng)*this.options.lengthUnit.factor,totalLength,plusLength;incremental?(totalLength=(clickCount?distance+this._totalLength||0:distance).toFixed(this.options.lengthUnit.decimal),plusLength=clickCount?'<br><div class="plus-length">(+'+distance.toFixed(this.options.lengthUnit.decimal)+")</div>":""):(this._totalLength+=distance,totalLength=(clickCount?this._totalLength:distance).toFixed(this.options.lengthUnit.decimal),plusLength="");var text="<b>"+this.options.angleUnit.label+"</b> "+bearing.toFixed(this.options.angleUnit.decimal)+" "+this.options.angleUnit.display+"<br><b>"+this.options.lengthUnit.label+"</b> "+totalLength+" "+this.options.lengthUnit.display+plusLength;layer.setLatLng(latlng);let tooltip=layer.getTooltip();return tooltip?tooltip.setTooltipContent(text):layer.bindTooltip(text,incremental?{direction:"auto",sticky:!0,offset:L.point(0,-40),className:"moving-tooltip"}:{permanent:!0,className:"result-tooltip"}).openTooltip(),layer},_addPoint:function(e){let latlng=e.latlng||e,point=L.circleMarker(latlng,this.options.circleMarker).addTo(this._circles);this._polyline.addLatLng(latlng),this._latlngs.length&&!latlng.equals(this._latlngs[this._latlngs.length-1])&&this._drawTooltip(latlng,point,!1),this._latlngs.push(latlng)},_moving:function(e){if(this._latlngs.length){let lastCLick=this._latlngs[this._latlngs.length-1];this._tempLine||(this._tempLine=L.polyline([],this.options.lineStyle).addTo(this._map)),this._tempPoint||(this._tempPoint=L.circleMarker(e.latlng,this.options.circleMarker).addTo(this._map)),this._tempLine.setLatLngs([lastCLick,e.latlng]),this._drawTooltip(e.latlng,this._tempPoint,!0),L.DomEvent.off(this._container,"click",this._toggleMeasure,this)}},_escape:function(e){27===e.keyCode&&(this._latlngs.length?this._closePath():(this._enabled=!0,this._toggleMeasure()))},_calculateBearing:function(start,end){const toRad=L.DomUtil.DEG_TO_RAD,toDeg=this.options.angleUnit.factor/2/Math.PI;let y=Math.sin((end.lng-start.lng)*toRad)*Math.cos(end.lat*toRad),x=Math.cos(start.lat*toRad)*Math.sin(end.lat*toRad)-Math.sin(start.lat*toRad)*Math.cos(end.lat*toRad)*Math.cos((end.lng-start.lng)*toRad);return(Math.atan2(y,x)*toDeg+this.options.angleUnit.factor)%this.options.angleUnit.factor},_closePath:function(){this._tempLine&&(this._map.removeLayer(this._tempLine),this._tempLine=null),this._tempPoint&&(this._map.removeLayer(this._tempPoint),this._tempLine=null),this._latlngs.length<=1&&this._map.removeLayer(this._circles),this._enabled=!1,L.DomEvent.on(this._container,"click",this._toggleMeasure,this),this._toggleMeasure()}}),L.control.ruler=function(options){return new L.Control.Ruler(options)};
\ No newline at end of file +L.Control.Ruler=L.Control.extend({options:{position:"topright",circleMarker:{color:"red",radius:2},lineStyle:{color:"red",dashArray:"1,6"},lengthUnit:{display:"km",decimal:2,factor:.001,label:"Distance:"},angleUnit:{display:"°",decimal:2,factor:360,label:"Bearing:"}},initialize(t){L.Util.setOptions(this,t),this._layers=new L.LayerGroup,this._enabled=!1},onAdd(t){this._defaultCursor=t._container.style.cursor,this._map=t;let e=L.DomUtil.create("div","leaflet-bar");return e.classList.add("leaflet-ruler"),L.DomEvent.disableClickPropagation(e),L.DomEvent.on(e,"click",this._toggleMeasure,this),this._container=e},onRemove(){L.DomEvent.off(this._container,"click",this._toggleMeasure,this)},_attachMouseEvents(){let t=this._map;t.doubleClickZoom.disable(),L.DomEvent.on(t._container,"keydown",this._escape,this),L.DomEvent.on(t._container,"dblclick",this._closePath,this),t._container.style.cursor="crosshair",t.on("click",this._addPoint,this),t.on(L.version.startsWith("2")?"pointermove":"mousemove",this._moving,this)},_removeMouseEvents(){let t=this._map;t.doubleClickZoom.enable(),L.DomEvent.off(t._container,"keydown",this._escape,this),L.DomEvent.off(t._container,"dblclick",this._closePath,this),t._container.style.cursor=this._defaultCursor,t.off("click",this._addPoint,this),t.off(L.version.startsWith("2")?"pointermove":"mousemove",this._moving,this)},_disable(){this._enabled=!1,this._container.classList.remove("leaflet-ruler-clicked"),this._layers.remove().clearLayers(),this._latlngs=[],this._totalLength=0,this._removeMouseEvents()},_enable(){this._enabled=!0,this._container.classList.add("leaflet-ruler-clicked"),this._circles=new L.FeatureGroup().addTo(this._layers),this._polyline=new L.Polyline([],this.options.lineStyle).addTo(this._layers),this._layers.addTo(this._map),this._latlngs=[],this._totalLength=0,this._attachMouseEvents()},_toggleMeasure(){this._enabled?this._disable():this._enable()},_drawTooltip(t,e,i){let s=this._latlngs[this._latlngs.length-1]??t,o=this._calculateBearing(s,t),l=s.distanceTo(t)*this.options.lengthUnit.factor,n=this._totalLength+l,a=n.toFixed(this.options.lengthUnit.decimal),h=i?'<br><div class="plus-length">(+'+l.toFixed(this.options.lengthUnit.decimal)+")</div>":"";this._totalLength=i?this._totalLength:n,e.getTooltip()||e.bindTooltip("",i?{direction:"auto",sticky:!0,offset:new L.Point(0,-40),className:"moving-tooltip"}:{permanent:!0,className:"result-tooltip"}).openTooltip(),e.setLatLng(t).setTooltipContent("<b>"+this.options.angleUnit.label+"</b> "+o.toFixed(this.options.angleUnit.decimal)+" "+this.options.angleUnit.display+"<br><b>"+this.options.lengthUnit.label+"</b> "+a+" "+this.options.lengthUnit.display+h)},_addPoint(t){let e=t.latlng||t,i=new L.CircleMarker(e,this.options.circleMarker).addTo(this._circles);this._polyline.addLatLng(e),this._latlngs.length&&!e.equals(this._latlngs[this._latlngs.length-1])&&this._drawTooltip(e,i,!1),this._latlngs.push(e)},_moving(t){if(this._latlngs.length){let e=this._latlngs[this._latlngs.length-1];this._tempLine||(this._tempLine=new L.Polyline([],this.options.lineStyle).addTo(this._map)),this._tempPoint||(this._tempPoint=new L.CircleMarker(t.latlng,this.options.circleMarker).addTo(this._map)),this._tempLine.setLatLngs([e,t.latlng]),this._drawTooltip(t.latlng,this._tempPoint,!0),L.DomEvent.off(this._container,"click",this._toggleMeasure,this)}},_escape(t){t.keyCode===27&&(this._latlngs.length?this._closePath():(this._enabled=!0,this._toggleMeasure()))},_calculateBearing(t,e){const i=Math.PI/180,s=this.options.angleUnit.factor/2/Math.PI;let o=Math.sin((e.lng-t.lng)*i)*Math.cos(e.lat*i),l=Math.cos(t.lat*i)*Math.sin(e.lat*i)-Math.sin(t.lat*i)*Math.cos(e.lat*i)*Math.cos((e.lng-t.lng)*i);return(Math.atan2(o,l)*s+this.options.angleUnit.factor)%this.options.angleUnit.factor},_closePath(){this._tempLine&&(this._tempLine.remove(),this._tempLine=null),this._tempPoint&&(this._tempPoint.remove(),this._tempLine=null),this._latlngs.length<=1&&this._circles.remove(),this._enabled=!1,L.DomEvent.on(this._container,"click",this._toggleMeasure,this),this._toggleMeasure()}}),L.control=L.control||{},L.control.ruler=function(t){return new L.Control.Ruler(t)}; diff --git a/assets/static/vendor/leaflet-elevation/src/components/chart.js b/assets/static/vendor/leaflet-elevation/src/components/chart.js index b0b5458..d5ffe93 100644 --- a/assets/static/vendor/leaflet-elevation/src/components/chart.js +++ b/assets/static/vendor/leaflet-elevation/src/components/chart.js @@ -1,444 +1,361 @@ -import * as D3 from './d3.js'; - const _ = L.Control.Elevation.Utils; -export var Chart = L.Control.Elevation.Chart = L.Class.extend({ - - includes: L.Evented ? L.Evented.prototype : L.Mixin.Events, +export var Chart = L.Control.Elevation.Chart = L.Evented.extend({ initialize(opts, control) { - this.options = opts; - this.control = control; - - this._data = control._data || []; - - // cache registered components - this._props = { - scales : {}, - paths : {}, - areas : {}, - grids : {}, - axes : {}, - legendItems : {}, - tooltipItems: {}, - }; - - this._scales = {}; - this._domains = {}; - this._ranges = {}; - this._paths = {}; - + this.options = opts; + this.control = control; + this._data = control._data || []; + this._props = { scales: {}, paths: {}, areas: {}, grids: {}, axes: {}, legendItems: {}, tooltipItems: {} }; + this._scales = {}; + this._domains = {}; + this._ranges = {}; + this._paths = {}; this._brushEnabled = opts.dragging; - this._zoomEnabled = opts.zooming; - - opts.xTicks = this._xTicks(); - opts.yTicks = this._yTicks(); - - let chart = this._chart = D3.Chart(opts); - - // SVG Container + this._zoomEnabled = opts.zooming; + this.__xTicks = opts.xTicks; + this.__yTicks = opts.yTicks; + this._transform = { k: 1, x: 0 }; + const { width, height, margins = {}, ruler, preferCanvas } = opts; + const svg = _.create('svg:svg', '', { class: 'background' }); + const defs = _.create('svg:defs', '', {}, svg); + const g = _.create('svg:g', '', {}, svg); + const panes = {}; + for (const name of ['grid', 'area', 'axis', 'point', 'brush', 'tooltip', 'ruler', 'legend']) panes[name] = _.create('svg:g', '', { class: name }, g); + panes.tooltip.setAttribute('display', 'none'); + const mask = _.create('svg:mask', '', { id: 'elevation-clipper-' + _.randomId(), 'fill-opacity': 1 }, panes.area); + const maskRect = _.create('svg:rect', '', { class: 'zoom', fill: 'white' }, mask); + const foreignObject = _.create('svg:foreignObject', '', { mask: `url(#${mask.id})` }, panes.area); + const canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'); + canvas.className = 'canvas-plot'; + foreignObject.appendChild(canvas); + const context = canvas.getContext('2d'); + const webkitCanvas = preferCanvas && /Mac|iPod|iPhone|iPad/.test(navigator.platform) && + /AppleWebkit/i.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent); + const canvasImage = webkitCanvas ? _.create('svg:image', '', { mask: `url(#${mask.id})`, 'pointer-events': 'none' }, panes.area) : null; + if (canvasImage) foreignObject.remove(); + const overlay = _.create('svg:rect', '', { class: 'overlay', fill: 'none', 'pointer-events': 'all' }, panes.brush); + const selection = _.create('svg:rect', '', { class: 'selection', fill: '#777', 'fill-opacity': 0.3, stroke: '#fff', display: 'none' }, panes.brush); + for (const edge of ['w', 'e']) _.create('svg:rect', '', { class: `handle handle--${edge}`, fill: 'none', 'pointer-events': 'all', display: 'none', cursor: 'ew-resize' }, panes.brush); + const chart = this._chart = { svg, g, panes, utils: { defs, mask, canvas, context }, pane: name => panes[name] || (panes[name] = _.create('svg:g', '', { class: name }, g)) }; + chart.get = name => chart.utils[name]; + // ponytail: Safari encodes one PNG per redraw; use a separate HTML canvas layer if encoding becomes a bottleneck. + chart._renderCanvas = () => { if (canvasImage) canvasImage.setAttribute('href', canvas.toDataURL()); }; + chart._resize = ({ width, height, margins = {}, ruler }) => { + const w = width - margins.left - margins.right, h = height - margins.top - margins.bottom; + _.setAttributes(svg, { width, height, viewBox: `0 0 ${width} ${height}` }); + g.setAttribute('transform', `translate(${margins.left},${margins.top})`); + _.setAttributes(maskRect, { width: w, height: h, x: 0, y: 0 }); + _.setAttributes(foreignObject, { width: w, height: h }); + _.setAttributes(canvas, { width: w, height: h }); + if (canvasImage) { _.setAttributes(canvasImage, { width: w, height: h }); canvasImage.removeAttribute('href'); } + _.setAttributes(overlay, { x: 0, y: 0, width: w, height: h }); + selection.setAttribute('display', 'none'); + for (const handle of panes.brush.querySelectorAll('.handle')) handle.setAttribute('display', 'none'); + if (ruler) { + const group = panes.ruler; + group.replaceChildren(); + group.dataset.y = h; + group.setAttribute('transform', `translate(0,${h})`); + _.create('svg:rect', '', { class: 'horizontal-drag-rect', x: 0, y: -8, width: w, height: 8, fill: 'none', 'pointer-events': 'all' }, group); + _.create('svg:line', '', { class: 'horizontal-drag-line', x1: 0, x2: w }, group); + _.create('svg:text', '', { class: 'horizontal-drag-label', 'text-anchor': 'end', x: w - 8, y: -8 }, group); + _.create('svg:path', '', { class: 'horizontal-drag-symbol', d: 'M0,-6L5,3L-5,3Z', transform: `translate(${w + 7},0) rotate(-90)` }, group); + } + chart._width = w; + chart._height = h; + svg.dispatchEvent(new CustomEvent('resize', { detail: { width: w, height: h } })); + }; + chart._resize({ width, height, margins, ruler }); this._container = chart.svg; - - // Panes - this._grid = chart.pane('grid'); - this._area = chart.pane('area'); - this._point = chart.pane('point'); - this._axis = chart.pane('axis'); - this._legend = chart.pane('legend'); - this._tooltip = chart.pane('tooltip'); - this._ruler = chart.pane('ruler'); - - // Scales - this._initScale(); - - // Helpers - this._mask = chart.get('mask'); - this._context = chart.get('context'); - this._brush = chart.get('brush'); - - this._zoom = d3.zoom(); - this._drag = d3.drag(); - - // Interactions - this._initInteractions(); - - // svg.on('resize', (e)=>console.log(e.detail)); - - // Handle multi-track segments + for (const name of ['grid', 'area', 'point', 'axis', 'legend', 'tooltip', 'ruler']) this['_' + name] = chart.pane(name); + this._mask = chart.get('mask'); + this._context = chart.get('context'); + this._registerAxisScale({ axis: 'x', position: 'bottom', attr: opts.xAttr, min: opts.xAxisMin, max: opts.xAxisMax, name: 'distance' }); + this._registerAxisScale({ axis: 'y', position: 'left', attr: opts.yAttr, min: opts.yAxisMin, max: opts.yAxisMax, name: 'altitude' }); + this._x = this._scales.distance; + this._y = this._scales.altitude; this._maskGaps = []; - control.on('eletrack_added', ({index}) => { + control.on('eletrack_added', ({ index }) => { this._maskGaps.push(index); - control.once('elepoint_added', ({index}) => this._maskGaps.push(index)); + control.once('elepoint_added', ({ index }) => this._maskGaps.push(index)); }); - - }, - - update(props) { - if (props) { - if (props.data) this._data = props.data; - if (props.options) this.options = props.options; - } - - this.options.xTicks = this._xTicks(); - this.options.yTicks = this._yTicks(); - - this._updateScale(); - this._updateAxis(); - this._updateMargins(); - this._updateLegend(); - this._updateClipper(); - this._updateArea(); - - return this; - }, - - render() { - return container => container.append(() => this._container.node()); - }, - - clear() { - this._resetDrag(); - this._hideDiagramIndicator() - this._area.selectAll('path').attr("d", "M0 0"); - this._context.clearRect(0, 0, this._width(), this._height()); - this._mask.selectAll(".gap").remove(); - this._maskGaps = []; - - // if (this._path) { - // this._x.domain([0, 1]); - // this._y.domain([0, 1]); - // } - }, - - _drawPath(name) { - let path = this._paths[name]; - let area = this._props.areas[name]; - - path.datum(this._data).attr("d", - D3.Area( - L.extend({}, area, { - width : this._width(), - height : this._height(), - scaleX : this._scales[area.scaleX], - scaleY : this._scales[area.scaleY] - }) - ) - ); - - if (!path.classed('leaflet-hidden')) { - this.options.preferCanvas - ? _.drawCanvas(this._context, path) - : _.append(this._area.node(), path.node()); - } - }, - - _hasActiveLayers() { - const paths = this._paths; - for (var i in paths) { - if (!paths[i].classed('leaflet-hidden')) { - return true; - } - } - return false; - }, - - /** - * Initialize "d3-brush". - */ - _initBrush(e) { - const brush = ({selection}) => { - if (selection && this._data.length) { - let start = this._findIndexForXCoord(selection[0]); - let end = this._findIndexForXCoord(selection[1]); - this.fire('dragged', { dragstart: this._data[start], dragend: this._data[end] }); + const brush = panes.brush; + const focus = event => { + if (!this.options.detached) event.stopPropagation(); + if (!this._data.length) return; + const xCoord = _.clamp(_.pointer(event, this._area)[0], [0, this._width()]); + this.fire('mouse_move', { item: this._data[this._findIndexForXCoord(xCoord)], xCoord }); + }; + const rulerLabel = () => { + const y = +this._ruler.dataset.y; + if (y <= 0 || y >= this._height()) this._ruler.querySelector('text').textContent = ''; + this._hideDiagramIndicator(); + }; + brush.style.touchAction = 'none'; + this._ruler.style.touchAction = 'none'; + brush.addEventListener('pointerenter', () => this.fire('mouse_enter')); + brush.addEventListener('pointerleave', () => { if (!this._gesture) this.fire('mouse_out'); }); + brush.addEventListener('pointermove', event => { if (!this._gesture) focus(event); }); + brush.addEventListener('mousemove', event => { + if (!this.options.detached) event.stopPropagation(); + }); + svg.addEventListener('pointerdown', event => { + if (this._gesture || !event.isPrimary) return; + const [x] = _.pointer(event, this._area); + let type; + if (this._ruler.contains(event.target) && this.options.ruler && event.button === 0) type = 'ruler'; + else if ((event.shiftKey || event.button === 1) && this._zoomEnabled) type = 'pan'; + else if (brush.contains(event.target) && !event.shiftKey && event.button === 0 && this._brushEnabled) { + type = event.target.classList.contains('handle--w') ? 'west' : + event.target.classList.contains('handle--e') ? 'east' : + event.target.classList.contains('selection') ? 'move' : 'brush'; } - } - - const focus = (e) => { - if (this._data.length && (e.type != 'brush' /*|| e.sourceEvent*/)) { - let rect = this._chart.panes.brush.select('.overlay').node(); - let coords = d3.pointers(e, rect)[0]; - let xCoord = _.clamp(coords[0], [0, this._width()]); // Clamps cursor position to chart's bounds (see issues: #270, #301) - let item = this._data[this._findIndexForXCoord(xCoord)]; - - this.fire("mouse_move", { item: item, xCoord: xCoord }); + if (!type) return; + event.preventDefault(); + event.stopPropagation(); + svg.setPointerCapture(event.pointerId); + this._gesture = { type, id: event.pointerId, start: x, selection: this._selection?.slice(), transform: { ...this._transform } }; + if (type === 'ruler') rulerLabel(); + else if (type === 'pan') svg.style.cursor = 'grabbing'; + else { + this.fire('mouse_enter'); + if (type === 'brush') this._setSelection([x, x]); + focus(event); } - }; - - this._brush - .filter(({shiftKey, button}) => !shiftKey && !button && this._brushEnabled) - .on("end.update", brush) - .on("brush.update", focus); - - this._chart.panes.brush - .on("mouseenter.focus touchstart.focus", this.fire.bind(this, "mouse_enter")) - .on("mouseout.focus touchend.focus", this.fire.bind(this, "mouse_out") ) - .on("mousemove.focus touchmove.focus", focus ); - - }, - - /** - * Initialize "d3-zoom" - */ - _initClipper() { - let svg = this._container; - let margin = this.options.margins; - - const zoom = this._zoom; - - const onStart = ({transform, sourceEvent}) => { - if (sourceEvent && sourceEvent.type == "mousedown") svg.style('cursor', 'grabbing'); - if (transform.k == 1 && transform.x == 0) { - this._container.classed('zoomed', true); - // Apply d3-zoom and bind <mask> - if (this._mask) { - this._point.attr('mask', 'url(#' + this._mask.attr('id') + ')'); + }); + svg.addEventListener('pointermove', event => { + const gesture = this._gesture; + if (!gesture || gesture.id !== event.pointerId) return; + event.preventDefault(); + const [rawX, rawY] = _.pointer(event, this._area); + const x = _.clamp(rawX, [0, this._width()]); + if (gesture.type === 'pan') { + this._setZoom(gesture.transform.k, gesture.transform.x + rawX - gesture.start); + this._hideDiagramIndicator(); + } else if (gesture.type === 'ruler') { + const y = _.clamp(rawY, [0, this._height()]); + this._ruler.dataset.y = y; + this._ruler.setAttribute('transform', `translate(0,${y})`); + this._ruler.classList.toggle('active', y < this._height()); + this._ruler.querySelector('text').textContent = this._y.invert(y).toFixed(0) + ' ' + (this.options.imperial ? 'ft' : 'm'); + const groups = []; + if (rawY > 0 && rawY < this._height()) { + const altitude = this._y.invert(rawY); + let group; + for (const item of this._data) { + if (item[this.options.yAttr] >= altitude) { + if (!group) groups.push(group = []); + group.push(item.latlng); + } else group = null; + } } + this.fire('ruler_filter', { coords: groups }); + } else { + let selection; + if (gesture.type === 'move') { + const delta = _.clamp(x - gesture.start, [-gesture.selection[0], this._width() - gesture.selection[1]]); + selection = gesture.selection.map(value => value + delta); + } else if (gesture.type === 'west') selection = [x, gesture.selection[1]]; + else if (gesture.type === 'east') selection = [gesture.selection[0], x]; + else selection = [_.clamp(gesture.start, [0, this._width()]), x]; + this._setSelection(selection); } - this.zooming = true; - }; - - const onEnd = ({transform}) => { - if (transform.k ==1 && transform.x == 0) { - this._container.classed('zoomed', false); - // Reset d3-zoom and remove <mask> - if (this._mask) { - this._point.attr('mask', null); - } + }); + const end = event => { + const gesture = this._gesture; + if (!gesture || gesture.id !== event.pointerId) return; + this._gesture = null; + svg.style.cursor = ''; + if (svg.hasPointerCapture(event.pointerId)) svg.releasePointerCapture(event.pointerId); + if (gesture.type === 'ruler') rulerLabel(); + else if (gesture.type !== 'pan') { + if (event.type === 'pointercancel' || !this._selection || this._selection[1] - this._selection[0] < 1) this._resetDrag(); + else if (this._data.length) this.fire('dragged', { + dragstart: this._data[this._findIndexForXCoord(this._selection[0])], + dragend: this._data[this._findIndexForXCoord(this._selection[1])], + }); } - this.zooming = false; - svg.style('cursor', ''); + if (event.pointerType === 'touch') this.fire('mouse_out'); }; - - const onZoom = ({transform, sourceEvent}) => { - // TODO: find a faster way to redraw the chart. - this.zooming = false; - this._updateScale(); // hacky way for restoring x scale when zooming out - this.zooming = true; - this._scales.distance = this._x = transform.rescaleX(this._x); // calculate x scale at zoom level - if (this._scales.time) this._scales.time = transform.rescaleX(this._scales.time); // calculate x scale at zoom level - this._resetDrag(); - if (sourceEvent && sourceEvent.type == "mousemove") { - this._hideDiagramIndicator(); - } - this.fire('zoom'); + for (const name of ['pointerup', 'pointercancel', 'lostpointercapture']) svg.addEventListener(name, end); + const zoomAt = (event, factor) => { + if (!this._zoomEnabled || !event.shiftKey) return; + event.preventDefault(); + const x = _.pointer(event, this._area)[0]; + const k = _.clamp(this._transform.k * factor, [1, 10]); + this._setZoom(k, x - (x - this._transform.x) * k / this._transform.k); }; - - zoom - .scaleExtent([1, 10]) - .extent([ - [margin.left, 0], - [this._width() - margin.right, this._height()] - ]) - .translateExtent([ - [margin.left, -Infinity], - [this._width() - margin.right, Infinity] - ]) - .filter(({shiftKey, buttons}) => (shiftKey || buttons == 4) && this._zoomEnabled) - .on("start", onStart) - .on("end", onEnd) - .on("zoom", onZoom); - - svg.call(zoom); // add zoom functionality to "svg" group - - // d3.select("body").on("keydown.grabzoom keyup.grabzoom", (e) => svg.style('cursor', e.shiftKey ? 'move' : '')); - + svg.addEventListener('wheel', event => zoomAt(event, 2 ** (-event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002))), { passive: false }); + svg.addEventListener('dblclick', event => zoomAt(event, 2)); + svg.addEventListener('legend_clicked', ({ detail: { path, name, legend, enabled } }) => { + if (!path) return; + this._togglePath(name, !enabled); + this.fire('elepath_toggle', { path, name, legend, enabled }); + }); }, - _initInteractions() { - this._initBrush(); - this._initRuler(); - this._initClipper(); - this._initLegend(); + render() { + return container => container.appendChild(this._container); }, - /** - * Toggle chart data on legend click - */ - _initLegend() { - this._container.on('legend_clicked', ({detail}) => { - let { path, legend, name, enabled } = detail; - if (path) { - let label = _.select('text', legend); - let rect = _.select('rect', legend); - _.toggleStyle(label, 'text-decoration-line', 'line-through', enabled); - _.toggleStyle(rect, 'fill-opacity', '0', enabled); - _.toggleClass(path, 'leaflet-hidden', enabled); - this._updateArea(); - this.fire("elepath_toggle", { path, name, legend, enabled }) - } - }); + clear() { + this._resetDrag(); + this._hideDiagramIndicator(); + this._transform = { k: 1, x: 0 }; + this._container.classList.remove('zoomed'); + this._point.removeAttribute('mask'); + this._point.replaceChildren(); + for (const path of Object.values(this._paths)) path.setAttribute('d', 'M0 0'); + this._context.clearRect(0, 0, this._width(), this._height()); + this._chart._renderCanvas(); + this._mask.querySelectorAll('.gap').forEach(node => node.remove()); + this._maskGaps = []; }, - /** - * Initialize "ruler". - */ - _initRuler() { - if (!this.options.ruler) return; - - // const yMax = this._height(); - const formatNum = d3.format(".0f"); - const drag = this._drag; - - const label = (e, d) => { - let yMax = this._height(); - let y = this._ruler.data()[0].y; - if (y >= yMax || y <= 0) this._ruler.select(".horizontal-drag-label").text(''); - this._hideDiagramIndicator(); - }; - - const position = (e, d) => { - let yCoord = d3.pointers(e, this._area.node())[0][1]; - let yMax = this._height(); - let y = _.clamp(yCoord, [0, yMax]); - - this._ruler - .data([L.extend(this._ruler.data()[0], { y: y })]) - .attr("transform", d => "translate(" + d.x + "," + d.y + ")") - .classed('active', y < yMax); - - this._container - .select(".horizontal-drag-label") - .text(formatNum(this._y.invert(y)) + " " + (this.options.imperial ? 'ft' : 'm')); - - this.fire('ruler_filter', { coords: yCoord < yMax && yCoord > 0 ? this._findCoordsForY(yCoord) : [] }); - } - - drag - .on("start end", label) - .on("drag", position); - - this._ruler.call(drag); - + _hasActiveLayers() { + return Object.values(this._paths).some(path => !path.classList.contains('leaflet-hidden')); }, - /** - * Initialize x and y scales - */ - _initScale() { - let opts = this.options; - - this._registerAxisScale({ - axis : 'x', - position: 'bottom', - attr : opts.xAttr, - min : opts.xAxisMin, - max : opts.xAxisMax, - name : 'distance' + _setSelection(values) { + this._selection = values.map(x => _.clamp(x, [0, this._width()])).sort((a, b) => a - b); + const [start, end] = this._selection; + _.setAttributes(this._chart.panes.brush.querySelector('.selection'), { + x: start, y: 0, width: end - start, height: this._height(), display: 'inline', cursor: 'move', }); - - this._registerAxisScale({ - axis : 'y', - position : 'left', - attr : opts.yAttr, - min : opts.yAxisMin, - max : opts.yAxisMax, - name : 'altitude' + for (const edge of ['w', 'e']) _.setAttributes(this._chart.panes.brush.querySelector('.handle--' + edge), { + x: (edge === 'w' ? start : end) - 3, y: 0, width: 6, height: this._height(), display: 'inline', }); + }, - this._x = this._scales.distance; - this._y = this._scales.altitude; + _setZoom(k, x) { + if (!Number.isFinite(k) || !Number.isFinite(x) || k <= 0) throw new Error('Invalid chart zoom'); + k = _.clamp(k, [1, 10]); + this._transform = { k, x: _.clamp(x, [this._width() * (1 - k), 0]) }; + this._container.classList.toggle('zoomed', k !== 1); + if (k !== 1) this._point.setAttribute('mask', `url(#${this._mask.id})`); + else this._point.removeAttribute('mask'); + this._resetDrag(); + this._updateScale(); + this.fire('zoom'); }, _registerAreaPath(props) { - if (props.scale == 'y') props.scale = this._y; - else if (props.scale == 'x') props.scale = this._x; - - let opts = this.options; - - if (!props.xAttr) props.xAttr = opts.xAttr; - if (!props.yAttr) props.yAttr = opts.yAttr; - if (typeof props.preferCanvas === "undefined") props.preferCanvas = opts.preferCanvas; - - // Save paths in memory for latter usage - this._paths[props.name] = D3.Path(props); + props = { xAttr: this.options.xAttr, yAttr: this.options.yAttr, preferCanvas: this.options.preferCanvas, ...props }; + const { name, color, strokeColor, strokeOpacity, fillOpacity, className = '' } = props; + const path = this._paths[name] = _.create('svg:path', '', { + class: `${name || ''} ${className}`, + fill: color || '#3366CC', stroke: strokeColor || '#000', + 'stroke-opacity': strokeOpacity ?? 1, 'fill-opacity': fillOpacity ?? 0.8, + }); + path.style.pointerEvents = 'none'; this._props.areas[props.name] = props; - - if (opts.legend) { - this._props.legendItems[props.name] = { - name : props.name, - label : props.label, - color : props.color, - className: props.className, - path : this._paths[props.name] - }; - } - + if (this.options.legend) this._props.legendItems[props.name] = { ...props, path: this._paths[props.name] }; }, _registerAxisGrid(props) { - if (props.scale == 'y') props.scale = this._y; - else if (props.scale == 'x') props.scale = this._x; - - this._props.grids[props.name || props.axis] = props; + this._props.grids[props.name || props.axis] = { ...props }; }, _registerAxisScale(props) { - if (props.scale == 'y') props.scale = this._y; - else if (props.scale == 'x') props.scale = this._x; - - let opts = this.options; - let scale = props.scale; - - if (typeof this._scales[props.name] === 'function') { - props.scale = this._scales[props.name]; // retrieve cached scale - } else if (typeof scale !== 'function') { - scale = L.extend({ - data : this._data, - forceBounds: opts.forceAxisBounds - }, scale); - - scale.attr = scale.attr || props.name; - - let domain = this._domains[props.name] = D3.Domain(props); - let range = this._ranges[props.name] = D3.Range(props); - scale.range = scale.range || range(this._width(),this._height()); - scale.domain = scale.domain || domain(this._data); - + props = { ...props }; + const alias = props.scale; + if (alias === 'y') props.scale = this._y; + else if (alias === 'x') props.scale = this._x; + if (typeof this._scales[props.name] === 'function') props.scale = this._scales[props.name]; + else if (typeof props.scale !== 'function') { + const scale = { data: this._data, forceBounds: this.options.forceAxisBounds, ...props.scale }; + scale.attr = scale.attr || props.name; + const { min, max, attr, name, forceBounds, scale: domainScale } = { forceBounds: scale.forceBounds, ...props }; + const key = (domainScale && domainScale.attr) || attr || name; + this._domains[props.name] = data => { + let low = Infinity, high = -Infinity; + for (const point of data || []) { + const value = point[key]; + if (value == null || !Number.isFinite(+value)) continue; + low = Math.min(low, +value); + high = Math.max(high, +value); + } + if (low === Infinity) [low, high] = [0, 1]; + if (min !== undefined && (min < low || forceBounds)) low = +min; + if (max !== undefined && (max > high || forceBounds)) high = +max; + return [low, high]; + }; + this._ranges[props.name] = (width, height) => props.axis === 'x' ? [0, width] : [height, 0]; + scale.range = scale.range || this._ranges[props.name](this._width(), this._height()); + scale.domain = scale.domain || this._domains[props.name](this._data); this._props.scales[props.name] = scale; - - props.scale = this._scales[props.name] = D3.Scale(scale); - } - - if (!props.ticks) { - if (props.axis == 'x') props.ticks = this._xTicks.bind(this); - else if (props.axis == 'y') props.ticks = this._yTicks.bind(this); + const Scale = function({ domain, range }) { + let bounds = domain; + let pixels = range; + const interpolate = (value, from, to) => { + const fraction = from[1] === from[0] ? 0.5 : (value - from[0]) / (from[1] - from[0]); + return to[0] + fraction * (to[1] - to[0]); + }; + const scale = value => value == null ? undefined : interpolate(+value, bounds, pixels); + scale.invert = value => interpolate(+value, pixels, bounds); + scale.domain = function(value) { + if (!arguments.length) return bounds.slice(); + bounds = value.map(Number); + return scale; + }; + scale.range = function(value) { + if (!arguments.length) return pixels.slice(); + pixels = value.map(Number); + return scale; + }; + scale.copy = () => Scale({ domain: bounds.slice(), range: pixels.slice() }); + scale.ticks = (count = 10) => { + const [low, high] = [Math.min(...bounds), Math.max(...bounds)]; + if (!(count > 0) || !Number.isFinite(low + high)) return []; + if (low === high) return [low]; + const raw = (high - low) / count; + const power = 10 ** Math.floor(Math.log10(raw)); + const error = raw / power; + const step = power * (error >= Math.sqrt(50) ? 10 : error >= Math.sqrt(10) ? 5 : error >= Math.sqrt(2) ? 2 : 1); + const first = Math.ceil(low / step), last = Math.floor(high / step); + const values = Array.from({ length: Math.max(0, last - first + 1) }, (_, i) => +( (first + i) * step).toPrecision(14)); + return bounds[0] > bounds[1] ? values.reverse() : values; + }; + return scale; + }; + props.scale = this._scales[props.name] = Scale(scale); + } else if (alias === 'x' || alias === 'y') { + // Aliases share the original scale, including its zoomed domain. + this._scales[props.name] = props.scale; } - + if (!props.ticks) props.ticks = (props.axis === 'x' ? this._xTicks : this._yTicks).bind(this); this._props.axes[props.name] = props; - - if (props.name == this.options.yScale) this._y = scale; - if (props.name == this.options.xScale) this._x = scale; - - return scale; + if (props.name === this.options.yScale) this._y = props.scale; + if (props.name === this.options.xScale) this._x = props.scale; + return props.scale; }, - /** - * Add a point of interest over the chart - */ _registerCheckPoint(point) { if (!this._data.length) return; - - const {xAttr, yAttr} = this.options; - let item, x, y; - + const { xAttr, yAttr } = this.options; + let item, x; if (point.latlng) { item = this._data[this._findIndexForLatLng(point.latlng)]; - x = this._x(item[xAttr]); - y = this._y(item[yAttr]); + x = this._x(item[xAttr]); } else if (!isNaN(point[xAttr])) { - x = this._x(point[xAttr]); - item = this._data[this._findIndexForXCoord(x)] - y = this._y(item[yAttr]); - } - - this._point.call(D3.CheckPoint({ - point: point, - width: this._width(), - height: this._height(), - x: x, - y: y, - })); + x = this._x(point[xAttr]); + item = this._data[this._findIndexForXCoord(x)]; + } + if (!item) return; + const y = this._y(item[yAttr]); + if (!Number.isFinite(x) || !Number.isFinite(y)) return; + if (!point.item?.isConnected) { + point.position = point.position || 'bottom'; + point.item = _.create('svg:g', '', {}, this._point); + _.create('svg:line', '', { x1: 0, y1: 0, style: 'stroke: rgb(51, 51, 51); stroke-width: 0.5; stroke-dasharray: 2, 2;' }, point.item); + _.create('svg:circle', '', { class: 'height-focus circle-lower', r: 3 }, point.item); + if (point.label) _.create('svg:text', '', { dx: '4px', dy: '-4px' }, point.item); + } + _.setAttributes(point.item, { class: 'point ' + point.position, transform: `translate(${x},${y})`, 'data-y': y }); + _.setAttributes(point.item.querySelector('line'), { y2: ({ top: -y, bottom: this._height() - y })[point.position], + x2: ({ left: -x, right: this._width() - x })[point.position] || 0 }); + if (point.label) point.item.querySelector('text').textContent = point.label; }, _registerTooltip(props) { @@ -447,337 +364,254 @@ export var Chart = L.Control.Elevation.Chart = L.Class.extend({ }, _updateArea() { - // Reset and update chart profiles this._context.clearRect(0, 0, this._width(), this._height()); - _.each(this._paths, (path, i) => !path.classed('leaflet-hidden') && this._drawPath(i)); - }, - - _updateAxis() { - - let opts = this.options; - - const gridOpts = { - width : this._width(), - height : this._height(), - tickFormat: "", - }; - - const axesOpts = { - width : this._width(), - height : this._height(), - }; - - // Reset grids - this._grid.selectAll('g').remove(); - _.each(this._props.grids, (grid, i) => { - if (opts[i] !== false && opts[i] !== 'summary') { - this._grid.call(D3.Grid(L.extend({}, gridOpts, grid))) + for (const name in this._paths) { + const path = this._paths[name], area = this._props.areas[name]; + if (path.classList.contains('leaflet-hidden')) continue; + const { xAttr, yAttr, interpolation = 'curveLinear' } = { interpolation: this.options.interpolation, ...area }; + const scaleX = this._scales[area.scaleX], scaleY = this._scales[area.scaleY]; + if (!['curveLinear', 'curveStep', 'curveStepBefore', 'curveStepAfter'].includes(interpolation)) { + throw new Error(`Unsupported interpolation "${interpolation}". Use curveLinear, curveStep, curveStepBefore or curveStepAfter.`); } - }); - - // Rest axis - this._axis.selectAll('g').remove(); - _.each(this._props.axes, (axis, i) => { - if (opts[i] !== false && opts[i] !== 'summary') { - this._axis.call(D3.Axis(L.extend({}, axesOpts, axis))); - } - }); - - // Adjust axis scale positions - this._axis - .selectAll('.y.axis.right') - .each((d, i, n) => { - - let axis = d3.select(n[i]); - let transform = axis.attr('transform'); - let translate = transform.substring(transform.indexOf("(") + 1, transform.indexOf(")")).split(","); - - axis.attr('transform', 'translate(' + (+translate[0] + (i * 40)) + ',' + translate[1] + ')') - - if (i > 0) { - axis.select(':scope > path') .attr('opacity', 0.25); - axis.selectAll(':scope > .tick line').attr('opacity', 0.75); + let outline = ''; + if (this._data.length) { + const points = this._data.map(d => [d.xDiagCoord = scaleX(d[xAttr]), scaleY(d[yAttr])]); + outline = `M${points[0]}`; + for (let i = 1; i < points.length; i++) { + const [x, y] = points[i], [previousX] = points[i - 1]; + if (interpolation === 'curveStepBefore') outline += `V${y}H${x}`; + else if (interpolation === 'curveStepAfter') outline += `H${x}V${y}`; + else if (interpolation === 'curveStep') outline += `H${(previousX + x) / 2}V${y}H${x}`; + else outline += `L${x},${y}`; } - - }); - - }, - - _updateClipper() { - const { xAttr, margins } = this.options; - const data = this._data; - - this._zoom - .scaleExtent([1, 10]) - .extent([ - [margins.left, 0], - [this._width() - margins.right, this._height()] - ]) - .translateExtent([ - [margins.left, -Infinity], - [this._width() - margins.right, Infinity] - ]); - - // Apply svg mask on multi-track segments - this._mask.selectAll(".gap").remove() - this._maskGaps.forEach((d, i) => { - if (i >= this._maskGaps.length - 2) return; - let x1 = this._x(data[this._findIndexForLatLng(data[this._maskGaps[i]].latlng)][xAttr]); - let x2 = this._x(data[this._findIndexForLatLng(data[this._maskGaps[i + 1]].latlng)][xAttr]); - this._mask - .append("rect") - .attr("x", x1) - .attr("y", 0) - .attr("width", x2 - x1 ) - .attr("height", this._height()) - .attr('class', 'gap') - .attr('fill-opacity', '0.8') - .attr("fill", 'black'); // hide = black (mask) - }); - }, - - _updateLegend: function () { - let xAxesB = this._axis.selectAll('.x.axis.bottom').nodes().length; - - // Get legend items - let items = Object.keys(this._paths); - - // Calculate legend item positions - let n = items.length; - let v = Array(Math.floor(n / 2)).fill(null).map((d, i) => (i + 1) * 2 - (1 - Math.sign(n % 2))); - let rev = v.slice().reverse().map((d) => -(d)); - - // push a fake element to handle center alignment (odd numbers) - if (n % 2 !== 0) { - rev.push(0); - } - v = rev.concat(v); - - // Reset legend items - this._legend.selectAll('g').remove(); - - // Render legend items - _.each(this._props.legendItems, (legend) => { - this._legend.append("g").call( - D3.LegendItem(L.extend({ - width : this._width(), - height : this._height(), - margins: this.options.margins, - }, legend)) - ); - }); - - // Render legend item switcher - if (n > 1) { - this._legend.append("g").call( - D3.LegendSmall({ - width : this._width(), - height : this._height(), - items : items, - onClick: (selected) => { - _.each(items, name => this._togglePath(name, selected == name, true)); - this._updateArea(); - } - }) - ); + outline += `L${points.at(-1)[0]},${this._height()}L${points[0][0]},${this._height()}Z`; + } + path.setAttribute('d', outline); + if (this.options.preferCanvas) _.drawCanvas(this._context, path); + else this._area.appendChild(path); } - - _.each(items, (name, i) => { - // Adjust legend item positions - this._legend.select('[data-name=' + name + ']').attr("transform", "translate(" + (v[i] * 55) + ", " + (xAxesB * 2) + ")"); - // Set initial state (disabled controls) - this._togglePath(name, !(name in this.options && this.options[name] == 'disabled'), true); - }); - + this._chart._renderCanvas(); }, - _updateMargins() { - // Get chart margins - let xAxesB = this._axis.selectAll('.x.axis.bottom').nodes().length; - let xAxesL = this._axis.selectAll('.y.axis.left').nodes().length; - let xAxesR = this._axis.selectAll('.y.axis.right').nodes().length; - let marginB = 60 + (xAxesB * 2); - let marginL = 10 + (xAxesL * 30); - let marginR = 40 + (xAxesR * 30); - - let marginsUpdated = false - - // Adjust right margin - if (xAxesR && this.options.margins.right < marginR) { - this.options.margins.right = marginR; - marginsUpdated = true; + update(props) { + if (props?.data) this._data = props.data; + if (props?.options) this.options = props.options; + this.options.xTicks = this._xTicks(); + this.options.yTicks = this._yTicks(); + this._updateScale(); + this._grid.replaceChildren(); + this._axis.replaceChildren(); + const entries = [ + ...Object.entries(this._props.grids).map(([name, props]) => [name, { tickFormat: '', ...props, type: 'grid' }, this._grid]), + ...Object.entries(this._props.axes).map(([name, props]) => [name, props, this._axis]), + ]; + for (const [key, props, parent] of entries) { + if (this.options[key] === false || this.options[key] === 'summary') continue; + const { + type = 'axis', tickSize = 6, tickPadding = 3, position, height, width, + axis, ticks, tickFormat, label, labelX, labelY, name = '', onAxisMount, + } = { width: this._width(), height: this._height(), ...props }; + const scale = props.scale === 'x' ? this._x : props.scale === 'y' ? this._y : props.scale; + const horizontal = axis === 'x'; + const sign = position === 'top' || position === 'left' ? -1 : 1; + const size = type === 'grid' ? horizontal ? -height : -width : tickSize; + const group = _.create('svg:g', '', { + class: [axis, type, position, name].join(' '), + transform: `translate(${position === 'right' ? width : 0},${position === 'bottom' ? height : 0})`, + fill: 'none', 'font-size': 10, 'font-family': 'sans-serif', + 'text-anchor': horizontal ? 'middle' : sign < 0 ? 'end' : 'start', + }, parent); + const range = scale.range(); + _.create('svg:path', '', { class: 'domain', stroke: 'currentColor', + d: horizontal ? `M${range[0]},${sign * 6}V0.5H${range[1]}V${sign * 6}` : `M${sign * 6},${range[0]}H0.5V${range[1]}H${sign * 6}` }, group); + const values = scale.ticks(typeof ticks === 'function' ? ticks() : ticks); + const step = values.length > 1 ? Math.abs(values[1] - values[0]) : 1; + const format = new Intl.NumberFormat('en-US', { maximumFractionDigits: Math.min(20, Math.max(0, -Math.floor(Math.log10(step)))) }); + for (const value of values) { + const coordinate = scale(value) + 0.5; + const tick = _.create('svg:g', '', { class: 'tick', opacity: 1, transform: horizontal ? `translate(${coordinate},0)` : `translate(0,${coordinate})` }, group); + _.create('svg:line', '', { stroke: 'currentColor', [horizontal ? 'y2' : 'x2']: sign * size }, tick); + const text = _.create('svg:text', '', { fill: 'currentColor', [horizontal ? 'y' : 'x']: sign * (Math.max(0, size) + tickPadding), + dy: horizontal ? sign < 0 ? '0em' : '0.71em' : '0.32em' }, tick); + text.textContent = typeof tickFormat === 'function' ? tickFormat(value) : tickFormat ?? format.format(value); + } + if (label) _.create('svg:text', '', { + x: typeof labelX === 'function' ? labelX() : labelX, + y: typeof labelY === 'function' ? labelY() : labelY, + }, group).textContent = label; + if (onAxisMount) onAxisMount(group); } - - // Adjust left margin - if (xAxesL && this.options.margins.left < marginL) { - this.options.margins.left = marginL; - marginsUpdated = true; + this._axis.querySelectorAll('.y.axis.right').forEach((axis, i) => { + axis.setAttribute('transform', `translate(${this._width() + i * 40},0)`); + if (i > 0) { + axis.querySelector(':scope > path').setAttribute('opacity', 0.25); + axis.querySelectorAll(':scope > .tick line').forEach(line => line.setAttribute('opacity', 0.75)); + } + }); + const margins = { + bottom: 60 + this._axis.querySelectorAll('.x.axis.bottom').length * 2, + left: 10 + this._axis.querySelectorAll('.y.axis.left').length * 30, + right: 40 + this._axis.querySelectorAll('.y.axis.right').length * 30, + }; + let updated = false; + for (const side in margins) { + if (this._axis.querySelector(side === 'bottom' ? '.x.axis.bottom' : '.y.axis.' + side) && this.options.margins[side] < margins[side]) { + this.options.margins[side] = margins[side]; + updated = true; + } } + if (updated) this.fire('margins_updated'); - // Adjust bottom margin - if (xAxesB && this.options.margins.bottom < marginB) { - this.options.margins.bottom = marginB; - marginsUpdated = true; + const xAxesB = this._axis.querySelectorAll('.x.axis.bottom').length; + const items = Object.keys(this._paths), n = items.length; + let positions = Array.from({ length: Math.floor(n / 2) }, (_, i) => (i + 1) * 2 - (1 - Math.sign(n % 2))); + positions = positions.slice().reverse().map(value => -value).concat(n % 2 ? [0] : [], positions); + this._legend.replaceChildren(); + for (const legend of Object.values(this._props.legendItems)) { + const { name, label, width, height, margins = {}, color, path, className = '' } = { + width: this._width(), height: this._height(), margins: this.options.margins, ...legend, + }; + const group = _.create('svg:g', '', { class: 'legend-item legend-' + name.toLowerCase(), 'data-name': name, role: 'button', tabindex: 0 }, this._legend); + const toggle = () => group.ownerSVGElement.dispatchEvent(new CustomEvent('legend_clicked', { + detail: { path, name, legend: group, enabled: !path.classList.contains('leaflet-hidden') }, + })); + group.addEventListener('click', toggle); + group.addEventListener('keydown', event => { + if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); toggle(); } + }); + _.create('svg:rect', '', { x: width / 2 - 50, y: height + margins.bottom / 2, width: 50, height: 10, + fill: color, stroke: '#000', 'stroke-opacity': 0.5, 'fill-opacity': 0.25, class: className }, group); + const text = _.create('svg:text', '', { x: width / 2 + 5, y: height + margins.bottom / 2, 'font-size': 10, 'font-weight': 700, dy: '0.75em' }, group); + text.textContent = L._(label || name); } - - if (marginsUpdated) { - this.fire('margins_updated'); + if (n > 1 && this.options.legend) { + let index = 0; + const group = _.create('svg:g', '', { class: 'legend-switcher', transform: `translate(${this._width()},${this._height() + 40})` }, this._legend); + const label = _.create('svg:text', '', { class: 'legend-switcher-label', 'text-anchor': 'end', x: -25, y: 5 }, group); + const select = delta => { + index = (index + delta + items.length) % items.length; + label.textContent = L._(items[index][0].toUpperCase() + items[index].slice(1)); + for (const name of items) this._togglePath(name, name === items[index], true); + this._updateArea(); + }; + label.addEventListener('click', () => select(1)); + for (const [x, y, angle, delta] of [[0, 3, 0, -1], [-13, 0, 180, 1]]) { + const symbol = _.create('svg:path', '', { class: 'legend-switcher-symbol', d: 'M0,-6L5,3L-5,3Z', + transform: `translate(${x},${y}) rotate(${angle})`, cursor: 'pointer', fill: '#000', + role: 'button', tabindex: 0, 'aria-label': L._(delta > 0 ? 'Next profile' : 'Previous profile') }, group); + symbol.addEventListener('click', () => select(delta)); + symbol.addEventListener('keydown', event => { + if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); select(delta); } + }); + } + select(0); } + items.forEach((name, i) => { + const legend = this._legend.querySelector(`[data-name="${name}"]`); + if (legend) legend.setAttribute('transform', `translate(${positions[i] * 55},${xAxesB * 2})`); + this._togglePath(name, this.options[name] !== 'disabled', true); + }); + this._mask.querySelectorAll('.gap').forEach(node => node.remove()); + this._maskGaps.forEach((index, i) => { + if (i >= this._maskGaps.length - 2) return; + const x1 = this._x(this._data[index][this.options.xAttr]); + const x2 = this._x(this._data[this._maskGaps[i + 1]][this.options.xAttr]); + _.create('svg:rect', '', { x: x1, y: 0, width: x2 - x1, height: this._height(), class: 'gap', 'fill-opacity': 0.8, fill: 'black' }, this._mask); + }); + this._updateArea(); + return this; }, _updateScale() { - if (this.zooming) return { x: this._x, y: this._y }; - - for (let i in this._scales) { - this._scales[i] - .domain(this._domains[i](this._data)) - .range(this._ranges[i](this._width(), this._height())) + for (const name in this._domains) { + const scale = this._scales[name]; + scale.domain(this._domains[name](this._data)).range(this._ranges[name](this._width(), this._height())); + if (this._props.axes[name].axis === 'x') { + const { k, x } = this._transform; + scale.domain(scale.range().map(pixel => scale.invert((pixel - x) / k))); + } } - return { x: this._x, y: this._y }; }, - /** - * Calculates chart width. - */ _width() { - if (this._chart) this._chart._width; - const { width, margins } = this.options; - return width - margins.left - margins.right; + return this.options.width - this.options.margins.left - this.options.margins.right; }, - /** - * Calculates chart height. - */ _height() { - if (this._chart) return this._chart._height; - const { height, margins } = this.options; - return height - margins.top - margins.bottom; + return this.options.height - this.options.margins.top - this.options.margins.bottom; }, - /* - * Finds data entries above a given y-elevation value and returns geo-coordinates - */ - _findCoordsForY(y) { - let data = this._data; - let z = this._y.invert(y); - - // save indexes of elevation values above the horizontal line - const list = data.reduce((array, item, index) => { - if (item[this.options.yAttr] >= z) array.push(index); - return array; - }, []); - - let start = 0; - let next; - - // split index list into blocks of coordinates - const coords = list.reduce((array, _, curr) => { - next = curr + 1; - if (list[next] !== list[curr] + 1 || next === list.length) { - array.push( - list - .slice(start, next) - .map(i => data[i].latlng) - ); - start = next; - } - return array; - }, []); - - return coords; - }, - - /* - * Finds a data entry for a given x-coordinate of the diagram - */ _findIndexForXCoord(x) { - return d3 - .bisector(d => d[this.options.xAttr]) - .left(this._data || [0, 1], this._x.invert(x)); + return Math.min(this._data.length - 1, _.bisect(this._data, this._x.invert(x), this.options.xAttr)); }, - /* - * Finds a data entry for a given latlng of the map - */ _findIndexForLatLng(latlng) { - let result = null; - let d = Infinity; + let result = null, distance = Infinity; this._data.forEach((item, index) => { - let dist = latlng.distanceTo(item.latlng); - if (dist < d) { - d = dist; - result = index; - } + const current = latlng.distanceTo(item.latlng); + if (current < distance) { distance = current; result = index; } }); return result; }, - /* - * Removes the drag rectangle and zoms back to the total extent of the data. - */ _resetDrag() { - if (this._chart.panes.brush.select(".selection").attr('width')) { - this._chart.panes.brush.call(this._brush.clear); - this._hideDiagramIndicator(); - this.fire('reset_drag'); - } + if (!this._selection) return; + this._selection = null; + for (const node of this._chart.panes.brush.querySelectorAll('.selection, .handle')) node.setAttribute('display', 'none'); + this._hideDiagramIndicator(); + this.fire('reset_drag'); }, _resetZoom() { - if (this._zoom) { - this._zoom.transform(this._chart.svg, d3.zoomIdentity); - } + this._setZoom(1, 0); }, - /** - * Display distance and altitude level ("focus-rect"). - */ _showDiagramIndicator(item, xCoordinate) { - this._tooltip - .attr("display", null) - .call(D3.Tooltip({ - xCoord: xCoordinate, - yCoord: this._y(item[this.options.yAttr]), - height: this._height(), - width : this._width(), - labels: this._props.tooltipItems, - item: item - })); + this._tooltip.removeAttribute('display'); + const group = this._tooltip; + const xCoord = xCoordinate, yCoord = this._y(item[this.options.yAttr]); + group.replaceChildren(); + _.create('svg:line', '', { class: 'mouse-focus-line', x1: xCoord, x2: xCoord, y1: this._height(), y2: 0 }, group); + const box = _.create('svg:g', '', { class: 'mouse-focus-label' }, group); + const rect = _.create('svg:rect', '', { class: 'mouse-focus-label-rect', rx: 3, ry: 3 }, box); + const text = _.create('svg:text', '', { class: 'mouse-focus-label-text', 'font-weight': 700 }, box); + Object.values(this._props.tooltipItems).sort((a, b) => a.order - b.order).forEach(label => { + _.create('svg:tspan', '', { class: 'mouse-focus-label-' + label.name, dy: '1.5em' }, text).textContent = + typeof label.value === 'function' ? label.value(item) : label.value; + }); + if (text.firstChild) text.firstChild.setAttribute('dy', '1em'); + for (const span of text.children) span.setAttribute('x', 0); + const bounds = text.getBBox(); + const x = xCoord ? xCoord + (xCoord < this._width() / 2 ? 10 : -bounds.width - 10) : 0; + const y = yCoord ? Math.max(yCoord - bounds.height, (L.Browser.webkit || L.Browser.safari) ? 0 : -Infinity) : 0; + for (const span of text.children) span.setAttribute('x', x); + text.setAttribute('y', y); + _.setAttributes(rect, { x: x + bounds.x - 5, y: y + bounds.y - 5, width: bounds.width + 10, height: bounds.height + 10 }); }, _togglePath(name, enabled = true, lazy = false) { - let path = this._paths[name]; - let legend = this._container.select('.legend [data-name=' + name + ']'); - path.classed('leaflet-hidden', !enabled); - legend.select('text').style('text-decoration-line', enabled ? '' : 'line-through'); - legend.select('rect').style('fill-opacity', enabled ? '': '0'); - // Apply d3-zoom (bind <clipPath> mask) - if (this._mask) { - path.attr('mask', 'url(#' + this._mask.attr('id') + ')'); - } - if (!lazy) { - this._updateArea(); + const path = this._paths[name]; + const legend = this._legend.querySelector(`[data-name="${name}"]`); + path.classList.toggle('leaflet-hidden', !enabled); + if (legend) { + legend.querySelector('text').style.textDecorationLine = enabled ? '' : 'line-through'; + legend.querySelector('rect').style.fillOpacity = enabled ? '' : '0'; + legend.setAttribute('aria-pressed', enabled); } + path.setAttribute('mask', `url(#${this._mask.id})`); + if (!lazy) this._updateArea(); }, _hideDiagramIndicator() { - this._tooltip.attr("display", 'none'); + this._tooltip.setAttribute('display', 'none'); }, - /** - * Calculate chart xTicks - */ _xTicks() { - if (this.__xTicks) this.__xTicks = this.options.xTicks; - return this.__xTicks || Math.round(this._width() / 75); -}, + return this.__xTicks || Math.round(this._width() / 75); + }, - /** - * Calculate chart yTicks - */ _yTicks() { - if (this.__yTicks) this.__yTicks = this.options.yTicks; return this.__yTicks || Math.round(this._height() / 30); - } + }, }); diff --git a/assets/static/vendor/leaflet-elevation/src/components/marker.js b/assets/static/vendor/leaflet-elevation/src/components/marker.js index 6f1f6af..00a316d 100644 --- a/assets/static/vendor/leaflet-elevation/src/components/marker.js +++ b/assets/static/vendor/leaflet-elevation/src/components/marker.js @@ -1,5 +1,3 @@ -import * as D3 from './d3.js'; - const _ = L.Control.Elevation.Utils; export var Marker = L.Class.extend({ @@ -9,12 +7,8 @@ export var Marker = L.Class.extend({ this.control = control switch(this.options.marker) { - case 'elevation-line': - // this._container = d3.create("g").attr("class", "height-focus-group"); - break; case 'position-marker': - // this._marker = L.circleMarker([0, 0], { pane: 'overlayPane', radius: 6, fillColor: '#fff', fillOpacity:1, color: '#000', weight:1, interactive: false }); - this._marker = L.marker([0, 0], { icon: this.options.markerIcon, zIndexOffset: 1000000, interactive: false }); + this._marker = new L.Marker([0, 0], { icon: this.options.markerIcon, zIndexOffset: 1000000, interactive: false }); break; } @@ -26,7 +20,11 @@ export var Marker = L.Class.extend({ addTo(map) { this._map = map; switch(this.options.marker) { - case 'elevation-line': this._container = d3.select(map.getPane('elevationPane')).select("svg > g").call(D3.PositionMarker({})); break; + case 'elevation-line': + this._container = map.getPane('elevationPane').querySelector("svg > g"); + this._container.replaceChildren(); + this._container.setAttribute('class', 'height-focus-group'); + break; case 'position-marker': this._marker.addTo(map, { pane: 'overlayPane' }); break; } return this; @@ -50,21 +48,30 @@ export var Marker = L.Class.extend({ case 'elevation-line': if (this._container) { let point = this._map.latLngToLayerPoint(this._latlng); - point = L.extend({}, props.item, this._map._rotate ? this._map.rotatedPointToMapPanePoint(point) : point); + point = Object.assign({}, props.item, this._map._rotate ? this._map.rotatedPointToMapPanePoint(point) : point); - let yMax = (this.control._height() / props.yCoordMax * point[this.options.yAttr]); + // Keep the zero baseline unless the track extends below sea level. + let yMin = props.yCoordMin || 0; + let yMax = (this.control._height() / (props.yCoordMax - yMin) * (point[this.options.yAttr] - yMin)); if (!isFinite(yMax) || isNaN(yMax)) yMax = 0; - this._container.classed("leaflet-hidden", false); - this._container.call(D3.PositionMarker({ - theme : this.options.theme, - xCoord: point.x, - yCoord: point.y, - length: point.y - yMax, // normalized Y - labels: this._labels, - item: point, - })); + const { x: xCoord, y: yCoord } = point; + if (!Number.isFinite(xCoord) || !Number.isFinite(yCoord)) return; + const group = this._container; + const { theme } = this.options; + const length = point.y - yMax; + group.replaceChildren(); + group.setAttribute('class', 'height-focus-group'); + _.create('svg:circle', '', { class: `${theme} height-focus circle-lower`, transform: `translate(${xCoord},${yCoord})`, r: 6, cx: 0, cy: 0 }, group); + _.create('svg:line', '', { class: `${theme} height-focus line`, x1: xCoord, x2: xCoord, y1: yCoord, y2: length }, group); + const text = _.create('svg:text', '', { class: `${theme} height-focus-label`, x: xCoord + 5, y: length, 'pointer-events': 'none' }, group); + Object.values(this._labels).sort((a, b) => a.order - b.order).forEach(label => { + _.create('svg:tspan', '', { class: 'height-focus-' + label.name, dy: '1.5em' }, text).textContent = + typeof label.value === 'function' ? label.value(point) : label.value; + }); + if (text.firstChild) text.firstChild.setAttribute('dy', text.children.length > 1 ? '-1.5em' : '0em'); + for (const span of text.children) span.setAttribute('x', xCoord + 5); } break; case 'position-marker': @@ -80,7 +87,7 @@ export var Marker = L.Class.extend({ remove() { this._props = null; switch(this.options.marker) { - case 'elevation-line': this._container && this._container.classed("leaflet-hidden", true); break; + case 'elevation-line': this._container && this._container.classList.add("leaflet-hidden"); break; case 'position-marker': _.addClass(this._marker.getElement(), 'leaflet-hidden'); break; } }, diff --git a/assets/static/vendor/leaflet-elevation/src/components/summary.js b/assets/static/vendor/leaflet-elevation/src/components/summary.js index e8da57f..95de5d4 100644 --- a/assets/static/vendor/leaflet-elevation/src/components/summary.js +++ b/assets/static/vendor/leaflet-elevation/src/components/summary.js @@ -1,43 +1,43 @@ -const _ = L.Control.Elevation.Utils;
-
-export var Summary = L.Class.extend({
- initialize(opts, control) {
- this.options = opts;
- this.control = control;
- this.labels = {};
-
- let summary = this._container = _.create("div", "elevation-summary " + (opts.summary ? opts.summary + "-summary" : ''));
- _.style(summary, 'max-width', opts.width ? opts.width + 'px' : '');
- },
-
- render() {
- return container => container.append(() => this._container);
- },
-
- reset() {
- this._container.innerHTML = '';
- },
-
- append(className, label, value) {
- this._container.innerHTML += `<span class="${className}"><span class="summarylabel">${label}</span><span class="summaryvalue">${value}</span></span>`;
- return this;
- },
-
- update() {
- Object
- .keys(this.labels)
- .sort((a, b) => this.labels[a].order - this.labels[b].order) // TODO: any performance issues?
- .forEach((i)=> {
- let value = typeof this.labels[i].value !== "function" ? this.labels[i].value : this.labels[i].value(this.control.track_info, this.labels[i].unit || '');
- this.append(i /*+ " order-" + this.labels[i].order*/, L._(this.labels[i].label), value, this.labels[i].order);
- });
- },
-
- _registerSummary(data) {
- for (let i in data) {
- data[i].order = data[i].order ?? 1000;
- this.labels[i] = data[i];
- }
- }
-
-});
+const _ = L.Control.Elevation.Utils; + +export var Summary = L.Class.extend({ + initialize(opts, control) { + this.options = opts; + this.control = control; + this.labels = {}; + + let summary = this._container = _.create("div", "elevation-summary " + (opts.summary ? opts.summary + "-summary" : '')); + _.style(summary, 'max-width', opts.width ? opts.width + 'px' : ''); + }, + + render() { + return container => container.appendChild(this._container); + }, + + reset() { + this._container.innerHTML = ''; + }, + + append(className, label, value) { + this._container.innerHTML += `<span class="${className}"><span class="summarylabel">${label}</span><span class="summaryvalue">${value}</span></span>`; + return this; + }, + + update() { + Object + .keys(this.labels) + .sort((a, b) => this.labels[a].order - this.labels[b].order) // TODO: any performance issues? + .forEach((i)=> { + let value = typeof this.labels[i].value !== "function" ? this.labels[i].value : this.labels[i].value(this.control.track_info, this.labels[i].unit || ''); + this.append(i /*+ " order-" + this.labels[i].order*/, L._(this.labels[i].label), value, this.labels[i].order); + }); + }, + + _registerSummary(data) { + for (let i in data) { + data[i].order = data[i].order ?? 1000; + this.labels[i] = data[i]; + } + } + +}); diff --git a/assets/static/vendor/leaflet-elevation/src/control.js b/assets/static/vendor/leaflet-elevation/src/control.js index 27ecf77..cc0edd0 100644 --- a/assets/static/vendor/leaflet-elevation/src/control.js +++ b/assets/static/vendor/leaflet-elevation/src/control.js @@ -8,15 +8,10 @@ if (!L._ || !L.i18n) { export const Elevation = L.Control.Elevation = L.Control.extend({ - includes: L.Evented ? L.Evented.prototype : L.Mixin.Events, - options: Options, __mileFactor: 0.621371, // 1 km = (0.621371 mi) - __footFactor: 3.28084, // 1 m = (3.28084 ft) - __D3: 'https://unpkg.com/d3@7.8.4/dist/d3.min.js', + __footFactor: 3.28084, // 1 m = (3.28084 ft) __TOGEOJSON: 'https://unpkg.com/@tmcw/togeojson@5.6.2/dist/togeojson.umd.js', - __LGEOMUTIL: 'https://unpkg.com/leaflet-geometryutil@0.10.1/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', __LEDGESCALE: '../libs/leaflet-edgescale.min.js', @@ -30,17 +25,16 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ * Add data to the diagram either from GPX or GeoJSON and update the axis domain and data */ addData(d, layer) { - this.import(this.__D3) - .then(() => { - if (this._modulesLoaded) { - layer = layer ?? (d.on && d); - this._addData(d); - this._addLayer(layer); - this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info }); - } else { - this.once('modules_loaded', () => this.addData(d,layer)); - } - }); + return Promise.resolve().then(() => { + if (!this._modulesLoaded) { + return new Promise(resolve => this.once('modules_loaded', () => resolve(this.addData(d, layer)))); + } + layer = layer ?? (d.on && d); + this._addData(d); + this._addLayer(layer); + this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info }); + }); + }, /** @@ -71,6 +65,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this._data = []; this.track_info = {}; + this._yCoordMin = 0; + this._yCoordMax = -Infinity; this._fireEvt("eledata_clear"); @@ -82,7 +78,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this._events.elechart_updated.forEach(({fn, ctx}) => this.off('elechart_updated', fn, ctx)); } if (this._chart && this._chart._container) { - this._chart._container.selectAll('g.point .point').remove(); + this._chart._container.querySelectorAll('g.point .point').forEach(node => node.remove()); this._chart.clear(); } }, @@ -100,7 +96,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ * * @link https://leafletjs.com/examples/extending/extending-3-controls.html#handlers */ - // addHandler: function (name, HandlerClass) { + // addHandler(name, HandlerClass) { // if (HandlerClass) { // let handler = this[name] = new HandlerClass(this); // this.handlers.push(handler); @@ -150,7 +146,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ }, getBounds(data) { - return L.latLngBounds((data || this._data).map((d) => d.latlng)); + return new L.LatLngBounds((data || this._data).map((d) => d.latlng)); }, /** @@ -172,20 +168,19 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ */ initialize(opts) { - // opts = L.setOptions(this, opts); - // Fixes: https://github.com/Raruto/leaflet-elevation/pull/240 - opts = L.setOptions(this, L.extend({}, _.cloneDeep(Options), opts)); // "deep copy" nested objects (multiple charts) + opts = L.Util.setOptions(this, Object.assign({}, _.cloneDeep(Options), opts)); // "deep copy" nested objects (multiple charts) 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], (opts.trkStart || Options.trkStart)); - this._end = L.circleMarker([0,0], (opts.trkEnd || Options.trkEnd)); + this._layers = new L.FeatureGroup(); + this._markers = new L.FeatureGroup(); + this._hotline = new L.FeatureGroup(); + this._circleMarkers = new L.FeatureGroup(); + this._markedSegments = new L.Polyline([]); + this._start = new L.CircleMarker([0,0], (opts.trkStart || Options.trkStart)); + this._end = new L.CircleMarker([0,0], (opts.trkEnd || Options.trkEnd)); this._chartEnabled = true; + this._yCoordMin = 0; this._yCoordMax = -Infinity; this.track_info = {}; // this.handlers = []; @@ -202,7 +197,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this._markedSegments.setStyle(opts.polylineSegments); // Leaflet canvas renderer colors - L.extend(_.Colors, opts.colors || {}); + Object.assign(_.Colors, opts.colors || {}); // Various stuff this._fixCanvasPaths(); @@ -218,10 +213,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ return Promise.all(src.map(m => this.import(m))); } switch(src) { - case this.__D3: condition = typeof d3 !== 'object'; break; case this.__TOGEOJSON: condition = typeof toGeoJSON !== 'object'; break; - case this.__LGEOMUTIL: condition = typeof L.GeometryUtil !== 'object'; break; - case this.__LALMOSTOVER: condition = typeof L.Handler.AlmostOver !== 'function'; break; case this.__LDISTANCEM: condition = typeof L.DistanceMarkers !== 'function'; break; case this.__LEDGESCALE: condition = typeof L.Control.EdgeScale !== 'function'; break; case this.__LHOTLINE: condition = typeof L.Hotline !== 'function'; break; @@ -245,7 +237,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ let container = this._container = _.create("div", "elevation-control " + this.options.theme + " " + (this.options.detached ? 'elevation-detached' : 'leaflet-control'), this.options.detached ? { id: 'elevation-' + _.randomId() } : {}); - if (!this.eleDiv) this.eleDiv = container; + this.eleDiv = container; this._loadModules(this.options.handlers).then(() => { // Inject here required modules (data handlers) this._initChart(container); @@ -257,6 +249,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this.fire('modules_loaded'); }); + + this.fire('add'); return container; @@ -362,6 +356,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this.fire("elepoint_added", { point: point, index: this._data.length - 1 }); + if (this._yCoordMin > this._data[this._data.length - 1][this.options.yAttr]) this._yCoordMin = this._data[this._data.length - 1][this.options.yAttr]; if (this._yCoordMax < this._data[this._data.length - 1][this.options.yAttr]) this._yCoordMax = this._data[this._data.length - 1][this.options.yAttr]; }); @@ -380,7 +375,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ x: x, y: y, z: z, - latlng: L.latLng(x, y, z) + latlng: new L.LatLng(x, y, z) }); this.fire("eledata_updated", { index: this._data.length - 1 }); @@ -402,31 +397,155 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ /** * Initialize "L.AlmostOver" integration + * + * Inspired by: https://github.com/makinacorpus/Leaflet.AlmostOver */ _initAlmostOverHandler(map, layer) { - return (map && this.options.almostOver && !L.Browser.mobile) ? this.import([this.__LGEOMUTIL, this.__LALMOSTOVER]) - .then(() => { - map.addHandler('almostOver', L.Handler.AlmostOver) - if (L.GeometryUtil && map.almostOver && map.almostOver.enabled()) { - map.almostOver.addLayer(layer); - map - .on('almost:move', this._onMouseMoveLayer, this) - .on('almost:out', this._onMouseOut, this); - this.once('eledata_clear', () => { - map.almostOver.removeLayer(layer); - map - .off('almost:move', this._onMouseMoveLayer, this) - .off('almost:out', this._onMouseOut, this); - }) + if (!map || !this.options.almostOver || L.Browser.mobile) return Promise.resolve(); + map.almostOver = map.almostOver || { + _map: map, + _projectedLayers: new WeakMap(), + _layers: [], + _previous: null, + _lastSample: 0, + enabled() { + return !!this._enabled; + }, + enable() { + if (this.enabled()) return; + this._enabled = true; + if (this._map.options.almostOnMouseMove !== false) this._map.on('mousemove', this._sampleMouseMove, this); + this._map.on('click dblclick', this._onMouseClick, this); + }, + disable() { + if (!this.enabled()) return; + this._map.off('mousemove', this._sampleMouseMove, this); + this._map.off('click dblclick', this._onMouseClick, this); + if (this._previous) this._map.fire('almost:out', { layer: this._previous.layer }); + this._previous = null; + this._enabled = false; + }, + addLayer(layer) { + if (layer.eachLayer) layer.eachLayer(child => this.addLayer(child)); + else if (!this._layers.includes(layer)) { + this._layers.push(layer); + this._projectedLayers.delete(layer); } - }) : Promise.resolve(); + }, + removeLayer(layer) { + if (layer.eachLayer) layer.eachLayer(child => this.removeLayer(child)); + else { + this._layers = this._layers.filter(item => item !== layer); + this._projectedLayers.delete(layer); + } + this._previous = null; + }, + getClosest(latlng) { + let closest; + const maxDistance = this._map.options.almostDistance ?? 25; + + const closestPointOnLayer = (map, layer, latlng, maxDistance, cache) => { + let closest; + const zoom = map.getZoom(); + const target = map.project(latlng, zoom); + + function checkPath(points) { + let closestSquared = closest ? closest.distance * closest.distance : maxDistance * maxDistance; + + for (let i = 1; i < points.length; i++) { + const start = points[i - 1]; + const end = points[i]; + const point = L.LineUtil.closestPointOnSegment(target, start, end); + const distanceSquared = (target.x - point.x) ** 2 + (target.y - point.y) ** 2; + + if (distanceSquared <= maxDistance * maxDistance && distanceSquared < closestSquared) { + closestSquared = distanceSquared; + closest = { + layer, + latlng: map.unproject(point, zoom), + distance: Math.sqrt(distanceSquared), + }; + } + } + } + if (layer.eachLayer) { + layer.eachLayer(child => { + const match = closestPointOnLayer(map, child, latlng, closest?.distance ?? maxDistance, cache); + if (match && (!closest || match.distance < closest.distance)) closest = match; + }); + } else if (layer.getLatLngs) { + const cached = cache.get(layer); + if (cached?.zoom === zoom) { + cached.paths.forEach(checkPath); + } else { + const paths = []; + const collectPaths = (coords) => { + if (!Array.isArray(coords)) return; + if (coords.length && Number.isFinite(coords[0]?.lat)) paths.push(coords.map(point => map.project(point, zoom))); + else coords.forEach(collectPaths); + } + collectPaths(layer.getLatLngs()); + cache.set(layer, { zoom, paths }); + paths.forEach(checkPath); + } + } + return closest; + } + + // ponytail: scans all route segments per sampled move; add a spatial index if large collections become slow. + for (const layer of this._layers) { + const match = closestPointOnLayer(this._map, layer, latlng, closest?.distance ?? maxDistance, this._projectedLayers); + if (match && (!closest || match.distance < closest.distance)) closest = match; + } + + return closest; + }, + _sampleMouseMove(event) { + const now = Date.now(); + if (this._map._animatingZoom || this._map._panAnim?._inProgress || + now - this._lastSample < (this._map.options.almostSamplingPeriod ?? 50) || !this._layers.length) return; + this._lastSample = now; + this._onMouseMove(event); + }, + _onMouseMove(event) { + const closest = this.getClosest(event.latlng); + if (closest) { + if (!this._previous || this._previous.layer !== closest.layer) { + if (this._previous) this._map.fire('almost:out', { layer: this._previous.layer }); + this._map.fire('almost:over', closest); + } + this._map.fire('almost:move', closest); + } else if (this._previous) { + this._map.fire('almost:out', { layer: this._previous.layer }); + } + this._previous = closest; + }, + _onMouseClick(event) { + const closest = this.getClosest(event.latlng); + if (closest) this._map.fire(`almost:${event.type}`, closest); + }, + }; + if (!map.almostOver.enabled() && map.options.almostOver !== false) map.almostOver.enable(); + if (map.almostOver.enabled()) { + map.almostOver.addLayer(layer); + map + .on('almost:move', this._onMouseMoveLayer, this) + .on('almost:out', this._onMouseOut, this); + this.once('eledata_clear', () => { + map.almostOver.removeLayer(layer); + map + .off('almost:move', this._onMouseMoveLayer, this) + .off('almost:out', this._onMouseOut, this); + }); + } + return Promise.resolve(); }, /** * Initialize "L.DistanceMarkers" integration */ _initDistanceMarkers() { - return this.options.distanceMarkers ? this.import([this.__LGEOMUTIL, this.__LDISTANCEM]) : Promise.resolve(); + return this.options.distanceMarkers ? this.import(this.__LDISTANCEM) : Promise.resolve(); }, /** @@ -445,7 +564,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ .then(() => { layer.eachLayer((trkseg) => { if (trkseg.feature.geometry.type != "Point") { - let geo = L.geoJson(trkseg.toGeoJSON(), { coordsToLatLng: (coords) => L.latLng(coords[0], coords[1], coords[2] * (this.options.altitudeFactor || 1))}); + let geo = new L.GeoJSON(trkseg.toGeoJSON(), { coordsToLatLng: (coords) => new L.LatLng(coords[0], coords[1], coords[2] * (this.options.altitudeFactor || 1))}); let line = L.hotline(geo.toGeoJSON().features[0].geometry.coordinates, { renderer: L.Hotline.renderer(), min: isFinite(this.track_info[prop + '_min']) ? this.track_info[prop + '_min'] : 0, @@ -532,7 +651,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ let options = layer.options; - options.color = color.line || color.area || theme; + options.color = control._chartEnabled ? (color.line || color.area || theme) : '#000'; options.stroke = !!options.color; oldProto.call(this, ctx, layer); @@ -596,7 +715,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ * Hides the position/height indicator marker drawn onto the map */ _hideMarker() { - if (this.options.autohideMarker) { + if (this.options.autohideMarker && this._marker) { this._marker.remove(); } }, @@ -620,17 +739,15 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ } this - .import([this.__D3, this.__LCHART]) + .import(this.__LCHART) .then((m) => { - let chart = this._chart = new (m[1] || Elevation).Chart(opts, this); + let chart = this._chart = new (m || Elevation).Chart(opts, this); this._x = this._chart._x; this._y = this._chart._y; - d3 - .select(container) - .call(chart.render()) + chart.render()(container); chart .on('reset_drag', this._hideMarker, this) @@ -663,6 +780,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this._updateChart(); this._updateSummary(); + map.invalidateSize(); }); @@ -687,11 +805,11 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ } if (this._renderer) this._renderer.remove() - this._renderer = L.svg({ pane: "elevationPane" }).addTo(this._map); // default leaflet svg renderer + this._renderer = new L.SVG({ pane: "elevationPane" }).addTo(this._map); // default leaflet svg renderer - this.import([this.__D3, this.__LMARKER]) + this.import(this.__LMARKER) .then((m) => { - this._marker = new (m[1] || Elevation).Marker(this.options, this); + this._marker = new (m || Elevation).Marker(this.options, this); this.fire("elechart_marker"); }); }, @@ -724,10 +842,12 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ _initSummary(container) { this.import(this.__LSUMMARY).then((m)=>{ this._summary = new (m || Elevation).Summary({ summary: this.options.summary }, this); - - this.on('elechart_init', () => { - d3.select(container).call(this._summary.render()); - }); + const render = () => { + this._summary.render()(container); + this._updateSummary(); + }; + if (this._chart && container.contains(this._chart._container)) render(); + else this.once('elechart_init', render); }); }, @@ -768,7 +888,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ */ _loadLayer(geojson) { let { polyline, theme, waypoints, wptIcons, wptLabels, distanceMarkers } = this.options; - let style = L.extend({}, polyline); + let style = Object.assign({}, polyline); + let dataAdded = []; if (theme) { style.className += ' ' + theme; @@ -778,7 +899,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this.track_info.name = geojson.name; } - let layer = L.geoJson(geojson, { + let layer = new L.GeoJSON(geojson, { distanceMarkers: distanceMarkers, style: style, pointToLayer: (feature, latlng) => { @@ -797,16 +918,16 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ if ([true, 'markers'].includes(waypoints) && wptIcons != false) { return this._registerMarker({ latlng : latlng, - sym : (sym ?? name).replace(' ', '-').replace('"', '').replace("'", '').toLowerCase(), + sym : (sym ?? name).replace(/["']/g, '').replace(/ /g, '-').toLowerCase(), content: [true, 'markers'].includes(wptLabels) && (name || desc) && decodeURI("<b>" + name + "</b>" + (desc.length > 0 ? '<br>' + desc : '')) }); } } }, - onEachFeature: (feature, layer) => feature.geometry && feature.geometry.type != 'Point' && this.addData(feature, layer), + onEachFeature: (feature, layer) => feature.geometry && feature.geometry.type != 'Point' && dataAdded.push(this.addData(feature, layer)), }); - this.import(this.__D3).then(() => { + Promise.all(dataAdded).then(() => { this._initMapIntegrations(layer); const event_data = { data: geojson, layer: layer, name: this.track_info.name, track_info: this.track_info }; if (this._modulesLoaded) { @@ -821,7 +942,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ _onDragEnd({ dragstart, dragend}) { this._hideMarker(); - this.fitBounds(L.latLngBounds([dragstart.latlng, dragend.latlng])); + this.fitBounds(new L.LatLngBounds([dragstart.latlng, dragend.latlng])); this.fire("elechart_dragged"); }, @@ -910,7 +1031,10 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this._chartEnabled = this._chart._hasActiveLayers(); // toggle layer visibility on empty chart - this._layers.eachLayer(layer => _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled)); + this._layers.eachLayer(layer => { + _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled); + if (layer._renderer instanceof L.Canvas) layer.redraw(); + }); // toggle option value (eg. altitude = { 'disabled' || 'enabled' }) this.options[name] = !enabled && this.options[name] == 'disabled' ? 'enabled' : 'disabled'; @@ -1130,20 +1254,20 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ }); if (grid) { - this._registerAxisGrid(L.extend({ name }, grid)); + this._registerAxisGrid(Object.assign({ name }, grid)); } if (this.options[name] !== "summary") { - if (scale) this._registerAxisScale(L.extend({ name, label: unit }, scale)); - if (path) this._registerAreaPath(L.extend({ name }, path)); + if (scale) this._registerAxisScale(Object.assign({ name, label: unit }, scale)); + if (path) this._registerAreaPath(Object.assign({ name }, path)); } if (tooltip || props.tooltips) { - _.each([tooltip, ...(props.tooltips || [])], t => t && this._registerTooltip(L.extend({ name }, t))); + _.each([tooltip, ...(props.tooltips || [])], t => t && this._registerTooltip(Object.assign({ name }, t))); } if (summary) { - _.each(summary, (s, k) => summary[k] = L.extend({ unit }, s)); + _.each(summary, (s, k) => summary[k] = Object.assign({ unit }, s)); this._registerSummary(summary); } } @@ -1153,9 +1277,9 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ let { wptIcons } = this.options; // generate and cache appropriate icon symbol if (!wptIcons.hasOwnProperty(sym)) { - wptIcons[sym] = L.divIcon(L.extend({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )); + wptIcons[sym] = new L.DivIcon(Object.assign({}, wptIcons[""].options, { html: '<i class="elevation-waypoint-icon ' + sym + '"></i>' } )); } - let marker = L.marker(latlng, { icon: wptIcons[sym] }); + let marker = new L.Marker(latlng, { icon: wptIcons[sym] }); if (content) { marker.bindPopup(content, { className: 'elevation-popup', keepInView: true }).openPopup(); marker.bindTooltip(content, { className: 'elevation-tooltip', direction: 'auto', sticky: true, opacity: 1 }).openTooltip(); @@ -1167,8 +1291,8 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ * Add chart or marker tooltip info */ _registerTooltip(props) { - props.chart && this.on("elechart_init", () => this._chart._registerTooltip(L.extend({}, props, { value: props.chart }))); - props.marker && this.on("elechart_marker", () => this._marker._registerTooltip(L.extend({}, props, { value: props.marker }))); + props.chart && this.on("elechart_init", () => this._chart._registerTooltip(Object.assign({}, props, { value: props.chart }))); + props.marker && this.on("elechart_marker", () => this._marker._registerTooltip(Object.assign({}, props, { value: props.marker }))); }, /** @@ -1262,6 +1386,7 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ this._marker.update({ map : this._map, item : item, + yCoordMin : this._yCoordMin, yCoordMax : this._yCoordMax || 0, options : this.options }); @@ -1333,3 +1458,12 @@ export const Elevation = L.Control.Elevation = L.Control.extend({ }, }); + +// backcomp for leaflet v1 +if (!('on' in Elevation.prototype)) { + for (const name of Object.getOwnPropertyNames(L.Evented.prototype)) { + if (name !== 'constructor') { + Object.defineProperty(Elevation.prototype, name, Object.getOwnPropertyDescriptor(L.Evented.prototype, name)); + } + } +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js b/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js index 9b31b5c..dfb775d 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js @@ -1,64 +1,64 @@ -export function Acceleration() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let acceleration = {};
-
- acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²');
- opts.accelerationFactor = opts.accelerationFactor || 1;
-
- return {
- name: 'acceleration',
- unit: acceleration.label,
- deltaMax: this.options.accelerationDeltaMax,
- clampRange: this.options.accelerationRange,
- decimals: 2,
- pointToAttr: (_, i) => {
- let dv = (this._data[i].speed - this._data[i > 0 ? i - 1 : i].speed) * (1000 / opts.timeFactor);
- let dt = (this._data[i].time - this._data[i > 0 ? i - 1 : i].time) / 1000;
- return dt > 0 ? Math.abs((dv / dt)) * opts.accelerationFactor : NaN;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale: {
- axis : "y",
- position : "right",
- scale : { min: 0, max: +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: {
- label : 'Acceleration',
- yAttr : 'acceleration',
- scaleX : 'distance',
- scaleY : 'acceleration',
- color : '#050402',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: {
- chart: (item) => L._("a: ") + item.acceleration + " " + acceleration.label,
- marker: (item) => Math.round(item.acceleration) + " " + acceleration.label,
- order: 60,
- },
- summary: {
- "minacceleration" : {
- label: "Min Acceleration: ",
- value: (track, unit) => Math.round(track.acceleration_min || 0) + ' ' + unit,
- order: 60
- },
- "maxacceleration" : {
- label: "Max Acceleration: ",
- value: (track, unit) => Math.round(track.acceleration_max || 0) + ' ' + unit,
- order: 61
- },
- "avgacceleration": {
- label: "Avg Acceleration: ",
- value: (track, unit) => Math.round(track.acceleration_avg || 0) + ' ' + unit,
- order: 62
- },
- }
- };
-}
+export function Acceleration() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let acceleration = {}; + + acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²'); + opts.accelerationFactor = opts.accelerationFactor || 1; + + return { + name: 'acceleration', + unit: acceleration.label, + deltaMax: this.options.accelerationDeltaMax, + clampRange: this.options.accelerationRange, + decimals: 2, + pointToAttr: (_, i) => { + let dv = (this._data[i].speed - this._data[i > 0 ? i - 1 : i].speed) * (1000 / opts.timeFactor); + let dt = (this._data[i].time - this._data[i > 0 ? i - 1 : i].time) / 1000; + return dt > 0 ? Math.abs((dv / dt)) * opts.accelerationFactor : NaN; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale: { + axis : "y", + position : "right", + scale : { min: 0, max: +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: { + label : 'Acceleration', + yAttr : 'acceleration', + scaleX : 'distance', + scaleY : 'acceleration', + color : '#050402', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: { + chart: (item) => L._("a: ") + item.acceleration + " " + acceleration.label, + marker: (item) => Math.round(item.acceleration) + " " + acceleration.label, + order: 60, + }, + summary: { + "minacceleration" : { + label: "Min Acceleration: ", + value: (track, unit) => Math.round(track.acceleration_min || 0) + ' ' + unit, + order: 60 + }, + "maxacceleration" : { + label: "Max Acceleration: ", + value: (track, unit) => Math.round(track.acceleration_max || 0) + ' ' + unit, + order: 61 + }, + "avgacceleration": { + label: "Avg Acceleration: ", + value: (track, unit) => Math.round(track.acceleration_avg || 0) + ' ' + unit, + order: 62 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js b/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js index b7fe6e3..5f6d6c8 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js @@ -1,78 +1,78 @@ -export function Altitude() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let altitude = {};
-
- let theme = opts.theme.split(' ')[0].replace('-theme', '');
- let color = _.Colors[theme] || {};
-
- opts.altitudeFactor = opts.imperial ? this.__footFactor : (opts.altitudeFactor || 1); // 1 m = (1 m)
- altitude.label = opts.imperial ? "ft" : opts.yLabel;
-
- return {
- name: 'altitude',
- required: this.options.slope,
- meta: 'z',
- unit: altitude.label,
- statsName: 'elevation',
- deltaMax: this.options.altitudeDeltaMax,
- clampRange: this.options.altitudeRange,
- // init: ({point}) => {
- // // "alt" property is generated inside "leaflet"
- // if ("alt" in point) point.meta.ele = point.alt;
- // },
- pointToAttr: (point, i) => {
- if ("alt" in point) point.meta.ele = point.alt; // "alt" property is generated inside "leaflet"
- return this._data[i].z *= opts.altitudeFactor;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- grid: {
- axis : "y",
- position : "left",
- scale : "y" // this._chart._y,
- },
- scale: {
- axis : "y",
- position: "left",
- scale : "y", // this._chart._y,
- labelX : -3,
- labelY : -8,
- },
- path: {
- label : 'Altitude',
- scaleX : 'distance',
- scaleY : 'altitude',
- className : 'area',
- color : color.area || theme,
- strokeColor : opts.detached ? color.stroke : '#000',
- strokeOpacity: "1",
- fillOpacity : opts.detached ? (color.alpha || '0.8') : 1,
- preferCanvas : opts.preferCanvas,
- },
- tooltip: {
- name: 'y',
- chart: (item) => L._("y: ") + _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label,
- marker: (item) => _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label,
- order: 10,
- },
- summary: {
- "minele" : {
- label: "Min Elevation: ",
- value: (track, unit) => (track.elevation_min || 0).toFixed(2) + ' ' + unit,
- order: 30,
- },
- "maxele" : {
- label: "Max Elevation: ",
- value: (track, unit) => (track.elevation_max || 0).toFixed(2) + ' ' + unit,
- order: 31,
- },
- "avgele" : {
- label: "Avg Elevation: ",
- value: (track, unit) => (track.elevation_avg || 0).toFixed(2) + ' ' + unit,
- order: 32,
- },
- }
- };
-}
+export function Altitude() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let altitude = {}; + + let theme = opts.theme.split(' ')[0].replace('-theme', ''); + let color = _.Colors[theme] || {}; + + opts.altitudeFactor = opts.imperial ? this.__footFactor : (opts.altitudeFactor || 1); // 1 m = (1 m) + altitude.label = opts.imperial ? "ft" : opts.yLabel; + + return { + name: 'altitude', + required: this.options.slope, + meta: 'z', + unit: altitude.label, + statsName: 'elevation', + deltaMax: this.options.altitudeDeltaMax, + clampRange: this.options.altitudeRange, + // init: ({point}) => { + // // "alt" property is generated inside "leaflet" + // if ("alt" in point) point.meta.ele = point.alt; + // }, + pointToAttr: (point, i) => { + if ("alt" in point) point.meta.ele = point.alt; // "alt" property is generated inside "leaflet" + return this._data[i].z *= opts.altitudeFactor; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + grid: { + axis : "y", + position : "left", + scale : "y" // this._chart._y, + }, + scale: { + axis : "y", + position: "left", + scale : "y", // this._chart._y, + labelX : -3, + labelY : -8, + }, + path: { + label : 'Altitude', + scaleX : 'distance', + scaleY : 'altitude', + className : 'area', + color : color.area || theme, + strokeColor : opts.detached ? color.stroke : '#000', + strokeOpacity: "1", + fillOpacity : opts.detached ? (color.alpha || '0.8') : 1, + preferCanvas : opts.preferCanvas, + }, + tooltip: { + name: 'y', + chart: (item) => L._("y: ") + _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label, + marker: (item) => _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label, + order: 10, + }, + summary: { + "minele" : { + label: "Min Elevation: ", + value: (track, unit) => (track.elevation_min || 0).toFixed(2) + ' ' + unit, + order: 30, + }, + "maxele" : { + label: "Max Elevation: ", + value: (track, unit) => (track.elevation_max || 0).toFixed(2) + ' ' + unit, + order: 31, + }, + "avgele" : { + label: "Avg Elevation: ", + value: (track, unit) => (track.elevation_avg || 0).toFixed(2) + ' ' + unit, + order: 32, + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js b/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js index 0ad7704..db1a6d7 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js @@ -1,54 +1,54 @@ -export function Cadence() {
-
- const _ = L.Control.Elevation.Utils;
-
- return {
- name: 'cadence', // <-- Your custom option name (eg. "cadence: true")
- unit: 'rpm',
- meta: 'cad', // <-- point.meta.cad
- coordinateProperties: ["cads", "cadences", "cad", "cadence"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON"
- pointToAttr: (point, i) => (point.cad ?? point.meta.cad ?? point.prev('cadence')) || 0,
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale: {
- axis : "y",
- position : "right",
- scale : { min: -1, max: +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: {
- label : 'RPM',
- yAttr : 'cadence',
- scaleX : 'distance',
- scaleY : 'cadence',
- color : '#FFF',
- strokeColor : 'blue',
- strokeOpacity: "0.85",
- fillOpacity : "0.1",
- },
- tooltip: {
- name: 'cadence',
- chart: (item) => L._("cad: ") + item.cadence + " " + 'rpm',
- marker: (item) => Math.round(item.cadence) + " " + 'rpm',
- order: 1
- },
- summary: {
- "minrpm": {
- label: "Min RPM: ",
- value: (track, unit) => Math.round(track.cadence_min || 0) + ' ' + unit,
- // order: 30
- },
- "maxrpm": {
- label: "Max RPM: ",
- value: (track, unit) => Math.round(track.cadence_max || 0) + ' ' + unit,
- // order: 30
- },
- "avgrpm": {
- label: "Avg RPM: ",
- value: (track, unit) => Math.round(track.cadence_avg || 0) + ' ' + unit,
- // order: 20
- },
- }
- };
+export function Cadence() { + + const _ = L.Control.Elevation.Utils; + + return { + name: 'cadence', // <-- Your custom option name (eg. "cadence: true") + unit: 'rpm', + meta: 'cad', // <-- point.meta.cad + coordinateProperties: ["cads", "cadences", "cad", "cadence"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON" + pointToAttr: (point, i) => (point.cad ?? point.meta.cad ?? point.prev('cadence')) || 0, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale: { + axis : "y", + position : "right", + scale : { min: -1, max: +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: { + label : 'RPM', + yAttr : 'cadence', + scaleX : 'distance', + scaleY : 'cadence', + color : '#FFF', + strokeColor : 'blue', + strokeOpacity: "0.85", + fillOpacity : "0.1", + }, + tooltip: { + name: 'cadence', + chart: (item) => L._("cad: ") + item.cadence + " " + 'rpm', + marker: (item) => Math.round(item.cadence) + " " + 'rpm', + order: 1 + }, + summary: { + "minrpm": { + label: "Min RPM: ", + value: (track, unit) => Math.round(track.cadence_min || 0) + ' ' + unit, + // order: 30 + }, + "maxrpm": { + label: "Max RPM: ", + value: (track, unit) => Math.round(track.cadence_max || 0) + ' ' + unit, + // order: 30 + }, + "avgrpm": { + label: "Avg RPM: ", + value: (track, unit) => Math.round(track.cadence_avg || 0) + ' ' + unit, + // order: 20 + }, + } + }; }
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/heart.js b/assets/static/vendor/leaflet-elevation/src/handlers/heart.js index 1930f60..1e81b3a 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/heart.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/heart.js @@ -1,53 +1,53 @@ -export function Heart() {
-
- const _ = L.Control.Elevation.Utils;
-
- return {
- name: 'heart', // <-- Your custom option name (eg. "heart: true")
- unit: 'bpm',
- meta: 'hr', // <-- point.meta.hr
- coordinateProperties: ["heart", "heartRates", "heartRate"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON"
- pointToAttr: (point, i) => (point.hr ?? point.meta.hr ?? point.prev('heart')) || 0,
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale: {
- axis : "y",
- position : "left",
- scale : { min: -1, max: +1 },
- tickPadding: 25,
- labelX : -30,
- labelY : -8,
- },
- path: {
- label : 'ECG',
- yAttr : 'heart',
- scaleX : 'distance',
- scaleY : 'heart',
- color : 'white',
- strokeColor : 'red',
- strokeOpacity: "0.85",
- fillOpacity : "0.1",
- },
- tooltip: {
- chart: (item) => L._("hr: ") + item.heart + " " + 'bpm',
- marker: (item) => Math.round(item.heart) + " " + 'bpm',
- order: 1
- },
- summary: {
- "minbpm": {
- label: "Min BPM: ",
- value: (track, unit) => Math.round(track.heart_min || 0) + ' ' + unit,
- // order: 30
- },
- "maxbpm": {
- label: "Max BPM: ",
- value: (track, unit) => Math.round(track.heart_max || 0) + ' ' + unit,
- // order: 30
- },
- "avgbpm": {
- label: "Avg BPM: ",
- value: (track, unit) => Math.round(track.heart_avg || 0) + ' ' + unit,
- // order: 20
- },
- }
- };
+export function Heart() { + + const _ = L.Control.Elevation.Utils; + + return { + name: 'heart', // <-- Your custom option name (eg. "heart: true") + unit: 'bpm', + meta: 'hr', // <-- point.meta.hr + coordinateProperties: ["heart", "heartRates", "heartRate"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON" + pointToAttr: (point, i) => (point.hr ?? point.meta.hr ?? point.prev('heart')) || 0, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale: { + axis : "y", + position : "left", + scale : { min: -1, max: +1 }, + tickPadding: 25, + labelX : -30, + labelY : -8, + }, + path: { + label : 'ECG', + yAttr : 'heart', + scaleX : 'distance', + scaleY : 'heart', + color : 'white', + strokeColor : 'red', + strokeOpacity: "0.85", + fillOpacity : "0.1", + }, + tooltip: { + chart: (item) => L._("hr: ") + item.heart + " " + 'bpm', + marker: (item) => Math.round(item.heart) + " " + 'bpm', + order: 1 + }, + summary: { + "minbpm": { + label: "Min BPM: ", + value: (track, unit) => Math.round(track.heart_min || 0) + ' ' + unit, + // order: 30 + }, + "maxbpm": { + label: "Max BPM: ", + value: (track, unit) => Math.round(track.heart_max || 0) + ' ' + unit, + // order: 30 + }, + "avgbpm": { + label: "Avg BPM: ", + value: (track, unit) => Math.round(track.heart_avg || 0) + ' ' + unit, + // order: 20 + }, + } + }; };
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/labels.js b/assets/static/vendor/leaflet-elevation/src/handlers/labels.js index 31b3cd6..4deb0c7 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/labels.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/labels.js @@ -17,25 +17,24 @@ export function Labels() { if (90 == Math.abs(textRotation)) { - pointG.selectAll('text') - .attr('dy', '4px') - .attr("dx", (d, i, el) => Math.sign(textRotation) * (this._height() - d3.select(el[i].parentElement).datum().y - 8) + 'px') - .attr('text-anchor', textRotation > 0 ? 'end' : 'start') - .attr('transform', 'rotate(' + textRotation + ')') + pointG.querySelectorAll('text').forEach(text => L.Control.Elevation.Utils.setAttributes(text, { + dy: '4px', + dx: Math.sign(textRotation) * (this._height() - Number(text.parentElement.dataset.y) - 8) + 'px', + 'text-anchor': textRotation > 0 ? 'end' : 'start', + transform: 'rotate(' + textRotation + ')', + })); - pointG.selectAll('circle') - .attr('r', '2.5') - .attr('fill', '#fff') - .attr("stroke", '#000') - .attr("stroke-width", '1.1'); + pointG.querySelectorAll('circle').forEach(circle => L.Control.Elevation.Utils.setAttributes(circle, { + r: 2.5, fill: '#fff', stroke: '#000', 'stroke-width': 1.1, + })); } else if (!isNaN(textRotation)) { - pointG.selectAll('text') - .attr("dx", "4px") - .attr("dy", "-9px") - .attr('text-anchor', textAnchor ?? (0 == textRotation ? 'start' : 'middle')) - .attr('transform', 'rotate('+ -textRotation +')') + pointG.querySelectorAll('text').forEach(text => L.Control.Elevation.Utils.setAttributes(text, { + dx: '4px', dy: '-9px', + 'text-anchor': textAnchor ?? (0 == textRotation ? 'start' : 'middle'), + transform: 'rotate(' + -textRotation + ')', + })); } diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js b/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js index 90e33ce..ccf5d73 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js @@ -16,6 +16,7 @@ * }, * }) * ``` + * `min` and `max` can also be numeric bounds. */ export function LinearGradient() { @@ -60,7 +61,7 @@ export function LinearGradient() { }; const { preferCanvas } = this.options; - const { attr, path: path_name, range, min, max } = L.extend({ + const { attr, path: path_name, range, min, max } = Object.assign({ attr: 'z', path: 'altitude', range: { 0.0: '#008800', 0.5: '#ffff00', 1.0: '#ff0000' }, @@ -80,8 +81,8 @@ export function LinearGradient() { const { defs } = chart._chart.utils; const palette = get_palette({ - min: isFinite(this.track_info[min]) ? this.track_info[min] : 0, - max: isFinite(this.track_info[max]) ? this.track_info[max] : 1, + min: isFinite(min) ? Number(min) : (isFinite(this.track_info[min]) ? this.track_info[min] : 0), + max: isFinite(max) ? Number(max) : (isFinite(this.track_info[max]) ? this.track_info[max] : 1), range, }); @@ -91,15 +92,22 @@ export function LinearGradient() { /** ref: `path.__fillStyle` within L.Control.Elevation.Utils::drawCanvas(ctx, path) */ path.__fillStyle = gradient = chart._context.createLinearGradient(0, 0, chart._width(), 0); } else { - defs.select('#' + gradient_id).remove(); - gradient = defs.append('svg:linearGradient').attr('id', gradient_id); - gradient.addColorStop = function(offset, color) { gradient.append('svg:stop').attr('offset', offset).attr('stop-color', color) }; - path.attr('fill', 'url(#' + gradient_id + ')').classed('area', false); + defs.querySelector('#' + gradient_id)?.remove(); + gradient = _.create('svg:linearGradient', '', { id: gradient_id }, defs); + gradient.addColorStop = (offset, color) => _.create('svg:stop', '', { offset, 'stop-color': color }, gradient); + path.setAttribute('fill', 'url(#' + gradient_id + ')'); + path.classList.remove('area'); } // Generate gradient for each segment picking colors from palette - for (let i = 0, data = this._data; i < data.length; i++) { - gradient.addColorStop((i) / data.length, palette.getRGBColor(data[i][attr])); + const data = this._data; + const xAttr = chart._props.areas[path_name].xAttr; + const minX = data[0][xAttr]; + const xRange = data[data.length - 1][xAttr] - minX; + + for (let i = 0; i < data.length; i++) { + const offset = xRange ? (data[i][xAttr] - minX) / xRange : 0; + gradient.addColorStop(offset, palette.getRGBColor(data[i][attr])); } }); @@ -108,14 +116,15 @@ export function LinearGradient() { this.on('elechart_updated', () => { const chart = this._chart; const { defs } = chart._chart.utils; - defs.select('#' + legend_id).remove(); - const legendGradient = defs.append('svg:linearGradient').attr('id', legend_id); - Object.keys(range).sort().forEach(i => legendGradient.append('svg:stop').attr('offset', i).attr('stop-color', range[i])); + defs.querySelector('#' + legend_id)?.remove(); + const legendGradient = _.create('svg:linearGradient', '', { id: legend_id }, defs); + Object.keys(range).sort().forEach(i => _.create('svg:stop', '', { offset: i, 'stop-color': range[i] }, legendGradient)); - chart._container - .select('.legend-' + path_name + ' > rect') - .attr('fill', 'url(#' + legend_id + ')') - .classed('area', false); + const rect = chart._container.querySelector('.legend-' + path_name + ' > rect'); + if (rect) { + rect.setAttribute('fill', 'url(#' + legend_id + ')'); + rect.classList.remove('area'); + } }); return { }; diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/pace.js b/assets/static/vendor/leaflet-elevation/src/handlers/pace.js index 9017f39..7f0c260 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/pace.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/pace.js @@ -1,65 +1,65 @@ -export function Pace() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let pace = {};
-
- pace.label = opts.paceLabel || L._(opts.imperial ? 'min/mi' : 'min/km');
- opts.paceFactor = opts.paceFactor || 60; // 1 min = 60 sec
-
- return {
- name: 'pace',
- unit: pace.label,
- deltaMax: this.options.paceDeltaMax,
- clampRange: this.options.paceRange,
- decimals: 2,
- pointToAttr: (_, i) => {
- let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
- let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
- return dx > 0 ? Math.abs((dt / dx) / opts.paceFactor) : NaN;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale : (this.options.pace && this.options.pace != "summary") && {
- axis : "y",
- position : "right",
- scale : { min : 0, max : +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: (this.options.pace && this.options.pace != "summary") && {
- // name : 'pace',
- label : 'Pace',
- yAttr : "pace",
- scaleX : 'distance',
- scaleY : 'pace',
- color : '#03ffff',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: (this.options.pace) && {
- chart: (item) => L._('pace: ') + item.pace + " " + pace.label,
- marker: (item) => Math.round(item.pace) + " " + pace.label,
- order: 50,
- },
- summary: (this.options.pace) && {
- "minpace" : {
- label: "Min Pace: ",
- value: (track, unit) => Math.round(track.pace_min || 0) + ' ' + unit,
- order: 51
- },
- "maxpace" : {
- label: "Max Pace: ",
- value: (track, unit) => Math.round(track.pace_max || 0) + ' ' + unit,
- order: 51
- },
- "avgpace": {
- label: "Avg Pace: ",
- value: (track, unit) => Math.round(track.pace_avg || 0) + ' ' + unit,
- order: 52
- },
- }
- };
-}
+export function Pace() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let pace = {}; + + pace.label = opts.paceLabel || L._(opts.imperial ? 'min/mi' : 'min/km'); + opts.paceFactor = opts.paceFactor || 60; // 1 min = 60 sec + + return { + name: 'pace', + unit: pace.label, + deltaMax: this.options.paceDeltaMax, + clampRange: this.options.paceRange, + decimals: 2, + pointToAttr: (_, i) => { + let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000; + let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time; + return dx > 0 ? Math.abs((dt / dx) / opts.paceFactor) : NaN; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale : (this.options.pace && this.options.pace != "summary") && { + axis : "y", + position : "right", + scale : { min : 0, max : +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: (this.options.pace && this.options.pace != "summary") && { + // name : 'pace', + label : 'Pace', + yAttr : "pace", + scaleX : 'distance', + scaleY : 'pace', + color : '#03ffff', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: (this.options.pace) && { + chart: (item) => L._('pace: ') + item.pace + " " + pace.label, + marker: (item) => Math.round(item.pace) + " " + pace.label, + order: 50, + }, + summary: (this.options.pace) && { + "minpace" : { + label: "Min Pace: ", + value: (track, unit) => Math.round(track.pace_min || 0) + ' ' + unit, + order: 51 + }, + "maxpace" : { + label: "Max Pace: ", + value: (track, unit) => Math.round(track.pace_max || 0) + ' ' + unit, + order: 51 + }, + "avgpace": { + label: "Avg Pace: ", + value: (track, unit) => Math.round(track.pace_avg || 0) + ' ' + unit, + order: 52 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/runner.js b/assets/static/vendor/leaflet-elevation/src/handlers/runner.js index 30dd80a..8135edd 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/runner.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/runner.js @@ -1,18 +1,20 @@ /** - * @see https://github.com/Igor-Vladyka/leaflet.motion + * Animate a track with requestAnimationFrame; motion speed is in km/h and duration in ms. * + * Inspired by: https://github.com/Igor-Vladyka/leaflet.motion + * * @example * ```js * L.control.Elevation({ handlers: [ 'Runner' ], runnerOptions: { polyline: {..}, motion: {..}, marker {..} } }) * ``` */ -export async function Runner() { +export function Runner() { - await this.import(this.__LMOTION || 'https://unpkg.com/leaflet.motion@0.3.2/dist/leaflet.motion.min.js', typeof L.Motion !== 'object') + const _ = L.Control.Elevation.Utils; let { runnerOptions } = this.options; - runnerOptions = L.extend( + runnerOptions = Object.assign( { polyline: {}, motion: {}, marker: undefined }, 'object' === typeof runnerOptions ? runnerOptions : {} ); @@ -40,13 +42,10 @@ export async function Runner() { this.addRunner = function (runner) { let x = this._x(runner.dist); let y = this._y(this._findItemForX(x).z) - let g = d3.select(this._container) - .select('svg > g') - .append("svg:circle") - .attr("class", "runner " + this.options.theme + " height-focus circle-lower") - .attr("r", 6) - .attr("cx", x) - .attr("cy", y); + let g = _.create('svg:circle', '', { + class: "runner " + this.options.theme + " height-focus circle-lower", + r: 6, cx: x, cy: y, + }, this._container.querySelector('svg > g')); return g; } @@ -71,13 +70,36 @@ export async function Runner() { curr = this._findItemForX(x); } - runner - .attr("cx", x) - .attr("cy", this._y(curr.z)); + runner.setAttribute("cx", x); + runner.setAttribute("cy", this._y(curr.z)); this.setPositionFromLatLng(curr.latlng); }; this.animate = function (layer, speed = 1500) { + const latlngs = []; + const collect = segment => { + if (segment instanceof L.Polyline) { + const append = points => { + if (L.LineUtil.isFlat(points)) latlngs.push(...points); + else points.forEach(append); + }; + append(segment.getLatLngs()); + } else if (segment.eachLayer) segment.eachLayer(collect); + }; + collect(layer); + if (!latlngs.length) throw new Error('The runner requires a track with coordinates.'); + + const distances = [0]; + for (let i = 1; i < latlngs.length; i++) { + distances.push(distances[i - 1] + latlngs[i - 1].distanceTo(latlngs[i])); + } + const length = distances[distances.length - 1]; + const motion = Object.assign({ auto: true, speed, easing: value => value }, runnerOptions.motion); + const duration = motion.duration || (motion.speed ? length / motion.speed * 3600 : 0); + if (!Number.isFinite(duration) || duration < 0 || !Number.isFinite(motion.speed) || motion.speed < 0) { + throw new Error('Runner speed and duration must be finite, non-negative numbers.'); + } + if (typeof motion.easing !== 'function') throw new Error('Runner easing must be a function.'); if (this._runner) { this._runner.remove(); @@ -85,24 +107,75 @@ export async function Runner() { layer.setStyle({ opacity: 0.5 }); - const geo = L.geoJson(layer.toGeoJSON(), { coordsToLatLng: (coords) => L.latLng(coords[0], coords[1], coords[2] * (this.options.altitudeFactor || 1)) }); - this._runner = L.motion.polyline( - geo.toGeoJSON().features[0].geometry.coordinates, - L.extend({}, { color: 'red', pane: 'elevationPane', attribution: '' }, runnerOptions.polyline), - L.extend({}, { auto: true, speed: speed, }, runnerOptions.motion), - runnerOptions.marker || undefined - ); + const runner = this._runner = new L.Polyline([], Object.assign( + { color: 'red', pane: 'elevationPane', attribution: '' }, runnerOptions.polyline + )); + const marker = runnerOptions.marker ? new L.Marker(latlngs[0], runnerOptions.marker) : null; + let circle; + let frame; + let started; + let elapsed = 0; + let running = false; - // Override default function behavior: `L.Motion.Polyline::_drawMarker()` - this._runner._drawMarker = new Proxy(this._runner._drawMarker, { - apply: (target, thisArg, argArray) => { - thisArg._runner = thisArg._runner || this.addRunner({ dist: 0 }); - this.updateRunnerPos(thisArg._runner, argArray[0]); - return target.apply(thisArg, argArray); + const draw = progress => { + const distance = length * progress; + let index = 1; + while (index < distances.length - 1 && distances[index] < distance) index++; + index = Math.min(index, latlngs.length - 1); + const previous = Math.max(0, index - 1); + const segmentLength = distances[index] - distances[previous]; + const ratio = segmentLength ? (distance - distances[previous]) / segmentLength : 0; + const from = this._map.project(latlngs[previous]); + const to = this._map.project(latlngs[index]); + const position = this._map.unproject(from.add(to.subtract(from).multiplyBy(ratio))); + runner.setLatLngs([...latlngs.slice(0, index), position]); + circle = circle || this.addRunner({ dist: 0 }); + this.updateRunnerPos(circle, position); + if (marker) marker.setLatLng(position).addTo(this._map); + }; + const advance = timestamp => { + started = started ?? timestamp - elapsed; + elapsed = timestamp - started; + const progress = duration ? Math.min(1, elapsed / duration) : 1; + draw(progress === 1 ? 1 : Math.max(0, Math.min(1, motion.easing(progress, elapsed, 0, 1, duration)))); + if (progress < 1) frame = requestAnimationFrame(advance); + else { + running = false; + if (runnerOptions.marker?.removeOnEnd) marker.remove(); + runner.fire('motion-ended', { layer: runner }); } + }; + runner.motionPause = () => { + cancelAnimationFrame(frame); + running = false; + started = undefined; + return runner; + }; + runner.motionResume = () => { + if (!running && runner._map) { + running = true; + frame = requestAnimationFrame(advance); + } + return runner; + }; + runner.motionStart = () => { + runner.motionPause(); + elapsed = 0; + return runner.motionResume(); + }; + runner.getMarker = () => marker; + runner.on('remove', () => { + runner.motionPause(); + circle?.remove(); + marker?.remove(); + this.off('eledata_clear', remove); + this.off('remove', remove); }); - - this._runner.addTo(this._map); + const remove = () => runner.remove(); + this.on('eledata_clear', remove); + this.on('remove', remove); + runner.addTo(this._map); + if (motion.auto) runner.motionStart(); }; return {}; diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/slope.js b/assets/static/vendor/leaflet-elevation/src/handlers/slope.js index 37291b3..1ed65af 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/slope.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/slope.js @@ -1,79 +1,79 @@ -export function Slope() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let slope = {};
-
- slope.label = opts.slopeLabel || '%';
-
- return {
- name: 'slope',
- meta: 'slope',
- unit: slope.label,
- deltaMax: this.options.slopedDeltaMax,
- clampRange: this.options.slopeRange,
- decimals: 2,
- pointToAttr: (_, i) => { // slope in % = ( dy / dx ) * 100;
- let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
- let dy = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
- return dx !== 0 ? (dy / dx) * 100 : NaN;
- },
- onPointAdded: (_, i) => {
- let dz = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
- if (dz > 0) this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent
- else if (dz < 0) this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg, },
- scale: {
- axis : "y",
- position : "right",
- scale : { min: -1, max: +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: {
- label : 'Slope',
- yAttr : 'slope',
- scaleX : 'distance',
- scaleY : 'slope',
- color : '#F00',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: {
- chart: (item) => L._("m: ") + item.slope + slope.label,
- marker: (item) => Math.round(item.slope) + slope.label,
- order: 40,
- },
- summary: {
- "minslope": {
- label: "Min Slope: ",
- value: (track, unit) => Math.round(track.slope_min || 0) + ' ' + unit,
- order: 40
- },
- "maxslope": {
- label: "Max Slope: ",
- value: (track, unit) => Math.round(track.slope_max || 0) + ' ' + unit,
- order: 41
- },
- "avgslope": {
- label: "Avg Slope: ",
- value: (track, unit) => Math.round(track.slope_avg || 0) + ' ' + unit,
- order: 42
- },
- "ascent" : {
- label: "Total Ascent: ",
- value: (track, unit) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
- order: 43
- },
- "descent" : {
- label: "Total Descent: ",
- value: (track, unit) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
- order: 45
- },
- }
- };
-}
+export function Slope() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let slope = {}; + + slope.label = opts.slopeLabel || '%'; + + return { + name: 'slope', + meta: 'slope', + unit: slope.label, + deltaMax: this.options.slopedDeltaMax, + clampRange: this.options.slopeRange, + decimals: 2, + pointToAttr: (_, i) => { // slope in % = ( dy / dx ) * 100; + let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000; + let dy = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr]; + return dx !== 0 ? (dy / dx) * 100 : NaN; + }, + onPointAdded: (_, i) => { + let dz = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr]; + if (dz > 0) this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent + else if (dz < 0) this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg, }, + scale: { + axis : "y", + position : "right", + scale : { min: -1, max: +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: { + label : 'Slope', + yAttr : 'slope', + scaleX : 'distance', + scaleY : 'slope', + color : '#F00', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: { + chart: (item) => L._("m: ") + item.slope + slope.label, + marker: (item) => Math.round(item.slope) + slope.label, + order: 40, + }, + summary: { + "minslope": { + label: "Min Slope: ", + value: (track, unit) => Math.round(track.slope_min || 0) + ' ' + unit, + order: 40 + }, + "maxslope": { + label: "Max Slope: ", + value: (track, unit) => Math.round(track.slope_max || 0) + ' ' + unit, + order: 41 + }, + "avgslope": { + label: "Avg Slope: ", + value: (track, unit) => Math.round(track.slope_avg || 0) + ' ' + unit, + order: 42 + }, + "ascent" : { + label: "Total Ascent: ", + value: (track, unit) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'), + order: 43 + }, + "descent" : { + label: "Total Descent: ", + value: (track, unit) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'), + order: 45 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/speed.js b/assets/static/vendor/leaflet-elevation/src/handlers/speed.js index 534b340..52068e8 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/speed.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/speed.js @@ -1,66 +1,66 @@ -export function Speed() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let speed = {};
-
- speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
- opts.speedFactor = opts.speedFactor || 1;
-
- return {
- name: 'speed',
- required: (this.options.acceleration),
- unit: speed.label,
- deltaMax: this.options.speedDeltaMax,
- clampRange: this.options.speedRange,
- decimals: 2,
- pointToAttr: (_, i) => {
- let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
- let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
- return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : NaN;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale : (this.options.speed && this.options.speed != "summary") && {
- axis : "y",
- position : "right",
- scale : { min : 0, max : +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: (this.options.speed && this.options.speed != "summary") && {
- // name : 'speed',
- label : 'Speed',
- yAttr : "speed",
- scaleX : 'distance',
- scaleY : 'speed',
- color : '#03ffff',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: (this.options.speed) && {
- chart: (item) => L._('v: ') + item.speed + " " + speed.label,
- marker: (item) => Math.round(item.speed) + " " + speed.label,
- order: 50,
- },
- summary: (this.options.speed) && {
- "minspeed" : {
- label: "Min Speed: ",
- value: (track, unit) => Math.round(track.speed_min || 0) + ' ' + unit,
- order: 51
- },
- "maxspeed" : {
- label: "Max Speed: ",
- value: (track, unit) => Math.round(track.speed_max || 0) + ' ' + unit,
- order: 51
- },
- "avgspeed": {
- label: "Avg Speed: ",
- value: (track, unit) => Math.round(track.speed_avg || 0) + ' ' + unit,
- order: 52
- },
- }
- };
-}
+export function Speed() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let speed = {}; + + speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h'); + opts.speedFactor = opts.speedFactor || 1; + + return { + name: 'speed', + required: (this.options.acceleration), + unit: speed.label, + deltaMax: this.options.speedDeltaMax, + clampRange: this.options.speedRange, + decimals: 2, + pointToAttr: (_, i) => { + let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000; + let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time; + return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : NaN; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale : (this.options.speed && this.options.speed != "summary") && { + axis : "y", + position : "right", + scale : { min : 0, max : +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: (this.options.speed && this.options.speed != "summary") && { + // name : 'speed', + label : 'Speed', + yAttr : "speed", + scaleX : 'distance', + scaleY : 'speed', + color : '#03ffff', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: (this.options.speed) && { + chart: (item) => L._('v: ') + item.speed + " " + speed.label, + marker: (item) => Math.round(item.speed) + " " + speed.label, + order: 50, + }, + summary: (this.options.speed) && { + "minspeed" : { + label: "Min Speed: ", + value: (track, unit) => Math.round(track.speed_min || 0) + ' ' + unit, + order: 51 + }, + "maxspeed" : { + label: "Max Speed: ", + value: (track, unit) => Math.round(track.speed_max || 0) + ' ' + unit, + order: 51 + }, + "avgspeed": { + label: "Avg Speed: ", + value: (track, unit) => Math.round(track.speed_avg || 0) + ' ' + unit, + order: 52 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/time.js b/assets/static/vendor/leaflet-elevation/src/handlers/time.js index d94b136..b1f08b8 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/time.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/time.js @@ -40,7 +40,7 @@ export function Time() { if (!point.meta || !point.meta.time) { point.meta = point.meta || {}; if (i > 0) { - let dx = (this._data[i].dist - this._data[i - 1].dist); + let dx = this._data[i].latlng.distanceTo(this._data[i - 1].latlng) / 1000; let t0 = this._data[i - 1].time.getTime(); point.meta.time = new Date(t0 + ( dx / this._timeAVGSpeed) * this.options.timeFactor * 1000); } else { @@ -57,27 +57,34 @@ export function Time() { scale: (opts.time && opts.time != "summary" && !L.Browser.mobile) && { axis : "x", position : "top", - scale : { - attr : "duration", - min : 0, - }, + scale : "x", label : time.label, labelY : -10, labelX : () => this._width(), name : "time", ticks : () => _.clamp(this._chart._xTicks() / 2, [4, +Infinity]), - tickFormat : (d) => (d == 0 ? '' : opts.xTimeFormat(d)), + tickFormat : (distance) => { + const data = this._data; + if (!data.length) return ''; + const i = _.bisect(data, distance, opts.xAttr, true); + const start = data[Math.max(0, i - 1)]; + const end = data[Math.min(i, data.length - 1)]; + const span = end[opts.xAttr] - start[opts.xAttr]; + // Time is only linear between consecutive recorded points, not across the whole track. + const fraction = span ? _.clamp((distance - start[opts.xAttr]) / span, [0, 1]) : 0; + const duration = start.duration + fraction * (end.duration - start.duration); + return duration == 0 ? '' : opts.xTimeFormat(duration); + }, onAxisMount: axis => { - axis.select(".domain") - .remove(); - axis.selectAll("text") - .attr('opacity', 0.65) - .style('font-family', 'Monospace') - .style('font-size', '110%'); - axis.selectAll(".tick line") - .attr('y2', this._height()) - .attr('stroke-dasharray', 2) - .attr('opacity', 0.75); + axis.querySelector(".domain").remove(); + axis.querySelectorAll("text").forEach(text => { + text.setAttribute('opacity', 0.65); + text.style.fontFamily = 'Monospace'; + text.style.fontSize = '110%'; + }); + axis.querySelectorAll(".tick line").forEach(line => _.setAttributes(line, { + y2: this._height(), 'stroke-dasharray': 2, opacity: 0.75, + })); } }, tooltips: [ diff --git a/assets/static/vendor/leaflet-elevation/src/index.css b/assets/static/vendor/leaflet-elevation/src/index.css index 9b29174..d2405bd 100644 --- a/assets/static/vendor/leaflet-elevation/src/index.css +++ b/assets/static/vendor/leaflet-elevation/src/index.css @@ -1,329 +1,329 @@ -.leaflet-hidden {
- visibility: hidden;
-}
-
-.legend {
- cursor: pointer;
-}
-
-.leaflet-container {
- z-index: 0;
- /* prevent overlapping the .elevation-detached chart */
-}
-
-.elevation-control .background {
- background-color: var(--ele-bg, rgba(70, 130, 180, 0.2));
- border-radius: 5px;
- overflow: visible;
- display: block;
- touch-action: none;
- user-select: none;
- max-width: 100%;
-}
-
-.elevation-control .grid,
-.elevation-control .area > foreignObject,
-.elevation-control .axis,
-.elevation-control .tooltip,
-.height-focus.line {
- pointer-events: none;
-}
-
-.elevation-control .axis line,
-.elevation-control .axis path {
- stroke: var(--ele-axis, #2D1130);
- stroke-width: 1;
- fill: none;
-}
-
-.elevation-control .grid .tick line {
- stroke: var(--ele-grid, #EEE);
- stroke-width: 1px;
- shape-rendering: crispEdges;
-}
-
-.elevation-control .grid path {
- stroke-width: 0;
-}
-
-.elevation-control .axis text,
-.elevation-control .legend text,
-.elevation-control .point text {
- fill: #000;
- font-weight: 700;
- paint-order: stroke fill;
- stroke: #fff;
- stroke-width: 2px
-}
-
-.elevation-control .y.axis text {
- text-anchor: end;
-}
-
-.elevation-control .area {
- fill: var(--ele-area, #4682B4);
- stroke: var(--ele-stroke, #000);
- stroke-width: 1.2;
- paint-order: stroke fill;
-}
-
-.elevation-control .horizontal-drag-line {
- cursor: row-resize;
- stroke: transparent;
- stroke-dasharray: 5;
- stroke-width: 1.1;
-}
-
-.elevation-control .active .horizontal-drag-line {
- stroke: #000;
-}
-
-.elevation-control .horizontal-drag-label {
- fill: #000;
- font-weight: 700;
- paint-order: stroke;
- stroke: #FFF;
- stroke-width: 2px;
-}
-
-.elevation-control .ruler {
- color: #000;
- cursor: row-resize;
-}
-
-.elevation-control .mouse-focus-line {
- stroke: #000;
- stroke-width: 1;
-}
-
-.elevation-control .mouse-focus-label-rect {
- fill: #000;
- fill-opacity: 0.75;
- stroke-width: 1;
- stroke: #444;
-}
-
-.elevation-control .mouse-focus-label-text {
- fill: #FFF;
- font-size: 10px;
-}
-
-.elevation-control .brush .overlay {
- cursor: unset;
-}
-
-.elevation-control .brush .selection {
- fill: var(--ele-brush, rgba(23, 74, 117, 0.4));
- stroke: none;
- fill-opacity: unset;
-}
-
-.elevation-summary {
- font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
- font-size: 12px;
- margin: var(--ele-sum-margin, 0 auto);
- text-shadow: var(--ele-sum-shadow, 1px 0 0 #FFF, -1px 0 0 #FFF, 0 1px 0 #FFF, 0 -1px 0 #FFF, 1px 1px #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF);
-}
-
-.elevation-summary>span:not(:last-child):after {
- content: var(--ele-sum-sep, '');
-}
-
-.multiline-summary>span {
- display: block;
-}
-
-.multiline-summary .download {
- float: right;
- margin-top: -3em;
- margin-right: 2em;
- font-weight: bold;
- font-size: 1.2em;
-}
-
-.elevation-summary .summaryvalue {
- font-weight: bold;
-}
-
-.elevation-toggle-icon {
- background-color: #fff;
- right: 5px;
- top: 5px;
- height: var(--ele-toggle-size, 36px);
- width: var(--ele-toggle-size, 36px);
- cursor: pointer;
- box-shadow: 0 1px 7px rgba(0, 0, 0, 0.4);
- border-radius: 5px;
- display: inline-block;
- position: var(--ele-toggle-pos, relative);
-}
-
-.elevation-toggle-icon:before {
- content: '\2716';
- display: var(--ele-close-btn, none);
- color: #000;
- width: 100%;
- line-height: 20px;
- text-align: center;
- font-weight: bold;
- font-size: 15px;
-}
-
-.leaflet-elevation-pane .height-focus,
-.leaflet-overlay-pane .height-focus {
- stroke: #000;
- fill: var(--ele-circle, var(--ele-area, #FFF));
-}
-
-.leaflet-elevation-pane .height-focus.line,
-.leaflet-overlay-pane .height-focus.line {
- stroke-width: 2;
-}
-
-.leaflet-elevation-pane .height-focus-label,
-.leaflet-overlay-pane .height-focus-label {
- font-size: 12px;
- font-weight: 600;
- fill: #000;
- paint-order: stroke;
- stroke: #FFF;
- stroke-width: 2px;
-}
-
-.elevation-waypoint-icon:before,
-.elevation-position-icon:before {
- content: "";
- width: 100%;
- height: 100%;
- display: inline-block;
- background: var(--ele-marker) no-repeat center center / contain;
-}
-
-.elevation-polyline {
- stroke: var(--ele-poly, var(--ele-area, #000));
- filter: drop-shadow(1px 1px 0 #FFF) drop-shadow(-1px -1px 0 #FFF) drop-shadow(1px -1px 0 #FFF) drop-shadow(-1px 1px 0 #FFF);
-}
-
-/* CHART STATES /////////////////////////////////////////////////// */
-
-.elevation-detached {
- font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
- height: auto;
- width: 100%;
- position: relative;
- z-index: 0;
-}
-
-.elevation-detached .area {
- fill-opacity: var(--ele-alpha, 0.8);
-}
-
-.elevation-detached.elevation-collapsed .elevation-summary {
- display: block;
-}
-
-.elevation-detached.elevation-collapsed .elevation-toggle-icon {
- top: 5px;
- right: 9px;
- bottom: 5px;
- margin: auto;
-}
-
-.elevation-control.elevation-collapsed > * {
- display: none;
-}
-
-.elevation-control.elevation-collapsed > .elevation-toggle-icon {
- display: inline-block;
-}
-
-.elevation-detached {
- --ele-sum-margin: 12px 35px;
- --ele-sum-shadow: none;
- --ele-toggle-pos: absolute;
-}
-
-.elevation-expanded {
- --ele-close-btn: inline-block;
- --ele-toggle-bg: none;
- --ele-toggle-pos: absolute;
- --ele-toggle-size: 20px;
-}
-
-.inline-summary {
- --ele-sum-sep: "\0020\2014\0020";
-}
-
-.elevation-waypoint-icon {
- --ele-marker: url(../images/elevation-pushpin.svg);
-}
-
-.elevation-position-icon {
- --ele-marker: url(../images/elevation-position.svg);
-}
-
-/* LIME THEME ///////////////////////////////////////////////////// */
-.lime-theme {
- --ele-bg: rgba(156, 194, 34, 0.2);
- --ele-axis: #566B13;
- --ele-area: #9CC222;
- --ele-grid: #CCC;
- --ele-brush: rgba(99, 126, 11, 0.4);
- --ele-poly: #566B13;
- --ele-line: #70ab00;
-}
-
-/* STEELBLUE THEME //////////////////////////////////////////////// */
-.steelblue-theme {
- --ele-axis: #0D1821;
- --ele-area: #4682B4;
- --ele-brush: rgba(23, 74, 117, 0.4);
- --ele-line: #174A75;
-}
-
-/* PURPLE THEME /////////////////////////////////////////////////// */
-.purple-theme {
- --ele-bg: rgba(115, 44, 123, 0.2);
- --ele-area: #732C7B;
- --ele-brush: rgba(74, 14, 80, 0.4);
- --ele-line: #732c7b;
-}
-
-/* YELLOW THEME /////////////////////////////////////////////////// */
-.yellow-theme {
- --ele-area: #FF0;
-}
-
-/* RED THEME ////////////////////////////////////////////////////// */
-.red-theme {
- --ele-area: #F00;
-}
-
-/* MAGENTA THEME ////////////////////////////////////////////////// */
-.magenta-theme {
- --ele-bg: rgba(255, 255, 255, 0.47);
- --ele-area: #FF005E;
-}
-
-/* LIGHTBLUE THEME //////////////////////////////////////////////// */
-.lightblue-theme {
- --ele-area: #3366CC;
- --ele-alpha: 0.45;
- --ele-stroke: #4682B4;
- --ele-circle: #fff;
- --ele-line: #000;
-}
-
-.elevation-detached.lightblue-theme .area {
- stroke: #3366CC;
-}
-
-/* leaflet-distance-markers */
-.dist-marker {
- font-size: 0.5rem;
- border: 1px solid #777;
- border-radius: 10px;
- text-align: center;
- color: #000;
- background: #fff;
-}
+.leaflet-hidden { + visibility: hidden; +} + +.legend { + cursor: pointer; +} + +.leaflet-container { + z-index: 0; + /* prevent overlapping the .elevation-detached chart */ +} + +.elevation-control .background { + background-color: var(--ele-bg, rgba(70, 130, 180, 0.2)); + border-radius: 5px; + overflow: visible; + display: block; + touch-action: none; + user-select: none; + max-width: 100%; +} + +.elevation-control .grid, +.elevation-control .area > foreignObject, +.elevation-control .axis, +.elevation-control .tooltip, +.height-focus.line { + pointer-events: none; +} + +.elevation-control .axis line, +.elevation-control .axis path { + stroke: var(--ele-axis, #2D1130); + stroke-width: 1; + fill: none; +} + +.elevation-control .grid .tick line { + stroke: var(--ele-grid, #EEE); + stroke-width: 1px; + shape-rendering: crispEdges; +} + +.elevation-control .grid path { + stroke-width: 0; +} + +.elevation-control .axis text, +.elevation-control .legend text, +.elevation-control .point text { + fill: #000; + font-weight: 700; + paint-order: stroke fill; + stroke: #fff; + stroke-width: 2px +} + +.elevation-control .y.axis text { + text-anchor: end; +} + +.elevation-control .area { + fill: var(--ele-area, #4682B4); + stroke: var(--ele-stroke, #000); + stroke-width: 1.2; + paint-order: stroke fill; +} + +.elevation-control .horizontal-drag-line { + cursor: row-resize; + stroke: transparent; + stroke-dasharray: 5; + stroke-width: 1.1; +} + +.elevation-control .active .horizontal-drag-line { + stroke: #000; +} + +.elevation-control .horizontal-drag-label { + fill: #000; + font-weight: 700; + paint-order: stroke; + stroke: #FFF; + stroke-width: 2px; +} + +.elevation-control .ruler { + color: #000; + cursor: row-resize; +} + +.elevation-control .mouse-focus-line { + stroke: #000; + stroke-width: 1; +} + +.elevation-control .mouse-focus-label-rect { + fill: #000; + fill-opacity: 0.75; + stroke-width: 1; + stroke: #444; +} + +.elevation-control .mouse-focus-label-text { + fill: #FFF; + font-size: 10px; +} + +.elevation-control .brush .overlay { + cursor: unset; +} + +.elevation-control .brush .selection { + fill: var(--ele-brush, rgba(23, 74, 117, 0.4)); + stroke: none; + fill-opacity: unset; +} + +.elevation-summary { + font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; + font-size: 12px; + margin: var(--ele-sum-margin, 0 auto); + text-shadow: var(--ele-sum-shadow, 1px 0 0 #FFF, -1px 0 0 #FFF, 0 1px 0 #FFF, 0 -1px 0 #FFF, 1px 1px #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF); +} + +.elevation-summary>span:not(:last-child):after { + content: var(--ele-sum-sep, ''); +} + +.multiline-summary>span { + display: block; +} + +.multiline-summary .download { + float: right; + margin-top: -3em; + margin-right: 2em; + font-weight: bold; + font-size: 1.2em; +} + +.elevation-summary .summaryvalue { + font-weight: bold; +} + +.elevation-toggle-icon { + background-color: #fff; + right: 5px; + top: 5px; + height: var(--ele-toggle-size, 36px); + width: var(--ele-toggle-size, 36px); + cursor: pointer; + box-shadow: 0 1px 7px rgba(0, 0, 0, 0.4); + border-radius: 5px; + display: inline-block; + position: var(--ele-toggle-pos, relative); +} + +.elevation-toggle-icon:before { + content: '\2716'; + display: var(--ele-close-btn, none); + color: #000; + width: 100%; + line-height: 20px; + text-align: center; + font-weight: bold; + font-size: 15px; +} + +.leaflet-elevation-pane .height-focus, +.leaflet-overlay-pane .height-focus { + stroke: #000; + fill: var(--ele-circle, var(--ele-area, #FFF)); +} + +.leaflet-elevation-pane .height-focus.line, +.leaflet-overlay-pane .height-focus.line { + stroke-width: 2; +} + +.leaflet-elevation-pane .height-focus-label, +.leaflet-overlay-pane .height-focus-label { + font-size: 12px; + font-weight: 600; + fill: #000; + paint-order: stroke; + stroke: #FFF; + stroke-width: 2px; +} + +.elevation-waypoint-icon:before, +.elevation-position-icon:before { + content: ""; + width: 100%; + height: 100%; + display: inline-block; + background: var(--ele-marker) no-repeat center center / contain; +} + +.elevation-polyline { + stroke: var(--ele-poly, var(--ele-area, #000)); + filter: drop-shadow(1px 1px 0 #FFF) drop-shadow(-1px -1px 0 #FFF) drop-shadow(1px -1px 0 #FFF) drop-shadow(-1px 1px 0 #FFF); +} + +/* CHART STATES /////////////////////////////////////////////////// */ + +.elevation-detached { + font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif; + height: auto; + width: 100%; + position: relative; + z-index: 0; +} + +.elevation-detached .area { + fill-opacity: var(--ele-alpha, 0.8); +} + +.elevation-detached.elevation-collapsed .elevation-summary { + display: block; +} + +.elevation-detached.elevation-collapsed .elevation-toggle-icon { + top: 5px; + right: 9px; + bottom: 5px; + margin: auto; +} + +.elevation-control.elevation-collapsed > * { + display: none; +} + +.elevation-control.elevation-collapsed > .elevation-toggle-icon { + display: inline-block; +} + +.elevation-detached { + --ele-sum-margin: 12px 35px; + --ele-sum-shadow: none; + --ele-toggle-pos: absolute; +} + +.elevation-expanded { + --ele-close-btn: inline-block; + --ele-toggle-bg: none; + --ele-toggle-pos: absolute; + --ele-toggle-size: 20px; +} + +.inline-summary { + --ele-sum-sep: "\0020\2014\0020"; +} + +.elevation-waypoint-icon { + --ele-marker: url(../images/elevation-pushpin.svg); +} + +.elevation-position-icon { + --ele-marker: url(../images/elevation-position.svg); +} + +/* LIME THEME ///////////////////////////////////////////////////// */ +.lime-theme { + --ele-bg: rgba(156, 194, 34, 0.2); + --ele-axis: #566B13; + --ele-area: #9CC222; + --ele-grid: #CCC; + --ele-brush: rgba(99, 126, 11, 0.4); + --ele-poly: #566B13; + --ele-line: #70ab00; +} + +/* STEELBLUE THEME //////////////////////////////////////////////// */ +.steelblue-theme { + --ele-axis: #0D1821; + --ele-area: #4682B4; + --ele-brush: rgba(23, 74, 117, 0.4); + --ele-line: #174A75; +} + +/* PURPLE THEME /////////////////////////////////////////////////// */ +.purple-theme { + --ele-bg: rgba(115, 44, 123, 0.2); + --ele-area: #732C7B; + --ele-brush: rgba(74, 14, 80, 0.4); + --ele-line: #732c7b; +} + +/* YELLOW THEME /////////////////////////////////////////////////// */ +.yellow-theme { + --ele-area: #FF0; +} + +/* RED THEME ////////////////////////////////////////////////////// */ +.red-theme { + --ele-area: #F00; +} + +/* MAGENTA THEME ////////////////////////////////////////////////// */ +.magenta-theme { + --ele-bg: rgba(255, 255, 255, 0.47); + --ele-area: #FF005E; +} + +/* LIGHTBLUE THEME //////////////////////////////////////////////// */ +.lightblue-theme { + --ele-area: #3366CC; + --ele-alpha: 0.45; + --ele-stroke: #4682B4; + --ele-circle: #fff; + --ele-line: #000; +} + +.elevation-detached.lightblue-theme .area { + stroke: #3366CC; +} + +/* leaflet-distance-markers */ +.dist-marker { + font-size: 0.5rem; + border: 1px solid #777; + border-radius: 10px; + text-align: center; + color: #000; + background: #fff; +} diff --git a/assets/static/vendor/leaflet-elevation/src/index.js b/assets/static/vendor/leaflet-elevation/src/index.js index 4e094ff..4263cef 100644 --- a/assets/static/vendor/leaflet-elevation/src/index.js +++ b/assets/static/vendor/leaflet-elevation/src/index.js @@ -1,42 +1,44 @@ -/*
- * Copyright (c) 2019, GPL-3.0+ Project, Raruto
- *
- * This file is free software: you may copy, redistribute and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 2 of the License, or (at your
- * option) any later version.
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * This file incorporates work covered by the following copyright and
- * permission notice:
- *
- * Copyright (c) 2013-2016, MIT License, Felix “MrMufflon” Bache
- *
- * Permission to use, copy, modify, and/or distribute this software
- * for any purpose with or without fee is hereby granted, provided
- * that the above copyright notice and this permission notice appear
- * in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-import * as _ from './utils';
-import { Elevation } from './control';
-
-Elevation.Utils = _;
-
-L.control.elevation = (options) => new Elevation(options);
+/* + * Copyright (c) 2019, GPL-3.0+ Project, Raruto + * + * This file is free software: you may copy, redistribute and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 2 of the License, or (at your + * option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (c) 2013-2016, MIT License, Felix “MrMufflon” Bache + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose with or without fee is hereby granted, provided + * that the above copyright notice and this permission notice appear + * in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +import * as _ from './utils'; +import { Elevation } from './control'; + +Elevation.Utils = _; + +// backcomps for leaflet v1 +L.control = L.control || {}; +L.control.elevation = (options) => new Elevation(options); diff --git a/assets/static/vendor/leaflet-elevation/src/options.js b/assets/static/vendor/leaflet-elevation/src/options.js index 5923163..1efcf29 100644 --- a/assets/static/vendor/leaflet-elevation/src/options.js +++ b/assets/static/vendor/leaflet-elevation/src/options.js @@ -4,7 +4,7 @@ export var Options = { autofitBounds: true, autohide: false, autohideMarker: true, - almostover: true, + almostOver: true, altitude: true, closeBtn: true, collapsed: false, @@ -21,7 +21,7 @@ export var Options = { handlers: ["Distance", "Time", "Altitude", "Slope", "Speed", "Acceleration"], hotline: 'elevation', marker: 'elevation-line', - markerIcon: L.divIcon({ + markerIcon: new L.DivIcon({ className: 'elevation-position-marker', html: '<i class="elevation-position-icon"></i>', iconSize: [32, 32], @@ -54,7 +54,7 @@ export var Options = { trkEnd: { className: 'end-marker', radius: 6, weight: 2, color: '#fff', fillColor: '#ff0606', fillOpacity: 1, interactive: false }, waypoints: true, wptIcons: { - '': L.divIcon({ + '': new L.DivIcon({ className: 'elevation-waypoint-marker', html: '<i class="elevation-waypoint-icon default"></i>', iconSize: [30, 30], @@ -67,7 +67,7 @@ export var Options = { yAttr: "z", yLabel: "m", zFollow: false, - zooming: !L.Browser.Mobile, + zooming: !L.Browser.mobile, // Quite uncommon and undocumented options margins: { top: 30, right: 30, bottom: 30, left: 40 }, @@ -84,5 +84,5 @@ export var Options = { yAxisMin: undefined, // Prevent CORS issues for relative locations (dynamic import) - srcFolder: ((document.currentScript && document.currentScript.src) || (import.meta && import.meta.url)).split("/").slice(0,-1).join("/") + '/', + srcFolder: ((document.currentScript && document.currentScript.src) || (import.meta && import.meta.url) || document.baseURI).split("/").slice(0,-1).join("/") + '/', }; diff --git a/assets/static/vendor/leaflet-elevation/src/utils.js b/assets/static/vendor/leaflet-elevation/src/utils.js index 90035f7..261ced2 100644 --- a/assets/static/vendor/leaflet-elevation/src/utils.js +++ b/assets/static/vendor/leaflet-elevation/src/utils.js @@ -64,23 +64,23 @@ export function formatTime(t) { * Convert SVG Path into Path2D and then update canvas */ export function drawCanvas(ctx, path) { - path.classed('canvas-path', true); + path.classList.add('canvas-path'); ctx.beginPath(); ctx.moveTo(0, 0); - let p = new Path2D(path.attr('d')); + let p = new Path2D(path.getAttribute('d')); - ctx.strokeStyle = path.__strokeStyle || path.attr('stroke'); - ctx.fillStyle = path.__fillStyle || path.attr('fill'); + ctx.strokeStyle = path.__strokeStyle || path.getAttribute('stroke'); + ctx.fillStyle = path.__fillStyle || path.getAttribute('fill'); ctx.lineWidth = 1.25; ctx.globalCompositeOperation = 'source-over'; // stroke opacity - ctx.globalAlpha = path.attr('stroke-opacity') || 0.3; + ctx.globalAlpha = path.getAttribute('stroke-opacity') || 0.3; ctx.stroke(p); // fill opacity - ctx.globalAlpha = path.attr('fill-opacity') || 0.45; + ctx.globalAlpha = path.getAttribute('fill-opacity') || 0.45; ctx.fill(p); ctx.globalAlpha = 1; @@ -117,15 +117,22 @@ export const parseDate = (property, id) => new Date(Date.parse((typeof property /** * A little bit shorter than L.DomUtil */ -export const addClass = (n, str) => n && str.split(" ").every(s => s && L.DomUtil.addClass(n, s)); -export const removeClass = (n, str) => n && str.split(" ").every(s => s && L.DomUtil.removeClass(n, s)); +export const addClass = (n, str) => n && str.split(" ").every(s => s && n.classList.add(s)); +export const removeClass = (n, str) => n && str.split(" ").every(s => s && n.classList.remove(s)); export const toggleClass = (n, str, cond) => (cond ? addClass : removeClass)(n, str); export const replaceClass = (n, rem, add) => (rem && removeClass(n, rem)) || (add && addClass(n, add)); -export const style = (n, k, v) => (typeof v === "undefined" && L.DomUtil.getStyle(n, k)) || n.style.setProperty(k, v); +export const style = (n, k, v) => (typeof v === "undefined" && getComputedStyle(n)[k]) || n.style.setProperty(k, v); export const toggleStyle = (n, k, v, cond) => style(n, k, cond ? v : ''); -export const setAttributes = (n, attrs) => { for (let k in attrs) { n.setAttribute(k, attrs[k]); } }; +export const setAttributes = (n, attrs) => { for (let k in attrs) { if (attrs[k] != null) n.setAttribute(k, attrs[k]); else n.removeAttribute(k); } }; export const toggleEvent = (el, e, fn, cond) => el[cond ? 'on' : 'off'](e, fn); -export const create = (tag, str, attrs, n) => { let elem = L.DomUtil.create(tag, str || ""); if (attrs) setAttributes(elem, attrs); if (n) append(n, elem); return elem; }; +export const create = (tag, str, attrs, n) => { + const svg = tag.startsWith('svg:'); + const elem = svg ? document.createElementNS('http://www.w3.org/2000/svg', tag.slice(4)) : L.DomUtil.create(tag, str || ""); + if (svg && str) elem.setAttribute('class', str); + if (attrs) setAttributes(elem, attrs); + if (n) append(n, elem); + return elem; +} export const append = (n, c) => n.appendChild(c); export const insert = (n, c, pos) => n.insertAdjacentElement(pos, c); export const select = (str, n) => (n || document).querySelector(str); @@ -133,6 +140,18 @@ export const each = (obj, fn) => { for (let i in obj) fn(obj export const randomId = () => Math.random().toString(36).substr(2, 9); /** + * Convert pointer client coordinates to local SVG coordinates, accounting for transforms. + */ +export function pointer(event, element) { + const svg = element.ownerSVGElement || element; + const point = svg.createSVGPoint(); + point.x = event.clientX; + point.y = event.clientY; + const local = point.matrixTransform(element.getScreenCTM().inverse()); + return [local.x, local.y]; +} + +/** * TODO: use generators instead? (ie. "yield") */ export const iMax = (iVal, max = -Infinity) => (iVal > max ? iVal : max); @@ -145,7 +164,7 @@ export const iSum = (iVal, sum = 0) => iVal + sum; */ export const { on, off } = L.DomEvent; export const { throttle, wrapNum } = L.Util; -export const { hasClass } = L.DomUtil; +export const hasClass = (n, str) => n && str.split(" ").every(s => s && n.classList.contains(s)); /** * Limit floating point precision @@ -158,6 +177,19 @@ export const round = L.Util.formatNum; export const clamp = (val, range) => range ? (val < range[0] ? range[0] : val > range[1] ? range[1] : val) : val; /** + * Find the insertion index in data sorted by attr, before equal values (or after if right). + */ +export function bisect(data, value, attr, right = false) { + let low = 0, high = data.length; + while (low < high) { + const middle = Math.floor((low + high) / 2); + if (data[middle][attr] < value || (right && data[middle][attr] === value)) low = middle + 1; + else high = middle; + } + return low; +} + +/** * Limit a delta difference between two values */ export const wrapDelta = (curr, prev, deltaMax) => Math.abs(curr - prev) > deltaMax ? prev + deltaMax * Math.sign(curr - prev) : curr; diff --git a/assets/static/vendor/leaflet-providers/leaflet-providers.js b/assets/static/vendor/leaflet-providers/leaflet-providers.js index a134d58..fad36b3 100644 --- a/assets/static/vendor/leaflet-providers/leaflet-providers.js +++ b/assets/static/vendor/leaflet-providers/leaflet-providers.js @@ -186,13 +186,6 @@ attribution: 'Map data: {attribution.OpenStreetMap} | Map style: © <a href="https://www.OpenRailwayMap.org">OpenRailwayMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)' } }, - OpenFireMap: { - url: 'http://openfiremap.org/hytiles/{z}/{x}/{y}.png', - options: { - maxZoom: 19, - attribution: 'Map data: {attribution.OpenStreetMap} | Map style: © <a href="http://www.openfiremap.org">OpenFireMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)' - } - }, SafeCast: { url: 'https://s3.amazonaws.com/te512.safecast.org/{z}/{x}/{y}.png', options: { @@ -278,6 +271,26 @@ variant: 'stamen_toner_lite' } }, + StamenTonerDark: { + options: { + attribution: + '© <a href="https://www.stadiamaps.com/" target="_blank">Stadia Maps</a> ' + + '© <a href="https://www.stamen.com/" target="_blank">Stamen Design</a> ' + + '© <a href="https://openmaptiles.org/" target="_blank">OpenMapTiles</a> ' + + '{attribution.OpenStreetMap}', + variant: 'stamen_toner_dark' + } + }, + StamenTonerBlacklite: { + options: { + attribution: + '© <a href="https://www.stadiamaps.com/" target="_blank">Stadia Maps</a> ' + + '© <a href="https://www.stamen.com/" target="_blank">Stamen Design</a> ' + + '© <a href="https://openmaptiles.org/" target="_blank">OpenMapTiles</a> ' + + '{attribution.OpenStreetMap}', + variant: 'stamen_toner_blacklite' + } + }, StamenWatercolor: { url: 'https://tiles.stadiamaps.com/tiles/{variant}/{z}/{x}/{y}.{ext}', options: { @@ -343,7 +356,7 @@ } }, Thunderforest: { - url: 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}{r}.png?apikey={apikey}', + url: 'https://api.thunderforest.com/{variant}/{z}/{x}/{y}{r}.png?apikey={apikey}', options: { attribution: '© <a href="http://www.thunderforest.com/">Thunderforest</a>, {attribution.OpenStreetMap}', @@ -372,7 +385,8 @@ Outdoors: 'outdoors', Pioneer: 'pioneer', MobileAtlas: 'mobile-atlas', - Neighbourhood: 'neighbourhood' + Neighbourhood: 'neighbourhood', + Atlas: 'atlas' } }, BaseMapDE: { @@ -616,7 +630,7 @@ url: 'https://maps.hereapi.com/v3/base/mc/' + // new base url for HERE maptile v3 api '{z}/{x}/{y}/{format}?style={variant}&size={size}' + // slightly modified parameters - '&apiKey={app_id}&lg={language}', // replacing app-id with apikey + '&apiKey={apiKey}&lg={language}', // replacing app-id with apikey options: { attribution: 'Map © 1987-' + new Date().getFullYear() + ' <a href="http://platform.here.com">HERE</a>', @@ -726,12 +740,13 @@ } }, CartoDB: { - url: 'https://{s}.basemaps.cartocdn.com/{variant}/{z}/{x}/{y}{r}.png', + url: 'https://{s}.basemaps.cartocdn.com/{variant}/{z}/{x}/{y}{r}.png?key={apikey}', options: { attribution: '{attribution.OpenStreetMap} © <a href="https://carto.com/attributions">CARTO</a>', subdomains: 'abcd', maxZoom: 20, - variant: 'light_all' + variant: 'light_all', + apikey: '<insert your API key here>', }, variants: { Positron: 'light_all', @@ -914,9 +929,10 @@ }, JusticeMap: { // Justice Map (http://www.justicemap.org/) + // Raster map tiles migrated to (https://maptile3.org/) in 2023 // Visualize race and income data for your community, county and country. // Includes tools for data journalists, bloggers and community activists. - url: 'https://www.justicemap.org/tile/{size}/{variant}/{z}/{x}/{y}.png', + url: 'https://maptile3.org/2020/{size}/{variant}/{z}/{x}/{y}.png', options: { attribution: '<a href="http://www.justicemap.org/terms.php">Justice Map</a>', // one of 'county', 'tract', 'block' diff --git a/package-lock.json b/package-lock.json index 228c41f..5546db6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,15 +10,15 @@ "leaflet": "^1.9.4", "leaflet-gpx": "^2.2.0", "leaflet-i18n": "^0.3.5", - "leaflet-providers": "^3.0.0", + "leaflet-providers": "^4.0.0", "leaflet.fullscreen": "^5.3.3", "pagefind": "^1.5.2" } }, "node_modules/@pagefind/darwin-arm64": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/@pagefind/darwin-arm64/-/darwin-arm64-1.5.2.tgz", - "integrity": "sha512-MXpI+7HsAdPkvJ0gk9xj9g541BCqBZOBbdwj9g6lB5LCj6kSV6nqDSjzcAJwvOsfu0fjwvC8hQU+ecfhp+MpiQ==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-arm64/-/darwin-arm64-1.6.0.tgz", + "integrity": "sha512-611gl64aqN12UcMyKPtZ8+vRWBKlJFSh2JgO8uScxa1Eyjo1dXz9r4wZuRno0yCUE/KN0FauEoKZ3KEwUYHCCg==", "cpu": [ "arm64" ], @@ -30,9 +30,9 @@ ] }, "node_modules/@pagefind/darwin-x64": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/@pagefind/darwin-x64/-/darwin-x64-1.5.2.tgz", - "integrity": "sha512-IojxFWMEJe0RQ7PQ3KXQsPIImNsbpPYpoZ+QUDrL8fAl/O27IX+LVLs74/UzEZy5uA2LD8Nz1AiwKr72vrkZQw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-x64/-/darwin-x64-1.6.0.tgz", + "integrity": "sha512-rd3ZbtuxyYqjASKZAPuIV7eeQQHJ7VYpoNKKG8CvglaD3g30eT5Nb7XGNLYwVReBsCccpkURwrGwWjSwr8nyQQ==", "cpu": [ "x64" ], @@ -44,9 +44,9 @@ ] }, "node_modules/@pagefind/freebsd-x64": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/@pagefind/freebsd-x64/-/freebsd-x64-1.5.2.tgz", - "integrity": "sha512-7EVzo9+0w+2cbe671BtMj10UlNo83I+HrLVLfRxO731svHRJKUfJ/mo05gU14pe9PCfpKNQT8FS3Xc/oDN6pOA==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/freebsd-x64/-/freebsd-x64-1.6.0.tgz", + "integrity": "sha512-d+sXqsaThszmPWGVDSRKqIz9GpZcj/bAksNZfg19asSxU0ogNPOMND4kV4giQvOjPFMsltUFf6hQJfoHQ6+hSQ==", "cpu": [ "x64" ], @@ -58,9 +58,9 @@ ] }, "node_modules/@pagefind/linux-arm64": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/@pagefind/linux-arm64/-/linux-arm64-1.5.2.tgz", - "integrity": "sha512-Ovt9+K35sqzn8H3ZMXGwls4TD/wMJuvRtShHIsmUQREmaxjrDEX7gHckRCrwYJ4XE1H1p6HkLz3wukrAnsfXQw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/linux-arm64/-/linux-arm64-1.6.0.tgz", + "integrity": "sha512-SLB2I+XqCZma8NvIGIH8nyKblgKIxw5PmqsVtofWOKxNHhEtOEsddbqU+hsrNcT3EV0faM6UmKDHVIxcPYq29w==", "cpu": [ "arm64" ], @@ -72,9 +72,9 @@ ] }, "node_modules/@pagefind/linux-x64": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/@pagefind/linux-x64/-/linux-x64-1.5.2.tgz", - "integrity": "sha512-V+tFqHKXhQKq/WqPBD67AFy7scn1/aZID00ws4fSDd+1daSi5UHR9VVlRrOUYKxn3VuFQYRD7lYXdZK1WED1YA==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/linux-x64/-/linux-x64-1.6.0.tgz", + "integrity": "sha512-IbMSx/+Vr/Xk0TTBlLkjgK+rvnbOXGmmb2/MKxQu99AR5DsqQoV3NKEA9PQz2tAhuCZjeD5xJBp4w5N5DHIC7Q==", "cpu": [ "x64" ], @@ -86,9 +86,9 @@ ] }, "node_modules/@pagefind/windows-arm64": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/@pagefind/windows-arm64/-/windows-arm64-1.5.2.tgz", - "integrity": "sha512-hN9Nh90fNW61nNRCW9ZyQrAj/mD0eRvmJ8NlTUzkbuW8kIzGJUi3cxjFkEcMZ5h/8FsKWD/VcouZl4yo1F7B6g==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/windows-arm64/-/windows-arm64-1.6.0.tgz", + "integrity": "sha512-wUrniW3REr7VWJHz6xE6F/p/AQgHDFpGZiY9sbWT71KfEijDE5Jnc37V8zc7cilV9h/QkwJGXoEP2+ZLwDmhtw==", "cpu": [ "arm64" ], @@ -100,9 +100,9 @@ ] }, "node_modules/@pagefind/windows-x64": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/@pagefind/windows-x64/-/windows-x64-1.5.2.tgz", - "integrity": "sha512-Fa2Iyw7kaDRzGMfNYNUXNW2zbL5FQVDgSOcbDHdzBrDEdpqOqg8TcZ68F22ol6NJ9IGzvUdmeyZypLW5dyhqsg==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/windows-x64/-/windows-x64-1.6.0.tgz", + "integrity": "sha512-cUA2+yXfbymdJllyMjY5YTBwuOgh0/H53Pn5fYKjDnDjk154Ft4U5RVj3TenWySPL/jG6zJfARUWSlyUyXHlZw==", "cpu": [ "x64" ], @@ -114,15 +114,14 @@ ] }, "node_modules/@raruto/leaflet-elevation": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/@raruto/leaflet-elevation/-/leaflet-elevation-2.5.2.tgz", - "integrity": "sha512-bXWxDe72MeD5eBn6u06mF9agf2PFUg81OvT6QBQRacg+fkI4UHYL9eLcbvFo5uHltf7bN/M6f+FWsHMfgc9+QA==", + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/@raruto/leaflet-elevation/-/leaflet-elevation-2.9.2.tgz", + "integrity": "sha512-lCNvPZ3pmKelhyxM1TWl66WXepJRYAvx5f/bK7Y2zBSUiJxvv4vEsSYEUb/IYdDJOAvoSQ9PxDLcXobbaWxdDg==", "dev": true, "license": "GPL-3.0", "peerDependencies": { "@tmcw/togeojson": "5.6.2", - "d3": "7.8.4", - "leaflet": "^1.7.0", + "leaflet": "^1.9.4 || ^2.0.0-alpha.1", "leaflet-i18n": "^0.3.1" } }, @@ -144,516 +143,6 @@ "license": "MIT", "peer": true }, - "node_modules/commander": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", - "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", - "dev": true, - "license": "MIT", - "peer": true, - "engines": { - "node": ">= 10" - } - }, - "node_modules/d3": { - "version": "7.8.4", - "resolved": "https://registry.npmjs.org/d3/-/d3-7.8.4.tgz", - "integrity": "sha512-q2WHStdhiBtD8DMmhDPyJmXUxr6VWRngKyiJ5EfXMxPw+tqT6BhNjhJZ4w3BHsNm3QoVfZLY8Orq/qPFczwKRA==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-array": "3", - "d3-axis": "3", - "d3-brush": "3", - "d3-chord": "3", - "d3-color": "3", - "d3-contour": "4", - "d3-delaunay": "6", - "d3-dispatch": "3", - "d3-drag": "3", - "d3-dsv": "3", - "d3-ease": "3", - "d3-fetch": "3", - "d3-force": "3", - "d3-format": "3", - "d3-geo": "3", - "d3-hierarchy": "3", - "d3-interpolate": "3", - "d3-path": "3", - "d3-polygon": "3", - "d3-quadtree": "3", - "d3-random": "3", - "d3-scale": "4", - "d3-scale-chromatic": "3", - "d3-selection": "3", - "d3-shape": "3", - "d3-time": "3", - "d3-time-format": "4", - "d3-timer": "3", - "d3-transition": "3", - "d3-zoom": "3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-array": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/d3-array/-/d3-array-3.2.4.tgz", - "integrity": "sha512-tdQAmyA18i4J7wprpYq8ClcxZy3SC31QMeByyCFyRt7BVHdREQZ5lpzoe5mFEYZUWe+oq8HBvk9JjpibyEV4Jg==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "internmap": "1 - 2" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-axis": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/d3-axis/-/d3-axis-3.0.0.tgz", - "integrity": "sha512-IH5tgjV4jE/GhHkRV0HiVYPDtvfjHQlQfJHs0usq7M30XcSBvOotpmH1IgkcXsO/5gEQZD43B//fc7SRT5S+xw==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-brush": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/d3-brush/-/d3-brush-3.0.0.tgz", - "integrity": "sha512-ALnjWlVYkXsVIGlOsuWH1+3udkYFI48Ljihfnh8FZPF2QS9o+PzGLBslO0PjzVoHLZ2KCVgAM8NVkXPJB2aNnQ==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-drag": "2 - 3", - "d3-interpolate": "1 - 3", - "d3-selection": "3", - "d3-transition": "3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-chord": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-chord/-/d3-chord-3.0.1.tgz", - "integrity": "sha512-VE5S6TNa+j8msksl7HwjxMHDM2yNK3XCkusIlpX5kwauBfXuyLAtNg9jCp/iHH61tgI4sb6R/EIMWCqEIdjT/g==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-path": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-color": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz", - "integrity": "sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-contour": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/d3-contour/-/d3-contour-4.0.2.tgz", - "integrity": "sha512-4EzFTRIikzs47RGmdxbeUvLWtGedDUNkTcmzoeyg4sP/dvCexO47AaQL7VKy/gul85TOxw+IBgA8US2xwbToNA==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-array": "^3.2.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-delaunay": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/d3-delaunay/-/d3-delaunay-6.0.4.tgz", - "integrity": "sha512-mdjtIZ1XLAM8bm/hx3WwjfHt6Sggek7qH043O8KEjDXN40xi3vx/6pYSVTwLjEgiXQTbvaouWKynLBiUZ6SK6A==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "delaunator": "5" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-dispatch": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-dispatch/-/d3-dispatch-3.0.1.tgz", - "integrity": "sha512-rzUyPU/S7rwUflMyLc1ETDeBj0NRuHKKAcvukozwhshr6g6c5d8zh4c2gQjY2bZ0dXeGLWc1PF174P2tVvKhfg==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-drag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/d3-drag/-/d3-drag-3.0.0.tgz", - "integrity": "sha512-pWbUJLdETVA8lQNJecMxoXfH6x+mO2UQo8rSmZ+QqxcbyA3hfeprFgIT//HW2nlHChWeIIMwS2Fq+gEARkhTkg==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-selection": "3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-dsv": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-dsv/-/d3-dsv-3.0.1.tgz", - "integrity": "sha512-UG6OvdI5afDIFP9w4G0mNq50dSOsXHJaRE8arAS5o9ApWnIElp8GZw1Dun8vP8OyHOZ/QJUKUJwxiiCCnUwm+Q==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "commander": "7", - "iconv-lite": "0.6", - "rw": "1" - }, - "bin": { - "csv2json": "bin/dsv2json.js", - "csv2tsv": "bin/dsv2dsv.js", - "dsv2dsv": "bin/dsv2dsv.js", - "dsv2json": "bin/dsv2json.js", - "json2csv": "bin/json2dsv.js", - "json2dsv": "bin/json2dsv.js", - "json2tsv": "bin/json2dsv.js", - "tsv2csv": "bin/dsv2dsv.js", - "tsv2json": "bin/dsv2json.js" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-ease": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.1.tgz", - "integrity": "sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==", - "dev": true, - "license": "BSD-3-Clause", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-fetch": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-fetch/-/d3-fetch-3.0.1.tgz", - "integrity": "sha512-kpkQIM20n3oLVBKGg6oHrUchHM3xODkTzjMoj7aWQFq5QEM+R6E4WkzT5+tojDY7yjez8KgCBRoj4aEr99Fdqw==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-dsv": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-force": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/d3-force/-/d3-force-3.0.0.tgz", - "integrity": "sha512-zxV/SsA+U4yte8051P4ECydjD/S+qeYtnaIyAs9tgHCqfguma/aAQDjo85A9Z6EKhBirHRJHXIgJUlffT4wdLg==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-quadtree": "1 - 3", - "d3-timer": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-format": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/d3-format/-/d3-format-3.1.2.tgz", - "integrity": "sha512-AJDdYOdnyRDV5b6ArilzCPPwc1ejkHcoyFarqlPqT7zRYjhavcT3uSrqcMvsgh2CgoPbK3RCwyHaVyxYcP2Arg==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-geo": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/d3-geo/-/d3-geo-3.1.1.tgz", - "integrity": "sha512-637ln3gXKXOwhalDzinUgY83KzNWZRKbYubaG+fGVuc/dxO64RRljtCTnf5ecMyE1RIdtqpkVcq0IbtU2S8j2Q==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-array": "2.5.0 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-hierarchy": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/d3-hierarchy/-/d3-hierarchy-3.1.2.tgz", - "integrity": "sha512-FX/9frcub54beBdugHjDCdikxThEqjnR93Qt7PvQTOHxyiNCAlvMrHhclk3cD5VeAaq9fxmfRp+CnWw9rEMBuA==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-interpolate": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.1.tgz", - "integrity": "sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-color": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-path": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/d3-path/-/d3-path-3.1.0.tgz", - "integrity": "sha512-p3KP5HCf/bvjBSSKuXid6Zqijx7wIfNW+J/maPs+iwR35at5JCbLUT0LzF1cnjbCHWhqzQTIN2Jpe8pRebIEFQ==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-polygon": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-polygon/-/d3-polygon-3.0.1.tgz", - "integrity": "sha512-3vbA7vXYwfe1SYhED++fPUQlWSYTTGmFmQiany/gdbiWgU/iEyQzyymwL9SkJjFFuCS4902BSzewVGsHHmHtXg==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-quadtree": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-quadtree/-/d3-quadtree-3.0.1.tgz", - "integrity": "sha512-04xDrxQTDTCFwP5H6hRhsRcb9xxv2RzkcsygFzmkSIOJy3PeRJP7sNk3VRIbKXcog561P9oU0/rVH6vDROAgUw==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-random": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-random/-/d3-random-3.0.1.tgz", - "integrity": "sha512-FXMe9GfxTxqd5D6jFsQ+DJ8BJS4E/fT5mqqdjovykEB2oFbTMDVdg1MGFxfQW+FBOGoB++k8swBrgwSHT1cUXQ==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-scale": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-4.0.2.tgz", - "integrity": "sha512-GZW464g1SH7ag3Y7hXjf8RoUuAFIqklOAq3MRl4OaWabTFJY9PN/E1YklhXLh+OQ3fM9yS2nOkCoS+WLZ6kvxQ==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-array": "2.10.0 - 3", - "d3-format": "1 - 3", - "d3-interpolate": "1.2.0 - 3", - "d3-time": "2.1.1 - 3", - "d3-time-format": "2 - 4" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-scale-chromatic": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/d3-scale-chromatic/-/d3-scale-chromatic-3.1.0.tgz", - "integrity": "sha512-A3s5PWiZ9YCXFye1o246KoscMWqf8BsD9eRiJ3He7C9OBaxKhAd5TFCdEx/7VbKtxxTsu//1mMJFrEt572cEyQ==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-color": "1 - 3", - "d3-interpolate": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-selection": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-3.0.0.tgz", - "integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-shape": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-3.2.0.tgz", - "integrity": "sha512-SaLBuwGm3MOViRq2ABk3eLoxwZELpH6zhl3FbAoJ7Vm1gofKx6El1Ib5z23NUEhF9AsGl7y+dzLe5Cw2AArGTA==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-path": "^3.1.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-time": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/d3-time/-/d3-time-3.1.0.tgz", - "integrity": "sha512-VqKjzBLejbSMT4IgbmVgDjpkYrNWUYJnbCGo874u7MMKIWsILRX+OpX/gTk8MqjpT1A/c6HY2dCA77ZN0lkQ2Q==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-array": "2 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-time-format": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/d3-time-format/-/d3-time-format-4.1.0.tgz", - "integrity": "sha512-dJxPBlzC7NugB2PDLwo9Q8JiTR3M3e4/XANkreKSUxF8vvXKqm1Yfq4Q5dl8budlunRVlUUaDUgFt7eA8D6NLg==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-time": "1 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-timer": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-3.0.1.tgz", - "integrity": "sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, - "node_modules/d3-transition": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/d3-transition/-/d3-transition-3.0.1.tgz", - "integrity": "sha512-ApKvfjsSR6tg06xrL434C0WydLr7JewBB3V+/39RMHsaXTOG0zmt/OAXeng5M5LBm0ojmxJrpomQVZ1aPvBL4w==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-color": "1 - 3", - "d3-dispatch": "1 - 3", - "d3-ease": "1 - 3", - "d3-interpolate": "1 - 3", - "d3-timer": "1 - 3" - }, - "engines": { - "node": ">=12" - }, - "peerDependencies": { - "d3-selection": "2 - 3" - } - }, - "node_modules/d3-zoom": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/d3-zoom/-/d3-zoom-3.0.0.tgz", - "integrity": "sha512-b8AmV3kfQaqWAuacbPuNbL6vahnOJflOhexLzMMNLga62+/nh0JzvJ0aO/5a5MVgUFGS7Hu1P9P03o3fJkDCyw==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "d3-dispatch": "1 - 3", - "d3-drag": "2 - 3", - "d3-interpolate": "1 - 3", - "d3-selection": "2 - 3", - "d3-transition": "2 - 3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/delaunator": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/delaunator/-/delaunator-5.1.0.tgz", - "integrity": "sha512-AGrQ4QSgssa1NGmWmLPqN5NY2KajF5MqxetNEO+o0n3ZwZZeTmt7bBnvzHWrmkZFxGgr4HdyFgelzgi06otLuQ==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "robust-predicates": "^3.0.2" - } - }, - "node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, - "license": "MIT", - "peer": true, - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/internmap": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/internmap/-/internmap-2.0.3.tgz", - "integrity": "sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=12" - } - }, "node_modules/leaflet": { "version": "1.9.4", "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.4.tgz", @@ -675,9 +164,9 @@ "dev": true }, "node_modules/leaflet-providers": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/leaflet-providers/-/leaflet-providers-3.0.0.tgz", - "integrity": "sha512-PWwsWRpf7xMrCofRUfWR6FBdw2v08j48tXCLQCoS1PinxPpVU70AQTr9N3NcbTIONiF9nS6m45LxBWVYx2i+wg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/leaflet-providers/-/leaflet-providers-4.0.0.tgz", + "integrity": "sha512-4m3Q4t0e+cHVNIPzlkW9HFWEgplImFRv8cnUFJYOfFoS6p2KosAfmh2Do6qk4HMdqutqbHMpv3F7sn/CUSw6oQ==", "dev": true, "license": "BSD-2-Clause" }, @@ -692,47 +181,23 @@ } }, "node_modules/pagefind": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/pagefind/-/pagefind-1.5.2.tgz", - "integrity": "sha512-XTUaK0hXMCu2jszWE584JGQT7y284TmMV9l/HX3rnG5uo3rHI/uHU56XTyyyPFjeWEBxECbAi0CaFDJOONtG0Q==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/pagefind/-/pagefind-1.6.0.tgz", + "integrity": "sha512-yeOd9EA0TUE1PUfbQIluBxzPadBG5/0BV48FAxwMVLkhZcOvwCz6TX4/a/Ofz97pF9/FwwT7CVbTC97BfmI+LQ==", "dev": true, "license": "MIT", "bin": { "pagefind": "lib/runner/bin.cjs" }, "optionalDependencies": { - "@pagefind/darwin-arm64": "1.5.2", - "@pagefind/darwin-x64": "1.5.2", - "@pagefind/freebsd-x64": "1.5.2", - "@pagefind/linux-arm64": "1.5.2", - "@pagefind/linux-x64": "1.5.2", - "@pagefind/windows-arm64": "1.5.2", - "@pagefind/windows-x64": "1.5.2" + "@pagefind/darwin-arm64": "1.6.0", + "@pagefind/darwin-x64": "1.6.0", + "@pagefind/freebsd-x64": "1.6.0", + "@pagefind/linux-arm64": "1.6.0", + "@pagefind/linux-x64": "1.6.0", + "@pagefind/windows-arm64": "1.6.0", + "@pagefind/windows-x64": "1.6.0" } - }, - "node_modules/robust-predicates": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/robust-predicates/-/robust-predicates-3.0.3.tgz", - "integrity": "sha512-NS3levdsRIUOmiJ8FZWCP7LG3QpJyrs/TE0Zpf1yvZu8cAJJ6QMW92H1c7kWpdIHo8RvmLxN/o2JXTKHp74lUA==", - "dev": true, - "license": "Unlicense", - "peer": true - }, - "node_modules/rw": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/rw/-/rw-1.3.3.tgz", - "integrity": "sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ==", - "dev": true, - "license": "BSD-3-Clause", - "peer": true - }, - "node_modules/safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true, - "license": "MIT", - "peer": true } } } diff --git a/package.json b/package.json index a68855e..85d2f55 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "leaflet": "^1.9.4", "leaflet-gpx": "^2.2.0", "leaflet-i18n": "^0.3.5", - "leaflet-providers": "^3.0.0", + "leaflet-providers": "^4.0.0", "leaflet.fullscreen": "^5.3.3", "pagefind": "^1.5.2" } |
