UNPKG

leaflet-plugins

Version:

Miscellaneous plugins for Leaflet library for services that need to display route information and need satellite imagery from different providers

34 lines (30 loc) 1.12 kB
<html> <head> <title>Leaflet</title> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script> <script src="../layer/vector/TOPOJSON.js"></script> </head> <body> <div style="width:100%; height:100%" id="map"></div> <script type='text/javascript'> var map = L.map('map', {center: L.latLng(58.4, 43.0), zoom: 3}); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);; var borders = new L.TOPOJSON('country.min.topojson', {async: true}).addTo(map); borders.on('addlayer',function (e) { e.layer.eachLayer(function (dist) { var iso = dist.toGeoJSON().properties.ISO2.toLowerCase(); dist.bindPopup('<strong>'+dist.toGeoJSON().properties.NAME_ISO+'</strong>',{closeButton:false}); if (dist.options) { dist.options.className = 'country country-'+iso; } else { dist.eachLayer(function (dist2) { dist2.options.className = 'country country-'+iso; }); } }); }); borders.on('loaded', function (e) { map.fitBounds(e.target.getBounds()); }); </script> </body> </html>