Advertisement
rodolpheg

Untitled

Feb 16th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Un titre</title>
  5. <meta charset="UTF-8">
  6. <!-- Téléchargement de la bibliothèque Leaflet.js -->
  7. <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>
  8. <!-- Téléchargement des instructions CSS de Leaflet, qui serviront à styliser les éléments de l'interface de la carte -->
  9. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" />
  10.  
  11. <style>
  12. html, body {height: 100%; margin: 0;}
  13. #Carte { width: 100%; height: 100%; }
  14. </style>
  15. </head>
  16. <body>
  17. <!-- Création d'un <div> qui contiendra notre carte-->
  18. <div id='Carte'></div>
  19.  
  20. <!-- Début du script JavaScript-->
  21. <script>
  22. // Création d'une variable "maCarte" qui contiendra... ma carte.
  23. maCarte = L.map('Carte')
  24. // On donne une position lat lng et un niveau de zoom par défaut
  25. maCarte.setView([45,-73], 5)
  26. // On définit notre fond de carte qui téléchargera les tuiles avec l'API OSM
  27. fondDeCarte = L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png')
  28. // J'attache ce fond de plan à ma carte
  29. fondDeCarte.addTo(maCarte)
  30.  
  31. // Je mets des données spatiales dans un objet JS
  32. points = {
  33. "type": "FeatureCollection",
  34. "features": [
  35. {
  36. "type": "Feature",
  37. "properties": {},
  38. "geometry": {
  39. "type": "Point",
  40. "coordinates": [
  41. 49.21875,
  42. 65.21989393613207
  43. ]
  44. }
  45. },
  46. {
  47. "type": "Feature",
  48. "properties": {},
  49. "geometry": {
  50. "type": "Point",
  51. "coordinates": [
  52. 14.0625,
  53. 13.581920900545844
  54. ]
  55. }
  56. },
  57. {
  58. "type": "Feature",
  59. "properties": {},
  60. "geometry": {
  61. "type": "Point",
  62. "coordinates": [
  63. -76.2890625,
  64. 50.51342652633956
  65. ]
  66. }
  67. },
  68. {
  69. "type": "Feature",
  70. "properties": {},
  71. "geometry": {
  72. "type": "Polygon",
  73. "coordinates": [
  74. [
  75. [
  76. -45.703125,
  77. 54.367758524068385
  78. ],
  79. [
  80. -1.7578125,
  81. 29.53522956294847
  82. ],
  83. [
  84. 26.71875,
  85. 61.938950426660604
  86. ],
  87. [
  88. -45.703125,
  89. 54.367758524068385
  90. ]
  91. ]
  92. ]
  93. }
  94. }
  95. ]
  96. }
  97.  
  98. // J'ajoute les données GeoJSON à la carte
  99. couche = L.geoJSON(points)
  100. couche.addTo(maCarte)
  101.  
  102. </script>
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement