index.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Leaflet motion plugin</title>
  5. <meta charset="utf-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
  8. <link rel="stylesheet" href="https://leaflet.github.io/Leaflet.draw/src/leaflet.draw.css"/>
  9. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/>
  10. <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.js"></script>
  12. <!--script src="src/leaflet.motion.js"></script>
  13. <script src="src/leaflet.motion.utils.js"></script>
  14. <script src="src/leaflet.motion.easing.js"></script>
  15. <script src="src/layer/leaflet.motion.polyline.js"></script>
  16. <script src="src/layer/leaflet.motion.polygon.js"></script>
  17. <script src="src/layer/leaflet.motion.group.js"></script>
  18. <script src="src/layer/leaflet.motion.seq.js"></script-->
  19. <script src="dist/leaflet.motion.min.js"></script>
  20. <style>
  21. html, body, #map { width: 100%; height: 100%; margin: 0px; padding: 0px;}
  22. .leaflet-div-icon {
  23. background: transparent!important;
  24. border: none!important;
  25. color: white;
  26. }
  27. .red {
  28. color: red!important;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="map"></div>
  34. <script>
  35. var map = L.map("map").setView([51, 1], 8);
  36. L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
  37. attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
  38. }).addTo(map);
  39. var options = {
  40. draw: {
  41. circle: false, // Turns off this drawing tool
  42. rectangle: false,
  43. marker: false,
  44. circlemarker: false
  45. }
  46. };
  47. var drawControl = new L.Control.Draw(options);
  48. map.addControl(drawControl);
  49. map.on(L.Draw.Event.CREATED, function (e) {
  50. var type = e.layerType,
  51. layer = e.layer;
  52. if (type === "polyline") {
  53. var line = L.motion.polyline(layer.getLatLngs(), {
  54. color: "orange"
  55. }, {
  56. auto: true,
  57. easing: L.Motion.Ease.swing
  58. }).motionSpeed(100000).addTo(map);
  59. }
  60. if (type === "polygon") {
  61. L.motion.polygon(layer.getLatLngs(), {
  62. color: "red",
  63. fill: true,
  64. fillOpacity: 0.4
  65. },{
  66. auto: true
  67. }, {
  68. removeOnEnd: true,
  69. icon: L.divIcon({className:"red", html: "<i class='fa fa-superpowers fa-spin fa-2x' aria-hidden='true' motion-base='0'></i>", iconSize: L.point(24, 24), iconAnchor: L.point(5, 22)})
  70. }).motionDuration(10000).addTo(map);
  71. }
  72. });
  73. var trackRoute = JSON.parse('[{"lat":51.15815239612826,"lng":-2.2055053710937504},{"lat":51.18569785341817,"lng":-2.1615600585937504},{"lat":51.19120493896969,"lng":-2.122009252198041},{"lat":51.22698519222996,"lng":-2.0187377929687504},{"lat":51.20221718842518,"lng":-1.979186986573041},{"lat":51.24211458943536,"lng":-1.8956908676773312},{"lat":51.22285808183325,"lng":-1.8429565429687502},{"lat":51.253114667550555,"lng":-1.7726440262049439},{"lat":51.25036488157529,"lng":-1.7023315094411375},{"lat":51.264112114656214,"lng":-1.6276245284825566},{"lat":51.28472525702113,"lng":-1.56829833984375},{"lat":51.26960987786426,"lng":-1.5309448074549437},{"lat":51.27510698339771,"lng":-1.4891967270523312},{"lat":51.29296795605501,"lng":-1.4474487304687502},{"lat":51.286099169144734,"lng":-1.3837279938161375},{"lat":51.27922935475756,"lng":-1.3397826813161373},{"lat":51.31494117540117,"lng":-1.2694701645523312},{"lat":51.32866911860522,"lng":-1.2057494278997185},{"lat":51.35611262745693,"lng":-1.1266478989273312},{"lat":51.39039390837808,"lng":-1.0695190262049439},{"lat":51.382168736719194,"lng":-1.0057982895523312},{"lat":51.37394211276064,"lng":-0.9596557449549438},{"lat":51.353369031707764,"lng":-0.9025268722325565},{"lat":51.347881294944216,"lng":-0.8651732560247184},{"lat":51.32866911860522,"lng":-0.8234251756221057},{"lat":51.31082203572863,"lng":-0.7860717270523311},{"lat":51.28335135620783,"lng":-0.6981811020523311},{"lat":51.291594301829406,"lng":-0.5905150528997184},{"lat":51.32043285621175,"lng":-0.5267943162471057},{"lat":51.36434245505222,"lng":-0.43670645914971834},{"lat":51.37805558339966,"lng":-0.35321029834449297},{"lat":51.3506252193158,"lng":-0.313659617677331},{"lat":51.32180564750844,"lng":-0.3004760574549437},{"lat":51.29296795605501,"lng":-0.27191153727471834},{"lat":51.27510698339771,"lng":-0.20159910432994368},{"lat":51.31631415723791,"lng":-0.12249740771949293},{"lat":51.361599352206966,"lng":-0.08074949495494367},{"lat":51.36022772609213,"lng":-0.0038450304418802266},{"lat":51.32866906624522,"lng":0.04449474625289441},{"lat":51.30807559747286,"lng":0.08184819482266904},{"lat":51.28747293535334,"lng":0.1367800030857325},{"lat":51.26686102604075,"lng":0.20709243603050712},{"lat":51.2599882819768,"lng":0.2444462198764086},{"lat":51.22148222615174,"lng":0.33453390933573246},{"lat":51.18156698919849,"lng":0.3960574138909579},{"lat":51.14988546610741,"lng":0.4663701821118594},{"lat":51.109908194320916,"lng":0.5718386638909579},{"lat":51.107149852721776,"lng":0.6751100812107326},{"lat":51.053329467578955,"lng":0.7805788982659579},{"lat":51.014650651391285,"lng":0.8377076033502817},{"lat":50.9690233345503,"lng":0.9036255721002818},{"lat":50.93996435333021,"lng":0.9585572127252818},{"lat":50.921966522212145,"lng":0.9651490766555072}]');
  74. var shipRoute = JSON.parse('[{"lat":50.921966522212145,"lng":0.9651490766555072},{"lat":50.926120475839824,"lng":1.0437014233320954},{"lat":50.94965276094792,"lng":1.1008302960544827},{"lat":50.96210622406778,"lng":1.184326456859708},{"lat":50.98700308620511,"lng":1.2678226176649334},{"lat":51.014650625032424,"lng":1.3710940349847078},{"lat":51.018796350737,"lng":1.4677737560123207},{"lat":51.062994180347005,"lng":1.5600588452070954},{"lat":51.07265684948244,"lng":1.65234393440187},{"lat":51.08093750173957,"lng":1.7358400952070954},{"lat":51.11680330181327,"lng":1.7973634321242573},{"lat":51.136104124419646,"lng":1.8940431531518698},{"lat":51.137482451626596,"lng":2.0126956980675463},{"lat":51.18845145219318,"lng":2.1203612443059687},{"lat":51.1898282161464,"lng":2.2412108536809687},{"lat":51.18569780089507,"lng":2.335693342611194},{"lat":51.207632884080915,"lng":2.427429333329201},{"lat":51.18836197273001,"lng":2.519714422523976},{"lat":51.1677055637131,"lng":2.618591375648976},{"lat":51.129466960517135,"lng":2.6630860380828385}]');
  75. var carRoute = JSON.parse('[{"lat":51.129466960517135,"lng":2.6630860380828385},{"lat":51.07664802198799,"lng":2.738342452794314},{"lat":51.055941653758396,"lng":2.749328780919314},{"lat":51.00067931792692,"lng":2.7778932172805075},{"lat":50.943967078334666,"lng":2.826233077794314},{"lat":50.89794502437422,"lng":2.867431640625},{"lat":50.846655509682435,"lng":2.9003906250000004},{"lat":50.824458803489804,"lng":2.9619141295552254},{"lat":50.79669804718136,"lng":3.0190430022776127},{"lat":50.76475273687021,"lng":3.1025391630828385},{"lat":50.72444284265441,"lng":3.1772460602223873},{"lat":50.65207604172236,"lng":3.282714877277613},{"lat":50.60469890778924,"lng":3.357421942055226},{"lat":50.562855920362125,"lng":3.425537142902613},{"lat":50.5181824559931,"lng":3.495849743485451},{"lat":50.47905843134065,"lng":3.570556808263064},{"lat":50.47626260659788,"lng":3.629882913082838},{"lat":50.492339146862776,"lng":3.772155828773976},{"lat":50.514693454200405,"lng":3.903991766273976},{"lat":50.510502790942944,"lng":3.9633178710937504},{"lat":50.49792872905663,"lng":4.024841375648976},{"lat":50.48185790425272,"lng":4.073730502277614},{"lat":50.47347053735934,"lng":4.133056774735452},{"lat":50.4776644868276,"lng":4.20336937531829},{"lat":50.479062245100565,"lng":4.231933560222388}]');
  76. var planeRoute1 = JSON.parse('[{"lat":50.48445898955202,"lng":4.251709654927255},{"lat":50,"lng":0}]');
  77. var planeRoute2 = JSON.parse('[{"lat":50,"lng":0},{"lat":51.15815239612826,"lng":-2.2055053710937504}]');
  78. var seqGroup = L.motion.seq([
  79. L.motion.polyline(trackRoute, {
  80. color: "orangered"
  81. }, {
  82. easing: L.Motion.Ease.easeInOutQuad
  83. }, {
  84. removeOnEnd: true,
  85. icon: L.divIcon({html: "<i class='fa fa-truck fa-2x fa-flip-horizontal' aria-hidden='true'></i>", iconSize: L.point(27.5, 24)})
  86. }).motionDuration(8000),
  87. L.motion.polyline(shipRoute, {
  88. color: "steelblue"
  89. }, {
  90. easing: L.Motion.Ease.easeInOutQuart
  91. }, {
  92. removeOnEnd: true,
  93. showMarker: true,
  94. icon: L.divIcon({html: "<i class='fa fa-ship fa-2x' aria-hidden='true'></i>", iconSize: L.point(27.5, 24)})
  95. }).motionDuration(9000),
  96. L.motion.polyline(carRoute, {
  97. colors: "SlateGrey"
  98. }, {
  99. easing: L.Motion.Ease.easeInOutElastic
  100. }, {
  101. removeOnEnd: true,
  102. icon: L.divIcon({html: "<i class='fa fa-car fa-2x' aria-hidden='true'></i>", iconSize: L.point(27.5, 24)})
  103. }).motionDuration(7000),
  104. L.motion.seq([L.motion.polyline(planeRoute1, {
  105. color:"indigo"
  106. }, null, {
  107. removeOnEnd: false,
  108. icon: L.divIcon({html: "<i class='fa fa-plane fa-2x' aria-hidden='true' motion-base='-43'></i>", iconSize: L.point(19, 24)})
  109. }).motionDuration(5000),
  110. L.motion.polyline(planeRoute2, {
  111. color:"khaki"
  112. }, null).motionDuration(7000)
  113. ])
  114. ]).addTo(map);
  115. seqGroup.on("click", function(){
  116. seqGroup.motionStart();
  117. });
  118. seqGroup.on("dblclick", function(e){
  119. seqGroup.motionToggle();
  120. });
  121. setTimeout(function () {
  122. seqGroup.motionStart();
  123. }, 1000);
  124. </script>
  125. </body>
  126. </html>