example.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>TestMap</title>
  7. </head>
  8. <body style="margin: 0; padding: 0; display: flex; align-items: stretch; justify-items: stretch;height: 100vh;">
  9. <div id="map" style="flex: 1 1 auto; flex-grow: 1;"></div>
  10. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" />
  11. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/>
  12. <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>
  13. <script src="src/leaflet.motion.js"></script>
  14. <script src="src/leaflet.motion.utils.js"></script>
  15. <script src="src/leaflet.motion.easing.js"></script>
  16. <script src="src/layer/leaflet.motion.polyline.js"></script>
  17. <script src="src/layer/leaflet.motion.polygon.js"></script>
  18. <script src="src/layer/leaflet.motion.group.js"></script>
  19. <script src="src/layer/leaflet.motion.seq.js"></script>
  20. <script src="/control.js"></script>
  21. <script>
  22. L.Motion.Dynamicline = L.Motion.Polyline.extend({
  23. addPoint: function(latLng) {
  24. if (this.animation) {
  25. this.motionPause();
  26. this._linePoints.push(latLng);
  27. this.motionOptions.duration = L.Motion.Utils.getDuration(this._map, this._linePoints, this.motionOptions.speed);
  28. this.motionResume();
  29. } else {
  30. this._linePoints.push(latLng);
  31. this._motion((new Date).getTime());
  32. }
  33. }
  34. });
  35. L.motion.dynamicline = function(latlngs, options, motionOptions, markerOptions){
  36. return new L.Motion.Dynamicline(latlngs, options, motionOptions, markerOptions);
  37. };
  38. function addButtonToMap() {
  39. L.control.custom({
  40. position: 'bottomright',
  41. content: '<button id="btnAutoPlay" type="button" >' +
  42. ' START' +
  43. '</button>',
  44. style: {
  45. margin: '5px',
  46. padding: '0px 0 0 0',
  47. cursor: 'pointer',
  48. },
  49. events: {
  50. click: function (data) {
  51. console.log('start motion');
  52. startMotion();
  53. },
  54. }
  55. })
  56. .addTo(map);
  57. }
  58. var seq;
  59. var map = L.map('map');
  60. var Esri_WorldGrayCanvas = L.tileLayer(
  61. 'https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}', {
  62. attribution: 'Tiles &copy; Esri &mdash; Esri, DeLorme, NAVTEQ',
  63. maxZoom: 16
  64. }).addTo(map);
  65. var points = [
  66. [45.62754, 8.71508],
  67. [21.03653, -86.87708],
  68. [40.49181, -3.56948]
  69. ];
  70. map.setView(points[0], 11);
  71. map.fitBounds(points);
  72. var layers1 = L.motion.polyline([points[0], points[1]], {
  73. color: "#0067b0"
  74. }, {
  75. auto: false,
  76. duration: 3000,
  77. easing: L.Motion.Ease.easeInOutQuart
  78. }, {
  79. removeOnEnd: true,
  80. showMarker: false,
  81. icon: L.divIcon({
  82. html: "<i class='fas fa-plane fa-2x' aria-hidden='true'></i>",
  83. iconSize: L.point(27.5, 24)
  84. })
  85. });
  86. var layers2 = L.motion.dynamicline([points[1], points[2]], {
  87. color: "#0067b0"
  88. }, {
  89. auto: false,
  90. duration: 3000,
  91. easing: L.Motion.Ease.easeInOutQuart
  92. }, {
  93. removeOnEnd: true,
  94. showMarker: false,
  95. icon: L.divIcon({
  96. html: "<i class='fas fa-plane fa-2x' aria-hidden='true'></i>",
  97. iconSize: L.point(27.5, 24)
  98. })
  99. });
  100. addButtonToMap();
  101. seq = L.motion.seq([layers1, layers2], {
  102. auto: false
  103. });
  104. seq.addTo(map);
  105. seq.on(L.Motion.Event.Ended, function (evt) {
  106. document.getElementById('btnAutoPlay').disabled = false;
  107. });
  108. map.on("click", function(e) {
  109. layers2.addPoint(L.latLng(e.latlng));
  110. })
  111. function startMotion() {
  112. seq.motionStart();
  113. }
  114. </script>
  115. </body>
  116. </html>