Advertisement
rodolpheg

Untitled

Feb 16th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 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,0], 2)
  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. polygones = {
  33. "type": "FeatureCollection",
  34. "features": [
  35. {
  36. "type": "Feature",
  37. "properties": {
  38. "cat": "A"
  39. },
  40. "geometry": {
  41. "type": "Polygon",
  42. "coordinates": [
  43. [
  44. [
  45. 36.5625,
  46. 64.47279382008166
  47. ],
  48. [
  49. 38.67187499999999,
  50. 36.5978891330702
  51. ],
  52. [
  53. 80.5078125,
  54. 56.36525013685606
  55. ],
  56. [
  57. 36.5625,
  58. 64.47279382008166
  59. ]
  60. ]
  61. ]
  62. }
  63. },
  64. {
  65. "type": "Feature",
  66. "properties": {
  67. "cat": "B"
  68. },
  69. "geometry": {
  70. "type": "Polygon",
  71. "coordinates": [
  72. [
  73. [
  74. -41.484375,
  75. 38.272688535980976
  76. ],
  77. [
  78. -45.3515625,
  79. 19.642587534013032
  80. ],
  81. [
  82. -8.7890625,
  83. 33.43144133557529
  84. ],
  85. [
  86. -26.3671875,
  87. 56.17002298293205
  88. ],
  89. [
  90. -41.484375,
  91. 38.272688535980976
  92. ]
  93. ]
  94. ]
  95. }
  96. },
  97. {
  98. "type": "Feature",
  99. "properties": {
  100. "cat": "C"
  101. },
  102. "geometry": {
  103. "type": "Polygon",
  104. "coordinates": [
  105. [
  106. [
  107. -92.8125,
  108. 56.17002298293205
  109. ],
  110. [
  111. -104.4140625,
  112. 52.482780222078226
  113. ],
  114. [
  115. -99.84374999999999,
  116. 45.583289756006316
  117. ],
  118. [
  119. -91.40625,
  120. 47.517200697839414
  121. ],
  122. [
  123. -92.8125,
  124. 43.068887774169625
  125. ],
  126. [
  127. -103.0078125,
  128. 39.36827914916011
  129. ],
  130. [
  131. -93.515625,
  132. 32.54681317351517
  133. ],
  134. [
  135. -81.9140625,
  136. 47.754097979680026
  137. ],
  138. [
  139. -92.8125,
  140. 56.17002298293205
  141. ]
  142. ]
  143. ]
  144. }
  145. }
  146. ]
  147. }
  148.  
  149. // J'ajoute les données GeoJSON à la carte
  150. couche = L.geoJSON(polygones, {
  151. style: function(feature) {
  152. if (feature.properties.cat === 'A') {
  153. return {color: "#D43E4C", "weight": 1, "fillOpacity": .75}
  154. }
  155. else if (feature.properties.cat === 'B') {
  156. return {color: "#6A8859", "dashArray": 10}
  157. }
  158. else if (feature.properties.cat === 'C') {
  159. return {color: "#7294B8", "dashArray": 3}
  160. }
  161. }
  162. })
  163.  
  164. couche.addTo(maCarte)
  165.  
  166. </script>
  167. </body>
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement