Javascript examples for Leaflet:Polygon
add polygon in leaflet.js
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script> <style id="compiled-css" type="text/css"> .map {//from w w w .ja v a 2 s.c o m width: 300px; height: 200px; } </style> <script type="text/javascript"> window.onload=function(){ const map = L.map('map', { preferCanvas: true, zoomControl: false, attributionControl: false, crs: L.CRS.Simple }); const latlngs = [ [ 116, 115 ], [ 117, 111 ], [ 119, 112 ] ]; const polygon = L.polygon(latlngs, {color: 'red'}).addTo(map); map.fitBounds(polygon.getBounds()); } </script> </head> <body> <div class="map" id="map"> </div> </body> </html>